assembly id hinzugefügt. Linke Frame wereitert. to_json und from_json implementiert. load and save implementiert
This commit is contained in:
+68
-14
@@ -1,10 +1,6 @@
|
||||
import json
|
||||
from controller import Controller
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CadItem():
|
||||
"""
|
||||
This item contains all data for writing all necessary data to the solid edg cad file
|
||||
@@ -34,7 +30,8 @@ class CadItem():
|
||||
"TOS_Trolley_Projekte", "TOS_Trolley_Omniflo",
|
||||
"TOS_Trolley_Spinnerei", "TOS_Trolley_ILS", "Änderungsbeschreibung",
|
||||
"Freigabevermerk", "ZusaetzlicheInformationen"]
|
||||
gui_data_keys = [ "teilenummer",
|
||||
gui_data_keys = [ "asm_id",
|
||||
"teilenummer",
|
||||
"pdm_kategorie_neu",
|
||||
"neuaufbau",
|
||||
"lebenszyklus_status_neu",
|
||||
@@ -48,22 +45,22 @@ class CadItem():
|
||||
# TODO siehe Layout Entwurf svg
|
||||
]
|
||||
|
||||
def __init__(self, asm_id):
|
||||
def __init__(self):
|
||||
""" is initalized with its unique id"""
|
||||
self.set_asm_id(asm_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.asm_id = asm_id
|
||||
def get_current_asm_id(self):
|
||||
return 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")
|
||||
@@ -84,6 +81,20 @@ class CadItem():
|
||||
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:
|
||||
@@ -101,7 +112,7 @@ class CadItem():
|
||||
""" gibt alle enthaltenen Daten zurück """
|
||||
return self.data
|
||||
|
||||
# Daten in der GUI
|
||||
# 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():
|
||||
@@ -118,14 +129,58 @@ class CadItem():
|
||||
def get_all_gui_data(self):
|
||||
return self.gui_data
|
||||
|
||||
def load():
|
||||
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_json(self):
|
||||
jsonobj = dict()
|
||||
|
||||
# die Oberflächendaten
|
||||
gui_data = self.get_gui_dict()
|
||||
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 json.dumps(jsonobj)
|
||||
|
||||
def load(self, path):
|
||||
#try:
|
||||
# with open('data.json', 'r') as f:
|
||||
# self.model.todos = json.load(f)
|
||||
#except Exception:
|
||||
# pass
|
||||
pass
|
||||
def save():
|
||||
def save(self, path):
|
||||
#with open('data.json', 'w') as f:
|
||||
# data = json.dump(self.model.data, f)
|
||||
pass
|
||||
@@ -153,7 +208,6 @@ class CadItemRepository:
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user