Annotation contexts are now drawn as solid lines in section cuts

This commit is contained in:
Dion Moult
2020-05-09 22:26:39 +10:00
parent 2a8251fc94
commit af11ebdc4f
2 changed files with 45 additions and 17 deletions
+31 -14
View File
@@ -1,4 +1,5 @@
import os
import bpy
import math
import time
import numpy
@@ -867,13 +868,14 @@ class SvgWriter():
'dominant-baseline': 'middle'
}))
for obj in self.ifc_cutter.hidden_objs:
self.draw_line_annotation(obj, ['hidden'])
for obj_data in self.ifc_cutter.hidden_objs:
self.draw_line_annotation(obj_data, ['hidden'])
for obj in self.ifc_cutter.solid_objs:
self.draw_line_annotation(obj, ['solid'])
for obj_data in self.ifc_cutter.solid_objs:
self.draw_line_annotation(obj_data, ['solid'])
self.draw_line_annotation(self.ifc_cutter.leader_obj, ['leader'])
if self.ifc_cutter.leader_obj:
self.draw_line_annotation(self.ifc_cutter.leader_obj, ['leader'])
if self.ifc_cutter.plan_level_obj:
for spline in self.ifc_cutter.plan_level_obj.data.splines:
@@ -951,21 +953,36 @@ class SvgWriter():
self.draw_text_annotations()
def draw_line_annotation(self, obj, classes):
def draw_line_annotation(self, obj_data, classes):
# TODO: properly scope these offsets
x_offset = self.raw_width / 2
y_offset = self.raw_height / 2
obj, data = obj_data
classes.extend(['annotation'])
matrix_world = obj.matrix_world
for spline in obj.data.splines:
points = self.get_spline_points(spline)
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in points]
d = ' '.join(['L {} {}'.format(
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
for p in projected_points])
d = 'M{}'.format(d[1:])
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
if isinstance(data, bpy.types.Curve):
for spline in data.splines:
points = self.get_spline_points(spline)
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in points]
d = ' '.join(['L {} {}'.format(
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
for p in projected_points])
d = 'M{}'.format(d[1:])
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
elif isinstance(data, bpy.types.Mesh):
for edge in data.edges:
v0_global = matrix_world @ data.vertices[edge.vertices[0]].co.xyz
v1_global = matrix_world @ data.vertices[edge.vertices[1]].co.xyz
v0 = self.project_point_onto_camera(v0_global)
v1 = self.project_point_onto_camera(v1_global)
start = Vector(((x_offset + v0.x), (y_offset - v0.y)))
end = Vector(((x_offset + v1.x), (y_offset - v1.y)))
vector = end - start
line = self.svg.add(self.svg.line(start=tuple(start * self.scale),
end=tuple(end * self.scale), class_=' '.join(classes)))
def draw_text_annotations(self):
x_offset = self.raw_width / 2
@@ -1588,7 +1588,7 @@ class CutSection(bpy.types.Operator):
ifc_cutter.text_objs = []
for obj in camera.users_collection[0].objects:
if 'Leader' in obj.name:
ifc_cutter.leader_obj = obj
ifc_cutter.leader_obj = (obj, obj.data)
elif 'Stair' in obj.name:
ifc_cutter.stair_obj = obj
elif 'Equal' in obj.name:
@@ -1596,9 +1596,9 @@ class CutSection(bpy.types.Operator):
elif 'Dimension' in obj.name:
ifc_cutter.dimension_obj = obj
elif 'Hidden' in obj.name:
ifc_cutter.hidden_objs.append(obj)
ifc_cutter.hidden_objs.append((obj, obj.data))
elif 'Solid' in obj.name:
ifc_cutter.solid_objs.append(obj)
ifc_cutter.solid_objs.append((obj, obj.data))
elif 'IfcGrid' in obj.name:
ifc_cutter.grid_objs.append(obj)
elif 'Plan Level' in obj.name:
@@ -1609,6 +1609,17 @@ class CutSection(bpy.types.Operator):
ifc_cutter.camera_obj = obj
elif obj.type == 'FONT':
ifc_cutter.text_objs.append(obj)
for obj in bpy.context.visible_objects:
for subcontext in obj.BIMObjectProperties.representation_contexts:
if subcontext.context == 'Plan' \
and subcontext.name == 'Annotation' \
and subcontext.target_view == 'PLAN_VIEW' \
and '/' in obj.data.name:
data = bpy.data.meshes.get('Plan/Annotation/PLAN_VIEW/{}'.format(obj.data.name.split('/')[-1]))
if data:
ifc_cutter.solid_objs.append((obj, data))
ifc_cutter.section_box = {
'projection': tuple(projection),
'x_axis': tuple(x_axis),