mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
Switching contexts are now more tolerant of broken IFCs. See #865.
This commit is contained in:
@@ -664,22 +664,22 @@ class IfcImporter():
|
|||||||
for r in element.Representation.Representations:
|
for r in element.Representation.Representations:
|
||||||
if r.ContextOfItems.is_a('IfcGeometricRepresentationSubContext'):
|
if r.ContextOfItems.is_a('IfcGeometricRepresentationSubContext'):
|
||||||
subcontexts.append('{}/{}/{}'.format(
|
subcontexts.append('{}/{}/{}'.format(
|
||||||
r.ContextOfItems.ContextType,
|
r.ContextOfItems.ContextType or '',
|
||||||
r.ContextOfItems.ContextIdentifier,
|
r.ContextOfItems.ContextIdentifier or '',
|
||||||
r.ContextOfItems.TargetView))
|
r.ContextOfItems.TargetView or ''))
|
||||||
else:
|
else:
|
||||||
subcontexts.append('{}/{}/{}'.format(
|
subcontexts.append('{}/{}/{}'.format(
|
||||||
r.ContextOfItems.ContextType,
|
r.ContextOfItems.ContextType or '',
|
||||||
r.ContextOfItems.ContextIdentifier,
|
r.ContextOfItems.ContextIdentifier or '',
|
||||||
None))
|
''))
|
||||||
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:
|
||||||
subcontexts.append('{}/{}/{}'.format(
|
subcontexts.append('{}/{}/{}'.format(
|
||||||
r.MappedRepresentation.ContextOfItems.ContextType,
|
r.MappedRepresentation.ContextOfItems.ContextType or '',
|
||||||
r.MappedRepresentation.ContextOfItems.ContextIdentifier,
|
r.MappedRepresentation.ContextOfItems.ContextIdentifier or '',
|
||||||
r.MappedRepresentation.ContextOfItems.TargetView))
|
r.MappedRepresentation.ContextOfItems.TargetView or ''))
|
||||||
subcontexts = set(subcontexts)
|
subcontexts = set(subcontexts)
|
||||||
for subcontext in subcontexts:
|
for subcontext in subcontexts:
|
||||||
representation_context = obj.BIMObjectProperties.representation_contexts.add()
|
representation_context = obj.BIMObjectProperties.representation_contexts.add()
|
||||||
|
|||||||
@@ -1983,6 +1983,7 @@ class AssignContext(bpy.types.Operator):
|
|||||||
class SwitchContext(bpy.types.Operator):
|
class SwitchContext(bpy.types.Operator):
|
||||||
bl_idname = 'bim.switch_context'
|
bl_idname = 'bim.switch_context'
|
||||||
bl_label = 'Switch Context'
|
bl_label = 'Switch Context'
|
||||||
|
has_target_context: bpy.props.BoolProperty()
|
||||||
context_name: bpy.props.StringProperty()
|
context_name: bpy.props.StringProperty()
|
||||||
subcontext_name: bpy.props.StringProperty()
|
subcontext_name: bpy.props.StringProperty()
|
||||||
target_view_name: bpy.props.StringProperty()
|
target_view_name: bpy.props.StringProperty()
|
||||||
@@ -1999,11 +2000,9 @@ class SwitchContext(bpy.types.Operator):
|
|||||||
self.subcontext = bpy.context.scene.BIMProperties.available_subcontexts
|
self.subcontext = bpy.context.scene.BIMProperties.available_subcontexts
|
||||||
self.target_view = bpy.context.scene.BIMProperties.available_target_views
|
self.target_view = bpy.context.scene.BIMProperties.available_target_views
|
||||||
|
|
||||||
if self.context_name:
|
if self.has_target_context:
|
||||||
self.context = self.context_name
|
self.context = self.context_name
|
||||||
if self.subcontext_name:
|
|
||||||
self.subcontext = self.subcontext_name
|
self.subcontext = self.subcontext_name
|
||||||
if self.target_view_name:
|
|
||||||
self.target_view = self.target_view_name
|
self.target_view = self.target_view_name
|
||||||
|
|
||||||
mesh = bpy.data.meshes.get('{}/{}/{}/{}'.format(
|
mesh = bpy.data.meshes.get('{}/{}/{}/{}'.format(
|
||||||
@@ -2031,17 +2030,27 @@ class SwitchContext(bpy.types.Operator):
|
|||||||
settings = ifcopenshell.geom.settings()
|
settings = ifcopenshell.geom.settings()
|
||||||
settings.set(settings.INCLUDE_CURVES, True)
|
settings.set(settings.INCLUDE_CURVES, True)
|
||||||
if element.is_a('IfcProduct'):
|
if element.is_a('IfcProduct'):
|
||||||
rep = [r for r in element.Representation.Representations if
|
representations = element.Representation.Representations
|
||||||
r.ContextOfItems.ContextType == self.context \
|
|
||||||
and r.ContextOfItems.ContextIdentifier == self.subcontext \
|
|
||||||
and r.ContextOfItems.TargetView == self.target_view][0]
|
|
||||||
else:
|
else:
|
||||||
rep = [rm.MappedRepresentation for rm in element.RepresentationMaps if
|
representations = element.RepresentationMaps
|
||||||
rm.MappedRepresentation.ContextOfItems.ContextType == self.context \
|
|
||||||
and rm.MappedRepresentation.ContextOfItems.ContextIdentifier == self.subcontext \
|
for rep in element.Representation.Representations:
|
||||||
and rm.MappedRepresentation.ContextOfItems.TargetView == self.target_view][0]
|
if rep.ContextOfItems.is_a('IfcGeometricRepresentationSubContext') \
|
||||||
|
and rep.ContextOfItems.ContextType == self.context \
|
||||||
|
and rep.ContextOfItems.ContextIdentifier == self.subcontext \
|
||||||
|
and rep.ContextOfItems.TargetView == self.target_view:
|
||||||
|
break
|
||||||
|
elif rep.ContextOfItems.is_a('IfcGeometricRepresentationContext') \
|
||||||
|
and rep.ContextOfItems.ContextType == self.context \
|
||||||
|
and rep.ContextOfItems.ContextIdentifier == self.subcontext:
|
||||||
|
break
|
||||||
|
|
||||||
|
if not element.is_a('IfcProduct'):
|
||||||
|
rep = rep.MappedRepresentation
|
||||||
|
|
||||||
shape = ifcopenshell.geom.create_shape(settings, rep)
|
shape = ifcopenshell.geom.create_shape(settings, rep)
|
||||||
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
||||||
|
ifc_importer.file = self.file
|
||||||
mesh = ifc_importer.create_mesh(element, shape)
|
mesh = ifc_importer.create_mesh(element, shape)
|
||||||
mesh.name = '{}/{}/{}/{}'.format(
|
mesh.name = '{}/{}/{}/{}'.format(
|
||||||
self.context, self.subcontext, self.target_view, self.obj.data.name.split('/')[3])
|
self.context, self.subcontext, self.target_view, self.obj.data.name.split('/')[3])
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ class BIM_PT_representations(Panel):
|
|||||||
row.prop(subcontext, 'name', text='')
|
row.prop(subcontext, 'name', text='')
|
||||||
row.prop(subcontext, 'target_view', text='')
|
row.prop(subcontext, 'target_view', text='')
|
||||||
op = row.operator('bim.switch_context', icon='OUTLINER_DATA_MESH', text='')
|
op = row.operator('bim.switch_context', icon='OUTLINER_DATA_MESH', text='')
|
||||||
|
op.has_target_context = True
|
||||||
op.context_name = subcontext.context
|
op.context_name = subcontext.context
|
||||||
op.subcontext_name = subcontext.name
|
op.subcontext_name = subcontext.name
|
||||||
op.target_view_name = subcontext.target_view
|
op.target_view_name = subcontext.target_view
|
||||||
|
|||||||
Reference in New Issue
Block a user