mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
ifcsverchok - add some sockets descriptions, specify types
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user