Files
create/src/Mod/Path/PathTests/TestPathHelpers.py
mlampert 1c530b2634 PATH: Feature/dogbone ii (#7660)
* Start of new dogbone dressup

* Added Instruction and tangents support for G2/3 moves

* Added Maneuver class to represent a set of moves and process them coherently

* Created kinks and verify their creation.

* Added dogbone detection and verification

* Simplified gcode strings

* Added horizontal t-bones generation

* Added support for vertical t-bone

* Consolidated t-bone creation

* Added support for pathLength

* Added support for tbone on short edge

* Added support for long edges

* Added support for dogbones

* Fixed dogbone for non-horizontal lead-in

* Horizontal bone adaptive length tests

* Fixed dogbone angle and adaptive length

* Some code cleanup

* Added adaptive length tests for dogbones

* Split base data classes into their own PathLanguage module.

* Splitting dogboneII implementation into its constituents

* Moved adaptive length into DogbonII module

* Separate dogboneII generator test cases and changed interface to allow for dynamic length calculations

* Unit tests for length calculation

* Initial DogboneII unit test

* Unit tests and fixes for plunge move handling

* Unit tests for the remaining styles and incision strategies

* Basic DogboneII gui

* Added support for markers

* Better color and selection scheme for markers

* Cleaned up import statements

* Added DogboneII to Path WB init

* Support for dogbone on dogbone and fixed t-bone generation

* Fixed t-bone on short leg bones

* Fixed tbone on short edge when short edge is m1

* Fixed t-bone on long edge for m0/m1 and CW/CCW

* Removed redundant code

* Removed redundant 'Dress-up' from menu entries

* black code formatting

* added generator to cmake

* Fixed typos
2022-11-02 15:25:09 -05:00

152 lines
5.6 KiB
Python

# -*- coding: utf-8 -*-
# ***************************************************************************
# * Copyright (c) 2021 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Part
import Path
import Path.Base.FeedRate as PathFeedRate
import Path.Base.MachineState as PathMachineState
import Path.Tool.Bit as PathToolBit
import Path.Tool.Controller as PathToolController
import PathScripts.PathUtils as PathUtils
from PathTests.PathTestUtils import PathTestBase
def createTool(name="t1", diameter=1.75):
attrs = {
"shape": None,
"name": name,
"parameter": {"Diameter": diameter},
"attribute": [],
}
return PathToolBit.Factory.CreateFromAttrs(attrs, name)
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)
# Test that non-change commands return false
result = machine.addCommand(Path.Command("G0 X20"))
self.assertFalse(result)
result = machine.addCommand(Path.Command("G0 X30"))
self.assertTrue(result)
# Test that Drilling moves are handled correctly
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"""
# filter a full circle
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)
# filter a 180 degree arc
results = PathUtils.filterArcs(e1)
self.assertTrue(len(results) == 1)
# Handle a straight segment
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)