From 0ce8a485e3f99c191805b10acc5dbd869075ec8f Mon Sep 17 00:00:00 2001 From: mistangl Date: Thu, 11 Jan 2024 12:14:03 +0100 Subject: [PATCH] Modul in Einzelteile zerlegt --- lib/CreoMigrateGui.py | 158 ++---------------------------------------- lib/caditem.py | 118 +++++++++++++++++++++++++++++++ lib/controller.py | 30 ++++++++ lib/test_gui.py | 79 +++++++++++++++++++++ 4 files changed, 231 insertions(+), 154 deletions(-) create mode 100644 lib/caditem.py create mode 100644 lib/controller.py create mode 100644 lib/test_gui.py diff --git a/lib/CreoMigrateGui.py b/lib/CreoMigrateGui.py index 0699b42..88d7435 100644 --- a/lib/CreoMigrateGui.py +++ b/lib/CreoMigrateGui.py @@ -1,5 +1,7 @@ import tkinter as tk from tkinter import ttk +from controller import Controller +from caditem import CadItem #from tkinter import messagebox #import logging @@ -7,7 +9,6 @@ from tkinter import ttk #logger = logging.getLogger(__name__) - class TreeView(): def __init__(self, frame): # a treeview @@ -181,8 +182,8 @@ class App(): style.theme_use('classic') current_id = self.controller.get_current_asm_id() - self.controller.get_parent_children() - self.controller.get_red_ids() + parent_children_mapping = self.controller.get_parent_children() + red_ids = self.controller.get_red_ids() self.tv = TreeView(left_frame) self.tv.create(parent_children_mapping, red_ids) gridhdl = self.tv.get_handle() @@ -282,154 +283,3 @@ if __name__ == "__main__": --sees --> -- uses --> USER """ - class CadItem(): - """ - This item contains all data for writing all necessary data to the solid edg cad file - - """ - # diese Daten bilden dann die Impfdaten - data_keys = [ "Author", "Teilenummer", "StartRevision", - "Bezeichnung1", "Bezeichnung2", "Bezeichnung4", "KategorieNE", - "BeschaffungsartNE", "TOS-Gruppe_ERP", "Dispogruppe", - "Dispolaufgruppe", "WerkstofftypNE", "WerkstoffNE", - "Oberflaechenbehandlung", "Farbe", "KalkulationsartNE", - "RuestcodeAusw", "Fertigungsart", "Allgemeintoleranz", - "HalbzeugInternAngabe", "Halbzeug", "HalbzeugOhneSaegeliste", - "EinheitNE", "FOS-GruppeNE", "Hersteller", "HerstellerTeilenummer", - "Serien-Status", "Kantennorm", "Oberflaechennorm", "Massnorm", - "Tolerierungsnorm", "TOS-Gruppe", "TOS_Schoenenberger_Produkt", - "TOS_Automation", "TOS_Maschinenelement", - "TOS_Schoenenberger_Komponenten", "TOS_Pneumatik", "TOS_Konfig", - "TOS_ILS", "TOS_MAS", "TOS_Spinnereikomponente", - "TOS_Betriebsmittel", "TOS_Geruest", "TOS_FremdTransport", - "TOS_MAS_Konfig", "TOS_Schaltschrank", "TOS_Schalt_Einbau", - "TOS_Dezentral", "TOS_Automation_Sensorik", "TOS_Kabel", - "TOS_Installation", "TOS_Automation_Sonstiges", - "TOS_Verbindungselement", "TOS_Lager", "TOS_Kraft_Drehmoment", - "TOS_Sicherungselement", "TOS_Bedienungselement", "TOS_ILS_2", - "TOS_ILS_Foerderer", "TOS_MAS_Fahrstecke", "TOS_Trolley", - "TOS_Trolley_Projekte", "TOS_Trolley_Omniflo", - "TOS_Trolley_Spinnerei", "TOS_Trolley_ILS", "Änderungsbeschreibung", - "Freigabevermerk", "ZusaetzlicheInformationen"] - - def __init__(self, asm_id): - """ is initalized with its unique id""" - self.set_asm_id(asm_id) - self.red_ids = {} - self.parent_children_mapping = {} - self.data = {} - self.gui_data = {} - - def set_asm_id(self, asm_id): - self.asm_id = asm_id - def get_current_asm_id(self): - return self.asm_id - - def get_current_part_id(self): - return self.prt_id - def set_part_id(self, prt_id): - self.prt_id = prt_id - - - def set_parent_children(self, parent_children_mapping): - """ contains all id relations below, data of subassemblies etc. in - a dict of the kind parent-children - """ - self.parent_children_mapping = parent_children_mapping - def get_parent_children(self): - return self.parent_children_mapping - - def set_red_ids(self, red_ids): - """ these ids are not yet known by the PDM""" - self.red_ids = red_ids - - def get_red_ids(self): - return self.red_ids - - def set_data(self, data:dict): - for k,v in data: - self.set_data(k,v) - def set_data(self, key, val): - if key not in self.data_keys: - raise Exception("this data can not be set") - else: - self.data[key] = val - - def get_data(self, key): - return self.data[key] - - def load(): - pass - def save(): - pass - - - class CadItemRepository: - """ - container class for all CadItems in the local folder - also just managed by the controller - """ - def __init__(self): - self.caditems = [] - - def add(self, caditem): - self.caditems.append(caditem) - - def get(self, id): - for caditem in self.caditems: - if caditem.id == id: - return caditem - return None - - def get_all(self): - return self.caditems - - def update(self, old_item, new_item): - self.delete(old_item.id) - self.add(new_item) - raise Exception("CadItem not found") - - def delete(self, id): - for p in self.caditems: - if p.id == id: - self.caditems.remove(p) - return - raise Exception("CadItem not found") - - class Controller(): - """ - Class for manipulating the model and returning data for the view - """ - def __init__(self, model): - self.model = model - - def get_current_asm_id(self): - self.model.get_current_asm_id() - def set_current_asm_id(self, asm_id): - self.model.set_current_asm_id(asm_id) - - def set_red_ids(self, red_ids): - self.model.set_red_ids(red_ids) - def get_red_ids(self): - return self.model.get_red_ids() - - def set_parent_children(self, parent_children_mapping): - self.model.set_parent_children(parent_children_mapping) - def get_parent_children(self): - return self.model.get_parent_children() - def set_data(self, key, value): - self.model.set_data(key, value) - - - - - #logging.basicConfig(level=logging.DEBUG) - model = CadItem("400102196") - - controller = Controller(model) - controller.set_parent_children(parent_children_mapping) - controller.set_red_ids(red_ids) - - root = tk.Tk() - app = App(root, controller) - app.mainloop() diff --git a/lib/caditem.py b/lib/caditem.py new file mode 100644 index 0000000..592412b --- /dev/null +++ b/lib/caditem.py @@ -0,0 +1,118 @@ +class CadItem(): + """ + This item contains all data for writing all necessary data to the solid edg cad file + + """ + # diese Daten bilden dann die Impfdaten + data_keys = [ "Author", "Teilenummer", "StartRevision", + "Bezeichnung1", "Bezeichnung2", "Bezeichnung4", "KategorieNE", + "BeschaffungsartNE", "TOS-Gruppe_ERP", "Dispogruppe", + "Dispolaufgruppe", "WerkstofftypNE", "WerkstoffNE", + "Oberflaechenbehandlung", "Farbe", "KalkulationsartNE", + "RuestcodeAusw", "Fertigungsart", "Allgemeintoleranz", + "HalbzeugInternAngabe", "Halbzeug", "HalbzeugOhneSaegeliste", + "EinheitNE", "FOS-GruppeNE", "Hersteller", "HerstellerTeilenummer", + "Serien-Status", "Kantennorm", "Oberflaechennorm", "Massnorm", + "Tolerierungsnorm", "TOS-Gruppe", "TOS_Schoenenberger_Produkt", + "TOS_Automation", "TOS_Maschinenelement", + "TOS_Schoenenberger_Komponenten", "TOS_Pneumatik", "TOS_Konfig", + "TOS_ILS", "TOS_MAS", "TOS_Spinnereikomponente", + "TOS_Betriebsmittel", "TOS_Geruest", "TOS_FremdTransport", + "TOS_MAS_Konfig", "TOS_Schaltschrank", "TOS_Schalt_Einbau", + "TOS_Dezentral", "TOS_Automation_Sensorik", "TOS_Kabel", + "TOS_Installation", "TOS_Automation_Sonstiges", + "TOS_Verbindungselement", "TOS_Lager", "TOS_Kraft_Drehmoment", + "TOS_Sicherungselement", "TOS_Bedienungselement", "TOS_ILS_2", + "TOS_ILS_Foerderer", "TOS_MAS_Fahrstecke", "TOS_Trolley", + "TOS_Trolley_Projekte", "TOS_Trolley_Omniflo", + "TOS_Trolley_Spinnerei", "TOS_Trolley_ILS", "Änderungsbeschreibung", + "Freigabevermerk", "ZusaetzlicheInformationen"] + + def __init__(self, asm_id): + """ is initalized with its unique id""" + self.set_asm_id(asm_id) + self.red_ids = {} + self.parent_children_mapping = {} + self.data = {} + self.gui_data = {} + + def set_asm_id(self, asm_id): + self.asm_id = asm_id + def get_current_asm_id(self): + return self.asm_id + + def get_current_part_id(self): + return self.prt_id + def set_part_id(self, prt_id): + self.prt_id = prt_id + + + def set_parent_children(self, parent_children_mapping): + """ contains all id relations below, data of subassemblies etc. in + a dict of the kind parent-children + """ + self.parent_children_mapping = parent_children_mapping + def get_parent_children(self): + return self.parent_children_mapping + + def set_red_ids(self, red_ids): + """ these ids are not yet known by the PDM""" + self.red_ids = red_ids + + def get_red_ids(self): + return self.red_ids + + def set_data(self, data:dict): + for k,v in data: + self.set_data(k,v) + def set_data(self, key, val): + if key not in self.data_keys: + raise Exception("this data can not be set") + else: + self.data[key] = val + + def get_data(self, key): + return self.data[key] + + def load(): + pass + def save(): + pass + +class CadItemRepository: + """ + container class for all CadItems in the local folder + also just managed by the controller + """ + def __init__(self): + self.caditems = [] + + def add(self, caditem): + self.caditems.append(caditem) + + def get(self, id): + for caditem in self.caditems: + if caditem.id == id: + return caditem + return None + + def get_all(self): + return self.caditems + + def update(self, old_item, new_item): + self.delete(old_item.id) + self.add(new_item) + raise Exception("CadItem not found") + + def delete(self, id): + for p in self.caditems: + if p.id == id: + self.caditems.remove(p) + return + raise Exception("CadItem not found") + +if __name__ == "__main__": + pass + + + diff --git a/lib/controller.py b/lib/controller.py new file mode 100644 index 0000000..dc128fe --- /dev/null +++ b/lib/controller.py @@ -0,0 +1,30 @@ +""" +Contains the logic for the MVC of CreoMigrate Gui +""" + +class Controller(): + """ + Class for manipulating the model and returning data for the view + """ + def __init__(self, model): + self.model = model + + def get_current_asm_id(self): + self.model.get_current_asm_id() + def set_current_asm_id(self, asm_id): + self.model.set_current_asm_id(asm_id) + + def set_red_ids(self, red_ids): + self.model.set_red_ids(red_ids) + def get_red_ids(self): + return self.model.get_red_ids() + + def set_parent_children(self, parent_children_mapping): + self.model.set_parent_children(parent_children_mapping) + def get_parent_children(self): + return self.model.get_parent_children() + def set_data(self, key, value): + self.model.set_data(key, value) + +if __name__ == "__main__": + pass diff --git a/lib/test_gui.py b/lib/test_gui.py new file mode 100644 index 0000000..2fe2c42 --- /dev/null +++ b/lib/test_gui.py @@ -0,0 +1,79 @@ +import tkinter as tk +from caditem import CadItem +from CreoMigrateGui import App +from controller import Controller + + +red_ids = ( '400102274', '400102275', '400102190', '400102198', + '400102161', '400102277', '400102163', '400102278', + '400102282', '400102284', '400102195', 'MA0000008', + 'MA0000004', '929055170', '400102267', '400102235', + '400102236', 'MA0000006', '400102237', '400102238', + '400102239', '400102268', '829416159', '924031058', + '924031081', '822064091', '822066199', '822066200') + +parent_children_mapping = {'400102196': ['400102125', '400102126', '400102130', + '400102161', '400102163', '400102165', + '400102166', '400102167', '400102168', + '400102190', '400102195', '400102198', + '400102246', '400102247', '400102267', + '400102272', '400102274', '400102275', + '400102277', '400102278', '400102282', + '400102284', '400102417', '720002003', + '721001034', '821114025', '822064091', + '822066085', '822996075', '829416061', + '829516004', '911021113', '911021181', + '911021259', '911091054', '911091096', + '911091097', '911251013', '912011009', + '919050006', '924031058', + '924031081'], + '400102282': ['822066026', '822066089', '919010052'], + '400102195': ['822066075', '822066216', + '822066154', '822066101', '822064090', + '822066196', '400102129', '822066217', + '822066160', '822066215', '913041045', + '913011009', '911011057', '822064035', + '925011006', '911091041', '913051040', + '911021112', '911021166', '825006003', + '912041005', '911011014', '911011009', + '911021144', '911021001', '913011016', + '929055170', '913011010', '911021035', + '829416065', '712000151', + '712000100'], + '822066075': ['822066157', '822066162', '911261023'], + '822066162': ['822064013'], + '822066196': ['MA0000008'], + '822066160': ['MA0000004'], + '822064035': ['822066065'], + '822064093': ['822066204', '822066205', '822066206', '822066207', '822066208'], + '822066220': ['924031033'], + '822064091': ['822066212', '822064093', '822066220', + '822066200', '912011010', '911021156', + '822066201', '911071027', '913011109', + '911011070', '913011001', '710005021', + '919010055', '720000008', '720000007'], + '400102267': ['400102235', '829416159', '829416077', + '829416079', '911021260', '911021147', + '911251014'], + '400102235': ['400102236', '400102237', '400102238', + '400102239', '400102268', '911021143', + '911021054', '911021055'], + '400102236': ['MA0000006'], + '829416159': ['829416089'], + '400102130': ['400102142'], + '821116004': ['822026004'], + '400102168': ['821116001'], + '821114025': ['911081007', '821116053'], + '400102167': ['821116004']} + + + +model = CadItem("400102196") + +controller = Controller(model) +controller.set_parent_children(parent_children_mapping) +controller.set_red_ids(red_ids) + +root = tk.Tk() +app = App(root, controller) +app.mainloop()