diff --git a/src/ifcblenderexport/blenderbim/bim/data/templates/titleblock.svg b/src/ifcblenderexport/blenderbim/bim/data/templates/titleblock.svg index c38141d29b..9b8b8be18b 100644 --- a/src/ifcblenderexport/blenderbim/bim/data/templates/titleblock.svg +++ b/src/ifcblenderexport/blenderbim/bim/data/templates/titleblock.svg @@ -5,10 +5,11 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" - width="841mm" - height="594mm" + viewBox="0 0 841 594" + id="root" version="1.1" - id="root"> + height="594mm" + width="841mm"> /home/dion/Projects/IfcOpenShell/src/ifcblenderexport/titleblock.dxf - scale = 1.000000, origin = (0.000000, 0.000000), method = manual + width="841" + height="594" + x="-4.3253262e-05" + y="3.1719057e-05" /> + style="stroke-width:0.94488188;stroke-miterlimit:4;stroke-dasharray:none"> + height="2093.5583" + width="3027.1016" + id="rect116616" + style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.88976377;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> REV. NO. + id="tspan116524">REV. NO. + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + id="path116534" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + id="path116538" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + id="path116542" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + id="path116546" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + id="path116550" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.94488188;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> DESCRIPTION - AUTHOR + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15.1536px;line-height:100%;font-family:'OpenGost Type B TT';-inkscape-font-specification:'OpenGost Type B TT';text-align:center;text-anchor:middle;stroke-width:0.94488188;stroke-miterlimit:4;stroke-dasharray:none">DESCRIPTION AUTHOR + DATE + y="909.15485" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:16.0591px;line-height:100%;font-family:'OpenGost Type B TT';-inkscape-font-specification:'OpenGost Type B TT';text-align:center;text-anchor:middle;stroke-width:0.94488188;stroke-miterlimit:4;stroke-dasharray:none">DATE {{number}} - DRAWING NUMBER + y="1020.4988" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11.2271px;line-height:100%;font-family:'OpenGost Type B TT';-inkscape-font-specification:'OpenGost Type B TT';text-align:center;text-anchor:middle;stroke-width:0.94488188;stroke-miterlimit:4;stroke-dasharray:none">DRAWING NUMBER {{revision}} + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11.2271px;line-height:100%;font-family:'OpenGost Type B TT';-inkscape-font-specification:'OpenGost Type B TT';text-align:center;text-anchor:middle;stroke-width:0.94488188;stroke-miterlimit:4;stroke-dasharray:none" + y="1020.4988" + x="3038.5586" + id="tspan1427">REV + {{revision}} REV + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13.3918px;line-height:125%;font-family:'OpenGost Type B TT';-inkscape-font-specification:'OpenGost Type B TT';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.999999px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + x="2804.7021" + y="1036.1166" + id="text2533">{{number}} + style="stroke-width:3.77953" /> + style="stroke-width:3.77953" /> + style="stroke-width:3.77953" /> + style="stroke-width:3.77953" /> + style="stroke-width:3.77953" /> diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 9a7ce9ee04..d05f42d3d9 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -150,6 +150,8 @@ def getDiagramScales(self, context): def updateDrawingName(self, context): + if not self.camera: + return if self.camera.name == self.name: return self.camera.name = 'IfcGroup/{}'.format(self.name) diff --git a/src/ifcblenderexport/blenderbim/bim/sheeter.py b/src/ifcblenderexport/blenderbim/bim/sheeter.py index 4f15dea0c4..3eb9b7e409 100644 --- a/src/ifcblenderexport/blenderbim/bim/sheeter.py +++ b/src/ifcblenderexport/blenderbim/bim/sheeter.py @@ -20,6 +20,7 @@ class SheetBuilder: root.attrib['version'] = '1.1' root.attrib['width'] = '841mm' root.attrib['height'] = '594mm' + root.attrib['viewBox'] = '0 0 841 594' view = ET.SubElement(root, 'g') view.attrib['data-type'] = 'titleblock' @@ -27,8 +28,8 @@ class SheetBuilder: titleblock.attrib['xlink:href'] = '../templates/titleblock.svg' titleblock.attrib['x'] = '0' titleblock.attrib['y'] = '0' - titleblock.attrib['width'] = '841mm' - titleblock.attrib['height'] = '594mm' + titleblock.attrib['width'] = '841' + titleblock.attrib['height'] = '594' with open(sheet_path, 'w') as f: f.write(minidom.parseString(ET.tostring(root)).toprettyxml(indent=' ')) @@ -51,26 +52,24 @@ class SheetBuilder: # here to accommodate browsers which do not nest images. view = ET.SubElement(sheet_root, 'g') view.attrib['data-type'] = 'drawing' + view_width = self.convert_to_mm(view_root.attrib.get('width')) + view_height = self.convert_to_mm(view_root.attrib.get('height')) background = ET.SubElement(view, 'image') background.attrib['xlink:href'] = '../diagrams/{}.png'.format(view_name) - background.attrib['x'] = '0' - background.attrib['y'] = '0' - background.attrib['width'] = view_root.attrib.get('width') - background.attrib['height'] = view_root.attrib.get('height') + background.attrib['x'] = '30' + background.attrib['y'] = '30' + background.attrib['width'] = str(view_width) + background.attrib['height'] = str(view_height) foreground = ET.SubElement(view, 'image') foreground.attrib['xlink:href'] = '../diagrams/{}.svg'.format(view_name) - foreground.attrib['x'] = '0' - foreground.attrib['y'] = '0' - foreground.attrib['width'] = view_root.attrib.get('width') - foreground.attrib['height'] = view_root.attrib.get('height') - - title = ET.SubElement(view, 'image') - title.attrib['xlink:href'] = '../templates/view-title.svg' - title.attrib['x'] = '0' - title.attrib['y'] = view_root.attrib.get('height') + foreground.attrib['x'] = '30' + foreground.attrib['y'] = '30' + foreground.attrib['width'] = str(view_width) + foreground.attrib['height'] = str(view_height) + self.add_view_title(30, view_height+35, view) sheet_tree.write(sheet_path) def add_schedule(self, schedule_name, sheet_name): @@ -85,24 +84,33 @@ class SheetBuilder: view_tree = ET.parse(view_path) view_root = view_tree.getroot() + view_width = self.convert_to_mm(view_root.attrib.get('width')) + view_height = self.convert_to_mm(view_root.attrib.get('height')) group = ET.SubElement(sheet_root, 'g') group.attrib['data-type'] = 'schedule' foreground = ET.SubElement(group, 'image') foreground.attrib['xlink:href'] = '../schedules/{}.svg'.format(schedule_name) - foreground.attrib['x'] = '0' - foreground.attrib['y'] = '0' - foreground.attrib['width'] = view_root.attrib.get('width') - foreground.attrib['height'] = view_root.attrib.get('height') - - title = ET.SubElement(group, 'image') - title.attrib['xlink:href'] = '../templates/view-title.svg' - title.attrib['x'] = '0' - title.attrib['y'] = view_root.attrib.get('height') + foreground.attrib['x'] = '30' + foreground.attrib['y'] = '30' + foreground.attrib['width'] = str(view_width) + foreground.attrib['height'] = str(view_height) + self.add_view_title(30, view_height+35, group) sheet_tree.write(sheet_path) + def add_view_title(self, x, y, parent): + title_tree = ET.parse(os.path.join(self.data_dir, 'templates', 'view-title.svg')) + title_root = title_tree.getroot() + title = ET.SubElement(parent, 'image') + title.attrib['xlink:href'] = '../templates/view-title.svg' + title.attrib['x'] = str(x) + title.attrib['y'] = str(y) + title.attrib['width'] = str(self.convert_to_mm(title_root.attrib.get('width'))) + title.attrib['height'] = str(self.convert_to_mm(title_root.attrib.get('height'))) + + def build(self, sheet_name): os.makedirs('{}build/{}/'.format(self.data_dir, sheet_name), exist_ok=True) @@ -184,11 +192,14 @@ class SheetBuilder: def parse_embedded_svg(self, image, data): group = ET.Element('g') group.attrib['transform'] = 'translate({},{})'.format( - self.mm_to_px(self.convert_to_mm(image.attrib.get('x'))), - self.mm_to_px(self.convert_to_mm(image.attrib.get('y')))) + self.convert_to_mm(image.attrib.get('x')), + self.convert_to_mm(image.attrib.get('y'))) svg_path = self.get_href(image) with open('{}sheets/{}'.format(self.data_dir, svg_path), 'r') as template: embedded = ET.fromstring(pystache.render(template.read(), data)) + # viewBox should not be nested + embedded.attrib['viewBox'] = '' + # TODO: This should not be in this function self.scale = embedded.attrib.get('data-scale') images = embedded.findall('{http://www.w3.org/2000/svg}image') for image in images: @@ -198,8 +209,6 @@ class SheetBuilder: return group def convert_to_mm(self, value): - if value.isnumeric(): - return float(value) if 'cm' in value: return float(value[0:-2]) * 10 elif 'mm' in value: @@ -214,6 +223,7 @@ class SheetBuilder: return float(value[0:-2]) * (1/72) * 2.54 * 10 elif 'px' in value: return float(value[0:-2]) * (1/96) * 2.54 * 10 + return float(value) def mm_to_px(self, value): return (value / 25.4) * 96