Debian Codegraph @

plugins/script/interfaces/SelectionInterface.h

raw
1 #pragma once
2
3 #include <pybind11/pybind11.h>
4
5 #include "iscript.h"
6 #include "iscriptinterface.h"
7 #include "selectionlib.h"
8 #include <map>
9
10 #include "SceneGraphInterface.h"
11 #include "BrushInterface.h"
12
13 namespace script
14 {
15
16 // ========== Selection Handling ==========
17
18 // Wrap around the SelectionSystem::Visitor interface
19 class SelectionVisitorWrapper :
20 public selection::SelectionSystem::Visitor
21 {
22 public:
23 void visit(const scene::INodePtr& node) const override
24 {
25 // Wrap this method to python
26 PYBIND11_OVERLOAD_PURE(
27 void, /* Return type */
28 selection::SelectionSystem::Visitor, /* Parent class */
29 visit, /* Name of function in C++ (must match Python name) */
30 ScriptSceneNode(node) /* Argument(s) */
31 );
32 }
33 };
34
35 // Special interface only used by Python scripts to visit selected faces
36 class SelectedFaceVisitor
37 {
38 public:
39 virtual ~SelectedFaceVisitor() {}
40
41 virtual void visitFace(IFace& face) = 0;
42 };
43
44 class SelectedFaceVisitorWrapper :
45 public SelectedFaceVisitor
46 {
47 public:
48 void visitFace(IFace& face) override
49 {
50 // Wrap this method to python
51 PYBIND11_OVERLOAD_PURE(
52 void, /* Return type */
53 SelectedFaceVisitor, /* Parent class */
54 visitFace, /* Name of function in C++ (must match Python name) */
55 ScriptFace(face) /* Argument(s) */
56 );
57 }
58 };
59
60 class SelectionInterface :
61 public IScriptInterface
62 {
63 public:
64 // SelectionSystem wrappers
65 const SelectionInfo& getSelectionInfo();
66
67 void foreachSelected(const selection::SelectionSystem::Visitor& visitor);
68 void foreachSelectedComponent(const selection::SelectionSystem::Visitor& visitor);
69 void foreachSelectedFace(SelectedFaceVisitor& visitor);
70
71 void setSelectedAll(int selected);
72 void setSelectedAllComponents(int selected);
73
74 ScriptSceneNode ultimateSelected();
75 ScriptSceneNode penultimateSelected();
76
77 // IScriptInterface implementation
78 void registerInterface(py::module& scope, py::dict& globals) override;
79 };
80
81 } // namespace script