Fix Path.Length calculation.

This commit is contained in:
Markus Lampert
2020-01-16 22:53:39 -08:00
parent 660335b1f3
commit d6c47715f3
4 changed files with 15 additions and 6 deletions

View File

@@ -60,7 +60,7 @@ Command::~Command()
// New methods
Placement Command::getPlacement (void) const
Placement Command::getPlacement (const Base::Vector3d pos) const
{
static const std::string x = "X";
static const std::string y = "Y";
@@ -68,7 +68,7 @@ Placement Command::getPlacement (void) const
static const std::string a = "A";
static const std::string b = "B";
static const std::string c = "C";
Vector3d vec(getParam(x),getParam(y),getParam(z));
Vector3d vec(getParam(x, pos.x),getParam(y, pos.y),getParam(z, pos.z));
Rotation rot;
rot.setYawPitchRoll(getParam(a),getParam(b),getParam(c));
Placement plac(vec,rot);

View File

@@ -49,7 +49,7 @@ namespace Path
virtual void Restore(Base::XMLReader &/*reader*/);
// specific methods
Base::Placement getPlacement (void) const; // returns a placement from the x,y,z,a,b,c parameters
Base::Placement getPlacement (const Base::Vector3d pos = Base::Vector3d()) const; // returns a placement from the x,y,z,a,b,c parameters
Base::Vector3d getCenter (void) const; // returns a 3d vector from the i,j,k parameters
void setCenter(const Base::Vector3d&, bool clockwise=true); // sets the center coordinates and the command name
std::string toGCode (int precision=6, bool padzero=true) const; // returns a GCode string representation of the command
@@ -61,9 +61,9 @@ namespace Path
void scaleBy(double factor); // scales the receiver - use for imperial/metric conversions
// this assumes the name is upper case
inline double getParam(const std::string &name) const {
inline double getParam(const std::string &name, double fallback = 0.0) const {
auto it = Parameters.find(name);
return it==Parameters.end()?0.0:it->second;
return it==Parameters.end() ? fallback : it->second;
}
// attributes

View File

@@ -129,7 +129,7 @@ double Toolpath::getLength()
Vector3d next;
for(std::vector<Command*>::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) {
std::string name = (*it)->Name;
next = (*it)->getPlacement().getPosition();
next = (*it)->getPlacement(last).getPosition();
if ( (name == "G0") || (name == "G00") || (name == "G1") || (name == "G01") ) {
// straight line
l += (next - last).Length();

View File

@@ -155,3 +155,12 @@ G0 Z0.500000
self.assertEqual(len(table.Tools), 2)
self.assertEqual(str(table.Tools), '{1: Tool 12.7mm Drill Bit, 2: Tool my other tool}' )
def test50(self):
"""Test Path.Length calculation"""
commands = []
commands.append(Path.Command("G1",{"X":1}))
commands.append(Path.Command("G1",{"Y":1}))
path = Path.Path(commands)
self.assertEqual(path.Length, 2)