Example #1
0
    def test080(self):
        # Split by Operation
        self.job.SplitOutput = True
        self.job.OrderOutputBy = "Operation"
        outlist = PathPost.buildPostList(self.job)

        teststring = "%j.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "MainJob-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "MainJob-1.nc")

        teststring = "%O-%j.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "OutsideProfile-MainJob-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "DrillAllHoles-MainJob-1.nc")
Example #2
0
    def test070(self):
        # Split by WCS
        self.job.SplitOutput = True
        self.job.OrderOutputBy = "Fixture"
        outlist = PathPost.buildPostList(self.job)

        teststring = "%j.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "MainJob-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "MainJob-1.nc")

        teststring = "%W-%j.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "G54-MainJob-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "G55-MainJob-1.nc")
Example #3
0
 def test030(self):
     teststring = "%M/outfile.nc"
     self.job.PostProcessorOutputFile = teststring
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(filename, f"{self.macro}outfile.nc")
Example #4
0
    def test060(self):
        # # Split by Tool
        self.job.SplitOutput = True
        self.job.OrderOutputBy = "Tool"
        outlist = PathPost.buildPostList(self.job)

        # substitute jobname and use default sequence numbers
        teststring = "%j.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "MainJob-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "MainJob-1.nc")

        # Use Toolnumbers and default sequence numbers
        teststring = "%T.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        outlist = PathPost.buildPostList(self.job)
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "5-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "2-1.nc")

        # Use Tooldescriptions and default sequence numbers
        teststring = "%t.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        outlist = PathPost.buildPostList(self.job)
        subpart, objs = outlist[0]
        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "TC__7_16__two_flute-0.nc")
        subpart, objs = outlist[1]
        filename = PathPost.resolveFileName(self.job, subpart, 1)
        self.assertEqual(filename, "TC__Drill-1.nc")
Example #5
0
 def test010(self):
     # Substitute current file path
     teststring = "%D/testfile.nc"
     self.job.PostProcessorOutputFile = teststring
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(filename, f"{self.testfilepath}/testfile.nc")
Example #6
0
 def test050(self):
     # explicitly using the sequence number should include it where indicated.
     teststring = "%S-%d.nc"
     self.job.PostProcessorOutputFile = teststring
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(filename, "0-test_filenaming.nc")
Example #7
0
 def test030(self):
     # No splitting should include all ops, tools, and fixtures
     self.job.SplitOutput = False
     self.job.OrderOutputBy = "Operation"
     postlist = PathPost.buildPostList(self.job)
     firstoutputitem = postlist[0]
     firstoplist = firstoutputitem[1]
     self.assertTrue(len(firstoplist) == 14)
Example #8
0
 def test040(self):
     # unused substitution strings should be ignored
     teststring = "%d%T%t%W%O/testdoc.nc"
     self.job.PostProcessorOutputFile = teststring
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(filename, f"{self.testfilename}/testdoc.nc")
Example #9
0
    def test010(self):
        postlist = PathPost.buildPostList(self.job)

        self.assertTrue(type(postlist) is list)

        firstoutputitem = postlist[0]
        self.assertTrue(type(firstoutputitem) is tuple)
        self.assertTrue(type(firstoutputitem[0]) is str)
        self.assertTrue(type(firstoutputitem[1]) is list)
Example #10
0
    def Activate(self):
        self.taskForm = CAMoticsUI(self)
        FreeCADGui.Control.showDialog(self.taskForm)
        self.job = FreeCADGui.Selection.getSelectionEx()[0].Object
        self.SIM.set_metric()
        self.SIM.set_resolution("high")

        bb = self.job.Stock.Shape.BoundBox
        self.SIM.set_workpiece(
            min=(bb.XMin, bb.YMin, bb.ZMin), max=(bb.XMax, bb.YMax, bb.ZMax)
        )

        for t in self.job.Tools.Group:
            self.SIM.set_tool(
                t.ToolNumber,
                metric=True,
                shape=self.SHAPEMAP.get(t.Tool.ShapeName, "Cylindrical"),
                length=t.Tool.Length.Value,
                diameter=t.Tool.Diameter.Value,
            )

        postlist = PathPost.buildPostList(self.job)
        PathLog.track(postlist)
        # self.filenames = [PathPost.resolveFileName(self.job)]

        success = True

        finalgcode = ""
        for idx, section in enumerate(postlist):
            partname = section[0]
            sublist = section[1]

            result, gcode, name = PathPost.CommandPathPost().exportObjectsWith(
                sublist,
                partname,
                self.job,
                idx,
                extraargs="--no-show-editor",
            )
            self.filenames.append(name)
            PathLog.track(result, gcode, name)

            if result is None:
                success = False
            else:
                finalgcode += gcode

        if not success:
            return

        self.SIM.compute_path(finalgcode)
        self.SIM.wait()

        tot = sum([step["time"] for step in self.SIM.get_path()])
        PathLog.debug("sim time: {}".format(tot))
        self.taskForm.setRunTime(tot)
