mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
ifcsverchok - experimenting with shape builder nodes
This commit is contained in:
@@ -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="")
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.guid
|
||||
from sverchok.node_tree import SverchCustomTreeNode
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.element
|
||||
from bpy.props import StringProperty
|
||||
from sverchok.data_structure import flatten_data, updateNode
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with IfcSverchok. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from email.mime import application
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import sverchok.core.sockets
|
||||
from bpy.props import StringProperty
|
||||
from ifcopenshell import template
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# IfcSverchok - IFC Sverchok extension
|
||||
# Copyright (C) 2022 Martina Jakubowska <martina@jakubowska.dk>
|
||||
#
|
||||
# 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 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)
|
||||
@@ -0,0 +1,57 @@
|
||||
# IfcSverchok - IFC Sverchok extension
|
||||
# Copyright (C) 2022 Martina Jakubowska <martina@jakubowska.dk>
|
||||
#
|
||||
# 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
|
||||
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)
|
||||
@@ -0,0 +1,64 @@
|
||||
# IfcSverchok - IFC Sverchok extension
|
||||
# Copyright (C) 2022 Martina Jakubowska <martina@jakubowska.dk>
|
||||
#
|
||||
# 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 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)
|
||||
@@ -0,0 +1,55 @@
|
||||
# IfcSverchok - IFC Sverchok extension
|
||||
# Copyright (C) 2022 Martina Jakubowska <martina@jakubowska.dk>
|
||||
#
|
||||
# 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
|
||||
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)
|
||||
Reference in New Issue
Block a user