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 <DataControlPlugin.hh>
48 
49 #include <OpenFlipper/BasePlugin/PythonFunctions.hh>
50 #include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
51 
52 namespace py = pybind11;
53 
54 
55 
56 PYBIND11_EMBEDDED_MODULE(DataControl, m) {
57 
58  QObject* pluginPointer = getPluginPointer("DataControl");
59 
60  if (!pluginPointer) {
61  std::cerr << "Error Getting plugin pointer for Plugin-DataControl" << std::endl;
62  return;
63  }
64 
65  DataControlPlugin* plugin = qobject_cast<DataControlPlugin*>(pluginPointer);
66 
67  if (!plugin) {
68  std::cerr << "Error converting plugin pointer for Plugin-DataControl" << std::endl;
69  return;
70  }
71 
72  // Export our core. Make sure that the c++ worlds core object is not deleted if
73  // the python side gets deleted!!
74  py::class_< DataControlPlugin,std::unique_ptr<DataControlPlugin, py::nodelete> > data(m, "DataControl");
75 
76  // On the c++ side we will just return the existing core instance
77  // and prevent the system to recreate a new core as we need
78  // to work on the existing one.
79  data.def(py::init([plugin]() { return plugin; }));
80 
81 
82  data.def("getObjectName", &DataControlPlugin::getObjectName,
83  QCoreApplication::translate("PythonDocDataControl","Returns the name of an object with given id.").toLatin1().data(),
84  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data()) );
85 
86 
87  data.def("objectDelete", &DataControlPlugin::objectDelete,
88  QCoreApplication::translate("PythonDocDataControl","Delete the given object").toLatin1().data(),
89  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data()));
90 
91  data.def("copyObject", static_cast<int (DataControlPlugin::*)(int)>( &DataControlPlugin::copyObject),
92  QCoreApplication::translate("PythonDocDataControl","Create a copy of an object and return the id of the new object").toLatin1().data(),
93  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object to copy").toLatin1().data()));
94 
95  data.def("getObject", &DataControlPlugin::getObject,
96  QCoreApplication::translate("PythonDocDataControl","Returns the id of an object with given name.").toLatin1().data()),
97  py::arg(QCoreApplication::translate("PythonDocDataControl","Name of an object").toLatin1().data());
98 
99  data.def("dataType", &DataControlPlugin::dataType,
100  QCoreApplication::translate("PythonDocDataControl","Returns the DataType of the object with the given id.").toLatin1().data()),
101  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data());
102 
103  data.def("hideObject", &DataControlPlugin::hideObject,
104  QCoreApplication::translate("PythonDocDataControl","Hide object with the given id.").toLatin1().data()),
105  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data());
106 
107  data.def("showObject", &DataControlPlugin::showObject,
108  QCoreApplication::translate("PythonDocDataControl","Show object with the given id.").toLatin1().data()),
109  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data());
110 
111  data.def("setTarget", &DataControlPlugin::setTarget,
112  QCoreApplication::translate("PythonDocDataControl","Set given object as target.").toLatin1().data()),
113  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data()),
114  py::arg(QCoreApplication::translate("PythonDocDataControl","Mark as target?").toLatin1().data());
115 
116  data.def("setSource", &DataControlPlugin::setSource,
117  QCoreApplication::translate("PythonDocDataControl","Set given object as source.").toLatin1().data()),
118  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data()),
119  py::arg(QCoreApplication::translate("PythonDocDataControl","Mark as target?").toLatin1().data());
120 
121  data.def("setObjectName", &DataControlPlugin::setObjectName,
122  QCoreApplication::translate("PythonDocDataControl","Set the name of the given object").toLatin1().data()),
123  py::arg(QCoreApplication::translate("PythonDocDataControl","ID of the object").toLatin1().data()),
124  py::arg(QCoreApplication::translate("PythonDocDataControl","New name").toLatin1().data());
125 
126  data.def("setAllTarget", &DataControlPlugin::setAllTarget,
127  QCoreApplication::translate("PythonDocDataControl","Set All objects as targets").toLatin1().data());
128 
129  data.def("setAllSource", &DataControlPlugin::setAllSource,
130  QCoreApplication::translate("PythonDocDataControl","Set All objects as source").toLatin1().data());
131 
132 
133  data.def("clearAllTarget", &DataControlPlugin::clearAllTarget,
134  QCoreApplication::translate("PythonDocDataControl","Clear targets").toLatin1().data());
135 
136  data.def("clearAllSource", &DataControlPlugin::clearAllSource,
137  QCoreApplication::translate("PythonDocDataControl","Clear sources").toLatin1().data());
138 
139  data.def("showAll", &DataControlPlugin::showAll,
140  QCoreApplication::translate("PythonDocDataControl","Show All objects").toLatin1().data());
141 
142  data.def("hideAll", &DataControlPlugin::hideAll,
143  QCoreApplication::translate("PythonDocDataControl","Hide all objects").toLatin1().data());
144 
145  data.def("addEmptyGroup", &DataControlPlugin::addEmptyGroup,
146  QCoreApplication::translate("PythonDocDataControl","Create new empty group. Returns the id of the new group.").toLatin1().data(),
147  py::arg(QCoreApplication::translate("PythonDocDataControl","Name of the new group").toLatin1().data()),
148  py::arg(QCoreApplication::translate("PythonDocDataControl","Parent group (Defaults to top level)").toLatin1().data() ) = 0) ;
149 
150  data.def("groupObjects", &DataControlPlugin::groupObjects,
151  QCoreApplication::translate("PythonDocDataControl","Group objects together. Return id of the new group or -1 on error").toLatin1().data(),
152  py::arg(QCoreApplication::translate("PythonDocDataControl","List of objects to be added to the group").toLatin1().data()),
153  py::arg(QCoreApplication::translate("PythonDocDataControl","Name of the new group").toLatin1().data() ) = "") ;
154 
155  data.def("addObjectToGroup", &DataControlPlugin::addObjectToGroup,
156  QCoreApplication::translate("PythonDocDataControl","Add an Object to an existing group").toLatin1().data(),
157  py::arg(QCoreApplication::translate("PythonDocDataControl","Id of an object").toLatin1().data()),
158  py::arg(QCoreApplication::translate("PythonDocDataControl","Group id").toLatin1().data() ) ) ;
159 
160  data.def("unGroupObject", &DataControlPlugin::unGroupObject,
161  QCoreApplication::translate("PythonDocDataControl","Remove the given object from its group and move it to the top level").toLatin1().data(),
162  py::arg(QCoreApplication::translate("PythonDocDataControl","Id of an Object").toLatin1().data()) ) ;
163 
164  data.def("getTargetObjects", &DataControlPlugin::getTargetObjects,
165  QCoreApplication::translate("PythonDocDataControl","Returns the IdList of all target objects with given DataType.").toLatin1().data(),
166  py::arg(QCoreApplication::translate("PythonDocDataControl","DataType of the target objects").toLatin1().data()) ) ;
167 
168  data.def("getSourceObjects", &DataControlPlugin::getSourceObjects,
169  QCoreApplication::translate("PythonDocDataControl","Returns the IdList of all source objects with given DataType.").toLatin1().data(),
170  py::arg(QCoreApplication::translate("PythonDocDataControl","DataType of the target objects").toLatin1().data()) ) ;
171 
172  data.def("groupCount", &DataControlPlugin::groupCount,
173  QCoreApplication::translate("PythonDocDataControl","Returns the number of groups").toLatin1().data() ) ;
174 
175  data.def("availableDataTypeNames", &DataControlPlugin::availableDataTypeNames,
176  QCoreApplication::translate("PythonDocDataControl","Returns a QStringList of all available DataType names.").toLatin1().data() ) ;
177 
178  data.def("printObjectInfoToLog", &DataControlPlugin::printObjectInfoToLog,
179  QCoreApplication::translate("PythonDocDataControl","Print information about all open objects to the console").toLatin1().data() ) ;
180 
181  data.def("getGroupElements", &DataControlPlugin::getGroupElements,
182  QCoreApplication::translate("PythonDocDataControl","Get all elements of the given group").toLatin1().data(),
183  py::arg(QCoreApplication::translate("PythonDocDataControl","Id of a group").toLatin1().data()) ) ;
184 
185  data.def("showReducedUi", &DataControlPlugin::showReducedUi,
186  QCoreApplication::translate("PythonDocDataControl","Show or hide the extended ui interface in the datacontrol toolbox").toLatin1().data(),
187  py::arg(QCoreApplication::translate("PythonDocDataControl","Show?").toLatin1().data()) ) ;
188 
189 }
190 
void hideAll()
Hides all objects.
IdList getSourceObjects(DataType _type)
Get all source objects of given type.
void hideObject(int objectId)
Hide the given Object.
void showAll()
Shows all objects.
int groupObjects(IdList _objectIDs, QString _groupName="")
Group given Objects together.
void setSource(int objectId, bool _source)
set the given Object as source
bool addObjectToGroup(int _objectId, int _groupId)
add an object to an existing group
void setTarget(int objectId, bool _target)
set the given Object as target
IdList getTargetObjects(DataType _type)
Get all target objects of given type.
void clearAllTarget()
Unselect all objects.
void setAllTarget()
Makes all available objects target.
void showReducedUi(bool reduced)
Show or hide the extended ui interface in the datacontrol toolbox.
QString getObjectName(int objectId)
Get the Objects name from the id.
void setAllSource()
Makes all available objects source.
unsigned int groupCount() const
Returns the number of groups.
DataType dataType(int objectId)
Get the DataType of a given object.
IdList getGroupElements(int _groupId)
Get all elements of the given group.
void printObjectInfoToLog()
Print information about all open objects to the console.
void objectDelete(int objectId)
Delete the given object.
int getObject(QString _name)
Get the id of an object by its name.
void clearAllSource()
remove source selection from all objects
void setObjectName(int objectId, QString _name)
set the name of the given object
int addEmptyGroup(QString _groupName="", int _parentGroupId=0)
Create new empty group.
QString availableDataTypeNames() const
Returns a list of all available DataTypes.
void showObject(int objectId)
Show the given Object.