Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit eb0b850

Browse files
committed
Merge branch 'master' into devel
2 parents f77269a + fa39add commit eb0b850

32 files changed

+794
-2537
lines changed

CMakeLists.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,38 @@ PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
3030
FINDPYTHON()
3131

3232
ADD_PROJECT_DEPENDENCY(dynamic-graph REQUIRED PKG_CONFIG_REQUIRES dynamic-graph)
33-
SET(BOOST_COMPONENTS filesystem system thread program_options unit_test_framework python)
34-
SEARCH_FOR_BOOST()
35-
33+
ADD_PROJECT_DEPENDENCY(eigenpy REQUIRED PKG_CONFIG_REQUIRES eigenpy)
34+
SEARCH_FOR_BOOST_PYTHON(REQUIRED)
35+
IF(BUILD_TESTING)
36+
FIND_PACKAGE(Boost REQUIRED COMPONENTS unit_test_framework)
37+
ENDIF(BUILD_TESTING)
3638

3739
# Main Library
3840
SET(${PROJECT_NAME}_HEADERS
3941
include/${CUSTOM_HEADER_DIR}/api.hh
4042
include/${CUSTOM_HEADER_DIR}/convert-dg-to-py.hh
4143
include/${CUSTOM_HEADER_DIR}/dynamic-graph-py.hh
42-
include/${CUSTOM_HEADER_DIR}/exception.hh
43-
include/${CUSTOM_HEADER_DIR}/exception-python.hh
4444
include/${CUSTOM_HEADER_DIR}/interpreter.hh
45+
include/${CUSTOM_HEADER_DIR}/module.hh
4546
include/${CUSTOM_HEADER_DIR}/python-compat.hh
47+
include/${CUSTOM_HEADER_DIR}/signal.hh
4648
include/${CUSTOM_HEADER_DIR}/signal-wrapper.hh
4749
)
4850

4951
SET(${PROJECT_NAME}_SOURCES
5052
src/interpreter.cc
5153
src/dynamic_graph/python-compat.cc
54+
src/dynamic_graph/entity-py.cc
55+
src/dynamic_graph/convert-dg-to-py.cc
5256
)
5357

5458
ADD_LIBRARY(${PROJECT_NAME} SHARED
5559
${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})
56-
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS})
60+
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIR})
5761
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
58-
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Boost_LIBRARIES}
59-
${PYTHON_LIBRARY} ${Boost_PYTHON_LIBRARIES} dynamic-graph::dynamic-graph)
62+
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${PYTHON_LIBRARY}
63+
dynamic-graph::dynamic-graph)
64+
TARGET_LINK_BOOST_PYTHON(${PROJECT_NAME} PRIVATE)
6065

6166
IF(SUFFIX_SO_VERSION)
6267
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION})
@@ -67,7 +72,9 @@ TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE PYTHON_LIBRARY="${PYTHON_LIBR
6772
INSTALL(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION lib)
6873

6974
ADD_SUBDIRECTORY(src)
70-
ADD_SUBDIRECTORY(tests)
75+
IF(BUILD_TESTING)
76+
ADD_SUBDIRECTORY(tests)
77+
ENDIF(BUILD_TESTING)
7178

7279
PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
7380
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})

include/dynamic-graph/python/convert-dg-to-py.hh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
22

3+
#include <boost/python.hpp>
4+
35
#include <dynamic-graph/linear-algebra.h>
46
#include <dynamic-graph/value.h>
5-
#include <dynamic-graph/python/exception-python.hh>
67

