| 1 |
#include "GridInterface.h" |
| 2 |
|
| 3 |
#include <pybind11/pybind11.h> |
| 4 |
|
| 5 |
#include "itextstream.h" |
| 6 |
#include "igrid.h" |
| 7 |
|
| 8 |
namespace script |
| 9 |
{ |
| 10 |
|
| 11 |
void GridInterface::setGridSize(int gridSize) |
| 12 |
{ |
| 13 |
// Sanity-check the incoming int |
| 14 |
if (gridSize < GRID_0125 || gridSize > GRID_256) { |
| 15 |
rError() << "Invalid grid size passed, allowed values are in the range " |
| 16 |
<< "[" << GRID_0125 << ".." << GRID_256 << "]" << std::endl; |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
GlobalGrid().setGridSize(static_cast<GridSize>(gridSize)); |
| 21 |
} |
| 22 |
|
| 23 |
float GridInterface::getGridSize() |
| 24 |
{ |
| 25 |
return GlobalGrid().getGridSize(); |
| 26 |
} |
| 27 |
|
| 28 |
int GridInterface::getGridPower() |
| 29 |
{ |
| 30 |
return GlobalGrid().getGridPower(); |
| 31 |
} |
| 32 |
|
| 33 |
void GridInterface::gridDown() |
| 34 |
{ |
| 35 |
GlobalGrid().gridDown(); |
| 36 |
} |
| 37 |
|
| 38 |
void GridInterface::gridUp() |
| 39 |
{ |
| 40 |
GlobalGrid().gridUp(); |
| 41 |
} |
| 42 |
|
| 43 |
void GridInterface::registerInterface(py::module& scope, py::dict& globals) |
| 44 |
{ |
| 45 |
// Add the module declaration to the given python namespace |
| 46 |
py::class_<GridInterface> grid(scope, "Grid"); |
| 47 |
|
| 48 |
grid.def("setGridSize", &GridInterface::setGridSize); |
| 49 |
grid.def("getGridSize", &GridInterface::getGridSize); |
| 50 |
grid.def("getGridPower", &GridInterface::getGridPower); |
| 51 |
grid.def("gridDown", &GridInterface::gridDown); |
| 52 |
grid.def("gridUp", &GridInterface::gridUp); |
| 53 |
|
| 54 |
// Now point the Python variable "GlobalGrid" to this instance |
| 55 |
globals["GlobalGrid"] = this; |
| 56 |
} |
| 57 |
|
| 58 |
} // namespace script |