Add BoundBox property to Path, usable without a gui.
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
//#include "Mod/Robot/App/kdl_cp/utilities/error.h"
|
||||
|
||||
#include "Path.h"
|
||||
#include <Mod/Path/App/PathSegmentWalker.h>
|
||||
|
||||
using namespace Path;
|
||||
using namespace Base;
|
||||
@@ -145,6 +146,78 @@ double Toolpath::getLength()
|
||||
return l;
|
||||
}
|
||||
|
||||
class BoundBoxSegmentVisitor : public PathSegmentVisitor
|
||||
{
|
||||
public:
|
||||
BoundBoxSegmentVisitor()
|
||||
{ }
|
||||
|
||||
virtual void g0(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts)
|
||||
{
|
||||
(void)id;
|
||||
processPt(last);
|
||||
processPts(pts);
|
||||
processPt(next);
|
||||
}
|
||||
virtual void g1(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts)
|
||||
{
|
||||
(void)id;
|
||||
processPt(last);
|
||||
processPts(pts);
|
||||
processPt(next);
|
||||
}
|
||||
virtual void g23(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts, const Base::Vector3d ¢er)
|
||||
{
|
||||
(void)id;
|
||||
(void)center;
|
||||
processPt(last);
|
||||
processPts(pts);
|
||||
processPt(next);
|
||||
}
|
||||
virtual void g8x(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque<Base::Vector3d> &pts,
|
||||
const std::deque<Base::Vector3d> &p, const std::deque<Base::Vector3d> &q)
|
||||
{
|
||||
(void)id;
|
||||
(void)q; // always within the bounds of p
|
||||
processPt(last);
|
||||
processPts(pts);
|
||||
processPts(p);
|
||||
processPt(next);
|
||||
}
|
||||
virtual void g38(int id, const Base::Vector3d &last, const Base::Vector3d &next)
|
||||
{
|
||||
(void)id;
|
||||
processPt(last);
|
||||
processPt(next);
|
||||
}
|
||||
|
||||
Base::BoundBox3d bb;
|
||||
|
||||
private:
|
||||
void processPts(const std::deque<Base::Vector3d> &pts) {
|
||||
for (std::deque<Base::Vector3d>::const_iterator it=pts.begin(); pts.end() != it; ++it) {
|
||||
processPt(*it);
|
||||
}
|
||||
}
|
||||
void processPt(const Base::Vector3d &pt) {
|
||||
bb.MaxX = std::max(bb.MaxX, pt.x);
|
||||
bb.MinX = std::min(bb.MinX, pt.x);
|
||||
bb.MaxY = std::max(bb.MaxY, pt.y);
|
||||
bb.MinY = std::min(bb.MinY, pt.y);
|
||||
bb.MaxZ = std::max(bb.MaxZ, pt.z);
|
||||
bb.MinZ = std::min(bb.MinZ, pt.z);
|
||||
}
|
||||
};
|
||||
|
||||
Base::BoundBox3d Toolpath::getBoundBox() const
|
||||
{
|
||||
BoundBoxSegmentVisitor visitor;
|
||||
PathSegmentWalker walker(*this);
|
||||
walker.walk(visitor, Vector3d(0, 0, 0));
|
||||
|
||||
return visitor.bb;
|
||||
}
|
||||
|
||||
static void bulkAddCommand(const std::string &gcodestr, std::vector<Command*> &commands, bool &inches)
|
||||
{
|
||||
Command *cmd = new Command();
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "Command.h"
|
||||
//#include "Mod/Robot/App/kdl_cp/path_composite.hpp"
|
||||
//#include "Mod/Robot/App/kdl_cp/frames_io.hpp"
|
||||
#include <Base/BoundBox.h>
|
||||
#include <Base/Persistence.h>
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
@@ -62,6 +63,7 @@ namespace Path
|
||||
void recalculate(void); // recalculates the points
|
||||
void setFromGCode(const std::string); // sets the path from the contents of the given GCode string
|
||||
std::string toGCode(void) const; // gets a gcode string representation from the Path
|
||||
Base::BoundBox3d getBoundBox(void) const;
|
||||
|
||||
// shortcut functions
|
||||
unsigned int getSize(void) const { return vpcCommands.size(); }
|
||||
|
||||
@@ -40,6 +40,12 @@ commands (optional) is a list of Path commands</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Center" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="BoundBox" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>the extent of this path</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="BoundBox" 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/BoundBoxPy.h"
|
||||
#include "Base/GeometryPyCXX.h"
|
||||
#include "CommandPy.h"
|
||||
|
||||
@@ -128,6 +129,11 @@ Py::Long PathPy::getSize(void) const
|
||||
return Py::Long((long)getToolpathPtr()->getSize());
|
||||
}
|
||||
|
||||
Py::Object PathPy::getBoundBox(void) const
|
||||
{
|
||||
return Py::BoundingBox(getToolpathPtr()->getBoundBox());
|
||||
}
|
||||
|
||||
// specific methods
|
||||
|
||||
PyObject* PathPy::copy(PyObject * args)
|
||||
|
||||
Reference in New Issue
Block a user