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,11 +14,14 @@ ...@@ -14,11 +14,14 @@
# #
# $Id$ # $Id$
class gcode: class gcode:
lastx = lasty = lastz = lasta = lastgcode = None lastx = lasty = lastz = lasta = lastgcode = None
lastfeed = None lastfeed = None
def __init__(self, startx, starty, startz, homeheight=1.5, safetyheight=None, tool_id=1): def __init__(self, startx, starty, startz, homeheight=1.5,
safetyheight=None, tool_id=1):
self.startx = startx self.startx = startx
self.starty = starty self.starty = starty
self.startz = startz self.startz = startz
...@@ -30,9 +33,10 @@ class gcode: ...@@ -30,9 +33,10 @@ class gcode:
self.lastz = max(self.homeheight, safetyheight) self.lastz = max(self.homeheight, safetyheight)
def begin(self): def begin(self):
return "G40 G49 G54 G80 G90\n" + \ return "G40 G49 G54 G80 G90\n" \
"G04 P3 T%d M6\n" % self.tool_id + \ + "G04 P3 T%d M6\n" % self.tool_id \
"G00 X%.4f Y%.4f Z%.4f\n" % (self.startx, self.starty, self.startz) + "G00 X%.4f Y%.4f Z%.4f\n" \
% (self.startx, self.starty, self.startz)
def end(self): def end(self):
return self.safety() + "\n" + "M2\n" return self.safety() + "\n" + "M2\n"
...@@ -43,12 +47,17 @@ class gcode: ...@@ -43,12 +47,17 @@ class gcode:
def continuous(self): def continuous(self):
return "G64" return "G64"
def rapid(self, x = None, y = None, z = None, a = None, gcode = "G00", feed=None): def rapid(self, x = None, y = None, z = None, a = None, gcode = "G00",
feed=None):
gcodestring = feedstring = xstring = ystring = zstring = astring = "" gcodestring = feedstring = xstring = ystring = zstring = astring = ""
if x == None: x = self.lastx if x == None:
if y == None: y = self.lasty x = self.lastx
if z == None: z = self.lastz if y == None:
if a == None: a = self.lasta y = self.lasty
if z == None:
z = self.lastz
if a == None:
a = self.lasta
if gcode != self.lastgcode: if gcode != self.lastgcode:
gcodestring = gcode gcodestring = gcode
self.lastgcode = gcode self.lastgcode = gcode
...@@ -64,7 +73,7 @@ class gcode: ...@@ -64,7 +73,7 @@ class gcode:
if a != self.lasta: if a != self.lasta:
astring = " A%.4f" % (a) astring = " A%.4f" % (a)
self.lasta = a self.lasta = a
if gcode == "G01" and feed and feed != self.lastfeed: if (gcode == "G01") and feed and (feed != self.lastfeed):
feedstring = " F%.4f" % (feed) feedstring = " F%.4f" % (feed)
self.lastfeed = feed self.lastfeed = feed
return gcodestring + feedstring + xstring + ystring + zstring + astring return gcodestring + feedstring + xstring + ystring + zstring + astring
...@@ -81,3 +90,4 @@ class gcode: ...@@ -81,3 +90,4 @@ class gcode:
def safety(self): def safety(self):
return self.rapid(z=self.safetyheight) 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