TrajectoryPyImp.cpp

Go to the documentation of this file.
00001 
00002 #include "PreCompiled.h"
00003 
00004 #include <Base/VectorPy.h>
00005 #include <Base/PlacementPy.h>
00006 #include "Mod/Robot/App/Trajectory.h"
00007 
00008 // inclusion of the generated files (generated out of TrajectoryPy.xml)
00009 #include "TrajectoryPy.h"
00010 #include "TrajectoryPy.cpp"
00011 
00012 #include "WaypointPy.h"
00013 
00014 using namespace Robot;
00015 
00016 // returns a string which represents the object e.g. when printed in python
00017 std::string TrajectoryPy::representation(void) const
00018 {
00019     std::stringstream str;
00020     str.precision(5);
00021     str << "Trajectory [";
00022     str << "size:" << getTrajectoryPtr()->getSize() << " ";
00023     str << "length:" << getTrajectoryPtr()->getLength() << " ";
00024     str << "duration:" << getTrajectoryPtr()->getDuration() << " ";
00025     str << "]";
00026 
00027     return str.str();
00028 }
00029 
00030 PyObject *TrajectoryPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00031 {
00032     // create a new instance of TrajectoryPy and the Twin object 
00033     return new TrajectoryPy(new Trajectory);
00034 }
00035 
00036 // constructor method
00037 int TrajectoryPy::PyInit(PyObject* args, PyObject* /*kwd*/)
00038 {
00039     PyObject *pcObj=0;
00040     if (!PyArg_ParseTuple(args, "|O!", &(PyList_Type), &pcObj))
00041         return -1;
00042 
00043     if (pcObj) {
00044         Py::List list(pcObj);
00045         for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00046             if (PyObject_TypeCheck((*it).ptr(), &(Robot::WaypointPy::Type))) {
00047                 Robot::Waypoint &wp = *static_cast<Robot::WaypointPy*>((*it).ptr())->getWaypointPtr();
00048                 getTrajectoryPtr()->addWaypoint(wp);
00049             }
00050         }
00051     }
00052     getTrajectoryPtr()->generateTrajectory();
00053     return 0;
00054 }
00055 
00056 
00057 PyObject* TrajectoryPy::insertWaypoints(PyObject * args)
00058 {
00059 
00060     PyObject* o;
00061     if (PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &o)) {
00062         Base::Placement *plm = static_cast<Base::PlacementPy*>(o)->getPlacementPtr();
00063         getTrajectoryPtr()->addWaypoint(Robot::Waypoint("Pt",*plm));
00064         getTrajectoryPtr()->generateTrajectory();
00065 
00066         return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
00067     }
00068 
00069     PyErr_Clear();
00070     if (PyArg_ParseTuple(args, "O!", &(Robot::WaypointPy::Type), &o)) {
00071         Robot::Waypoint &wp = *static_cast<Robot::WaypointPy*>(o)->getWaypointPtr();
00072         getTrajectoryPtr()->addWaypoint(wp);
00073         getTrajectoryPtr()->generateTrajectory();
00074        
00075         return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
00076         //Py_Return;
00077     }
00078 
00079     PyErr_Clear();
00080     if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &o)) {
00081         Py::List list(o);
00082         for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00083             if (PyObject_TypeCheck((*it).ptr(), &(Robot::WaypointPy::Type))) {
00084                 Robot::Waypoint &wp = *static_cast<Robot::WaypointPy*>((*it).ptr())->getWaypointPtr();
00085                 getTrajectoryPtr()->addWaypoint(wp);
00086             }
00087         }
00088         getTrajectoryPtr()->generateTrajectory();
00089        
00090         return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
00091     }
00092 
00093     Py_Error(PyExc_Exception, "Wrong parameters - waypoint or placement expected");
00094 
00095 }
00096 
00097 PyObject* TrajectoryPy::position(PyObject * args)
00098 {
00099     double pos;
00100     if (!PyArg_ParseTuple(args, "d", &pos))
00101         return NULL;
00102 
00103     return (new Base::PlacementPy(new Base::Placement(getTrajectoryPtr()->getPosition(pos))));
00104 }
00105 
00106 PyObject* TrajectoryPy::velocity(PyObject * args)
00107 {
00108     double pos;
00109     if (!PyArg_ParseTuple(args, "d", &pos))
00110         return NULL;
00111 
00112      // return velocity as float
00113     return Py::new_reference_to(Py::Float(getTrajectoryPtr()->getVelocity(pos)));
00114 }
00115 
00116 PyObject* TrajectoryPy::deleteLast(PyObject *args)
00117 {
00118     int n=1;
00119     if (!PyArg_ParseTuple(args, "|i", &n))
00120         return NULL;
00121     getTrajectoryPtr()->deleteLast(n);
00122     return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
00123  }
00124 
00125 
00126 
00127 Py::Float TrajectoryPy::getDuration(void) const
00128 {
00129     return Py::Float(getTrajectoryPtr()->getDuration());
00130 }
00131 
00132 Py::List TrajectoryPy::getWaypoints(void) const
00133 {
00134     Py::List list;
00135     for(unsigned int i = 0; i < getTrajectoryPtr()->getSize(); i++)
00136         list.append(Py::Object(new Robot::WaypointPy(new Robot::Waypoint(getTrajectoryPtr()->getWaypoint(i)))));
00137 
00138     return list;
00139 }
00140 
00141 Py::Float TrajectoryPy::getLength(void) const
00142 {
00143     return Py::Float(getTrajectoryPtr()->getLength());
00144 }
00145 
00146 
00147 
00148 void TrajectoryPy::setWaypoints(Py::List)
00149 {
00150    
00151 }
00152 
00153 PyObject *TrajectoryPy::getCustomAttributes(const char* /*attr*/) const
00154 {
00155     return 0;
00156 }
00157 
00158 int TrajectoryPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00159 {
00160     return 0; 
00161 }
00162 
00163 

Generated on Wed Nov 23 19:00:50 2011 for FreeCAD by  doxygen 1.6.1