Basic unit test for linuxcnc output.

This commit is contained in:
ml
2016-11-06 18:21:34 -08:00
committed by Markus Lampert
parent dce16252dc
commit 2aa2560529
7 changed files with 175 additions and 36 deletions

View File

@@ -28,10 +28,11 @@ from FreeCAD import Vector
import TechDraw
from PathScripts import PathUtils
from PathScripts.PathUtils import depth_params
from PySide import QtCore
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore, QtGui
from PySide import QtGui
# Qt tanslation handling
try:
_encoding = QtGui.QApplication.UnicodeUTF8
@@ -258,7 +259,8 @@ class ObjectContour:
if obj.Active:
path = Path.Path(output)
obj.Path = path
obj.ViewObject.Visibility = True
if obj.ViewObject:
obj.ViewObject.Visibility = True
else:
path = Path.Path("(inactive operation)")

View File

@@ -181,13 +181,14 @@ PathUtils.addToJob(obj)
FreeCAD.ActiveDocument.recompute()
@staticmethod
def Create(jobname = None):
def Create(jobname = None, assignViewProvider = True):
import PathScripts
import PathUtils
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "TC")
PathScripts.PathLoadTool.LoadTool(obj)
PathScripts.PathLoadTool._ViewProviderLoadTool(obj.ViewObject)
if assignViewProvider:
PathScripts.PathLoadTool._ViewProviderLoadTool(obj.ViewObject)
PathUtils.addToJob(obj, jobname)

View File

@@ -79,7 +79,7 @@ class DlgSelectPostProcessor:
class CommandPathPost:
def resolveFileName(self, job):
print("resolveFileName(%s)" % job.Label)
#print("resolveFileName(%s)" % job.Label)
path = PathPreferences.defaultOutputFile()
if job.OutputFile:
path = job.OutputFile
@@ -134,7 +134,7 @@ class CommandPathPost:
else:
filename = None
print("resolveFileName(%s, %s) -> '%s'" % (path, policy, filename))
#print("resolveFileName(%s, %s) -> '%s'" % (path, policy, filename))
return filename
def resolvePostProcessor(self, job):
@@ -179,35 +179,44 @@ class CommandPathPost:
job = PathUtils.findParentJob(obj)
if job:
jobs.add(job)
fail = True
rc = ''
if len(jobs) != 1:
FreeCAD.Console.PrintError("Please select a single job or other path object\n")
FreeCAD.ActiveDocument.abortTransaction()
else:
job = jobs.pop()
print("Job for selected objects = %s" % job.Name)
(fail, rc) = exportObjectsWith(selected, job)
# check if the user has a project and has set the default post and
# output filename
postArgs = PathPreferences.defaultPostProcessorArgs()
if hasattr(job, "PostProcessorArgs") and job.PostProcessorArgs:
postArgs = job.PostProcessorArgs
elif hasattr(job, "PostProcessor") and job.PostProcessor:
postArgs = ''
postname = self.resolvePostProcessor(job)
if postname:
filename = self.resolveFileName(job)
if postname and filename:
print("post: %s(%s, %s)" % (postname, filename, postArgs))
processor = PostProcessor.load(postname)
processor.export(selected, filename, postArgs)
FreeCAD.ActiveDocument.commitTransaction()
else:
FreeCAD.ActiveDocument.abortTransaction()
if fail:
FreeCAD.ActiveDocument.abortTransaction()
else:
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
def exportObjectsWith(self, objs, job, needFilename = True):
# check if the user has a project and has set the default post and
# output filename
postArgs = PathPreferences.defaultPostProcessorArgs()
if hasattr(job, "PostProcessorArgs") and job.PostProcessorArgs:
postArgs = job.PostProcessorArgs
elif hasattr(job, "PostProcessor") and job.PostProcessor:
postArgs = ''
postname = self.resolvePostProcessor(job)
filename = '-'
if postname and needFilename:
filename = self.resolveFileName(job)
if postname and filename:
print("post: %s(%s, %s)" % (postname, filename, postArgs))
processor = PostProcessor.load(postname)
gcode = processor.export(objs, filename, postArgs)
return (False, gcode)
else:
return (True, '')
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Post', CommandPathPost())

View File

@@ -78,4 +78,4 @@ class PostProcessor:
self.script = script
def export(self, obj, filename, args):
self.script.export(obj, filename, args)
return self.script.export(obj, filename, args)

View File

@@ -38,6 +38,7 @@ Arguments for linuxcnc:
--header,--no-header ... output headers (--header)
--comments,--no-comments ... output comments (--comments)
--line-numbers,--no-line-numbers ... prefix with line numbers (--no-lin-numbers)
--show-editor, --no-show-editor ... pop up editor before writing output(--show-editor)
'''
import datetime
@@ -90,6 +91,7 @@ def processArguments(argstring):
global OUTPUT_HEADER
global OUTPUT_COMMENTS
global OUTPUT_LINE_NUMBERS
global SHOW_EDITOR
for arg in argstring.split():
if arg == '--header':
OUTPUT_HEADER = True
@@ -103,6 +105,10 @@ def processArguments(argstring):
OUTPUT_LINE_NUMBERS = True
elif arg == '--no-line-numbers':
OUTPUT_LINE_NUMBERS = False
elif arg == '--show-editor':
SHOW_EDITOR = True
elif arg == '--no-show-editor':
SHOW_EDITOR = False
def export(objectslist, filename, argstring):
processArguments(argstring)
@@ -179,9 +185,12 @@ def export(objectslist, filename, argstring):
print "done postprocessing."
gfile = pythonopen(filename, "wb")
gfile.write(gcode)
gfile.close()
if not filename == '-':
gfile = pythonopen(filename, "wb")
gfile.write(final)
gfile.close()
return final
def linenumber():