mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Enable export with auto-generated bounding box representations
This commit is contained in:
@@ -970,6 +970,14 @@ class IfcParser():
|
||||
def load_representations(self):
|
||||
if not self.ifc_export_settings.has_representations:
|
||||
return
|
||||
self.generated_subcontexts = []
|
||||
for context in self.ifc_export_settings.context_tree:
|
||||
for subcontext in context['subcontexts']:
|
||||
for target_view in subcontext['target_views']:
|
||||
if context['name'] == 'Model' \
|
||||
and subcontext['name'] == 'Box' \
|
||||
and target_view == 'MODEL_VIEW':
|
||||
self.generated_subcontexts = '/'.join([context['name'], subcontext['name'], target_view])
|
||||
for product in self.selected_products \
|
||||
+ self.selected_types \
|
||||
+ self.selected_spatial_structure_elements:
|
||||
@@ -1000,6 +1008,9 @@ class IfcParser():
|
||||
def append_default_representation(self, obj):
|
||||
self.representations['Model/Body/MODEL_VIEW/{}'.format(obj.data.name)] = self.get_representation(
|
||||
obj.data, obj, 'Model', 'Body', 'MODEL_VIEW')
|
||||
if 'Model/Box/MODEL_VIEW' in self.generated_subcontexts:
|
||||
self.representations['Model/Box/MODEL_VIEW/{}'.format(obj.data.name)] = self.get_representation(
|
||||
obj.data, obj, 'Model', 'Box', 'MODEL_VIEW')
|
||||
|
||||
def append_point_cloud_representation(self, obj):
|
||||
self.representations['Model/Body/MODEL_VIEW/{}'.format(obj.name)] = self.get_representation(
|
||||
@@ -1034,6 +1045,12 @@ class IfcParser():
|
||||
if mesh:
|
||||
self.representations[mesh_name] = self.get_representation(
|
||||
mesh, obj, context, subcontext, target_view)
|
||||
if 'Model/Box/MODEL_VIEW' in self.generated_subcontexts \
|
||||
and context == 'Model' \
|
||||
and subcontext == 'Body' \
|
||||
and target_view == 'MODEL_VIEW':
|
||||
self.representations['Model/Box/MODEL_VIEW/{}'.format(mesh_name.split('/')[3])] = self.get_representation(
|
||||
obj.data, obj, 'Model', 'Box', 'MODEL_VIEW')
|
||||
elif context_prefix == 'Model/Body/MODEL_VIEW' \
|
||||
and obj.data \
|
||||
and not self.is_mesh_context_sensitive(obj.data.name):
|
||||
@@ -2890,7 +2907,6 @@ class IfcExportSettings:
|
||||
self.has_quantities = True
|
||||
self.contexts = ['Model', 'Plan']
|
||||
self.subcontexts = ['Annotation', 'Axis', 'Box', 'FootPrint', 'Reference', 'Body', 'Clearance', 'CoG', 'Profile', 'SurveyPoints']
|
||||
self.generated_subcontexts = ['Box']
|
||||
self.schema = 'IFC4'
|
||||
self.target_views = ['GRAPH_VIEW', 'SKETCH_VIEW', 'MODEL_VIEW', 'PLAN_VIEW', 'REFLECTED_PLAN_VIEW',
|
||||
'SECTION_VIEW', 'ELEVATION_VIEW', 'USERDEFINED', 'NOTDEFINED']
|
||||
|
||||
@@ -2321,6 +2321,8 @@ class SwitchContext(bpy.types.Operator):
|
||||
self.subcontext = self.subcontext_name
|
||||
self.target_view = self.target_view_name
|
||||
|
||||
existing_mesh = self.obj.data
|
||||
existing_mesh.use_fake_user = True
|
||||
mesh = bpy.data.meshes.get('{}/{}/{}/{}'.format(
|
||||
self.context, self.subcontext, self.target_view, self.obj.data.name.split('/')[3]))
|
||||
if not mesh:
|
||||
@@ -2328,15 +2330,22 @@ class SwitchContext(bpy.types.Operator):
|
||||
global_id = self.obj.BIMObjectProperties.attributes.get('GlobalId').string_value
|
||||
mesh = self.pull_mesh_from_ifc(global_id)
|
||||
except:
|
||||
existing_mesh = self.obj.data
|
||||
mesh = self.obj.data.copy()
|
||||
mesh.name = '{}/{}/{}/{}'.format(
|
||||
self.context, self.subcontext, self.target_view, self.obj.data.name.split('/')[3])
|
||||
representation_context = self.obj.BIMObjectProperties.representation_contexts.add()
|
||||
representation_context.context = self.context
|
||||
representation_context.name = self.subcontext
|
||||
representation_context.target_view = self.target_view
|
||||
|
||||
has_context = False
|
||||
for context in self.obj.BIMObjectProperties.representation_contexts:
|
||||
if context.context == self.context \
|
||||
and context.name == self.subcontext \
|
||||
and context.target_view == self.target_view:
|
||||
has_context = True
|
||||
break
|
||||
if not has_context:
|
||||
representation_context = self.obj.BIMObjectProperties.representation_contexts.add()
|
||||
representation_context.context = self.context
|
||||
representation_context.name = self.subcontext
|
||||
representation_context.target_view = self.target_view
|
||||
mesh.use_fake_user = True
|
||||
self.obj.data = mesh
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
@@ -837,6 +837,11 @@ class BIM_PT_camera(Panel):
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
if '/' not in context.active_object.name:
|
||||
layout.label(text="This is not a BIM camera.")
|
||||
return
|
||||
|
||||
layout.use_property_split = True
|
||||
dprops = bpy.context.scene.DocProperties
|
||||
props = context.active_object.data.BIMCameraProperties
|
||||
|
||||
Reference in New Issue
Block a user