Skip to content

Commit

Permalink
Merge pull request #2909 from mlampert/bugfix/path-length
Browse files Browse the repository at this point in the history
Path: Fix Path.Length calculation.
  • Loading branch information
sliptonic committed Jan 18, 2020
2 parents 120b69c + ec80948 commit 099d06a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Path/App/Command.cpp
Expand Up @@ -60,15 +60,15 @@ 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";
static const std::string z = "Z";
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);
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Path/App/Command.h
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Path/App/Path.cpp
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions src/Mod/Path/PathTests/TestPathCore.py
Expand Up @@ -155,3 +155,12 @@ def test20(self):

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)

0 comments on commit 099d06a

Please sign in to comment.