From a99df36351ba8ba97ce66ee9eca35991a3cf7e95 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 21 Oct 2021 19:16:15 +1100 Subject: [PATCH] The type of mapped representations is now shown in the interface, with an asterisk denoting it is mapped. --- .../blenderbim/bim/module/geometry/data.py | 35 +++++++++++++++++++ .../blenderbim/bim/module/geometry/ui.py | 25 ++++++------- .../blenderbim/bim/module/model/pie.py | 2 +- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/geometry/data.py b/src/blenderbim/blenderbim/bim/module/geometry/data.py index 4dfd5d62f9..74413ccb3c 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/data.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/data.py @@ -24,6 +24,41 @@ from mathutils import Vector def refresh(): DerivedPlacementsData.is_loaded = False + RepresentationsData.is_loaded = False + + +class RepresentationsData: + data = {} + is_loaded = False + + @classmethod + def load(cls): + cls.data = {"representations": cls.representations()} + cls.is_loaded = True + + @classmethod + def representations(cls): + results = [] + element = tool.Ifc.get_entity(bpy.context.active_object) + if element.is_a("IfcProduct") and element.Representation: + representations = element.Representation.Representations + elif element.is_a("IfcTypeProduct"): + representations = [rm.MappedRepresentation for rm in element.RepresentationMaps or []] + for representation in representations: + representation_type = representation.RepresentationType + if representation_type == "MappedRepresentation": + representation_type = representation.Items[0].MappingSource.MappedRepresentation.RepresentationType + representation_type += "*" + results.append( + { + "id": representation.id(), + "ContextType": representation.ContextOfItems.ContextType, + "ContextIdentifier": representation.ContextOfItems.ContextIdentifier, + "TargetView": representation.ContextOfItems.TargetView, + "RepresentationType": representation_type, + } + ) + return results class DerivedPlacementsData: diff --git a/src/blenderbim/blenderbim/bim/module/geometry/ui.py b/src/blenderbim/blenderbim/bim/module/geometry/ui.py index 4917de183e..845bb707b3 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/ui.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/ui.py @@ -18,9 +18,8 @@ import bpy from bpy.types import Panel -from ifcopenshell.api.geometry.data import Data from blenderbim.bim.ifc import IfcStore -from blenderbim.bim.module.geometry.data import DerivedPlacementsData +from blenderbim.bim.module.geometry.data import RepresentationsData, DerivedPlacementsData class BIM_PT_representations(Panel): @@ -40,33 +39,31 @@ class BIM_PT_representations(Panel): return IfcStore.get_file() def draw(self, context): + if not RepresentationsData.is_loaded: + RepresentationsData.load() + layout = self.layout props = context.active_object.BIMObjectProperties - if props.ifc_definition_id not in Data.products: - Data.load(IfcStore.get_file(), props.ifc_definition_id) - - representations = Data.products[props.ifc_definition_id] - if not representations: + if not RepresentationsData.data["representations"]: layout.label(text="No representations found") row = layout.row(align=True) row.prop(context.scene.BIMProperties, "contexts", text="") row.operator("bim.add_representation", icon="ADD", text="") - for ifc_definition_id in representations: - representation = Data.representations[ifc_definition_id] + for representation in RepresentationsData.data["representations"]: row = self.layout.row(align=True) - row.label(text=representation["ContextOfItems"]["ContextType"]) - row.label(text=representation["ContextOfItems"]["ContextIdentifier"]) - row.label(text=representation["ContextOfItems"]["TargetView"]) + row.label(text=representation["ContextType"]) + row.label(text=representation["ContextIdentifier"]) + row.label(text=representation["TargetView"]) row.label(text=representation["RepresentationType"]) op = row.operator("bim.switch_representation", icon="OUTLINER_DATA_MESH", text="") op.should_switch_all_meshes = True op.should_reload = True - op.ifc_definition_id = ifc_definition_id + op.ifc_definition_id = representation["id"] op.disable_opening_subtractions = False - row.operator("bim.remove_representation", icon="X", text="").representation_id = ifc_definition_id + row.operator("bim.remove_representation", icon="X", text="").representation_id = representation["id"] class BIM_PT_mesh(Panel): diff --git a/src/blenderbim/blenderbim/bim/module/model/pie.py b/src/blenderbim/blenderbim/bim/module/model/pie.py index 2d4195eb1c..aceb281be3 100644 --- a/src/blenderbim/blenderbim/bim/module/model/pie.py +++ b/src/blenderbim/blenderbim/bim/module/model/pie.py @@ -80,7 +80,7 @@ class VIEW3D_MT_PIE_bim(bpy.types.Menu): def draw(self, context): pie = self.layout.menu_pie() pie.operator("bim.edit_object_placement") - pie.operator("bim.update_representation") + pie.operator("bim.update_representation").ifc_representation_class = "" pie.operator("bim.pie_add_opening") pie.operator("bim.pie_update_container") pie.operator("bim.open_pie_class", text="Assign IFC Class")