mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Add support for dimensions added with MeasureIt-ARCH
This commit is contained in:
@@ -116,6 +116,7 @@ class SvgWriter():
|
|||||||
self.draw_dimension_annotations(self.ifc_cutter.equal_obj, text_override='EQ')
|
self.draw_dimension_annotations(self.ifc_cutter.equal_obj, text_override='EQ')
|
||||||
if self.ifc_cutter.dimension_obj:
|
if self.ifc_cutter.dimension_obj:
|
||||||
self.draw_dimension_annotations(self.ifc_cutter.dimension_obj)
|
self.draw_dimension_annotations(self.ifc_cutter.dimension_obj)
|
||||||
|
self.draw_measureit_arch_dimension_annotations()
|
||||||
|
|
||||||
if self.ifc_cutter.break_obj:
|
if self.ifc_cutter.break_obj:
|
||||||
self.draw_break_annotations(self.ifc_cutter.break_obj)
|
self.draw_break_annotations(self.ifc_cutter.break_obj)
|
||||||
@@ -340,52 +341,63 @@ class SvgWriter():
|
|||||||
path = self.svg.add(self.svg.path(d=d, class_=' '.join(['breakline'])))
|
path = self.svg.add(self.svg.path(d=d, class_=' '.join(['breakline'])))
|
||||||
|
|
||||||
def draw_dimension_annotations(self, dimension_obj, text_override=None):
|
def draw_dimension_annotations(self, dimension_obj, text_override=None):
|
||||||
x_offset = self.raw_width / 2
|
|
||||||
y_offset = self.raw_height / 2
|
|
||||||
|
|
||||||
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:
|
||||||
points = self.get_spline_points(spline)
|
points = self.get_spline_points(spline)
|
||||||
for i, p in enumerate(points):
|
for i, p in enumerate(points):
|
||||||
if i+1 >= len(points):
|
if i+1 >= len(points):
|
||||||
continue
|
continue
|
||||||
classes = ['annotation', 'dimension', 'blahblah']
|
|
||||||
v0_global = matrix_world @ points[i].co.xyz
|
v0_global = matrix_world @ points[i].co.xyz
|
||||||
v1_global = matrix_world @ points[i+1].co.xyz
|
v1_global = matrix_world @ points[i+1].co.xyz
|
||||||
v0 = self.project_point_onto_camera(v0_global)
|
self.draw_dimension_annotation(v0_global, v1_global, text_override)
|
||||||
v1 = self.project_point_onto_camera(v1_global)
|
|
||||||
start = Vector(((x_offset + v0.x), (y_offset - v0.y)))
|
def draw_measureit_arch_dimension_annotations(self):
|
||||||
end = Vector(((x_offset + v1.x), (y_offset - v1.y)))
|
try:
|
||||||
mid = ((end - start) / 2) + start
|
import MeasureIt_ARCH.measureit_arch_external_utils
|
||||||
# TODO: hardcoded meters to mm conversion, until I properly do units
|
coords = MeasureIt_ARCH.measureit_arch_external_utils.blenderBIM_get_coords(bpy.context)
|
||||||
vector = end - start
|
except:
|
||||||
perpendicular = Vector((vector.y, -vector.x)).normalized()
|
return
|
||||||
dimension = (v1_global - v0_global).length * 1000
|
for coord in coords:
|
||||||
sheet_dimension = ((end*self.scale) - (start*self.scale)).length
|
self.draw_dimension_annotation(Vector(coord[0]), Vector(coord[1]))
|
||||||
if sheet_dimension < 5: # annotation can't fit
|
|
||||||
# offset text to right of marker
|
def draw_dimension_annotation(self, v0_global, v1_global, text_override=None):
|
||||||
text_position = (end * self.scale) + perpendicular + (3 * vector.normalized())
|
classes = ['annotation', 'dimension']
|
||||||
else:
|
x_offset = self.raw_width / 2
|
||||||
text_position = (mid * self.scale) + perpendicular
|
y_offset = self.raw_height / 2
|
||||||
rotation = math.degrees(vector.angle_signed(Vector((1, 0))))
|
v0 = self.project_point_onto_camera(v0_global)
|
||||||
line = self.svg.add(self.svg.line(start=tuple(start * self.scale),
|
v1 = self.project_point_onto_camera(v1_global)
|
||||||
end=tuple(end * self.scale), class_=' '.join(classes)))
|
start = Vector(((x_offset + v0.x), (y_offset - v0.y)))
|
||||||
line['marker-start'] = 'url(#dimension-marker-start)'
|
end = Vector(((x_offset + v1.x), (y_offset - v1.y)))
|
||||||
line['marker-end'] = 'url(#dimension-marker-end)'
|
mid = ((end - start) / 2) + start
|
||||||
if text_override is not None:
|
# TODO: hardcoded meters to mm conversion, until I properly do units
|
||||||
text = text_override
|
vector = end - start
|
||||||
else:
|
perpendicular = Vector((vector.y, -vector.x)).normalized()
|
||||||
text = str(round(dimension))
|
dimension = (v1_global - v0_global).length * 1000
|
||||||
self.svg.add(self.svg.text(text, insert=tuple(text_position), **{
|
sheet_dimension = ((end*self.scale) - (start*self.scale)).length
|
||||||
'transform': 'rotate({} {} {})'.format(
|
if sheet_dimension < 5: # annotation can't fit
|
||||||
rotation,
|
# offset text to right of marker
|
||||||
text_position.x,
|
text_position = (end * self.scale) + perpendicular + (3 * vector.normalized())
|
||||||
text_position.y
|
else:
|
||||||
),
|
text_position = (mid * self.scale) + perpendicular
|
||||||
'font-size': annotation.Annotator.get_svg_text_size(2.5),
|
rotation = math.degrees(vector.angle_signed(Vector((1, 0))))
|
||||||
'font-family': 'OpenGost Type B TT',
|
line = self.svg.add(self.svg.line(start=tuple(start * self.scale),
|
||||||
'text-anchor': 'middle'
|
end=tuple(end * self.scale), class_=' '.join(classes)))
|
||||||
}))
|
line['marker-start'] = 'url(#dimension-marker-start)'
|
||||||
|
line['marker-end'] = 'url(#dimension-marker-end)'
|
||||||
|
if text_override is not None:
|
||||||
|
text = text_override
|
||||||
|
else:
|
||||||
|
text = str(round(dimension))
|
||||||
|
self.svg.add(self.svg.text(text, insert=tuple(text_position), **{
|
||||||
|
'transform': 'rotate({} {} {})'.format(
|
||||||
|
rotation,
|
||||||
|
text_position.x,
|
||||||
|
text_position.y
|
||||||
|
),
|
||||||
|
'font-size': annotation.Annotator.get_svg_text_size(2.5),
|
||||||
|
'font-family': 'OpenGost Type B TT',
|
||||||
|
'text-anchor': 'middle'
|
||||||
|
}))
|
||||||
|
|
||||||
def project_point_onto_camera(self, point):
|
def project_point_onto_camera(self, point):
|
||||||
return self.ifc_cutter.camera_obj.matrix_world.inverted() @ geometry.intersect_line_plane(
|
return self.ifc_cutter.camera_obj.matrix_world.inverted() @ geometry.intersect_line_plane(
|
||||||
|
|||||||
Reference in New Issue
Block a user