Commit 0e42d380 authored by sumpfralle's avatar sumpfralle

removed unused gcode export code

fixed remaining issues with the new code


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@989 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 9d0a70f6
......@@ -13,6 +13,7 @@ Version 0.4.1 - UNRELEASED
* added a configuration setting for automatically loading a custom task settings file on startup
* added a simple "undo" feature for reversing model manipulations
* added a minimum step width for GCode positions to be written
* GCode positioning precision (number of digits) is configurable
* enabled drag'n'drop for loading models
* support non-local file handling (e.g. http, ...)
* the scroll wheel now behaves similarly to Inkscape's interface (pan and zoom)
......
......@@ -2,7 +2,7 @@
"""
$Id$
Copyright 2010 Lars Kruse <devel@sumpfralle.de>
Copyright 2010-2011 Lars Kruse <devel@sumpfralle.de>
Copyright 2008-2009 Lode Leroy
This file is part of PyCAM.
......@@ -36,6 +36,7 @@ MAX_DIGITS = 12
def _get_num_of_significant_digits(number):
""" Determine the number of significant digits of a float number. """
# use only positive numbers
number = abs(number)
max_diff = 0.1 ** MAX_DIGITS
......@@ -55,6 +56,9 @@ def _get_num_of_significant_digits(number):
def _get_num_converter(step_width):
""" Return a float-to-decimal conversion function with a prevision suitable
for the given step width.
"""
digits=_get_num_of_significant_digits(step_width)
format_string = "%%.%df" % digits
return lambda number: decimal.Decimal(format_string % number)
......@@ -185,8 +189,8 @@ class GCodeGenerator:
if self.last_position[index] is None:
no_diff = False
break
diff = new_pos[index] - self.last_position[index]
if diff > self._axes_formatter[index][0]:
diff = abs(new_pos[index] - self.last_position[index])
if diff >= self._axes_formatter[index][0]:
no_diff = False
break
if no_diff:
......@@ -202,12 +206,13 @@ class GCodeGenerator:
pos_string.append("%s%s" % (axis_spec, new_pos[index]))
self.last_position[index] = new_pos[index]
if rapid == self.last_rapid:
prefix = " "
prefix = ""
elif rapid:
prefix = "G00"
else:
prefix = "G01"
self.append(prefix + " ".join(pos_string))
self.last_rapid = rapid
self.append("%s %s" % (prefix, " ".join(pos_string)))
def finish(self):
self.add_move_to_safety()
......
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2010 Lars Kruse <devel@sumpfralle.de>
Copyright 2008-2009 Lode Leroy
This file is part of PyCAM.
PyCAM 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 3 of the License, or
(at your option) any later version.
PyCAM 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 PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
from pycam.Exporters.gcode import gcode
import os
# simplistic GCode exporter
# does each run, and moves the tool to the safetyheight in between
class SimpleGCodeExporter:
def __init__(self, destination, unit, feedrate,
speed, safety_height=None, tool_id=1, finish_program=False,
max_skip_safety_distance=None, comment=None):
self._last_path_point = None
self._max_skip_safety_distance = max_skip_safety_distance
if isinstance(destination, basestring):
# open the file
self.destination = file(destination,"w")
self._close_stream_on_exit = True
else:
# assume that "destination" is something like a StringIO instance
# or an open file
self.destination = destination
# don't close the stream if we did not open it on our own
self._close_stream_on_exit = False
if comment:
self.add_comment(comment)
if unit == "mm":
self.destination.write("G21\n")
else:
self.destination.write("G20\n")
self.gcode = gcode(safetyheight=safety_height, tool_id=tool_id)
self._finish_program_on_exit = finish_program
self.destination.write(self.gcode.begin() + "\n")
self.destination.write("F" + str(feedrate) + "\n")
self.destination.write("S" + str(speed) + "\n")
# enable "exact path" mode (prefer accuracy over speed)
self.destination.write(self.gcode.exactpath())
self.destination.write(self.gcode.safety() + "\n")
def close(self):
gc = self.gcode
self.destination.write(gc.safety() + "\n")
if self._finish_program_on_exit:
self.destination.write(gc.end() + "\n")
if self._close_stream_on_exit:
self.destination.close()
def _check_distance_for_skipping_safety_height(self, new_point):
if (self._last_path_point is None) \
or (self._max_skip_safety_distance is None):
return False
distance = new_point.sub(self._last_path_point).norm
return distance <= self._max_skip_safety_distance
def add_comment(self, comment):
for line in comment.split(os.linesep):
self.destination.write(";%s\n" % line)
def AddPath(self, path):
gc = self.gcode
point = path.points[0]
# first move to the safety height if the distance to the last point
# does not exceed the given maximum
if not self._check_distance_for_skipping_safety_height(point):
# move to safety height at the end of the previous path
if not self._last_path_point is None:
self.destination.write(gc.rapid(self._last_path_point.x,
self._last_path_point.y, gc.safetyheight) + "\n")
# move to safety height for the start of the current path
self.destination.write(gc.rapid(point.x, point.y, gc.safetyheight) \
+ "\n")
for point in path.points:
self.destination.write(gc.cut(point.x, point.y, point.z) + "\n")
self._last_path_point = point
def AddPathList(self, pathlist):
for path in pathlist:
self.AddPath(path)
# add the move to safety height to the last path
if not self._last_path_point is None:
self.destination.write(self.gcode.rapid(self._last_path_point.x,
self._last_path_point.y, self.gcode.safetyheight) + "\n")
def ExportPathList(destination, pathlist, unit, feedrate, speed, **kwargs):
exporter = SimpleGCodeExporter(destination, unit, feedrate, speed, **kwargs)
exporter.AddPathList(pathlist)
exporter.close()
......@@ -21,6 +21,5 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
__all__ = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter",
"EMCToolExporter"]
__all__ = [ "GCodeExporter", "SVGExporter", "STLExporter", "EMCToolExporter"]
## gcode.py 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. gcode.py 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 gcode.py; if
## not, write to the Free Software Foundation, Inc., 59 Temple Place,
## Suite 330, Boston, MA 02111-1307 USA
##
## gcode.py is Copyright (C) 2005 Chris Radek
## chris@timeguy.com
#
# $Id$
class gcode:
def __init__(self, safetyheight=1.0, tool_id=1):
self.tool_id = tool_id
self.safetyheight = safetyheight
self.lastfeed = None
self.lastx = None
self.lasty = None
self.lastz = None
self.lasta = None
self.lastgcode = None
self.lastz = None
def delay(self, seconds):
return "G04 P%d" % seconds
def begin(self):
"""
G40: disable tool radius compensation
G49: disable tool length compensation
G54: select coordinate system 1
G80: cancel model motion
G90: use absolute coordinates instead of axis increments
G00 Z?: no x/y positioning - just go up to safety height
"""
return ("G40 G49 G54 G80 G90",
"G04 P3 T%d M6" % self.tool_id,
"G00 Z%.4f" % self.safetyheight)
def end(self):
return "M2"
def exactpath(self):
return "G61"
def continuous(self):
return "G64"
def rapid(self, x=None, y=None, z=None, a=None, code="G00", feed=None):
gcodestring = ""
feedstring = ""
xstring = ""
ystring = ""
zstring = ""
astring = ""
if x == None:
x = self.lastx
if y == None:
y = self.lasty
if z == None:
z = self.lastz
if a == None:
a = self.lasta
if code != self.lastgcode:
gcodestring = code
self.lastgcode = code
if x != self.lastx:
xstring = " X%.4f" % (x)
self.lastx = x
if y != self.lasty:
ystring = " Y%.4f" % (y)
self.lasty = y
if z != self.lastz:
zstring = " Z%.4f" % (z)
self.lastz = z
if a != self.lasta:
astring = " A%.4f" % (a)
self.lasta = a
if (code == "G01") and feed and (feed != self.lastfeed):
feedstring = " F%.4f" % (feed)
self.lastfeed = feed
positionstring = xstring + ystring + zstring + astring
if len(positionstring) > 0:
return gcodestring + feedstring + positionstring
else:
return ""
def cut(self, x = None, y = None, z = None, a = None, feed=None):
if x == None: x = self.lastx
if y == None: y = self.lasty
if z == None: z = self.lastz
if a == None: a = self.lasta
return self.rapid(x, y, z, a, code="G01", feed=feed)
def safety(self):
return self.rapid(z=self.safetyheight)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment