Ejemplo n.º 1
0
    def onChanged(self, obj, prop):
        mode = 2
        obj.setEditorMode('Placement', mode)

        if prop == "PostProcessor" and obj.PostProcessor:
            processor = PostProcessor.load(obj.PostProcessor)
            self.tooltip = processor.tooltip
            self.tooltipArgs = processor.tooltipArgs
Ejemplo n.º 2
0
	def updateTooltip(self, item):
		if item.text() in self.tooltips.keys():
			tooltip = self.tooltips[item.text()]
		else:
			processor = PostProcessor.load(item.text())
			self.tooltips[item.text()] = processor.tooltip
			tooltip = processor.tooltip
		self.dialog.lwPostProcessor.setToolTip(tooltip)
Ejemplo n.º 3
0
 def updateTooltip(self, item):
     if item.text() in self.tooltips.keys():
         tooltip = self.tooltips[item.text()]
     else:
         processor = PostProcessor.load(item.text())
         self.tooltips[item.text()] = processor.tooltip
         tooltip = processor.tooltip
     self.dialog.lwPostProcessor.setToolTip(tooltip)
Ejemplo n.º 4
0
    def Activated(self):
        FreeCAD.ActiveDocument.openTransaction(
            translate("Path_Post", "Post Process the Selected path(s)"))
        FreeCADGui.addModule("PathScripts.PathPost")
        # select the Path Job that you want to post output from
        selected = FreeCADGui.Selection.getCompleteSelection()
        print "in activated %s" % (selected)

        # try to find the job, if it's not directly selected ...
        jobs = set()
        for obj in selected:
            if hasattr(obj, 'OutputFile') or hasattr(obj, 'PostProcessor'):
                jobs.add(obj)
            elif hasattr(obj, 'Path') or hasattr(obj, 'ToolNumber'):
                job = PathUtils.findParentJob(obj)
                if job:
                    jobs.add(job)
        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)

            # 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()
        FreeCAD.ActiveDocument.recompute()
Ejemplo n.º 5
0
    def Activated(self):
        FreeCAD.ActiveDocument.openTransaction(
            translate("Path_Post", "Post Process the Selected path(s)"))
        FreeCADGui.addModule("PathScripts.PathPost")
        # select the Path Job that you want to post output from
        selected = FreeCADGui.Selection.getCompleteSelection()
        print "in activated %s" %(selected)

        # try to find the job, if it's not directly selected ...
        jobs = set()
        for obj in selected:
            if hasattr(obj, 'OutputFile') or hasattr(obj, 'PostProcessor'):
                jobs.add(obj)
            elif hasattr(obj, 'Path') or hasattr(obj, 'ToolNumber'):
                job = PathUtils.findParentJob(obj)
                if job:
                    jobs.add(job)
        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)

            # 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()
        FreeCAD.ActiveDocument.recompute()
Ejemplo n.º 6
0
    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, '')
Ejemplo n.º 7
0
    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, '')
Ejemplo n.º 8
0
    def onChanged(self, obj, prop):
        mode = 2
        obj.setEditorMode('Placement', mode)

        if prop == "PostProcessor" and obj.PostProcessor:
            processor = PostProcessor.load(obj.PostProcessor)
            if processor.units:
                obj.MachineUnits = processor.units
            if processor.machineName:
                obj.MachineName = processor.machineName
            if processor.cornerMax:
                obj.X_Max = processor.cornerMax['x']
                obj.Y_Max = processor.cornerMax['y']
                obj.Z_Max = processor.cornerMax['z']
            if processor.cornerMin:
                obj.X_Min = processor.cornerMin['x']
                obj.Y_Min = processor.cornerMin['y']
                obj.Z_Min = processor.cornerMin['z']
            self.tooltip = processor.tooltip
            self.tooltipArgs = processor.tooltipArgs

            self.PostProcessorArgs = ''
Ejemplo n.º 9
0
    def onChanged(self, obj, prop):
        mode = 2
        obj.setEditorMode('Placement', mode)

        if prop == "PostProcessor" and obj.PostProcessor:
            processor = PostProcessor.load(obj.PostProcessor)
            if processor.units:
                obj.MachineUnits = processor.units
            if processor.machineName:
                obj.MachineName = processor.machineName
            if processor.cornerMax:
                obj.X_Max = processor.cornerMax['x']
                obj.Y_Max = processor.cornerMax['y']
                obj.Z_Max = processor.cornerMax['z']
            if processor.cornerMin:
                obj.X_Min = processor.cornerMin['x']
                obj.Y_Min = processor.cornerMin['y']
                obj.Z_Min = processor.cornerMin['z']
            self.tooltip = processor.tooltip
            self.tooltipArgs = processor.tooltipArgs

            self.PostProcessorArgs = ''
Ejemplo n.º 10
0
    def exportObjectsWith(self, objs, partname, job, sequence, extraargs=None):
        PathLog.track(extraargs)
        # check if the user has a project and has set the default post and
        # output filename
        # extraargs can be passed in at this time
        PathLog.track(partname, sequence)
        PathLog.track(objs)

        # partname = objs[0]
        # slist = objs[1]
        PathLog.track(objs, partname)

        postArgs = PathPreferences.defaultPostProcessorArgs()
        if hasattr(job, "PostProcessorArgs") and job.PostProcessorArgs:
            postArgs = job.PostProcessorArgs
        elif hasattr(job, "PostProcessor") and job.PostProcessor:
            postArgs = ""

        if extraargs is not None:
            postArgs += " {}".format(extraargs)

        PathLog.track(postArgs)

        postname = self.resolvePostProcessor(job)
        # filename = "-"
        filename = resolveFileName(job, partname, sequence)
        # if postname and needFilename:
        #     filename = 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, filename)
        else:
            return (True, "", filename)
Ejemplo n.º 11
0
 def getPostProcessor(self, name):
     if not name in self.processor.keys():
         processor = PostProcessor.load(name)
         self.processor[name] = processor
         return processor
     return self.processor[name]
Ejemplo n.º 12
0
 def onChanged(self, obj, prop):
     if prop == "PostProcessor" and obj.PostProcessor:
         processor = PostProcessor.load(obj.PostProcessor)
         self.tooltip = processor.tooltip
         self.tooltipArgs = processor.tooltipArgs
Ejemplo n.º 13
0
 def onChanged(self, obj, prop):
     if prop == "PostProcessor" and obj.PostProcessor:
         processor = PostProcessor.load(obj.PostProcessor)
         self.tooltip = processor.tooltip
         self.tooltipArgs = processor.tooltipArgs
Ejemplo n.º 14
0
 def getPostProcessor(self, name):
     if not name in self.processor.keys():
         processor = PostProcessor.load(name)
         self.processor[name] = processor
         return processor
     return self.processor[name]
