Added center property to Path to deal with rendering rotational axis.
This commit is contained in:
committed by
Yorik van Havre
parent
1f030de9ac
commit
cbd5f297f3
@@ -51,9 +51,10 @@ Toolpath::Toolpath()
|
||||
}
|
||||
|
||||
Toolpath::Toolpath(const Toolpath& otherPath)
|
||||
:vpcCommands(otherPath.vpcCommands.size())
|
||||
: vpcCommands(otherPath.vpcCommands.size())
|
||||
, center(otherPath.center)
|
||||
{
|
||||
operator=(otherPath);
|
||||
*this = otherPath;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
@@ -67,8 +68,10 @@ Toolpath &Toolpath::operator=(const Toolpath& otherPath)
|
||||
clear();
|
||||
vpcCommands.resize(otherPath.vpcCommands.size());
|
||||
int i = 0;
|
||||
for (std::vector<Command*>::const_iterator it=otherPath.vpcCommands.begin();it!=otherPath.vpcCommands.end();++it,i++)
|
||||
for (std::vector<Command*>::const_iterator it=otherPath.vpcCommands.begin();it!=otherPath.vpcCommands.end();++it,i++) {
|
||||
vpcCommands[i] = new Command(**it);
|
||||
}
|
||||
center = otherPath.center;
|
||||
recalculate();
|
||||
return *this;
|
||||
}
|
||||
@@ -229,7 +232,7 @@ void Toolpath::recalculate(void) // recalculates the path cache
|
||||
|
||||
// TODO recalculate the KDL stuff. At the moment, this is unused.
|
||||
|
||||
/*
|
||||
#if 0
|
||||
// delete the old and create a new one
|
||||
if(pcPath)
|
||||
delete (pcPath);
|
||||
@@ -281,7 +284,7 @@ void Toolpath::recalculate(void) // recalculates the path cache
|
||||
} catch (KDL::Error &e) {
|
||||
throw Base::Exception(e.Description());
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
|
||||
// reimplemented from base class
|
||||
@@ -291,19 +294,35 @@ unsigned int Toolpath::getMemSize (void) const
|
||||
return toGCode().size();
|
||||
}
|
||||
|
||||
void Toolpath::setCenter(const Base::Vector3d &c)
|
||||
{
|
||||
center = c;
|
||||
recalculate();
|
||||
}
|
||||
|
||||
static void saveCenter(Writer &writer, const Base::Vector3d ¢er)
|
||||
{
|
||||
writer.Stream() << writer.ind() << "<Center x=\"" << center.x << "\" y=\"" << center.y << "\" z=\"" << center.z << "\"/>" << std::endl;
|
||||
}
|
||||
|
||||
void Toolpath::Save (Writer &writer) const
|
||||
{
|
||||
if (writer.isForceXML()) {
|
||||
writer.Stream() << writer.ind() << "<Path count=\"" << getSize() <<"\">" << std::endl;
|
||||
writer.Stream() << writer.ind() << "<Path count=\"" << getSize() << "\" version=\"" << SchemaVersion << "\">" << std::endl;
|
||||
writer.incInd();
|
||||
for(unsigned int i = 0;i<getSize(); i++)
|
||||
saveCenter(writer, center);
|
||||
for(unsigned int i = 0; i < getSize(); i++) {
|
||||
vpcCommands[i]->Save(writer);
|
||||
}
|
||||
writer.decInd();
|
||||
writer.Stream() << writer.ind() << "</Path>" << std::endl;
|
||||
} else {
|
||||
writer.Stream() << writer.ind()
|
||||
<< "<Path file=\"" << writer.addFile((writer.ObjectName+".nc").c_str(), this) << "\"/>" << std::endl;
|
||||
<< "<Path file=\"" << writer.addFile((writer.ObjectName+".nc").c_str(), this) << "\" version=\"" << SchemaVersion << "\">" << std::endl;
|
||||
writer.incInd();
|
||||
saveCenter(writer, center);
|
||||
writer.decInd();
|
||||
}
|
||||
writer.Stream() << writer.ind() << "</Path>" << std::endl;
|
||||
}
|
||||
|
||||
void Toolpath::SaveDocFile (Base::Writer &writer) const
|
||||
|
||||
@@ -64,12 +64,19 @@ namespace Path
|
||||
std::string toGCode(void) const; // gets a gcode string representation from the Path
|
||||
|
||||
// shortcut functions
|
||||
unsigned int getSize(void) const{return vpcCommands.size();}
|
||||
const std::vector<Command*> &getCommands(void)const{return vpcCommands;}
|
||||
const Command &getCommand(unsigned int pos)const {return *vpcCommands[pos];}
|
||||
unsigned int getSize(void) const { return vpcCommands.size(); }
|
||||
const std::vector<Command*> &getCommands(void) const { return vpcCommands; }
|
||||
const Command &getCommand(unsigned int pos) const { return *vpcCommands[pos]; }
|
||||
|
||||
// support for rotation
|
||||
const Base::Vector3d& getCenter() const { return center; }
|
||||
void setCenter(const Base::Vector3d &c);
|
||||
|
||||
static const int SchemaVersion = 2;
|
||||
|
||||
protected:
|
||||
std::vector<Command*> vpcCommands;
|
||||
Base::Vector3d center;
|
||||
//KDL::Path_Composite *pcPath;
|
||||
|
||||
/*
|
||||
|
||||
@@ -34,6 +34,12 @@ commands (optional) is a list of Path commands</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Commands" Type="List"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Center" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>the center position for all rotational parameters</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Center" Type="Object"/>
|
||||
</Attribute>
|
||||
<Methode Name="addCommands">
|
||||
<Documentation>
|
||||
<UserDocu>adds a command or a list of commands at the end of the path</UserDocu>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "PathPy.h"
|
||||
#include "PathPy.cpp"
|
||||
|
||||
#include "Base/GeometryPyCXX.h"
|
||||
#include "CommandPy.h"
|
||||
|
||||
using namespace Path;
|
||||
@@ -105,6 +106,16 @@ void PathPy::setCommands(Py::List list)
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object PathPy::getCenter(void) const
|
||||
{
|
||||
return Py::Vector(getToolpathPtr()->getCenter());
|
||||
}
|
||||
|
||||
void PathPy::setCenter(Py::Object obj)
|
||||
{
|
||||
getToolpathPtr()->setCenter(Py::Vector(obj).toVector());
|
||||
}
|
||||
|
||||
// read-only attributes
|
||||
|
||||
Py::Float PathPy::getLength(void) const
|
||||
|
||||
@@ -111,12 +111,24 @@ void PropertyPath::Save (Base::Writer &writer) const
|
||||
void PropertyPath::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
reader.readElement("Path");
|
||||
std::string file (reader.getAttribute("file") );
|
||||
|
||||
std::string file (reader.getAttribute("file") );
|
||||
if (!file.empty()) {
|
||||
// initate a file read
|
||||
reader.addFile(file.c_str(),this);
|
||||
}
|
||||
|
||||
if (reader.hasAttribute("version")) {
|
||||
int version = reader.getAttributeAsInteger("version");
|
||||
if (version >= Toolpath::SchemaVersion) {
|
||||
reader.readElement("Center");
|
||||
double x = reader.getAttributeAsFloat("x");
|
||||
double y = reader.getAttributeAsFloat("y");
|
||||
double z = reader.getAttributeAsFloat("z");
|
||||
Base::Vector3d center(x, y, z);
|
||||
_Path.setCenter(center);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyPath::SaveDocFile (Base::Writer &) const
|
||||
|
||||
Reference in New Issue
Block a user