From 2a601ec3c194a3b4f3e6a2c1c6cae5c79ef8de63 Mon Sep 17 00:00:00 2001 From: Simon Steuer Date: Sun, 20 Apr 2025 17:40:52 +0200 Subject: [PATCH] =?UTF-8?q?In=20CreoMigrate=20(GUI-Applikation)=20k=C3=B6n?= =?UTF-8?q?nen=20nun=20auch=20Teilenummern=20ohne=20St=C3=BCckliste=20migr?= =?UTF-8?q?iert=20werden.=20Hierf=C3=BCr=20wurde=20in=20Methode=20'get=5Fc?= =?UTF-8?q?sv=5Ffiles=5Fof=5Fasm'=20von=20'controller.py'=20ein=20Aufruf?= =?UTF-8?q?=20der=20Methode=20'extend=5Fasm=5Fbom'=20aus=20der=20Klasse=20?= =?UTF-8?q?'SivasBOM'=20in=20'manage=5Fconfigs.py'=20erg=C3=A4nzt.=20Inner?= =?UTF-8?q?halb=20der=20Methode=20wird=20die=20angegebene=20Teilenummer=20?= =?UTF-8?q?aus=20dem=20Eingabefeld=20in=20der=20GUI,=20d.h.=20die=20Hauptn?= =?UTF-8?q?ummer=20in=20die=20St=C3=BCcklistendaten=20aufgenommen=20-=20st?= =?UTF-8?q?andardm=C3=A4=C3=9Fig=20ist=20sie=20nicht=20enthalten.=20Als=20?= =?UTF-8?q?Oberbaugruppe=20dieser=20Nummer=20wird=20dabei=20die=20fiktive?= =?UTF-8?q?=20Baugruppe=20'None'=20definiert.=20Durch=20diese=20Erg=C3=A4n?= =?UTF-8?q?zung=20in=20den=20St=C3=BCcklistendaten=20wird=20eine=20Teilenu?= =?UTF-8?q?mmer=20ohne=20St=C3=BCckliste=20also=20selbst=20zu=20einem=20Be?= =?UTF-8?q?standteil=20der=20fiktiven=20Baugruppe=20'None'.=20Somit=20wird?= =?UTF-8?q?=20also=20wie=20bisher=20nur=20mit=20Baugruppen=20gearbeitet,?= =?UTF-8?q?=20wodurch=20die=20Grundlogik=20zur=20Erstellung=20des=20Treevi?= =?UTF-8?q?ews=20im=20Programm=20gleich=20bleibt.=20Lediglich=20die=20Vorg?= =?UTF-8?q?ehensweise,=20wenn=20parent=20=3D=20'None'=20gilt=20musste=20in?= =?UTF-8?q?=20den=20Treeview-Methoden=20angepasst=20werden.=20Im=20Zuge=20?= =?UTF-8?q?dessen=20wurde=20auch=20die=20Methode=20'=5Fhas=5Fchilds'=20der?= =?UTF-8?q?=20Treeview-Klasse=20in=20'gui.py'=20angepasst,=20um=20sie=20ef?= =?UTF-8?q?fizienter=20zu=20machen.=20Konkret=20wird=20nun=20nicht=20mehr?= =?UTF-8?q?=20jedes=20mal=20durch=20das=20parent=5Fchildren=5Fmapping-dict?= =?UTF-8?q?=20gelooped=20werden,=20um=20herauszufinden,=20ob=20die=20angeg?= =?UTF-8?q?ebene=20Nummer=20enthalten=20ist.=20Da=20alle=20Nummern,=20die?= =?UTF-8?q?=20als=20Key=20in=20genanntem=20Dict=20vorliegen=20immer=20Kind?= =?UTF-8?q?er=20haben=20muss=20stattdessen=20nur=20gepr=C3=BCft=20werden,?= =?UTF-8?q?=20ob=20die=20Nummer=20als=20Key=20vorliegt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controller.py | 27 ++++++++++++++------------- lib/gui.py | 25 ++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/controller.py b/lib/controller.py index 606011a..e41ec07 100644 --- a/lib/controller.py +++ b/lib/controller.py @@ -2,7 +2,7 @@ import os from tkinter import messagebox import update_database -from manage_configs import SivasBOM, RuleDesignerDatabaseConfig, MigrationStatus +from manage_configs import SivasBOM, SivasTeilestamm, RuleDesignerDatabaseConfig, MigrationStatus """ Contains the logic for the MVC of CreoMigrate Gui @@ -115,26 +115,27 @@ class Controller(Observer): orange[red] = True return orange - def get_csv_files_of_asm(self, asm_id, load_local_asm_json, load_local_rd_dbase): + def get_csv_files_of_asm(self, asm_id, load_local_asm_json=False, load_local_rd_dbase=False): + """ Holt sich die Metadaten der Stücklistenpositionen als CSV""" data_dir = self.get_env("data") rd_dbase_filename = self.get_env("rd_dbase_filename") - asm_data = SivasBOM(data_dir, asm_id + '.json', load_local_asm_json) + sivas_bom = SivasBOM(data_dir, asm_id + '.json', load_local_asm_json) + sivas_bom.extend_asm_bom(asm_id, {"Parent": None, "Position": "10/0"}) # Ergänzt Stücklistendaten um eine fiktive Baugruppe "None", in der die Haupt-Teilenummer als Pos. 1 vorliegt. Dadurch können auch Teilenummern ohne Stückliste korrekt abgebildet werden + rd_data = RuleDesignerDatabaseConfig(data_dir, rd_dbase_filename, load_local_rd_dbase) - migration_status = MigrationStatus(asm_data.child_ids, rd_data.ids) - if not load_local_asm_json: - try: - update_database.get_sivas_teilestamm(migration_status.ids_pending, data_dir) - except: - self.message_error('Abfrage hat nicht funktioniert', 'sivas_db_error') - return + migration_status = MigrationStatus(sivas_bom.child_ids, rd_data.ids) + pending_ids = migration_status.ids_pending - self._model.set_red_ids(migration_status.ids_pending) - self._model.set_parent_children(asm_data.parent_children) + sivas_teilestamm = SivasTeilestamm(data_dir, asm_id + '.csv') + sivas_teilestamm.create_csvs(pending_ids) + + self._model.set_red_ids(pending_ids) + self._model.set_parent_children(sivas_bom.parent_children) self._model.set_asm_id(asm_id) - self._model.set_bom_properties(asm_data.all_bom_properties) + self._model.set_bom_properties(sivas_bom.all_bom_properties) def set_model(self, model): self._model = model diff --git a/lib/gui.py b/lib/gui.py index 1f06146..da792c8 100644 --- a/lib/gui.py +++ b/lib/gui.py @@ -55,10 +55,7 @@ class AllFrames(): class TreeView(): def __init__(self, frame, nrow=0): # a treeview - # hier Anzahl der sichtbaren Zeilen des Baums angeben: - self.tree = ttk.Treeview(frame, height=65) - # TODO hier anstatt root die Statistik rein schreiben. - #self.tree.heading('#0', text='root', anchor=tk.W) + self.tree = ttk.Treeview(frame, height=65) # 'height' steuert Anzahl der sichtbaren Zeilen im Baum self.tree.grid(row=nrow, column=0, sticky=tk.NSEW) # add a scrollbar @@ -75,7 +72,9 @@ class TreeView(): done_items = set() undone_items = set() for parent,children in parent_children_mapping.items(): - if parent in red_ids: + if parent is None: + pass + elif parent in red_ids: undone_items.add(parent) else: done_items.add(parent) @@ -108,18 +107,16 @@ class TreeView(): self.tree.delete(c) def _has_childs(self, sid, parent_children_mapping): - '''gibt zurück ob sid ein ein Zwischenknoten eines Baume ist, also kein Blatt hat''' - for parent,children in parent_children_mapping.items(): - if sid == parent: - return True - return False + '''gibt zurück ob sivas-id ein Zwischenknoten eines Baume ist, also kein Blatt hat''' + return True if sid in parent_children_mapping else False def create(self, parent_children_mapping, red_ids, orange_ids): pool = dict() - self.set_heading_text(parent_children_mapping, red_ids) for parent, children in parent_children_mapping.items(): # parent erzeugen, falls es diese nicht schon gibt (check der pool ids) - if parent not in pool: + if parent is None: + parent_id = None + elif parent not in pool: if parent not in red_ids: rowtags = ('good') elif parent in orange_ids: rowtags = ('orange') else: rowtags = ('missing') @@ -148,7 +145,9 @@ class TreeView(): child_id = self.tree.insert('', tk.END, text=child, tags=rowtags, open=True) pool[child] = child_id # hier werden die keys - sivas Nummern auch überschrieben self.trid2sivasId[child_id] = child # merken der eindeutigen Zuordnung für den späteren Doppelklick - self.tree.move(child_id, parent_id, 'end') + + if parent_id is not None: + self.tree.move(child_id, parent_id, 'end') # https://www.askpython.com/python-modules/tkinter/tkinter-colors #self.tree.tag_configure('good', background='LawnGreen')