diff --git a/doc/release/notes/python_changes.rst b/doc/release/notes/python_changes.rst new file mode 100644 index 0000000000000000000000000000000000000000..2047e2fa09ba478db6398b4098e763b0d687c4df --- /dev/null +++ b/doc/release/notes/python_changes.rst @@ -0,0 +1,7 @@ +Attribute Resource Changes +========================== + +Values methods for Items derived from ValueItems +------------------------------------------------ + +The C++ ValueItemTemplate class provided methods of setting multiple values of the item using iterators. Unfortunately these methods could not be made available in the Python wrapped API. Instead we have added *setValues* and *values* methods to the pybind11 wrapping for DoubleItem, IntItem, and DoubleItem which allows the use of Python arrays to set (and get) all of the values of the Item. diff --git a/smtk/attribute/pybind11/PybindDoubleItem.h b/smtk/attribute/pybind11/PybindDoubleItem.h index e1aa67f8dd1a61ff1e93bfcd0e2317a19bb8554c..ec93395482eb3521fb630c05ecedbe71ceaca79b 100644 --- a/smtk/attribute/pybind11/PybindDoubleItem.h +++ b/smtk/attribute/pybind11/PybindDoubleItem.h @@ -27,6 +27,20 @@ inline PySharedPtrClass< smtk::attribute::DoubleItem, smtk::attribute::ValueItem .def("hasExplicitUnits", &smtk::attribute::DoubleItem::hasExplicitUnits) .def(py::init<::smtk::attribute::DoubleItem const &>()) .def("type", &smtk::attribute::DoubleItem::type) + .def("setValues", [&](smtk::attribute::DoubleItem* self, const std::vector& values) + { + return self->setValues(values.begin(), values.end()); + }, py::arg("values")) + .def("values", [&](smtk::attribute::DoubleItem* self) -> std::vector + { + std::vector values; + values.reserve(self->numberOfValues()); + for (const auto& vv : *self) + { + values.push_back(vv); + } + return values; + }) .def_static("CastTo", [](const std::shared_ptr i) { return std::dynamic_pointer_cast(i); }) diff --git a/smtk/attribute/pybind11/PybindIntItem.h b/smtk/attribute/pybind11/PybindIntItem.h index c990dc266925932643942399f58b18f69d1d0520..925ca3e76d752cc72959cdd9ab182f33e190940e 100644 --- a/smtk/attribute/pybind11/PybindIntItem.h +++ b/smtk/attribute/pybind11/PybindIntItem.h @@ -23,6 +23,20 @@ inline PySharedPtrClass< smtk::attribute::IntItem, smtk::attribute::ValueItemTem instance .def(py::init<::smtk::attribute::IntItem const &>()) .def("type", &smtk::attribute::IntItem::type) + .def("setValues", [&](smtk::attribute::IntItem* self, const std::vector& values) + { + return self->setValues(values.begin(), values.end()); + }, py::arg("values")) + .def("values", [&](smtk::attribute::IntItem* self) -> std::vector + { + std::vector values; + values.reserve(self->numberOfValues()); + for (const auto& vv : *self) + { + values.push_back(vv); + } + return values; + }) .def_static("CastTo", [](const std::shared_ptr i) { return std::dynamic_pointer_cast(i); }) diff --git a/smtk/attribute/pybind11/PybindStringItem.h b/smtk/attribute/pybind11/PybindStringItem.h index 14d77d9aee60df7cf78633a3b30bb8a0bf5c9806..e201fb3b55fb91d9029906a7a3ff86b2f417b077 100644 --- a/smtk/attribute/pybind11/PybindStringItem.h +++ b/smtk/attribute/pybind11/PybindStringItem.h @@ -24,6 +24,20 @@ inline PySharedPtrClass< smtk::attribute::StringItem, smtk::attribute::ValueItem .def(py::init<::smtk::attribute::StringItem const &>()) .def("isSecure", &smtk::attribute::StringItem::isSecure) .def("type", &smtk::attribute::StringItem::type) + .def("setValues", [&](smtk::attribute::StringItem* self, const std::vector& values) + { + return self->setValues(values.begin(), values.end()); + }, py::arg("values")) + .def("values", [&](smtk::attribute::StringItem* self) -> std::vector + { + std::vector values; + values.reserve(self->numberOfValues()); + for (const auto& vv : *self) + { + values.push_back(vv); + } + return values; + }) .def_static("CastTo", [](const std::shared_ptr i) { return std::dynamic_pointer_cast(i); })