mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Add annotation by default to the active drawing #5216
Approach in 358c834 didn't worked out because annotations are assigned to the drawing after assign_class and we can't check in assign_class whether it's going to be part of the drawing.
This commit is contained in:
@@ -86,7 +86,7 @@ def assign_class(
|
||||
obj=obj, context=context, ifc_representation_class=ifc_representation_class, profile_set_usage=None
|
||||
)
|
||||
|
||||
if default_container := root.get_default_container():
|
||||
if not root.is_drawing_annotation(element) and (default_container := root.get_default_container()):
|
||||
if root.is_spatial_element(element):
|
||||
ifc.run("aggregate.assign_object", products=[element], relating_object=default_container)
|
||||
elif root.is_containable(element):
|
||||
|
||||
@@ -723,6 +723,7 @@ class Root:
|
||||
def get_object_representation(cls, obj): pass
|
||||
def get_representation_context(cls, representation): pass
|
||||
def is_containable(cls, element): pass
|
||||
def is_drawing_annotation(cls, element): pass
|
||||
def is_element_a(cls, element, ifc_class): pass
|
||||
def is_spatial_element(cls, element): pass
|
||||
def link_object_data(cls, source_obj, destination_obj): pass
|
||||
|
||||
@@ -170,16 +170,21 @@ class Root(bonsai.core.tool.Root):
|
||||
|
||||
@classmethod
|
||||
def is_containable(cls, element: ifcopenshell.entity_instance) -> bool:
|
||||
if element.is_a("IfcElement") or element.is_a("IfcGrid"):
|
||||
if element.is_a("IfcElement") or element.is_a("IfcGrid") or element.is_a("IfcAnnotation"):
|
||||
return True
|
||||
if element.is_a("IfcAnnotation"):
|
||||
if element.ObjectType == "DRAWING":
|
||||
return False
|
||||
drawing_group = tool.Drawing.get_drawing_group(element)
|
||||
if not drawing_group:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def is_drawing_annotation(cls, element: ifcopenshell.entity_instance) -> bool:
|
||||
if not element.is_a("IfcAnnotation"):
|
||||
return False
|
||||
if element.ObjectType == "DRAWING":
|
||||
return True
|
||||
camera = bpy.context.scene.camera
|
||||
if not camera or not tool.Ifc.get_entity(camera):
|
||||
return False
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def is_element_a(cls, element: ifcopenshell.entity_instance, ifc_class: str) -> bool:
|
||||
return element.is_a(ifc_class)
|
||||
|
||||
@@ -130,6 +130,7 @@ class TestAssignClass:
|
||||
obj="obj", context="context", ifc_representation_class="ifc_representation_class", profile_set_usage=None
|
||||
).should_be_called()
|
||||
|
||||
root.is_drawing_annotation("element").should_be_called().will_return(False)
|
||||
root.get_default_container().should_be_called().will_return("default_container")
|
||||
root.is_spatial_element("element").should_be_called().will_return(True)
|
||||
ifc.run("aggregate.assign_object", products=["element"], relating_object="default_container").should_be_called()
|
||||
@@ -161,6 +162,7 @@ class TestAssignClass:
|
||||
obj="obj", context="context", ifc_representation_class="ifc_representation_class", profile_set_usage=None
|
||||
).should_be_called()
|
||||
|
||||
root.is_drawing_annotation("element").should_be_called().will_return(False)
|
||||
root.get_default_container().should_be_called().will_return("default_container")
|
||||
root.is_spatial_element("element").should_be_called().will_return(False)
|
||||
root.is_containable("element").should_be_called().will_return(True)
|
||||
@@ -181,6 +183,33 @@ class TestAssignClass:
|
||||
ifc_representation_class="ifc_representation_class",
|
||||
)
|
||||
|
||||
def test_assign_a_class_to_drawing_annotation_without_assigning_container(self, ifc, collector, root):
|
||||
ifc.get_entity("obj").should_be_called().will_return(None)
|
||||
root.get_object_name("obj").should_be_called().will_return("name")
|
||||
ifc.run(
|
||||
"root.create_entity", ifc_class="ifc_class", predefined_type="predefined_type", name="name"
|
||||
).should_be_called().will_return("element")
|
||||
root.set_object_name("obj", "element").should_be_called()
|
||||
ifc.link("element", "obj").should_be_called()
|
||||
root.run_geometry_add_representation(
|
||||
obj="obj", context="context", ifc_representation_class="ifc_representation_class", profile_set_usage=None
|
||||
).should_be_called()
|
||||
|
||||
root.is_drawing_annotation("element").should_be_called().will_return(True)
|
||||
|
||||
collector.assign("obj").should_be_called()
|
||||
subject.assign_class(
|
||||
ifc,
|
||||
collector,
|
||||
root,
|
||||
obj="obj",
|
||||
ifc_class="ifc_class",
|
||||
predefined_type="predefined_type",
|
||||
should_add_representation=True,
|
||||
context="context",
|
||||
ifc_representation_class="ifc_representation_class",
|
||||
)
|
||||
|
||||
def test_not_adding_a_representation_if_requested_no_default_container(self, ifc, collector, root):
|
||||
ifc.get_entity("obj").should_be_called().will_return(None)
|
||||
root.get_object_name("obj").should_be_called().will_return("name")
|
||||
@@ -189,6 +218,7 @@ class TestAssignClass:
|
||||
).should_be_called().will_return("element")
|
||||
root.set_object_name("obj", "element").should_be_called()
|
||||
ifc.link("element", "obj").should_be_called()
|
||||
root.is_drawing_annotation("element").should_be_called().will_return(False)
|
||||
root.get_default_container().should_be_called().will_return(None)
|
||||
collector.assign("obj").should_be_called()
|
||||
subject.assign_class(
|
||||
|
||||
Reference in New Issue
Block a user