See #2887. Fix bad UI design that could lead to objects created with the unintended context.

This commit is contained in:
Dion Moult
2023-03-23 10:44:57 +11:00
parent 2003bfe4fe
commit 416efa4f14
5 changed files with 39 additions and 13 deletions
@@ -35,6 +35,7 @@ classes = (
operator.SwitchRepresentation, operator.SwitchRepresentation,
operator.UpdateParametricRepresentation, operator.UpdateParametricRepresentation,
operator.UpdateRepresentation, operator.UpdateRepresentation,
prop.BIMObjectGeometryProperties,
prop.BIMGeometryProperties, prop.BIMGeometryProperties,
ui.BIM_PT_derived_placements, ui.BIM_PT_derived_placements,
ui.BIM_PT_representations, ui.BIM_PT_representations,
@@ -48,6 +49,7 @@ addon_keymaps = []
def register(): def register():
bpy.types.Object.BIMGeometryProperties = bpy.props.PointerProperty(type=prop.BIMObjectGeometryProperties)
bpy.types.Scene.BIMGeometryProperties = bpy.props.PointerProperty(type=prop.BIMGeometryProperties) bpy.types.Scene.BIMGeometryProperties = bpy.props.PointerProperty(type=prop.BIMGeometryProperties)
bpy.types.OBJECT_PT_transform.append(ui.BIM_PT_transform) bpy.types.OBJECT_PT_transform.append(ui.BIM_PT_transform)
bpy.types.VIEW3D_MT_object.append(ui.object_menu) bpy.types.VIEW3D_MT_object.append(ui.object_menu)
@@ -71,6 +73,7 @@ def unregister():
bpy.types.VIEW3D_MT_object.remove(ui.object_menu) bpy.types.VIEW3D_MT_object.remove(ui.object_menu)
bpy.types.OBJECT_PT_transform.remove(ui.BIM_PT_transform) bpy.types.OBJECT_PT_transform.remove(ui.BIM_PT_transform)
del bpy.types.Scene.BIMGeometryProperties del bpy.types.Scene.BIMGeometryProperties
del bpy.types.Object.BIMGeometryProperties
wm = bpy.context.window_manager wm = bpy.context.window_manager
kc = wm.keyconfigs.addon kc = wm.keyconfigs.addon
if kc: if kc:
@@ -35,6 +35,7 @@ class RepresentationsData:
@classmethod @classmethod
def load(cls): def load(cls):
cls.data = {"representations": cls.representations()} cls.data = {"representations": cls.representations()}
cls.data["contexts"] = cls.contexts()
cls.is_loaded = True cls.is_loaded = True
@classmethod @classmethod
@@ -64,6 +65,25 @@ class RepresentationsData:
results.append(data) results.append(data)
return results return results
@classmethod
def contexts(cls):
results = []
for element in tool.Ifc.get().by_type("IfcGeometricRepresentationContext", include_subtypes=False):
results.append((str(element.id()), element.ContextType or "Unnamed", ""))
for element in tool.Ifc.get().by_type("IfcGeometricRepresentationSubContext", include_subtypes=False):
results.append(
(
str(element.id()),
"{}/{}/{}".format(
element.ContextType or "Unnamed",
element.ContextIdentifier or "Unnamed",
element.TargetView or "Unnamed",
),
"",
)
)
return results
class ConnectionsData: class ConnectionsData:
data = {} data = {}
@@ -34,7 +34,6 @@ import blenderbim.bim.handler
from mathutils import Vector from mathutils import Vector
from blenderbim.bim import import_ifc from blenderbim.bim import import_ifc
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.root.prop import get_contexts
class Operator: class Operator:
@@ -60,27 +59,20 @@ class AddRepresentation(bpy.types.Operator, Operator):
bl_idname = "bim.add_representation" bl_idname = "bim.add_representation"
bl_label = "Add Representation" bl_label = "Add Representation"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
context_id: bpy.props.IntProperty()
ifc_representation_class: bpy.props.StringProperty()
profile_set_usage: bpy.props.IntProperty()
def _execute(self, context): def _execute(self, context):
ifc_context = self.context_id ifc_context = int(context.active_object.BIMGeometryProperties.contexts or "0") or None
if not ifc_context and get_contexts(self, context):
ifc_context = int(context.scene.BIMRootProperties.contexts or "0") or None
if ifc_context: if ifc_context:
ifc_context = tool.Ifc.get().by_id(ifc_context) ifc_context = tool.Ifc.get().by_id(ifc_context)
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
core.add_representation( core.add_representation(
tool.Ifc, tool.Ifc,
tool.Geometry, tool.Geometry,
tool.Style, tool.Style,
tool.Surveyor, tool.Surveyor,
obj=obj, obj=context.active_object,
context=ifc_context, context=ifc_context,
ifc_representation_class=self.ifc_representation_class, ifc_representation_class=None,
profile_set_usage=tool.Ifc.get().by_id(self.profile_set_usage) if self.profile_set_usage else None, profile_set_usage=None,
) )
@@ -18,6 +18,7 @@
import bpy import bpy
from blenderbim.bim.prop import StrProperty, Attribute from blenderbim.bim.prop import StrProperty, Attribute
from blenderbim.bim.module.geometry.data import RepresentationsData
from bpy.types import PropertyGroup from bpy.types import PropertyGroup
from bpy.props import ( from bpy.props import (
PointerProperty, PointerProperty,
@@ -31,6 +32,16 @@ from bpy.props import (
) )
def get_contexts(self, context):
if not RepresentationsData.is_loaded:
RepresentationsData.load()
return RepresentationsData.data["contexts"]
class BIMObjectGeometryProperties(PropertyGroup):
contexts: EnumProperty(items=get_contexts, name="Contexts")
class BIMGeometryProperties(PropertyGroup): class BIMGeometryProperties(PropertyGroup):
# Revit workaround # Revit workaround
should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False) should_use_presentation_style_assignment: BoolProperty(name="Force Presentation Style Assignment", default=False)
@@ -58,7 +58,7 @@ class BIM_PT_representations(Panel):
layout.label(text="No representations found") layout.label(text="No representations found")
row = layout.row(align=True) row = layout.row(align=True)
prop_with_search(row, context.scene.BIMRootProperties, "contexts", text="") prop_with_search(row, context.active_object.BIMGeometryProperties, "contexts", text="")
row.operator("bim.add_representation", icon="ADD", text="") row.operator("bim.add_representation", icon="ADD", text="")
for representation in RepresentationsData.data["representations"]: for representation in RepresentationsData.data["representations"]: