mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
ifcsverchok - operator to apply graph to Bonsai file
This commit is contained in:
@@ -22,6 +22,7 @@ from . import ui, prop, operator
|
|||||||
classes = (
|
classes = (
|
||||||
operator.DrawSystemArrows,
|
operator.DrawSystemArrows,
|
||||||
operator.GetConnectedSystemElements,
|
operator.GetConnectedSystemElements,
|
||||||
|
operator.IfcSverchokUseBonsaiFile,
|
||||||
operator.ResizeToStorey,
|
operator.ResizeToStorey,
|
||||||
operator.SetOverrideColour,
|
operator.SetOverrideColour,
|
||||||
operator.SnapSpacesTogether,
|
operator.SnapSpacesTogether,
|
||||||
|
|||||||
@@ -348,3 +348,24 @@ class DrawSystemArrows(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return matrix
|
return matrix
|
||||||
|
|
||||||
|
|
||||||
|
class IfcSverchokUseBonsaiFile(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.ifcsverchok_use_bonsai_file"
|
||||||
|
bl_label = "Use Bonsai IFC File"
|
||||||
|
bl_description = "Apply current IfcSverchok tree to the active Bonsai file."
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
import sverchok.node_tree
|
||||||
|
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
if ifc_file is None:
|
||||||
|
self.report({"ERROR"}, "No active IFC file.")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
space_data = context.space_data
|
||||||
|
assert isinstance(space_data, bpy.types.SpaceNodeEditor)
|
||||||
|
node_tree = space_data.node_tree
|
||||||
|
assert isinstance(node_tree, sverchok.node_tree.SverchCustomTree)
|
||||||
|
tool.Model.run_ifcsverchok_graph_on_bonsai_file(node_tree)
|
||||||
|
|||||||
@@ -2669,3 +2669,25 @@ class Model(bonsai.core.tool.Model):
|
|||||||
material.OffsetFromReferenceLine = custom_offset
|
material.OffsetFromReferenceLine = custom_offset
|
||||||
|
|
||||||
cls.recreate_wall(element, wall)
|
cls.recreate_wall(element, wall)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run_ifcsverchok_graph_on_bonsai_file(cls, node_tree: sverchok.node_tree.SverchCustomTree) -> None:
|
||||||
|
from ifcsverchok.ifcstore import SvIfcStore
|
||||||
|
from sverchok.core.update_system import UpdateTree
|
||||||
|
|
||||||
|
# We should be very careful and use bonsai file just for 1 graph update.
|
||||||
|
# To avoid producing duplicated data in non-ephemeral file.
|
||||||
|
SvIfcStore.use_bonsai_file = True
|
||||||
|
try:
|
||||||
|
# The ones below refresh asyncronously, so we're using different method to get results synchronously.
|
||||||
|
# - bpy.ops.node.sverchok_update_context(force_mode=True)
|
||||||
|
# - node_tree.force_update()
|
||||||
|
# TODO: Ideally we should find shape output node and update only it's furtherest children.
|
||||||
|
# Because user might have some nodes just floating around unused.
|
||||||
|
# ` update_tree = UpdateTree.get(node_tree); update_tree.add_outdated(nodes)` can be used for this.
|
||||||
|
UpdateTree.reset_tree(node_tree)
|
||||||
|
nodes_to_update = UpdateTree.main_update(node_tree)
|
||||||
|
# Consuming generator, which triggers the update.
|
||||||
|
list(nodes_to_update)
|
||||||
|
finally:
|
||||||
|
SvIfcStore.use_bonsai_file = False
|
||||||
|
|||||||
@@ -297,11 +297,13 @@ class IFC_PT_write_file_panel(bpy.types.Panel):
|
|||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
ng = context.space_data.node_tree
|
ng = context.space_data.node_tree
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
assert layout
|
||||||
row = layout.split(factor=0.2, align=True)
|
row = layout.split(factor=0.2, align=True)
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row2 = layout.row()
|
row2 = layout.row()
|
||||||
row.operator("ifc.sverchok_update_current", text="IFC Re-run all nodes")
|
row.operator("ifc.sverchok_update_current", text="IFC Re-run all nodes")
|
||||||
row2.operator("ifc.write_file_panel")
|
row2.operator("ifc.write_file_panel")
|
||||||
|
layout.operator("bim.ifcsverchok_use_bonsai_file")
|
||||||
|
|
||||||
|
|
||||||
CLASSES = [IFC_Sv_UpdateCurrent, IFC_Sv_write_file, IFC_PT_write_file_panel]
|
CLASSES = [IFC_Sv_UpdateCurrent, IFC_Sv_write_file, IFC_PT_write_file_panel]
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
|
import bonsai.tool as tool
|
||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
@@ -50,6 +51,8 @@ class SvIfcStore:
|
|||||||
future = []
|
future = []
|
||||||
schema_identifiers = ["IFC4", "IFC2X3"]
|
schema_identifiers = ["IFC4", "IFC2X3"]
|
||||||
|
|
||||||
|
use_bonsai_file = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def purge() -> None:
|
def purge() -> None:
|
||||||
SvIfcStore.path = ""
|
SvIfcStore.path = ""
|
||||||
@@ -95,6 +98,8 @@ class SvIfcStore:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_file() -> ifcopenshell.file:
|
def get_file() -> ifcopenshell.file:
|
||||||
|
if SvIfcStore.use_bonsai_file:
|
||||||
|
return tool.Ifc.get()
|
||||||
if SvIfcStore.file is None:
|
if SvIfcStore.file is None:
|
||||||
SvIfcStore.create_boilerplate()
|
SvIfcStore.create_boilerplate()
|
||||||
return SvIfcStore.file
|
return SvIfcStore.file
|
||||||
|
|||||||
Reference in New Issue
Block a user