Commit a05e1f98 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Update Python signal wrapper.

parent 49916ff3
......@@ -18,7 +18,7 @@ class PythonSignalContainer : public Entity {
DYNAMIC_GRAPH_ENTITY_DECL();
public:
PythonSignalContainer(const std::string& name);
using Entity::Entity;
void signalRegistration(const SignalArray<int>& signals);
......
......@@ -17,6 +17,7 @@
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/command.h>
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/tracer.h>
......@@ -24,6 +25,7 @@
#include "dynamic-graph/python/dynamic-graph-py.hh"
#include "dynamic-graph/python/signal-wrapper.hh"
#include "dynamic-graph/python/convert-dg-to-py.hh"
#include "dynamic-graph/python/module.hh"
namespace dynamicgraph {
namespace python {
......@@ -69,6 +71,24 @@ dg::SignalBase<int>* getSignal(dg::Entity& e, const std::string& name) {
return &e.getSignal(name);
}
class PythonEntity : public dg::Entity
{
DYNAMIC_GRAPH_ENTITY_DECL();
public:
using dg::Entity::Entity;
void signalRegistration(dg::SignalBase<int> &signal)
{
dg::Entity::signalRegistration(signal);
}
void signalDeregistration(const std::string &name)
{
dg::Entity::signalDeregistration(name);
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(PythonEntity, "PythonEntity");
void exposeEntityBase()
{
using namespace dynamicgraph;
......@@ -175,6 +195,16 @@ void exposeEntityBase()
// For backward compat
.add_static_property ("entities", bp::make_function(&getEntityMap, reference_existing_object()))
;
python::exposeEntity<PythonEntity, bp::bases<Entity>, 0>()
.def("signalRegistration", &PythonEntity::signalRegistration)
.def("signalDeregistration", &PythonEntity::signalDeregistration)
;
python::exposeEntity<python::PythonSignalContainer, bp::bases<Entity>, 0>()
.def("rmSignal", &python::PythonSignalContainer::rmSignal, "Remove a signal", bp::arg("signal_name"))
;
}
void exposeCommand()
......
......@@ -17,6 +17,7 @@
#include "dynamic-graph/python/dynamic-graph-py.hh"
#include "dynamic-graph/python/convert-dg-to-py.hh"
#include "dynamic-graph/python/signal-wrapper.hh"
#include "dynamic-graph/python/module.hh"
using dynamicgraph::SignalBase;
......@@ -111,6 +112,13 @@ template<> auto exposeSignal<MatrixHomogeneous, time_type> (const std::string& n
return obj;
}
template<typename T, typename Time> auto exposeSignalWrapper (const std::string& name)
{
typedef SignalWrapper<T, Time> S_t;
bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(name.c_str(), bp::no_init);
return obj;
}
template<typename T, typename Time> auto exposeSignalPtr (const std::string& name)
{
typedef SignalPtr<T, Time> S_t;
......@@ -133,6 +141,7 @@ void exposeSignalsOfType(const std::string& name)
{
exposeSignal<T, Time>("Signal" + name);
exposeSignalPtr<T, Time>("SignalPtr" + name);
exposeSignalWrapper<T, Time>("SignalWrapper" + name);
exposeSignalTimeDependent<T, Time>("SignalTimeDependent" + name);
}
......
......@@ -8,19 +8,6 @@
namespace dynamicgraph {
namespace python {
PythonSignalContainer::PythonSignalContainer(const std::string& name) : Entity(name) {
std::string docstring;
docstring =
" \n"
" Remove a signal\n"
" \n"
" Input:\n"
" - name of the signal\n"
" \n";
addCommand("rmSignal", command::makeCommandVoid1(*this, &PythonSignalContainer::rmSignal, docstring));
}
void PythonSignalContainer::signalRegistration(const SignalArray<int>& signals) {
Entity::signalRegistration(signals);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment