#1153 Add support for Annotation3D representations

This commit is contained in:
Dion Moult
2022-04-24 10:00:16 +10:00
parent c2cad06cfa
commit 31ddb0f2c5
6 changed files with 17 additions and 52 deletions
@@ -206,25 +206,14 @@ class UpdateRepresentation(bpy.types.Operator):
new_representation = ifcopenshell.api.run("geometry.add_representation", self.file, **representation_data)
[
blenderbim.core.style.add_style(tool.Ifc, tool.Style, obj=s.material)
for s in obj.material_slots
if s.material and not s.material.BIMMaterialProperties.ifc_style_id
]
if isinstance(obj.data, bpy.types.Mesh) and len(obj.data.polygons):
if tool.Geometry.is_body_representation(new_representation):
[tool.Geometry.run_style_add_style(obj=mat) for mat in tool.Geometry.get_object_materials_without_styles(obj)]
ifcopenshell.api.run(
"style.assign_representation_styles",
self.file,
**{
"shape_representation": new_representation,
"styles": [
self.file.by_id(s.material.BIMMaterialProperties.ifc_style_id)
for s in obj.material_slots
if s.material
],
"should_use_presentation_style_assignment": context.scene.BIMGeometryProperties.should_use_presentation_style_assignment,
},
shape_representation=new_representation,
styles=tool.Geometry.get_styles(obj),
should_use_presentation_style_assignment=context.scene.BIMGeometryProperties.should_use_presentation_style_assignment,
)
tool.Geometry.record_object_materials(obj)
+1 -1
View File
@@ -55,7 +55,7 @@ def add_representation(
profile_set_usage=profile_set_usage,
)
if geometry.does_object_have_mesh_with_faces(obj):
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(
"style.assign_representation_styles",
-1
View File
@@ -206,7 +206,6 @@ class Geometry:
def clear_scale(cls, obj): pass
def create_dynamic_voids(cls, obj): pass
def delete_data(cls, data): pass
def does_object_have_mesh_with_faces(cls, obj): pass
def does_representation_id_exist(cls, representation_id): pass
def duplicate_object_data(cls, obj): pass
def get_cartesian_point_coordinate_offset(cls, obj): pass
@@ -75,10 +75,6 @@ class Geometry(blenderbim.core.tool.Geometry):
def delete_data(cls, data):
bpy.data.meshes.remove(data)
@classmethod
def does_object_have_mesh_with_faces(cls, obj):
return bool(isinstance(obj.data, bpy.types.Mesh) and len(obj.data.polygons))
@classmethod
def does_representation_id_exist(cls, representation_id):
try:
-19
View File
@@ -102,25 +102,6 @@ class TestDeleteData(NewFile):
assert not bpy.data.meshes.get("Mesh")
class TestDoesObjectHaveMeshWithFaces(NewFile):
def test_empties_return_false(self):
obj = bpy.data.objects.new("Object", None)
assert subject.does_object_have_mesh_with_faces(obj) is False
def test_non_meshes_return_false(self):
obj = bpy.data.objects.new("Object", bpy.data.cameras.new("Curve"))
assert subject.does_object_have_mesh_with_faces(obj) is False
def test_meshes_without_faces_return_false(self):
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
assert subject.does_object_have_mesh_with_faces(obj) is False
def test_meshes_with_faces_return_true(self):
bpy.ops.mesh.primitive_cube_add()
obj = bpy.data.objects.get("Cube")
assert subject.does_object_have_mesh_with_faces(obj) is True
class TestDoesRepresentationIdExist(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -115,7 +115,7 @@ class Usecase:
if self.settings["context"].is_a() == "IfcGeometricRepresentationContext":
return self.create_variable_representation()
if self.settings["context"].ContextIdentifier == "Annotation":
return self.create_geometric_set_representation()
return self.create_annotation_representation(is_2d=False)
elif self.settings["context"].ContextIdentifier == "Axis":
return self.create_curve3d_representation()
elif self.settings["context"].ContextIdentifier == "Body":
@@ -149,7 +149,7 @@ class Usecase:
shape_representation.Items = items
return shape_representation
elif self.settings["context"].ContextIdentifier == "Annotation":
return self.create_annotation2d_representation()
return self.create_annotation_representation(is_2d=True)
elif self.settings["context"].ContextIdentifier == "Axis":
return self.create_curve2d_representation()
elif self.settings["context"].ContextIdentifier == "Body":
@@ -170,7 +170,7 @@ class Usecase:
elif self.settings["context"].ContextIdentifier == "SurveyPoints":
pass
else:
return self.create_annotation2d_representation()
return self.create_annotation_representation(is_2d=True)
def create_lighting_representation(self):
return self.file.createIfcShapeRepresentation(
@@ -289,15 +289,15 @@ class Usecase:
self.create_curves(is_2d=True),
)
def create_annotation_fill_areas(self):
def create_annotation_fill_areas(self, is_2d=False):
items = []
if self.file.schema != "IFC2X3":
points = self.create_cartesian_point_list_from_vertices(self.settings["geometry"].vertices, is_2d=True)
points = self.create_cartesian_point_list_from_vertices(self.settings["geometry"].vertices, is_2d=is_2d)
for polygon in self.settings["geometry"].polygons:
if self.file.schema == "IFC2X3":
curve = self.create_curve_from_polygon_ifc2x3(polygon, is_2d=True)
curve = self.create_curve_from_polygon_ifc2x3(polygon, is_2d=is_2d)
else:
curve = self.create_curve_from_polygon(points, polygon, is_2d=True)
curve = self.create_curve_from_polygon(points, polygon, is_2d=is_2d)
items.append(self.file.createIfcAnnotationFillArea(OuterBoundary=curve))
return items
@@ -623,15 +623,15 @@ class Usecase:
return (co / self.settings["unit_scale"]) + self.settings["coordinate_offset"]
return co / self.settings["unit_scale"]
def create_annotation2d_representation(self):
def create_annotation_representation(self, is_2d=False):
if isinstance(self.settings["geometry"], bpy.types.Mesh) and len(self.settings["geometry"].polygons):
items = self.create_annotation_fill_areas()
items = self.create_annotation_fill_areas(is_2d=is_2d)
else:
items = [self.file.createIfcGeometricCurveSet(self.create_curves(is_2d=True))]
items = [self.file.createIfcGeometricCurveSet(self.create_curves(is_2d=is_2d))]
return self.file.createIfcShapeRepresentation(
self.settings["context"],
self.settings["context"].ContextIdentifier,
"Annotation2D",
"Annotation2D" if is_2d else "GeometricSet",
items,
)