Developer Documentation
Loading...
Searching...
No Matches
Python.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43#include <pybind11/pybind11.h>
44#include <pybind11/embed.h>
45
46
47#include <MovePlugin.hh>
48#include <OpenFlipper/BasePlugin/PythonFunctions.hh>
49#include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
50
51namespace py = pybind11;
52
53PYBIND11_EMBEDDED_MODULE(Move, m) {
54
55 QObject* pluginPointer = getPluginPointer("Move");
56
57 if (!pluginPointer) {
58 std::cerr << "Error Getting plugin pointer for Plugin-Move" << std::endl;
59 return;
60 }
61
62 MovePlugin* plugin = qobject_cast<MovePlugin*>(pluginPointer);
63
64 if (!plugin) {
65 std::cerr << "Error converting plugin pointer for Plugin-Move" << std::endl;
66 return;
67 }
68
69 // Export our core. Make sure that the c++ worlds core object is not deleted if
70 // the python side gets deleted!!
71 py::class_< MovePlugin,std::unique_ptr<MovePlugin, py::nodelete> > move(m, "Move");
72
73 // On the c++ side we will just return the existing core instance
74 // and prevent the system to recreate a new core as we need
75 // to work on the existing one.
76 move.def(py::init([plugin]() { return plugin; }));
77
78 move.def("moveToOrigin", &MovePlugin::slotMoveToOrigin,
79 QCoreApplication::translate("PythonDocMove","Move all target Meshes cog to the origin").toLatin1().data() );
80
81 move.def("unifyBoundingBoxDiagonal", &MovePlugin::slotUnifyBoundingBoxDiagonal,
82 QCoreApplication::translate("PythonDocMove","Unify bounding box diagonal of all target meshes").toLatin1().data() );
83
84 move.def("unifyBoundingBoxLongestAxis", &MovePlugin::slotUnifyBoundingBoxLongestAxis,
85 QCoreApplication::translate("PythonDocMove","Scale bounding box of all target meshes such that longest axis has unit size (keeps aspect ratio)").toLatin1().data() );
86
87 move.def("unifyBoundingBoxAllAxis", &MovePlugin::slotUnifyBoundingBoxAllAxis,
88 QCoreApplication::translate("PythonDocMove","Scale bounding box of all target meshes such that all axis have unit size").toLatin1().data() );
89
90 move.def("translate", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translate),
91 QCoreApplication::translate("PythonDocMove","Translate object by given vector.").toLatin1().data(),
92 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
93 py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
94
95 move.def("translate", static_cast<void (MovePlugin::*)(int,IdList,Vector)>(&MovePlugin::translate),
96 QCoreApplication::translate("PythonDocMove","Translate vertices of an object by given vector.").toLatin1().data(),
97 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
98 py::arg(QCoreApplication::translate("PythonDocMove","List of vertex indices to be moved").toLatin1().data()),
99 py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
100
101 move.def("translateVertexSelection", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translateVertexSelection),
102 QCoreApplication::translate("PythonDocMove","Translate current vertex selection of an object by given vector.").toLatin1().data(),
103 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
104 py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
105
106
107
108 move.def("translateFaceSelection", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translateFaceSelection),
109 QCoreApplication::translate("PythonDocMove","Translate current face selection of an object by given vector.").toLatin1().data(),
110 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
111 py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
112
113 move.def("translateEdgeSelection", static_cast<void (MovePlugin::*)(int,Vector)>(&MovePlugin::translateEdgeSelection),
114 QCoreApplication::translate("PythonDocMove","Translate current edge selection of an object by given vector.").toLatin1().data(),
115 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
116 py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
117
118 move.def("transform", static_cast<void (MovePlugin::*)(int,Matrix4x4)>(&MovePlugin::transform),
119 QCoreApplication::translate("PythonDocMove","Transform an object with a 4x4 matrix").toLatin1().data(),
120 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
121 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
122
123 move.def("transform", static_cast<void (MovePlugin::*)(int,IdList,Matrix4x4)>(&MovePlugin::transform),
124 QCoreApplication::translate("PythonDocMove","Transform an object with a 4x4 matrix").toLatin1().data(),
125 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
126 py::arg(QCoreApplication::translate("PythonDocMove","List of vertex handles to move").toLatin1().data()),
127 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
128
129 move.def("transformVertexSelection", static_cast<bool (MovePlugin::*)(int,Matrix4x4)>(&MovePlugin::transformVertexSelection),
130 QCoreApplication::translate("PythonDocMove","Transform selected vertices by given matrix.").toLatin1().data(),
131 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
132 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
133
134
135 move.def("transformFaceSelection", static_cast<bool (MovePlugin::*)(int,Matrix4x4)>(&MovePlugin::transformFaceSelection),
136 QCoreApplication::translate("PythonDocMove","Transform selected faces by given matrix.").toLatin1().data(),
137 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
138 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
139
140 move.def("transformEdgeSelection", static_cast<bool (MovePlugin::*)(int,Matrix4x4)>(&MovePlugin::transformEdgeSelection),
141 QCoreApplication::translate("PythonDocMove","Transform selected edges by given matrix.").toLatin1().data(),
142 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
143 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
144
145 move.def("transformCellSelection", static_cast<bool (MovePlugin::*)(int,Matrix4x4)>(&MovePlugin::transformCellSelection),
146 QCoreApplication::translate("PythonDocMove","Transform selected cells by given matrix.").toLatin1().data(),
147 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
148 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
149
150 move.def("transformHandleRegion", static_cast<void (MovePlugin::*)(int,Matrix4x4)>(&MovePlugin::transformHandleRegion),
151 QCoreApplication::translate("PythonDocMove","Transform handle region by given matrix.").toLatin1().data(),
152 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
153 py::arg(QCoreApplication::translate("PythonDocMove","Transformation matrix").toLatin1().data()) );
154
155 move.def("setManipulatorPosition", &MovePlugin::setManipulatorPosition,
156 QCoreApplication::translate("PythonDocMove","Set the position of the manipulator.").toLatin1().data(),
157 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
158 py::arg(QCoreApplication::translate("PythonDocMove","3D position").toLatin1().data()) );
159
160 move.def("manipulatorPosition", &MovePlugin::manipulatorPosition,
161 QCoreApplication::translate("PythonDocMove","Get the position of the manipulator.").toLatin1().data(),
162 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
163
164 move.def("setManipulatorDirection", &MovePlugin::setManipulatorDirection,
165 QCoreApplication::translate("PythonDocMove","Set the direction of the manipulator.").toLatin1().data(),
166 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
167 py::arg(QCoreApplication::translate("PythonDocMove","X-Axis direction").toLatin1().data()),
168 py::arg(QCoreApplication::translate("PythonDocMove","Y-Axis direction").toLatin1().data()));
169
170 move.def("manipulatorDirectionX", &MovePlugin::manipulatorDirectionX,
171 QCoreApplication::translate("PythonDocMove","Get the x-direction of an object's manipulator.").toLatin1().data(),
172 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
173
174 move.def("manipulatorDirectionY", &MovePlugin::manipulatorDirectionY,
175 QCoreApplication::translate("PythonDocMove","Get the y-direction of an object's manipulator.").toLatin1().data(),
176 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
177
178 move.def("manipulatorDirectionZ", &MovePlugin::manipulatorDirectionZ,
179 QCoreApplication::translate("PythonDocMove","Get the z-direction of an object's manipulator.").toLatin1().data(),
180 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
181
182 move.def("objectRenderingMatrixIdentity", &MovePlugin::objectRenderingMatrixIdentity,
183 QCoreApplication::translate("PythonDocMove","Resets the objects rendering matrix to identity.").toLatin1().data(),
184 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()) );
185
186 move.def("objectRenderingMatrixScale", &MovePlugin::objectRenderingMatrixScale,
187 QCoreApplication::translate("PythonDocMove","Adds a scaling factor to the Object rendering Matrix in the scenegraph.").toLatin1().data(),
188 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
189 py::arg(QCoreApplication::translate("PythonDocMove","scaling factor").toLatin1().data()) );
190
191 move.def("objectRenderingMatrixTranslate", &MovePlugin::objectRenderingMatrixTranslate,
192 QCoreApplication::translate("PythonDocMove","Adds a translation to the Object rendering Matrix in the scenegraph.").toLatin1().data(),
193 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
194 py::arg(QCoreApplication::translate("PythonDocMove","Translation vector").toLatin1().data()) );
195
196 move.def("objectRenderingMatrixRotate", &MovePlugin::objectRenderingMatrixRotate,
197 QCoreApplication::translate("PythonDocMove","Adds a rotation to the Object rendering Matrix in the scenegraph.").toLatin1().data(),
198 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()),
199 py::arg(QCoreApplication::translate("PythonDocMove","Rotation axis").toLatin1().data()),
200 py::arg(QCoreApplication::translate("PythonDocMove","Rotation angle").toLatin1().data()) );
201
202 move.def("getObjectRenderingMatrix", &MovePlugin::getObjectRenderingMatrix,
203 QCoreApplication::translate("PythonDocMove","Returns the current object transformation matrix from the Scenegraph.").toLatin1().data(),
204 py::arg(QCoreApplication::translate("PythonDocMove","ID of an object").toLatin1().data()));
205
206}
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition DataTypes.hh:181
void objectRenderingMatrixTranslate(int _objectId, Vector _translation)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
void translateEdgeSelection(int _objectId, Vector _vector)
translate current edge selection of an Object by a given vector
void slotUnifyBoundingBoxAllAxis()
Scale all Boundingbox axis to unit size.
void slotUnifyBoundingBoxLongestAxis()
Scale Boundingbox longest axis to unit size (keeps aspect ratio)
void objectRenderingMatrixIdentity(int _objectId)
Sets the Object Matrix in the scenegraph to identity.
Vector manipulatorDirectionX(int _objectId)
Get the x-direction of the manipulator.
bool transformCellSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
void slotUnifyBoundingBoxDiagonal()
Scale Boundingbox Diagonal to unit size.
void translate(int _objectId, Vector _vector)
translate an Object by a given vector
Matrix4x4 getObjectRenderingMatrix(int _objectId)
Gets the Object Matrix in the scenegraph.
Vector manipulatorPosition(int _objectId)
Get the position of the manipulator.
void objectRenderingMatrixRotate(int _objectId, Vector _axis, double _angle)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
void objectRenderingMatrixScale(int _objectId, double _s)
Adds a scaling factor to the Object rendering Matrix in the scenegraph.
bool transformVertexSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
Vector manipulatorDirectionY(int _objectId)
Get the y-direction of the manipulator.
bool transformEdgeSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
Vector manipulatorDirectionZ(int _objectId)
Get the z-direction of the manipulator.
void translateFaceSelection(int _objectId, Vector _vector)
translate current face selection of an Object by a given vector
void setManipulatorPosition(int _objectId, Vector _position)
Set the position of the manipulator.
void setManipulatorDirection(int _objectId, Vector _directionX, Vector _directionY)
Set the direction of the manipulator.
void transformHandleRegion(int _objectId, Matrix4x4 _matrix)
Transform handle region using the given transformation matrix.
void translateVertexSelection(int _objectId, Vector _vector)
translate current vertex selection of an Object by a given vector
void transform(int _objectId, Matrix4x4 _matrix)
transform an Object by a given matrix
bool transformFaceSelection(int _objectId, Matrix4x4 _matrix)
transform current selection of an Object by a given matrix
void slotMoveToOrigin()
Move target Meshes cog to the origin.