Example #11
0
    def test050(self):
        # ordering by tool with tool description for string
        teststring = "%t.nc"
        self.job.SplitOutput = True
        self.job.PostProcessorOutputFile = teststring
        self.job.OrderOutputBy = "Tool"
        postlist = PathPost.buildPostList(self.job)

        firstoutputitem = postlist[0]
        self.assertTrue(firstoutputitem[0] == "TC__7_16__two_flute")
Example #12
0
 def test030(self):
     teststring = "%M/outfile.nc"
     self.job.PostProcessorOutputFile = teststring
     PathPreferences.setOutputFileDefaults(
         teststring, "Append Unique ID on conflict"
     )
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(filename, f"{self.macro}outfile.nc")
Example #13
0
    def test015(self):
        # Test basic string substitution without splitting
        teststring = "~/Desktop/%j.nc"
        self.job.PostProcessorOutputFile = teststring
        self.job.SplitOutput = False
        outlist = PathPost.buildPostList(self.job)

        self.assertTrue(len(outlist) == 1)
        subpart, objs = outlist[0]

        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, "~/Desktop/MainJob.nc")
Example #14
0
    def test060(self):
        # Ordering by fixture and splitting
        teststring = "%W.nc"
        self.job.SplitOutput = True
        self.job.PostProcessorOutputFile = teststring
        self.job.OrderOutputBy = "Fixture"

        postlist = PathPost.buildPostList(self.job)
        firstoutputitem = postlist[0]
        firstoplist = firstoutputitem[1]
        self.assertTrue(len(firstoplist) == 6)
        self.assertTrue(firstoutputitem[0] == "G54")
Example #15
0
    def test000(self):
        # Test basic name generation with empty string
        FreeCAD.setActiveDocument(self.doc.Label)
        teststring = ""
        self.job.PostProcessorOutputFile = teststring
        self.job.SplitOutput = False
        outlist = PathPost.buildPostList(self.job)

        self.assertTrue(len(outlist) == 1)
        subpart, objs = outlist[0]

        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(filename, f"{self.testfilename}.nc")
Example #16
0
 def test010(self):
     # Substitute current file path
     teststring = "%D/testfile.nc"
     self.job.PostProcessorOutputFile = teststring
     PathPreferences.setOutputFileDefaults(
         teststring, "Append Unique ID on conflict"
     )
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(
         os.path.normpath(filename),
         os.path.normpath(f"{self.testfilepath}/testfile.nc"),
     )
Example #17
0
 def test040(self):
     # unused substitution strings should be ignored
     teststring = "%d%T%t%W%O/testdoc.nc"
     self.job.PostProcessorOutputFile = teststring
     PathPreferences.setOutputFileDefaults(
         teststring, "Append Unique ID on conflict"
     )
     outlist = PathPost.buildPostList(self.job)
     subpart, objs = outlist[0]
     filename = PathPost.resolveFileName(self.job, subpart, 0)
     self.assertEqual(
         os.path.normpath(filename),
         os.path.normpath(f"{self.testfilename}/testdoc.nc"),
     )
Example #18
0
    def test040(self):
        # Test splitting by tool
        # ordering by tool with toolnumber for string
        teststring = "%T.nc"
        self.job.SplitOutput = True
        self.job.PostProcessorOutputFile = teststring
        self.job.OrderOutputBy = "Tool"
        postlist = PathPost.buildPostList(self.job)

        firstoutputitem = postlist[0]
        self.assertTrue(firstoutputitem[0] == str(5))

        # check length of output
        firstoplist = firstoutputitem[1]
        self.assertTrue(len(firstoplist) == 5)
Example #19
0
    def test015(self):
        # Test basic string substitution without splitting
        teststring = "~/Desktop/%j.nc"
        self.job.PostProcessorOutputFile = teststring
        PathPreferences.setOutputFileDefaults(
            teststring, "Append Unique ID on conflict"
        )
        self.job.SplitOutput = False
        outlist = PathPost.buildPostList(self.job)

        self.assertTrue(len(outlist) == 1)
        subpart, objs = outlist[0]

        filename = PathPost.resolveFileName(self.job, subpart, 0)
        self.assertEqual(
            os.path.normpath(filename), os.path.normpath("~/Desktop/MainJob.nc")
        )
Example #20
0
 def test020(self):
     # Without splitting, result should be list of one item
     self.job.SplitOutput = False
     self.job.OrderOutputBy = "Operation"
     postlist = PathPost.buildPostList(self.job)
     self.assertTrue(len(postlist) == 1)
Example #21
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)