Skip to content

Commit

Permalink
Fix #4615. Report to user if they are attempting to create an incompa…
Browse files Browse the repository at this point in the history
…tible context-representation combination.
  • Loading branch information
Moult committed May 11, 2024
1 parent 00ae680 commit 3fa573e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
29 changes: 19 additions & 10 deletions src/blenderbim/blenderbim/bim/module/geometry/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def _execute(self, context):
return
ifc_context = tool.Ifc.get().by_id(ifc_context)

original_data = obj.data

if self.representation_conversion_method == "OUTLINE":
if ifc_context.ContextType == "Plan":
data = tool.Geometry.generate_outline_mesh(obj, axis="+Z")
Expand All @@ -166,16 +168,23 @@ def _execute(self, context):
data = tool.Geometry.generate_3d_box_mesh(obj)
tool.Geometry.change_object_data(obj, data, is_global=True)

core.add_representation(
tool.Ifc,
tool.Geometry,
tool.Style,
tool.Surveyor,
obj=obj,
context=ifc_context,
ifc_representation_class=None,
profile_set_usage=None,
)
try:
core.add_representation(
tool.Ifc,
tool.Geometry,
tool.Style,
tool.Surveyor,
obj=obj,
context=ifc_context,
ifc_representation_class=None,
profile_set_usage=None,
)
except core.IncompatibleRepresentationError:
if obj.data != original_data:
tool.Geometry.change_object_data(obj, original_data, is_global=True)
bpy.data.meshes.remove(data)
self.report({"ERROR"}, "No compatible representation for the context could be created.")
return {"CANCELLED"}

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
Expand Down
9 changes: 8 additions & 1 deletion src/blenderbim/blenderbim/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_representation(
data = geometry.get_object_data(obj)

if not data and ifc_representation_class != "IfcTextLiteral":
return
raise IncompatibleRepresentationError()

representation = ifc.run(
"geometry.add_representation",
Expand All @@ -63,6 +63,9 @@ def add_representation(
profile_set_usage=profile_set_usage,
)

if not representation:
raise IncompatibleRepresentationError()

if geometry.is_body_representation(representation):
[geometry.run_style_add_style(obj=mat) for mat in geometry.get_object_materials_without_styles(obj)]
ifc.run(
Expand Down Expand Up @@ -221,3 +224,7 @@ def edit_similar_opening_placement(geometry, opening=None, similar_openings=None
old_placement = similar_opening.ObjectPlacement
similar_opening.ObjectPlacement = opening.ObjectPlacement
geometry.delete_opening_object_placement(old_placement)


class IncompatibleRepresentationError(Exception):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,10 @@ def create_swept_disk_solid_representation(self):
)

def create_curve3d_representation(self):
return self.file.createIfcShapeRepresentation(
self.settings["context"],
self.settings["context"].ContextIdentifier,
"Curve3D",
self.create_curves(),
)
if curves := self.create_curves():
return self.file.createIfcShapeRepresentation(
self.settings["context"], self.settings["context"].ContextIdentifier, "Curve3D", curves
)

def create_curve2d_representation(self):
return self.file.createIfcShapeRepresentation(
Expand Down Expand Up @@ -425,7 +423,7 @@ def create_swept_disk_solids(self):
results.append(self.file.createIfcSweptDiskSolid(curve, radius))
return results

def is_mesh_curve_consequtive(self, geom_data):
def is_mesh_curve_consecutive(self, geom_data):
import blenderbim.tool as tool

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

if isinstance(geom_data, bpy.types.Mesh):
if self.is_mesh_curve_consequtive(geom_data):
if self.file.schema == "IFC2X3":
return self.create_curves_from_mesh_ifc2x3(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
else:
return self.create_curves_from_mesh(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
if not self.is_mesh_curve_consecutive(geom_data):
return
if self.file.schema == "IFC2X3":
return self.create_curves_from_mesh_ifc2x3(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
return self.create_curves_from_mesh(should_exclude_faces=should_exclude_faces, is_2d=is_2d)

import blenderbim.tool as tool

Expand Down

0 comments on commit 3fa573e

Please sign in to comment.