mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix #4615. Report to user if they are attempting to create an incompatible context-representation combination.
This commit is contained in:
@@ -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,16 +168,23 @@ 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)
|
||||||
|
|
||||||
core.add_representation(
|
try:
|
||||||
tool.Ifc,
|
core.add_representation(
|
||||||
tool.Geometry,
|
tool.Ifc,
|
||||||
tool.Style,
|
tool.Geometry,
|
||||||
tool.Surveyor,
|
tool.Style,
|
||||||
obj=obj,
|
tool.Surveyor,
|
||||||
context=ifc_context,
|
obj=obj,
|
||||||
ifc_representation_class=None,
|
context=ifc_context,
|
||||||
profile_set_usage=None,
|
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):
|
def invoke(self, context, event):
|
||||||
return context.window_manager.invoke_props_dialog(self)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|||||||
@@ -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,12 +352,10 @@ class Usecase:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def create_curve3d_representation(self):
|
def create_curve3d_representation(self):
|
||||||
return self.file.createIfcShapeRepresentation(
|
if curves := self.create_curves():
|
||||||
self.settings["context"],
|
return self.file.createIfcShapeRepresentation(
|
||||||
self.settings["context"].ContextIdentifier,
|
self.settings["context"], self.settings["context"].ContextIdentifier, "Curve3D", curves
|
||||||
"Curve3D",
|
)
|
||||||
self.create_curves(),
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_curve2d_representation(self):
|
def create_curve2d_representation(self):
|
||||||
return self.file.createIfcShapeRepresentation(
|
return self.file.createIfcShapeRepresentation(
|
||||||
@@ -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,11 +473,11 @@ 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):
|
||||||
if self.file.schema == "IFC2X3":
|
return
|
||||||
return self.create_curves_from_mesh_ifc2x3(should_exclude_faces=should_exclude_faces, is_2d=is_2d)
|
if self.file.schema == "IFC2X3":
|
||||||
else:
|
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)
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user