Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
863d137
commit ffd6d0b
Showing
7 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#include "SelectionGroupInterface.h" | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace script | ||
{ | ||
|
||
ScriptSelectionGroup::ScriptSelectionGroup(const selection::ISelectionGroupPtr& group) : | ||
_group(group) | ||
{} | ||
|
||
std::size_t ScriptSelectionGroup::getId() | ||
{ | ||
return _group ? _group->getId() : 0; | ||
} | ||
|
||
const std::string& ScriptSelectionGroup::getName() | ||
{ | ||
return _group ? _group->getName() : _emptyStr; | ||
} | ||
|
||
void ScriptSelectionGroup::setName(const std::string& name) | ||
{ | ||
if (_group) | ||
{ | ||
_group->setName(name); | ||
} | ||
} | ||
|
||
void ScriptSelectionGroup::addNode(const ScriptSceneNode& node) | ||
{ | ||
if (_group) | ||
{ | ||
_group->addNode(node); | ||
} | ||
} | ||
|
||
void ScriptSelectionGroup::removeNode(const scene::INodePtr& node) | ||
{ | ||
if (_group) | ||
{ | ||
_group->removeNode(node); | ||
} | ||
} | ||
|
||
std::size_t ScriptSelectionGroup::size() | ||
{ | ||
return _group ? _group->size() : 0; | ||
} | ||
|
||
void ScriptSelectionGroup::setSelected(int selected) | ||
{ | ||
if (_group) | ||
{ | ||
_group->setSelected(static_cast<bool>(selected)); | ||
} | ||
} | ||
|
||
void ScriptSelectionGroup::foreachNode(SelectionGroupVisitor& visitor) | ||
{ | ||
if (_group) | ||
{ | ||
_group->foreachNode([&](const scene::INodePtr& node) | ||
{ | ||
visitor.visit(node); | ||
}); | ||
} | ||
} | ||
|
||
std::string ScriptSelectionGroup::_emptyStr; | ||
|
||
// ----------------------------------- | ||
|
||
ScriptSelectionGroup SelectionGroupInterface::createSelectionGroup() | ||
{ | ||
return ScriptSelectionGroup(GlobalSelectionGroupManager().createSelectionGroup()); | ||
} | ||
|
||
ScriptSelectionGroup SelectionGroupInterface::getSelectionGroup(std::size_t id) | ||
{ | ||
return ScriptSelectionGroup(GlobalSelectionGroupManager().getSelectionGroup(id)); | ||
} | ||
|
||
ScriptSelectionGroup SelectionGroupInterface::findOrCreateSelectionGroup(std::size_t id) | ||
{ | ||
return ScriptSelectionGroup(GlobalSelectionGroupManager().findOrCreateSelectionGroup(id)); | ||
} | ||
|
||
void SelectionGroupInterface::setGroupSelected(std::size_t id, int selected) | ||
{ | ||
GlobalSelectionGroupManager().setGroupSelected(id, static_cast<bool>(selected)); | ||
} | ||
|
||
void SelectionGroupInterface::deleteAllSelectionGroups() | ||
{ | ||
GlobalSelectionGroupManager().deleteAllSelectionGroups(); | ||
} | ||
|
||
void SelectionGroupInterface::deleteSelectionGroup(std::size_t id) | ||
{ | ||
GlobalSelectionGroupManager().deleteSelectionGroup(id); | ||
} | ||
|
||
// IScriptInterface implementation | ||
void SelectionGroupInterface::registerInterface(py::module& scope, py::dict& globals) | ||
{ | ||
// Expose the SelectionGroupVisitor interface | ||
py::class_<SelectionGroupVisitor, SelectionGroupVisitorWrapper> visitor(scope, "SelectionGroupVisitor"); | ||
|
||
visitor.def(py::init<>()); | ||
visitor.def("visit", &SelectionGroupVisitor::visit); | ||
|
||
// Add SelectionGroup declaration | ||
py::class_<ScriptSelectionGroup> selectionGroup(scope, "SelectionGroup"); | ||
|
||
selectionGroup.def(py::init<const selection::ISelectionGroupPtr&>()); | ||
selectionGroup.def("getId", &ScriptSelectionGroup::getId); | ||
selectionGroup.def("getName", &ScriptSelectionGroup::getName, py::return_value_policy::reference); | ||
selectionGroup.def("setName", &ScriptSelectionGroup::setName); | ||
selectionGroup.def("addNode", &ScriptSelectionGroup::addNode); | ||
selectionGroup.def("removeNode", &ScriptSelectionGroup::removeNode); | ||
selectionGroup.def("size", &ScriptSelectionGroup::size); | ||
selectionGroup.def("setSelected", &ScriptSelectionGroup::setSelected); | ||
selectionGroup.def("foreachNode", &ScriptSelectionGroup::foreachNode); | ||
|
||
// Add the module declaration to the given python namespace | ||
py::class_<SelectionGroupInterface> selectionGroupManager(scope, "SelectionGroupManager"); | ||
|
||
selectionGroupManager.def("createSelectionGroup", &SelectionGroupInterface::createSelectionGroup); | ||
selectionGroupManager.def("getSelectionGroup", &SelectionGroupInterface::getSelectionGroup); | ||
selectionGroupManager.def("findOrCreateSelectionGroup", &SelectionGroupInterface::findOrCreateSelectionGroup); | ||
selectionGroupManager.def("setGroupSelected", &SelectionGroupInterface::setGroupSelected); | ||
selectionGroupManager.def("deleteAllSelectionGroups", &SelectionGroupInterface::deleteAllSelectionGroups); | ||
selectionGroupManager.def("deleteSelectionGroup", &SelectionGroupInterface::deleteSelectionGroup); | ||
|
||
// Now point the Python variable "GlobalSelectionGroupManager" to this instance | ||
globals["GlobalSelectionGroupManager"] = this; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include "iscript.h" | ||
#include "iselectiongroup.h" | ||
|
||
#include "SceneGraphInterface.h" | ||
|
||
namespace script | ||
{ | ||
|
||
// ========== SelectionGroup Handling ========== | ||
|
||
class SelectionGroupVisitor | ||
{ | ||
public: | ||
virtual ~SelectionGroupVisitor() {} | ||
virtual void visit(const scene::INodePtr& node) = 0; | ||
}; | ||
|
||
// Wrap around the ISelectionSetManager::Visitor interface | ||
class SelectionGroupVisitorWrapper : | ||
public SelectionGroupVisitor | ||
{ | ||
public: | ||
void visit(const scene::INodePtr& node) override | ||
{ | ||
// Wrap this method to python | ||
PYBIND11_OVERLOAD_PURE( | ||
void, /* Return type */ | ||
SelectionGroupVisitor, /* Parent class */ | ||
visit, /* Name of function in C++ (must match Python name) */ | ||
ScriptSceneNode(node) /* Argument(s) */ | ||
); | ||
} | ||
}; | ||
|
||
class ScriptSelectionGroup | ||
{ | ||
private: | ||
selection::ISelectionGroupPtr _group; | ||
|
||
static std::string _emptyStr; | ||
public: | ||
ScriptSelectionGroup(const selection::ISelectionGroupPtr& group); | ||
|
||
std::size_t getId(); | ||
const std::string& getName(); | ||
void setName(const std::string& name); | ||
void addNode(const ScriptSceneNode& node); | ||
void removeNode(const scene::INodePtr& node); | ||
std::size_t size(); | ||
void setSelected(int selected); | ||
void foreachNode(SelectionGroupVisitor& visitor); | ||
}; | ||
|
||
class SelectionGroupInterface : | ||
public IScriptInterface | ||
{ | ||
public: | ||
ScriptSelectionGroup createSelectionGroup(); | ||
ScriptSelectionGroup getSelectionGroup(std::size_t id); | ||
ScriptSelectionGroup findOrCreateSelectionGroup(std::size_t id); | ||
void setGroupSelected(std::size_t id, int selected); | ||
void deleteAllSelectionGroups(); | ||
void deleteSelectionGroup(std::size_t id); | ||
|
||
// IScriptInterface implementation | ||
void registerInterface(py::module& scope, py::dict& globals) override; | ||
}; | ||
|
||
} // namespace script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters