Fix #4615. Report to user if they are attempting to create an incompatible context-representation combination.

This commit is contained in:
Dion Moult
2024-05-11 20:48:38 +10:00
parent 00ae6809a9
commit 3fa573e3c1
3 changed files with 37 additions and 23 deletions
@@ -149,6 +149,8 @@ class AddRepresentation(bpy.types.Operator, Operator):
return return
ifc_context = tool.Ifc.get().by_id(ifc_context) ifc_context = tool.Ifc.get().by_id(ifc_context)
original_data = obj.data
if self.representation_conversion_method == "OUTLINE": if self.representation_conversion_method == "OUTLINE":
if ifc_context.ContextType == "Plan": if ifc_context.ContextType == "Plan":
data = tool.Geometry.generate_outline_mesh(obj, axis="+Z") data = tool.Geometry.generate_outline_mesh(obj, axis="+Z")
@@ -166,6 +168,7 @@ class AddRepresentation(bpy.types.Operator, Operator):
data = tool.Geometry.generate_3d_box_mesh(obj) data = tool.Geometry.generate_3d_box_mesh(obj)
tool.Geometry.change_object_data(obj, data, is_global=True) tool.Geometry.change_object_data(obj, data, is_global=True)
try:
core.add_representation( core.add_representation(
tool.Ifc, tool.Ifc,
tool.Geometry, tool.Geometry,
@@ -176,6 +179,12 @@ class AddRepresentation(bpy.types.Operator, Operator):
ifc_representation_class=None, ifc_representation_class=None,
profile_set_usage=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): def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
+8 -1
View File
@@ -47,7 +47,7 @@ def add_representation(
data = geometry.get_object_data(obj) data = geometry.get_object_data(obj)
if not data and ifc_representation_class != "IfcTextLiteral": if not data and ifc_representation_class != "IfcTextLiteral":
return raise IncompatibleRepresentationError()
representation = ifc.run( representation = ifc.run(
"geometry.add_representation", "geometry.add_representation",
@@ -63,6 +63,9 @@ def add_representation(
profile_set_usage=profile_set_usage, profile_set_usage=profile_set_usage,
) )
if not representation:
raise IncompatibleRepresentationError()
if geometry.is_body_representation(representation): if geometry.is_body_representation(representation):
[geometry.run_style_add_style(obj=mat) for mat in geometry.get_object_materials_without_styles(obj)] [geometry.run_style_add_style(obj=mat) for mat in geometry.get_object_materials_without_styles(obj)]
ifc.run( ifc.run(
@@ -221,3 +224,7 @@ def edit_similar_opening_placement(geometry, opening=None, similar_openings=None
old_placement = similar_opening.ObjectPlacement old_placement = similar_opening.ObjectPlacement
similar_opening.ObjectPlacement = opening.ObjectPlacement similar_opening.ObjectPlacement = opening.ObjectPlacement
geometry.delete_opening_object_placement(old_placement) geometry.delete_opening_object_placement(old_placement)
class IncompatibleRepresentationError(Exception):
pass
@@ -352,11 +352,9 @@ class Usecase:
) )
def create_curve3d_representation(self): def create_curve3d_representation(self):
if curves := self.create_curves():
return self.file.createIfcShapeRepresentation( return self.file.createIfcShapeRepresentation(
self.settings["context"], self.settings["context"], self.settings["context"].ContextIdentifier, "Curve3D", curves
self.settings["context"].ContextIdentifier,
"Curve3D",
self.create_curves(),
) )
def create_curve2d_representation(self): def create_curve2d_representation(self):
@@ -425,7 +423,7 @@ class Usecase:
results.append(self.file.createIfcSweptDiskSolid(curve, radius)) results.append(self.file.createIfcSweptDiskSolid(curve, radius))
return results return results
def is_mesh_curve_consequtive(self, geom_data): def is_mesh_curve_consecutive(self, geom_data):
import blenderbim.tool as tool import blenderbim.tool as tool
bm = tool.Blender.get_bmesh_for_mesh(geom_data) bm = tool.Blender.get_bmesh_for_mesh(geom_data)
@@ -475,10 +473,10 @@ class Usecase:
geom_data = self.settings["geometry"] geom_data = self.settings["geometry"]
if isinstance(geom_data, bpy.types.Mesh): if isinstance(geom_data, bpy.types.Mesh):
if self.is_mesh_curve_consequtive(geom_data): if not self.is_mesh_curve_consecutive(geom_data):
return
if self.file.schema == "IFC2X3": 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_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) return self.create_curves_from_mesh(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
import blenderbim.tool as tool import blenderbim.tool as tool