diff --git a/src/ifcsverchok/__init__.py b/src/ifcsverchok/__init__.py
index 660ea6f707..2c9e37f623 100644
--- a/src/ifcsverchok/__init__.py
+++ b/src/ifcsverchok/__init__.py
@@ -81,7 +81,7 @@ ensure_addons_are_enabled("bonsai", "sverchok")
from sverchok.ui.nodeview_space_menu import add_node_menu
-def nodes_index():
+def nodes_index() -> list[tuple[str, list[tuple[str, str]]]]:
return [
(
"IFC",
@@ -111,15 +111,24 @@ def nodes_index():
("ifc.create_project", "SvIfcCreateProject"),
("ifc.quick_project_setup", "SvIfcQuickProjectSetup"),
],
- )
+ ),
+ (
+ "IFC Shape Builder",
+ [
+ ("ifc.shape_builder.rectangle", "SvIfcSbRectangle"),
+ ("ifc.shape_builder.extrude", "SvIfcSbExtrude"),
+ ("ifc.shape_builder.representation", "SvIfcSbRepresentation"),
+ ("ifc.shape_builder.test", "SvIfcSbTest"),
+ ],
+ ),
]
def make_node_categories() -> list[dict[str, list[str]]]:
- node_categories = [{}]
+ node_categories: list[dict[str, list[str]]] = []
for category, nodes in nodes_index():
nodes = [node_name for idname, node_name in nodes]
- node_categories[0][category] = nodes
+ node_categories.append({category: nodes})
return node_categories
@@ -156,11 +165,11 @@ from ifcsverchok.ifcstore import SvIfcStore
class IFC_Sv_UpdateCurrent(bpy.types.Operator):
"""Update current Sverchok node tree.
- Will reset transient IFC file.
- """
+ Will reset transient IFC file"""
bl_idname = "ifc.sverchok_update_current"
bl_label = "Update Current Node Tree"
+ # bl_description = "Update current Sverchok node tree, resetting transient IFC file."
bl_options = {"REGISTER", "UNDO", "INTERNAL"}
node_group: bpy.props.StringProperty(default="")
diff --git a/src/ifcsverchok/helper.py b/src/ifcsverchok/helper.py
index d20626f365..8f9bda0c97 100644
--- a/src/ifcsverchok/helper.py
+++ b/src/ifcsverchok/helper.py
@@ -16,12 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with IfcSverchok. If not, see .
-from typing import Any, TypeVar, Union
+from typing import Any, Literal, TypeVar, Union
import bpy
import ifcopenshell
import sverchok.core.sockets
-from sverchok.data_structure import zip_long_repeat
+from sverchok.data_structure import flatten_data, zip_long_repeat
+
+from ifcsverchok.ifcstore import SvIfcStore
T_socket = TypeVar("T_socket", bound=sverchok.core.sockets.SvSocketCommon)
@@ -67,6 +69,34 @@ def get_selected_nodes() -> list[bpy.types.Node]:
return [n for n in node_tree.nodes if n.select]
+def get_socket_value(
+ sockets: Union[bpy.types.NodeInputs, bpy.types.NodeOutputs],
+ name: str,
+ *,
+ value_type: Literal["SINGLE_VALUE", "CONTAINER", "FLATTEN"] = "SINGLE_VALUE",
+) -> Any:
+ value = sockets[name].sv_get()
+ if value_type == "FLATTEN":
+ return flatten_data(value)
+ value = value[0]
+ if value_type == "SINGLE_VALUE":
+ return value[0]
+ return value
+
+
+def set_socket_value(
+ sockets: bpy.types.NodeOutputs,
+ name: str,
+ value: Any,
+ *,
+ value_type: Literal["SINGLE_VALUE", "FINAL_VALUE"] = "SINGLE_VALUE",
+) -> None:
+ if value_type == "SINGLE_VALUE":
+ sockets[name].sv_set([[value]])
+ return
+ sockets[name].sv_set(value)
+
+
def create_socket(
inputs_or_outputs: Union[bpy.types.NodeInputs, bpy.types.NodeOutputs],
name: str,
@@ -87,3 +117,7 @@ def create_socket(
if prop_name:
socket.prop_name = prop_name
return socket
+
+
+def get_file() -> ifcopenshell.file:
+ return SvIfcStore.get_file()
diff --git a/src/ifcsverchok/nodes/ifc/create_shape.py b/src/ifcsverchok/nodes/ifc/create_shape.py
index 7b94008952..3238d08663 100644
--- a/src/ifcsverchok/nodes/ifc/create_shape.py
+++ b/src/ifcsverchok/nodes/ifc/create_shape.py
@@ -102,10 +102,8 @@ class SvIfcCreateShape(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.
def register():
- # bpy.utils.register_class(SvIfcCreateShapeRefresh)
bpy.utils.register_class(SvIfcCreateShape)
def unregister():
bpy.utils.unregister_class(SvIfcCreateShape)
- # bpy.utils.unregister_class(SvIfcCreateShapeRefresh)
diff --git a/src/ifcsverchok/nodes/ifc/generate_guid.py b/src/ifcsverchok/nodes/ifc/generate_guid.py
index 26f50e8ae6..759dcbb90e 100644
--- a/src/ifcsverchok/nodes/ifc/generate_guid.py
+++ b/src/ifcsverchok/nodes/ifc/generate_guid.py
@@ -17,7 +17,6 @@
# along with IfcSverchok. If not, see .
import bpy
-import ifcopenshell
import ifcopenshell.guid
from sverchok.node_tree import SverchCustomTreeNode
diff --git a/src/ifcsverchok/nodes/ifc/get_attribute.py b/src/ifcsverchok/nodes/ifc/get_attribute.py
index e809500de3..7f90e742a8 100644
--- a/src/ifcsverchok/nodes/ifc/get_attribute.py
+++ b/src/ifcsverchok/nodes/ifc/get_attribute.py
@@ -17,8 +17,6 @@
# along with IfcSverchok. If not, see .
import bpy
-import ifcopenshell
-import ifcopenshell.util.element
from bpy.props import StringProperty
from sverchok.data_structure import flatten_data, updateNode
from sverchok.node_tree import SverchCustomTreeNode
diff --git a/src/ifcsverchok/nodes/ifc/get_property.py b/src/ifcsverchok/nodes/ifc/get_property.py
index f99dff7aa3..e8af45d606 100644
--- a/src/ifcsverchok/nodes/ifc/get_property.py
+++ b/src/ifcsverchok/nodes/ifc/get_property.py
@@ -17,7 +17,6 @@
# along with IfcSverchok. If not, see .
import bpy
-import ifcopenshell
import ifcopenshell.util.element
from bpy.props import StringProperty
from sverchok.data_structure import flatten_data, updateNode
diff --git a/src/ifcsverchok/nodes/ifc/quick_project_setup.py b/src/ifcsverchok/nodes/ifc/quick_project_setup.py
index 5787e29187..c98e80a5c4 100644
--- a/src/ifcsverchok/nodes/ifc/quick_project_setup.py
+++ b/src/ifcsverchok/nodes/ifc/quick_project_setup.py
@@ -16,11 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with IfcSverchok. If not, see .
-
-from email.mime import application
-
import bpy
-import ifcopenshell
import sverchok.core.sockets
from bpy.props import StringProperty
from ifcopenshell import template
diff --git a/src/ifcsverchok/nodes/ifc/read_entity.py b/src/ifcsverchok/nodes/ifc/read_entity.py
index 38a703151d..454293e7d3 100644
--- a/src/ifcsverchok/nodes/ifc/read_entity.py
+++ b/src/ifcsverchok/nodes/ifc/read_entity.py
@@ -19,7 +19,7 @@
import bpy
import ifcopenshell
from bpy.props import StringProperty
-from sverchok.data_structure import ensure_min_nesting, flatten_data, updateNode
+from sverchok.data_structure import flatten_data, updateNode
from sverchok.node_tree import SverchCustomTreeNode
import ifcsverchok.helper
diff --git a/src/ifcsverchok/nodes/ifc/shape_builder/extrude.py b/src/ifcsverchok/nodes/ifc/shape_builder/extrude.py
new file mode 100644
index 0000000000..f58f8dfd75
--- /dev/null
+++ b/src/ifcsverchok/nodes/ifc/shape_builder/extrude.py
@@ -0,0 +1,76 @@
+# IfcSverchok - IFC Sverchok extension
+# Copyright (C) 2022 Martina Jakubowska
+#
+# 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 .
+
+import bpy
+import ifcopenshell
+import ifcopenshell.api
+import ifcopenshell.api.context
+import ifcopenshell.api.root
+import ifcopenshell.api.unit
+from ifcopenshell.util.shape_builder import ShapeBuilder
+from sverchok.node_tree import SverchCustomTreeNode
+
+import ifcsverchok.helper
+import ifcsverchok.helper as helper
+from ifcsverchok.nodes.ifc.add_pset import flatten_data
+
+
+class SvIfcSbExtrude(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
+ bl_idname = "SvIfcSbExtrude"
+ bl_label = "IFC Extrude"
+
+ def sv_init(self, context):
+ helper.create_socket(
+ self.inputs,
+ "Curve",
+ description="Curve to extrude",
+ data_type="list[list[ifcopenshell.entity_instance]]",
+ )
+ helper.create_socket(
+ self.inputs,
+ "Magnitude",
+ data_type="list[list[float]]",
+ )
+ helper.create_socket(
+ self.inputs,
+ "Position",
+ data_type="list[list[tuple[float, float, float]]]",
+ )
+ helper.create_socket(
+ self.outputs,
+ "Extruded Profile",
+ description="Extruded Profile",
+ data_type="list[list[ifcopenshell.entity_instance]]",
+ )
+
+ def process(self):
+ self.file = helper.get_file()
+ curve: ifcopenshell.entity_instance = helper.get_socket_value(self.inputs, "Curve")
+ magnitude: float = helper.get_socket_value(self.inputs, "Magnitude")
+ position: tuple[float, float, float] = helper.get_socket_value(self.inputs, "Position")
+ builder = ShapeBuilder(self.file)
+ extrude = builder.extrude(curve, magnitude=magnitude, position=position)
+ helper.set_socket_value(self.outputs, "Extruded Profile", extrude)
+
+
+def register():
+ bpy.utils.register_class(SvIfcSbExtrude)
+
+
+def unregister():
+ bpy.utils.unregister_class(SvIfcSbExtrude)
diff --git a/src/ifcsverchok/nodes/ifc/shape_builder/rectangle.py b/src/ifcsverchok/nodes/ifc/shape_builder/rectangle.py
new file mode 100644
index 0000000000..8b9b60c81d
--- /dev/null
+++ b/src/ifcsverchok/nodes/ifc/shape_builder/rectangle.py
@@ -0,0 +1,57 @@
+# IfcSverchok - IFC Sverchok extension
+# Copyright (C) 2022 Martina Jakubowska
+#
+# 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 .
+
+import bpy
+from ifcopenshell.util.shape_builder import ShapeBuilder
+from sverchok.node_tree import SverchCustomTreeNode
+
+import ifcsverchok.helper
+import ifcsverchok.helper as helper
+
+
+class SvIfcSbRectangle(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
+ bl_idname = "SvIfcSbRectangle"
+ bl_label = "IFC Rectangle"
+
+ def sv_init(self, context):
+ helper.create_socket(
+ self.inputs,
+ "Size (2D)",
+ data_type="list[list[tuple[float, float]]]",
+ )
+ helper.create_socket(
+ self.outputs,
+ "Rectangle",
+ description="Rectangle",
+ data_type="list[list[ifcopenshell.entity_instance]]",
+ )
+
+ def process(self):
+ file = helper.get_file()
+ builder = ShapeBuilder(file)
+ size: tuple[float, ...] = helper.get_socket_value(self.inputs, "Size", value_type="CONTAINER")
+ rectangle = builder.rectangle(size=size)
+ helper.set_socket_value(self.outputs, "Rectangle", rectangle)
+
+
+def register():
+ bpy.utils.register_class(SvIfcSbRectangle)
+
+
+def unregister():
+ bpy.utils.unregister_class(SvIfcSbRectangle)
diff --git a/src/ifcsverchok/nodes/ifc/shape_builder/representation.py b/src/ifcsverchok/nodes/ifc/shape_builder/representation.py
new file mode 100644
index 0000000000..c1e8a9eb54
--- /dev/null
+++ b/src/ifcsverchok/nodes/ifc/shape_builder/representation.py
@@ -0,0 +1,64 @@
+# IfcSverchok - IFC Sverchok extension
+# Copyright (C) 2022 Martina Jakubowska
+#
+# 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 .
+
+import bpy
+import ifcopenshell
+import ifcopenshell.util.representation
+from ifcopenshell.util.shape_builder import ShapeBuilder
+from sverchok.node_tree import SverchCustomTreeNode
+
+import ifcsverchok.helper
+import ifcsverchok.helper as helper
+
+
+class SvIfcSbRepresentation(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
+ bl_idname = "SvIfcSbRepresentation"
+ bl_label = "IFC Representation"
+
+ def sv_init(self, context):
+ helper.create_socket(
+ self.inputs,
+ "Representation Item",
+ description="Representation Item",
+ data_type="list[list[ifcopenshell.entity_instance]]",
+ )
+ helper.create_socket(
+ self.outputs,
+ "Shape Representation",
+ description="IfcShapeRepresentation",
+ data_type="list[list[ifcopenshell.entity_instance]]",
+ )
+
+ def process(self):
+ self.file = helper.get_file()
+ representation_items: list[ifcopenshell.entity_instance]
+ representation_items = helper.get_socket_value(self.inputs, "Representation Item", value_type="FLATTEN")
+
+ builder = ShapeBuilder(self.file)
+ context = ifcopenshell.util.representation.get_context(self.file, "Model", "Body", "MODEL_VIEW")
+ assert context is not None
+ representation = builder.get_representation(context, items=representation_items)
+ helper.set_socket_value(self.outputs, "Shape Representation", representation)
+
+
+def register():
+ bpy.utils.register_class(SvIfcSbRepresentation)
+
+
+def unregister():
+ bpy.utils.unregister_class(SvIfcSbRepresentation)
diff --git a/src/ifcsverchok/nodes/ifc/shape_builder/test.py b/src/ifcsverchok/nodes/ifc/shape_builder/test.py
new file mode 100644
index 0000000000..e2fc702721
--- /dev/null
+++ b/src/ifcsverchok/nodes/ifc/shape_builder/test.py
@@ -0,0 +1,55 @@
+# IfcSverchok - IFC Sverchok extension
+# Copyright (C) 2022 Martina Jakubowska
+#
+# 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 .
+
+import bpy
+from sverchok.node_tree import SverchCustomTreeNode
+
+import ifcsverchok.helper
+import ifcsverchok.helper as helper
+
+
+class SvIfcSbTest(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
+ bl_idname = "SvIfcSbTest"
+ bl_label = "IFC Test"
+
+ def sv_init(self, context):
+ helper.create_socket(
+ self.inputs,
+ "Input",
+ )
+ helper.create_socket(
+ self.outputs,
+ "Output",
+ description="Extruded Profile",
+ )
+
+ def process(self):
+ print("test!")
+ self.sv_input_names = ["Input"]
+ super().process()
+
+ def process_ifc(self, input_value: float) -> None:
+ self.outputs["Output"].sv_set([[input_value]])
+
+
+def register():
+ bpy.utils.register_class(SvIfcSbTest)
+
+
+def unregister():
+ bpy.utils.unregister_class(SvIfcSbTest)