226 lines
7.4 KiB
Python
226 lines
7.4 KiB
Python
import json
|
|
from controller import Controller
|
|
|
|
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"]
|
|
gui_data_keys = [ "asm_id",
|
|
"teilenummer",
|
|
"pdm_kategorie_neu",
|
|
"neuaufbau",
|
|
"lebenszyklus_status_neu",
|
|
"aus_halbzeug_neu",
|
|
"zusatzinfos_text_neu",
|
|
"bezeichnung_sivas", "bezeichnung_neu",
|
|
"beschaffungsart_sivas","beschaffungsart_neu"
|
|
"mengeneinheit_sivas","mengeneinheit_neu"
|
|
"halbzeug_sivas","halbzeug_neu",
|
|
"tos_gruppe_sivas","tos_gruppe_neu"
|
|
# TODO siehe Layout Entwurf svg
|
|
]
|
|
|
|
def __init__(self):
|
|
""" is initalized with its unique id"""
|
|
self.red_ids = {}
|
|
self.parent_children_mapping = {}
|
|
self.data = {}
|
|
self.gui_data = {}
|
|
self.read_only_items = {}
|
|
self.controller = None
|
|
|
|
def set_controller(self, controller):
|
|
self.controller = controller
|
|
|
|
def set_asm_id(self, asm_id):
|
|
self.set_gui_data("asm_id", asm_id)
|
|
def get_asm_id(self):
|
|
return self.get_gui_data("asm_id")
|
|
|
|
def get_current_part_id(self):
|
|
return self.get_gui_data("teilenummer")
|
|
|
|
|
|
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
|
|
|
|
# Methoden um die Verwendbarkeit einzelner Schalter auszugrauen
|
|
def set_read_only_dict(self, data:dict):
|
|
for k,v in data:
|
|
self.set_read_only(k,v)
|
|
def set_read_only(self, key, val):
|
|
if key not in self.gui_data:
|
|
raise Exception("this data can not be set")
|
|
else:
|
|
self.read_only_items[key] = val
|
|
def get_read_only(self, key):
|
|
return self.read_only_items[key]
|
|
def get_all_read_only_data(self):
|
|
return self.read_only_items
|
|
|
|
# Daten zum Impfen merken
|
|
def set_data_dict(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):
|
|
""" gibt ein Datenstück zurück """
|
|
return self.data[key]
|
|
def get_all_data(self):
|
|
""" gibt alle enthaltenen Daten zurück """
|
|
return self.data
|
|
|
|
# Daten die in der GUI gespeichert werden sollen
|
|
def set_gui_dict(self, data:dict):
|
|
""" setzt die Daten der GUI """
|
|
for k,v in data.items():
|
|
self.set_gui_data(k,v)
|
|
def set_gui_data(self, key, val):
|
|
""" merkt sich ein Datenatom für die GUI """
|
|
if key not in self.gui_data_keys:
|
|
raise Exception("this data can not be set"+ key)
|
|
else:
|
|
self.gui_data[key] = val
|
|
|
|
def get_gui_data(self, key):
|
|
return self.gui_data[key]
|
|
def get_all_gui_data(self):
|
|
return self.gui_data
|
|
|
|
def from_json(self, json_str):
|
|
jsonobj = json.loads(json_str)
|
|
|
|
if "gui_data" in jsonobj:
|
|
gui_data = jsonobj["gui_data"]
|
|
self.set_gui_dict(gui_data)
|
|
else:
|
|
raise Exception("no gui_data given in string")
|
|
|
|
if "data" in jsonobj:
|
|
data = jsonobj["data"]
|
|
self.set_data_dict(data)
|
|
else:
|
|
raise Exception("no data given in string")
|
|
|
|
if "parent_children_mapping" in jsonobj:
|
|
parent_children_mapping = jsonobj["parent_children_mapping"]
|
|
self.set_parent_children(parent_children_mapping)
|
|
else:
|
|
raise Exception("no parent_children_mapping given in string")
|
|
if "red_ids" in jsonobj:
|
|
red_ids = jsonobj["red_ids"]
|
|
self.set_red_ids(red_ids)
|
|
|
|
def to_dict(self):
|
|
jsonobj = dict()
|
|
|
|
# die Oberflächendaten
|
|
gui_data = self.get_all_gui_data()
|
|
jsonobj["gui_data"] = gui_data
|
|
|
|
# die Impfdaten
|
|
data = self.get_all_data()
|
|
jsonobj["data"] = data
|
|
|
|
# der Baum
|
|
parent_children_mapping = self.get_parent_children()
|
|
jsonobj["parent_children_mapping"] = parent_children_mapping
|
|
|
|
# die ids der nicht migrierten Dateien
|
|
red_ids = self.get_red_ids()
|
|
jsonobj["red_ids"] = red_ids
|
|
return jsonobj
|
|
def to_json(self):
|
|
obj = self.to_dict()
|
|
return json.dumps(obj)
|
|
|
|
def load(self, path):
|
|
try:
|
|
with open(path, 'r') as f:
|
|
self.from_json(json.load(f))
|
|
except Exception:
|
|
raise Exception("guid_data, data, parent_children_mapping or red_ids not found")
|
|
|
|
def save(self, path):
|
|
with open(path, 'w') as f:
|
|
json.dump(self.to_dict(), f)
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
|
|
|