Minor code review for #1804.

This commit is contained in:
Dion Moult
2021-10-26 09:29:15 +11:00
parent 47cf2ea29e
commit e5b5403eaa
2 changed files with 20 additions and 15 deletions
+18 -15
View File
@@ -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)
@@ -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"