From e5b5403eaa0186e4edef117adc0d8f0fc7aa63a6 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 26 Oct 2021 09:29:15 +1100 Subject: [PATCH] Minor code review for #1804. --- src/blenderbim/blenderbim/bim/import_ifc.py | 33 ++++++++++--------- .../bim/module/sequence/operator.py | 2 ++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index c9e2a1fde9..06919f5409 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -278,13 +278,11 @@ class IfcImporter: ] if self.body_contexts: self.settings.set_context_ids(self.body_contexts) - self.non_body_contexts = [ - c.id() - for c in self.file.by_type("IfcGeometricRepresentationSubContext") - if c.ContextIdentifier not in ["Body", "Facetation"] + self.plan_contexts = [ + c.id() for c in self.file.by_type("IfcGeometricRepresentationContext") if c.ContextType == "Plan" ] - if self.non_body_contexts: - self.settings_2d.set_context_ids(self.non_body_contexts) + if self.plan_contexts: + self.settings_2d.set_context_ids(self.plan_contexts) def process_element_filter(self): if self.ifc_import_settings.has_filter: @@ -590,12 +588,16 @@ class IfcImporter: self.create_generic_elements(self.elements) def create_generic_elements(self, elements): - products = self.create_pointclouds(elements) - elements -= products + # Based on my experience in viewing BIM models, representations are prioritised as follows: + # 1. 3D Body, 2. 2D Plans, 3. Point clouds, 4. No representation + # If an element has a representation that doesn't follow 1, 2, or 3, it will not show by default. + # The user can load them later if they want to view them. products = self.create_products(elements) elements -= products products = self.create_curve_products(elements) elements -= products + products = self.create_pointclouds(elements) + elements -= products for element in elements: self.create_product(element) @@ -688,25 +690,25 @@ class IfcImporter: self.link_element(product, obj) def get_pointcloud_representation(self, product): - if hasattr(product, 'Representation') and hasattr(product.Representation, 'Representations'): + if hasattr(product, "Representation") and hasattr(product.Representation, "Representations"): representations = product.Representation.Representations - elif hasattr(product, "RepresentationMaps") and hasattr(product.RepresentationMaps, 'RepresentationMaps'): + elif hasattr(product, "RepresentationMaps") and hasattr(product.RepresentationMaps, "RepresentationMaps"): representations = product.RepresentationMaps else: return None for representation in representations: - if representation.RepresentationType == 'PointCloud': + if representation.RepresentationType == "PointCloud": return representation - elif self.file.schema == "IFC2X3" and representation.RepresentationType == 'GeometricSet': + elif self.file.schema == "IFC2X3" and representation.RepresentationType == "GeometricSet": for item in representation.Items: if not (item.is_a("IfcCartesianPointList") or item.is_a("IfcCartesianPoint")): break else: return representation - elif representation.RepresentationType == 'MappedRepresentation': + elif representation.RepresentationType == "MappedRepresentation": for item in representation.Items: mapped_representation = self.get_pointcloud_representation(item) if mapped_representation is not None: @@ -729,8 +731,9 @@ class IfcImporter: vertex_list = [] for item in representation.Items: if item.is_a("IfcCartesianPointList"): - vertex_list.extend(mathutils.Vector(list(coordinates)) * self.unit_scale - for coordinates in item.CoordList) + vertex_list.extend( + mathutils.Vector(list(coordinates)) * self.unit_scale for coordinates in item.CoordList + ) elif item.is_a("IfcCartesianPoint"): vertex_list.append(mathutils.Vector(list(item.Coordinates)) * self.unit_scale) diff --git a/src/blenderbim/blenderbim/bim/module/sequence/operator.py b/src/blenderbim/blenderbim/bim/module/sequence/operator.py index 0ce3cbb2a4..58c69a7d86 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/operator.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/operator.py @@ -1097,6 +1097,7 @@ class ImportP6(bpy.types.Operator, ImportHelper): print("Import finished in {:.2f} seconds".format(time.time() - start)) return {"FINISHED"} + class ImportP6XER(bpy.types.Operator, ImportHelper): bl_idname = "import_p6xer.bim" bl_label = "Import P6 XER" @@ -1118,6 +1119,7 @@ class ImportP6XER(bpy.types.Operator, ImportHelper): print("Import finished in {:.2f} seconds".format(time.time() - start)) return {"FINISHED"} + class ImportMSP(bpy.types.Operator, ImportHelper): bl_idname = "import_msp.bim" bl_label = "Import MSP"