Permalink
Browse files

* Added initial python port for gams::pose

  • Loading branch information...
jredmondson committed Oct 3, 2018
1 parent 4d4de85 commit 1c1f20aca3b8b21a400a79abeacb3104c785ac3b
@@ -0,0 +1,24 @@
project (GAMS_Python) : using_madara, using_gams, port/python/using_python {
requires += python
after += gams
sharedname = gams.pyd
postbuild = python port/python/rename_lib.py
libout = $(GAMS_ROOT)/lib
Documentation_Files {
port/python
}
Header_Files {
port/python/src
}
Source_Files {
port/python/src
}
}
@@ -48,6 +48,10 @@ openjdk = 0
/// Enable this feature if you want to generate documentation
docs = 0
/// @feature python
/// Enable this to support python
python = 0
/// @feature ros
/// Enable this to support ROS platforms
@@ -3,6 +3,7 @@ workspace {
cmdline += -feature_file $GAMS_ROOT/default.features
gams.mpc
Gams_Python.mpc
tests.mpc
simulation.mpc
docs/Documentation.mpc
@@ -0,0 +1,27 @@
package(default_visibility = ["//visibility:public"])
# Python binding support
cc_binary(
name = "gams.so",
srcs = glob(
[
"src/*.h",
"src/*.cpp",
],
),
copts = [
"-w",
],
linkshared = 1,
deps = [
"@gams//:gams_python",
],
)
py_library(
name = "gams",
data = [
":gams.so",
],
imports = ["."],
)
@@ -0,0 +1,33 @@
# !/usr/bin/python
import os, sys
final_so_file = os.environ['GAMS_ROOT'] + "/lib/gams.so"
final_dll_file = os.environ['GAMS_ROOT'] + "/lib/gams.dll"
source_so_file = os.environ['GAMS_ROOT'] + "/lib/libgams.pyd.so"
source_dll_file = os.environ['GAMS_ROOT'] + "/lib/gams.pyd.dll"
source_lib_file = os.environ['GAMS_ROOT'] + "/lib/gams.pyds.lib"
# init_file = os.environ['GAMS_ROOT'] + "/lib/__init__.py"
# delete any lib/gams.pyd if it existed
if os.path.isfile(final_so_file):
os.remove(final_so_file)
elif os.path.isfile(final_dll_file):
os.remove(final_dll_file)
if os.path.isfile(source_so_file):
os.rename(source_so_file, final_so_file)
elif os.path.isfile(source_dll_file):
os.rename(source_dll_file, final_dll_file)
elif os.path.isfile(source_lib_file):
final_file = source_lib_file
final_file.replace ('.pyd', '')
os.rename(source_lib_file, final_file)
#if os.path.isfile(final_file):
# file = open(init_file, 'w')
# if file:
# file.close()
@@ -0,0 +1,40 @@
#ifndef _MADARA_PYTHON_FUNCTION_DEFAULTS_
#define _MADARA_PYTHON_FUNCTION_DEFAULTS_
/**
* @file FunctionDefaults.cpp
* @author James Edmondson <jedmondson@gmail.com>
*
* This file contains Boost.Python function overload definitions
* for various MADARA functions.
**/
#include "madara/knowledge/KnowledgeBase.h"
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/args.hpp>
#include <boost/python/tuple.hpp>
#include <boost/python/class.hpp>
#include <boost/python/overloads.hpp>
#include <boost/python/return_internal_reference.hpp>
#include "madara/utility/Utility.h"
/********************************************************
* Settings overloads
********************************************************/
/********************************************************
* Class members (functions inside of classes)
********************************************************/
// BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(m_to_string_0_of_1, to_string, 0, 1)
/********************************************************
* Static functions (standalone functions)
********************************************************/
// BOOST_PYTHON_FUNCTION_OVERLOADS(
// file_from_fragments_2_of_4, madara::utility::file_from_fragments, 2, 4)
#endif
@@ -0,0 +1,81 @@
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#endif
#include <boost/python/detail/wrap_python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
#include <boost/python/dict.hpp>
#include <boost/python/import.hpp>
#include <boost/python/enum.hpp>
#include "madara/knowledge/KnowledgeBase.h"
#include "FunctionDefaults.h"
#include "GamsPose.h"
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/**
* @file Madara.cpp
* @author James Edmondson <jedmondson@gmail.com>
*
* This file contains Boost.Python mappings for the C++ MADARA library
* to a Python module called madara.
**/
using namespace boost::python;
template<typename Container>
list stl_to_python(const Container& input)
{
typedef typename Container::value_type T;
list lst;
std::for_each(input.begin(), input.end(), [&](const T& t) { lst.append(t); });
return lst;
}
template<typename Container>
Container python_to_stl(const list& input)
{
typedef typename Container::value_type T;
Container vec;
stl_input_iterator<T> beg(input), end;
std::for_each(beg, end, [&](const T& t) { vec.push_back(t); });
return vec;
}
BOOST_PYTHON_MODULE(gams)
{
// Launch the appropriate thread management initialization
PyEval_InitThreads();
// Declare classes inside Madara namespace (top namespace of Python module)
class_<std::vector<std::string>>("StringVector")
.def(vector_indexing_suite<std::vector<std::string>>());
class_<std::vector<madara::knowledge::KnowledgeRecord::Integer>>(
"IntegerVector")
.def(vector_indexing_suite<std::vector<int64_t>>());
class_<std::vector<double>>("DoubleVector")
.def(vector_indexing_suite<std::vector<double>>());
def("to_pydoubles", &stl_to_python<std::vector<double>>);
def("to_pylongs", &stl_to_python<std::vector<int64_t>>);
def("from_pydoubles", &python_to_stl<std::vector<double>>);
def("from_pylongs", &python_to_stl<std::vector<int64_t>>);
define_pose();
}
Oops, something went wrong.

0 comments on commit 1c1f20a

Please sign in to comment.