##// END OF EJS Templates
Added QVector<double> PB11 wrapper this will help debug...
jeandet -
r40:70eb884a0ee3
parent child
Show More
@@ -1,126 +1,127
1 #include <pybind11/pybind11.h>
1 #include <pybind11/pybind11.h>
2 #include <pybind11/operators.h>
2 #include <pybind11/operators.h>
3 #include <pybind11/embed.h>
3 #include <pybind11/embed.h>
4 #include <pybind11/numpy.h>
4 #include <pybind11/numpy.h>
5 #include <pybind11/chrono.h>
5 #include <pybind11/chrono.h>
6 #include <pybind11/functional.h>
6 #include <pybind11/functional.h>
7
7
8 #include <string>
8 #include <string>
9 #include <sstream>
9 #include <sstream>
10
10
11 #include "pywrappers_common.h"
11 #include "pywrappers_common.h"
12 #include "CoreWrappers.h"
12 #include "CoreWrappers.h"
13
13
14 #include <Data/DataSeriesType.h>
14 #include <Data/DataSeriesType.h>
15 #include <Data/ScalarSeries.h>
15 #include <Data/ScalarSeries.h>
16 #include <Data/VectorSeries.h>
16 #include <Data/VectorSeries.h>
17 #include <Data/Unit.h>
17 #include <Data/Unit.h>
18 #include <Data/IDataProvider.h>
18 #include <Data/IDataProvider.h>
19
19
20 #include <Variable/VariableController2.h>
20 #include <Variable/VariableController2.h>
21
21
22 #include <Time/TimeController.h>
22 #include <Time/TimeController.h>
23
23
24 #include <Network/Downloader.h>
24 #include <Network/Downloader.h>
25
25
26
26
27
27
28 namespace py = pybind11;
28 namespace py = pybind11;
29 using namespace std::chrono;
29 using namespace std::chrono;
30
30
31 PYBIND11_MODULE(pysciqlopcore,m){
31 PYBIND11_MODULE(pysciqlopcore,m){
32
32
33 py::enum_<DataSeriesType>(m, "DataSeriesType")
33 py::enum_<DataSeriesType>(m, "DataSeriesType")
34 .value("SCALAR", DataSeriesType::SCALAR)
34 .value("SCALAR", DataSeriesType::SCALAR)
35 .value("SPECTROGRAM", DataSeriesType::SPECTROGRAM)
35 .value("SPECTROGRAM", DataSeriesType::SPECTROGRAM)
36 .value("UNKNOWN", DataSeriesType::UNKNOWN)
36 .value("UNKNOWN", DataSeriesType::UNKNOWN)
37 .export_values();
37 .export_values();
38
38
39 py::class_<Unit>(m, "Unit")
39 py::class_<Unit>(m, "Unit")
40 .def_readwrite("name", &Unit::m_Name)
40 .def_readwrite("name", &Unit::m_Name)
41 .def_readwrite("time_unit", &Unit::m_TimeUnit)
41 .def_readwrite("time_unit", &Unit::m_TimeUnit)
42 .def(py::self == py::self)
42 .def(py::self == py::self)
43 .def(py::self != py::self)
43 .def(py::self != py::self)
44 .def("__repr__",__repr__<Unit>);
44 .def("__repr__",__repr__<Unit>);
45
45
46 py::class_<Response>(m,"Response")
46 py::class_<Response>(m,"Response")
47 .def("status_code", &Response::status_code);
47 .def("status_code", &Response::status_code);
48
48
49 py::class_<Downloader>(m,"Downloader")
49 py::class_<Downloader>(m,"Downloader")
50 .def_static("get", Downloader::get)
50 .def_static("get", Downloader::get)
51 .def_static("getAsync", Downloader::getAsync)
51 .def_static("getAsync", Downloader::getAsync)
52 .def_static("downloadFinished", Downloader::downloadFinished);
52 .def_static("downloadFinished", Downloader::downloadFinished);
53
53
54 py::class_<DataSeriesIteratorValue>(m,"DataSeriesIteratorValue")
54 py::class_<DataSeriesIteratorValue>(m,"DataSeriesIteratorValue")
55 .def_property_readonly("x", &DataSeriesIteratorValue::x)
55 .def_property_readonly("x", &DataSeriesIteratorValue::x)
56 .def("value", py::overload_cast<>(&DataSeriesIteratorValue::value, py::const_))
56 .def("value", py::overload_cast<>(&DataSeriesIteratorValue::value, py::const_))
57 .def("value", py::overload_cast<int>(&DataSeriesIteratorValue::value, py::const_));
57 .def("value", py::overload_cast<int>(&DataSeriesIteratorValue::value, py::const_))
58 .def("values", &DataSeriesIteratorValue::values);
58
59
59 py::class_<IDataSeries, std::shared_ptr<IDataSeries>>(m, "IDataSeries")
60 py::class_<IDataSeries, std::shared_ptr<IDataSeries>>(m, "IDataSeries")
60 .def("nbPoints", &IDataSeries::nbPoints)
61 .def("nbPoints", &IDataSeries::nbPoints)
61 .def_property_readonly("xAxisUnit", &IDataSeries::xAxisUnit)
62 .def_property_readonly("xAxisUnit", &IDataSeries::xAxisUnit)
62 .def_property_readonly("yAxisUnit", &IDataSeries::yAxisUnit)
63 .def_property_readonly("yAxisUnit", &IDataSeries::yAxisUnit)
63 .def_property_readonly("valuesUnit", &IDataSeries::valuesUnit)
64 .def_property_readonly("valuesUnit", &IDataSeries::valuesUnit)
64 .def("__getitem__", [](IDataSeries& serie, int key) {
65 .def("__getitem__", [](IDataSeries& serie, int key) {
65 return *(serie.begin()+key);
66 return *(serie.begin()+key);
66 }, py::is_operator())
67 }, py::is_operator())
67 .def("__len__", &IDataSeries::nbPoints)
68 .def("__len__", &IDataSeries::nbPoints)
68 .def("__iter__", [](IDataSeries& serie) {
69 .def("__iter__", [](IDataSeries& serie) {
69 return py::make_iterator(serie.begin(), serie.end());
70 return py::make_iterator(serie.begin(), serie.end());
70 }, py::keep_alive<0, 1>())
71 }, py::keep_alive<0, 1>())
71 .def("__repr__",__repr__<IDataSeries>);
72 .def("__repr__",__repr__<IDataSeries>);
72
73
73 py::class_<ScalarSeries, std::shared_ptr<ScalarSeries>, IDataSeries>(m, "ScalarSeries")
74 py::class_<ScalarSeries, std::shared_ptr<ScalarSeries>, IDataSeries>(m, "ScalarSeries")
74 .def("nbPoints", &ScalarSeries::nbPoints);
75 .def("nbPoints", &ScalarSeries::nbPoints);
75
76
76 py::class_<VectorSeries, std::shared_ptr<VectorSeries>, IDataSeries>(m, "VectorSeries")
77 py::class_<VectorSeries, std::shared_ptr<VectorSeries>, IDataSeries>(m, "VectorSeries")
77 .def("nbPoints", &VectorSeries::nbPoints);
78 .def("nbPoints", &VectorSeries::nbPoints);
78
79
79
80
80 py::class_<IDataProvider, std::shared_ptr<IDataProvider>>(m, "IDataProvider");
81 py::class_<IDataProvider, std::shared_ptr<IDataProvider>>(m, "IDataProvider");
81
82
82
83
83 py::class_<Variable,std::shared_ptr<Variable>>(m, "Variable")
84 py::class_<Variable,std::shared_ptr<Variable>>(m, "Variable")
84 .def(py::init<const QString&>())
85 .def(py::init<const QString&>())
85 .def_property("name", &Variable::name, &Variable::setName)
86 .def_property("name", &Variable::name, &Variable::setName)
86 .def_property("range", &Variable::range, &Variable::setRange)
87 .def_property("range", &Variable::range, &Variable::setRange)
87 .def_property("cacheRange", &Variable::cacheRange, &Variable::setCacheRange)
88 .def_property("cacheRange", &Variable::cacheRange, &Variable::setCacheRange)
88 .def_property_readonly("nbPoints", &Variable::nbPoints)
89 .def_property_readonly("nbPoints", &Variable::nbPoints)
89 .def_property_readonly("dataSeries", &Variable::dataSeries)
90 .def_property_readonly("dataSeries", &Variable::dataSeries)
90 .def("__len__", [](Variable& variable) {
91 .def("__len__", [](Variable& variable) {
91 auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd);
92 auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd);
92 return std::distance(rng.first,rng.second);
93 return std::distance(rng.first,rng.second);
93 })
94 })
94 .def("__iter__", [](Variable& variable) {
95 .def("__iter__", [](Variable& variable) {
95 auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd);
96 auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd);
96 return py::make_iterator(rng.first, rng.second);
97 return py::make_iterator(rng.first, rng.second);
97 }, py::keep_alive<0, 1>())
98 }, py::keep_alive<0, 1>())
98 .def("__getitem__", [](Variable& variable, int key) {
99 .def("__getitem__", [](Variable& variable, int key) {
99 //insane and slow!
100 //insane and slow!
100 auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd);
101 auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd);
101 if(key<0)
102 if(key<0)
102 return *(rng.second+key);
103 return *(rng.second+key);
103 else
104 else
104 return *(rng.first+key);
105 return *(rng.first+key);
105 })
106 })
106 .def("__repr__",__repr__<Variable>);
107 .def("__repr__",__repr__<Variable>);
107
108
108
109
109 py::class_<DateTimeRange>(m,"SqpRange")
110 py::class_<DateTimeRange>(m,"SqpRange")
110 //.def("fromDateTime", &DateTimeRange::fromDateTime, py::return_value_policy::move)
111 //.def("fromDateTime", &DateTimeRange::fromDateTime, py::return_value_policy::move)
111 .def(py::init([](double start, double stop){return DateTimeRange{start, stop};}))
112 .def(py::init([](double start, double stop){return DateTimeRange{start, stop};}))
112 .def(py::init([](system_clock::time_point start, system_clock::time_point stop)
113 .def(py::init([](system_clock::time_point start, system_clock::time_point stop)
113 {
114 {
114 double start_ = 0.001 * duration_cast<milliseconds>(start.time_since_epoch()).count();
115 double start_ = 0.001 * duration_cast<milliseconds>(start.time_since_epoch()).count();
115 double stop_ = 0.001 * duration_cast<milliseconds>(stop.time_since_epoch()).count();
116 double stop_ = 0.001 * duration_cast<milliseconds>(stop.time_since_epoch()).count();
116 return DateTimeRange{start_, stop_};
117 return DateTimeRange{start_, stop_};
117 }))
118 }))
118 .def_property_readonly("start", [](const DateTimeRange& range){
119 .def_property_readonly("start", [](const DateTimeRange& range){
119 return system_clock::from_time_t(range.m_TStart);
120 return system_clock::from_time_t(range.m_TStart);
120 })
121 })
121 .def_property_readonly("stop", [](const DateTimeRange& range){
122 .def_property_readonly("stop", [](const DateTimeRange& range){
122 return system_clock::from_time_t(range.m_TEnd);
123 return system_clock::from_time_t(range.m_TEnd);
123 })
124 })
124 .def("__repr__", __repr__<DateTimeRange>);
125 .def("__repr__", __repr__<DateTimeRange>);
125
126
126 }
127 }
@@ -1,33 +1,44
1 #include <QString>
1 #include <QString>
2 #include <QUuid>
2 #include <QUuid>
3 #include <QDate>
3 #include <QDate>
4 #include <QTime>
4 #include <QTime>
5 #include <QVector>
5 #include <string>
6 #include <string>
6 #include <sstream>
7 #include <sstream>
7 #include "pywrappers_common.h"
8 #include "pywrappers_common.h"
8 #include <pybind11/pybind11.h>
9 #include <pybind11/pybind11.h>
9 #include "QtWrappers.h"
10 #include "QtWrappers.h"
10
11
11 namespace py = pybind11;
12 namespace py = pybind11;
12
13
13
14
14
15
15 PYBIND11_MODULE(sciqlopqt,m){
16 PYBIND11_MODULE(sciqlopqt,m){
16 py::class_<QString>(m, "QString")
17 py::class_<QString>(m, "QString")
17 .def(py::init([](const std::string& value){return QString::fromStdString(value);}))
18 .def(py::init([](const std::string& value){return QString::fromStdString(value);}))
18 .def("__repr__", __repr__<QString>);
19 .def("__repr__", __repr__<QString>);
19
20
20 py::class_<QUuid>(m,"QUuid")
21 py::class_<QUuid>(m,"QUuid")
21 .def(py::init([](){return QUuid::createUuid();}))
22 .def(py::init([](){return QUuid::createUuid();}))
22 .def("__repr__",__repr__<QUuid>);
23 .def("__repr__",__repr__<QUuid>);
23
24
24 py::class_<QDate>(m,"QDate")
25 py::class_<QDate>(m,"QDate")
25 .def(py::init<int,int,int>());
26 .def(py::init<int,int,int>());
26
27
27 py::class_<QTime>(m,"QTime")
28 py::class_<QTime>(m,"QTime")
28 .def(py::init<int,int,int>());
29 .def(py::init<int,int,int>());
29
30
30
31 py::class_<QVector<double>>(m, "DoubleQVector")
32 .def(py::init<>())
33 .def("clear", &QVector<double>::clear)
34 .def("pop_back", &QVector<double>::pop_back)
35 .def("__len__", [](const QVector<double> &v) { return v.size(); })
36 .def("__iter__", [](QVector<double> &v) {
37 return py::make_iterator(v.begin(), v.end());
38 }, py::keep_alive<0, 1>())
39 .def("__getitem__", [](const QVector<double> &s, size_t i) {
40 if (i >= s.size()) throw py::index_error();
41 return s[i];});
31 py::implicitly_convertible<std::string, QString>();
42 py::implicitly_convertible<std::string, QString>();
32 }
43 }
33
44
General Comments 0
You need to be logged in to leave comments. Login now