| 1 |
#include "SelectionInterface.h" |
| 2 |
|
| 3 |
namespace script |
| 4 |
{ |
| 5 |
|
| 6 |
const SelectionInfo& SelectionInterface::getSelectionInfo() |
| 7 |
{ |
| 8 |
return GlobalSelectionSystem().getSelectionInfo(); |
| 9 |
} |
| 10 |
|
| 11 |
void SelectionInterface::foreachSelected(const selection::SelectionSystem::Visitor& visitor) |
| 12 |
{ |
| 13 |
GlobalSelectionSystem().foreachSelected(visitor); |
| 14 |
} |
| 15 |
|
| 16 |
void SelectionInterface::foreachSelectedComponent(const selection::SelectionSystem::Visitor& visitor) |
| 17 |
{ |
| 18 |
GlobalSelectionSystem().foreachSelectedComponent(visitor); |
| 19 |
} |
| 20 |
|
| 21 |
void SelectionInterface::foreachSelectedFace(SelectedFaceVisitor& visitor) |
| 22 |
{ |
| 23 |
GlobalSelectionSystem().foreachFace([&](IFace& face) |
| 24 |
{ |
| 25 |
visitor.visitFace(face); |
| 26 |
}); |
| 27 |
} |
| 28 |
|
| 29 |
void SelectionInterface::setSelectedAll(int selected) |
| 30 |
{ |
| 31 |
GlobalSelectionSystem().setSelectedAll(static_cast<bool>(selected)); |
| 32 |
} |
| 33 |
|
| 34 |
void SelectionInterface::setSelectedAllComponents(int selected) |
| 35 |
{ |
| 36 |
GlobalSelectionSystem().setSelectedAllComponents(static_cast<bool>(selected)); |
| 37 |
} |
| 38 |
|
| 39 |
ScriptSceneNode SelectionInterface::ultimateSelected() |
| 40 |
{ |
| 41 |
return GlobalSelectionSystem().ultimateSelected(); |
| 42 |
} |
| 43 |
|
| 44 |
ScriptSceneNode SelectionInterface::penultimateSelected() |
| 45 |
{ |
| 46 |
return GlobalSelectionSystem().penultimateSelected(); |
| 47 |
} |
| 48 |
|
| 49 |
// IScriptInterface implementation |
| 50 |
void SelectionInterface::registerInterface(py::module& scope, py::dict& globals) |
| 51 |
{ |
| 52 |
// Expose the SelectionInfo structure |
| 53 |
py::class_<SelectionInfo> selInfo(scope, "SelectionInformation"); |
| 54 |
selInfo.def(py::init<>()); |
| 55 |
selInfo.def_readonly("totalCount", &SelectionInfo::totalCount); |
| 56 |
selInfo.def_readonly("patchCount", &SelectionInfo::patchCount); |
| 57 |
selInfo.def_readonly("brushCount", &SelectionInfo::brushCount); |
| 58 |
selInfo.def_readonly("entityCount", &SelectionInfo::entityCount); |
| 59 |
selInfo.def_readonly("componentCount", &SelectionInfo::componentCount); |
| 60 |
|
| 61 |
// Expose the SelectionSystem::Visitor interface |
| 62 |
py::class_<selection::SelectionSystem::Visitor, SelectionVisitorWrapper> visitor(scope, "SelectionVisitor"); |
| 63 |
visitor.def(py::init<>()); |
| 64 |
visitor.def("visit", &selection::SelectionSystem::Visitor::visit); |
| 65 |
|
| 66 |
// Expose the SelectionFaceVisitor interface |
| 67 |
py::class_<SelectedFaceVisitor, SelectedFaceVisitorWrapper> faceVisitor(scope, "SelectedFaceVisitor"); |
| 68 |
faceVisitor.def(py::init<>()); |
| 69 |
faceVisitor.def("visitFace", &SelectedFaceVisitor::visitFace); |
| 70 |
|
| 71 |
// Add the module declaration to the given python namespace |
| 72 |
py::class_<SelectionInterface> selSys(scope, "SelectionSystem"); |
| 73 |
|
| 74 |
selSys.def("getSelectionInfo", &SelectionInterface::getSelectionInfo, py::return_value_policy::reference); |
| 75 |
selSys.def("foreachSelected", &SelectionInterface::foreachSelected); |
| 76 |
selSys.def("foreachSelectedComponent", &SelectionInterface::foreachSelectedComponent); |
| 77 |
selSys.def("foreachSelectedFace", &SelectionInterface::foreachSelectedFace); |
| 78 |
selSys.def("setSelectedAll", &SelectionInterface::setSelectedAll); |
| 79 |
selSys.def("setSelectedAllComponents", &SelectionInterface::setSelectedAllComponents); |
| 80 |
selSys.def("ultimateSelected", &SelectionInterface::ultimateSelected); |
| 81 |
selSys.def("penultimateSelected", &SelectionInterface::penultimateSelected); |
| 82 |
|
| 83 |
// Now point the Python variable "GlobalSelectionSystem" to this instance |
| 84 |
globals["GlobalSelectionSystem"] = this; |
| 85 |
} |
| 86 |
|
| 87 |
} // namespace script |