#1153. Add support for elevation symbols in generated SVGs.

This commit is contained in:
Dion Moult
2022-03-29 20:30:10 +11:00
parent 2c6cb2fbb2
commit 6cd4a2d78b
3 changed files with 37 additions and 5 deletions
@@ -5,6 +5,13 @@
</g>
<g id="door-tag">
<circle cy="1.75" r="5" fill="white" stroke="black" style="stroke-width: 0.25;" />
<line x1="-5" y1="1.75" x2="5" y2="1.75" style="stroke:black; stroke-width: 0.25;" />
<line x1="-5" y1="1.75" x2="5" y2="1.75" style="stroke: black; stroke-width: 0.25;" />
</g>
<g id="elevation-arrow">
<path style="fill: black;" d="M -7.07106 0 0 -7.07106 7.07106 0" />
</g>
<g id="elevation-tag">
<circle r="5" fill="white" stroke="black" style="stroke-width: 0.25;" />
<line x1="-5" y1="0" x2="5" y2="0" style="stroke: black; stroke-width: 0.25;" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 893 B

@@ -457,6 +457,8 @@ class CreateDrawing(bpy.types.Operator):
svg_writer.annotations.setdefault("equal_objs", []).append(obj)
elif element.ObjectType == "DIMENSION":
svg_writer.annotations.setdefault("dimension_objs", []).append(obj)
elif element.ObjectType == "ELEVATION":
svg_writer.annotations.setdefault("elevation_objs", []).append(obj)
elif element.ObjectType == "BREAKLINE":
svg_writer.annotations["break_obj"] = obj
elif element.ObjectType == "HIDDEN_LINE":
@@ -681,6 +683,7 @@ class ActivateView(bpy.types.Operator):
project_collection.children["Views"].children[camera.users_collection[0].name].hide_viewport = False
bpy.data.collections.get(camera.users_collection[0].name).hide_render = False
bpy.context.scene.DocProperties.active_drawing_id = self.drawing
bpy.ops.bim.activate_drawing_style()
core.sync_references(tool.Ifc, tool.Collector, tool.Drawing, drawing=tool.Ifc.get().by_id(self.drawing))
return {"FINISHED"}
@@ -286,7 +286,12 @@ class SvgWriter:
},
)
)
self.draw_text_annotations()
for obj in self.annotations.get("elevation_objs", []):
self.draw_elevation_annotation(obj)
for text_obj in self.annotations.get("text_objs", []):
self.draw_text_annotation(text_obj, text_obj.location)
def draw_ifc_annotation(self):
x_offset = self.raw_width / 2
@@ -425,9 +430,25 @@ class SvgWriter:
position = Vector((0, 0, 0))
self.draw_text_annotation(obj, position)
def draw_text_annotations(self):
for text_obj in self.annotations.get("text_objs", []):
self.draw_text_annotation(text_obj, text_obj.location)
def draw_elevation_annotation(self, obj):
x_offset = self.raw_width / 2
y_offset = self.raw_height / 2
symbol_position = self.project_point_onto_camera(obj.location)
symbol_position = Vector(((x_offset + symbol_position.x), (y_offset - symbol_position.y)))
v1 = self.project_point_onto_camera(obj.matrix_world @ Vector((0, 0, 0)))
v2 = self.project_point_onto_camera(obj.matrix_world @ Vector((0, 0, -1)))
angle = -math.degrees((v2 - v1).xy.angle_signed(Vector((0, 1))))
transform = "rotate({}, {}, {})".format(
angle,
(symbol_position * self.scale)[0],
(symbol_position * self.scale)[1],
)
self.svg.add(self.svg.use("#elevation-arrow", insert=tuple(symbol_position * self.scale), transform=transform))
self.svg.add(self.svg.use("#elevation-tag", insert=tuple(symbol_position * self.scale)))
def draw_text_annotation(self, text_obj, position):
x_offset = self.raw_width / 2
@@ -646,6 +667,7 @@ class SvgWriter:
)
def project_point_onto_camera(self, point):
# TODO is this needlessly complex?
return self.camera.matrix_world.inverted() @ geometry.intersect_line_plane(
point.xyz,
point.xyz - Vector(self.camera_projection),