From 882615380a6a79850ae253ba13fd59495a9fcc07 Mon Sep 17 00:00:00 2001 From: codereader Date: Fri, 21 Jul 2017 05:51:43 +0200 Subject: [PATCH] Migrate SelectionSetInterface --- .../interfaces/SelectionSetInterface.cpp | 44 +++++++++---------- .../script/interfaces/SelectionSetInterface.h | 26 ++++++----- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/plugins/script/interfaces/SelectionSetInterface.cpp b/plugins/script/interfaces/SelectionSetInterface.cpp index d002540ed7..b6fab5d517 100644 --- a/plugins/script/interfaces/SelectionSetInterface.cpp +++ b/plugins/script/interfaces/SelectionSetInterface.cpp @@ -67,36 +67,36 @@ ScriptSelectionSet SelectionSetInterface::findSelectionSet(const std::string& na } // IScriptInterface implementation -void SelectionSetInterface::registerInterface(boost::python::object& nspace) +void SelectionSetInterface::registerInterface(py::module& scope, py::dict& globals) { // Expose the SelectionSystem::Visitor interface - nspace["SelectionSetVisitor"] = boost::python::class_("SelectionSetVisitor") - .def("visit", boost::python::pure_virtual(&selection::ISelectionSetManager::Visitor::visit)) - ; + py::class_ visitor(scope, "SelectionSetVisitor"); + + visitor.def(py::init<>()); + visitor.def("visit", &selection::ISelectionSetManager::Visitor::visit); // Add SelectionSet declaration - nspace["SelectionSet"] = boost::python::class_("SelectionSet", - boost::python::init()) - .def("getName", &ScriptSelectionSet::getName, - boost::python::return_value_policy()) - .def("empty", &ScriptSelectionSet::empty) - .def("clear", &ScriptSelectionSet::clear) - .def("select", &ScriptSelectionSet::select) - .def("deselect", &ScriptSelectionSet::deselect) - .def("assignFromCurrentScene", &ScriptSelectionSet::assignFromCurrentScene) - ; + py::class_ selectionSet(scope, "SelectionSet"); + + selectionSet.def(py::init()); + selectionSet.def("getName", &ScriptSelectionSet::getName, py::return_value_policy::reference); + selectionSet.def("empty", &ScriptSelectionSet::empty); + selectionSet.def("clear", &ScriptSelectionSet::clear); + selectionSet.def("select", &ScriptSelectionSet::select); + selectionSet.def("deselect", &ScriptSelectionSet::deselect); + selectionSet.def("assignFromCurrentScene", &ScriptSelectionSet::assignFromCurrentScene); // Add the module declaration to the given python namespace - nspace["GlobalSelectionSetManager"] = boost::python::class_("GlobalSelectionSetManager") - .def("foreachSelectionSet", &SelectionSetInterface::foreachSelectionSet) - .def("createSelectionSet", &SelectionSetInterface::createSelectionSet) - .def("deleteSelectionSet", &SelectionSetInterface::deleteSelectionSet) - .def("deleteAllSelectionSets", &SelectionSetInterface::deleteAllSelectionSets) - .def("findSelectionSet", &SelectionSetInterface::findSelectionSet) - ; + py::class_ selectionSetManager(scope, "SelectionSetManager"); + + selectionSetManager.def("foreachSelectionSet", &SelectionSetInterface::foreachSelectionSet); + selectionSetManager.def("createSelectionSet", &SelectionSetInterface::createSelectionSet); + selectionSetManager.def("deleteSelectionSet", &SelectionSetInterface::deleteSelectionSet); + selectionSetManager.def("deleteAllSelectionSets", &SelectionSetInterface::deleteAllSelectionSets); + selectionSetManager.def("findSelectionSet", &SelectionSetInterface::findSelectionSet); // Now point the Python variable "GlobalSelectionSetManager" to this instance - nspace["GlobalSelectionSetManager"] = boost::python::ptr(this); + globals["GlobalSelectionSetManager"] = this; } } // namespace script diff --git a/plugins/script/interfaces/SelectionSetInterface.h b/plugins/script/interfaces/SelectionSetInterface.h index 0222ea0c21..1fe3dd70f6 100644 --- a/plugins/script/interfaces/SelectionSetInterface.h +++ b/plugins/script/interfaces/SelectionSetInterface.h @@ -1,11 +1,12 @@ -#ifndef _SELECTION_SET_INTERFACE_H_ -#define _SELECTION_SET_INTERFACE_H_ +#pragma once + +#include -#include #include "iscript.h" #include "iselectionset.h" -namespace script { +namespace script +{ // ========== SelectionSet Handling ========== @@ -28,14 +29,18 @@ class ScriptSelectionSet // Wrap around the ISelectionSetManager::Visitor interface class SelectionSetVisitorWrapper : - public selection::ISelectionSetManager::Visitor, - public boost::python::wrapper + public selection::ISelectionSetManager::Visitor { public: - void visit(const selection::ISelectionSetPtr& set) + void visit(const selection::ISelectionSetPtr& set) override { // Wrap this method to python - this->get_override("visit")(ScriptSelectionSet(set)); + PYBIND11_OVERLOAD_PURE( + void, /* Return type */ + selection::ISelectionSetManager::Visitor, /* Parent class */ + visit, /* Name of function in C++ (must match Python name) */ + ScriptSelectionSet(set) /* Argument(s) */ + ); } }; @@ -51,10 +56,7 @@ class SelectionSetInterface : ScriptSelectionSet findSelectionSet(const std::string& name); // IScriptInterface implementation - void registerInterface(boost::python::object& nspace); + void registerInterface(py::module& scope, py::dict& globals) override; }; -typedef std::shared_ptr SelectionSetInterfacePtr; } // namespace script - -#endif /* _SELECTION_SET_INTERFACE_H_ */