Ejemplo n.º 15
0
 def test_postprocessors(self):
     """Test the postprocessors."""
     #
     # The tests are performed in the order they are listed:
     # one test performed on all of the postprocessors
     # then the next test on all of the postprocessors, etc.
     # You can comment out the tuples for tests that you don't want
     # to use.
     #
     tests_to_perform = (
         # (output_file_id, freecad_document, job_name, postprocessor_arguments,
         #  postprocessor_list)
         #
         # test with all of the defaults (metric mode, etc.)
         ("default", "boxtest1", "Job", "--no-show-editor", ()),
         # test in Imperial mode
         ("imperial", "boxtest1", "Job", "--no-show-editor --inches", ()),
         # test in metric, G55, M4, the other way around the part
         ("other_way", "boxtest1", "Job001", "--no-show-editor", ()),
         # test in metric, split by fixtures, G54, G55, G56
         ("split", "boxtest1", "Job002", "--no-show-editor", ()),
         # test in metric mode without the header
         ("no_header", "boxtest1", "Job", "--no-header --no-show-editor", ()),
         # test translating G81, G82, and G83 to G00 and G01 commands
         (
             "drill_translate",
             "drill_test1",
             "Job",
             "--no-show-editor --translate_drill",
             ("grbl", "refactored_grbl"),
         ),
     )
     #
     # The postprocessors to test.
     # You can comment out any postprocessors that you don't want
     # to test.
     #
     postprocessors_to_test = (
         "centroid",
         # "fanuc",
         "grbl",
         "linuxcnc",
         "mach3_mach4",
         "refactored_centroid",
         # "refactored_fanuc",
         "refactored_grbl",
         "refactored_linuxcnc",
         "refactored_mach3_mach4",
         "refactored_test",
     )
     #
     # Enough of the path to where the tests are stored so that
     # they can be found by the python interpreter.
     #
     PATHTESTS_LOCATION = "Mod/Path/PathTests"
     #
     # The following code tries to re-use an open FreeCAD document
     # as much as possible.  It compares the current document with
     # the document for the next test.  If the names are different
     # then the current document is closed and the new document is
     # opened.  The final document is closed at the end of the code.
     #
     current_document = ""
     for (
         output_file_id,
         freecad_document,
         job_name,
         postprocessor_arguments,
         postprocessor_list,
     ) in tests_to_perform:
         if current_document != freecad_document:
             if current_document != "":
                 FreeCAD.closeDocument(current_document)
             current_document = freecad_document
             current_document_path = (
                 FreeCAD.getHomePath()
                 + PATHTESTS_LOCATION
                 + os.path.sep
                 + current_document
                 + ".fcstd"
             )
             FreeCAD.open(current_document_path)
         job = FreeCAD.ActiveDocument.getObject(job_name)
         # Create the objects to be written by the postprocessor.
         postlist = PathPost.buildPostList(job)
         for postprocessor_id in postprocessors_to_test:
             if postprocessor_list == () or postprocessor_id in postprocessor_list:
                 print(
                     "\nRunning %s test on %s postprocessor:\n"
                     % (output_file_id, postprocessor_id)
                 )
                 processor = PostProcessor.load(postprocessor_id)
                 output_file_path = FreeCAD.getHomePath() + PATHTESTS_LOCATION
                 output_file_pattern = "test_%s_%s" % (
                     postprocessor_id,
                     output_file_id,
                 )
                 output_file_extension = ".ngc"
                 for idx, section in enumerate(postlist):
                     partname = section[0]
                     sublist = section[1]
                     output_filename = PathPost.processFileNameSubstitutions(
                         job,
                         partname,
                         idx,
                         output_file_path,
                         output_file_pattern,
                         output_file_extension,
                     )
                     # print("output file: " + output_filename)
                     file_path, extension = os.path.splitext(output_filename)
                     reference_file_name = "%s%s%s" % (file_path, "_ref", extension)
                     # print("reference file: " + reference_file_name)
                     gcode = processor.export(
                         sublist, output_filename, postprocessor_arguments
                     )
                     if not gcode:
                         print("no gcode")
                     with open(reference_file_name, "r") as fp:
                         reference_gcode = fp.read()
                     if not reference_gcode:
                         print("no reference gcode")
                     # Remove the "Output Time:" line in the header from the
                     # comparison if it is present because it changes with
                     # every test.
                     gcode_lines = [
                         i for i in gcode.splitlines(True) if "Output Time:" not in i
                     ]
                     reference_gcode_lines = [
                         i
                         for i in reference_gcode.splitlines(True)
                         if "Output Time:" not in i
                     ]
                     if gcode_lines != reference_gcode_lines:
                         msg = "".join(
                             difflib.ndiff(gcode_lines, reference_gcode_lines)
                         )
                         self.fail(
                             os.path.basename(output_filename)
                             + " output doesn't match:\n"
                             + msg
                         )
                     if not KEEP_DEBUG_OUTPUT:
                         os.remove(output_filename)
     if current_document != "":
         FreeCAD.closeDocument(current_document)