Allow any type of curve to be used for construction documentation annotation

This commit is contained in:
Dion Moult
2020-03-24 10:34:58 +11:00
parent 662a9fdad7
commit 44d884590a
+24 -16
View File
@@ -793,7 +793,8 @@ class SvgWriter():
matrix_world = self.ifc_cutter.leader_obj.matrix_world matrix_world = self.ifc_cutter.leader_obj.matrix_world
for spline in self.ifc_cutter.leader_obj.data.splines: for spline in self.ifc_cutter.leader_obj.data.splines:
classes = ['annotation', 'leader'] classes = ['annotation', 'leader']
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in spline.points] 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( d = ' '.join(['L {} {}'.format(
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale) (x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
for p in projected_points]) for p in projected_points])
@@ -804,18 +805,19 @@ class SvgWriter():
if self.ifc_cutter.plan_level_obj: if self.ifc_cutter.plan_level_obj:
for spline in self.ifc_cutter.plan_level_obj.data.splines: for spline in self.ifc_cutter.plan_level_obj.data.splines:
classes = ['annotation', 'plan-level'] classes = ['annotation', 'plan-level']
d = ' '.join(['L {} {}'.format((x_offset + p.co.x) * self.scale, (y_offset - p.co.y) * self.scale) for p in spline.points]) points = self.get_spline_points(spline)
d = ' '.join(['L {} {}'.format((x_offset + p.co.x) * self.scale, (y_offset - p.co.y) * self.scale) for p in points])
d = 'M{}'.format(d[1:]) d = 'M{}'.format(d[1:])
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes))) path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
path['marker-end'] = 'url(#plan-level-marker)' path['marker-end'] = 'url(#plan-level-marker)'
text_position = Vector(( text_position = Vector((
(x_offset + spline.points[0].co.x) * self.scale, (x_offset + points[0].co.x) * self.scale,
((y_offset - spline.points[0].co.y) * self.scale) - 2.5 ((y_offset - points[0].co.y) * self.scale) - 2.5
)) ))
# TODO: unhardcode m unit # TODO: unhardcode m unit
rl = ((self.ifc_cutter.plan_level_obj.matrix_world @ rl = ((self.ifc_cutter.plan_level_obj.matrix_world @
spline.points[0].co).xyz + self.ifc_cutter.plan_level_obj.location).z points[0].co).xyz + self.ifc_cutter.plan_level_obj.location).z
if spline.points[0].co.x > spline.points[-1].co.x: if points[0].co.x > points[-1].co.x:
text_anchor = 'end' text_anchor = 'end'
else: else:
text_anchor = 'start' text_anchor = 'start'
@@ -831,7 +833,8 @@ class SvgWriter():
matrix_world = self.ifc_cutter.section_level_obj.matrix_world matrix_world = self.ifc_cutter.section_level_obj.matrix_world
for spline in self.ifc_cutter.section_level_obj.data.splines: for spline in self.ifc_cutter.section_level_obj.data.splines:
classes = ['annotation', 'section-level'] classes = ['annotation', 'section-level']
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in spline.points] 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( d = ' '.join(['L {} {}'.format(
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale) (x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
for p in projected_points]) for p in projected_points])
@@ -844,7 +847,7 @@ class SvgWriter():
((y_offset - projected_points[0].y) * self.scale) - 3.5 ((y_offset - projected_points[0].y) * self.scale) - 3.5
)) ))
# TODO: unhardcode m unit # TODO: unhardcode m unit
rl = (matrix_world @ spline.points[0].co.xyz).z rl = (matrix_world @ points[0].co.xyz).z
self.svg.add(self.svg.text('RL +{:.3f}m'.format(rl), insert=tuple(text_position), **{ self.svg.add(self.svg.text('RL +{:.3f}m'.format(rl), insert=tuple(text_position), **{
'font-size': '4.13', # 2.5 'font-size': '4.13', # 2.5
'font-family': 'OpenGost Type B TT', 'font-family': 'OpenGost Type B TT',
@@ -856,10 +859,11 @@ class SvgWriter():
if self.ifc_cutter.stair_obj: if self.ifc_cutter.stair_obj:
for spline in self.ifc_cutter.stair_obj.data.splines: for spline in self.ifc_cutter.stair_obj.data.splines:
classes = ['annotation', 'stair'] classes = ['annotation', 'stair']
d = ' '.join(['L {} {}'.format((x_offset + p.co.x) * self.scale, (y_offset - p.co.y) * self.scale) for p in spline.points]) points = self.get_spline_points(spline)
d = ' '.join(['L {} {}'.format((x_offset + p.co.x) * self.scale, (y_offset - p.co.y) * self.scale) for p in points])
d = 'M{}'.format(d[1:]) d = 'M{}'.format(d[1:])
start = Vector(((x_offset + spline.points[0].co.x), (y_offset - spline.points[0].co.y))) start = Vector(((x_offset + points[0].co.x), (y_offset - points[0].co.y)))
next_point = Vector(((x_offset + spline.points[1].co.x), (y_offset - spline.points[1].co.y))) next_point = Vector(((x_offset + points[1].co.x), (y_offset - points[1].co.y)))
text_position = (start * self.scale) - ((next_point - start).normalized() * 5) text_position = (start * self.scale) - ((next_point - start).normalized() * 5)
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes))) path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
path['marker-start'] = 'url(#stair-marker-start)' path['marker-start'] = 'url(#stair-marker-start)'
@@ -910,12 +914,13 @@ class SvgWriter():
matrix_world = dimension_obj.matrix_world matrix_world = dimension_obj.matrix_world
for spline in dimension_obj.data.splines: for spline in dimension_obj.data.splines:
for i, p in enumerate(spline.points): points = self.get_spline_points(spline)
if i+1 >= len(spline.points): for i, p in enumerate(points):
if i+1 >= len(points):
continue continue
classes = ['annotation', 'dimension'] classes = ['annotation', 'dimension', 'blahblah']
v0_global = matrix_world @ spline.points[i].co.xyz v0_global = matrix_world @ points[i].co.xyz
v1_global = matrix_world @ spline.points[i+1].co.xyz v1_global = matrix_world @ points[i+1].co.xyz
v0 = self.project_point_onto_camera(v0_global) v0 = self.project_point_onto_camera(v0_global)
v1 = self.project_point_onto_camera(v1_global) v1 = self.project_point_onto_camera(v1_global)
start = Vector(((x_offset + v0.x), (y_offset - v0.y))) start = Vector(((x_offset + v0.x), (y_offset - v0.y)))
@@ -961,6 +966,9 @@ class SvgWriter():
Vector(self.ifc_cutter.section_box['projection']) Vector(self.ifc_cutter.section_box['projection'])
) )
def get_spline_points(self, spline):
return spline.bezier_points if spline.bezier_points else spline.points
def draw_cut_polygons(self): def draw_cut_polygons(self):
for polygon in self.ifc_cutter.cut_polygons: for polygon in self.ifc_cutter.cut_polygons:
self.draw_polygon(polygon, 'cut') self.draw_polygon(polygon, 'cut')