Die Stücklistendaten, die aus der JSON-Datei des Programms 'Sivas2Json' erzeugt werden, wird jetzt immer die Teilenummer der Hauptbaugruppe ergänzt. Dadurch kann die Methode '_print_tree' auch die Nummer der Hauptbaugruppe schreiben. Bisher war hierfür die separate Methode '_tree_header' erforderlich. Für die Aufnahme der Hauptbaugruppe in die Stücklistendaten ist die neue Methode '_add_asm_id_to_bom' zuständig. Die Anpassung wurde vorbereitend für die nächste Erweiterung dieses Programms ergänzt, mit der es möglich sein soll, den Migrationsstand von einzelnen Teilenummern, d.h. Nummern, die keine Baugruppen sind, anzuzeigen.

This commit is contained in:
2025-04-18 22:13:07 +02:00
parent fe302ef950
commit 80000c15c3
+45 -40
View File
@@ -75,7 +75,7 @@ class ExcelExport:
sorting = self._create_sorting_string()
migrated_ids = self.migration_status.ids_in_rd
child_descriptions:dict = self.asm_data.get_bom_property_values("Bezeichnung")
child_descriptions:dict = self.asm_data.get_prop_val_for_all_ids("Bezeichnung")
parent_description:str = self.asm_metadata.get_property_values("Bezeichnung1")
descriptions = child_descriptions.copy()
@@ -212,47 +212,45 @@ class Treeview:
+ padding_after_id
return self._longest_entry
def _add_asm_id_to_bom(self):
"""Standardmäßig ist die oberste Baugruppennummer kein Bestandteil der JSON-Datei, in der die Baugruppenstruktur aufgelistet ist und
die über das Programm 'Sivas2Json' von Hr. Jakob generiert wird. Damit der Baum die Bezeichnung der obersten Baugruppennummer im
Baum angezeigt wird ist es jedoch erforderlich, dass die Nummer mitsamt ihrer Bezeichnung in der JSON enthalten ist"""
metadata = {"Bezeichnung": self.asm_metadata.get_property_values("Bezeichnung1"),
"Position": "10/0"}
self.asm_bom_data.extend_asm_bom(self.asm_id, metadata)
def generate_tree(self):
self._tree_header()
self._tree_body()
self._tree_summary()
self._add_asm_id_to_bom()
self._print_tree()
self._print_summary()
def _tree_header(self):
"""Prints root number (number for which the user wants to see the tree) to the console"""
def _print_tree(self, parent_id=None, prefix=""):
id = self.asm_id
color = self._set_text_background_color(id)
text_before_description = f"{color}{id}{Treeview.console_colors['RESET']}".ljust(self.longest_entry)
description = self.asm_metadata.get_property_values("Bezeichnung1")
print(f"{text_before_description}{description}")
def _tree_body(self, parent_id=None, prefix=""):
"""Prints the body (all partnumbers except root/main-partnumber) of the tree to the console"""
if parent_id is None:
parent_id = self.asm_id
"""Gibt die Baugruppenstruktur in Form eines Baumes in der Konsole aus"""
parent_children = self.asm_bom_data.parent_children
children_ids = parent_children[parent_id]
for index, child_id in enumerate(children_ids):
for i, id in enumerate(children_ids):
is_last_assembly_child = self._last_child_check(index, children_ids)
last_child = self._last_child_check(i, children_ids)
connector_symbol = self._set_connector_symbol(id, last_child)
background_color = self._set_background_color(id)
connector_symbol = self._set_connector_symbol(is_last_assembly_child)
partnumber_background_color = self._set_text_background_color(child_id)
self._print_entry(id, prefix, connector_symbol, background_color)
self._print_entry(child_id, prefix, connector_symbol, partnumber_background_color)
if id in parent_children:
next_prefix = self._set_next_prefix(prefix, id, last_child)
self._print_tree(parent_id=id, prefix=next_prefix)
if child_id in parent_children:
next_prefix = self._prefix(prefix, is_last_assembly_child)
self._tree_body(parent_id=child_id, prefix=next_prefix)
def _tree_summary(self):
def _print_summary(self):
amount_in_rd = len(self.migration_status.ids_in_rd)
amount_pending = len(self.migration_status.ids_pending)
@@ -299,36 +297,44 @@ class Treeview:
"""Eintrag in die Konsole drucken"""
text_before_description = f"{prefix}{connector}{color}{child_id}{Treeview.console_colors['RESET']}".ljust(self.longest_entry)
description = self.asm_bom_data.get_bom_property_values("Bezeichnung")[child_id]
description = self.asm_bom_data.get_prop_val_for_single_id(child_id, "Bezeichnung")
print(f"{text_before_description}{description}")
def _last_child_check(self, child_index, children):
def _last_child_check(self, child_idx, children_ids):
"""Prüft, ob aktuelle ID das letzte Kind der Baugruppe ist"""
return True if child_index == len(children) - 1 else False
return True if child_idx == len(children_ids) - 1 else False
def _set_connector_symbol(self, child_is_last_child):
def _set_connector_symbol(self, child_id, last_child):
"""Legt Verbindungssymbol für aktuellen Eintrag im Baum fest"""
return Treeview.connector_symbols["ELBOW"] if child_is_last_child else Treeview.connector_symbols["T"]
if child_id == self.asm_id: # Oberste Baugruppennummer wird immer ohne Verbindersymbol dargestellt
return ""
if not last_child:
return Treeview.connector_symbols["T"]
return Treeview.connector_symbols["ELBOW"]
def _prefix(self, prefix, child_is_last_child):
def _set_next_prefix(self, prefix, child_id, last_child):
"""Erstellt für jeden Eintrag im Baum einen Präfix (Teil vor dem Verbindersymbol) fest"""
"""Legt den Teil VOR dem Verbindersymbol für den nächsten Eintrag im Baum fest"""
prefix += Treeview.prefix_types["EMPTY"] if child_is_last_child else Treeview.prefix_types["PIPE"]
if child_id == self.asm_id: # Erste Stücklistenposition der obersten Baugruppennummer hat nie Präfix
return ""
prefix += Treeview.prefix_types["EMPTY"] if last_child else Treeview.prefix_types["PIPE"]
return prefix
def _set_text_background_color(self, id):
def _set_background_color(self, id):
"""Legt Hintergrundfarbe der Teilenummer basierend auf ihrem Migrationsstatus fest:
@@ -397,7 +403,6 @@ if __name__ == '__main__':
load_local_asm_csv=args.asm_csv_local,
load_local_rd_dbase=args.rd_ids_local,
no_blue_ids=args.no_blue_ids)
treeview_comparison.generate_tree()
else:
parser.print_help()