Debian Codegraph @

python/dartpy/gui/osg/DragAndDrop.cpp

raw
1 /*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <dart/dart.hpp>
34 #include <dart/gui/osg/osg.hpp>
35 #include <pybind11/eigen.h>
36 #include <pybind11/pybind11.h>
37
38 PYBIND11_DECLARE_HOLDER_TYPE(T, ::osg::ref_ptr<T>, true);
39
40 namespace py = pybind11;
41
42 namespace dart {
43 namespace python {
44
45 void DragAndDrop(py::module& m)
46 {
47 ::py::class_<
48 dart::gui::osg::DragAndDrop,
49 dart::common::Observer,
50 dart::common::Subject,
51 ::std::shared_ptr<dart::gui::osg::DragAndDrop>>(m, "DragAndDrop")
52 .def(
53 "update", +[](dart::gui::osg::DragAndDrop* self) { self->update(); })
54 .def(
55 "setObstructable",
56 +[](dart::gui::osg::DragAndDrop* self, bool _obstructable) {
57 self->setObstructable(_obstructable);
58 },
59 ::py::arg("obstructable"))
60 .def(
61 "isObstructable",
62 +[](const dart::gui::osg::DragAndDrop* self) -> bool {
63 return self->isObstructable();
64 })
65 .def(
66 "move", +[](dart::gui::osg::DragAndDrop* self) { self->move(); })
67 .def(
68 "saveState",
69 +[](dart::gui::osg::DragAndDrop* self) { self->saveState(); })
70 .def(
71 "release",
72 +[](dart::gui::osg::DragAndDrop* self) { self->release(); })
73 .def(
74 "getConstrainedDx",
75 +[](const dart::gui::osg::DragAndDrop* self) -> Eigen::Vector3d {
76 return self->getConstrainedDx();
77 })
78 .def(
79 "getConstrainedRotation",
80 +[](const dart::gui::osg::DragAndDrop* self) -> Eigen::AngleAxisd {
81 return self->getConstrainedRotation();
82 })
83 .def(
84 "unconstrain",
85 +[](dart::gui::osg::DragAndDrop* self) { self->unconstrain(); })
86 .def(
87 "constrainToLine",
88 +[](dart::gui::osg::DragAndDrop* self, const Eigen::Vector3d& slope) {
89 self->constrainToLine(slope);
90 },
91 ::py::arg("slope"))
92 .def(
93 "constrainToPlane",
94 +[](dart::gui::osg::DragAndDrop* self,
95 const Eigen::Vector3d& normal) {
96 self->constrainToPlane(normal);
97 },
98 ::py::arg("normal"))
99 .def(
100 "isMoving",
101 +[](const dart::gui::osg::DragAndDrop* self) -> bool {
102 return self->isMoving();
103 })
104 .def(
105 "setRotationOption",
106 +[](dart::gui::osg::DragAndDrop* self,
107 dart::gui::osg::DragAndDrop::RotationOption option) {
108 self->setRotationOption(option);
109 },
110 ::py::arg("option"))
111 .def(
112 "getRotationOption",
113 +[](const dart::gui::osg::DragAndDrop* self)
114 -> dart::gui::osg::DragAndDrop::RotationOption {
115 return self->getRotationOption();
116 })
117 .def(
118 "setRotationModKey",
119 +[](dart::gui::osg::DragAndDrop* self,
120 osgGA::GUIEventAdapter::ModKeyMask rotationModKey) {
121 self->setRotationModKey(rotationModKey);
122 },
123 ::py::arg("rotationModKey"))
124 .def(
125 "getRotationModKey",
126 +[](const dart::gui::osg::DragAndDrop* self)
127 -> osgGA::GUIEventAdapter::ModKeyMask {
128 return self->getRotationModKey();
129 });
130
131 auto attr = m.attr("DragAndDrop");
132
133 ::py::enum_<dart::gui::osg::DragAndDrop::RotationOption>(
134 attr, "RotationOption")
135 .value(
136 "HOLD_MODKEY",
137 dart::gui::osg::DragAndDrop::RotationOption::HOLD_MODKEY)
138 .value(
139 "ALWAYS_ON", dart::gui::osg::DragAndDrop::RotationOption::ALWAYS_ON)
140 .value(
141 "ALWAYS_OFF", dart::gui::osg::DragAndDrop::RotationOption::ALWAYS_OFF)
142 .export_values();
143
144 ::py::class_<
145 dart::gui::osg::SimpleFrameDnD,
146 dart::gui::osg::DragAndDrop,
147 ::std::shared_ptr<dart::gui::osg::SimpleFrameDnD>>(m, "SimpleFrameDnD")
148 .def(
149 ::py::init<dart::gui::osg::Viewer*, dart::dynamics::SimpleFrame*>(),
150 ::py::arg("viewer"),
151 ::py::arg("frame"))
152 .def(
153 "move", +[](dart::gui::osg::SimpleFrameDnD* self) { self->move(); })
154 .def(
155 "saveState",
156 +[](dart::gui::osg::SimpleFrameDnD* self) { self->saveState(); });
157
158 ::py::class_<
159 dart::gui::osg::SimpleFrameShapeDnD,
160 dart::gui::osg::SimpleFrameDnD,
161 std::shared_ptr<dart::gui::osg::SimpleFrameShapeDnD>>(
162 m, "SimpleFrameShapeDnD")
163 .def(
164 ::py::init<
165 dart::gui::osg::Viewer*,
166 dart::dynamics::SimpleFrame*,
167 dart::dynamics::Shape*>(),
168 ::py::arg("viewer"),
169 ::py::arg("frame"),
170 ::py::arg("shape"))
171 .def(
172 "update",
173 +[](dart::gui::osg::SimpleFrameShapeDnD* self) { self->update(); });
174
175 ::py::class_<
176 dart::gui::osg::BodyNodeDnD,
177 dart::gui::osg::DragAndDrop,
178 std::shared_ptr<dart::gui::osg::BodyNodeDnD>>(m, "BodyNodeDnD")
179 .def(
180 ::py::init<dart::gui::osg::Viewer*, dart::dynamics::BodyNode*>(),
181 ::py::arg("viewer"),
182 ::py::arg("bn"))
183 .def(
184 ::py::
185 init<dart::gui::osg::Viewer*, dart::dynamics::BodyNode*, bool>(),
186 ::py::arg("viewer"),
187 ::py::arg("bn"),
188 ::py::arg("useExternalIK"))
189 .def(
190 ::py::init<
191 dart::gui::osg::Viewer*,
192 dart::dynamics::BodyNode*,
193 bool,
194 bool>(),
195 ::py::arg("viewer"),
196 ::py::arg("bn"),
197 ::py::arg("useExternalIK"),
198 ::py::arg("useWholeBody"))
199 .def(
200 "update", +[](dart::gui::osg::BodyNodeDnD* self) { self->update(); })
201 .def(
202 "move", +[](dart::gui::osg::BodyNodeDnD* self) { self->move(); })
203 .def(
204 "saveState",
205 +[](dart::gui::osg::BodyNodeDnD* self) { self->saveState(); })
206 .def(
207 "release",
208 +[](dart::gui::osg::BodyNodeDnD* self) { self->release(); })
209 .def(
210 "useExternalIK",
211 +[](dart::gui::osg::BodyNodeDnD* self, bool external) {
212 self->useExternalIK(external);
213 },
214 ::py::arg("external"))
215 .def(
216 "isUsingExternalIK",
217 +[](const dart::gui::osg::BodyNodeDnD* self) -> bool {
218 return self->isUsingExternalIK();
219 })
220 .def(
221 "useWholeBody",
222 +[](dart::gui::osg::BodyNodeDnD* self, bool wholeBody) {
223 self->useWholeBody(wholeBody);
224 },
225 ::py::arg("wholeBody"))
226 .def(
227 "isUsingWholeBody",
228 +[](const dart::gui::osg::BodyNodeDnD* self) -> bool {
229 return self->isUsingWholeBody();
230 })
231 .def(
232 "setPreserveOrientationModKey",
233 +[](dart::gui::osg::BodyNodeDnD* self,
234 osgGA::GUIEventAdapter::ModKeyMask modkey) {
235 self->setPreserveOrientationModKey(modkey);
236 },
237 ::py::arg("modkey"))
238 .def(
239 "getPreserveOrientationModKey",
240 +[](const dart::gui::osg::BodyNodeDnD* self)
241 -> osgGA::GUIEventAdapter::ModKeyMask {
242 return self->getPreserveOrientationModKey();
243 })
244 .def(
245 "setJointRestrictionModKey",
246 +[](dart::gui::osg::BodyNodeDnD* self,
247 osgGA::GUIEventAdapter::ModKeyMask modkey) {
248 self->setJointRestrictionModKey(modkey);
249 },
250 ::py::arg("modkey"))
251 .def(
252 "getJointRestrictionModKey",
253 +[](const dart::gui::osg::BodyNodeDnD* self)
254 -> osgGA::GUIEventAdapter::ModKeyMask {
255 return self->getJointRestrictionModKey();
256 });
257
258 ::py::class_<
259 dart::gui::osg::InteractiveFrameDnD,
260 dart::gui::osg::DragAndDrop,
261 std::shared_ptr<dart::gui::osg::InteractiveFrameDnD>>(
262 m, "InteractiveFrameDnD")
263 .def(
264 ::py::init<
265 dart::gui::osg::Viewer*,
266 dart::gui::osg::InteractiveFrame*>(),
267 ::py::arg("viewer"),
268 ::py::arg("frame"))
269 .def(
270 "update",
271 +[](dart::gui::osg::InteractiveFrameDnD* self) { self->update(); })
272 .def(
273 "move",
274 +[](dart::gui::osg::InteractiveFrameDnD* self) { self->move(); })
275 .def(
276 "saveState", +[](dart::gui::osg::InteractiveFrameDnD* self) {
277 self->saveState();
278 });
279 }
280
281 } // namespace python
282 } // namespace dart