From 2a36625cdd08c369ed8a75f9081a64e1a3367552 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sun, 1 Aug 2010 07:35:26 -0400 Subject: [PATCH] support for layers in .dxf output (Bug 410928) --- share/extensions/dxf_outlines.py | 30 +++++++++++++++++++++++----- share/extensions/dxf_templates.py | 33 ++++--------------------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/share/extensions/dxf_outlines.py b/share/extensions/dxf_outlines.py index 752c42add..219ee1dda 100755 --- a/share/extensions/dxf_outlines.py +++ b/share/extensions/dxf_outlines.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ''' Copyright (C) 2005,2007,2008 Aaron Spike, aaron@ekips.org -Copyright (C) 2008 Alvin Penner, penner@vaxxine.com +Copyright (C) 2008,2010 Alvin Penner, penner@vaxxine.com - template dxf_outlines.dxf added Feb 2008 by Alvin Penner - ROBO-Master output option added Aug 2008 @@ -9,6 +9,7 @@ Copyright (C) 2008 Alvin Penner, penner@vaxxine.com - LWPOLYLINE output modification added Dec 2008 - toggle between LINE/LWPOLYLINE added Jan 2010 - support for transform elements added July 2010 +- support for layers added July 2010 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -60,6 +61,8 @@ class MyEffect(inkex.Effect): self.OptionParser.add_option("--inputhelp", action="store", type="string", dest="inputhelp") self.dxf = [] self.handle = 255 # handle for DXF ENTITY + self.layers = ['0'] + self.layer = '0' # mandatory layer self.csp_old = [[0.0,0.0]]*4 # previous spline self.d = array([0], float) # knot vector self.poly = [[0.0,0.0]] # LWPOLYLINE data @@ -69,7 +72,7 @@ class MyEffect(inkex.Effect): self.dxf.append(str) def dxf_line(self,csp): self.handle += 1 - self.dxf_add(" 0\nLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbLine\n" % (self.handle, self.color)) + self.dxf_add(" 0\nLINE\n 5\n%x\n100\nAcDbEntity\n 8\n%s\n 62\n%d\n100\nAcDbLine\n" % (self.handle, self.layer, self.color)) self.dxf_add(" 10\n%f\n 20\n%f\n 30\n0.0\n 11\n%f\n 21\n%f\n 31\n0.0\n" % (csp[0][0],csp[0][1],csp[1][0],csp[1][1])) def LWPOLY_line(self,csp): if (abs(csp[0][0] - self.poly[-1][0]) > .0001 @@ -77,19 +80,20 @@ class MyEffect(inkex.Effect): self.LWPOLY_output() # terminate current polyline self.poly = [csp[0]] # initiallize new polyline self.color_LWPOLY = self.color + self.layer_LWPOLY = self.layer self.poly.append(csp[1]) def LWPOLY_output(self): if len(self.poly) == 1: return self.handle += 1 - self.dxf_add(" 0\nLWPOLYLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbPolyline\n 90\n%d\n 70\n0\n" % (self.handle, self.color_LWPOLY, len(self.poly))) + self.dxf_add(" 0\nLWPOLYLINE\n 5\n%x\n100\nAcDbEntity\n 8\n%s\n 62\n%d\n100\nAcDbPolyline\n 90\n%d\n 70\n0\n" % (self.handle, self.layer_LWPOLY, self.color_LWPOLY, len(self.poly))) for i in range(len(self.poly)): self.dxf_add(" 10\n%f\n 20\n%f\n 30\n0.0\n" % (self.poly[i][0],self.poly[i][1])) def dxf_spline(self,csp): knots = 8 ctrls = 4 self.handle += 1 - self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbSpline\n" % (self.handle, self.color)) + self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n%s\n 62\n%d\n100\nAcDbSpline\n" % (self.handle, self.layer, self.color)) self.dxf_add(" 70\n8\n 71\n3\n 72\n%d\n 73\n%d\n 74\n0\n" % (knots, ctrls)) for i in range(2): for j in range(4): @@ -106,6 +110,7 @@ class MyEffect(inkex.Effect): self.yfit = array([csp[0][1]], float) self.d = array([0], float) self.color_ROBO = self.color + self.layer_ROBO = self.layer self.xfit = concatenate((self.xfit, zeros((3)))) # append to current spline self.yfit = concatenate((self.yfit, zeros((3)))) self.d = concatenate((self.d, zeros((3)))) @@ -139,7 +144,7 @@ class MyEffect(inkex.Effect): xctrl = solve(solmatrix, self.xfit) yctrl = solve(solmatrix, self.yfit) self.handle += 1 - self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n0\n 62\n%d\n100\nAcDbSpline\n" % (self.handle, self.color_ROBO)) + self.dxf_add(" 0\nSPLINE\n 5\n%x\n100\nAcDbEntity\n 8\n%s\n 62\n%d\n100\nAcDbSpline\n" % (self.handle, self.layer_ROBO, self.color_ROBO)) self.dxf_add(" 70\n0\n 71\n3\n 72\n%d\n 73\n%d\n 74\n%d\n" % (knots, ctrls, fits)) for i in range(knots): self.dxf_add(" 40\n%f\n" % self.d[i-3]) @@ -182,6 +187,11 @@ class MyEffect(inkex.Effect): self.dxf_spline([s[1],s[2],e[0],e[1]]) def process_group(self, group): + if group.get(inkex.addNS('groupmode', 'inkscape')) == 'layer': + layer = group.get(inkex.addNS('label', 'inkscape')) + layer = layer.replace(' ', '_') + if layer in self.layers: + self.layer = layer trans = group.get('transform') if trans: self.groupmat.append(simpletransform.composeTransform(self.groupmat[-1], simpletransform.parseTransform(trans))) @@ -199,6 +209,16 @@ class MyEffect(inkex.Effect): # The NURBS Book By Les Piegl and Wayne Tiller (Springer, 1995) self.dxf_add("999\nDXF created by Inkscape\n") self.dxf_add(dxf_templates.r14_header) + for node in self.document.getroot().xpath('//svg:g', namespaces=inkex.NSS): + if node.get(inkex.addNS('groupmode', 'inkscape')) == 'layer': + layer = node.get(inkex.addNS('label', 'inkscape')) + layer = layer.replace(' ', '_') + if layer and not layer in self.layers: + self.layers.append(layer) + self.dxf_add(" 2\nLAYER\n 5\n2\n100\nAcDbSymbolTable\n 70\n%s\n" % len(self.layers)) + for i in range(len(self.layers)): + self.dxf_add(" 0\nLAYER\n 5\n%x\n100\nAcDbSymbolTableRecord\n100\nAcDbLayerTableRecord\n 2\n%s\n 70\n0\n 6\nCONTINUOUS\n" % (i + 80, self.layers[i])) + self.dxf_add(dxf_templates.r14_style) scale = 25.4/90.0 h = inkex.unittouu(self.document.getroot().xpath('@height', namespaces=inkex.NSS)[0]) diff --git a/share/extensions/dxf_templates.py b/share/extensions/dxf_templates.py index c0a85f6b8..5c027456f 100644 --- a/share/extensions/dxf_templates.py +++ b/share/extensions/dxf_templates.py @@ -196,35 +196,10 @@ Solid line ENDTAB 0 TABLE - 2 -LAYER - 5 -2 -330 -0 -100 -AcDbSymbolTable - 70 -1 - 0 -LAYER - 5 -10 -330 -2 -100 -AcDbSymbolTableRecord -100 -AcDbLayerTableRecord - 2 -0 - 70 - 0 - 62 - 7 - 6 -CONTINUOUS - 0 +''' + + +r14_style = ''' 0 ENDTAB 0 TABLE -- 2.30.2