Getpositions angepasst, sodass Jsons geschrieben werden. Ausserdem Anpassung, sodass Leichen (=Bloecke ohne pos) nicht erfasst werden
This commit is contained in:
+24
-43
@@ -27,39 +27,6 @@ def write_results(jsnResults, outdir, filename):
|
||||
fh.write(jsnResults)
|
||||
print("done")
|
||||
|
||||
|
||||
def get_world_position_of_attribute(insert, attrib):
|
||||
"""
|
||||
Berechnet die echte Weltposition eines Block-Attributs (ATTRIB)
|
||||
unter Berücksichtigung von Skalierung, Drehung und Blockverschiebung.
|
||||
|
||||
:param insert: Blockreferenz-Entity (INSERT)
|
||||
:param attrib: Attribut-Entity (ATTRIB)
|
||||
:return: Vector (x, y, z) in Weltkoordinaten
|
||||
"""
|
||||
# Lokale Position des Attributs
|
||||
local_pos = attrib.dxf.insert
|
||||
|
||||
# Blockeinfügepunkt
|
||||
block_pos = insert.dxf.insert
|
||||
|
||||
# Blockskalierung (Standard = 1.0)
|
||||
xscale = getattr(insert.dxf, 'xscale', 1.0)
|
||||
yscale = getattr(insert.dxf, 'yscale', 1.0)
|
||||
|
||||
# Rotation des Blocks (in Grad)
|
||||
rotation_deg = insert.dxf.rotation
|
||||
|
||||
# Transformation aufbauen: Skalierung -> Rotation -> Translation
|
||||
m = (
|
||||
Matrix44.scale(xscale, yscale, 1) @
|
||||
Matrix44.z_rotate(rotation_deg * math.pi / 180) @
|
||||
Matrix44.translate(block_pos.x, block_pos.y, block_pos.z)
|
||||
)
|
||||
|
||||
# Lokale Position transformieren
|
||||
return m.transform(local_pos)
|
||||
|
||||
def merge_two_dicts(x, y):
|
||||
z = x.copy()
|
||||
z.update(y)
|
||||
@@ -96,16 +63,22 @@ def get_input_positions(msp: ezdxf.document.Drawing.modelspace):
|
||||
#print(f"-- coord {attrib.dxf.text} --: {attrib.dxf.insert}")
|
||||
if attrib.dxf.tag == "REALE_POSITION" and attrib.dxf.text == "x":
|
||||
#print(f"-- coord real --: {attrib.dxf.insert}")
|
||||
world_pos = get_world_position_of_attribute(insert, attrib)
|
||||
#print(f"-- world --: {world_pos}")
|
||||
ld["block_pos"] = attrib.dxf.insert
|
||||
ld["world_pos"] = world_pos
|
||||
pos = attrib.dxf.insert #Position Ecke unten links von "x"-Marker auslesen
|
||||
|
||||
# Hoehe und Breite von "x" addieren, um Mittelpunkt zu finden
|
||||
breite_marker = config.getfloat("Sensor_Marker", "Breite")
|
||||
hoehe_marker = config.getfloat("Sensor_Marker", "Hoehe")
|
||||
pos_midx = pos.x + breite_marker*0.5
|
||||
pos_midy = pos.y + hoehe_marker*0.5
|
||||
|
||||
if not id == "":
|
||||
if not id in allIds:
|
||||
allIds[id] = ld
|
||||
else:
|
||||
allIds[id] = merge_two_dicts(allIds[id], ld)
|
||||
ld["pos"] = (pos_midx, pos_midy)
|
||||
|
||||
# Nur wenn eine ID vorhanden ist, und eine gültige Position existiert
|
||||
if id and "pos" in ld and isinstance(ld["pos"], tuple) and len(ld["pos"]) == 2:
|
||||
if id in allIds:
|
||||
allIds[id] = merge_two_dicts(allIds[id], ld) #Kombiniert alle infos aus dxf und "pos"
|
||||
else:
|
||||
allIds[id] = ld
|
||||
return allIds
|
||||
|
||||
|
||||
@@ -172,7 +145,7 @@ def get_rack_positions(msp):
|
||||
return ret
|
||||
|
||||
def to_json(d, pretty: bool = True) -> str:
|
||||
return json.dumps(d, indent=2 if pretty else None, default=str)
|
||||
return json.dumps(d, indent=2 if pretty else None, ensure_ascii=False, default=str) #ensure_ascii false für darstellung von "ue"
|
||||
|
||||
def get_dxf_file(filepath):
|
||||
"""hole das dxf file
|
||||
@@ -199,6 +172,7 @@ if __name__ == '__main__':
|
||||
|
||||
out_dir = os.environ.get('PROJECT_DATA')
|
||||
work_dir = os.environ.get('PROJECT_WORK')
|
||||
config_dir = os.environ.get("PROJECT_CFG")
|
||||
filename = args.filename
|
||||
|
||||
doc = get_dxf_file(os.path.join(work_dir, filename)) # type: ignore
|
||||
@@ -208,18 +182,25 @@ if __name__ == '__main__':
|
||||
res_dist = dict()
|
||||
res_rac = dict()
|
||||
if args.sensors or args.dists or args.rack:
|
||||
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
config.read(os.path.join(config_dir, "getpositions.cfg"))
|
||||
|
||||
if args.sensors:
|
||||
res_pos = get_input_positions(msp)
|
||||
if args.console:
|
||||
print(to_json(res_pos))
|
||||
write_results(to_json(res_pos), work_dir, "sensors.json")
|
||||
if args.dists:
|
||||
res_dist = get_subdistributor_positions(msp)
|
||||
if args.console:
|
||||
print(to_json(res_dist))
|
||||
write_results(to_json(res_dist), work_dir, "subdistributors.json")
|
||||
if args.rack:
|
||||
res_rac = get_rack_positions(msp)
|
||||
if args.console:
|
||||
print(to_json(res_rac))
|
||||
write_results(to_json(res_rac), work_dir, "racks.json")
|
||||
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
Reference in New Issue
Block a user