From 2d67950503560b2fb4021435299db222b8dbb1ef Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 18 May 2023 14:07:48 +0500 Subject: [PATCH] 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. --- .../blenderbim/bim/module/drawing/workspace.py | 4 ++-- .../blenderbim/bim/module/geometry/operator.py | 7 +++++++ src/blenderbim/blenderbim/core/drawing.py | 4 +++- src/blenderbim/blenderbim/core/tool.py | 2 +- src/blenderbim/blenderbim/tool/drawing.py | 9 +++++++-- src/blenderbim/test/core/test_drawing.py | 4 ++-- src/blenderbim/test/tool/test_drawing.py | 4 ++++ 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/workspace.py b/src/blenderbim/blenderbim/bim/module/drawing/workspace.py index 3cdbbbaa7a..6c048c8dd7 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/workspace.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/workspace.py @@ -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, diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 972650a313..a82fdbddb3 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -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": diff --git a/src/blenderbim/blenderbim/core/drawing.py b/src/blenderbim/blenderbim/core/drawing.py index c097564e68..873c554ba0 100644 --- a/src/blenderbim/blenderbim/core/drawing.py +++ b/src/blenderbim/blenderbim/core/drawing.py @@ -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" diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index d52f4ecdd6..5c1a55aa7e 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -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 diff --git a/src/blenderbim/blenderbim/tool/drawing.py b/src/blenderbim/blenderbim/tool/drawing.py index 636b544a58..ee0b4f3590 100644 --- a/src/blenderbim/blenderbim/tool/drawing.py +++ b/src/blenderbim/blenderbim/tool/drawing.py @@ -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) diff --git a/src/blenderbim/test/core/test_drawing.py b/src/blenderbim/test/core/test_drawing.py index 6dc9417c99..e35be93fe0 100644 --- a/src/blenderbim/test/core/test_drawing.py +++ b/src/blenderbim/test/core/test_drawing.py @@ -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") diff --git a/src/blenderbim/test/tool/test_drawing.py b/src/blenderbim/test/tool/test_drawing.py index ffef47f4ae..4ea61d372c 100644 --- a/src/blenderbim/test/tool/test_drawing.py +++ b/src/blenderbim/test/tool/test_drawing.py @@ -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):