From 2eb3cf14dd30da03a16aa6d0f79fc069cf9af7f2 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 20 Feb 2018 15:17:22 -0500 Subject: Replace dxf12 output with a pure python implementation --- share/extensions/dxf12_outlines.inx | 20 +++++ share/extensions/dxf12_outlines.py | 145 ++++++++++++++++++++++++++++++++++++ share/extensions/dxf_output.inx | 18 ----- share/extensions/ps2dxf.sh | 10 --- 4 files changed, 165 insertions(+), 28 deletions(-) create mode 100644 share/extensions/dxf12_outlines.inx create mode 100644 share/extensions/dxf12_outlines.py delete mode 100644 share/extensions/dxf_output.inx delete mode 100755 share/extensions/ps2dxf.sh diff --git a/share/extensions/dxf12_outlines.inx b/share/extensions/dxf12_outlines.inx new file mode 100644 index 000000000..1bcc8e7db --- /dev/null +++ b/share/extensions/dxf12_outlines.inx @@ -0,0 +1,20 @@ + + <_name>myDXF Output + org.ekips.output.dxf12_outlines + org.inkscape.output.svg.inkscape + inkex.py + simpletransform.py + cubicsuperpath.py + cspsubdiv.py + + .dxf + image/dxf + <_filetypename>Desktop Cutting Plotter (AutoCAD DXF R12) (*.dxf) + <_filetypetooltip>DXF R12 Output + TRUE + + + diff --git a/share/extensions/dxf12_outlines.py b/share/extensions/dxf12_outlines.py new file mode 100644 index 000000000..89d6c3a25 --- /dev/null +++ b/share/extensions/dxf12_outlines.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python +# +# Copyright (C) 2005,2007 Aaron Spike, aaron@ekips.org +# - template dxf_outlines.dxf added Feb 2008 by Alvin Penner, penner@vaxxine.com +# - layers, transformation, flattening added April 2008 by Bob Cook, bob@bobcookdev.com +# - added support for dxf R12, Nov. 2008 by Switcher +# - brought together to replace ps2edit version 2018 by Martin Owens +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import inkex, simplepath, cubicsuperpath, cspsubdiv, re + +import simpletransform + +r12_header = ''' 0 +SECTION + 2 +HEADER + 9 +$ACADVER + 1 +AC1009 + 9 +$EXTMIN + 10 + 0 + 20 + 0 + 9 +$EXTMAX + 10 + 8.5 + 20 + 11 + 0 +ENDSEC + 0 +SECTION + 2 +ENTITIES +''' + +r12_footer = ''' 0 +ENDSEC + 0 +EOF''' + +class MyEffect(inkex.Effect): + + def __init__(self): + + inkex.Effect.__init__(self) + self.dxf = '' + self.handle = 255 + self.flatness = 0.1 + + def output(self): + print self.dxf + + def dxf_add(self, str): + self.dxf += str + + def dxf_insert_code(self, code, value): + self.dxf += code + "\n" + value + "\n" + + def dxf_line(self,layer,csp): + self.dxf_insert_code( '0', 'LINE' ) + self.dxf_insert_code( '8', layer ) + ######self.dxf_insert_code( '62', '1' ) #Change the Line Color + self.dxf_insert_code( '10', '%f' % csp[0][0] ) + self.dxf_insert_code( '20', '%f' % csp[0][1] ) + self.dxf_insert_code( '11', '%f' % csp[1][0] ) + self.dxf_insert_code( '21', '%f' % csp[1][1] ) + + def dxf_path_to_lines(self,layer,p): + f = self.flatness + is_flat = 0 + while is_flat < 1: + try: + cspsubdiv.cspsubdiv(p, self.flatness) + is_flat = 1 + except: + f += 0.1 + + for sub in p: + for i in range(len(sub)-1): + self.handle += 1 + s = sub[i] + e = sub[i+1] + self.dxf_line(layer,[s[1],e[1]]) + + def dxf_path_to_point(self,layer,p): + bbox = simpletransform.roughBBox(p) + x = (bbox[0] + bbox[1]) / 2 + y = (bbox[2] + bbox[3]) / 2 + self.dxf_point(layer,x,y) + + def effect(self): + self.dxf_insert_code( '999', '"DXF R12 Output" (www.mydxf.blogspot.com)' ) + self.dxf_add( r12_header ) + + scale = 25.4/90.0 + h = self.unittouu(self.getDocumentHeight()) + + path = '//svg:path' + for node in self.document.getroot().xpath(path, namespaces=inkex.NSS): + + layer = node.getparent().get(inkex.addNS('label','inkscape')) + if layer == None: + layer = 'Layer 1' + + d = node.get('d') + p = cubicsuperpath.parsePath(d) + + t = node.get('transform') + if t != None: + m = simpletransform.parseTransform(t) + simpletransform.applyTransformToPath(m,p) + + m = [[scale,0,0],[0,-scale,h*scale]] + simpletransform.applyTransformToPath(m,p) + + if re.search('drill$',layer,re.I) == None: + #if layer == 'Brackets Drill': + self.dxf_path_to_lines(layer,p) + else: + self.dxf_path_to_point(layer,p) + + self.dxf_add( r12_footer ) + +e = MyEffect() +e.affect() diff --git a/share/extensions/dxf_output.inx b/share/extensions/dxf_output.inx deleted file mode 100644 index 7f43fc131..000000000 --- a/share/extensions/dxf_output.inx +++ /dev/null @@ -1,18 +0,0 @@ - - - <_name>DXF Output - org.inkscape.output.dxf - org.inkscape.print.ps.cairo - ps2dxf.sh - pstoedit - - .dxf - image/dxf - <_filetypename>AutoCAD DXF R12 (*.dxf) - <_filetypetooltip>DXF file written by pstoedit - - - diff --git a/share/extensions/ps2dxf.sh b/share/extensions/ps2dxf.sh deleted file mode 100755 index 3479800e1..000000000 --- a/share/extensions/ps2dxf.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -TMPDIR="${TMPDIR-/tmp}" -TEMPFILENAME=`mktemp 2>/dev/null || echo "$TMPDIR/tmp-ps-$$.dxf"` -pstoedit -f dxf "$1" "${TEMPFILENAME}" > /dev/null 2>&1 -rc=0 -cat < "${TEMPFILENAME}" || rc=1 -rm -f "${TEMPFILENAME}" -exit $rc -d \ No newline at end of file -- cgit v1.2.3