cleaned print statements etc

This commit is contained in:
martinaCodes
2022-11-07 18:08:27 +01:00
committed by Dion Moult
parent b09068e1f4
commit 4ae7643874
6 changed files with 17 additions and 113 deletions
@@ -12,7 +12,7 @@ from sverchok.data_structure import updateNode, flatten_data, repeat_last_for_le
class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
bl_idname = "SvIfcAddSpatialElement"
bl_label = "IFC Add Spatial Element"
node_dict2 = {}
node_dict = {}
Names: StringProperty(name="Name(s)", update=updateNode)
IfcClass: StringProperty(name="IFC Class", update=updateNode, default="IfcSpace")
@@ -23,44 +23,29 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
self.inputs.new("SvStringsSocket", "IfcClass").prop_name = "IfcClass"
self.inputs.new("SvStringsSocket", "Elements").prop_name = "Elements"
self.outputs.new("SvStringsSocket", "Entities")
self.node_dict2[hash(self)] = {}
self.node_dict[hash(self)] = {}
def draw_buttons(self, context, layout):
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Ifc entity by type."
def process(self):
print("#"*20, "\n running add_spatial_element PROCESS()... \n", "#"*20,)
print("#"*20, "\n hash(self):", hash(self), "\n", "#"*20,)
try:
print("SvIfcStore.id_map: ", SvIfcStore.id_map)
print("self-node_id: ",self.node_id)
print("#"*20, "\n node_dict2 before before... \n", self.node_dict2, "\n", "#"*20,)
except:
pass
self.sv_input_names = [i.name for i in self.inputs]
if hash(self) not in self.node_dict2:
self.node_dict2[hash(self)] = {} #happens if node is already on canvas when blender loads
if not self.node_dict2[hash(self)]:
self.node_dict2[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
if hash(self) not in self.node_dict:
self.node_dict[hash(self)] = {} #happens if node is already on canvas when blender loads
if not self.node_dict[hash(self)]:
self.node_dict[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
print("#"*20, "\n node_dict2 before... \n", self.node_dict2, "\n", "#"*20,)
if not any(socket.is_linked for socket in self.outputs):
return
edit = False
edit_elements = False
for i in range(len(self.inputs)):
print(f"current node_dict2 iter:{i}: ", self.node_dict2[hash(self)])
input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=True, default =[])
print("current input: ", input)
print("previous input: ", self.node_dict2[hash(self)][self.inputs[i].name])
if isinstance(self.node_dict2[hash(self)][self.inputs[i].name], list) and input != self.node_dict2[hash(self)][self.inputs[i].name]:
if isinstance(self.node_dict[hash(self)][self.inputs[i].name], list) and input != self.node_dict[hash(self)][self.inputs[i].name]:
edit = True
print("Edit = True")
if self.inputs[i].name == "Elements":
edit_elements = True
print("edit_elements = True")
self.node_dict2[hash(self)][self.inputs[i].name] = input.copy()
print("#"*20, "\n node_dict2 after... \n", self.node_dict2,"\n", "#"*20,)
self.node_dict[hash(self)][self.inputs[i].name] = input.copy()
self.names = flatten_data(self.inputs["Names"].sv_get(), target_level=1)
self.ifc_class = flatten_data(self.inputs["IfcClass"].sv_get(), target_level=1)[0]
@@ -69,62 +54,43 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
if not self.elements[0][0]:
raise Exception('Mandatory input "Element(s)" is missing.')
return
print("elements: ", self.elements)
self.file = SvIfcStore.get_file()
self.elements = [[self.file.by_id(step_id) for step_id in element] for element in self.elements]
if "len" not in self.node_dict2[hash(self)]:
self.node_dict2[hash(self)]["len"] = 0
print("len elements: ", len(self.elements), "stored len_elements: ", self.node_dict2[hash(self)]["len"])
print("elements: ", self.elements)
if "len" not in self.node_dict[hash(self)]:
self.node_dict[hash(self)]["len"] = 0
self.names = self.repeat_input_unique(self.names, len(self.elements))
print("Names: ",self.names)
print("IfcClass: ",self.ifc_class)
print("node_dict2: ", self.node_dict2)
if (self.node_id not in SvIfcStore.id_map) or (len(self.elements) != self.node_dict2[hash(self)]["len"]):
print("\nRunning create")
if (self.node_id not in SvIfcStore.id_map) or (len(self.elements) != self.node_dict[hash(self)]["len"]):
self.remove()
elements = self.create()
self.node_dict2[hash(self)]["len"] = len(self.elements)
print("stored len_elements: ", self.node_dict2[hash(self)]["len"])
self.node_dict[hash(self)]["len"] = len(self.elements)
else:
if edit is True:
elements = self.edit(edit_elements)
else:
print("No changes")
elements = SvIfcStore.id_map[self.node_id]
print("\n ##### spatial element results: ", elements)
self.outputs["Entities"].sv_set(elements)
def create(self, index=None):
print("#"*20, "\n running add_spatial_element create()... \n", "#"*20,)
spatial_ids = []
iterator = range(len(self.elements))
if index is not None:
iterator = [index]
for i in iterator:
print("element: ", self.elements[i])
result = ifcopenshell.api.run("root.create_entity", self.file, name=self.names[i], ifc_class=self.ifc_class)
for items in self.elements[i]:
print("items: ", items)
if items.is_a("IfcSpatialElement") or items.is_a("IfcSpatialStructureElement"):
ifcopenshell.api.run("aggregate.assign_object", self.file, product=items, relating_object=result)
else:
ifcopenshell.api.run("spatial.assign_container", self.file, product=items, relating_structure=result)
# SvIfcStore.id_map[result.id()] = self.node_id
SvIfcStore.id_map.setdefault(self.node_id, []).append(result.id())
spatial_ids.append(result.id())
return spatial_ids
def edit(self, edit_elements):
spatial_ids = []
id_map = SvIfcStore.id_map[self.node_id]
id_map_copy = SvIfcStore.id_map[self.node_id].copy()
print("#"*20, "\n running add_spatial_element edit()... \n", "#"*20,)
print("#"*20, "\n id_map:", id_map, "\n", "#"*20,)
for i, element in enumerate(self.elements):
try:
result_id = id_map_copy[i]
@@ -133,57 +99,30 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
spatial_ids.append(id[0])
continue
result = self.file.by_id(result_id)
print("#"*20, "\n result", result, "\n", "#"*20,)
result.Name = self.names[i]
if edit_elements:
subelements = ifcopenshell.util.element.get_decomposition(result)
print("subelements: ", subelements)
subelements = set(subelements)
print("subelements after: ", subelements)
for element in self.elements[i]:
print("\n\n\n","#"*50)
print("\nElement: ", element)
element_set = set([element])
print("\nRESULT: ", result)
print("subelements: ", subelements)
print("elements_set: ", element_set)
for removed_element in subelements - element_set:
# Just realised I don't have a spatial.unassign_container, but if so we'd do it here
print("removed_element: ", removed_element)
if removed_element.is_a("IfcSpatialElement") or removed_element.is_a("IfcSpatialStructureElement"):
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=removed_element, relating_object=result)
else:
# ifcopenshell.api.run("spatial.unassign_container", self.file, product=removed_element, relating_object=result)
self.unassign_container(removed_element)
ifcopenshell.api.run("spatial.unassign_container", self.file, product=removed_element, relating_object=result)
for added_element in element_set - subelements:
print("added_element: ", added_element)
if added_element.is_a("IfcSpatialElement") or added_element.is_a("IfcSpatialStructureElement"):
ifcopenshell.api.run("aggregate.assign_object", self.file, product=added_element, relating_object=result)
else:
ifcopenshell.api.run("spatial.assign_container", self.file, product=added_element, relating_structure=result)
print("assigned container")
spatial_ids.append(result.id())
SvIfcStore.id_map[self.node_id] = spatial_ids
return spatial_ids
def unassign_container(self, product):
for rel in product.ContainedInStructure or []:
related_elements = list(rel.RelatedElements)
related_elements.remove(product)
if related_elements:
rel.RelatedElements = related_elements
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
else:
self.file.remove(rel)
def remove(self):
print("#"*20, "\n running add_spatial_element remove()... \n", "#"*20,)
if self.node_id in SvIfcStore.id_map:
print(SvIfcStore.id_map[self.node_id])
for element_id in SvIfcStore.id_map[self.node_id]:
element = self.file.by_id(element_id)
print("\nremoving element: ", element)
self.file.write("/Users/martina/Documents/GSoC/CodeTests/IfcFileTest_6_11_before_remove.ifc")
ifcopenshell.api.run("root.remove_product", self.file, product=element)
del SvIfcStore.id_map[self.node_id]
@@ -196,7 +135,7 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
def sv_free(self):
try:
del SvIfcStore.id_map[self.node_id]
del self.node_dict2[hash(self)]
del self.node_dict[hash(self)]
print('Node was deleted')
except KeyError or AttributeError:
pass
@@ -142,7 +142,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
bpy.ops.mesh.separate(type='LOOSE')
for obj in bpy.context.selected_objects:
representation = ifcopenshell.api.run("geometry.add_representation", self.file, should_run_listeners=False,blender_object = obj, geometry=obj.data, context = self.get_context())
print("\n", "#"*30, "representation: ", representation)
if not representation:
raise Exception("Couldn't create representation. Possibly wrong context.")
representations_ids.append(representation.id())
@@ -174,7 +173,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
parent = ifcopenshell.util.representation.get_context(self.file, self.context_type)
if not parent:
parent = ifcopenshell.api.run("context.add_context", self.file, context_type=self.context_type)
print("\nParent: ", parent)
context = ifcopenshell.api.run(
"context.add_context",
self.file,
-3
View File
@@ -27,7 +27,6 @@ from sverchok.data_structure import updateNode, flatten_data
from sverchok.utils.handle_blender_data import keep_enum_reference
def get_ifc_products(self, context):
print("#"*20, "\n running get_ifc_products PROCESS()... \n", "#"*20,)
ifc_products = getattr(self, "ifc_products", [])
file = SvIfcStore.get_file()
if not file:
@@ -55,12 +54,10 @@ def get_ifc_products(self, context):
def update_ifc_products(self, context):
print("#"*20, "\n by_type update_ifc_products()... \n", "#"*20,)
if hasattr(self, "ifc_classes"):
self.ifc_classes.clear()
def get_ifc_classes(self, context):
print("#"*20, "\n by_type get_ifc_classes()... \n", "#"*20,)
ifc_classes = getattr(self, "ifc_classes", [])
if ifc_classes:
return self.ifc_classes
@@ -56,8 +56,6 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
def process(self):
print("#"*20, "\n running create_entity3 PROCESS()... \n", "#"*20,)
print("#"*20, "\n hash(self):", hash(self), "\n", "#"*20,)
self.names = flatten_data(self.inputs["Names"].sv_get(), target_level=1)
self.descriptions = flatten_data(self.inputs["Descriptions"].sv_get(), target_level=1)
@@ -73,26 +71,18 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
self.node_dict[hash(self)] = {} #happens if node is already on canvas when blender loads
if not self.node_dict[hash(self)]:
self.node_dict[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
print("node_dict: ", self.node_dict)
if not self.inputs["IfcClass"].sv_get()[0][0]:
raise Exception('Mandatory input "IfcClass" is missing.')
return
edit = False
for i in range(len(self.inputs)):
# if self.sv_input_names[i] == "Locations":
# input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=False, default = [])
input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=True, default =[])
# print("input: ", input)
# print("self.node_dict[hash(self)][self.inputs[i].name]: ", self.node_dict[hash(self)][self.inputs[i].name])
if isinstance(self.node_dict[hash(self)][self.inputs[i].name], list) and input != self.node_dict[hash(self)][self.inputs[i].name]:
edit = True
self.node_dict[hash(self)][self.inputs[i].name] = input.copy()
if self.refresh_local:
edit = True
print("\nrepresentations before convert: ", self.representations)
self.file = SvIfcStore.get_file()
if self.representations[0]:
@@ -105,23 +95,15 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
elif not self.representations[0]:
self.descriptions = self.repeat_input_unique(self.descriptions, len(self.names))
# print("REPRESENTATION: ", self.representations)
print("IfcClass: ", self.ifc_class)
print("Names: ",self.names)
print("Descriptions: ",self.descriptions)
# print("\nrepresentations after convert: ", self.representations)
if self.node_id not in SvIfcStore.id_map:
entities = self.create()
else:
if edit is True:
entities = self.edit()
else:
# entities = self.get_existing_element()
entities = SvIfcStore.id_map[self.node_id]
print("Entities: ", entities)
print("SvIfcStore.id_map: ", SvIfcStore.id_map)
self.outputs["Entities"].sv_set(entities)
@@ -134,15 +116,12 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
try:
entity = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=self.ifc_class, name=self.names[i], description=self.descriptions[i])
try:
print("representations[i]: ", self.representations[i])
if self.representations[i]:
ifcopenshell.api.run("geometry.assign_representation", self.file, product=entity, representation=self.representations[i])
except IndexError:
pass
try:
print("IS INSTANCE MATRIX: ", isinstance(self.locations[i], Matrix), isinstance(self.locations[i], Vector))
if isinstance(self.locations[i], Matrix):
print("LOCATION[i]: ", self.locations[i], type(self.locations[i]))
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=entity, matrix=self.locations[i])
except IndexError:
pass
@@ -175,7 +154,6 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
pass
try:
if isinstance(self.locations[i], Matrix):
print("LOCATION[i]: ", self.locations[i])
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=entity, matrix=self.locations[i])
except IndexError:
pass
+2 -5
View File
@@ -24,9 +24,7 @@ from bpy.props import StringProperty, EnumProperty
from ifcsverchok.ifcstore import SvIfcStore
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.utils.handle_blender_data import keep_enum_reference
@keep_enum_reference
def get_ifc_products(self, context):
ifc_products = getattr(self, "ifc_products", [])
file = SvIfcStore.get_file()
@@ -53,12 +51,12 @@ def get_ifc_products(self, context):
ifc_products[2] = ("IfcSpatialStructureElement", "IfcSpatialStructureElement", "")
return ifc_products
@keep_enum_reference
def update_ifc_products(self, context):
if hasattr(self, "ifc_classes"):
self.ifc_classes.clear()
@keep_enum_reference
def get_ifc_classes(self, context):
ifc_classes = getattr(self, "ifc_classes", [])
if ifc_classes:
@@ -98,7 +96,6 @@ class SvIfcPickIfcClass(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Ifc Class Picker"
def process(self):
# ifc_product = self.inputs["ifc_product"].sv_get()
ifc_class = self.inputs["ifc_class"].sv_get()[0][0]
self.outputs["IfcClass"].sv_set([ifc_class])
+1 -6
View File
@@ -89,13 +89,11 @@ class SvIfcSverchokToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
if not self.node_dict[hash(self)]:
self.node_dict[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
print("node_dict: ", self.node_dict)
edit = False
for i in range(len(self.inputs)):
input = self.inputs[i].sv_get(deepcopy=False)
if isinstance(self.node_dict[hash(self)][self.inputs[i].name], list) and input != self.node_dict[hash(self)][self.inputs[i].name]:
edit = True
print("Edit = True")
self.node_dict[hash(self)][self.inputs[i].name] = input
self.vertices = self.inputs["Vertices"].sv_get(deepcopy=False)
@@ -107,14 +105,13 @@ class SvIfcSverchokToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
representations = self.create(geo_data)
else:
print("edit: ", edit)
if edit is True:
self.edit()
representations = self.create(geo_data)
else:
# representations = self.get_existing_element()
representations = SvIfcStore.id_map[self.node_id]["Representations"]
self.outputs["Representation(s)"].sv_set(representations)
def create(self, geo_data):
@@ -133,7 +130,6 @@ class SvIfcSverchokToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
if not representation:
raise Exception("Couldn't create representation. Possibly wrong context.")
representations_ids.append(representation.id())
print("Representation: ", representation)
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Representations", []).append(representation.id())
return representations_ids
@@ -164,7 +160,6 @@ class SvIfcSverchokToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
target_view=self.target_view,
parent=parent,
)
print("context: ", context)
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Contexts", []).append(context.id())
return context