Developer Documentation

Python.cc
1
2 /*===========================================================================*\
3 * *
4 * OpenFlipper *
5 * Copyright (c) 2001-2015, RWTH-Aachen University *
6 * Department of Computer Graphics and Multimedia *
7 * All rights reserved. *
8 * www.openflipper.org *
9 * *
10 *---------------------------------------------------------------------------*
11 * This file is part of OpenFlipper. *
12 *---------------------------------------------------------------------------*
13 * *
14 * Redistribution and use in source and binary forms, with or without *
15 * modification, are permitted provided that the following conditions *
16 * are met: *
17 * *
18 * 1. Redistributions of source code must retain the above copyright notice, *
19 * this list of conditions and the following disclaimer. *
20 * *
21 * 2. Redistributions in binary form must reproduce the above copyright *
22 * notice, this list of conditions and the following disclaimer in the *
23 * documentation and/or other materials provided with the distribution. *
24 * *
25 * 3. Neither the name of the copyright holder nor the names of its *
26 * contributors may be used to endorse or promote products derived from *
27 * this software without specific prior written permission. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40 * *
41 \*===========================================================================*/
42
43 #include <pybind11/include/pybind11/pybind11.h>
44 #include <pybind11/include/pybind11/embed.h>
45
46
47 #include <ViewControlPlugin.hh>
48 #include <OpenFlipper/BasePlugin/PythonFunctions.hh>
49 #include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
50
51 namespace py = pybind11;
52
53
54
55 PYBIND11_EMBEDDED_MODULE(ViewControl, m) {
56
57 QObject* pluginPointer = getPluginPointer("ViewControl");
58
59 if (!pluginPointer) {
60 std::cerr << "Error Getting plugin pointer for Plugin-ViewControl" << std::endl;
61 return;
62 }
63
64 ViewControlPlugin* plugin = qobject_cast<ViewControlPlugin*>(pluginPointer);
65
66 if (!plugin) {
67 std::cerr << "Error converting plugin pointer for Plugin-ViewControl" << std::endl;
68 return;
69 }
70
71 // Export our core. Make sure that the c++ worlds core object is not deleted if
72 // the python side gets deleted!!
73 py::class_< ViewControlPlugin,std::unique_ptr<ViewControlPlugin, py::nodelete> > view(m, "ViewControl");
74
75 // On the c++ side we will just return the existing core instance
76 // and prevent the system to recreate a new core as we need
77 // to work on the existing one.
78 view.def(py::init([plugin]() { return plugin; }));
79
80
81
82 view.def("selectionVisible", &ViewControlPlugin::selectionVisible,
83 QCoreApplication::translate("PythonDocViewControl","For meshes returns if the selection for this object is visible").toLatin1().data(),
84 py::arg(QCoreApplication::translate("PythonDocViewControl","ID of the mesh object").toLatin1().data()) );
85
86 view.def("showSelection", &ViewControlPlugin::showSelection,
87 QCoreApplication::translate("PythonDocViewControl","For meshes show or hide the selection.").toLatin1().data(),
88 py::arg(QCoreApplication::translate("PythonDocViewControl","ID of the mesh object").toLatin1().data()),
89 py::arg(QCoreApplication::translate("PythonDocViewControl","Visible or not?").toLatin1().data()) );
90
91 view.def("modelingAreasVisible", &ViewControlPlugin::modelingAreasVisible,
92 QCoreApplication::translate("PythonDocViewControl","For meshes returns if the modeling area for this object is visible").toLatin1().data(),
93 py::arg(QCoreApplication::translate("PythonDocViewControl","ID of the mesh object").toLatin1().data()) );
94
95 view.def("showModelingAreas", &ViewControlPlugin::showModelingAreas,
96 QCoreApplication::translate("PythonDocViewControl","For meshes show or hide the modeling area.").toLatin1().data(),
97 py::arg(QCoreApplication::translate("PythonDocViewControl","ID of the mesh object").toLatin1().data()),
98 py::arg(QCoreApplication::translate("PythonDocViewControl","Visible or not?").toLatin1().data()) );
99
100
101 // /** Disable the given shader for a given object and draw mode.
102 // * @param _objectId ID of the object for which to disable the shader
103 // * @param _drawMode _drawMode for which the shader is disabled
104 // * @param _shader Shader which is disabled. If this shader is not currently active for
105 // * the given _drawMode, nothing will be disabled. In order to disable
106 // * all shaders for the given _drawMode, use _shader=0 (default).
107 // */
108 // void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo* _shader=0);
109 //
110 // /** Sets a shader for the object and the given drawMode( can be a combination of draw modes )
111 // * @param _id Object Id
112 // * @param _drawMode ; separated list of drawmodes used by the shader
113 // * @param _shader Shader information
114 // */
115 // void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader);
116
117 // /** Sets a Shader for a specific draw mode
118 // *
119 // * @param _id Object id that should use the shader
120 // * @param _drawMode Draw mode where this shader will be active
121 // * @param _name Name of the shader that should be used
122 // */
123 // void setShader(int _id, QString _drawMode, QString _name );
124 //
125 // /// get information about available uniforms for a given shader
126 // QStringList getUniforms(QString _shader);
127 //
128 // QString getUniformType(QString _shader, QString _uniform );
129 // QString getUniformDefault(QString _shader, QString _uniform );
130 // QString getUniformMin(QString _shader, QString _uniform );
131 // QString getUniformMax(QString _shader, QString _uniform );
132 //
133 // /// set the value of a uniform in a shader for a specific drawMode
134 // void setUniform(int _objID, ACG::SceneGraph::DrawModes::DrawMode _drawMode, QString _shader, QString _uniform, QString _value );
135
136 view.def("setViewingDirection", &ViewControlPlugin::setViewingDirection,
137 QCoreApplication::translate("PythonDocViewControl","Set the viewing direction").toLatin1().data(),
138 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewing Direction").toLatin1().data()),
139 py::arg(QCoreApplication::translate("PythonDocViewControl","Up vector").toLatin1().data()),
140 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to set viewing direction (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
141
142 view.def("setSceneRadius", &ViewControlPlugin::setSceneRadius,
143 QCoreApplication::translate("PythonDocViewControl","Set scene radius").toLatin1().data(),
144 py::arg(QCoreApplication::translate("PythonDocViewControl","Radius").toLatin1().data()),
145 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to set radius (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
146
147 view.def("rotate", &ViewControlPlugin::rotate,
148 QCoreApplication::translate("PythonDocViewControl","Rotate scene").toLatin1().data(),
149 py::arg(QCoreApplication::translate("PythonDocViewControl","Rotation axis").toLatin1().data()),
150 py::arg(QCoreApplication::translate("PythonDocViewControl","Rotation angle").toLatin1().data()),
151 py::arg(QCoreApplication::translate("PythonDocViewControl","Rotation center").toLatin1().data()),
152 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to rotate (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
153
154
155 view.def("translate", &ViewControlPlugin::translate,
156 QCoreApplication::translate("PythonDocViewControl","Translate scene").toLatin1().data(),
157 py::arg(QCoreApplication::translate("PythonDocViewControl","Translation vector").toLatin1().data()),
158 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to translate (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
159
160 view.def("setDrawMode", &ViewControlPlugin::setDrawMode,
161 QCoreApplication::translate("PythonDocViewControl","Set the draw mode of a viewer").toLatin1().data(),
162 py::arg(QCoreApplication::translate("PythonDocViewControl","List of draw modes ( ; separated list ) ").toLatin1().data()),
163 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to set draw mode (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
164
165 view.def("setObjectDrawMode", &ViewControlPlugin::setObjectDrawMode,
166 QCoreApplication::translate("PythonDocViewControl"," This function can be used to set the drawmode for an object.").toLatin1().data(),
167 py::arg(QCoreApplication::translate("PythonDocViewControl","List of draw modes ( ; separated list ) ").toLatin1().data()),
168 py::arg(QCoreApplication::translate("PythonDocViewControl","Object ID to set the drawmode on.").toLatin1().data()),
169 py::arg(QCoreApplication::translate("PythonDocViewControl","Set the draw mode even if its not directly supported by the objects nodes").toLatin1().data()) = true);
170
171 view.def("viewingDirection", &ViewControlPlugin::viewingDirection,
172 QCoreApplication::translate("PythonDocViewControl","Get the current viewing direction").toLatin1().data(),
173 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get viewing direction from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
174
175 view.def("upVector", &ViewControlPlugin::upVector,
176 QCoreApplication::translate("PythonDocViewControl","Get the current upVector").toLatin1().data(),
177 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get upVector from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
178
179 view.def("eyePosition", &ViewControlPlugin::eyePosition,
180 QCoreApplication::translate("PythonDocViewControl","Get the current eyePosition").toLatin1().data(),
181 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get eyePosition from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
182
183 view.def("sceneCenter", &ViewControlPlugin::sceneCenter,
184 QCoreApplication::translate("PythonDocViewControl","Get the current sceneCenter").toLatin1().data(),
185 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get scene center from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
186
187 view.def("setSceneCenter", &ViewControlPlugin::setSceneCenter,
188 QCoreApplication::translate("PythonDocViewControl","Set the scene center").toLatin1().data(),
189 py::arg(QCoreApplication::translate("PythonDocViewControl","Coordinates of center?").toLatin1().data()),
190 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to change (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
191
192 view.def("enableBackfaceCulling", &ViewControlPlugin::enableBackfaceCulling,
193 QCoreApplication::translate("PythonDocViewControl","Enable or disable Backface culling").toLatin1().data(),
194 py::arg(QCoreApplication::translate("PythonDocViewControl","Enable?").toLatin1().data()),
195 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to change (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
196
197 view.def("setEyePosition", &ViewControlPlugin::setEyePosition),
198 QCoreApplication::translate("PythonDocViewControl","Change the Eye position to the given value").toLatin1().data(),
199 py::arg(QCoreApplication::translate("PythonDocViewControl","Eye position").toLatin1().data()) ;
200
201 view.def("viewAll", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::viewAll),
202 QCoreApplication::translate("PythonDocViewControl","Change View in all viewers to view whole scene").toLatin1().data());
203 view.def("viewAll", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::viewAll),
204 QCoreApplication::translate("PythonDocViewControl","Change View in given viewer to view whole scene").toLatin1().data(),
205 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer which should be switched").toLatin1().data()) );
206
207 view.def("viewHome", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::viewHome),
208 QCoreApplication::translate("PythonDocViewControl","Change View on all viewers to view home position").toLatin1().data());
209 view.def("viewHome", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::viewHome),
210 QCoreApplication::translate("PythonDocViewControl","Change View on given viewer to view home position").toLatin1().data(),
211 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer to change").toLatin1().data()) );
212
213 view.def("orthographicProjection", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::orthographicProjection),
214 QCoreApplication::translate("PythonDocViewControl","Change all Viewers to orthographic projection").toLatin1().data());
215 view.def("orthographicProjection", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::orthographicProjection),
216 QCoreApplication::translate("PythonDocViewControl","Change Viewer to orthographic projection").toLatin1().data(),
217 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer to change").toLatin1().data()) );
218
219 view.def("perspectiveProjection", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::orthographicProjection),
220 QCoreApplication::translate("PythonDocViewControl","Change all Viewers to perspective projection").toLatin1().data());
221 view.def("perspectiveProjection", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::orthographicProjection),
222 QCoreApplication::translate("PythonDocViewControl","Change Viewer to perspective projection").toLatin1().data(),
223 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer to change").toLatin1().data()) );
224
225 view.def("setFOVY", &ViewControlPlugin::setFOVY,
226 QCoreApplication::translate("PythonDocViewControl","Set fovy angle of projection for all viewers.").toLatin1().data(),
227 py::arg(QCoreApplication::translate("PythonDocViewControl","fovy angle").toLatin1().data()) );
228
229 view.def("setCoordsysProjection", &ViewControlPlugin::setCoordsysProjection,
230 QCoreApplication::translate("PythonDocViewControl","Set the projection mode of the coordinate system.").toLatin1().data(),
231 py::arg(QCoreApplication::translate("PythonDocViewControl","If true, orthogonal projection otherwise perspective projection").toLatin1().data()) );
232
233 view.def("setTwoSidedLighting", &ViewControlPlugin::setTwoSidedLighting,
234 QCoreApplication::translate("PythonDocViewControl","Enable or disable two sided lighting.").toLatin1().data(),
235 py::arg(QCoreApplication::translate("PythonDocViewControl","Specifies whether to enable or disable two sided lighting.").toLatin1().data()) );
236
237 //
238 // emit setSlotDescription("setObjectDrawMode(QString,int,bool)", "Set the drawMode for an object",
239 // QString("DrawMode,ObjectID,Force").split(","),
240 // QString("the drawMode ( ; separated list ),Object id,Apply without checking support(default is true)").split(","));
241
242
243 }
244
ViewControlPlugin::setSceneRadius
void setSceneRadius(double _radius, int _viewer=PluginFunctions::ALL_VIEWERS)
Set scene radius.
Definition: ViewControlPlugin.cc:1232
ViewControlPlugin
Definition: ViewControlPlugin.hh:83
ViewControlPlugin::orthographicProjection
void orthographicProjection()
Change Viewer to orthographicProjection.
Definition: ViewControlPlugin.cc:1398
ViewControlPlugin::upVector
Vector upVector(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers up vector
Definition: ViewControlPlugin.cc:1312
ViewControlPlugin::viewHome
void viewHome()
Change View on given Viewer to view home position.
Definition: ViewControlPlugin.cc:1390
ViewControlPlugin::setCoordsysProjection
void setCoordsysProjection(bool _orthogonal)
Definition: ViewControlPlugin.cc:1421
ViewControlPlugin::enableBackfaceCulling
void enableBackfaceCulling(bool _state, int _viewer=PluginFunctions::ALL_VIEWERS)
Enable or disable Backface culling.
Definition: ViewControlPlugin.cc:1249
ViewControlPlugin::eyePosition
Vector eyePosition(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers eye Position
Definition: ViewControlPlugin.cc:1316
pybind11
Definition: PythonTypeConversions.hh:49
ViewControlPlugin::setViewingDirection
void setViewingDirection(Vector _direction, Vector _upvector, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the viewing direction.
Definition: ViewControlPlugin.cc:1226
ViewControlPlugin::viewingDirection
Vector viewingDirection(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get a viewers viewing direction.
Definition: ViewControlPlugin.cc:1308
ViewControlPlugin::translate
void translate(Vector _vec, int _viewer=PluginFunctions::ALL_VIEWERS)
translate Scene
Definition: ViewControlPlugin.cc:1244
ViewControlPlugin::modelingAreasVisible
bool modelingAreasVisible(int _id)
For meshes returns if the modeling areas for this object is visible.
Definition: ViewControlPlugin.cc:443
ViewControlPlugin::viewAll
void viewAll()
Change View on all viewers to view whole scene.
Definition: ViewControlPlugin.cc:1382
ViewControlPlugin::showModelingAreas
void showModelingAreas(int _id, bool _state)
Allows to enable/disable visualization of the objects modeling area for meshes.
Definition: ViewControlPlugin.cc:470
ViewControlPlugin::showSelection
void showSelection(int _id, bool _state)
Allows to enable/disable visualization of the objects selection for meshes.
Definition: ViewControlPlugin.cc:475
ViewControlPlugin::setFOVY
void setFOVY(double _fovy)
Set fovy angle of projection.
Definition: ViewControlPlugin.cc:1415
ViewControlPlugin::selectionVisible
bool selectionVisible(int _id)
For meshes returns if the selection for this object is visible.
Definition: ViewControlPlugin.cc:394
ViewControlPlugin::sceneCenter
Vector sceneCenter(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get the scene center.
Definition: ViewControlPlugin.cc:1324
ViewControlPlugin::rotate
void rotate(Vector _axis, double _angle, Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Rotate Scene.
Definition: ViewControlPlugin.cc:1238
ViewControlPlugin::setSceneCenter
void setSceneCenter(Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the scene center.
Definition: ViewControlPlugin.cc:1320
ViewControlPlugin::setObjectDrawMode
void setObjectDrawMode(QString _mode, int _objectID, bool _force=true)
Set the draw mode for an object.
Definition: ViewControlPlugin.cc:1285
ViewControlPlugin::setDrawMode
void setDrawMode(QString _mode, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the draw mode for a viewer.
Definition: ViewControlPlugin.cc:1266