Schalter für Einlesen von positions_json in drawdxf etfernt (bat-Datei und Python Skript angepasst)., Sensor dataclass in drawdxf entfernt

get_type_of_name_cfg als Config-basierte Methode statt hardcode geschrieben.
map_sensor_to_cable_cfg als config basierte methode mitsamt kürzung de Kabel, etc..
Erstellung von Betriebsmittelkennzeichner Config.
This commit is contained in:
2025-06-12 10:54:02 +02:00
parent cc36734790
commit 2657117c24
5 changed files with 99 additions and 14 deletions
+42 -10
View File
@@ -49,11 +49,6 @@ class Polylines:
errors_existing_dists: List[str]
errors_existing_sensors: List[str]
@dataclass
class Sensors:
name: str
artinr: str
pos: List[float]
def add_polyline(msp, points:Polyline, dxf_attribs):
pts = points.to_tuple()
@@ -125,7 +120,6 @@ def find_close_key(pos2sensors, x, y, tolerance=10): # !!! Toleranz nicht
return (px, py)
return None
def draw_sensors(plines, doc):
msp = doc.modelspace()
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M")
@@ -485,13 +479,47 @@ def map_sensor_to_cable(plines):
return sens2cable
def map_sensor_to_cable_cfg(plines):
sens2cable = defaultdict(list)
mapping = config_BMK["Cable-Mapping"]
for pl in plines.kabel:
sensor_name = pl.id.split('-')[-1]
cable_length = pl.length/1000
sensor_artinr = pl.s_artinr
name_prefix = sensor_name[:2]
# Suche nach Key in der BMK-Config
key_with_artnr = f"{name_prefix}-{sensor_artinr}"
if key_with_artnr in mapping:
section_list = mapping[key_with_artnr]
elif name_prefix in mapping:
section_list = mapping[name_prefix]
else:
sens2cable[pl.id].append("Kein Kabeltyp zugewiesen")
# Liste aus evtl. mehreren Sektionen erzeugen
sections = [s.strip for s in section_list.split(",")]
# Evtl. Kabelkürzung durchführen, fall Kabelschwanz vorhanden
if config_BMK.has_section("Length-Adjustments") and config_BMK.has_option("Length-Adjustments", name_prefix):
length_reduction = float(config_BMK.get("Length-Adjustments", name_prefix))
cable_length = max(0.0, cable_length-length_reduction)
# Kabel-Atikelnummer innerhalb der Sektion der kabel.cfg bestimmen
for section in sections:
cable_artnr = get_cable_artnr(section, cable_length)
if cable_artnr is None:
sens2cable[pl.id].append(f"Kabel länger als max. Kabellänge")
else:
sens2cable[pl.id].append(cable_artnr)
return sens2cable
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='draws a dxf file with the given cable coordinates', prog='drawdxf')
parser.add_argument('-f', '--filename', action='store', required=True, help='this json file contains all cables and its coordinates which should be drawn. Saved with an unique timestamp', metavar='myfile.json')
parser.add_argument('-p','--positions', action='store', required=True, help='this json file contains positional information written by getpositions', metavar='myfile.json')
parser.add_argument('-d', '--dxf', action='store', help='this dxf drawing will be copied and the new layer with the cables will be added. Original file must be added with --origin', metavar='myfile.dxf')
parser.add_argument('-c', '--copy_layer', action='store', help='copy layers of racks, sensors, distributors into a new .dxf-file. File also contains cable paths. Original file must be added with --origin', metavar='original.dxf')
parser.add_argument('-n', '--new', action='store', help='create a new dxf file only with cables in it. Name is basename and a timestamp')
@@ -519,20 +547,24 @@ if __name__ == '__main__':
exit()
plines = model_from_json(json_path)
sensors = parse_sensors_from_json(positions_path)
# Allgemeine Config laden
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config.optionxform = lambda option: option # preserve case for letters
config.read(os.path.join(config_dir, "allgemein.cfg"))
# Config für Kabel-Atikelnummern laden
# Config für Kabel-Artikelnummern laden
cable_cfg = configparser.ConfigParser()
cable_cfg.optionxform = str #Keys case-sensitive
with open(os.path.join(config_dir, "kabel.cfg"), encoding="utf-8") as f:
cable_cfg.read_file(f)
# Betriebsmittelkennzeichnungs-Config laden
config_BMK = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config_BMK.optionxform = lambda option: option # preserve case for letters
config_BMK.read(os.path.join(config_dir, "BMK.cfg"))
dxf_file = args.dxf
if args.dxf or args.copy_layer:
+17 -2
View File
@@ -55,7 +55,7 @@ def get_type_of_name(name):
"SF" # Drucktaster
]
prefix = name[0:2]
prefix = name[:2]
if prefix in SpecialKeys:
typ = "Sensor"
@@ -72,6 +72,16 @@ def get_type_of_name(name):
return typ
def get_type_of_name_cfg(name):
prefix = name[:2]
if config_BMK.has_option("Routing-Include", prefix):
return "Sensor"
elif config_BMK.has_option("Routing-Ignore", prefix):
return "Schaltschrankelement"
else:
return "unknown"
def get_attributes_of_insert(insert):
id = ""
ld = dict()
@@ -441,10 +451,15 @@ if __name__ == '__main__':
if args.sensors or args.dists or args.rack:
# Allgemeine Config Laden
config = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config.optionxform = lambda option: option # preserve case for letters
config.read(os.path.join(config_dir, "allgemein.cfg"))
# Betriebsmittelkennzeichnungs-Config laden
config_BMK = configparser.ConfigParser(allow_no_value=True, delimiters=("="))
config_BMK.optionxform = lambda option: option # preserve case for letters
config_BMK.read(os.path.join(config_dir, "BMK.cfg"))
output_results = dict()