From bfeeac6e4889d1e9a1083b3c7efc59652981b168 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 1 Aug 2016 08:20:23 +0200 Subject: o Moving the generation logic to Python, embedding a Python interpreter with the help of pybind11. o Adding install configuration to CMake to make it easier to reuse the project later on. o Splitting out the examples into its own project to make it easier to test the whole installation setup and python/template loading. o Trying to reorganize the code a bit, not very much better yet. --- python/kicad_utils_py.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 python/kicad_utils_py.cpp (limited to 'python/kicad_utils_py.cpp') diff --git a/python/kicad_utils_py.cpp b/python/kicad_utils_py.cpp new file mode 100644 index 0000000..6cd3948 --- /dev/null +++ b/python/kicad_utils_py.cpp @@ -0,0 +1,38 @@ +#include "trygvis/kicad/GenerateHeaderPy.h" + +#include "pybind11/stl.h" + +using namespace std; +using namespace trygvis::kicad::netlist; +using namespace trygvis::kicad::python; + +void init_module(py::module &m) { + py::class_(m, "node"). + def_readonly("ref", &node::ref). + def_readonly("pin", &node::pin); + + py::class_(m, "net"). + def_readonly("code", &net::code). + def_readonly("name", &net::name). + def_readonly("nodes", &net::nodes). + def("node_for_ref", &net::node_for_ref, py::return_value_policy::reference); + + py::class_(m, "netlist"). + def("find_usages_of", &nl::find_usage_of, py::return_value_policy::reference); + + py::class_(m, "GenerateHeader"). + def(py::init()). + def_property_readonly("netlist", &GenerateHeaderPy::netlist). + def_property_readonly("ref", &GenerateHeaderPy::ref). + def_property_readonly("str", &GenerateHeaderPy::str). + def("print", &GenerateHeaderPy::print). + def("println", &GenerateHeaderPy::println); +} + +PYBIND11_PLUGIN(kicad_utils_py) { + py::module kicad_utils("kicad_utils_py"); + + init_module(kicad_utils); + + return kicad_utils.ptr(); +} -- cgit v1.2.3