From 9c8f8ba56f5716fc185df0620e79f953155d1a35 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 2 Sep 2020 21:50:58 +1000 Subject: [PATCH] You can now add arbitrary annotation to a drawing, not just belonging to one of the preset types --- .../blenderbim/bim/operator.py | 15 +++++++++---- .../blenderbim/bim/svgwriter.py | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index f380018f9e..c30cb533b0 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -2152,7 +2152,16 @@ class CutSection(bpy.types.Operator): ifc_cutter.section_level_obj = None ifc_cutter.grid_objs = [] ifc_cutter.text_objs = [] + ifc_cutter.misc_objs = [] for obj in camera.users_collection[0].objects: + if 'IfcGrid' in obj.name: + ifc_cutter.grid_objs.append(obj) + elif 'IfcGroup' in obj.name and obj.type == 'CAMERA': + ifc_cutter.camera_obj = obj + + if 'IfcAnnotation/' not in obj.name: + continue + if 'Leader' in obj.name: ifc_cutter.leader_obj = (obj, obj.data) elif 'Stair' in obj.name: @@ -2167,16 +2176,14 @@ class CutSection(bpy.types.Operator): ifc_cutter.hidden_objs.append((obj, obj.data)) elif 'Solid' in obj.name: 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: ifc_cutter.plan_level_obj = obj elif 'Section Level' in obj.name: ifc_cutter.section_level_obj = obj - elif obj.type == 'CAMERA': - ifc_cutter.camera_obj = obj elif obj.type == 'FONT': ifc_cutter.text_objs.append(obj) + else: + ifc_cutter.misc_objs.append(obj) ifc_cutter.section_box = { 'projection': tuple(projection), diff --git a/src/ifcblenderexport/blenderbim/bim/svgwriter.py b/src/ifcblenderexport/blenderbim/bim/svgwriter.py index d615a945ce..0d77b0b584 100644 --- a/src/ifcblenderexport/blenderbim/bim/svgwriter.py +++ b/src/ifcblenderexport/blenderbim/bim/svgwriter.py @@ -159,6 +159,9 @@ class SvgWriter(): self.draw_ifc_annotation() + for obj in self.ifc_cutter.misc_objs: + self.draw_misc_annotation(obj, ['IfcAnnotation']) + for obj_data in self.ifc_cutter.hidden_objs: self.draw_line_annotation(obj_data, ['hidden']) @@ -264,6 +267,25 @@ class SvgWriter(): line = self.svg.add(self.svg.line(start=tuple(start * self.scale), end=tuple(end * self.scale), class_=' '.join(annotation['classes']))) + def draw_misc_annotation(self, obj, classes): + # We have to decide whether this should come from Blender or from IFC. + # For the moment, for convenience of experimenting with ideas, it comes + # from Blender. In the future, it should probably come from IFC. + classes.extend(self.get_attribute_classes(obj)) + if len(obj.data.polygons) == 0: + self.draw_edge_annotation(obj, classes) + return + x_offset = self.raw_width / 2 + y_offset = self.raw_height / 2 + matrix_world = obj.matrix_world + for polygon in obj.data.polygons: + points = [obj.data.vertices[v] for v in polygon.vertices] + 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))) def draw_line_annotation(self, obj_data, classes): # TODO: properly scope these offsets x_offset = self.raw_width / 2