// Copyright (C) 2002-2003 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. // #include #include #include #include #include #include "held_ptr.hpp" using namespace boost::python; namespace { using namespace osgParticle; class PyOperator : public Operator { public: PyOperator() : Operator(), _self(NULL) {} PyOperator(PyObject * p) : Operator(), _self(p) {} PyOperator(const PyOperator ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY) : Operator(copy, copyop) {} META_Object(osgParticle, PyOperator); ~PyOperator() {} void operate(Particle *P, double dt) { try { call_method(_self, "operate", ptr(P), dt); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); return; } } void beginOperate(Program * prog) { try { call_method(_self, "beginOperate", ptr(prog)); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); return; } } void endOperate() { try { call_method(_self, "endOperate"); } catch(...) { handle_exception(); PyErr_Print(); throw_error_already_set(); return; } } void beginOperate_imp(Program * prog) { this->Operator::beginOperate(prog); } void endOperate_imp() { this->Operator::endOperate(); } void operate_imp(Particle *P, double dt) { // this->Operator::operate(P, dt); } private: PyObject * _self; }; } namespace PyOSGParticle { void init_Operator() { class_, bases, boost::noncopyable > operat("Operator", "An abstract base class used by ModularProgram to perform operations on particles before they are updated. " "To implement a new operator, derive from this class and override the operate() method." "You should also override the beginOperate() method to query the calling program for the reference frame" "used, and initialize the right transformations if needed.", no_init); operat.def(init<>()); operat.def("isEnabled", &osgParticle::Operator::isEnabled, "Get whether this operator is enabled."); operat.def("setEnabled", &osgParticle::Operator::setEnabled, "Enable or disable this operator."); operat.def("operate", &osgParticle::Operator::operate, "Do something on a particle. " "This method is called by ModularProgram objects to perform some operations" "on the particles. You must override it in descendant classes. Common operations" "consist of modifying the particle's velocity vector. The dt parameter is" "the time elapsed from last operation."); operat.def("beginOperate", &PyOperator::beginOperate_imp, "Do something before processing particles via the operate() method." "Overriding this method could be necessary to query the calling Program object" "for the current reference frame. If the reference frame is RELATIVE_TO_PARENTS, then your" "class should prepare itself to do all operations in local coordinates."); operat.def("endOperate", &PyOperator::endOperate_imp, "Do something after all particles have been processed."); // operat.def("operate", &PyOperator::operate_imp); } }