new pick_ifc_class node + minor fixes. Add_spatial_element is WIP

This commit is contained in:
martinaCodes
2022-10-31 18:50:17 +01:00
parent c72031fa5d
commit 13a97babd8
5 changed files with 177 additions and 21 deletions
@@ -16,26 +16,33 @@ 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_dict = {}
n_id: StringProperty()
Name: StringProperty(name="Name(s)", update=updateNode)
IfcClass: StringProperty(name="IFC Class", update=updateNode, default="IfcSpace")
Elements: StringProperty(name="Elements", update=updateNode)
len_elements = 0
def sv_init(self, context):
self.inputs.new("SvStringsSocket", "Name(s)").prop_name = "Name"
self.inputs.new("SvStringsSocket", "Names").prop_name = "Name"
self.inputs.new("SvStringsSocket", "IfcClass").prop_name = "IfcClass"
self.inputs.new("SvStringsSocket", "Elements").prop_name = "Elements"
self.outputs.new("SvStringsSocket", "Entities")
self.outputs.new("SvStringsSocket", "file")
def process(self):
print("#"*20, "\n running add_spatial_element PROCESS()... \n", "#"*20,)
print("#"*20, "\n hash(self):", hash(self), "\n", "#"*20,)
if not any(socket.is_linked for socket in self.outputs):
return
self.names = flatten_data(self.inputs["Name(s)"].sv_get(), target_level=1)
self.ifc_class = self.inputs["IfcClass"].sv_get()[0][0]
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]
self.elements = ensure_min_nesting(self.inputs["Elements"].sv_get(), 2)
self.elements = flatten_data(self.elements, target_level=2)
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]
@@ -44,16 +51,35 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
print("elements: ", self.elements)
self.names = self.repeat_input_unique(self.names, len(self.elements))
print("Names: ",self.names)
print("IfcClass: ",self.ifc_class)
self.sv_input_names = [i.name for i in self.inputs]
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("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
if (self.node_id not in SvIfcStore.id_map) or (len(self.elements) != self.len_elements):
print("\nRunning create")
elements = self.create()
self.len_elements = len(self.elements)
else:
elements = self.edit()
if edit is True:
elements = self.edit()
else:
elements = SvIfcStore.id_map[self.node_id]
print("\n ##### results: ", elements)
self.outputs["Entities"].sv_set(elements)
self.outputs["file"].sv_set([self.file])
def create(self):
results = []
@@ -74,10 +100,14 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
def edit(self):
results = []
results_ids = SvIfcStore.id_map[self.node_id]
print("#"*20, "\n running add_spatial_element edit()... \n", "#"*20,)
print("#"*20, "\n results_ids:", results_ids, "\n", "#"*20,)
for result_id in results_ids:
result = self.file.by_id(result_id)
print("#"*20, "\n result", result, "\n", "#"*20,)
subelements = set(ifcopenshell.util.element.get_decomposition(result))
for element in self.elements:
print("\n\n\n","#"*50)
print("\nElement: ", element)
element_set = set(element)
print("\nRESULT: ", result)
@@ -85,7 +115,10 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
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
pass
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:
pass
for added_element in element_set - subelements:
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)