File: SelectionInterface.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (87 lines) | stat: -rw-r--r-- 3,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "SelectionInterface.h"

namespace script 
{

const SelectionInfo& SelectionInterface::getSelectionInfo() 
{
	return GlobalSelectionSystem().getSelectionInfo();
}

void SelectionInterface::foreachSelected(const selection::SelectionSystem::Visitor& visitor)
{
	GlobalSelectionSystem().foreachSelected(visitor);
}

void SelectionInterface::foreachSelectedComponent(const selection::SelectionSystem::Visitor& visitor)
{
	GlobalSelectionSystem().foreachSelectedComponent(visitor);
}

void SelectionInterface::foreachSelectedFace(SelectedFaceVisitor& visitor)
{
    GlobalSelectionSystem().foreachFace([&](IFace& face)
    {
        visitor.visitFace(face);
    });
}

void SelectionInterface::setSelectedAll(int selected)
{
	GlobalSelectionSystem().setSelectedAll(static_cast<bool>(selected));
}

void SelectionInterface::setSelectedAllComponents(int selected)
{
	GlobalSelectionSystem().setSelectedAllComponents(static_cast<bool>(selected));
}

ScriptSceneNode SelectionInterface::ultimateSelected()
{
	return GlobalSelectionSystem().ultimateSelected();
}

ScriptSceneNode SelectionInterface::penultimateSelected() 
{
	return GlobalSelectionSystem().penultimateSelected();
}

// IScriptInterface implementation
void SelectionInterface::registerInterface(py::module& scope, py::dict& globals)
{
	// Expose the SelectionInfo structure
	py::class_<SelectionInfo> selInfo(scope, "SelectionInformation");
	selInfo.def(py::init<>());
	selInfo.def_readonly("totalCount", &SelectionInfo::totalCount);
	selInfo.def_readonly("patchCount", &SelectionInfo::patchCount);
	selInfo.def_readonly("brushCount", &SelectionInfo::brushCount);
	selInfo.def_readonly("entityCount", &SelectionInfo::entityCount);
	selInfo.def_readonly("componentCount", &SelectionInfo::componentCount);

	// Expose the SelectionSystem::Visitor interface
	py::class_<selection::SelectionSystem::Visitor, SelectionVisitorWrapper> visitor(scope, "SelectionVisitor");
	visitor.def(py::init<>());
	visitor.def("visit", &selection::SelectionSystem::Visitor::visit);

    // Expose the SelectionFaceVisitor interface
    py::class_<SelectedFaceVisitor, SelectedFaceVisitorWrapper> faceVisitor(scope, "SelectedFaceVisitor");
    faceVisitor.def(py::init<>());
    faceVisitor.def("visitFace", &SelectedFaceVisitor::visitFace);

	// Add the module declaration to the given python namespace
	py::class_<SelectionInterface> selSys(scope, "SelectionSystem");

	selSys.def("getSelectionInfo", &SelectionInterface::getSelectionInfo, py::return_value_policy::reference);
	selSys.def("foreachSelected", &SelectionInterface::foreachSelected);
	selSys.def("foreachSelectedComponent", &SelectionInterface::foreachSelectedComponent);
	selSys.def("foreachSelectedFace", &SelectionInterface::foreachSelectedFace);
	selSys.def("setSelectedAll", &SelectionInterface::setSelectedAll);
	selSys.def("setSelectedAllComponents", &SelectionInterface::setSelectedAllComponents);
	selSys.def("ultimateSelected", &SelectionInterface::ultimateSelected);
	selSys.def("penultimateSelected", &SelectionInterface::penultimateSelected);

	// Now point the Python variable "GlobalSelectionSystem" to this instance
	globals["GlobalSelectionSystem"] = this;
}

} // namespace script