1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/***************************************************************************
* Copyright (c) 2010 Jrgen Riegel (juergen.riegel@web.de) *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#include <Base/VectorPy.h>
#include <Base/PlacementPy.h>
#include "Mod/Robot/App/Trajectory.h"
// inclusion of the generated files (generated out of TrajectoryPy.xml)
#include "TrajectoryPy.h"
#include "TrajectoryPy.cpp"
#include "WaypointPy.h"
using namespace Robot;
// returns a string which represents the object e.g. when printed in python
std::string TrajectoryPy::representation(void) const
{
std::stringstream str;
str.precision(5);
str << "Trajectory [";
str << "size:" << getTrajectoryPtr()->getSize() << " ";
str << "length:" << getTrajectoryPtr()->getLength() << " ";
str << "duration:" << getTrajectoryPtr()->getDuration() << " ";
str << "]";
return str.str();
}
PyObject *TrajectoryPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of TrajectoryPy and the Twin object
return new TrajectoryPy(new Trajectory);
}
// constructor method
int TrajectoryPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
PyObject *pcObj=0;
if (!PyArg_ParseTuple(args, "|O!", &(PyList_Type), &pcObj))
return -1;
if (pcObj) {
Py::List list(pcObj);
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
if (PyObject_TypeCheck((*it).ptr(), &(Robot::WaypointPy::Type))) {
Robot::Waypoint &wp = *static_cast<Robot::WaypointPy*>((*it).ptr())->getWaypointPtr();
getTrajectoryPtr()->addWaypoint(wp);
}
}
}
getTrajectoryPtr()->generateTrajectory();
return 0;
}
PyObject* TrajectoryPy::insertWaypoints(PyObject * args)
{
PyObject* o;
if (PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &o)) {
Base::Placement *plm = static_cast<Base::PlacementPy*>(o)->getPlacementPtr();
getTrajectoryPtr()->addWaypoint(Robot::Waypoint("Pt",*plm));
getTrajectoryPtr()->generateTrajectory();
return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!", &(Robot::WaypointPy::Type), &o)) {
Robot::Waypoint &wp = *static_cast<Robot::WaypointPy*>(o)->getWaypointPtr();
getTrajectoryPtr()->addWaypoint(wp);
getTrajectoryPtr()->generateTrajectory();
return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
//Py_Return;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &o)) {
Py::List list(o);
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
if (PyObject_TypeCheck((*it).ptr(), &(Robot::WaypointPy::Type))) {
Robot::Waypoint &wp = *static_cast<Robot::WaypointPy*>((*it).ptr())->getWaypointPtr();
getTrajectoryPtr()->addWaypoint(wp);
}
}
getTrajectoryPtr()->generateTrajectory();
return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
}
Py_Error(PyExc_Exception, "Wrong parameters - waypoint or placement expected");
}
PyObject* TrajectoryPy::position(PyObject * args)
{
double pos;
if (!PyArg_ParseTuple(args, "d", &pos))
return NULL;
return (new Base::PlacementPy(new Base::Placement(getTrajectoryPtr()->getPosition(pos))));
}
PyObject* TrajectoryPy::velocity(PyObject * args)
{
double pos;
if (!PyArg_ParseTuple(args, "d", &pos))
return NULL;
// return velocity as float
return Py::new_reference_to(Py::Float(getTrajectoryPtr()->getVelocity(pos)));
}
PyObject* TrajectoryPy::deleteLast(PyObject *args)
{
int n=1;
if (!PyArg_ParseTuple(args, "|i", &n))
return NULL;
getTrajectoryPtr()->deleteLast(n);
return new TrajectoryPy(new Robot::Trajectory(*getTrajectoryPtr()));
}
Py::Float TrajectoryPy::getDuration(void) const
{
return Py::Float(getTrajectoryPtr()->getDuration());
}
Py::List TrajectoryPy::getWaypoints(void) const
{
Py::List list;
for(unsigned int i = 0; i < getTrajectoryPtr()->getSize(); i++)
list.append(Py::Object(new Robot::WaypointPy(new Robot::Waypoint(getTrajectoryPtr()->getWaypoint(i)))));
return list;
}
Py::Float TrajectoryPy::getLength(void) const
{
return Py::Float(getTrajectoryPtr()->getLength());
}
void TrajectoryPy::setWaypoints(Py::List)
{
}
PyObject *TrajectoryPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int TrajectoryPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}
|