Skip to content

Commit

Permalink
Started adding python bindings for GNDS 1.9 standard components
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Apr 2, 2021
1 parent 594fdba commit 06a01fd
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pybind11_add_module( GNDStk.python
EXCLUDE_FROM_ALL
python/src/GNDStk.python.cpp
python/src/core/Node.python.cpp
python/src/v1.9/gpdc.python.cpp
python/src/v1.9/gpdc/Axis.python.cpp
)
target_link_libraries( GNDStk.python PRIVATE GNDStk )
target_compile_options( GNDStk.python PRIVATE "-fPIC" )
Expand Down
20 changes: 18 additions & 2 deletions python/src/GNDStk.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace core {
void wrapNode( python::module& );
}

// v1.9 interface declarations
namespace v1_9 {

void wrapGeneralPurposeDataContainers( python::module& );
}

/**
* @brief GNDStk python bindings
*
Expand All @@ -22,12 +28,22 @@ namespace core {
PYBIND11_MODULE( GNDStk, module ) {

// create the core submodule
python::module submodule = module.def_submodule(
python::module coremodule = module.def_submodule(

"core",
"core - GNDS core interface components"
);

// wrap core components
core::wrapNode( submodule );
core::wrapNode( coremodule );

// create the core submodule
python::module v1_9_module = module.def_submodule(

"v1_9",
"v1.9 - GNDS v1.9 standard components"
);

// wrap GNDS v1.9 standard components
v1_9::wrapGeneralPurposeDataContainers( v1_9_module );
}
32 changes: 32 additions & 0 deletions python/src/v1.9/gpdc.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// other includes

// namespace aliases
namespace python = pybind11;

// v1.9 interface declarations
namespace v1_9 {

// gpdc declarations
namespace gpdc {

void wrapAxis( python::module& );
}

void wrapGeneralPurposeDataContainers( python::module& module ) {

// create the gpdc submodule
python::module submodule = module.def_submodule(

"gpdc",
"v1.9 gpdc - GNDS general purpose data containers"
);

// wrap core components
gpdc::wrapAxis( submodule );
}

} // v1_9 namespace
63 changes: 63 additions & 0 deletions python/src/v1.9/gpdc/Axis.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// local includes
#include "GNDStk/v1.9/gpdc/Axis.hpp"

// namespace aliases
namespace python = pybind11;

namespace v1_9 {
namespace gpdc {

void wrapAxis( python::module& module ) {

// type aliases
using Component = njoy::GNDStk::v1_9::gpdc::Axis;

// create the component
python::class_< Component > component(

module,
"Axis",
"Container component - an axis with index, label and unit"
);

// wrap the component
component
.def(

python::init< const std::optional<njoy::GNDStk::Integer32>&,
const std::optional<njoy::GNDStk::XMLName>&,
const std::optional<njoy::GNDStk::XMLName>& >(),
python::arg( "index" ), python::arg( "label" ), python::arg( "unit" ),
"Initialise the component\n\n"
"Arguments:\n"
" self the component\n"
" index the axis index\n"
" label the axis label\n"
" unit the axis unit"
)
.def_property_readonly(

"index",
&Component::index,
"The axis index"
)
.def_property_readonly(

"label",
&Component::label,
"The axis label"
)
.def_property_readonly(

"unit",
&Component::unit,
"The unit index"
);
}

} // namespace gpdc
} // namespace v1_9

0 comments on commit 06a01fd

Please sign in to comment.