mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 02:31:09 +00:00
WIP refactor context UI into its own module. Remove dependency to Blender properties. See #1222.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import bpy
|
||||
from . import ui, operator
|
||||
|
||||
classes = (
|
||||
operator.AddSubcontext,
|
||||
operator.RemoveSubcontext,
|
||||
ui.BIM_PT_context,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
pass
|
||||
|
||||
|
||||
def unregister():
|
||||
pass
|
||||
@@ -0,0 +1,30 @@
|
||||
import blenderbim.bim.ifc
|
||||
|
||||
is_loaded = False
|
||||
|
||||
class Data:
|
||||
is_loaded = False
|
||||
contexts = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
file = blenderbim.bim.ifc.IfcStore.get_file()
|
||||
if not file:
|
||||
return
|
||||
cls.contexts = {}
|
||||
for context in file.by_type("IfcGeometricRepresentationContext", include_subtypes=False):
|
||||
subcontexts = {}
|
||||
# See bug #1224 for why we don't use HasSubContexts
|
||||
for subcontext in file.by_type("IfcGeometricRepresentationSubContext"):
|
||||
if subcontext.ParentContext != context:
|
||||
continue
|
||||
subcontexts[int(subcontext.id())] = {
|
||||
"ContextType": subcontext.ContextType,
|
||||
"ContextIdentifier": subcontext.ContextIdentifier,
|
||||
"TargetView": subcontext.TargetView,
|
||||
}
|
||||
cls.contexts[int(context.id())] = {
|
||||
"ContextType": context.ContextType,
|
||||
"HasSubContexts": subcontexts
|
||||
}
|
||||
cls.is_loaded = True
|
||||
@@ -0,0 +1,37 @@
|
||||
import bpy
|
||||
import blenderbim.bim.ifc
|
||||
import blenderbim.bim.module.context.add_context as add_context
|
||||
import blenderbim.bim.module.context.remove_context as remove_context
|
||||
from blenderbim.bim.module.context.data import Data
|
||||
|
||||
class AddSubcontext(bpy.types.Operator):
|
||||
bl_idname = "bim.add_subcontext"
|
||||
bl_label = "Add Subcontext"
|
||||
|
||||
def execute(self, context):
|
||||
self.file = blenderbim.bim.ifc.IfcStore.get_file()
|
||||
usecase = add_context.Usecase(self.file, {
|
||||
"context": bpy.context.scene.BIMProperties.available_contexts,
|
||||
"subcontext": bpy.context.scene.BIMProperties.available_subcontexts,
|
||||
"target_view": bpy.context.scene.BIMProperties.available_target_views,
|
||||
})
|
||||
result = usecase.execute()
|
||||
|
||||
Data.load()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveSubcontext(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_subcontext"
|
||||
bl_label = "Remove Context"
|
||||
ifc_definition_id: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.file = blenderbim.bim.ifc.IfcStore.get_file()
|
||||
usecase = remove_context.Usecase(self.file, {
|
||||
"context": self.file.by_id(self.ifc_definition_id)
|
||||
})
|
||||
usecase.execute()
|
||||
|
||||
Data.load()
|
||||
return {"FINISHED"}
|
||||
@@ -0,0 +1,35 @@
|
||||
from bpy.types import Panel
|
||||
from blenderbim.bim.module.context.data import Data
|
||||
|
||||
class BIM_PT_context(Panel):
|
||||
bl_label = "IFC Geometric Representation Contexts"
|
||||
bl_idname = "BIM_PT_context"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "scene"
|
||||
|
||||
def draw(self, context):
|
||||
if not Data.is_loaded:
|
||||
Data.load()
|
||||
|
||||
layout = self.layout
|
||||
props = context.scene.BIMProperties
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.prop(props, "available_contexts", text="")
|
||||
row.prop(props, "available_subcontexts", text="")
|
||||
row.prop(props, "available_target_views", text="")
|
||||
row.operator("bim.add_subcontext", icon="ADD", text="")
|
||||
|
||||
for ifc_definition_id, context in Data.contexts.items():
|
||||
box = self.layout.box()
|
||||
row = box.row(align=True)
|
||||
row.label(text=context["ContextType"])
|
||||
row.operator("bim.remove_subcontext", icon="X", text="").ifc_definition_id = ifc_definition_id
|
||||
for ifc_definition_id2, subcontext in context["HasSubContexts"].items():
|
||||
row = box.row(align=True)
|
||||
row.label(text=subcontext["ContextType"])
|
||||
row.label(text=subcontext["ContextIdentifier"])
|
||||
row.label(text=subcontext["TargetView"])
|
||||
row.operator("bim.remove_subcontext", icon="X", text="").ifc_definition_id = ifc_definition_id2
|
||||
Reference in New Issue
Block a user