Update Path to py3-compatible printing

This commit is contained in:
Kurt Kremitzki 2017-01-29 22:11:45 -06:00 committed by looooo
parent 32bacd0b63
commit e47edae9c3
23 changed files with 92 additions and 77 deletions

View File

@ -20,6 +20,7 @@
# * USA *
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import FreeCADGui
@ -57,7 +58,7 @@ class ObjectCompoundExtended:
def onChanged(self, obj, prop):
if prop == "Group":
print 'check order'
print('check order')
for child in obj.Group:
if child.isDerivedFrom("Path::Feature"):
child.touch()

View File

@ -21,6 +21,7 @@
# * USA *
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import FreeCADGui
import Path
@ -90,7 +91,7 @@ class ViewProviderDressup:
if g.Name == self.Object.Base.Name:
group.remove(g)
i.Group = group
print i.Group
print(i.Group)
return [self.Object.Base]
def __getstate__(self):

View File

@ -21,6 +21,7 @@
# * USA *
# * *
# ***************************************************************************
from __future__ import print_function
import DraftGeomUtils
import FreeCAD
import FreeCADGui
@ -951,7 +952,7 @@ class ViewProviderDressup:
if g.Name == self.Object.Base.Name:
group.remove(g)
i.Group = group
print i.Group
print(i.Group)
#FreeCADGui.ActiveDocument.getObject(obj.Base.Name).Visibility = False
return [self.Object.Base]

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import FreeCADGui
import Path
@ -451,7 +452,7 @@ class ViewProviderDressup:
if g.Name == self.Object.Base.Name:
group.remove(g)
i.Group = group
print i.Group
print(i.Group)
#FreeCADGui.ActiveDocument.getObject(obj.Base.Name).Visibility = False
return [self.Object.Base]

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import Path
import Part
@ -304,7 +305,7 @@ class ObjectDrilling:
else:
baselist.append(item)
print baselist
print(baselist)
obj.Base = baselist
self.execute(obj)

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
'''PathKurveUtils - functions needed for using libarea (created by Dan Heeks) for making simple CNC profile paths '''
from __future__ import print_function
import Part
import math
import area
@ -142,7 +143,7 @@ def profile(curve, side_of_line, radius=1.0, vertfeed=0.0, horizfeed=0.0, offset
output = ""
output += "G0 Z" + str(clearance) + "\n"
print "in profile: 151"
print("in profile: 151")
offset_curve = area.Curve(curve)
if offset_curve.getNumVertices() <= 1:
raise Exception, "Sketch has no elements!"
@ -338,10 +339,10 @@ def profile2(curve, direction="on", radius=1.0, vertfeed=0.0,
using_area_for_offset = True
a = area.Area()
a.append(curve)
print "curve, offset: " , str(curve), str(offset)
print("curve, offset: " , str(curve), str(offset))
a.Offset(-offset)
for curve in a.getCurves():
print "result curve: ", curve
print("result curve: ", curve)
curve_cw = curve.IsClockwise()
if cw != curve_cw:
curve.Reverse()

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import Path
from PySide import QtCore, QtGui
@ -211,7 +212,7 @@ class ObjectFace:
# To reload this from FreeCAD, use: import PathScripts.PathFace; reload(PathScripts.PathFace)
def execute(self, obj):
print "in execute"
print("in execute")
if not obj.Active:
path = Path.Path("(inactive operation)")
@ -260,7 +261,7 @@ class ObjectFace:
if isinstance (shape, Part.Face):
faces.append(shape)
else:
print ('falling out')
print('falling out')
return
planeshape = Part.makeCompound(faces)

View File

@ -154,7 +154,7 @@ class ObjectPocket:
else:
baselist.append(item)
obj.Base = baselist
print "this base is: " + str(baselist)
print("this base is: " + str(baselist))
self.execute(obj)
def getStock(self, obj):
@ -316,7 +316,7 @@ class ObjectPocket:
# Otherwise, straight plunge... Don't want to, but sometimes you might not have a choice.
# FIXME: At least not with the lazy ramp programming above...
else:
print "WARNING: Straight-plunging... probably not good, but we didn't find a place to helix or ramp"
print("WARNING: Straight-plunging... probably not good, but we didn't find a place to helix or ramp")
startPoint = edge.Vertexes[0].Point
output += "G0 Z" + fmt(obj.ClearanceHeight.Value) + "F " + PathUtils.fmt(self.vertRapid) + "\n"
output += "G0 X" + fmt(startPoint.x) + " Y" + fmt(startPoint.y) +\

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
''' Post Process command that will make use of the Output File and Post Processor entries in PathJob '''
from __future__ import print_function
import FreeCAD
import FreeCADGui
from PySide import QtCore, QtGui
@ -190,7 +191,7 @@ class CommandPathPost:
FreeCADGui.addModule("PathScripts.PathPost")
# select the Path Job that you want to post output from
selected = FreeCADGui.Selection.getCompleteSelection()
print "in activated %s" %(selected)
print("in activated %s" %(selected))
# try to find the job, if it's not directly selected ...
jobs = set()

View File

@ -35,12 +35,12 @@ class PostProcessor:
def load(cls, processor):
postname = processor + "_post"
exec "import %s as current_post" % postname
exec("import %s as current_post" % postname)
# make sure the script is reloaded if it was previously loaded
# should the script have been imported for the first time above
# then the initialization code of the script gets executed twice
# resulting in 2 load messages if the script outputs one of those.
exec "reload(%s)" % 'current_post'
exec("reload(%s)" % 'current_post')
instance = PostProcessor(current_post)
instance.units = None

View File

@ -165,8 +165,8 @@ class ObjectProfile:
curve = PathKurveUtils.makeAreaCurve(edgelist, obj.Direction, startpoint, endpoint)
'''The following line uses a profile function written for use with FreeCAD. It's clean but incomplete. It doesn't handle
print "x = " + str(point.x)
print "y - " + str(point.y)
print("x = " + str(point.x))
print("y - " + str(point.y))
holding tags
start location
CRC

View File

@ -25,6 +25,7 @@
Path projects. Ideally, the user could execute these utilities from an icon
to make sure tools are selected and configured and defaults have been revised'''
from __future__ import print_function
from PySide import QtCore, QtGui
import FreeCAD
import FreeCADGui
@ -50,7 +51,7 @@ def review(obj):
FreeCAD.Console.PrintWarning(translate("Path_Sanity", "It appears the machine limits haven't been set. Not able to check path extents.\n"))
for item in obj.Group:
print "Checking: " + item.Label
print("Checking: " + item.Label)
if item.Name[:2] == "TC":
toolcontrolcount += 1
if item.ToolNumber == 0:

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import Path
from PathScripts import PathUtils
@ -145,7 +146,7 @@ class ObjectSurface:
str(fmt(p.x)) + " Y" + str(fmt(p.y)) + \
" Z" + str(fmt(zheight)) + "\n"
loopstring += "(loop end)" + "\n"
print " loop ", nloop, " with ", len(loop), " points"
print(" loop ", nloop, " with ", len(loop), " points")
nloop = nloop + 1
waterlinestring += loopstring
waterlinestring += "(waterline end)" + "\n"
@ -174,7 +175,7 @@ class ObjectSurface:
# (see c++ code)
all_loops = []
for zh in zheights:
print "calculating Waterline at z= ", zh
print("calculating Waterline at z= ", zh)
wl.reset()
wl.setZ(zh) # height for this waterline
wl.run()
@ -184,10 +185,10 @@ class ObjectSurface:
n = 0
output = ""
for loops in all_loops: # at each z-height, we may get many loops
print " %d/%d:" % (n, len(all_loops))
print(" %d/%d:" % (n, len(all_loops)))
output += drawLoops(loops)
n = n + 1
print "(" + str(calctime) + ")"
print("(" + str(calctime) + ")")
return output
def _dropcutter(self, obj, s, bb):
@ -231,11 +232,11 @@ class ObjectSurface:
t_before = time.time()
pdc.run()
t_after = time.time()
print "calculation took ", t_after - t_before, " s"
print("calculation took ", t_after - t_before, " s")
# retrieve the points
clp = pdc.getCLPoints()
print "points received: " + str(len(clp))
print("points received: " + str(len(clp)))
# generate the path commands
output = ""
@ -296,7 +297,7 @@ class ObjectSurface:
mesh = parentJob.Base
if mesh is None:
return
print "base object: " + mesh.Name
print("base object: " + mesh.Name)
@ -499,13 +500,13 @@ class TaskPanel:
# get type of object
if sel.TypeId.startswith('Mesh'):
# it is a mesh already
print 'was already mesh'
print('was already mesh')
elif sel.TypeId.startswith('Part') and \
(sel.Shape.BoundBox.XLength > 0) and \
(sel.Shape.BoundBox.YLength > 0) and \
(sel.Shape.BoundBox.ZLength > 0):
print 'this is a solid Part object'
print('this is a solid Part object')
else:
FreeCAD.Console.PrintError(

View File

@ -22,6 +22,7 @@
# * *
# ***************************************************************************
from __future__ import print_function
import FreeCAD
import xml.sax
import FreeCADGui
@ -254,8 +255,8 @@ class ToolLibraryManager():
if listname == "<Main>":
self.saveMainLibrary(tt)
return True
except Exception, e:
print "could not parse file", e
except Exception as e:
print("could not parse file", e)
def write(self, filename, listname):
"exports the tooltable to a file"
@ -266,14 +267,14 @@ class ToolLibraryManager():
file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
file.write(tt.Content)
file.close()
print "Written ", unicode(filename[0])
print("Written ", unicode(filename[0]))
except Exception, e:
print "Could not write file:", e
except Exception as e:
print("Could not write file:", e)
def addnew(self, listname, tool, position = None):
"adds a new tool at the end of the table"
print listname, tool, position
print(listname, tool, position)
tt = self._findList(listname)
if position is None:
tt.addTools(tool)
@ -413,7 +414,7 @@ class EditorPanel():
def addTool(self):
t = Path.Tool()
print ("adding a new tool")
print("adding a new tool")
editform = FreeCADGui.PySideUic.loadUi(":/panels/ToolEdit.ui")
r = editform.exec_()

View File

@ -620,7 +620,7 @@ def addToJob(obj, jobname = None):
if r is False:
return None
else:
print form.cboProject.currentText()
print(form.cboProject.currentText())
job = [i for i in jobs if i.Name == form.cboProject.currentText()][0]
g = job.Group
@ -690,7 +690,7 @@ def arc(cx, cy, sx, sy, ex, ey, horizFeed=0, ez=None, ccw=False):
eps = 0.01
if (math.sqrt((cx - sx)**2 + (cy - sy)**2) - math.sqrt((cx - ex)**2 + (cy - ey)**2)) >= eps:
print "ERROR: Illegal arc: Start and end radii not equal"
print("ERROR: Illegal arc: Start and end radii not equal")
return ""
retstr = ""

View File

@ -21,6 +21,7 @@
#* USA *
#* *
#***************************************************************************
from __future__ import print_function
TOOLTIP=''' example post for Centroid CNC mill'''
import FreeCAD
@ -85,7 +86,7 @@ def export(selection,filename,argstring):
else:
UNITS = "G20"
if myMachine is None:
print "No machine found in this selection"
print("No machine found in this selection")
gcode =''
gcode+= HEADER % (FreeCAD.ActiveDocument.FileName)

View File

@ -20,7 +20,7 @@
# * USA *
# * *
# ***************************************************************************/
from __future__ import print_function
TOOLTIP='''
Dumper is an extremely simple postprocessor file for the Path workbench. It is used
@ -52,9 +52,9 @@ def export(objectslist, filename,argstring):
for obj in objectslist:
if not hasattr(obj, "Path"):
print "the object " + obj.Name + " is not a path. Please select only path and Compounds."
print("the object " + obj.Name + " is not a path. Please select only path and Compounds.")
return
print "postprocessing..."
print("postprocessing...")
output += parse(obj)
if SHOW_EDITOR:
@ -68,7 +68,7 @@ def export(objectslist, filename,argstring):
else:
final = output
print "done postprocessing."
print("done postprocessing.")
def parse(pathobj):
@ -90,4 +90,4 @@ def parse(pathobj):
out += str(c) + "\n"
return out
print __name__ + " gcode postprocessor loaded."
print(__name__ + " gcode postprocessor loaded.")

View File

@ -24,7 +24,7 @@
#* (c) Linden (Linden@aktfast.net) 2016 *
#* *
#***************************************************************************/
from __future__ import print_function
TOOLTIP='''
This is a postprocessor file for the Path workbench. It is used to
@ -114,10 +114,10 @@ def export(objectslist,filename,argstring):
global UNITS
for obj in objectslist:
if not hasattr(obj,"Path"):
print "the object " + obj.Name + " is not a path. Please select only path and Compounds."
print("the object " + obj.Name + " is not a path. Please select only path and Compounds.")
return
print "postprocessing..."
print("postprocessing...")
gcode = ""
#Find the machine.
@ -132,7 +132,7 @@ def export(objectslist,filename,argstring):
else:
UNITS = "G20"
if myMachine is None:
print "No machine found in this selection"
print("No machine found in this selection")
# write header
if OUTPUT_HEADER:
@ -177,7 +177,7 @@ def export(objectslist,filename,argstring):
else:
final = gcode
print "done postprocessing."
print("done postprocessing.")
gfile = pythonopen(filename,"wb")
gfile.write(gcode)
@ -259,5 +259,5 @@ def parse(pathobj):
return out
print __name__ + " gcode postprocessor loaded."
print(__name__ + " gcode postprocessor loaded.")

View File

@ -20,7 +20,7 @@
# * USA *
# * *
# ***************************************************************************/
from __future__ import print_function
TOOLTIP='''
This is an example postprocessor file for the Path workbench. It is used
@ -42,11 +42,11 @@ if open.__module__ == '__builtin__':
def export(objectslist, filename,argstring):
"called when freecad exports a list of objects"
if len(objectslist) > 1:
print "This script is unable to write more than one Path object"
print("This script is unable to write more than one Path object")
return
obj = objectslist[0]
if not hasattr(obj, "Path"):
print "the given object is not a path"
print("the given object is not a path")
gcode = obj.Path.toGCode()
gcode = parse(gcode)
gfile = pythonopen(filename, "wb")
@ -56,7 +56,7 @@ def export(objectslist, filename,argstring):
def parse(inputstring):
"parse(inputstring): returns a parsed output string"
print "postprocessing..."
print("postprocessing...")
output = ""
@ -95,7 +95,7 @@ def parse(inputstring):
output += "N" + str(linenr + 30) + " G17 G80 G40 G90\n"
output += "N" + str(linenr + 40) + " M99\n"
print "done postprocessing."
print("done postprocessing.")
return output
print __name__ + " gcode postprocessor loaded."
print(__name__ + " gcode postprocessor loaded.")

View File

@ -22,6 +22,7 @@
#* *
#***************************************************************************
from __future__ import print_function
TOOLTIP='''Post processor for Maho M 600E mill
Machines with Philips or Heidenhain control should be very easy to adapt.
@ -285,7 +286,7 @@ def export(selection,filename,argstring):
modalParamsDict[mp] = None
for obj in selection:
if not hasattr(obj,"Path"):
print "the object " + obj.Name + " is not a path. Please select only path and Compounds."
print("the object " + obj.Name + " is not a path. Please select only path and Compounds.")
return
myMachine = None
for pathobj in selection:
@ -297,7 +298,7 @@ def export(selection,filename,argstring):
else:
UNITS = "G20"
if myMachine is None:
print "No machine found in this selection"
print("No machine found in this selection")
gcode =''
gcode+= mkHeader(selection)

View File

@ -20,7 +20,7 @@
# * USA *
# * *
# ***************************************************************************/
from __future__ import print_function
TOOLTIP='''
This is a postprocessor file for the Path workbench. It is used to
@ -118,10 +118,10 @@ def export(objectslist, filename, argstring):
global UNITS
for obj in objectslist:
if not hasattr(obj, "Path"):
print "the object " + obj.Name + " is not a path. Please select only path and Compounds."
print("the object " + obj.Name + " is not a path. Please select only path and Compounds.")
return
print "postprocessing..."
print("postprocessing...")
gcode = ""
# Find the machine.
@ -137,7 +137,7 @@ def export(objectslist, filename, argstring):
else:
UNITS = "G20"
if myMachine is None:
print "No machine found in this selection"
print("No machine found in this selection")
# write header
if OUTPUT_HEADER:
@ -186,7 +186,7 @@ def export(objectslist, filename, argstring):
else:
final = gcode
print "done postprocessing."
print("done postprocessing.")
if not filename == '-':
gfile = pythonopen(filename, "wb")
@ -279,4 +279,4 @@ def parse(pathobj):
return out
print __name__ + " gcode postprocessor loaded."
print(__name__ + " gcode postprocessor loaded.")

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import datetime
from PathScripts import PostUtils
@ -81,14 +82,14 @@ def export(objectslist, filename, argstring):
if not hasattr(obj, "Path"):
s = "the object " + obj.Name
s += " is not a path. Please select only path and Compounds."
print s
print(s)
return
CurrentState = {
'X': 0, 'Y': 0, 'Z': 0, 'F': 0, 'S': 0,
'JSXY': 0, 'JSZ': 0, 'MSXY': 0, 'MSZ': 0
}
print "postprocessing..."
print("postprocessing...")
gcode = ""
# write header
@ -136,7 +137,7 @@ def export(objectslist, filename, argstring):
else:
final = gcode
print "done postprocessing."
print("done postprocessing.")
# Write the output
gfile = pythonopen(filename, "wb")
@ -216,11 +217,11 @@ def move(command):
txt += "," + format(command.Parameters["Z"], '.4f')
txt += "\n"
elif axis == "":
print "warning: skipping duplicate move."
print("warning: skipping duplicate move.")
else:
print CurrentState
print command
print "I don't know how to handle '{}' for a move.".format(axis)
print(CurrentState)
print(command)
print("I don't know how to handle '{}' for a move.".format(axis))
return txt
@ -255,7 +256,7 @@ def tool_change(command):
def comment(command):
print "a comment"
print("a comment")
return
@ -314,8 +315,8 @@ def parse(pathobj):
if c.Parameters:
CurrentState.update(c.Parameters)
else:
print "I don't know what the hell the command: ",
print command + " means. Maybe I should support it."
print("I don't know what the hell the command: ",end='')
print(command + " means. Maybe I should support it.")
return output
@ -323,6 +324,6 @@ def linenumber():
return ""
print __name__ + " gcode postprocessor loaded."
print(__name__ + " gcode postprocessor loaded.")
# eof

View File

@ -46,6 +46,7 @@ TODO
Many other OpenSBP commands not handled
'''
from __future__ import print_function
import FreeCAD
import os, Path
@ -81,7 +82,7 @@ def insert(filename,docname):
def parse(inputstring):
"parse(inputstring): returns a list of parsed output string"
print "preprocessing..."
print("preprocessing...")
# split the input by line
lines = inputstring.split("\n")
return_output = []
@ -182,7 +183,7 @@ def parse(inputstring):
if words[0] in ["CG"]: #Gcode circle/arc
if words[1] != "": # diameter mode
print "diameter mode not supported"
print("diameter mode not supported")
continue
else:
@ -201,9 +202,9 @@ def parse(inputstring):
#Make sure all appended paths have at least one move command.
if any (x in output for x in movecommand):
return_output.append(output)
print "done preprocessing."
print("done preprocessing.")
return return_output
print __name__ + " gcode preprocessor loaded."
print(__name__ + " gcode preprocessor loaded.")