mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
Annotation contexts are now drawn as solid lines in section cuts
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import bpy
|
||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
import numpy
|
import numpy
|
||||||
@@ -867,13 +868,14 @@ class SvgWriter():
|
|||||||
'dominant-baseline': 'middle'
|
'dominant-baseline': 'middle'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
for obj in self.ifc_cutter.hidden_objs:
|
for obj_data in self.ifc_cutter.hidden_objs:
|
||||||
self.draw_line_annotation(obj, ['hidden'])
|
self.draw_line_annotation(obj_data, ['hidden'])
|
||||||
|
|
||||||
for obj in self.ifc_cutter.solid_objs:
|
for obj_data in self.ifc_cutter.solid_objs:
|
||||||
self.draw_line_annotation(obj, ['solid'])
|
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:
|
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:
|
||||||
@@ -951,21 +953,36 @@ class SvgWriter():
|
|||||||
|
|
||||||
self.draw_text_annotations()
|
self.draw_text_annotations()
|
||||||
|
|
||||||
def draw_line_annotation(self, obj, classes):
|
def draw_line_annotation(self, obj_data, classes):
|
||||||
# TODO: properly scope these offsets
|
# TODO: properly scope these offsets
|
||||||
x_offset = self.raw_width / 2
|
x_offset = self.raw_width / 2
|
||||||
y_offset = self.raw_height / 2
|
y_offset = self.raw_height / 2
|
||||||
|
|
||||||
|
obj, data = obj_data
|
||||||
|
|
||||||
classes.extend(['annotation'])
|
classes.extend(['annotation'])
|
||||||
matrix_world = obj.matrix_world
|
matrix_world = obj.matrix_world
|
||||||
for spline in obj.data.splines:
|
|
||||||
points = self.get_spline_points(spline)
|
if isinstance(data, bpy.types.Curve):
|
||||||
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in points]
|
for spline in data.splines:
|
||||||
d = ' '.join(['L {} {}'.format(
|
points = self.get_spline_points(spline)
|
||||||
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
|
projected_points = [self.project_point_onto_camera(matrix_world @ p.co.xyz) for p in points]
|
||||||
for p in projected_points])
|
d = ' '.join(['L {} {}'.format(
|
||||||
d = 'M{}'.format(d[1:])
|
(x_offset + p.x) * self.scale, (y_offset - p.y) * self.scale)
|
||||||
path = self.svg.add(self.svg.path(d=d, class_=' '.join(classes)))
|
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):
|
def draw_text_annotations(self):
|
||||||
x_offset = self.raw_width / 2
|
x_offset = self.raw_width / 2
|
||||||
|
|||||||
@@ -1588,7 +1588,7 @@ class CutSection(bpy.types.Operator):
|
|||||||
ifc_cutter.text_objs = []
|
ifc_cutter.text_objs = []
|
||||||
for obj in camera.users_collection[0].objects:
|
for obj in camera.users_collection[0].objects:
|
||||||
if 'Leader' in obj.name:
|
if 'Leader' in obj.name:
|
||||||
ifc_cutter.leader_obj = obj
|
ifc_cutter.leader_obj = (obj, obj.data)
|
||||||
elif 'Stair' in obj.name:
|
elif 'Stair' in obj.name:
|
||||||
ifc_cutter.stair_obj = obj
|
ifc_cutter.stair_obj = obj
|
||||||
elif 'Equal' in obj.name:
|
elif 'Equal' in obj.name:
|
||||||
@@ -1596,9 +1596,9 @@ class CutSection(bpy.types.Operator):
|
|||||||
elif 'Dimension' in obj.name:
|
elif 'Dimension' in obj.name:
|
||||||
ifc_cutter.dimension_obj = obj
|
ifc_cutter.dimension_obj = obj
|
||||||
elif 'Hidden' in obj.name:
|
elif 'Hidden' in obj.name:
|
||||||
ifc_cutter.hidden_objs.append(obj)
|
ifc_cutter.hidden_objs.append((obj, obj.data))
|
||||||
elif 'Solid' in obj.name:
|
elif 'Solid' in obj.name:
|
||||||
ifc_cutter.solid_objs.append(obj)
|
ifc_cutter.solid_objs.append((obj, obj.data))
|
||||||
elif 'IfcGrid' in obj.name:
|
elif 'IfcGrid' in obj.name:
|
||||||
ifc_cutter.grid_objs.append(obj)
|
ifc_cutter.grid_objs.append(obj)
|
||||||
elif 'Plan Level' in obj.name:
|
elif 'Plan Level' in obj.name:
|
||||||
@@ -1609,6 +1609,17 @@ class CutSection(bpy.types.Operator):
|
|||||||
ifc_cutter.camera_obj = obj
|
ifc_cutter.camera_obj = obj
|
||||||
elif obj.type == 'FONT':
|
elif obj.type == 'FONT':
|
||||||
ifc_cutter.text_objs.append(obj)
|
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 = {
|
ifc_cutter.section_box = {
|
||||||
'projection': tuple(projection),
|
'projection': tuple(projection),
|
||||||
'x_axis': tuple(x_axis),
|
'x_axis': tuple(x_axis),
|
||||||
|
|||||||
Reference in New Issue
Block a user