| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import FreeCAD |
| | import Part |
| | import Path |
| | import Path.Base.FeedRate as PathFeedRate |
| | import Path.Base.MachineState as PathMachineState |
| | from Path.Tool.toolbit import ToolBit |
| | import Path.Tool.Controller as PathToolController |
| | import PathScripts.PathUtils as PathUtils |
| |
|
| | from CAMTests.PathTestUtils import PathTestBase |
| |
|
| |
|
| | def createTool(name="t1", diameter=1.75): |
| | attrs = { |
| | "name": name or "t1", |
| | "shape": "endmill.fcstd", |
| | "parameter": {"Diameter": diameter}, |
| | "attribute": {}, |
| | } |
| | toolbit = ToolBit.from_dict(attrs) |
| | return toolbit.attach_to_doc(doc=FreeCAD.ActiveDocument) |
| |
|
| |
|
| | class TestPathHelpers(PathTestBase): |
| | def setUp(self): |
| | self.doc = FreeCAD.newDocument("TestPathUtils") |
| |
|
| | c1 = Path.Command("G0 Z10") |
| | c2 = Path.Command("G0 X20 Y10") |
| | c3 = Path.Command("G1 X20 Y10 Z5") |
| | c4 = Path.Command("G1 X20 Y20") |
| |
|
| | self.commandlist = [c1, c2, c3, c4] |
| |
|
| | def tearDown(self): |
| | FreeCAD.closeDocument("TestPathUtils") |
| |
|
| | def test00(self): |
| | """Test that FeedRate Helper populates horiz and vert feed rate based on TC""" |
| | t = createTool("test", 5.0) |
| | tc = PathToolController.Create("TC0", t) |
| | tc.VertRapid = 5 |
| | tc.HorizRapid = 10 |
| | tc.VertFeed = 15 |
| | tc.HorizFeed = 20 |
| |
|
| | resultlist = PathFeedRate.setFeedRate(self.commandlist, tc) |
| | print(resultlist) |
| |
|
| | self.assertTrue(resultlist[0].Parameters["F"] == 5) |
| | self.assertTrue(resultlist[1].Parameters["F"] == 10) |
| | self.assertTrue(resultlist[2].Parameters["F"] == 15) |
| | self.assertTrue(resultlist[3].Parameters["F"] == 20) |
| |
|
| | def test01(self): |
| | """Test that Machine State initializes and stores position correctly""" |
| |
|
| | machine = PathMachineState.MachineState() |
| | state = machine.getState() |
| | self.assertTrue(state["X"] == 0) |
| | self.assertTrue(state["Y"] == 0) |
| | self.assertTrue(state["Z"] == 0) |
| | self.assertTrue(machine.WCS == "G54") |
| |
|
| | for c in self.commandlist: |
| | result = machine.addCommand(c) |
| |
|
| | state = machine.getState() |
| | self.assertTrue(state["X"] == 20) |
| | self.assertTrue(state["Y"] == 20) |
| | self.assertTrue(state["Z"] == 5) |
| |
|
| | machine.addCommand(Path.Command("M3 S200")) |
| | self.assertTrue(machine.S == 200) |
| | self.assertTrue(machine.Spindle == "CW") |
| |
|
| | machine.addCommand(Path.Command("M4 S200")) |
| | self.assertTrue(machine.Spindle == "CCW") |
| |
|
| | machine.addCommand(Path.Command("M2")) |
| | self.assertTrue(machine.Spindle == "off") |
| | self.assertTrue(machine.S == 0) |
| |
|
| | machine.addCommand(Path.Command("G57")) |
| | self.assertTrue(machine.WCS == "G57") |
| |
|
| | machine.addCommand(Path.Command("M6 T5")) |
| | self.assertTrue(machine.T == 5) |
| |
|
| | |
| | result = machine.addCommand(Path.Command("G0 X20")) |
| | self.assertFalse(result) |
| |
|
| | result = machine.addCommand(Path.Command("G0 X30")) |
| | self.assertTrue(result) |
| |
|
| | |
| | result = machine.addCommand(Path.Command("G81 X50 Y50 Z0")) |
| | state = machine.getState() |
| | self.assertTrue(state["X"] == 50) |
| | self.assertTrue(state["Y"] == 50) |
| | self.assertTrue(state["Z"] == 5) |
| |
|
| | def test02(self): |
| | """Test PathUtils filterarcs""" |
| |
|
| | |
| | c = Part.Circle() |
| | c.Radius = 5 |
| | edge = c.toShape() |
| |
|
| | results = PathUtils.filterArcs(edge) |
| | self.assertTrue(len(results) == 2) |
| | e1 = results[0] |
| | self.assertTrue(isinstance(e1.Curve, Part.Circle)) |
| | self.assertTrue(Path.Geom.pointsCoincide(edge.Curve.Location, e1.Curve.Location)) |
| | self.assertTrue(edge.Curve.Radius == e1.Curve.Radius) |
| |
|
| | |
| | results = PathUtils.filterArcs(e1) |
| | self.assertTrue(len(results) == 1) |
| |
|
| | |
| | v1 = FreeCAD.Vector(0, 0, 0) |
| | v2 = FreeCAD.Vector(10, 0, 0) |
| | l = Part.makeLine(v1, v2) |
| | results = PathUtils.filterArcs(l) |
| | self.assertTrue(len(results) == 0) |
| |
|