78
namespace dynamicgraph {
89
namespace python {
910
namespace convert {
1011

11-
command::Value pythonToValue(PyObject* pyObject, const command::Value::Type& valueType);
12-
PyObject* vectorToPython(const Vector& vector);
13-
PyObject* matrixToPython(const ::dynamicgraph::Matrix& matrix);
14-
PyObject* matrix4dToPython(const Eigen::Matrix4d& matrix);
15-
PyObject* valueToPython(const ::dynamicgraph::command::Value& value);
12+
command::Value toValue(boost::python::object o, const command::Value::Type& type);
13+
boost::python::object fromValue(const command::Value& value);
1614

1715
} // namespace convert
1816
} // namespace python

include/dynamic-graph/python/dynamic-graph-py.hh

Lines changed: 42 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -4,189 +4,70 @@
44
#include <iostream>
55
#include <sstream>
66

7+
#include <boost/python.hpp>
8+
79
#include <dynamic-graph/debug.h>
810
#include <dynamic-graph/exception-factory.h>
911
#include <dynamic-graph/signal-base.h>
1012

1113
#include "dynamic-graph/python/signal-wrapper.hh"
1214

15+
namespace bp = boost::python;
16+
1317
namespace dynamicgraph {
1418
namespace python {
1519

20+
template <typename Iterator>
21+
inline bp::list to_py_list(Iterator begin, Iterator end) {
22+
typedef typename Iterator::value_type T;
23+
bp::list lst;
24+
std::for_each(begin, end, [&](const T& t) { lst.append(t); });
25+
return lst;
26+
}
27+
28+
template <typename Iterator>
29+
inline bp::tuple to_py_tuple(Iterator begin, Iterator end) {
30+
return bp::tuple(to_py_list(begin, end));
31+
}
32+
33+
template <typename T>
34+
inline std::vector<T> to_std_vector(const bp::object& iterable) {
35+
return std::vector<T>(bp::stl_input_iterator<T>(iterable), bp::stl_input_iterator<T>());
36+
}
37+
38+
void exposeSignals();
39+
1640
// Declare functions defined in other source files
1741
namespace signalBase {
18-
PyObject* create(PyObject* self, PyObject* args);
19-
PyObject* createSignalWrapper(PyObject* self, PyObject* args);
20-
PyObject* getTime(PyObject* self, PyObject* args);
21-
PyObject* setTime(PyObject* self, PyObject* args);
22-
PyObject* getName(PyObject* self, PyObject* args);
23-
PyObject* getClassName(PyObject* self, PyObject* args);
24-
PyObject* display(PyObject* self, PyObject* args);
25-
PyObject* displayDependencies(PyObject* self, PyObject* args);
26-
PyObject* getValue(PyObject* self, PyObject* args);
27-
PyObject* setValue(PyObject* self, PyObject* args);
28-
PyObject* recompute(PyObject* self, PyObject* args);
29-
PyObject* unplug(PyObject* self, PyObject* args);
30-
PyObject* isPlugged(PyObject* self, PyObject* args);
31-
PyObject* getPlugged(PyObject* self, PyObject* args);
42+
SignalBase<int>* createSignalWrapper(const char* name, const char* type, bp::object object);
3243
} // namespace signalBase
3344
namespace entity {
34-
PyObject* create(PyObject* self, PyObject* args);
35-
PyObject* display(PyObject* self, PyObject* args);
36-
PyObject* display(PyObject* self, PyObject* args);
37-
PyObject* getName(PyObject* self, PyObject* args);
38-
PyObject* getClassName(PyObject* self, PyObject* args);
39-
PyObject* hasSignal(PyObject* self, PyObject* args);
40-
PyObject* getSignal(PyObject* self, PyObject* args);
41-
PyObject* listSignals(PyObject* self, PyObject* args);
42-
PyObject* executeCommand(PyObject* self, PyObject* args);
43-
PyObject* listCommands(PyObject* self, PyObject* args);
44-
PyObject* getCommandDocstring(PyObject* self, PyObject* args);
45-
PyObject* getDocString(PyObject* self, PyObject* args);
46-
PyObject* setLoggerVerbosityLevel(PyObject* self, PyObject* args);
47-
PyObject* getLoggerVerbosityLevel(PyObject* self, PyObject* args);
48-
PyObject* setTimeSample(PyObject* self, PyObject* args);
49-
PyObject* getTimeSample(PyObject* self, PyObject* args);
50-
PyObject* setStreamPrintPeriod(PyObject* self, PyObject* args);
51-
PyObject* getStreamPrintPeriod(PyObject* self, PyObject* args);
45+
46+
/// \param obj an Entity object
47+
void addCommands(boost::python::object obj);
48+
void addSignals(boost::python::object obj);
49+
50+
Entity* create(const char* type, const char* name);
51+
bp::object executeCmd(bp::tuple args, bp::dict);
5252
} // namespace entity
5353

5454
namespace factory {
55-
PyObject* getEntityClassList(PyObject* self, PyObject* args);
56-
}
57-
namespace signalCaster {
58-
PyObject* getSignalTypeList(PyObject* self, PyObject* args);
55+
bp::tuple getEntityClassList();
5956
}
6057
namespace pool {
61-
PyObject* writeGraph(PyObject* self, PyObject* args);
62-
PyObject* getEntityList(PyObject* self, PyObject* args);
58+
void writeGraph(const char* filename);
59+
bp::list getEntityList();
60+
const std::map<std::string, Entity*>* getEntityMap();
6361
} // namespace pool
6462
namespace debug {
65-
PyObject* addLoggerFileOutputStream(PyObject* self, PyObject* args);
66-
PyObject* addLoggerCoutOutputStream(PyObject* self, PyObject* args);
67-
PyObject* closeLoggerFileOutputStream(PyObject* self, PyObject* args);
68-
PyObject* realTimeLoggerSpinOnce(PyObject* self, PyObject* args);
69-
PyObject* realTimeLoggerDestroy(PyObject* self, PyObject* args);
70-
PyObject* realTimeLoggerInstance(PyObject* self, PyObject* args);
63+
void addLoggerFileOutputStream(const char* filename);
64+
void addLoggerCoutOutputStream();
65+
void closeLoggerFileOutputStream();
66+
void realTimeLoggerSpinOnce();
67+
void realTimeLoggerDestroy();
68+
void realTimeLoggerInstance();
7169
} // namespace debug
7270

73-
struct module_state {
74-
PyObject* dgpyError;
75-
};
76-
77-
PyObject* plug(PyObject* /*self*/, PyObject* args);
78-
79-
PyObject* enableTrace(PyObject* /*self*/, PyObject* args);
80-
81-
PyObject* error_out(
82-
#if PY_MAJOR_VERSION >= 3
83-
PyObject* m, PyObject*
84-
#else
85-
PyObject*, PyObject*
86-
#endif
87-
);
88-
89-
/**
90-
\brief List of python functions
91-
*/
92-
__attribute__((unused)) static PyMethodDef dynamicGraphMethods[] = {
93-
{"w_plug", dynamicgraph::python::plug, METH_VARARGS, "plug an output signal into an input signal"},
94-
{"enableTrace", dynamicgraph::python::enableTrace, METH_VARARGS, "Enable or disable tracing debug info in a file"},
95-
// Signals
96-
{"create_signal_base", dynamicgraph::python::signalBase::create, METH_VARARGS, "create a SignalBase C++ object"},
97-
{"create_signal_wrapper", dynamicgraph::python::signalBase::createSignalWrapper, METH_VARARGS,
98-
"create a SignalWrapper C++ object"},
99-
{"signal_base_get_time", dynamicgraph::python::signalBase::getTime, METH_VARARGS, "Get time of a SignalBase"},
100-
{"signal_base_set_time", dynamicgraph::python::signalBase::setTime, METH_VARARGS, "Set time of a SignalBase"},
101-
{"signal_base_get_name", dynamicgraph::python::signalBase::getName, METH_VARARGS, "Get the name of a signal"},
102-
{"signal_base_get_class_name", dynamicgraph::python::signalBase::getClassName, METH_VARARGS,
103-
"Get the class name of a signal"},
104-
{"signal_base_display", dynamicgraph::python::signalBase::display, METH_VARARGS, "Print the signal in a string"},
105-
{"signal_base_display_dependencies", dynamicgraph::python::signalBase::displayDependencies, METH_VARARGS,
106-
"Print the signal dependencies in a string"},
107-
{"signal_base_get_value", dynamicgraph::python::signalBase::getValue, METH_VARARGS, "Read the value of a signal"},
108-
{"signal_base_set_value", dynamicgraph::python::signalBase::setValue, METH_VARARGS, "Set the value of a signal"},
109-
{"signal_base_recompute", dynamicgraph::python::signalBase::recompute, METH_VARARGS,
110-
"Recompute the signal at given time"},
111-
{"signal_base_unplug", dynamicgraph::python::signalBase::unplug, METH_VARARGS, "Unplug the signal"},
112-
{"signal_base_isPlugged", dynamicgraph::python::signalBase::isPlugged, METH_VARARGS,
113-
"Whether the signal is plugged"},
114-
{"signal_base_getPlugged", dynamicgraph::python::signalBase::getPlugged, METH_VARARGS,
115-
"To which signal the signal is plugged"},
116-
// Entity
117-
{"create_entity", dynamicgraph::python::entity::create, METH_VARARGS, "create an Entity C++ object"},
118-
{"display_entity", dynamicgraph::python::entity::display, METH_VARARGS, "print an Entity C++ object"},
119-
{"entity_get_name", dynamicgraph::python::entity::getName, METH_VARARGS, "get the name of an Entity"},
120-
{"entity_get_class_name", dynamicgraph::python::entity::getClassName, METH_VARARGS,
121-
"get the class name of an Entity"},
122-
{"entity_has_signal", dynamicgraph::python::entity::hasSignal, METH_VARARGS,
123-
"return True if the entity has a signal with the given name"},
124-
{"entity_get_signal", dynamicgraph::python::entity::getSignal, METH_VARARGS, "get signal by name from an Entity"},
125-
{"entity_list_signals", dynamicgraph::python::entity::listSignals, METH_VARARGS,
126-
"Return the list of signals of an entity."},
127-
{"entity_execute_command", dynamicgraph::python::entity::executeCommand, METH_VARARGS, "execute a command"},
128-
{"entity_list_commands", dynamicgraph::python::entity::listCommands, METH_VARARGS,
129-
"list the commands of an entity"},
130-
{"entity_get_command_docstring", dynamicgraph::python::entity::getCommandDocstring, METH_VARARGS,
131-
"get the docstring of an entity command"},
132-
{"entity_get_docstring", dynamicgraph::python::entity::getDocString, METH_VARARGS,
133-
"get the doc string of an entity type"},
134-
{"factory_get_entity_class_list", dynamicgraph::python::factory::getEntityClassList, METH_VARARGS,
135-
"return the list of entity classes"},
136-
{"signal_caster_get_type_list", dynamicgraph::python::signalCaster::getSignalTypeList, METH_VARARGS,
137-
"return the list of signal type names"},
138-
{"writeGraph", dynamicgraph::python::pool::writeGraph, METH_VARARGS, "Write the graph of entities in a filename."},
139-
{"get_entity_list", dynamicgraph::python::pool::getEntityList, METH_VARARGS,
140-
"return the list of instanciated entities"},
141-
{"entity_set_logger_verbosity", dynamicgraph::python::entity::setLoggerVerbosityLevel, METH_VARARGS,
142-
"set the verbosity level of the entity"},
143-
{"entity_get_logger_verbosity", dynamicgraph::python::entity::getLoggerVerbosityLevel, METH_VARARGS,
144-
"get the verbosity level of the entity"},
145-
{"addLoggerFileOutputStream", dynamicgraph::python::debug::addLoggerFileOutputStream, METH_VARARGS,
146-
"add a output file stream to the logger by filename"},
147-
{"addLoggerCoutOutputStream", dynamicgraph::python::debug::addLoggerCoutOutputStream, METH_VARARGS,
148-
"add std::cout as output stream to the logger"},
149-
{"closeLoggerFileOutputStream", dynamicgraph::python::debug::closeLoggerFileOutputStream, METH_VARARGS,
150-
"close all the loggers file output streams."},
151-
{"entity_set_time_sample", dynamicgraph::python::entity::setTimeSample, METH_VARARGS,
152-
"set the time sample for printing debugging information"},
153-
{"entity_get_time_sample", dynamicgraph::python::entity::getTimeSample, METH_VARARGS,
154-
"get the time sample for printing debugging information"},
155-
{"entity_set_stream_print_period", dynamicgraph::python::entity::setStreamPrintPeriod, METH_VARARGS,
156-
"set the period at which debugging information are printed"},
157-
{"entity_get_stream_print_period", dynamicgraph::python::entity::getStreamPrintPeriod, METH_VARARGS,
158-
"get the period at which debugging information are printed"},
159-
{"real_time_logger_destroy", dynamicgraph::python::debug::realTimeLoggerDestroy, METH_VARARGS,
160-
"Destroy the real time logger."},
161-
{"real_time_logger_spin_once", dynamicgraph::python::debug::realTimeLoggerSpinOnce, METH_VARARGS,
162-
"Destroy the real time logger."},
163-
{"real_time_logger_instance", dynamicgraph::python::debug::realTimeLoggerInstance, METH_VARARGS,
164-
"Starts the real time logger."},
165-
{"error_out", (PyCFunction)dynamicgraph::python::error_out, METH_NOARGS, NULL},
166-
{NULL, NULL, 0, NULL} /* Sentinel */
167-
};
168-
169-
#if PY_MAJOR_VERSION >= 3
170-
__attribute__((unused)) static struct PyModuleDef dynamicGraphModuleDef = {
171-
PyModuleDef_HEAD_INIT,
172-
"wrap",
173-
NULL,
174-
sizeof(struct dynamicgraph::python::module_state),
175-
dynamicGraphMethods,
176-
NULL,
177-
NULL,
178-
NULL,
179-
NULL};
180-
#define GETSTATE(m) ((struct dynamicgraph::python::module_state*)PyModule_GetState(m))
181-
#define DGPYERROR(m) GETSTATE(m)->dgpyError
182-
#define INITERROR return NULL
183-
#else
184-
__attribute__((unused)) static struct module_state _state;
185-
#define GETSTATE(m) (&dynamicgraph::python::_state)
186-
#define DGPYERROR(m) dynamicgraph::python::dgpyError
187-
#define INITERROR return
188-
#endif
189-
19071
} // namespace python
19172
} // namespace dynamicgraph
19273

include/dynamic-graph/python/exception-python.hh

Lines changed: 0 additions & 47 deletions
This file was deleted.

include/dynamic-graph/python/exception.hh

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)