mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 20:00:02 +00:00
WIP refactor context UI into its own module. Remove dependency to Blender properties. See #1222.
This commit is contained in:
@@ -5,9 +5,10 @@ bpy = sys.modules.get("bpy")
|
|||||||
|
|
||||||
if bpy is not None:
|
if bpy is not None:
|
||||||
import bpy
|
import bpy
|
||||||
|
import blenderbim.bim.module.bcf as module_bcf
|
||||||
|
import blenderbim.bim.module.context as module_context
|
||||||
import blenderbim.bim.module.covetool as module_covetool
|
import blenderbim.bim.module.covetool as module_covetool
|
||||||
import blenderbim.bim.module.model as module_model
|
import blenderbim.bim.module.model as module_model
|
||||||
import blenderbim.bim.module.bcf as module_bcf
|
|
||||||
from . import ui, prop, operator
|
from . import ui, prop, operator
|
||||||
|
|
||||||
classes = [
|
classes = [
|
||||||
@@ -107,8 +108,6 @@ if bpy is not None:
|
|||||||
operator.FetchLibraryInformation,
|
operator.FetchLibraryInformation,
|
||||||
operator.FetchExternalMaterial,
|
operator.FetchExternalMaterial,
|
||||||
operator.FetchObjectPassport,
|
operator.FetchObjectPassport,
|
||||||
operator.AddSubcontext,
|
|
||||||
operator.RemoveSubcontext,
|
|
||||||
operator.CutSection,
|
operator.CutSection,
|
||||||
operator.AddSheet,
|
operator.AddSheet,
|
||||||
operator.OpenSheet,
|
operator.OpenSheet,
|
||||||
@@ -281,7 +280,6 @@ if bpy is not None:
|
|||||||
ui.BIM_PT_owner,
|
ui.BIM_PT_owner,
|
||||||
ui.BIM_PT_people,
|
ui.BIM_PT_people,
|
||||||
ui.BIM_PT_organisations,
|
ui.BIM_PT_organisations,
|
||||||
ui.BIM_PT_context,
|
|
||||||
ui.BIM_PT_qa,
|
ui.BIM_PT_qa,
|
||||||
ui.BIM_PT_library,
|
ui.BIM_PT_library,
|
||||||
ui.BIM_PT_gis,
|
ui.BIM_PT_gis,
|
||||||
@@ -323,6 +321,7 @@ if bpy is not None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
classes.extend(module_bcf.classes)
|
classes.extend(module_bcf.classes)
|
||||||
|
classes.extend(module_context.classes)
|
||||||
classes.extend(module_covetool.classes)
|
classes.extend(module_covetool.classes)
|
||||||
classes.extend(module_model.classes)
|
classes.extend(module_model.classes)
|
||||||
|
|
||||||
@@ -357,6 +356,7 @@ if bpy is not None:
|
|||||||
bpy.types.TextCurve.BIMTextProperties = bpy.props.PointerProperty(type=prop.BIMTextProperties)
|
bpy.types.TextCurve.BIMTextProperties = bpy.props.PointerProperty(type=prop.BIMTextProperties)
|
||||||
bpy.types.SCENE_PT_unit.append(ui.ifc_units)
|
bpy.types.SCENE_PT_unit.append(ui.ifc_units)
|
||||||
module_bcf.register()
|
module_bcf.register()
|
||||||
|
module_context.register()
|
||||||
module_covetool.register()
|
module_covetool.register()
|
||||||
module_model.register()
|
module_model.register()
|
||||||
bpy.app.handlers.depsgraph_update_pre.append(operator.depsgraph_update_pre_handler)
|
bpy.app.handlers.depsgraph_update_pre.append(operator.depsgraph_update_pre_handler)
|
||||||
@@ -381,5 +381,6 @@ if bpy is not None:
|
|||||||
bpy.types.SCENE_PT_unit.remove(ui.ifc_units)
|
bpy.types.SCENE_PT_unit.remove(ui.ifc_units)
|
||||||
module_model.unregister()
|
module_model.unregister()
|
||||||
module_covetool.unregister()
|
module_covetool.unregister()
|
||||||
|
module_context.unregister()
|
||||||
module_bcf.unregister()
|
module_bcf.unregister()
|
||||||
bpy.app.handlers.depsgraph_update_pre.remove(operator.depsgraph_update_pre_handler)
|
bpy.app.handlers.depsgraph_update_pre.remove(operator.depsgraph_update_pre_handler)
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -2096,50 +2096,6 @@ class FetchObjectPassport(bpy.types.Operator):
|
|||||||
bpy.context.active_object.data = bpy.data.meshes[reference.name]
|
bpy.context.active_object.data = bpy.data.meshes[reference.name]
|
||||||
|
|
||||||
|
|
||||||
class AddSubcontext(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.add_subcontext"
|
|
||||||
bl_label = "Add Subcontext"
|
|
||||||
context: bpy.props.StringProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
self.file = ifc.IfcStore.get_file()
|
|
||||||
import blenderbim.bim.module.context.add_context as add_context
|
|
||||||
usecase = add_context.Usecase(self.file, {
|
|
||||||
"context": self.context.capitalize(),
|
|
||||||
"subcontext": bpy.context.scene.BIMProperties.available_subcontexts,
|
|
||||||
"target_view": bpy.context.scene.BIMProperties.available_target_views,
|
|
||||||
})
|
|
||||||
result = usecase.execute()
|
|
||||||
|
|
||||||
props = bpy.context.scene.BIMProperties
|
|
||||||
subcontext = getattr(bpy.context.scene.BIMProperties, "{}_subcontexts".format(self.context)).add()
|
|
||||||
subcontext.name = bpy.context.scene.BIMProperties.available_subcontexts
|
|
||||||
subcontext.target_view = bpy.context.scene.BIMProperties.available_target_views
|
|
||||||
subcontext.ifc_definition_id = int(result)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveSubcontext(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.remove_subcontext"
|
|
||||||
bl_label = "Remove Context"
|
|
||||||
indexes: bpy.props.StringProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
context, subcontext_index = self.indexes.split("-")
|
|
||||||
subcontext_index = int(subcontext_index)
|
|
||||||
subcontexts = getattr(bpy.context.scene.BIMProperties, "{}_subcontexts".format(context))
|
|
||||||
|
|
||||||
self.file = ifc.IfcStore.get_file()
|
|
||||||
import blenderbim.bim.module.context.remove_context as remove_context
|
|
||||||
usecase = remove_context.Usecase(self.file, {
|
|
||||||
"context": self.file.by_id(subcontexts[subcontext_index].ifc_definition_id)
|
|
||||||
})
|
|
||||||
usecase.execute()
|
|
||||||
|
|
||||||
subcontexts.remove(subcontext_index)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class OpenView(bpy.types.Operator):
|
class OpenView(bpy.types.Operator):
|
||||||
bl_idname = "bim.open_view"
|
bl_idname = "bim.open_view"
|
||||||
bl_label = "Open View"
|
bl_label = "Open View"
|
||||||
|
|||||||
@@ -1465,42 +1465,6 @@ def draw_addresses_ui(layout, parent, parent_type):
|
|||||||
row.prop(address, "messaging_ids")
|
row.prop(address, "messaging_ids")
|
||||||
|
|
||||||
|
|
||||||
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):
|
|
||||||
layout = self.layout
|
|
||||||
|
|
||||||
scene = context.scene
|
|
||||||
props = scene.BIMProperties
|
|
||||||
|
|
||||||
for context in ["model", "plan"]:
|
|
||||||
row = layout.row(align=True)
|
|
||||||
row.prop(props, f"has_{context}_context")
|
|
||||||
|
|
||||||
if not getattr(props, f"has_{context}_context"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
layout.label(text="Geometric Representation Subcontexts:")
|
|
||||||
row = layout.row(align=True)
|
|
||||||
row.prop(props, "available_subcontexts", text="")
|
|
||||||
row.prop(props, "available_target_views", text="")
|
|
||||||
row.operator("bim.add_subcontext", icon="ADD", text="").context = context
|
|
||||||
|
|
||||||
for subcontext_index, subcontext in enumerate(getattr(props, "{}_subcontexts".format(context))):
|
|
||||||
row = layout.row(align=True)
|
|
||||||
row.prop(subcontext, "name", text="")
|
|
||||||
row.prop(subcontext, "target_view", text="")
|
|
||||||
row.operator("bim.remove_subcontext", icon="X", text="").indexes = "{}-{}".format(
|
|
||||||
context, subcontext_index
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_bim(Panel):
|
class BIM_PT_bim(Panel):
|
||||||
bl_label = "Building Information Modeling"
|
bl_label = "Building Information Modeling"
|
||||||
bl_idname = "BIM_PT_bim"
|
bl_idname = "BIM_PT_bim"
|
||||||
|
|||||||
Reference in New Issue
Block a user