From a98a7ac8569506d6b23dc0ee01901a62c5c4d665 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 21 Mar 2025 18:36:50 +0500 Subject: [PATCH] ifcsverchok - add some sockets descriptions, specify types --- src/ifcsverchok/helper.py | 35 ++++++++++++++++++- src/ifcsverchok/nodes/ifc/add.py | 25 ++++++++++--- src/ifcsverchok/nodes/ifc/add_pset.py | 27 +++++++++++--- src/ifcsverchok/nodes/ifc/api.py | 18 ++++++++-- src/ifcsverchok/nodes/ifc/by_guid.py | 9 +++-- src/ifcsverchok/nodes/ifc/create_entity.py | 3 +- src/ifcsverchok/nodes/ifc/create_file.py | 14 ++++++-- src/ifcsverchok/nodes/ifc/create_project.py | 16 ++++++--- .../nodes/ifc/quick_project_setup.py | 10 +++++- src/ifcsverchok/nodes/ifc/read_file.py | 9 +++-- src/ifcsverchok/nodes/ifc/remove.py | 24 +++++++++++-- .../nodes/ifc/select_blender_objects.py | 9 ++++- src/ifcsverchok/nodes/ifc/write_file.py | 21 +++++++++-- 13 files changed, 188 insertions(+), 32 deletions(-) diff --git a/src/ifcsverchok/helper.py b/src/ifcsverchok/helper.py index 61b2b5de45..748afe1081 100644 --- a/src/ifcsverchok/helper.py +++ b/src/ifcsverchok/helper.py @@ -18,8 +18,11 @@ import bpy import ifcopenshell +import sverchok.core.sockets from sverchok.data_structure import zip_long_repeat -from typing import Any +from typing import Any, Union, TypeVar + +T_socket = TypeVar("T_socket", bound=sverchok.core.sockets.SvSocketCommon) ifc_files: dict[str, ifcopenshell.file] = {} @@ -28,6 +31,14 @@ class SvIfcCore: sv_input_names: list[str] def process(self) -> None: + """Process inputs from `self.sv_input_names` and call `process_ifc()`. + + For `process()` inputs are supposed to be double nested. + E.g. file input should have type `list[list[ifcopenshell.file]]`. + + Similarly, outputs should also be double nested, + so they can be easily passed as inputs to other nodes. + """ sv_inputs_nested = [] for name in self.sv_input_names: sv_inputs_nested.append(self.inputs[name].sv_get()) @@ -38,3 +49,25 @@ class SvIfcCore: def process_ifc(self, *args: Any, **kwargs: Any) -> None: raise NotImplementedError + + +def create_socket( + inputs_or_outputs: Union[bpy.types.NodeInputs, bpy.types.NodeOutputs], + name: str, + *, + description: str = "", + data_type: str = "", + prop_name: str = "", + socket_type: type[T_socket] = sverchok.core.sockets.SvStringsSocket, +) -> T_socket: + socket = inputs_or_outputs.new(socket_type.bl_idname, name) + assert isinstance(socket, socket_type) + + if data_type: + data_type = f"Type: `{data_type}`." + description = "\n\n".join(filter(None, [description, data_type])) + socket.description = description + + if prop_name: + socket.prop_name = prop_name + return socket diff --git a/src/ifcsverchok/nodes/ifc/add.py b/src/ifcsverchok/nodes/ifc/add.py index dbb8b84dcc..5aab0da1f1 100644 --- a/src/ifcsverchok/nodes/ifc/add.py +++ b/src/ifcsverchok/nodes/ifc/add.py @@ -19,6 +19,7 @@ import bpy import ifcopenshell import ifcsverchok.helper +import ifcsverchok.helper as helper from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -32,10 +33,26 @@ class SvIfcAdd(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCor entity: StringProperty(name="entity", update=updateNode) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "file").prop_name = "file" - self.inputs.new("SvStringsSocket", "entity").prop_name = "entity" - self.outputs.new("SvStringsSocket", "file") - self.outputs.new("SvStringsSocket", "entity") + helper.create_socket( + self.inputs, + "file", + description="File to add entity to.", + data_type="list[list[ifcopenshell.file]]", + prop_name="file", + ) + helper.create_socket( + self.inputs, + "entity", + description="Entity to add to file.", + data_type="list[list[ifcopenshell.entity_instance]]", + prop_name="entity", + ) + helper.create_socket( + self.outputs, "file", description="File with added entity.", data_type="list[list[ifcopenshell.file]]" + ) + helper.create_socket( + self.outputs, "entity", description="Added entity.", data_type="list[list[ifcopenshell.entity_instance]]" + ) def process(self): self.sv_input_names = ["file", "entity"] diff --git a/src/ifcsverchok/nodes/ifc/add_pset.py b/src/ifcsverchok/nodes/ifc/add_pset.py index 70b92b5f17..4e6f0d7674 100644 --- a/src/ifcsverchok/nodes/ifc/add_pset.py +++ b/src/ifcsverchok/nodes/ifc/add_pset.py @@ -19,10 +19,11 @@ import bpy import ifcopenshell +import sverchok.core.sockets import ifcsverchok.helper +import ifcsverchok.helper as helper from ifcsverchok.ifcstore import SvIfcStore -import bpy import json import ifcopenshell import ifcopenshell.api @@ -52,10 +53,26 @@ class SvIfcAddPset(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIf Elements: StringProperty(name="Element Ids", update=updateNode) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "Name").prop_name = "Name" - self.inputs.new("SvTextSocket", "Properties").prop_name = "Properties" - self.inputs.new("SvStringsSocket", "Elements").prop_name = "Elements" - self.outputs.new("SvStringsSocket", "Entity") + helper.create_socket( + self.inputs, "Name", description="Name of the property set.", data_type="list[list[str]]", prop_name="Name" + ) + helper.create_socket( + self.inputs, + "Properties", + description="Properties in a JSON format.", + data_type="list[list[str]]", + prop_name="Properties", + socket_type=sverchok.core.sockets.SvTextSocket, + ) + helper.create_socket( + self.inputs, "Elements", description="Element Ids.", data_type="list[list[str]]", prop_name="Elements" + ) + helper.create_socket( + self.outputs, + "Entity", + description="Added/edited psets.", + data_type="list[list[ifcopenshell.entity_instance]]]", + ) def draw_buttons(self, context, layout): layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = ( diff --git a/src/ifcsverchok/nodes/ifc/api.py b/src/ifcsverchok/nodes/ifc/api.py index 3e6954952d..af0b8766dd 100644 --- a/src/ifcsverchok/nodes/ifc/api.py +++ b/src/ifcsverchok/nodes/ifc/api.py @@ -19,7 +19,9 @@ import bpy import ifcopenshell import ifcopenshell.api +import sverchok.core.sockets import ifcsverchok.helper +import ifcsverchok.helper as helper from bpy.props import StringProperty, EnumProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -56,8 +58,20 @@ class SvIfcApi(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCor usecase: StringProperty(name="Usecase", update=update_usecase) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "usecase").prop_name = "usecase" - self.outputs.new("SvVerticesSocket", "file") + helper.create_socket( + self.inputs, + "usecase", + description="Usecase to run.", + data_type="list[list[str]]", + prop_name="usecase", + ) + helper.create_socket( + self.outputs, + "file", + description="Use case output.", + data_type="list[Any]", + socket_type=sverchok.core.sockets.SvVerticesSocket, + ) def draw_buttons(self, context, layout): op = layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False) diff --git a/src/ifcsverchok/nodes/ifc/by_guid.py b/src/ifcsverchok/nodes/ifc/by_guid.py index 6957d55331..43bea96c84 100644 --- a/src/ifcsverchok/nodes/ifc/by_guid.py +++ b/src/ifcsverchok/nodes/ifc/by_guid.py @@ -21,6 +21,7 @@ import itertools import bpy import ifcopenshell import ifcsverchok.helper +import ifcsverchok.helper as helper from ifcsverchok.ifcstore import SvIfcStore from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode @@ -37,8 +38,12 @@ class SvIfcByGuid(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfc guids: list[str] def sv_init(self, context): - self.inputs.new("SvStringsSocket", "guid").prop_name = "guid" - self.outputs.new("SvStringsSocket", "Entities") + helper.create_socket( + self.inputs, "guid", description="Entities guids.", data_type="list[list[str]]", prop_name="guid" + ) + helper.create_socket( + self.outputs, "Entities", description="Entities", data_type="list[list[ifcopenshell.entity_instance]]" + ) def draw_buttons(self, context, layout): layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = ( diff --git a/src/ifcsverchok/nodes/ifc/create_entity.py b/src/ifcsverchok/nodes/ifc/create_entity.py index d5794fa12e..0bfb88b786 100644 --- a/src/ifcsverchok/nodes/ifc/create_entity.py +++ b/src/ifcsverchok/nodes/ifc/create_entity.py @@ -24,6 +24,7 @@ import ifcopenshell.api.geometry import ifcopenshell.api.root import ifcopenshell.util.schema import ifcsverchok.helper +import ifcsverchok.helper as helper from ifcsverchok.ifcstore import SvIfcStore from bpy.props import StringProperty, BoolProperty @@ -79,7 +80,7 @@ class SvIfcCreateEntity(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper self.inputs.new("SvStringsSocket", "Representations").prop_name = "Representations" self.inputs.new("SvMatrixSocket", "Locations").is_mandatory = False # self.inputs.new("SvStringsSocket", "Properties").prop_name = "Properties" - self.outputs.new("SvStringsSocket", "Entities") + helper.create_socket(self.outputs, "Entities", description="Created entities ids.", data_type="list[list[int]]") self.node_dict[hash(self)] = {} def draw_buttons(self, context, layout): diff --git a/src/ifcsverchok/nodes/ifc/create_file.py b/src/ifcsverchok/nodes/ifc/create_file.py index f15128d711..50a77a5198 100644 --- a/src/ifcsverchok/nodes/ifc/create_file.py +++ b/src/ifcsverchok/nodes/ifc/create_file.py @@ -20,6 +20,8 @@ import bpy import ifcopenshell import ifcopenshell.guid import ifcsverchok.helper +import ifcsverchok.helper as helper +import sverchok.core.sockets from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -48,8 +50,16 @@ class SvIfcCreateFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.S schema: StringProperty(name="schema", update=updateNode, default="IFC4") def sv_init(self, context): - self.inputs.new("SvStringsSocket", "schema").prop_name = "schema" - self.outputs.new("SvVerticesSocket", "file") + helper.create_socket( + self.inputs, "schema", description="IFC schema to use.", data_type="str", prop_name="schema" + ) + helper.create_socket( + self.outputs, + "file", + description="Opened IFC file.", + data_type="list[list[ifcopenshell.file]]", + socket_type=sverchok.core.sockets.SvVerticesSocket, + ) def draw_buttons(self, context, layout): self.wrapper_tracked_ui_draw_op(layout, "node.sv_ifc_create_file_refresh", icon="FILE_REFRESH", text="Refresh") diff --git a/src/ifcsverchok/nodes/ifc/create_project.py b/src/ifcsverchok/nodes/ifc/create_project.py index c302021ec7..d228267d88 100644 --- a/src/ifcsverchok/nodes/ifc/create_project.py +++ b/src/ifcsverchok/nodes/ifc/create_project.py @@ -20,6 +20,7 @@ import bpy import ifcopenshell import ifcopenshell.api import ifcsverchok.helper +import ifcsverchok.helper as helper from sverchok.node_tree import SverchCustomTreeNode @@ -28,11 +29,16 @@ class SvIfcCreateProject(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helpe bl_label = "IFC Create Project" def sv_init(self, context): - input_socket = self.inputs.new("SvStringsSocket", "file") - input_socket.description = "ifc file to add the project to" - input_socket = self.inputs.new("SvStringsSocket", "project_name") - input_socket.description = "Project name" - self.outputs.new("SvVerticesSocket", "file") + helper.create_socket( + self.inputs, "file", description="IFC file to add the project to", data_type="list[list[ifcopenshell.file]]" + ) + helper.create_socket(self.inputs, "project_name", description="Project name", data_type="list[list[str]]") + helper.create_socket( + self.outputs, + "file", + description="IFC file with the project added", + data_type="list[list[ifcopenshell.file]]", + ) def draw_buttons(self, context, layout): op = layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = ( diff --git a/src/ifcsverchok/nodes/ifc/quick_project_setup.py b/src/ifcsverchok/nodes/ifc/quick_project_setup.py index b06b07d97d..49c621d8ba 100644 --- a/src/ifcsverchok/nodes/ifc/quick_project_setup.py +++ b/src/ifcsverchok/nodes/ifc/quick_project_setup.py @@ -20,7 +20,9 @@ from email.mime import application import bpy import ifcopenshell +import sverchok.core.sockets import ifcsverchok.helper +import ifcsverchok.helper as helper from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -57,7 +59,13 @@ class SvIfcQuickProjectSetup(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h input_socket.description = "Project GlobalId" input_socket = self.inputs.new("SvStringsSocket", "project_name") input_socket.description = "Project name" - self.outputs.new("SvVerticesSocket", "file") + helper.create_socket( + self.outputs, + "file", + description="New IFC file with the project added.", + data_type="list[list[ifcopenshell.file]]", + socket_type=sverchok.core.sockets.SvVerticesSocket, + ) def draw_buttons(self, context, layout): op = layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = ( diff --git a/src/ifcsverchok/nodes/ifc/read_file.py b/src/ifcsverchok/nodes/ifc/read_file.py index 2a772bd787..ab754d7278 100644 --- a/src/ifcsverchok/nodes/ifc/read_file.py +++ b/src/ifcsverchok/nodes/ifc/read_file.py @@ -20,6 +20,7 @@ import bpy import ifcopenshell import ifcopenshell.guid import ifcsverchok.helper +import ifcsverchok.helper as helper from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -32,8 +33,12 @@ class SvIfcReadFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvI path: StringProperty(name="path", update=updateNode) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "path").prop_name = "path" - self.outputs.new("SvVerticesSocket", "file") + helper.create_socket( + self.inputs, "path", description="Path to IFC file.", data_type="list[list[str]]", prop_name="path" + ) + helper.create_socket( + self.outputs, "file", description="Opened IFC file.", data_type="list[list[ifcopenshell.file]]" + ) def process(self): self.sv_input_names = ["path"] diff --git a/src/ifcsverchok/nodes/ifc/remove.py b/src/ifcsverchok/nodes/ifc/remove.py index b7af0f4ccc..2e76d28896 100644 --- a/src/ifcsverchok/nodes/ifc/remove.py +++ b/src/ifcsverchok/nodes/ifc/remove.py @@ -19,6 +19,7 @@ import bpy import ifcopenshell import ifcsverchok.helper +import ifcsverchok.helper as helper from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -32,9 +33,26 @@ class SvIfcRemove(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfc entity: StringProperty(name="entity", update=updateNode) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "file").prop_name = "file" - self.inputs.new("SvStringsSocket", "entity").prop_name = "entity" - self.outputs.new("SvStringsSocket", "file") + helper.create_socket( + self.inputs, + "file", + description="IFC file to remove entity from.", + data_type="list[list[ifcopenshell.file]]", + prop_name="file", + ) + helper.create_socket( + self.inputs, + "entity", + description="Entity to remove from IFC file.", + data_type="list[list[ifcopenshell.entity_instance]]", + prop_name="entity", + ) + helper.create_socket( + self.outputs, + "file", + description="New IFC file with the entity removed.", + data_type="list[list[ifcopenshell.file]]", + ) def process(self): file: ifcopenshell.file diff --git a/src/ifcsverchok/nodes/ifc/select_blender_objects.py b/src/ifcsverchok/nodes/ifc/select_blender_objects.py index ef88f225ac..5067db7ccf 100644 --- a/src/ifcsverchok/nodes/ifc/select_blender_objects.py +++ b/src/ifcsverchok/nodes/ifc/select_blender_objects.py @@ -21,6 +21,7 @@ import ifcopenshell import ifcopenshell.util.selector import bonsai.tool as tool import ifcsverchok.helper +import ifcsverchok.helper as helper from bpy.props import StringProperty from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode @@ -50,7 +51,13 @@ class SvIfcSelectBlenderObjects(bpy.types.Node, SverchCustomTreeNode, ifcsvercho query: StringProperty(name="query", update=updateNode) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "entities").prop_name = "entities" + helper.create_socket( + self.inputs, + "entities", + description="IFC entities to select Bonsai Blender objects for (selects only objects by matching GlobalId).", + data_type="list[list[ifcopenshell.entity_instance]]", + prop_name="entities", + ) def draw_buttons(self, context, layout): self.wrapper_tracked_ui_draw_op( diff --git a/src/ifcsverchok/nodes/ifc/write_file.py b/src/ifcsverchok/nodes/ifc/write_file.py index aac5afbe31..b277ccadf3 100644 --- a/src/ifcsverchok/nodes/ifc/write_file.py +++ b/src/ifcsverchok/nodes/ifc/write_file.py @@ -22,6 +22,7 @@ import ifcopenshell import ifcopenshell.api import ifcopenshell.util.element import ifcsverchok.helper +import ifcsverchok.helper as helper from ifcsverchok.ifcstore import SvIfcStore from bpy.props import StringProperty, BoolProperty from sverchok.node_tree import SverchCustomTreeNode @@ -39,7 +40,9 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv self.process() self.refresh_local = False - refresh_local: BoolProperty(name="Write", description="Write to file", update=refresh_node_local) + refresh_local: BoolProperty( + name="Write", description="Write to file when changed to True.", update=refresh_node_local + ) bl_idname = "SvIfcWriteFile" bl_label = "IFC Write File" @@ -50,8 +53,20 @@ class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.Sv ) def sv_init(self, context): - self.inputs.new("SvStringsSocket", "path").prop_name = "path" - self.outputs.new("SvStringsSocket", "output") + helper.create_socket( + self.inputs, + "path", + description="File path to write to. Can be relative.", + data_type="str", + prop_name="path", + ) + helper.create_socket( + self.outputs, + "output", + description="Node result output message.", + data_type="str", + prop_name="output", + ) def draw_buttons(self, context, layout): row = layout.row(align=True)