Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 3fa573e

Browse files
committed
Fix IfcOpenShell#4615. Report to user if they are attempting to create an incompatible context-representation combination.
1 parent 00ae680 commit 3fa573e

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

src/blenderbim/blenderbim/bim/module/geometry/operator.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ def _execute(self, context):
149149
return
150150
ifc_context = tool.Ifc.get().by_id(ifc_context)
151151

152+
original_data = obj.data
153+
152154
if self.representation_conversion_method == "OUTLINE":
153155
if ifc_context.ContextType == "Plan":
154156
data = tool.Geometry.generate_outline_mesh(obj, axis="+Z")
@@ -166,16 +168,23 @@ def _execute(self, context):
166168
data = tool.Geometry.generate_3d_box_mesh(obj)
167169
tool.Geometry.change_object_data(obj, data, is_global=True)
168170

169-
core.add_representation(
170-
tool.Ifc,
171-
tool.Geometry,
172-
tool.Style,
173-
tool.Surveyor,
174-
obj=obj,
175-
context=ifc_context,
176-
ifc_representation_class=None,
177-
profile_set_usage=None,
178-
)
171+
try:
172+
core.add_representation(
173+
tool.Ifc,
174+
tool.Geometry,
175+
tool.Style,
176+
tool.Surveyor,
177+
obj=obj,
178+
context=ifc_context,
179+
ifc_representation_class=None,
180+
profile_set_usage=None,
181+
)
182+
except core.IncompatibleRepresentationError:
183+
if obj.data != original_data:
184+
tool.Geometry.change_object_data(obj, original_data, is_global=True)
185+
bpy.data.meshes.remove(data)
186+
self.report({"ERROR"}, "No compatible representation for the context could be created.")
187+
return {"CANCELLED"}
179188

180189
def invoke(self, context, event):
181190
return context.window_manager.invoke_props_dialog(self)

src/blenderbim/blenderbim/core/geometry.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def add_representation(
4747
data = geometry.get_object_data(obj)
4848

4949
if not data and ifc_representation_class != "IfcTextLiteral":
50-
return
50+
raise IncompatibleRepresentationError()
5151

5252
representation = ifc.run(
5353
"geometry.add_representation",
@@ -63,6 +63,9 @@ def add_representation(
6363
profile_set_usage=profile_set_usage,
6464
)
6565

66+
if not representation:
67+
raise IncompatibleRepresentationError()
68+
6669
if geometry.is_body_representation(representation):
6770
[geometry.run_style_add_style(obj=mat) for mat in geometry.get_object_materials_without_styles(obj)]
6871
ifc.run(
@@ -221,3 +224,7 @@ def edit_similar_opening_placement(geometry, opening=None, similar_openings=None
221224
old_placement = similar_opening.ObjectPlacement
222225
similar_opening.ObjectPlacement = opening.ObjectPlacement
223226
geometry.delete_opening_object_placement(old_placement)
227+
228+
229+
class IncompatibleRepresentationError(Exception):
230+
pass

src/ifcopenshell-python/ifcopenshell/api/geometry/add_representation.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,10 @@ def create_swept_disk_solid_representation(self):
352352
)
353353

354354
def create_curve3d_representation(self):
355-
return self.file.createIfcShapeRepresentation(
356-
self.settings["context"],
357-
self.settings["context"].ContextIdentifier,
358-
"Curve3D",
359-
self.create_curves(),
360-
)
355+
if curves := self.create_curves():
356+
return self.file.createIfcShapeRepresentation(
357+
self.settings["context"], self.settings["context"].ContextIdentifier, "Curve3D", curves
358+
)
361359

362360
def create_curve2d_representation(self):
363361
return self.file.createIfcShapeRepresentation(
@@ -425,7 +423,7 @@ def create_swept_disk_solids(self):
425423
results.append(self.file.createIfcSweptDiskSolid(curve, radius))
426424
return results
427425

428-
def is_mesh_curve_consequtive(self, geom_data):
426+
def is_mesh_curve_consecutive(self, geom_data):
429427
import blenderbim.tool as tool
430428

431429
bm = tool.Blender.get_bmesh_for_mesh(geom_data)
@@ -475,11 +473,11 @@ def create_curves(self, should_exclude_faces=False, is_2d=False, ignore_non_loos
475473
geom_data = self.settings["geometry"]
476474

477475
if isinstance(geom_data, bpy.types.Mesh):
478-
if self.is_mesh_curve_consequtive(geom_data):
479-
if self.file.schema == "IFC2X3":
480-
return self.create_curves_from_mesh_ifc2x3(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
481-
else:
482-
return self.create_curves_from_mesh(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
476+
if not self.is_mesh_curve_consecutive(geom_data):
477+
return
478+
if self.file.schema == "IFC2X3":
479+
return self.create_curves_from_mesh_ifc2x3(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
480+
return self.create_curves_from_mesh(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
483481

484482
import blenderbim.tool as tool
485483

0 commit comments

Comments
 (0)