mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Minor code review for #1804.
This commit is contained in:
@@ -278,13 +278,11 @@ class IfcImporter:
|
|||||||
]
|
]
|
||||||
if self.body_contexts:
|
if self.body_contexts:
|
||||||
self.settings.set_context_ids(self.body_contexts)
|
self.settings.set_context_ids(self.body_contexts)
|
||||||
self.non_body_contexts = [
|
self.plan_contexts = [
|
||||||
c.id()
|
c.id() for c in self.file.by_type("IfcGeometricRepresentationContext") if c.ContextType == "Plan"
|
||||||
for c in self.file.by_type("IfcGeometricRepresentationSubContext")
|
|
||||||
if c.ContextIdentifier not in ["Body", "Facetation"]
|
|
||||||
]
|
]
|
||||||
if self.non_body_contexts:
|
if self.plan_contexts:
|
||||||
self.settings_2d.set_context_ids(self.non_body_contexts)
|
self.settings_2d.set_context_ids(self.plan_contexts)
|
||||||
|
|
||||||
def process_element_filter(self):
|
def process_element_filter(self):
|
||||||
if self.ifc_import_settings.has_filter:
|
if self.ifc_import_settings.has_filter:
|
||||||
@@ -590,12 +588,16 @@ class IfcImporter:
|
|||||||
self.create_generic_elements(self.elements)
|
self.create_generic_elements(self.elements)
|
||||||
|
|
||||||
def create_generic_elements(self, elements):
|
def create_generic_elements(self, elements):
|
||||||
products = self.create_pointclouds(elements)
|
# Based on my experience in viewing BIM models, representations are prioritised as follows:
|
||||||
elements -= products
|
# 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)
|
products = self.create_products(elements)
|
||||||
elements -= products
|
elements -= products
|
||||||
products = self.create_curve_products(elements)
|
products = self.create_curve_products(elements)
|
||||||
elements -= products
|
elements -= products
|
||||||
|
products = self.create_pointclouds(elements)
|
||||||
|
elements -= products
|
||||||
for element in elements:
|
for element in elements:
|
||||||
self.create_product(element)
|
self.create_product(element)
|
||||||
|
|
||||||
@@ -688,25 +690,25 @@ class IfcImporter:
|
|||||||
self.link_element(product, obj)
|
self.link_element(product, obj)
|
||||||
|
|
||||||
def get_pointcloud_representation(self, product):
|
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
|
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
|
representations = product.RepresentationMaps
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for representation in representations:
|
for representation in representations:
|
||||||
if representation.RepresentationType == 'PointCloud':
|
if representation.RepresentationType == "PointCloud":
|
||||||
return representation
|
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:
|
for item in representation.Items:
|
||||||
if not (item.is_a("IfcCartesianPointList") or item.is_a("IfcCartesianPoint")):
|
if not (item.is_a("IfcCartesianPointList") or item.is_a("IfcCartesianPoint")):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
elif representation.RepresentationType == 'MappedRepresentation':
|
elif representation.RepresentationType == "MappedRepresentation":
|
||||||
for item in representation.Items:
|
for item in representation.Items:
|
||||||
mapped_representation = self.get_pointcloud_representation(item)
|
mapped_representation = self.get_pointcloud_representation(item)
|
||||||
if mapped_representation is not None:
|
if mapped_representation is not None:
|
||||||
@@ -729,8 +731,9 @@ class IfcImporter:
|
|||||||
vertex_list = []
|
vertex_list = []
|
||||||
for item in representation.Items:
|
for item in representation.Items:
|
||||||
if item.is_a("IfcCartesianPointList"):
|
if item.is_a("IfcCartesianPointList"):
|
||||||
vertex_list.extend(mathutils.Vector(list(coordinates)) * self.unit_scale
|
vertex_list.extend(
|
||||||
for coordinates in item.CoordList)
|
mathutils.Vector(list(coordinates)) * self.unit_scale for coordinates in item.CoordList
|
||||||
|
)
|
||||||
elif item.is_a("IfcCartesianPoint"):
|
elif item.is_a("IfcCartesianPoint"):
|
||||||
vertex_list.append(mathutils.Vector(list(item.Coordinates)) * self.unit_scale)
|
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))
|
print("Import finished in {:.2f} seconds".format(time.time() - start))
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ImportP6XER(bpy.types.Operator, ImportHelper):
|
class ImportP6XER(bpy.types.Operator, ImportHelper):
|
||||||
bl_idname = "import_p6xer.bim"
|
bl_idname = "import_p6xer.bim"
|
||||||
bl_label = "Import P6 XER"
|
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))
|
print("Import finished in {:.2f} seconds".format(time.time() - start))
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ImportMSP(bpy.types.Operator, ImportHelper):
|
class ImportMSP(bpy.types.Operator, ImportHelper):
|
||||||
bl_idname = "import_msp.bim"
|
bl_idname = "import_msp.bim"
|
||||||
bl_label = "Import MSP"
|
bl_label = "Import MSP"
|
||||||
|
|||||||
Reference in New Issue
Block a user