Skip to content

Commit

Permalink
Migrate SelectionSetInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 21, 2017
1 parent 5707a10 commit 8826153
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
44 changes: 22 additions & 22 deletions plugins/script/interfaces/SelectionSetInterface.cpp
Expand Up @@ -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_<SelectionSetVisitorWrapper, boost::noncopyable>("SelectionSetVisitor")
.def("visit", boost::python::pure_virtual(&selection::ISelectionSetManager::Visitor::visit))
;
py::class_<selection::ISelectionSetManager::Visitor, SelectionSetVisitorWrapper> visitor(scope, "SelectionSetVisitor");

visitor.def(py::init<>());
visitor.def("visit", &selection::ISelectionSetManager::Visitor::visit);

// Add SelectionSet declaration
nspace["SelectionSet"] = boost::python::class_<ScriptSelectionSet>("SelectionSet",
boost::python::init<const selection::ISelectionSetPtr&>())
.def("getName", &ScriptSelectionSet::getName,
boost::python::return_value_policy<boost::python::copy_const_reference>())
.def("empty", &ScriptSelectionSet::empty)
.def("clear", &ScriptSelectionSet::clear)
.def("select", &ScriptSelectionSet::select)
.def("deselect", &ScriptSelectionSet::deselect)
.def("assignFromCurrentScene", &ScriptSelectionSet::assignFromCurrentScene)
;
py::class_<ScriptSelectionSet> selectionSet(scope, "SelectionSet");

selectionSet.def(py::init<const selection::ISelectionSetPtr&>());
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_<SelectionSetInterface>("GlobalSelectionSetManager")
.def("foreachSelectionSet", &SelectionSetInterface::foreachSelectionSet)
.def("createSelectionSet", &SelectionSetInterface::createSelectionSet)
.def("deleteSelectionSet", &SelectionSetInterface::deleteSelectionSet)
.def("deleteAllSelectionSets", &SelectionSetInterface::deleteAllSelectionSets)
.def("findSelectionSet", &SelectionSetInterface::findSelectionSet)
;
py::class_<SelectionSetInterface> 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
26 changes: 14 additions & 12 deletions plugins/script/interfaces/SelectionSetInterface.h
@@ -1,11 +1,12 @@
#ifndef _SELECTION_SET_INTERFACE_H_
#define _SELECTION_SET_INTERFACE_H_
#pragma once

#include <pybind11/pybind11.h>

#include <boost/python.hpp>
#include "iscript.h"
#include "iselectionset.h"

namespace script {
namespace script
{

// ========== SelectionSet Handling ==========

Expand All @@ -28,14 +29,18 @@ class ScriptSelectionSet

// Wrap around the ISelectionSetManager::Visitor interface
class SelectionSetVisitorWrapper :
public selection::ISelectionSetManager::Visitor,
public boost::python::wrapper<selection::ISelectionSetManager::Visitor>
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) */
);
}
};

Expand All @@ -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<SelectionSetInterface> SelectionSetInterfacePtr;

} // namespace script

#endif /* _SELECTION_SET_INTERFACE_H_ */

0 comments on commit 8826153

Please sign in to comment.