mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
new pick_ifc_class node + minor fixes. Add_spatial_element is WIP
This commit is contained in:
@@ -53,6 +53,7 @@ def nodes_index():
|
||||
("ifc.create_entity", "SvIfcCreateEntity"),
|
||||
("ifc.create_shape", "SvIfcCreateShape"),
|
||||
("ifc.read_entity", "SvIfcReadEntity"),
|
||||
("ifc.pick_ifc_class", "SvIfcPickIfcClass"),
|
||||
("ifc.by_id", "SvIfcById"),
|
||||
("ifc.by_guid", "SvIfcByGuid"),
|
||||
("ifc.by_type", "SvIfcByType"),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -23,7 +23,7 @@ import ifcsverchok.helper
|
||||
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.data_structure import updateNode, flatten_data
|
||||
|
||||
|
||||
def get_ifc_products(self, context):
|
||||
@@ -103,17 +103,27 @@ class SvIfcByType(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfc
|
||||
if self.file:
|
||||
self.ifc_products = get_ifc_products(self, bpy.context)
|
||||
self.ifc_classes = get_ifc_classes(self, bpy.context)
|
||||
self.sv_input_names = ["ifc_product", "ifc_class", "custom_ifc_class"]
|
||||
super().process()
|
||||
# self.sv_input_names = ["ifc_product", "ifc_class", "custom_ifc_class"]
|
||||
self.ifc_product = flatten_data(self.inputs["ifc_product"].sv_get(), target_level=1)[0]
|
||||
self.ifc_class = flatten_data(self.inputs["ifc_class"].sv_get(), target_level=1)[0]
|
||||
self.custom_ifc_class = flatten_data(self.inputs["custom_ifc_class"].sv_get(), target_level=1)[0]
|
||||
|
||||
def process_ifc(self, ifc_product, ifc_class, custom_ifc_class):
|
||||
if custom_ifc_class:
|
||||
self.outputs["Entity"].sv_set([self.file.by_type(custom_ifc_class)])
|
||||
elif ifc_class:
|
||||
self.outputs["Entity"].sv_set([self.file.by_type(ifc_class)])
|
||||
# super().process()
|
||||
if self.custom_ifc_class:
|
||||
self.outputs["Entity"].sv_set([self.file.by_type(self.custom_ifc_class)])
|
||||
elif self.ifc_class:
|
||||
self.outputs["Entity"].sv_set([self.file.by_type(self.ifc_class)])
|
||||
else:
|
||||
self.outputs["Entity"].sv_set([])
|
||||
|
||||
# def process_ifc(self, ifc_product, ifc_class, custom_ifc_class):
|
||||
# if custom_ifc_class:
|
||||
# self.outputs["Entity"].sv_set([self.file.by_type(custom_ifc_class)])
|
||||
# elif ifc_class:
|
||||
# self.outputs["Entity"].sv_set([self.file.by_type(ifc_class)])
|
||||
# else:
|
||||
# self.outputs["Entity"].sv_set([])
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(SvIfcByType)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import bpy
|
||||
from mathutils import Matrix
|
||||
from mathutils import Matrix, Vector
|
||||
import ifcopenshell
|
||||
import ifcsverchok.helper
|
||||
from ifcsverchok.ifcstore import SvIfcStore
|
||||
@@ -64,7 +64,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
||||
|
||||
self.names = flatten_data(self.inputs["Names"].sv_get(), target_level=1)
|
||||
self.descriptions = flatten_data(self.inputs["Descriptions"].sv_get(), target_level=1)
|
||||
self.ifc_class = self.inputs["IfcClass"].sv_get()[0][0]
|
||||
self.ifc_class = flatten_data(self.inputs["IfcClass"].sv_get(), target_level=1)[0]
|
||||
self.representations = flatten_data(self.inputs["Representations"].sv_get(), target_level=1)
|
||||
self.locations = flatten_data(self.inputs["Locations"].sv_get(default=[]), target_level=1)
|
||||
self.properties = self.inputs["Properties"].sv_get()
|
||||
@@ -78,7 +78,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
||||
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("Insert IfcClass")
|
||||
raise Exception('Mandatory input "IfcClass" is missing.')
|
||||
return
|
||||
|
||||
edit = False
|
||||
@@ -109,7 +109,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
||||
self.descriptions = self.repeat_input_unique(self.descriptions, len(self.names))
|
||||
|
||||
# print("REPRESENTATION: ", self.representations)
|
||||
# print("IfcClass: ",self.ifc_class)
|
||||
print("IfcClass: ", self.ifc_class)
|
||||
print("Names: ",self.names)
|
||||
print("Descriptions: ",self.descriptions)
|
||||
# print("\nrepresentations after convert: ", self.representations)
|
||||
@@ -144,6 +144,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
||||
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])
|
||||
@@ -177,8 +178,9 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper
|
||||
except IndexError:
|
||||
pass
|
||||
try:
|
||||
print("LOCATION[i]: ", self.locations[i])
|
||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=entity, matrix=self.locations[i])
|
||||
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
|
||||
if entity.is_a() != self.ifc_class:
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
|
||||
# IfcSverchok - IFC Sverchok extension
|
||||
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of IfcSverchok.
|
||||
#
|
||||
# IfcSverchok is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# IfcSverchok is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcsverchok.helper
|
||||
from bpy.props import StringProperty, EnumProperty
|
||||
from ifcsverchok.ifcstore import SvIfcStore
|
||||
from sverchok.node_tree import SverchCustomTreeNode
|
||||
from sverchok.data_structure import updateNode
|
||||
|
||||
|
||||
def get_ifc_products(self, context):
|
||||
ifc_products = getattr(self, "ifc_products", [])
|
||||
file = SvIfcStore.get_file()
|
||||
if not file:
|
||||
return []
|
||||
if ifc_products and file:
|
||||
return ifc_products
|
||||
ifc_products = []
|
||||
ifc_products.extend(
|
||||
[
|
||||
(e, e, "")
|
||||
for e in [
|
||||
"IfcElement",
|
||||
"IfcElementType",
|
||||
"IfcSpatialElement",
|
||||
"IfcGroup",
|
||||
"IfcStructuralItem",
|
||||
"IfcContext",
|
||||
"IfcAnnotation",
|
||||
]
|
||||
]
|
||||
)
|
||||
if file.schema == "IFC2X3":
|
||||
ifc_products[2] = ("IfcSpatialStructureElement", "IfcSpatialStructureElement", "")
|
||||
return ifc_products
|
||||
|
||||
|
||||
def update_ifc_products(self, context):
|
||||
if hasattr(self, "ifc_classes"):
|
||||
self.ifc_classes.clear()
|
||||
|
||||
|
||||
def get_ifc_classes(self, context):
|
||||
ifc_classes = getattr(self, "ifc_classes", [])
|
||||
if ifc_classes:
|
||||
return self.ifc_classes
|
||||
file = SvIfcStore.get_file()
|
||||
if not file:
|
||||
return []
|
||||
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(file.schema)
|
||||
declaration = schema.declaration_by_name(self.ifc_product)
|
||||
|
||||
def get_classes(declaration):
|
||||
results = []
|
||||
if not declaration.is_abstract():
|
||||
results.append(declaration.name())
|
||||
for subtype in declaration.subtypes():
|
||||
results.extend(get_classes(subtype))
|
||||
return results
|
||||
|
||||
classes = get_classes(declaration)
|
||||
ifc_classes.extend([(c, c, "") for c in sorted(classes)])
|
||||
return ifc_classes
|
||||
|
||||
|
||||
class SvIfcPickIfcClass(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
|
||||
bl_idname = "SvIfcPickIfcClass"
|
||||
bl_label = "IFC Class Picker"
|
||||
ifc_product: EnumProperty(items=get_ifc_products, name="IfcProduct", description="Pick an IfcProduct from drop-down.", update=update_ifc_products)
|
||||
ifc_class: EnumProperty(items=get_ifc_classes, name="IfcClass", description="Pick an IfcClass from drop-down.", update=updateNode)
|
||||
|
||||
def sv_init(self, context):
|
||||
self.inputs.new("SvStringsSocket", "ifc_product").prop_name = "ifc_product"
|
||||
self.inputs.new("SvStringsSocket", "ifc_class").prop_name = "ifc_class"
|
||||
self.outputs.new("SvStringsSocket", "IfcClass")
|
||||
self.width = 200
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
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])
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(SvIfcPickIfcClass)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_class(SvIfcPickIfcClass)
|
||||
Reference in New Issue
Block a user