diff --git a/src/Mod/Path/App/Path.cpp b/src/Mod/Path/App/Path.cpp index f9d9ba2c25..84b82c827a 100644 --- a/src/Mod/Path/App/Path.cpp +++ b/src/Mod/Path/App/Path.cpp @@ -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::const_iterator it=otherPath.vpcCommands.begin();it!=otherPath.vpcCommands.end();++it,i++) + for (std::vector::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() << "
" << std::endl; +} + void Toolpath::Save (Writer &writer) const { if (writer.isForceXML()) { - writer.Stream() << writer.ind() << "" << std::endl; + writer.Stream() << writer.ind() << "" << std::endl; writer.incInd(); - for(unsigned int i = 0;iSave(writer); + } writer.decInd(); - writer.Stream() << writer.ind() << "" << std::endl; } else { writer.Stream() << writer.ind() - << "" << std::endl; + << "" << std::endl; + writer.incInd(); + saveCenter(writer, center); + writer.decInd(); } + writer.Stream() << writer.ind() << "" << std::endl; } void Toolpath::SaveDocFile (Base::Writer &writer) const diff --git a/src/Mod/Path/App/Path.h b/src/Mod/Path/App/Path.h index 7ce9e602a1..16319627b5 100644 --- a/src/Mod/Path/App/Path.h +++ b/src/Mod/Path/App/Path.h @@ -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 &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 &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 vpcCommands; + Base::Vector3d center; //KDL::Path_Composite *pcPath; /* diff --git a/src/Mod/Path/App/PathPy.xml b/src/Mod/Path/App/PathPy.xml index 6433f01171..22c6722255 100644 --- a/src/Mod/Path/App/PathPy.xml +++ b/src/Mod/Path/App/PathPy.xml @@ -34,6 +34,12 @@ commands (optional) is a list of Path commands + + + the center position for all rotational parameters + + + adds a command or a list of commands at the end of the path diff --git a/src/Mod/Path/App/PathPyImp.cpp b/src/Mod/Path/App/PathPyImp.cpp index 11de15a4f5..2757d96913 100644 --- a/src/Mod/Path/App/PathPyImp.cpp +++ b/src/Mod/Path/App/PathPyImp.cpp @@ -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 diff --git a/src/Mod/Path/App/PropertyPath.cpp b/src/Mod/Path/App/PropertyPath.cpp index eedd5ef7cd..f0360b07cf 100644 --- a/src/Mod/Path/App/PropertyPath.cpp +++ b/src/Mod/Path/App/PropertyPath.cpp @@ -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