Path: improved Command efficiency

This commit is contained in:
Zheng, Lei
2017-03-17 16:21:02 +08:00
committed by wmayer
parent bf064df4da
commit 226e812c19
2 changed files with 36 additions and 60 deletions

View File

@@ -58,68 +58,38 @@ Command::~Command()
// New methods
Placement Command::getPlacement (void)
Placement Command::getPlacement (void) const
{
std::string x = "X";
std::string y = "Y";
std::string z = "Z";
std::string a = "A";
std::string b = "B";
std::string c = "C";
double xval = 0.0;
double yval = 0.0;
double zval = 0.0;
double aval = 0.0;
double bval = 0.0;
double cval = 0.0;
if (Parameters.count(x))
xval = Parameters[x];
if (Parameters.count(y))
yval = Parameters[y];
if (Parameters.count(z))
zval = Parameters[z];
if (Parameters.count(a))
aval = Parameters[a];
if (Parameters.count(b))
bval = Parameters[b];
if (Parameters.count(c))
cval = Parameters[c];
Vector3d vec(xval,yval,zval);
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));
Rotation rot;
rot.setYawPitchRoll(aval,bval,cval);
rot.setYawPitchRoll(getParam(a),getParam(b),getParam(c));
Placement plac(vec,rot);
return plac;
}
Vector3d Command::getCenter (void)
Vector3d Command::getCenter (void) const
{
std::string i = "I";
std::string j = "J";
std::string k = "K";
double ival = 0.0;
double jval = 0.0;
double kval = 0.0;
if (Parameters.count(i))
ival = Parameters[i];
if (Parameters.count(j))
jval = Parameters[j];
if (Parameters.count(k))
kval = Parameters[k];
Vector3d vec(ival,jval,kval);
static const std::string i = "I";
static const std::string j = "J";
static const std::string k = "K";
Vector3d vec(getParam(i),getParam(j),getParam(k));
return vec;
}
double Command::getValue(const std::string& attr)
double Command::getValue(const std::string& attr) const
{
std::string a(attr);
boost::to_upper(a);
double val = 0.0;
if (Parameters.count(a))
val = Parameters[a];
return val;
return getParam(a);
}
bool Command::has(const std::string& attr)
bool Command::has(const std::string& attr) const
{
std::string a(attr);
boost::to_upper(a);
@@ -210,12 +180,12 @@ void Command::setFromPlacement (const Base::Placement &plac)
{
Name = "G1";
Parameters.clear();
std::string x = "X";
std::string y = "Y";
std::string z = "Z";
std::string a = "A";
std::string b = "B";
std::string c = "C";
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";
double xval, yval, zval, aval, bval, cval;
xval = plac.getPosition().x;
yval = plac.getPosition().y;
@@ -242,9 +212,9 @@ void Command::setCenter(const Base::Vector3d &pos, bool clockwise)
} else {
Name = "G3";
}
std::string i = "I";
std::string j = "J";
std::string k = "K";
static const std::string i = "I";
static const std::string j = "J";
static const std::string k = "K";
double ival, jval, kval;
ival = pos.x;
jval = pos.y;

View File

@@ -49,15 +49,21 @@ namespace Path
virtual void Restore(Base::XMLReader &/*reader*/);
// specific methods
Base::Placement getPlacement (void); // returns a placement from the x,y,z,a,b,c parameters
Base::Vector3d getCenter (void); // returns a 3d vector from the i,j,k parameters
Base::Placement getPlacement (void) 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 (void) const; // returns a GCode string representation of the command
void setFromGCode (const std::string&); // sets the parameters from the contents of the given GCode string
void setFromPlacement (const Base::Placement&); // sets the parameters from the contents of the given placement
bool has(const std::string&); // returns true if the given string exists in the parameters
bool has(const std::string&) const; // returns true if the given string exists in the parameters
Command transform(const Base::Placement); // returns a transformed copy of this command
double getValue(const std::string&); // returns the value of a given parameter
double getValue(const std::string &name) const; // returns the value of a given parameter
// this assumes the name is upper case
inline double getParam(const std::string &name) const {
auto it = Parameters.find(name);
return it==Parameters.end()?0.0:it->second;
}
// attributes
std::string Name;