mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
Importing now stores a link to the original IFC representation contexts and subcontext IDs
This commit is contained in:
@@ -246,6 +246,7 @@ if bpy is not None:
|
||||
prop.DrawingStyle,
|
||||
prop.Sheet,
|
||||
prop.Subcontext,
|
||||
prop.Representation,
|
||||
prop.PresentationLayer,
|
||||
prop.BIMProperties,
|
||||
prop.BIMDebugProperties,
|
||||
|
||||
@@ -848,7 +848,7 @@ class IfcImporter:
|
||||
self.add_element_classifications(element, obj)
|
||||
self.add_element_document_relations(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_products[element.GlobalId] = obj
|
||||
|
||||
@@ -974,7 +974,7 @@ class IfcImporter:
|
||||
self.add_defines_by_type_relation(element, obj)
|
||||
self.add_opening_relation(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
|
||||
|
||||
if element.is_a("IfcOpeningElement"):
|
||||
@@ -1355,57 +1355,23 @@ class IfcImporter:
|
||||
bpy.ops.mesh.normals_make_consistent(context_override)
|
||||
bpy.ops.object.editmode_toggle(context_override)
|
||||
|
||||
def add_product_representation_contexts(self, element, obj):
|
||||
subcontexts = []
|
||||
ifc_definition_ids = []
|
||||
def add_product_representations(self, element, obj):
|
||||
if element.is_a("IfcProduct"):
|
||||
if not element.Representation:
|
||||
return
|
||||
for r in element.Representation.Representations:
|
||||
ifc_definition_ids.append(r.id())
|
||||
if r.ContextOfItems.is_a("IfcGeometricRepresentationSubContext"):
|
||||
subcontexts.append(
|
||||
"{}/{}/{}".format(
|
||||
r.ContextOfItems.ContextType or "",
|
||||
r.ContextOfItems.ContextIdentifier or "",
|
||||
r.ContextOfItems.TargetView or "",
|
||||
)
|
||||
)
|
||||
else:
|
||||
subcontexts.append(
|
||||
"{}/{}/{}".format(
|
||||
r.ContextOfItems.ContextType or "", r.ContextOfItems.ContextIdentifier or "", ""
|
||||
)
|
||||
)
|
||||
new = obj.BIMObjectProperties.representations.add()
|
||||
new.name = r.RepresentationIdentifier
|
||||
new.type = r.RepresentationType
|
||||
new.ifc_definition_id = r.id()
|
||||
elif element.is_a("IfcTypeProduct"):
|
||||
if not element.RepresentationMaps:
|
||||
return
|
||||
for r in element.RepresentationMaps:
|
||||
ifc_definition_ids.append(r.id())
|
||||
if r.MappedRepresentation.ContextOfItems.is_a("IfcGeometricRepresentationSubContext"):
|
||||
subcontexts.append(
|
||||
"{}/{}/{}".format(
|
||||
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]
|
||||
new = obj.BIMObjectProperties.representations.add()
|
||||
new.name = r.MappedRepresentation.RepresentationIdentifier
|
||||
new.type = r.MappedRepresentation.RepresentationType
|
||||
new.ifc_definition_id = r.MappedRepresentation.id()
|
||||
|
||||
def add_product_definitions(self, element, obj):
|
||||
if not hasattr(element, "IsDefinedBy") or not element.IsDefinedBy:
|
||||
@@ -1580,6 +1546,7 @@ class IfcImporter:
|
||||
subcontext = subcontexts.add()
|
||||
subcontext.name = context.ContextIdentifier
|
||||
subcontext.target_view = context.TargetView
|
||||
subcontext.ifc_definition_id = context.id()
|
||||
elif context.ContextType == "Model":
|
||||
bpy.context.scene.BIMProperties.has_model_context = True
|
||||
elif context.ContextType == "Plan":
|
||||
|
||||
@@ -565,6 +565,12 @@ class Subcontext(PropertyGroup):
|
||||
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):
|
||||
name: StringProperty(name="Name")
|
||||
material: PointerProperty(name="Material", type=bpy.types.Material)
|
||||
@@ -1502,7 +1508,7 @@ class BIMObjectProperties(PropertyGroup):
|
||||
has_boundary_condition: BoolProperty(name="Has Boundary Condition")
|
||||
boundary_condition: PointerProperty(name="Boundary Condition", type=BoundaryCondition)
|
||||
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: PointerProperty(name="Address", type=Address)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import bpy
|
||||
from . import ifc
|
||||
from bpy.types import Panel
|
||||
from bpy.props import StringProperty
|
||||
|
||||
@@ -637,27 +638,34 @@ class BIM_PT_representations(Panel):
|
||||
layout = self.layout
|
||||
props = context.active_object.BIMObjectProperties
|
||||
|
||||
if not props.representation_contexts:
|
||||
if not props.representations:
|
||||
layout.label(text="No representations found")
|
||||
|
||||
row = layout.row(align=True)
|
||||
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_target_views", text="")
|
||||
op = row.operator("bim.switch_context", icon="ADD", text="")
|
||||
op.has_target_context = False
|
||||
# TODO: reimplement with incremental editing
|
||||
# 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.prop(subcontext, "context", text="")
|
||||
row.prop(subcontext, "name", text="")
|
||||
row.prop(subcontext, "target_view", text="")
|
||||
op = row.operator("bim.switch_context", icon="OUTLINER_DATA_MESH", text="")
|
||||
op.has_target_context = True
|
||||
op.context_name = subcontext.context
|
||||
op.subcontext_name = subcontext.name
|
||||
op.target_view_name = subcontext.target_view
|
||||
row.operator("bim.remove_context", icon="X", text="").index = index
|
||||
row.prop(representation, "name", text="")
|
||||
row.prop(representation, "type", text="")
|
||||
if not representation.ifc_definition_id:
|
||||
continue
|
||||
subcontext = self.file.by_id(representation.ifc_definition_id).ContextOfItems
|
||||
if subcontext.is_a() == "IfcGeometricRepresentationContext":
|
||||
continue
|
||||
# TODO: reimplement with incremental editing
|
||||
# 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):
|
||||
|
||||
Reference in New Issue
Block a user