Importing now stores a link to the original IFC representation contexts and subcontext IDs

This commit is contained in:
Dion Moult
2020-12-30 21:09:19 +11:00
parent c844076efb
commit 9def261316
4 changed files with 41 additions and 59 deletions
@@ -246,6 +246,7 @@ if bpy is not None:
prop.DrawingStyle, prop.DrawingStyle,
prop.Sheet, prop.Sheet,
prop.Subcontext, prop.Subcontext,
prop.Representation,
prop.PresentationLayer, prop.PresentationLayer,
prop.BIMProperties, prop.BIMProperties,
prop.BIMDebugProperties, prop.BIMDebugProperties,
@@ -848,7 +848,7 @@ class IfcImporter:
self.add_element_classifications(element, obj) self.add_element_classifications(element, obj)
self.add_element_document_relations(element, obj) self.add_element_document_relations(element, obj)
self.add_type_product_psets(element, obj) self.add_type_product_psets(element, obj)
self.add_product_representation_contexts(element, obj) self.add_product_representations(element, obj)
self.type_collection.objects.link(obj) self.type_collection.objects.link(obj)
self.type_products[element.GlobalId] = obj self.type_products[element.GlobalId] = obj
@@ -974,7 +974,7 @@ class IfcImporter:
self.add_defines_by_type_relation(element, obj) self.add_defines_by_type_relation(element, obj)
self.add_opening_relation(element, obj) self.add_opening_relation(element, obj)
self.add_product_definitions(element, obj) self.add_product_definitions(element, obj)
self.add_product_representation_contexts(element, obj) self.add_product_representations(element, obj)
self.added_data[element.GlobalId] = obj self.added_data[element.GlobalId] = obj
if element.is_a("IfcOpeningElement"): if element.is_a("IfcOpeningElement"):
@@ -1355,57 +1355,23 @@ class IfcImporter:
bpy.ops.mesh.normals_make_consistent(context_override) bpy.ops.mesh.normals_make_consistent(context_override)
bpy.ops.object.editmode_toggle(context_override) bpy.ops.object.editmode_toggle(context_override)
def add_product_representation_contexts(self, element, obj): def add_product_representations(self, element, obj):
subcontexts = []
ifc_definition_ids = []
if element.is_a("IfcProduct"): if element.is_a("IfcProduct"):
if not element.Representation: if not element.Representation:
return return
for r in element.Representation.Representations: for r in element.Representation.Representations:
ifc_definition_ids.append(r.id()) new = obj.BIMObjectProperties.representations.add()
if r.ContextOfItems.is_a("IfcGeometricRepresentationSubContext"): new.name = r.RepresentationIdentifier
subcontexts.append( new.type = r.RepresentationType
"{}/{}/{}".format( new.ifc_definition_id = r.id()
r.ContextOfItems.ContextType or "",
r.ContextOfItems.ContextIdentifier or "",
r.ContextOfItems.TargetView or "",
)
)
else:
subcontexts.append(
"{}/{}/{}".format(
r.ContextOfItems.ContextType or "", r.ContextOfItems.ContextIdentifier or "", ""
)
)
elif element.is_a("IfcTypeProduct"): elif element.is_a("IfcTypeProduct"):
if not element.RepresentationMaps: if not element.RepresentationMaps:
return return
for r in element.RepresentationMaps: for r in element.RepresentationMaps:
ifc_definition_ids.append(r.id()) new = obj.BIMObjectProperties.representations.add()
if r.MappedRepresentation.ContextOfItems.is_a("IfcGeometricRepresentationSubContext"): new.name = r.MappedRepresentation.RepresentationIdentifier
subcontexts.append( new.type = r.MappedRepresentation.RepresentationType
"{}/{}/{}".format( new.ifc_definition_id = r.MappedRepresentation.id()
r.MappedRepresentation.ContextOfItems.ContextType or "",
r.MappedRepresentation.ContextOfItems.ContextIdentifier or "",
r.MappedRepresentation.ContextOfItems.TargetView or "",
)
)
else:
subcontexts.append(
"{}/{}/{}".format(
r.MappedRepresentation.ContextOfItems.ContextType or "",
r.MappedRepresentation.ContextOfItems.ContextIdentifier or "",
"",
)
)
for i, subcontext in enumerate(subcontexts):
representation_context = obj.BIMObjectProperties.representation_contexts.add()
(
representation_context.context,
representation_context.name,
representation_context.target_view,
) = subcontext.split("/")
representation_context.ifc_definition_id = ifc_definition_ids[i]
def add_product_definitions(self, element, obj): def add_product_definitions(self, element, obj):
if not hasattr(element, "IsDefinedBy") or not element.IsDefinedBy: if not hasattr(element, "IsDefinedBy") or not element.IsDefinedBy:
@@ -1580,6 +1546,7 @@ class IfcImporter:
subcontext = subcontexts.add() subcontext = subcontexts.add()
subcontext.name = context.ContextIdentifier subcontext.name = context.ContextIdentifier
subcontext.target_view = context.TargetView subcontext.target_view = context.TargetView
subcontext.ifc_definition_id = context.id()
elif context.ContextType == "Model": elif context.ContextType == "Model":
bpy.context.scene.BIMProperties.has_model_context = True bpy.context.scene.BIMProperties.has_model_context = True
elif context.ContextType == "Plan": elif context.ContextType == "Plan":
+7 -1
View File
@@ -565,6 +565,12 @@ class Subcontext(PropertyGroup):
ifc_definition_id: IntProperty(name="IFC Definition ID") ifc_definition_id: IntProperty(name="IFC Definition ID")
class Representation(PropertyGroup):
name: StringProperty(name="Name")
type: StringProperty(name="Type")
ifc_definition_id: IntProperty(name="IFC Definition ID")
class MaterialLayer(PropertyGroup): class MaterialLayer(PropertyGroup):
name: StringProperty(name="Name") name: StringProperty(name="Name")
material: PointerProperty(name="Material", type=bpy.types.Material) material: PointerProperty(name="Material", type=bpy.types.Material)
@@ -1502,7 +1508,7 @@ class BIMObjectProperties(PropertyGroup):
has_boundary_condition: BoolProperty(name="Has Boundary Condition") has_boundary_condition: BoolProperty(name="Has Boundary Condition")
boundary_condition: PointerProperty(name="Boundary Condition", type=BoundaryCondition) boundary_condition: PointerProperty(name="Boundary Condition", type=BoundaryCondition)
structural_member_connection: PointerProperty(name="Structural Member Connection", type=bpy.types.Object) structural_member_connection: PointerProperty(name="Structural Member Connection", type=bpy.types.Object)
representation_contexts: CollectionProperty(name="Representation Contexts", type=Subcontext) representations: CollectionProperty(name="Representations", type=Representation)
# Address applies to IfcSite's SiteAddress and IfcBuilding's BuildingAddress # Address applies to IfcSite's SiteAddress and IfcBuilding's BuildingAddress
address: PointerProperty(name="Address", type=Address) address: PointerProperty(name="Address", type=Address)
+21 -13
View File
@@ -1,5 +1,6 @@
import os import os
import bpy import bpy
from . import ifc
from bpy.types import Panel from bpy.types import Panel
from bpy.props import StringProperty from bpy.props import StringProperty
@@ -637,27 +638,34 @@ class BIM_PT_representations(Panel):
layout = self.layout layout = self.layout
props = context.active_object.BIMObjectProperties props = context.active_object.BIMObjectProperties
if not props.representation_contexts: if not props.representations:
layout.label(text="No representations found") layout.label(text="No representations found")
row = layout.row(align=True) row = layout.row(align=True)
row.prop(bpy.context.scene.BIMProperties, "available_contexts", text="") row.prop(bpy.context.scene.BIMProperties, "available_contexts", text="")
row.prop(bpy.context.scene.BIMProperties, "available_subcontexts", text="") row.prop(bpy.context.scene.BIMProperties, "available_subcontexts", text="")
row.prop(bpy.context.scene.BIMProperties, "available_target_views", text="") row.prop(bpy.context.scene.BIMProperties, "available_target_views", text="")
op = row.operator("bim.switch_context", icon="ADD", text="") # TODO: reimplement with incremental editing
op.has_target_context = False # op = row.operator("bim.switch_context", icon="ADD", text="")
# op.has_target_context = False
for index, subcontext in enumerate(props.representation_contexts): self.file = ifc.IfcStore.get_file()
for index, representation in enumerate(props.representations):
row = layout.row(align=True) row = layout.row(align=True)
row.prop(subcontext, "context", text="") row.prop(representation, "name", text="")
row.prop(subcontext, "name", text="") row.prop(representation, "type", text="")
row.prop(subcontext, "target_view", text="") if not representation.ifc_definition_id:
op = row.operator("bim.switch_context", icon="OUTLINER_DATA_MESH", text="") continue
op.has_target_context = True subcontext = self.file.by_id(representation.ifc_definition_id).ContextOfItems
op.context_name = subcontext.context if subcontext.is_a() == "IfcGeometricRepresentationContext":
op.subcontext_name = subcontext.name continue
op.target_view_name = subcontext.target_view # TODO: reimplement with incremental editing
row.operator("bim.remove_context", icon="X", text="").index = index # op = row.operator("bim.switch_context", icon="OUTLINER_DATA_MESH", text="")
# op.has_target_context = True
# op.context_name = subcontext.ContextType
# op.subcontext_name = subcontext.ContextIdentifier
# op.target_view_name = subcontext.TargetView
# row.operator("bim.remove_context", icon="X", text="").index = index
class BIM_PT_classification_references(Panel): class BIM_PT_classification_references(Panel):