Editiing arbitrary profile without enabling editing profile

It was a bit confusing UX since when you finish editing arbitrary profile path the data is already saved in ifc but you were still in editing profile properties
This commit is contained in:
Andrej730
2023-07-03 15:54:51 +05:00
parent 9864f7d19e
commit 1b39f243eb
3 changed files with 24 additions and 15 deletions
@@ -131,14 +131,15 @@ class EnableEditingArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator):
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
def _execute(self, context): def _execute(self, context):
for obj in context.selected_objects:
obj.select_set(False)
props = context.scene.BIMProfileProperties props = context.scene.BIMProfileProperties
profile = tool.Ifc.get().by_id(props.active_profile_id) active_profile = props.profiles[props.active_profile_index]
profile_id = active_profile.ifc_definition_id
props.active_arbitrary_profile_id = profile_id
profile = tool.Ifc.get().by_id(profile_id)
obj = tool.Model.import_profile(profile) obj = tool.Model.import_profile(profile)
tool.Ifc.link(profile, obj) tool.Ifc.link(profile, obj)
bpy.context.scene.collection.objects.link(obj) bpy.context.scene.collection.objects.link(obj)
bpy.context.view_layer.objects.active = obj tool.Blender.select_and_activate_single_object(context, obj)
bpy.ops.object.mode_set(mode="EDIT") bpy.ops.object.mode_set(mode="EDIT")
ProfileDecorator.install(context, exit_edit_mode_callback=lambda: disable_editing_arbitrary_profile(context)) ProfileDecorator.install(context, exit_edit_mode_callback=lambda: disable_editing_arbitrary_profile(context))
bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool") bpy.ops.wm.tool_set_by_id(tool.Blender.get_viewport_context(), name="bim.cad_tool")
@@ -153,6 +154,8 @@ def disable_editing_arbitrary_profile(context):
bpy.data.objects.remove(obj) bpy.data.objects.remove(obj)
bpy.data.meshes.remove(profile_mesh) bpy.data.meshes.remove(profile_mesh)
props = context.scene.BIMProfileProperties
props.active_arbitrary_profile_id = 0
# need to update profile manager ui # need to update profile manager ui
# if this was called from decorator # if this was called from decorator
refresh() refresh()
@@ -174,7 +177,7 @@ class EditArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
props = context.scene.BIMProfileProperties props = context.scene.BIMProfileProperties
old_profile = tool.Ifc.get().by_id(props.active_profile_id) old_profile = tool.Ifc.get().by_id(props.active_arbitrary_profile_id)
obj = context.active_object obj = context.active_object
@@ -194,6 +197,7 @@ class EditArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.object.mode_set(mode="EDIT") bpy.ops.object.mode_set(mode="EDIT")
return return
prev_profile_id = profile.id()
profile_mesh = obj.data profile_mesh = obj.data
bpy.data.objects.remove(obj) bpy.data.objects.remove(obj)
bpy.data.meshes.remove(profile_mesh) bpy.data.meshes.remove(profile_mesh)
@@ -204,6 +208,8 @@ class EditArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator):
ifcopenshell.util.element.replace_attribute(inverse, old_profile, profile) ifcopenshell.util.element.replace_attribute(inverse, old_profile, profile)
ifcopenshell.util.element.remove_deep2(tool.Ifc.get(), old_profile) ifcopenshell.util.element.remove_deep2(tool.Ifc.get(), old_profile)
bpy.ops.bim.load_profiles() bpy.ops.bim.load_profiles()
props.active_profile_id = profile.id() if props.active_profile_id == prev_profile_id:
props.active_profile_id = profile.id()
props.active_arbitrary_profile_id = 0
model_profile.DumbProfileRegenerator().regenerate_from_profile_def(profile) model_profile.DumbProfileRegenerator().regenerate_from_profile_def(profile)
@@ -54,6 +54,7 @@ class BIMProfileProperties(PropertyGroup):
profiles: CollectionProperty(name="Profiles", type=Profile) profiles: CollectionProperty(name="Profiles", type=Profile)
active_profile_index: IntProperty(name="Active Profile Index") active_profile_index: IntProperty(name="Active Profile Index")
active_profile_id: IntProperty(name="Active Profile Id") active_profile_id: IntProperty(name="Active Profile Id")
active_arbitrary_profile_id: IntProperty(name="Active Arbitrary Profile Id")
profile_attributes: CollectionProperty(name="Profile Attributes", type=Attribute) profile_attributes: CollectionProperty(name="Profile Attributes", type=Attribute)
profile_classes: EnumProperty(items=get_profile_classes, name="Profile Classes") profile_classes: EnumProperty(items=get_profile_classes, name="Profile Classes")
@@ -42,10 +42,12 @@ class BIM_PT_profiles(Panel):
ProfileData.load() ProfileData.load()
self.props = context.scene.BIMProfileProperties self.props = context.scene.BIMProfileProperties
active_profile = None
if self.props.is_editing and self.props.profiles and self.props.active_profile_index < len(self.props.profiles): if self.props.is_editing and self.props.profiles and self.props.active_profile_index < len(self.props.profiles):
preview_collection = ProfileData.preview_collection preview_collection = ProfileData.preview_collection
box = self.layout.box() box = self.layout.box()
profile_id = self.props.profiles[self.props.active_profile_index].ifc_definition_id active_profile = self.props.profiles[self.props.active_profile_index]
profile_id = active_profile.ifc_definition_id
profile_id_str = str(profile_id) profile_id_str = str(profile_id)
if profile_id_str in preview_collection: if profile_id_str in preview_collection:
preview_image = preview_collection[profile_id_str] preview_image = preview_collection[profile_id_str]
@@ -77,19 +79,19 @@ class BIM_PT_profiles(Panel):
self.props, self.props,
"active_profile_index", "active_profile_index",
) )
if active_profile and active_profile.ifc_class == "IfcArbitraryClosedProfileDef":
if self.props.active_arbitrary_profile_id:
row = self.layout.row(align=True)
row.operator("bim.edit_arbitrary_profile", text="Save Arbitrary Profile", icon="CHECKMARK")
row.operator("bim.disable_editing_arbitrary_profile", text="", icon="CANCEL")
else:
row = self.layout.row()
row.operator("bim.enable_editing_arbitrary_profile", text="Edit Arbitrary Profile", icon="GREASEPENCIL")
if self.props.active_profile_id: if self.props.active_profile_id:
self.draw_editable_ui(context) self.draw_editable_ui(context)
def draw_editable_ui(self, context): def draw_editable_ui(self, context):
if ProfileData.data["is_arbitrary_profile"]:
if ProfileData.data["is_editing_arbitrary_profile"]:
row = self.layout.row(align=True)
row.operator("bim.edit_arbitrary_profile", text="Save Profile", icon="CHECKMARK")
row.operator("bim.disable_editing_arbitrary_profile", text="", icon="CANCEL")
else:
row = self.layout.row()
row.operator("bim.enable_editing_arbitrary_profile", text="Edit Profile", icon="GREASEPENCIL")
blenderbim.bim.helper.draw_attributes(self.props.profile_attributes, self.layout) blenderbim.bim.helper.draw_attributes(self.props.profile_attributes, self.layout)