mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 11:18:18 +00:00
Support adding a new IfcProjectLibrary from UI
Example - https://imgur.com/a/NUQkvHf
This commit is contained in:
@@ -20,6 +20,7 @@ import bpy
|
|||||||
from . import ui, prop, operator, workspace, gizmo, decorator
|
from . import ui, prop, operator, workspace, gizmo, decorator
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
|
operator.AddProjectLibrary,
|
||||||
operator.AppendEntireLibrary,
|
operator.AppendEntireLibrary,
|
||||||
operator.AppendInspectedLinkedElement,
|
operator.AppendInspectedLinkedElement,
|
||||||
operator.AppendLibraryElement,
|
operator.AppendLibraryElement,
|
||||||
|
|||||||
@@ -138,9 +138,12 @@ class ProjectLibraryData:
|
|||||||
("-", "No Library", "Show elements without library assigned", "", 1),
|
("-", "No Library", "Show elements without library assigned", "", 1),
|
||||||
]
|
]
|
||||||
props = tool.Project.get_project_props()
|
props = tool.Project.get_project_props()
|
||||||
|
libs = []
|
||||||
for i, data in enumerate(cls.data["project_libraries"].values(), len(results)):
|
for i, data in enumerate(cls.data["project_libraries"].values(), len(results)):
|
||||||
icon = "GREASEPENCIL" if props.editing_project_library_id == data["id"] else ""
|
icon = "GREASEPENCIL" if props.editing_project_library_id == data["id"] else ""
|
||||||
results.append((str(data["id"]), data["Name"] or "", data["Description"] or "", icon, i))
|
libs.append((str(data["id"]), data["Name"] or "Unnamed", data["Description"] or "", icon, i))
|
||||||
|
libs.sort(key=lambda x: x[1])
|
||||||
|
results += libs
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import numpy as np
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.api.project
|
import ifcopenshell.api.project
|
||||||
|
import ifcopenshell.api.root
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
import ifcopenshell.ifcopenshell_wrapper as W
|
import ifcopenshell.ifcopenshell_wrapper as W
|
||||||
import ifcopenshell.util.file
|
import ifcopenshell.util.file
|
||||||
@@ -55,7 +56,7 @@ from collections import defaultdict
|
|||||||
from mathutils import Vector, Matrix
|
from mathutils import Vector, Matrix
|
||||||
from bpy.app.handlers import persistent
|
from bpy.app.handlers import persistent
|
||||||
from ifcopenshell.geom import ShapeElementType
|
from ifcopenshell.geom import ShapeElementType
|
||||||
from bonsai.bim.module.project.data import LinksData
|
from bonsai.bim.module.project.data import LinksData, ProjectLibraryData
|
||||||
from bonsai.bim.module.project.decorator import ProjectDecorator, ClippingPlaneDecorator, MeasureDecorator
|
from bonsai.bim.module.project.decorator import ProjectDecorator, ClippingPlaneDecorator, MeasureDecorator
|
||||||
from bonsai.bim.module.model.decorator import PolylineDecorator
|
from bonsai.bim.module.model.decorator import PolylineDecorator
|
||||||
from bonsai.bim.module.model.polyline import PolylineOperator
|
from bonsai.bim.module.model.polyline import PolylineOperator
|
||||||
@@ -639,6 +640,42 @@ class EditProjectLibrary(bpy.types.Operator):
|
|||||||
IfcStore.library_file.redo()
|
IfcStore.library_file.redo()
|
||||||
|
|
||||||
|
|
||||||
|
class AddProjectLibrary(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.add_project_library"
|
||||||
|
bl_label = "Add Project Library"
|
||||||
|
bl_description = "Add new IfcProjectLibrary to the currently selected library."
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
IfcStore.begin_transaction(self)
|
||||||
|
library_file = IfcStore.library_file
|
||||||
|
assert library_file
|
||||||
|
library_file.begin_transaction()
|
||||||
|
result = self._execute(context)
|
||||||
|
library_file.end_transaction()
|
||||||
|
IfcStore.add_transaction_operation(self)
|
||||||
|
IfcStore.end_transaction(self)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
props = tool.Project.get_project_props()
|
||||||
|
library_file = IfcStore.library_file
|
||||||
|
assert library_file
|
||||||
|
project = library_file.by_type("IfcProject")[0]
|
||||||
|
project_library = ifcopenshell.api.root.create_entity(library_file, "IfcProjectLibrary")
|
||||||
|
ifcopenshell.api.project.assign_declaration(library_file, [project_library], project)
|
||||||
|
ProjectLibraryData.load() # Update enum.
|
||||||
|
props.selected_project_library = str(project_library.id())
|
||||||
|
props.is_editing_project_library = True
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def rollback(self, data):
|
||||||
|
IfcStore.library_file.undo()
|
||||||
|
|
||||||
|
def commit(self, data):
|
||||||
|
IfcStore.library_file.redo()
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingHeader(bpy.types.Operator):
|
class EnableEditingHeader(bpy.types.Operator):
|
||||||
bl_idname = "bim.enable_editing_header"
|
bl_idname = "bim.enable_editing_header"
|
||||||
bl_label = "Enable Editing Header"
|
bl_label = "Enable Editing Header"
|
||||||
|
|||||||
@@ -366,15 +366,16 @@ class BIM_PT_project_library(Panel):
|
|||||||
layout = self.layout
|
layout = self.layout
|
||||||
props = self.props
|
props = self.props
|
||||||
|
|
||||||
if not self.props.library_elements:
|
library_file = IfcStore.library_file
|
||||||
row = self.layout.row()
|
assert library_file
|
||||||
row.label(text="No Assets Found", icon="ERROR")
|
|
||||||
return
|
|
||||||
|
|
||||||
library_is_selected = props.selected_project_library not in ("*", "-")
|
library_is_selected = props.selected_project_library not in ("*", "-")
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(self.props, "selected_project_library", text="")
|
row.prop(self.props, "selected_project_library", text="")
|
||||||
|
|
||||||
|
if library_file.schema != "IFC2X3":
|
||||||
|
row.operator("bim.add_project_library", text="", icon="ADD")
|
||||||
|
|
||||||
if library_is_selected and not props.is_editing_project_library:
|
if library_is_selected and not props.is_editing_project_library:
|
||||||
row.prop(props, "is_editing_project_library", text="", icon="GREASEPENCIL")
|
row.prop(props, "is_editing_project_library", text="", icon="GREASEPENCIL")
|
||||||
|
|
||||||
@@ -387,6 +388,11 @@ class BIM_PT_project_library(Panel):
|
|||||||
draw_attributes(props.project_library_attributes, layout)
|
draw_attributes(props.project_library_attributes, layout)
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
|
||||||
|
if not self.props.library_elements:
|
||||||
|
row = self.layout.row()
|
||||||
|
row.label(text="No Assets Found", icon="ERROR")
|
||||||
|
return
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text=self.props.active_library_element or "Top Level Assets")
|
row.label(text=self.props.active_library_element or "Top Level Assets")
|
||||||
if self.props.active_library_element:
|
if self.props.active_library_element:
|
||||||
|
|||||||
@@ -332,7 +332,9 @@ class Project(bonsai.core.tool.Project):
|
|||||||
else:
|
else:
|
||||||
|
|
||||||
def condition(elements: list[ifcopenshell.entity_instance]):
|
def condition(elements: list[ifcopenshell.entity_instance]):
|
||||||
pass
|
# Hacky way to create empty generator.
|
||||||
|
return
|
||||||
|
yield
|
||||||
|
|
||||||
return condition
|
return condition
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user