Developer Documentation
Loading...
Searching...
No Matches
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/pybind11.h>
44#include <pybind11/embed.h>
45
46
47#include <ViewControlPlugin.hh>
48#include <OpenFlipper/BasePlugin/PythonFunctions.hh>
49#include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
50
51namespace py = pybind11;
52
53
54
55PYBIND11_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 view.def("setSelectionLineWidth", &ViewControlPlugin::setSelectionLineWidth,
101 QCoreApplication::translate("PythonDocViewControl","For meshes set the line width of selections.").toLatin1().data(),
102 py::arg(QCoreApplication::translate("PythonDocViewControl","ID of the mesh object").toLatin1().data()),
103 py::arg(QCoreApplication::translate("PythonDocViewControl","Line width to set").toLatin1().data()) );
104
105 view.def("setFeatureLineWidth", &ViewControlPlugin::setFeatureLineWidth,
106 QCoreApplication::translate("PythonDocViewControl","For meshes set the line width of features.").toLatin1().data(),
107 py::arg(QCoreApplication::translate("PythonDocViewControl","ID of the mesh object").toLatin1().data()),
108 py::arg(QCoreApplication::translate("PythonDocViewControl","Line width to set").toLatin1().data()) );
109
110
111// /** Disable the given shader for a given object and draw mode.
112// * @param _objectId ID of the object for which to disable the shader
113// * @param _drawMode _drawMode for which the shader is disabled
114// * @param _shader Shader which is disabled. If this shader is not currently active for
115// * the given _drawMode, nothing will be disabled. In order to disable
116// * all shaders for the given _drawMode, use _shader=0 (default).
117// */
118// void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo* _shader=0);
119//
120// /** Sets a shader for the object and the given drawMode( can be a combination of draw modes )
121// * @param _id Object Id
122// * @param _drawMode ; separated list of drawmodes used by the shader
123// * @param _shader Shader information
124// */
125// void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader);
126
127// /** Sets a Shader for a specific draw mode
128// *
129// * @param _id Object id that should use the shader
130// * @param _drawMode Draw mode where this shader will be active
131// * @param _name Name of the shader that should be used
132// */
133// void setShader(int _id, QString _drawMode, QString _name );
134//
135// /// get information about available uniforms for a given shader
136// QStringList getUniforms(QString _shader);
137//
138// QString getUniformType(QString _shader, QString _uniform );
139// QString getUniformDefault(QString _shader, QString _uniform );
140// QString getUniformMin(QString _shader, QString _uniform );
141// QString getUniformMax(QString _shader, QString _uniform );
142//
143// /// set the value of a uniform in a shader for a specific drawMode
144// void setUniform(int _objID, ACG::SceneGraph::DrawModes::DrawMode _drawMode, QString _shader, QString _uniform, QString _value );
145
146 view.def("setViewingDirection", &ViewControlPlugin::setViewingDirection,
147 QCoreApplication::translate("PythonDocViewControl","Set the viewing direction").toLatin1().data(),
148 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewing Direction").toLatin1().data()),
149 py::arg(QCoreApplication::translate("PythonDocViewControl","Up vector").toLatin1().data()),
150 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to set viewing direction (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
151
152 view.def("setSceneRadius", &ViewControlPlugin::setSceneRadius,
153 QCoreApplication::translate("PythonDocViewControl","Set scene radius").toLatin1().data(),
154 py::arg(QCoreApplication::translate("PythonDocViewControl","Radius").toLatin1().data()),
155 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to set radius (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
156
157 view.def("rotate", &ViewControlPlugin::rotate,
158 QCoreApplication::translate("PythonDocViewControl","Rotate scene").toLatin1().data(),
159 py::arg(QCoreApplication::translate("PythonDocViewControl","Rotation axis").toLatin1().data()),
160 py::arg(QCoreApplication::translate("PythonDocViewControl","Rotation angle").toLatin1().data()),
161 py::arg(QCoreApplication::translate("PythonDocViewControl","Rotation center").toLatin1().data()),
162 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to rotate (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
163
164
165 view.def("translate", &ViewControlPlugin::translate,
166 QCoreApplication::translate("PythonDocViewControl","Translate scene").toLatin1().data(),
167 py::arg(QCoreApplication::translate("PythonDocViewControl","Translation vector").toLatin1().data()),
168 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to translate (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
169
170 view.def("setDrawMode", &ViewControlPlugin::setDrawMode,
171 QCoreApplication::translate("PythonDocViewControl","Set the draw mode of a viewer").toLatin1().data(),
172 py::arg(QCoreApplication::translate("PythonDocViewControl","List of draw modes ( ; separated list ) ").toLatin1().data()),
173 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to set draw mode (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
174
175 view.def("setObjectDrawMode", &ViewControlPlugin::setObjectDrawMode,
176 QCoreApplication::translate("PythonDocViewControl"," This function can be used to set the drawmode for an object.").toLatin1().data(),
177 py::arg(QCoreApplication::translate("PythonDocViewControl","List of draw modes ( ; separated list ) ").toLatin1().data()),
178 py::arg(QCoreApplication::translate("PythonDocViewControl","Object ID to set the drawmode on.").toLatin1().data()),
179 py::arg(QCoreApplication::translate("PythonDocViewControl","Set the draw mode even if its not directly supported by the objects nodes").toLatin1().data()) = true);
180
181 view.def("viewingDirection", &ViewControlPlugin::viewingDirection,
182 QCoreApplication::translate("PythonDocViewControl","Get the current viewing direction").toLatin1().data(),
183 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get viewing direction from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
184
185 view.def("upVector", &ViewControlPlugin::upVector,
186 QCoreApplication::translate("PythonDocViewControl","Get the current upVector").toLatin1().data(),
187 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get upVector from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
188
189 view.def("eyePosition", &ViewControlPlugin::eyePosition,
190 QCoreApplication::translate("PythonDocViewControl","Get the current eyePosition").toLatin1().data(),
191 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get eyePosition from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
192
193 view.def("sceneCenter", &ViewControlPlugin::sceneCenter,
194 QCoreApplication::translate("PythonDocViewControl","Get the current sceneCenter").toLatin1().data(),
195 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to get scene center from (Default is the active viewer)?").toLatin1().data()) = PluginFunctions::ACTIVE_VIEWER );
196
197 view.def("setSceneCenter", &ViewControlPlugin::setSceneCenter,
198 QCoreApplication::translate("PythonDocViewControl","Set the scene center").toLatin1().data(),
199 py::arg(QCoreApplication::translate("PythonDocViewControl","Coordinates of center?").toLatin1().data()),
200 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to change (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
201
202 view.def("enableBackfaceCulling", &ViewControlPlugin::enableBackfaceCulling,
203 QCoreApplication::translate("PythonDocViewControl","Enable or disable Backface culling").toLatin1().data(),
204 py::arg(QCoreApplication::translate("PythonDocViewControl","Enable?").toLatin1().data()),
205 py::arg(QCoreApplication::translate("PythonDocViewControl","Viewer id to change (Default is all viewers)?").toLatin1().data()) = PluginFunctions::ALL_VIEWERS );
206
207 view.def("setEyePosition", &ViewControlPlugin::setEyePosition),
208 QCoreApplication::translate("PythonDocViewControl","Change the Eye position to the given value").toLatin1().data(),
209 py::arg(QCoreApplication::translate("PythonDocViewControl","Eye position").toLatin1().data()) ;
210
211 view.def("viewAll", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::viewAll),
212 QCoreApplication::translate("PythonDocViewControl","Change View in all viewers to view whole scene").toLatin1().data());
213 view.def("viewAll", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::viewAll),
214 QCoreApplication::translate("PythonDocViewControl","Change View in given viewer to view whole scene").toLatin1().data(),
215 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer which should be switched").toLatin1().data()) );
216
217 view.def("viewHome", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::viewHome),
218 QCoreApplication::translate("PythonDocViewControl","Change View on all viewers to view home position").toLatin1().data());
219 view.def("viewHome", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::viewHome),
220 QCoreApplication::translate("PythonDocViewControl","Change View on given viewer to view home position").toLatin1().data(),
221 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer to change").toLatin1().data()) );
222
223 view.def("orthographicProjection", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::orthographicProjection),
224 QCoreApplication::translate("PythonDocViewControl","Change all Viewers to orthographic projection").toLatin1().data());
225 view.def("orthographicProjection", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::orthographicProjection),
226 QCoreApplication::translate("PythonDocViewControl","Change Viewer to orthographic projection").toLatin1().data(),
227 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer to change").toLatin1().data()) );
228
229 view.def("perspectiveProjection", static_cast<void (ViewControlPlugin::*)()>(&ViewControlPlugin::orthographicProjection),
230 QCoreApplication::translate("PythonDocViewControl","Change all Viewers to perspective projection").toLatin1().data());
231 view.def("perspectiveProjection", static_cast<void (ViewControlPlugin::*)(int)>(&ViewControlPlugin::orthographicProjection),
232 QCoreApplication::translate("PythonDocViewControl","Change Viewer to perspective projection").toLatin1().data(),
233 py::arg(QCoreApplication::translate("PythonDocViewControl","Id of the viewer to change").toLatin1().data()) );
234
235 view.def("setFOVY", &ViewControlPlugin::setFOVY,
236 QCoreApplication::translate("PythonDocViewControl","Set fovy angle of projection for all viewers.").toLatin1().data(),
237 py::arg(QCoreApplication::translate("PythonDocViewControl","fovy angle").toLatin1().data()) );
238
239 view.def("setCoordsysProjection", &ViewControlPlugin::setCoordsysProjection,
240 QCoreApplication::translate("PythonDocViewControl","Set the projection mode of the coordinate system.").toLatin1().data(),
241 py::arg(QCoreApplication::translate("PythonDocViewControl","If true, orthogonal projection otherwise perspective projection").toLatin1().data()) );
242
243 view.def("setTwoSidedLighting", &ViewControlPlugin::setTwoSidedLighting,
244 QCoreApplication::translate("PythonDocViewControl","Enable or disable two sided lighting.").toLatin1().data(),
245 py::arg(QCoreApplication::translate("PythonDocViewControl","Specifies whether to enable or disable two sided lighting.").toLatin1().data()) );
246
247 view.def("project", &ViewControlPlugin::project,
248 QCoreApplication::translate("PythonDocViewControl","Use the projection matrix of the given viewer to project the point").toLatin1().data(),
249 py::arg(QCoreApplication::translate("PythonDocViewControl","Coordinates of a point").toLatin1().data()),
250 py::arg(QCoreApplication::translate("PythonDocViewControl","ViewerId").toLatin1().data()) = 0 );
251
252//
253// emit setSlotDescription("setObjectDrawMode(QString,int,bool)", "Set the drawMode for an object",
254// QString("DrawMode,ObjectID,Force").split(","),
255// QString("the drawMode ( ; separated list ),Object id,Apply without checking support(default is true)").split(","));
256
257
258}
259
void setSceneCenter(Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the scene center.
void showSelection(int _id, bool _state)
Allows to enable/disable visualization of the objects selection for meshes.
void viewAll()
Change View on all viewers to view whole scene.
void setViewingDirection(Vector _direction, Vector _upvector, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the viewing direction.
void translate(Vector _vec, int _viewer=PluginFunctions::ALL_VIEWERS)
translate Scene
void rotate(Vector _axis, double _angle, Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Rotate Scene.
Vector eyePosition(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers eye Position
void showModelingAreas(int _id, bool _state)
Allows to enable/disable visualization of the objects modeling area for meshes.
Vector upVector(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers up vector
void setFOVY(double _fovy)
Set fovy angle of projection.
void viewHome()
Change View on given Viewer to view home position.
bool selectionVisible(int _id)
For meshes returns if the selection for this object is visible.
ACG::Vec3d project(ACG::Vec3d _point, int _viewerId=0)
Use the projection matrix of the given viewer to project the point.
void setDrawMode(QString _mode, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the draw mode for a viewer.
Vector viewingDirection(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get a viewers viewing direction.
bool modelingAreasVisible(int _id)
For meshes returns if the modeling areas for this object is visible.
void setObjectDrawMode(QString _mode, int _objectID, bool _force=true)
Set the draw mode for an object.
void setFeatureLineWidth(int _id, double _width)
Set the line width of the features.
void setCoordsysProjection(bool _orthogonal)
void setSelectionLineWidth(int _id, double _width)
Set the line width of the selections.
void orthographicProjection()
Change Viewer to orthographicProjection.
void setSceneRadius(double _radius, int _viewer=PluginFunctions::ALL_VIEWERS)
Set scene radius.
void enableBackfaceCulling(bool _state, int _viewer=PluginFunctions::ALL_VIEWERS)
Enable or disable Backface culling.
Vector sceneCenter(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get the scene center.