Commit f711455e authored by sumpfralle's avatar sumpfralle

fixed code-style issues


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@496 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6364ac9a
...@@ -34,7 +34,8 @@ class EMCToolExporter: ...@@ -34,7 +34,8 @@ class EMCToolExporter:
tool = self.tools[index] tool = self.tools[index]
# use an arbitrary length # use an arbitrary length
tool_length = tool["tool_radius"] * 10 tool_length = tool["tool_radius"] * 10
line = "T%d P%d D%f Z-%f ;%s" % (index + 1, index + 1, 2 * tool["tool_radius"], tool_length, tool["name"]) line = "T%d P%d D%f Z-%f ;%s" % (index + 1, index + 1,
2 * tool["tool_radius"], tool_length, tool["name"])
result.append(line) result.append(line)
# add the dummy line for the "last" tool # add the dummy line for the "last" tool
result.append("T99999 P99999 Z+0.100000 ;dummy tool") result.append("T99999 P99999 Z+0.100000 ;dummy tool")
......
...@@ -49,11 +49,13 @@ class SVGExporter: ...@@ -49,11 +49,13 @@ class SVGExporter:
x = -7 x = -7
if y < -1000: if y < -1000:
y = -7 y = -7
l = "<circle fill='" + self._fill +"'" + (" cx='%g'" % x) + (" cy='%g'" % -y) + " r='0.04'/>\n" l = "<circle fill='" + self._fill +"'" + (" cx='%g'" % x) \
+ (" cy='%g'" % -y) + " r='0.04'/>\n"
self.file.write(l) self.file.write(l)
def AddText(self, x, y, text): def AddText(self, x, y, text):
l = "<text fill='" + self._fill +"'" + (" x='%g'" % x) + (" y='%g'" % -y) + " dx='0.07'>" + text + "</text>\n" l = "<text fill='" + self._fill +"'" + (" x='%g'" % x) \
+ (" y='%g'" % -y) + " dx='0.07'>" + text + "</text>\n"
self.file.write(l) self.file.write(l)
...@@ -62,17 +64,19 @@ class SVGExporter: ...@@ -62,17 +64,19 @@ class SVGExporter:
y1 = -7 y1 = -7
if y2 < -1000: if y2 < -1000:
y2 = -7 y2 = -7
l = "<line fill='" + self._fill +"' stroke='" + self._stroke + "'" + (" x1='%g'" % x1) + (" y1='%g'" % -y1) + (" x2='%g'" % x2) + (" y2='%g'" % -y2) + " />\n" l = "<line fill='" + self._fill +"' stroke='" + self._stroke + "'" \
+ (" x1='%g'" % x1) + (" y1='%g'" % -y1) + (" x2='%g'" % x2) \
+ (" y2='%g'" % -y2) + " />\n"
self.file.write(l) self.file.write(l)
def AddPoint(self, p): def AddPoint(self, p):
AddDot(p.x, p.y) self.AddDot(p.x, p.y)
def AddPath(self, path): def AddPath(self, path):
l = "<path fill='" + self._fill +"' stroke='" + self._stroke + "' d='" l = "<path fill='" + self._fill +"' stroke='" + self._stroke + "' d='"
for i in range(0, len(path.points)): for i in range(0, len(path.points)):
p = path.points[i] p = path.points[i]
if i==0: if i == 0:
l += "M " l += "M "
else: else:
l += " L " l += " L "
...@@ -83,3 +87,4 @@ class SVGExporter: ...@@ -83,3 +87,4 @@ class SVGExporter:
def AddPathList(self, pathlist): def AddPathList(self, pathlist):
for path in pathlist: for path in pathlist:
self.AddPath(path) self.AddPath(path)
...@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License ...@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from gcode import gcode from pycam.Exporters.gcode import gcode
import os import os
# simplistic GCode exporter # simplistic GCode exporter
...@@ -50,7 +50,8 @@ class SimpleGCodeExporter: ...@@ -50,7 +50,8 @@ class SimpleGCodeExporter:
self.destination.write("G21\n") self.destination.write("G21\n")
else: else:
self.destination.write("G20\n") self.destination.write("G20\n")
self.gcode = gcode(startx, starty, startz, safetyheight=safety_height, tool_id=tool_id) self.gcode = gcode(startx, starty, startz, safetyheight=safety_height,
tool_id=tool_id)
gc = self.gcode gc = self.gcode
self._finish_program_on_exit = finish_program self._finish_program_on_exit = finish_program
self.destination.write(gc.begin() + "\n") self.destination.write(gc.begin() + "\n")
...@@ -67,7 +68,8 @@ class SimpleGCodeExporter: ...@@ -67,7 +68,8 @@ class SimpleGCodeExporter:
self.destination.close() self.destination.close()
def _check_distance_for_skipping_safety_height(self, new_point): 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): if (self._last_path_point is None) \
or (self._max_skip_safety_distance is None):
return False return False
distance = new_point.sub(self._last_path_point).norm() distance = new_point.sub(self._last_path_point).norm()
return distance <= self._max_skip_safety_distance return distance <= self._max_skip_safety_distance
...@@ -87,7 +89,8 @@ class SimpleGCodeExporter: ...@@ -87,7 +89,8 @@ class SimpleGCodeExporter:
self.destination.write(gc.rapid(self._last_path_point.x, self.destination.write(gc.rapid(self._last_path_point.x,
self._last_path_point.y, gc.safetyheight) + "\n") self._last_path_point.y, gc.safetyheight) + "\n")
# move to safety height for the start of the current path # move to safety height for the start of the current path
self.destination.write(gc.rapid(point.x, point.y, gc.safetyheight) + "\n") self.destination.write(gc.rapid(point.x, point.y, gc.safetyheight) \
+ "\n")
for point in path.points: for point in path.points:
self.destination.write(gc.cut(point.x, point.y, point.z) + "\n") self.destination.write(gc.cut(point.x, point.y, point.z) + "\n")
self._last_path_point = point self._last_path_point = point
......
...@@ -21,5 +21,6 @@ You should have received a copy of the GNU General Public License ...@@ -21,5 +21,6 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
__all__ = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter", "EMCToolExporter"] __all__ = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter",
"EMCToolExporter"]
...@@ -14,70 +14,80 @@ ...@@ -14,70 +14,80 @@
# #
# $Id$ # $Id$
class gcode: class gcode:
lastx = lasty = lastz = lasta = lastgcode = None
lastfeed = None
def __init__(self, startx, starty, startz, homeheight=1.5, safetyheight=None, tool_id=1): lastx = lasty = lastz = lasta = lastgcode = None
self.startx = startx lastfeed = None
self.starty = starty
self.startz = startz def __init__(self, startx, starty, startz, homeheight=1.5,
self.tool_id = tool_id safetyheight=None, tool_id=1):
if safetyheight is None: self.startx = startx
safetyheight = max(max(startz, homeheight), 0.04) self.starty = starty
self.homeheight = max(startz, homeheight) self.startz = startz
self.safetyheight = safetyheight self.tool_id = tool_id
self.lastz = max(self.homeheight, safetyheight) if safetyheight is None:
safetyheight = max(max(startz, homeheight), 0.04)
self.homeheight = max(startz, homeheight)
self.safetyheight = safetyheight
self.lastz = max(self.homeheight, safetyheight)
def begin(self):
return "G40 G49 G54 G80 G90\n" \
+ "G04 P3 T%d M6\n" % self.tool_id \
+ "G00 X%.4f Y%.4f Z%.4f\n" \
% (self.startx, self.starty, self.startz)
def begin(self): def end(self):
return "G40 G49 G54 G80 G90\n" + \ return self.safety() + "\n" + "M2\n"
"G04 P3 T%d M6\n" % self.tool_id + \
"G00 X%.4f Y%.4f Z%.4f\n" % (self.startx, self.starty, self.startz)
def end(self): def exactpath(self):
return self.safety() + "\n" + "M2\n" return "G61"
def exactpath(self): def continuous(self):
return "G61" return "G64"
def continuous(self): def rapid(self, x = None, y = None, z = None, a = None, gcode = "G00",
return "G64" 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 gcode != self.lastgcode:
gcodestring = gcode
self.lastgcode = gcode
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 (gcode == "G01") and feed and (feed != self.lastfeed):
feedstring = " F%.4f" % (feed)
self.lastfeed = feed
return gcodestring + feedstring + xstring + ystring + zstring + astring
def rapid(self, x = None, y = None, z = None, a = None, gcode = "G00", feed=None): def cut(self, x = None, y = None, z = None, a = None, feed=None):
gcodestring = feedstring = xstring = ystring = zstring = astring = "" if x == None: x = self.lastx
if x == None: x = self.lastx if y == None: y = self.lasty
if y == None: y = self.lasty if z == None: z = self.lastz
if z == None: z = self.lastz if a == None: a = self.lasta
if a == None: a = self.lasta return self.rapid(x, y, z, a, gcode="G01", feed=feed)
if gcode != self.lastgcode:
gcodestring = gcode
self.lastgcode = gcode
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 gcode == "G01" and feed and feed != self.lastfeed:
feedstring = " F%.4f" % (feed)
self.lastfeed = feed
return gcodestring + feedstring + xstring + ystring + zstring + astring
def cut(self, x = None, y = None, z = None, a = None, feed=None): def home(self):
if x == None: x = self.lastx return self.rapid(z=self.homeheight)
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, gcode="G01", feed=feed)
def home(self): def safety(self):
return self.rapid(z=self.homeheight) return self.rapid(z=self.safetyheight)
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