summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2018-02-20 20:17:22 +0000
committerMartin Owens <doctormo@gmail.com>2018-02-20 20:17:22 +0000
commit2eb3cf14dd30da03a16aa6d0f79fc069cf9af7f2 (patch)
tree62cb9d790de7868ce29c2ff9849507805363e3ee
parentMisc. typos (diff)
downloadinkscape-2eb3cf14dd30da03a16aa6d0f79fc069cf9af7f2.tar.gz
inkscape-2eb3cf14dd30da03a16aa6d0f79fc069cf9af7f2.zip
Replace dxf12 output with a pure python implementation
-rw-r--r--share/extensions/dxf12_outlines.inx20
-rw-r--r--share/extensions/dxf12_outlines.py145
-rw-r--r--share/extensions/dxf_output.inx18
-rwxr-xr-xshare/extensions/ps2dxf.sh10
4 files changed, 165 insertions, 28 deletions
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 @@
+<inkscape-extension>
+ <_name>myDXF Output</_name>
+ <id>org.ekips.output.dxf12_outlines</id>
+ <dependency type="extension">org.inkscape.output.svg.inkscape</dependency>
+ <dependency type="executable" location="extensions">inkex.py</dependency>
+ <dependency type="executable" location="extensions">simpletransform.py</dependency>
+ <dependency type="executable" location="extensions">cubicsuperpath.py</dependency>
+ <dependency type="executable" location="extensions">cspsubdiv.py</dependency>
+ <output>
+ <extension>.dxf</extension>
+ <mimetype>image/dxf</mimetype>
+ <_filetypename>Desktop Cutting Plotter (AutoCAD DXF R12) (*.dxf)</_filetypename>
+ <_filetypetooltip>DXF R12 Output</_filetypetooltip>
+ <dataloss>TRUE</dataloss>
+ </output>
+ <script>
+ <command reldir="extensions" interpreter="python">dxf12_outlines.py</command>
+ <helper_extension>org.inkscape.output.svg.inkscape</helper_extension>
+ </script>
+</inkscape-extension>
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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
- <_name>DXF Output</_name>
- <id>org.inkscape.output.dxf</id>
- <dependency type="extension">org.inkscape.print.ps.cairo</dependency>
- <dependency type="executable" location="extensions">ps2dxf.sh</dependency>
- <dependency type="executable" _description="pstoedit must be installed to run; see http://www.pstoedit.net/pstoedit">pstoedit</dependency>
- <output>
- <extension>.dxf</extension>
- <mimetype>image/dxf</mimetype>
- <_filetypename>AutoCAD DXF R12 (*.dxf)</_filetypename>
- <_filetypetooltip>DXF file written by pstoedit</_filetypetooltip>
- </output>
- <script>
- <command reldir="extensions">ps2dxf.sh</command>
- <helper_extension>org.inkscape.print.ps.cairo</helper_extension>
- </script>
-</inkscape-extension>
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