plotter.py revision 3a73dfd143fd2dc5abdc4757dcd8f15bc391fe7d
# coding=utf-8
'''
Copyright (C) 2013 Sebastian Wüst, sebi@timewaster.de
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
'''
# standard library
import re
import string
import sys
# local libraries
import gettext
import hpgl_decoder
import hpgl_encoder
import inkex
self.OptionParser.add_option('--serialPort', action='store', type='string', dest='serialPort', default='COM1', help='Serial port')
self.OptionParser.add_option('--serialBaudRate', action='store', type='string', dest='serialBaudRate', default='9600', help='Serial Baud rate')
self.OptionParser.add_option('--serialByteSize', action='store', type='string', dest='serialByteSize', default='eight', help='Serial byte size')
self.OptionParser.add_option('--serialStopBits', action='store', type='string', dest='serialStopBits', default='one', help='Serial stop bits')
self.OptionParser.add_option('--serialParity', action='store', type='string', dest='serialParity', default='none', help='Serial parity')
self.OptionParser.add_option('--serialFlowControl', action='store', type='string', dest='serialFlowControl', default='0', help='Flow control')
self.OptionParser.add_option('--commandLanguage', action='store', type='string', dest='commandLanguage', default='hpgl', help='Command Language')
self.OptionParser.add_option('--initCommands', action='store', type='string', dest='initCommands', default='', help='Initialization commands')
self.OptionParser.add_option('--resolutionX', action='store', type='float', dest='resolutionX', default=1016.0, help='Resolution X (dpi)')
self.OptionParser.add_option('--resolutionY', action='store', type='float', dest='resolutionY', default=1016.0, help='Resolution Y (dpi)')
self.OptionParser.add_option('--pen', action='store', type='int', dest='pen', default=1, help='Pen number')
self.OptionParser.add_option('--force', action='store', type='int', dest='force', default=24, help='Pen force (g)')
self.OptionParser.add_option('--speed', action='store', type='int', dest='speed', default=20, help='Pen speed (cm/s)')
self.OptionParser.add_option('--orientation', action='store', type='string', dest='orientation', default='90', help='Rotation (Clockwise)')
self.OptionParser.add_option('--mirrorX', action='store', type='inkbool', dest='mirrorX', default='FALSE', help='Mirror X axis')
self.OptionParser.add_option('--mirrorY', action='store', type='inkbool', dest='mirrorY', default='FALSE', help='Mirror Y axis')
self.OptionParser.add_option('--center', action='store', type='inkbool', dest='center', default='FALSE', help='Center zero point')
self.OptionParser.add_option('--overcut', action='store', type='float', dest='overcut', default=1.0, help='Overcut (mm)')
self.OptionParser.add_option('--toolOffset', action='store', type='float', dest='toolOffset', default=0.25, help='Tool (Knife) offset correction (mm)')
self.OptionParser.add_option('--precut', action='store', type='inkbool', dest='precut', default='TRUE', help='Use precut')
self.OptionParser.add_option('--flat', action='store', type='float', dest='flat', default=1.2, help='Curve flatness')
self.OptionParser.add_option('--autoAlign', action='store', type='inkbool', dest='autoAlign', default='TRUE', help='Auto align')
self.OptionParser.add_option('--debug', action='store', type='inkbool', dest='debug', default='FALSE', help='Show debug information')
# get hpgl data
try:
# issue error if no paths found
return 1
else:
# TODO: Get preview to work. This requires some work on the C++ side to be able to determine if it is
# a preview or a final run. (Remember to set <effect needs-live-preview='false'> to true)
'''
if MAGIC:
# reparse data for preview
self.options.showMovements = True
self.options.docWidth = self.uutounit(self.unittouu(self.document.getroot().get('width')), "px")
self.options.docHeight = self.uutounit(self.unittouu(self.document.getroot().get('height')), "px")
myHpglDecoder = hpgl_decoder.hpglDecoder(self.hpgl, self.options)
doc, warnings = myHpglDecoder.getSvg()
# deliver document to inkscape
self.document = doc
else:
'''
# convert to other formats
# output
else:
def convertToHpgl(self):
# convert raw HPGL to HPGL
hpglInit = 'IN'
def convertToDmpl(self):
# convert HPGL to DMPL
# ;: = Initialise plotter
# H = Home position
# A = Absolute pen positioning
# Ln = Line type
# Pn = Pen select
# Vn = velocity
# ECn = Coordinate addressing, 1: 0.001 inch, 5: 0.005 inch, M: 0.1 mm
# D = Pen down
# U = Pen up
# Z = Reset plotter
# n,n, = Coordinate pair
dmplInit = ';:HAL0'
dmplInit += 'EC1'
def convertToKNK(self):
# convert HPGL to KNK Plotter Language
hpglInit = 'ZG'
def sendHpglToSerial(self):
# gracefully exit script when pySerial is missing
try:
import serial
except ImportError, e:
+ "\n\n1. Download pySerial here (not the \".exe\"!): http://pypi.python.org/pypi/pyserial"
+ "\n2. Extract the \"serial\" subfolder from the zip to the following folder: C:\\[Program files]\\inkscape\\python\\Lib\\"
+ "\n3. Restart Inkscape."))
return
# init serial framework
# set serial port
# set baudrate
# set bytesize
# set stopbits
# set parity
# set short timeout to avoid locked up interface
# set flow control
# try to establish connection
try:
inkex.errormsg(_("Could not open port. Please check that your plotter is running, connected and the settings are correct."))
return
else:
# send data to plotter
# show debug information
inkex.errormsg("---------------------------------\nDebug information\n---------------------------------\n\nSettings:\n")
if version:
if fileName:
inkex.errormsg(' Width: ' + str(debugObject.debugValues['docWidth']) + ' ' + self.getDocumentUnit())
inkex.errormsg(' Height: ' + str(debugObject.debugValues['docHeight']) + ' ' + self.getDocumentUnit())
else:
inkex.errormsg(' Viewbox Width: ' + str(self.unittouu(self.addDocumentUnit(debugObject.debugValues['viewBoxWidth']))) + ' ' + self.getDocumentUnit())
inkex.errormsg(' Viewbox Height: ' + str(self.unittouu(self.addDocumentUnit(debugObject.debugValues['viewBoxHeight']))) + ' ' + self.getDocumentUnit())
inkex.errormsg(' Drawing width: ' + str(self.unittouu(self.addDocumentUnit(str(debugObject.debugValues['drawingWidthUU'])))) + ' ' + self.getDocumentUnit())
inkex.errormsg(' Drawing height: ' + str(self.unittouu(self.addDocumentUnit(str(debugObject.debugValues['drawingHeightUU'])))) + ' ' + self.getDocumentUnit())
inkex.errormsg(' Drawing width: ' + str(debugObject.debugValues['drawingWidth']) + ' plotter steps')
inkex.errormsg(' Drawing height: ' + str(debugObject.debugValues['drawingHeight']) + ' plotter steps')
if __name__ == '__main__':
# start extension
e = Plot()
e.affect()
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99