Debian Codegraph @

python/dartpy/gui/osg/WorldNode.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/functional.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 class PyWorldNode : public dart::gui::osg::WorldNode
46 {
47 public:
48 // Inherit the constructors
49 using WorldNode::WorldNode;
50
51 // Trampoline for virtual function
52 void refresh() override
53 {
54 PYBIND11_OVERLOAD(
55 void, // Return type
56 WorldNode, // Parent class
57 refresh, // Name of function in C++ (must match Python name)
58 );
59 }
60
61 // Trampoline for virtual function
62 void customPreRefresh() override
63 {
64 PYBIND11_OVERLOAD(
65 void, // Return type
66 WorldNode, // Parent class
67 customPreRefresh, // Name of function in C++ (must match Python name)
68 );
69 }
70
71 // Trampoline for virtual function
72 void customPostRefresh() override
73 {
74 PYBIND11_OVERLOAD(
75 void, // Return type
76 WorldNode, // Parent class
77 customPostRefresh, // Name of function in C++ (must match Python name)
78 );
79 }
80
81 // Trampoline for virtual function
82 void customPreStep() override
83 {
84 PYBIND11_OVERLOAD(
85 void, // Return type
86 WorldNode, // Parent class
87 customPreStep, // Name of function in C++ (must match Python name)
88 );
89 }
90
91 // Trampoline for virtual function
92 void customPostStep() override
93 {
94 PYBIND11_OVERLOAD(
95 void, // Return type
96 WorldNode, // Parent class
97 customPostStep, // Name of function in C++ (must match Python name)
98 );
99 }
100 };
101
102 void WorldNode(py::module& m)
103 {
104 ::py::class_<
105 dart::gui::osg::WorldNode,
106 PyWorldNode,
107 ::osg::ref_ptr<dart::gui::osg::WorldNode>>(m, "WorldNode")
108 .def(::py::init<>())
109 .def(
110 ::py::init<std::shared_ptr<dart::simulation::World>>(),
111 ::py::arg("world"))
112 .def(
113 ::py::init<
114 std::shared_ptr<dart::simulation::World>,
115 osg::ref_ptr<osgShadow::ShadowTechnique>>(),
116 ::py::arg("world"),
117 ::py::arg("shadowTechnique"))
118 .def(
119 "setWorld",
120 +[](dart::gui::osg::WorldNode* self,
121 std::shared_ptr<dart::simulation::World> newWorld) {
122 self->setWorld(newWorld);
123 },
124 ::py::arg("newWorld"))
125 .def(
126 "getWorld",
127 +[](const dart::gui::osg::WorldNode* self)
128 -> std::shared_ptr<dart::simulation::World> {
129 return self->getWorld();
130 })
131 .def(
132 "refresh", +[](dart::gui::osg::WorldNode* self) { self->refresh(); })
133 .def(
134 "customPreRefresh",
135 +[](dart::gui::osg::WorldNode* self) { self->customPreRefresh(); })
136 .def(
137 "customPostRefresh",
138 +[](dart::gui::osg::WorldNode* self) { self->customPostRefresh(); })
139 .def(
140 "customPreStep",
141 +[](dart::gui::osg::WorldNode* self) { self->customPreStep(); })
142 .def(
143 "customPostStep",
144 +[](dart::gui::osg::WorldNode* self) { self->customPostStep(); })
145 .def(
146 "isSimulating",
147 +[](const dart::gui::osg::WorldNode* self) -> bool {
148 return self->isSimulating();
149 })
150 .def(
151 "simulate",
152 +[](dart::gui::osg::WorldNode* self, bool on) { self->simulate(on); },
153 ::py::arg("on"))
154 .def(
155 "setNumStepsPerCycle",
156 +[](dart::gui::osg::WorldNode* self, std::size_t steps) {
157 self->setNumStepsPerCycle(steps);
158 },
159 ::py::arg("steps"))
160 .def(
161 "getNumStepsPerCycle",
162 +[](const dart::gui::osg::WorldNode* self) -> std::size_t {
163 return self->getNumStepsPerCycle();
164 })
165 .def(
166 "isShadowed",
167 +[](const dart::gui::osg::WorldNode* self) -> bool {
168 return self->isShadowed();
169 })
170 .def(
171 "setShadowTechnique",
172 +[](dart::gui::osg::WorldNode* self) { self->setShadowTechnique(); })
173 .def(
174 "setShadowTechnique",
175 +[](dart::gui::osg::WorldNode* self,
176 osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique) {
177 self->setShadowTechnique(shadowTechnique);
178 },
179 ::py::arg("shadowTechnique"))
180 .def(
181 "getShadowTechnique",
182 +[](const dart::gui::osg::WorldNode* self)
183 -> osg::ref_ptr<osgShadow::ShadowTechnique> {
184 return self->getShadowTechnique();
185 })
186 .def_static(
187 "createDefaultShadowTechnique",
188 +[](const dart::gui::osg::Viewer* viewer)
189 -> osg::ref_ptr<osgShadow::ShadowTechnique> {
190 return dart::gui::osg::WorldNode::createDefaultShadowTechnique(
191 viewer);
192 },
193 ::py::arg("viewer"));
194 }
195
196 } // namespace python
197 } // namespace dart