mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
3d annotations for FALL, SECTION_LEVEL, PLAN_LEVEL #3145
Before that commit if you created those types of annotations and then reopened .ifc file (without .blend) then you would lose their z coordinate and therefore would lose their value (because they were created previously as 2d annotations). Now those annotations created as 3d to avoid that problem. I've also added temporary fallback that will turn your existing annotations to 3d next time you edit them.
This commit is contained in:
@@ -108,7 +108,7 @@ def create_annotation_type(context):
|
||||
tool.Drawing.ensure_annotation_in_drawing_plane(obj)
|
||||
|
||||
drawing = tool.Ifc.get_entity(context.scene.camera)
|
||||
ifc_context = tool.Drawing.get_annotation_context(tool.Drawing.get_drawing_target_view(drawing))
|
||||
ifc_context = tool.Drawing.get_annotation_context(tool.Drawing.get_drawing_target_view(drawing), object_type)
|
||||
|
||||
element = tool.Drawing.run_root_assign_class(
|
||||
obj=obj,
|
||||
@@ -133,7 +133,7 @@ def create_annotation_occurence(context):
|
||||
drawing = tool.Ifc.get_entity(context.scene.camera)
|
||||
obj = tool.Drawing.create_annotation_object(drawing, object_type)
|
||||
obj.name = relating_type.Name
|
||||
ifc_context = tool.Drawing.get_annotation_context(tool.Drawing.get_drawing_target_view(drawing))
|
||||
ifc_context = tool.Drawing.get_annotation_context(tool.Drawing.get_drawing_target_view(drawing), object_type)
|
||||
relating_type_repr = tool.Drawing.get_annotation_representation(relating_type)
|
||||
element = tool.Drawing.run_root_assign_class(
|
||||
obj=obj,
|
||||
|
||||
@@ -199,6 +199,13 @@ class UpdateRepresentation(bpy.types.Operator, Operator):
|
||||
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||
context_of_items = old_representation.ContextOfItems
|
||||
|
||||
# TODO: remove this code a bit later
|
||||
# added this as a fallback for easier transition some annotation types to 3d
|
||||
# if they were create before as 2d
|
||||
element = tool.Ifc.get_entity(obj)
|
||||
if tool.Drawing.is_annotation_object_type(element, ("FALL", "SECTION_LEVEL", "PLAN_LEVEL")):
|
||||
context_of_items = tool.Drawing.get_annotation_context("MODEL_VIEW")
|
||||
|
||||
gprop = context.scene.BIMGeoreferenceProperties
|
||||
coordinate_offset = None
|
||||
if gprop.has_blender_offset and obj.BIMObjectProperties.blender_offset_type == "CARTESIAN_POINT":
|
||||
|
||||
@@ -325,7 +325,9 @@ def update_drawing_name(ifc, drawing_tool, drawing=None, name=None):
|
||||
|
||||
|
||||
def add_annotation(ifc, collector, drawing_tool, drawing=None, object_type=None):
|
||||
context = drawing_tool.get_annotation_context(target_view := drawing_tool.get_drawing_target_view(drawing))
|
||||
context = drawing_tool.get_annotation_context(
|
||||
target_view := drawing_tool.get_drawing_target_view(drawing), object_type
|
||||
)
|
||||
if not context:
|
||||
return f"No annotation context Annotation/{target_view} for drawing"
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ class Drawing:
|
||||
def generate_drawing_matrix(cls, target_view, location_hint): pass
|
||||
def generate_drawing_name(cls, target_view, location_hint): pass
|
||||
def generate_sheet_identification(cls): pass
|
||||
def get_annotation_context(cls, target_view): pass
|
||||
def get_annotation_context(cls, target_view, object_type=None): pass
|
||||
def get_assigned_product(cls, element): pass
|
||||
def get_body_context(cls): pass
|
||||
def get_default_drawing_path(cls, name): pass
|
||||
|
||||
@@ -315,8 +315,13 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
return literals
|
||||
|
||||
@classmethod
|
||||
def get_annotation_context(cls, target_view):
|
||||
if target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW"):
|
||||
def get_annotation_context(cls, target_view, object_type=None):
|
||||
# checking PLAN target view and annotation type that doesn't require 3d
|
||||
if target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW") and object_type not in (
|
||||
"FALL",
|
||||
"SECTION_LEVEL",
|
||||
"PLAN_LEVEL",
|
||||
):
|
||||
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Plan", "Annotation", target_view)
|
||||
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Annotation", target_view)
|
||||
|
||||
|
||||
@@ -429,7 +429,7 @@ class TestAddAnnotation:
|
||||
def test_run(self, ifc, collector, drawing):
|
||||
drawing.show_decorations().should_be_called()
|
||||
drawing.get_drawing_target_view("drawing").should_be_called().will_return("target_view")
|
||||
drawing.get_annotation_context("target_view").should_be_called().will_return("context")
|
||||
drawing.get_annotation_context("target_view", "object_type").should_be_called().will_return("context")
|
||||
drawing.create_annotation_object("drawing", "object_type").should_be_called().will_return("obj")
|
||||
ifc.get_entity("obj").should_be_called().will_return(None)
|
||||
drawing.get_ifc_representation_class("object_type").should_be_called().will_return("ifc_representation_class")
|
||||
@@ -449,5 +449,5 @@ class TestAddAnnotation:
|
||||
|
||||
def test_do_not_add_without_an_annotation_context(self, ifc, collector, drawing):
|
||||
drawing.get_drawing_target_view("drawing").should_be_called().will_return("target_view")
|
||||
drawing.get_annotation_context("target_view").should_be_called().will_return(None)
|
||||
drawing.get_annotation_context("target_view", "object_type").should_be_called().will_return(None)
|
||||
subject.add_annotation(ifc, collector, drawing, drawing="drawing", object_type="object_type")
|
||||
|
||||
@@ -235,9 +235,13 @@ class TestGetAnnotationContext(NewFile):
|
||||
context2 = ifc.createIfcGeometricRepresentationSubContext(
|
||||
ContextType="Model", ContextIdentifier="Annotation", TargetView="ELEVATION_VIEW"
|
||||
)
|
||||
context3 = ifc.createIfcGeometricRepresentationSubContext(
|
||||
ContextType="Model", ContextIdentifier="Annotation", TargetView="PLAN_VIEW"
|
||||
)
|
||||
tool.Ifc.set(ifc)
|
||||
assert subject.get_annotation_context("PLAN_VIEW") == context
|
||||
assert subject.get_annotation_context("ELEVATION_VIEW") == context2
|
||||
assert subject.get_annotation_context("PLAN_VIEW", "FALL") == context3
|
||||
|
||||
|
||||
class TestGetBodyContext(NewFile):
|
||||
|
||||
Reference in New Issue
Block a user