Fix bug where annotative grids did not sync.

This commit is contained in:
Dion Moult
2021-11-12 15:16:10 +11:00
parent 63872abaef
commit 8ac885ced1
3 changed files with 33 additions and 9 deletions
@@ -469,7 +469,8 @@ class CreateDrawing(bpy.types.Operator):
svg_writer.camera_projection = tuple(camera.matrix_world.to_quaternion() @ Vector((0, 0, -1))) svg_writer.camera_projection = tuple(camera.matrix_world.to_quaternion() @ Vector((0, 0, -1)))
for obj in camera.users_collection[0].objects: for obj in camera.users_collection[0].objects:
if "IfcGrid" in obj.name: element = tool.Ifc.get_entity(obj)
if element.ObjectType == "GRID":
svg_writer.annotations.setdefault("grid_objs", []).append(obj) svg_writer.annotations.setdefault("grid_objs", []).append(obj)
elif obj.type == "CAMERA": elif obj.type == "CAMERA":
continue continue
@@ -1232,6 +1233,12 @@ class CopyGrid(bpy.types.Operator):
return helper.get_active_drawing(context.scene)[0] is not None return helper.get_active_drawing(context.scene)[0] is not None
def execute(self, context): def execute(self, context):
subcontext = ifcopenshell.util.representation.get_context(
IfcStore.get_file(), "Plan", "Annotation", context.scene.camera.data.BIMCameraProperties.target_view
)
if not subcontext:
return {"FINISHED"}
proj_coll = helper.get_project_collection(context.scene) proj_coll = helper.get_project_collection(context.scene)
view_coll, camera = helper.get_active_drawing(context.scene) view_coll, camera = helper.get_active_drawing(context.scene)
is_ortho = camera.data.type == "ORTHO" is_ortho = camera.data.type == "ORTHO"
@@ -1240,11 +1247,19 @@ class CopyGrid(bpy.types.Operator):
elevating = is_ortho and camera.data.BIMCameraProperties.target_view in ("ELEVATION_VIEW", "SECTION_VIEW") elevating = is_ortho and camera.data.BIMCameraProperties.target_view in ("ELEVATION_VIEW", "SECTION_VIEW")
def grep(coll): def grep(coll):
return [obj for obj in coll.all_objects if obj.name.startswith("IfcGridAxis")] results = []
for obj in coll.all_objects:
element = tool.Ifc.get_entity(obj)
if element and element.is_a("IfcAnnotation") and element.ObjectType == "GRID":
results.append(obj)
return results
def clone(src): def clone(src):
dst = src.copy() dst = src.copy()
dst.data = dst.data.copy() dst.data = dst.data.copy()
dst.name = dst.name.replace("IfcGridAxis/", "")
dst.BIMObjectProperties.ifc_definition_id = 0
dst.data.BIMMeshProperties.ifc_definition_id = 0
return dst return dst
def disassemble(obj): def disassemble(obj):
@@ -1291,17 +1306,25 @@ class CopyGrid(bpy.types.Operator):
for obj in grep(view_coll): for obj in grep(view_coll):
view_coll.objects.unlink(obj) view_coll.objects.unlink(obj)
grid = [localize(*disassemble(clone(obj))) for obj in grep(proj_coll)] grids = []
for element in tool.Ifc.get().by_type("IfcGridAxis"):
obj = tool.Ifc.get_object(element)
if not obj:
continue
grids.append((*localize(*disassemble(clone(obj))), element))
if clipping: if clipping:
grid = [(obj, clip(mesh)) for obj, mesh in grid] grids = [(obj, clip(mesh), element) for obj, mesh, element in grids]
elif elevating: elif elevating:
grid = [(obj, elev(mesh)) for obj, mesh in grid] grids = [(obj, elev(mesh), element) for obj, mesh, element in grids]
for obj, mesh in grid: for obj, mesh, element in grids:
if mesh is not None: if mesh is not None:
view_coll.objects.link(assemble(obj, mesh)) view_coll.objects.link(assemble(obj, mesh))
bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcAnnotation", context_id=subcontext.id())
annotation = tool.Ifc.get_entity(obj)
annotation.Name = element.AxisTag
annotation.ObjectType = "GRID"
return {"FINISHED"} return {"FINISHED"}
@@ -24,6 +24,7 @@ import pystache
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import svgwrite import svgwrite
import ifcopenshell import ifcopenshell
import blenderbim.tool as tool
import blenderbim.bim.module.drawing.helper as helper import blenderbim.bim.module.drawing.helper as helper
import blenderbim.bim.module.drawing.annotation as annotation import blenderbim.bim.module.drawing.annotation as annotation
from mathutils import Vector from mathutils import Vector
@@ -168,7 +169,7 @@ class SvgWriter:
line["marker-start"] = "url(#grid-marker)" line["marker-start"] = "url(#grid-marker)"
line["marker-end"] = "url(#grid-marker)" line["marker-end"] = "url(#grid-marker)"
line["stroke-dasharray"] = "12.5, 3, 3, 3" line["stroke-dasharray"] = "12.5, 3, 3, 3"
axis_tag = IfcStore.get_file().by_id(grid_obj.BIMObjectProperties.ifc_definition_id).AxisTag axis_tag = tool.Ifc.get_entity(grid_obj).Name
self.svg.add( self.svg.add(
self.svg.text( self.svg.text(
axis_tag, axis_tag,
@@ -271,7 +271,7 @@ class BIM_PT_text(Panel):
class BIM_PT_annotation_utilities(Panel): class BIM_PT_annotation_utilities(Panel):
bl_idname = "BIM_PT_annotation_utilities" bl_idname = "BIM_PT_annotation_utilities"
bl_label = "Annotation" bl_label = "Drawing"
bl_options = {"DEFAULT_CLOSED"} bl_options = {"DEFAULT_CLOSED"}
bl_space_type = "VIEW_3D" bl_space_type = "VIEW_3D"
bl_region_type = "UI" bl_region_type = "UI"