def test00(self): """Test Basic Drill Generator Return""" v1 = FreeCAD.Vector(0, 0, 10) v2 = FreeCAD.Vector(0, 0, 0) e = Part.makeLine(v1, v2) result = generator.generate(e) self.assertTrue(type(result) is list) self.assertTrue(type(result[0]) is Path.Command) command = result[0] self.assertTrue(command.Name == "G81") self.assertTrue(command.Parameters["R"] == 10) self.assertTrue(command.Parameters["X"] == 0) self.assertTrue(command.Parameters["Y"] == 0) self.assertTrue(command.Parameters["Z"] == 0) # repeat must be > 0 args = {"edge": e, "repeat": 0} self.assertRaises(ValueError, generator.generate, **args) # repeat must be integer args = {"edge": e, "repeat": 1.5} self.assertRaises(ValueError, generator.generate, **args)
def test41(self): """Not specifying retract height should set R parameter to Z position of start point""" v1 = FreeCAD.Vector(0, 0, 10) v2 = FreeCAD.Vector(0, 0, 0) e = Part.makeLine(v1, v2) result = generator.generate(e) command = result[0] self.assertTrue(command.Parameters["R"] == 10.0)
def test40(self): """Specifying retract height should set R parameter to specified value""" v1 = FreeCAD.Vector(0, 0, 10) v2 = FreeCAD.Vector(0, 0, 0) e = Part.makeLine(v1, v2) result = generator.generate(e, retractheight=20.0) command = result[0] self.assertTrue(command.Parameters["R"] == 20.0)
def test30(self): """Test Basic Dwell Drill Generator Return""" v1 = FreeCAD.Vector(0, 0, 10) v2 = FreeCAD.Vector(0, 0, 0) e = Part.makeLine(v1, v2) result = generator.generate(e, dwelltime=0.5) self.assertTrue(type(result) is list) self.assertTrue(type(result[0]) is Path.Command) command = result[0] self.assertTrue(command.Name == "G82") self.assertTrue(command.Parameters["P"] == 0.5) # dwelltime should be a float args = {"edge": e, "dwelltime": 1} self.assertRaises(ValueError, generator.generate, **args)
def test20(self): """Test Basic Peck Drill Generator Return""" v1 = FreeCAD.Vector(0, 0, 10) v2 = FreeCAD.Vector(0, 0, 0) e = Part.makeLine(v1, v2) result = generator.generate(e, peckdepth=1.2) self.assertTrue(type(result) is list) self.assertTrue(type(result[0]) is Path.Command) command = result[0] self.assertTrue(command.Name == "G83") self.assertTrue(command.Parameters["Q"] == 1.2) # peckdepth must be a float args = {"edge": e, "peckdepth": 1} self.assertRaises(ValueError, generator.generate, **args)
def circularHoleExecute(self, obj, holes): """circularHoleExecute(obj, holes) ... generate drill operation for each hole in holes.""" PathLog.track() machine = PathMachineState.MachineState() self.commandlist.append(Path.Command("(Begin Drilling)")) # rapid to clearance height command = Path.Command("G0", {"Z": obj.ClearanceHeight.Value}) machine.addCommand(command) self.commandlist.append(command) self.commandlist.append(Path.Command("G90")) # Absolute distance mode # Calculate offsets to add to target edge endoffset = 0.0 if obj.ExtraOffset == "Drill Tip": endoffset = PathUtils.drillTipLength(self.tool) elif obj.ExtraOffset == "2x Drill Tip": endoffset = PathUtils.drillTipLength(self.tool) * 2 # http://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g98-g99 self.commandlist.append(Path.Command(obj.ReturnLevel)) holes = PathUtils.sort_locations(holes, ["x", "y"]) # This section is technical debt. The computation of the # target shapes should be factored out for re-use. # This will likely mean refactoring upstream CircularHoleBase to pass # spotshapes instead of holes. startHeight = obj.StartDepth.Value + self.job.SetupSheet.SafeHeightOffset.Value edgelist = [] for hole in holes: v1 = FreeCAD.Vector(hole["x"], hole["y"], obj.StartDepth.Value) v2 = FreeCAD.Vector(hole["x"], hole["y"], obj.FinalDepth.Value - endoffset) edgelist.append(Part.makeLine(v1, v2)) # iterate the edgelist and generate gcode for edge in edgelist: PathLog.debug(edge) # move to hole location startPoint = edge.Vertexes[0].Point command = Path.Command("G0", { "X": startPoint.x, "Y": startPoint.y }) self.commandlist.append(command) machine.addCommand(command) command = Path.Command("G0", {"Z": startHeight}) self.commandlist.append(command) machine.addCommand(command) # command = Path.Command("G1", {"Z": obj.StartDepth.Value}) # self.commandlist.append(command) # machine.addCommand(command) # Technical Debt: We are assuming the edges are aligned. # This assumption should be corrected and the necessary rotations # performed to align the edge with the Z axis for drilling # Perform drilling dwelltime = obj.DwellTime if obj.DwellEnabled else 0.0 peckdepth = obj.PeckDepth.Value if obj.PeckEnabled else 0.0 repeat = 1 # technical debt: Add a repeat property for user control chipBreak = (obj.chipBreakEnabled and obj.PeckEnabled) try: drillcommands = generator.generate(edge, dwelltime, peckdepth, repeat, obj.RetractHeight.Value, chipBreak=chipBreak) except ValueError as e: # any targets that fail the generator are ignored PathLog.info(e) continue for command in drillcommands: self.commandlist.append(command) machine.addCommand(command) # Cancel canned drilling cycle self.commandlist.append(Path.Command("G80")) command = Path.Command("G0", {"Z": obj.SafeHeight.Value}) self.commandlist.append(command) machine.addCommand(command) # Apply feedrates to commands PathFeedRate.setFeedRate(self.commandlist, obj.ToolController)