PythonInterpreter.cc 40 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
*                                                                            *
\*===========================================================================*/

42
#define PYTHON_DEBUG true
43
44
45

#include <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
46
#include <pybind11/include/pybind11/numpy.h>
47
48
49
50
51
52


#include "PyLogHook.h"

#include "PythonInterpreter.hh"

53
54
55
#include <QMetaObject>
#include <QMetaMethod>

56
57
#include "PythonTypeConversions.hh"

58
59
#include <OpenFlipper/BasePlugin/PythonFunctionsCore.hh>

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace py = pybind11;

static Core* core_;

static pybind11::module mainModule_;

static PythonInterpreter* interpreter_ = nullptr;

/** \brief Stores a clean dictionary for interpreter reset
 *
 */
static PyObject* global_dict_clean_ = nullptr;


void setCorePointer( Core* _core ) {
  core_ = _core;
}

PythonInterpreter* PythonInterpreter::getInstance() {

  if (interpreter_ == nullptr)
  {
    interpreter_ = new PythonInterpreter();
  }

  return interpreter_;

}

89
PythonInterpreter::PythonInterpreter() :
90
    externalLogging_(true)
91
{
92
93
94
95
96
97
98
99
100
101
102
103
104

}

PythonInterpreter::~PythonInterpreter() {

}

bool PythonInterpreter::modulesInitialized() {
  ///@TODO: Why does this work?
  return static_cast<bool>(mainModule_);
}

void PythonInterpreter::initPython() {
Jan Möbius's avatar
Jan Möbius committed
105
106
107
108
109

  if (Py_IsInitialized()  ) {
    #ifdef PYTHON_DEBUG
      std::cerr << "Python already Initialized!" << std::endl;
    #endif
110
    return;
Jan Möbius's avatar
Jan Möbius committed
111
112
113
114
115
  }

  #ifdef PYTHON_DEBUG
    std::cerr << "Initialize interpreter ... " ;
  #endif
116
117
118

  py::initialize_interpreter();

Jan Möbius's avatar
Jan Möbius committed
119
120
121
122
  #ifdef PYTHON_DEBUG
     std::cerr << " Done" << std::endl;
     std::cerr << "Initialize Threads ...";
  #endif
123
124
125

  PyEval_InitThreads();

Jan Möbius's avatar
Jan Möbius committed
126
127
128
  #ifdef PYTHON_DEBUG
     std::cerr << " Done" << std::endl;
  #endif
129
130

  if (!modulesInitialized()) {
131
    #ifdef PYTHON_DEBUG
Jan Möbius's avatar
Jan Möbius committed
132
      std::cerr << "Import __main__" ;
133
    #endif
134
135
136
137

    //dlopen("libpython3.5m.so.1.0", RTLD_LAZY | RTLD_GLOBAL);
    py::module main{ py::module::import("__main__") };

138
139
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
140
      std::cerr << "Redirect Outputs ...";
141
142
143
    #endif

    // Redirect python output to integrated logger functions
144
145
146
    tyti::pylog::redirect_stderr([this](const char*w) {this->pyError(w); });
    tyti::pylog::redirect_stdout([this](const char* w) {this->pyOutput(w); });

147
148
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
149
      std::cerr << "Get __dict__ from  main namespace ...";
150
    #endif
151

152
153
154
    // =========================================================
    // Add OpenFlipper Core module to main namespace
    // =========================================================
155
156
    py::object main_namespace = main.attr("__dict__");

157
158
159
160
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
      std::cerr << "Importing OpenFlipper core module ...";
    #endif
161
162
163
164

    py::module of_module(py::module::import("openflipper"));
    main_namespace["openflipper"] = of_module;

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
    #endif

    // =========================================================
    // Import with python interface to main namespace
    // =========================================================

    QStringList pythonPlugins = getPythonPlugins();

    for ( int i = 0 ; i < pythonPlugins.size() ; ++i ) {

      #ifdef PYTHON_DEBUG
        std::cerr << "Importing "+ pythonPlugins[i].toStdString() + " module ...";
      #endif

      py::module om_module(py::module::import(pythonPlugins[i].toStdString().c_str()));
      main_namespace[pythonPlugins[i].toStdString().c_str()] = om_module;

      #ifdef PYTHON_DEBUG
        std::cerr << " Done" << std::endl;
      #endif
    }

    #ifdef PYTHON_DEBUG
      std::cerr << "Copy dict ...";
    #endif
192
193
194

    global_dict_clean_ = PyDict_Copy(PyModule_GetDict(main.ptr()));

195
196
197
198
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
      std::cerr << "Set to validate state ...";
    #endif
199
200
201
202

    // set the main module member to a validate state, shows, that all modules are successfully initialized
    mainModule_ = std::move(main);

203
204
205
206
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
      std::cerr << "Save thread ...";
    #endif
207
208
209
210

    // Do not release the GIL until all modules are initalzed
    PyEval_SaveThread();

211
212
213
214
    #ifdef PYTHON_DEBUG
      std::cerr << " Done" << std::endl;
    #endif

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

  }

}

void PythonInterpreter::resetInterpreter()
{
    if (!Py_IsInitialized() || !modulesInitialized())
        return;

    PyGILState_STATE state = PyGILState_Ensure();
    PyObject* dict = PyModule_GetDict(mainModule_.ptr());
    PyDict_Clear(dict);
    PyDict_Update(dict, global_dict_clean_);
    PyGILState_Release(state);
}


bool PythonInterpreter::runScript(QString _script) {

235
#ifdef PYTHON_DEBUG
236
  std::cerr << "runScript" << std::endl;
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#endif

  //============================================================
  // Prepend module instance getter to the script
  //============================================================

  _script.prepend("core = openflipper.Core()\n");

  QStringList pythonPlugins = getPythonPlugins();

  for ( int i = 0 ; i < pythonPlugins.size() ; ++i ) {
      QString import = pythonPlugins[i].toLower() + " = " + pythonPlugins[i] + "." + pythonPlugins[i] + "()\n";
      _script.prepend(import);
  }
251

Jan Möbius's avatar
Jan Möbius committed
252
  // Try to initialize python system
253
254
  try
  {
Jan Möbius's avatar
Jan Möbius committed
255
256
257
258
259

    #ifdef PYTHON_DEBUG
      std::cerr << "Initialize Python" << std::endl;
    #endif

260
    initPython();
Jan Möbius's avatar
Jan Möbius committed
261
262
263
264

    #ifdef PYTHON_DEBUG
      std::cerr << "Done initializing Python" << std::endl;
    #endif
265
266
267
268
269
270
271
272
  }
  catch (py::error_already_set &e)
  {
    pyError(e.what());
    return false;
  }

  PyGILState_STATE state = PyGILState_Ensure();
Jan Möbius's avatar
Jan Möbius committed
273
  //PyThreadState* tstate = PyGILState_GetThisThreadState();
274
275
276
277
278
279
280
281

  auto locals = mainModule_.attr("__dict__");

  bool result = true;

  try
  {

282
283
284
    std::cerr << "Now executing script:" << std::endl;
    std::cerr << _script.toStdString() << std::endl;

285
    py::exec(_script.toStdString(), py::globals(), locals);
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

    std::cerr << "Finished successfully" << std::endl;
  }
  catch (py::error_already_set &e)
  {
    pyError(e.what());
    e.restore();
    result = false;
  }
  catch (const std::runtime_error &e)
  {
    pyError(e.what());
    pyOutput("Restarting Interpreter.");
    resetInterpreter();
    result = false;
    state = PyGILState_Ensure();
  }

  PyGILState_Release(state);

  return result;
}

309
310
311
312
313
314
315
316
QString PythonInterpreter::runScriptOutput(QString _script) {
  LogOut.clear();
  LogErr.clear();
  externalLogging_ = false;
  runScript(_script);
  externalLogging_ = true;
  return LogOut + LogErr;
}
317
318
319
320
321


// Python callback functions
void PythonInterpreter::pyOutput(const char* w)
{
322
  if (externalLogging_) {
323
    emit log(LOGOUT, QString(w));
324
325
326
  } else {
    LogOut += QString::fromUtf8(w);
  }
327
328
329
330
}

void PythonInterpreter::pyError(const char* w)
{
331
  if (externalLogging_) {
332
333
334
335
    if (OpenFlipper::Options::nogui()) {
      std::cerr << "Python Error! " << w << std::endl;
      exit(1);
    }
336
    emit log(LOGERR, QString(w));
337
338
339
  } else {
    LogErr += QString::fromUtf8(w);
  }
340
341
}

342

343
344


345
346
PYBIND11_EMBEDDED_MODULE(openflipper, m) {

347
348
  // Export our core. Make sure that the c++ worlds core objet is not deleted if
  // the python side gets deleted!!
349
  py::class_<Core,std::unique_ptr<Core, py::nodelete>> core(m, "Core");
350
351
352
353
354
355

  // On the c++ side we will just return the existing core instance
  // and prevent the system to recreate a new core as we need
  // to work on the existing one.
  core.def(py::init([]() { return core_; }));

356
357
358
359
360
361
362
  core.def("updateView", &Core::updateView, QCoreApplication::translate("PythonDocCore","Redraw the contents of the viewer.").toLatin1().data() );
  core.def("blockScenegraphUpdates", &Core::blockScenegraphUpdates, QCoreApplication::translate("PythonDocCore","Disable Scenegraph Updates (e.g. before loading or adding a large number of files)").toLatin1().data() );
  core.def("updateUI", &Core::updateUI, QCoreApplication::translate("PythonDocCore","Process events during script execution to keep the ui alive").toLatin1().data() );
  core.def("clearAll", &Core::clearAll, QCoreApplication::translate("PythonDocCore","Clear all data objects.").toLatin1().data() );
  core.def("deleteObject", &Core::deleteObject, QCoreApplication::translate("PythonDocCore","Delete an object from the scene.").toLatin1().data() ,
                                       py::arg( QCoreApplication::translate("PythonDocCore","Id of the object to delete.").toLatin1().data() ) );

363
364
365
366
367
368
369
370
371
372
373
  core.def("setObjectComment", &Core::setObjectComment, QCoreApplication::translate("PythonDocCore","Add a comment to an object (saved e.g. in screenshot metadata).").toLatin1().data()) ,
                                               py::arg( QCoreApplication::translate("PythonDocCore","Id of the object to add comment.").toLatin1().data()),
                                               py::arg( QCoreApplication::translate("PythonDocCore","Key value").toLatin1().data()),
                                               py::arg( QCoreApplication::translate("PythonDocCore","Actual comment").toLatin1().data());

  core.def("clearObjectComment", &Core::clearObjectComment, QCoreApplication::translate("PythonDocCore","Remove a comment from an object.").toLatin1().data()) ,
                                                   py::arg( QCoreApplication::translate("PythonDocCore","Id of the object to remove comment from.").toLatin1().data()),
                                                   py::arg( QCoreApplication::translate("PythonDocCore","Key value to remove").toLatin1().data());

  core.def("clearAllComments", &Core::clearObjectComment, QCoreApplication::translate("PythonDocCore","Remove all comments from an object.").toLatin1().data()) ,
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Id of the object to remove comments from.").toLatin1().data());
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

  core.def("fullscreen", &Core::fullscreen, QCoreApplication::translate("PythonDocCore","Enable or disable fullscreen mode.").toLatin1().data() ,
                                   py::arg( QCoreApplication::translate("PythonDocCore","Enable or disable?").toLatin1().data() ) );

  core.def("showViewModeControls", &Core::deleteObject, QCoreApplication::translate("PythonDocCore","Show or hide the view mode control box").toLatin1().data() ,
                                               py::arg( QCoreApplication::translate("PythonDocCore","Visible?").toLatin1().data() ) );

  core.def("loggerState", &Core::loggerState, QCoreApplication::translate("PythonDocCore","Change the logger window state").toLatin1().data() ,
                                     py::arg( QCoreApplication::translate("PythonDocCore","0 = In Scene , 1 = Normal, 2 = Hidden").toLatin1().data() ) );

  core.def("enableOpenMeshErrorLog", &Core::enableOpenMeshErrorLog, QCoreApplication::translate("PythonDocCore","Enable or disable OpenMesh error logging").toLatin1().data() ,
                                                           py::arg( QCoreApplication::translate("PythonDocCore","Enable or Disable").toLatin1().data() ) );

  core.def("showToolbox", &Core::showToolbox, QCoreApplication::translate("PythonDocCore","Show or hide toolbox").toLatin1().data() ,
                                     py::arg( QCoreApplication::translate("PythonDocCore","Visible?").toLatin1().data() ) );

  core.def("showStatusBar", &Core::showStatusBar, QCoreApplication::translate("PythonDocCore","Show or hide status bar").toLatin1().data() ,
                                         py::arg( QCoreApplication::translate("PythonDocCore","Visible?").toLatin1().data() ) );

  core.def("multiViewMode", &Core::multiViewMode, QCoreApplication::translate("PythonDocCore","Switch MultiView Mode").toLatin1().data() ,
                                         py::arg( QCoreApplication::translate("PythonDocCore","0: One Viewer, 1: Double Viewer, 2: Grid, 3: Horizontal split").toLatin1().data() ) );

  core.def("restrictFrameRate", &Core::restrictFrameRate, QCoreApplication::translate("PythonDocCore","Restrict maximal rendering FrameRate to MaxFrameRate").toLatin1().data() ,
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Restrict Framerate?").toLatin1().data() ) );

  core.def("setMaxFrameRate", &Core::setMaxFrameRate, QCoreApplication::translate("PythonDocCore","Set the maximal framerate (automatically enables framerate restriction)").toLatin1().data() ,
                                             py::arg( QCoreApplication::translate("PythonDocCore","Maximum frameRate").toLatin1().data() ) );

  core.def("snapshotBaseFileName", &Core::snapshotBaseFileName, QCoreApplication::translate("PythonDocCore","Set a base filename for storing snapshots. This setting is viewer dependent").toLatin1().data() ,
                                                       py::arg( QCoreApplication::translate("PythonDocCore","Base filename").toLatin1().data()),
                                                       py::arg( QCoreApplication::translate("PythonDocCore","Viewer ID to set the filename for").toLatin1().data() ) );

  core.def("snapshotFileType", &Core::snapshotFileType, QCoreApplication::translate("PythonDocCore","Set a filetype for storing snapshots.").toLatin1().data() ,
                                               py::arg( QCoreApplication::translate("PythonDocCore","Image type as string (e.g. jpg )").toLatin1().data()),
                                               py::arg( QCoreApplication::translate("PythonDocCore","Viewer ID to set the filetype for").toLatin1().data() ) );

  core.def("snapshotCounterStart", &Core::snapshotCounterStart, QCoreApplication::translate("PythonDocCore","Set the starting number for the snapshot counter.").toLatin1().data() ,
                                                       py::arg( QCoreApplication::translate("PythonDocCore","Starting number for the counter").toLatin1().data() ),
                                                       py::arg( QCoreApplication::translate("PythonDocCore","Viewer ID to set the counter for").toLatin1().data() ) );


  core.def("snapshot", &Core::snapshot, QCoreApplication::translate("PythonDocCore",   "Make a snapshot of the viewer with id viewerId.\n"
                                                                                       "Pass 0 as viewerId parameter to capture the current viewer. \n"
                                                                                       "The captured image will have the specified dimensions. \n"
                                                                                       "If 0 is passed as either width or height parameter, the value will \n"
                                                                                       "automatically be set to hold the right aspect ratio, respectively. \n"
                                                                                       "If 0 is passed for both width and height values, the viewport's current \n"
                                                                                       "dimension is used. Set alpha to true if you want the background to be transparent. \n"
                                                                                       "The fifth parameter is used to hide the coordinate system in the upper right corner of the screen. \n"
                                                                                       "If no filename was set using snapshotBaseFileName() the snapshot is stored \n"
                                                                                       "in snap.png in the current directory. For every snapshot \n"
                                                                                       "a counter is added to the filename.").toLatin1().data() ,
                               py::arg( QCoreApplication::translate("PythonDocCore","Id of viewer").toLatin1().data() ) = 0,
                               py::arg( QCoreApplication::translate("PythonDocCore","Width of image").toLatin1().data() )= 0,
                               py::arg( QCoreApplication::translate("PythonDocCore","Height of image").toLatin1().data() )= 0,
                               py::arg( QCoreApplication::translate("PythonDocCore","Transparent background?").toLatin1().data() ) = false,
                               py::arg( QCoreApplication::translate("PythonDocCore","Hide coordinate system?").toLatin1().data() ) = false ,
                               py::arg( QCoreApplication::translate("PythonDocCore","Number of samples per pixel").toLatin1().data() ) =1  );


  core.def("applicationSnapshot", &Core::applicationSnapshot, QCoreApplication::translate("PythonDocCore","Create a snapshot of the whole application").toLatin1().data() );

  core.def("applicationSnapshotName", &Core::applicationSnapshotName, QCoreApplication::translate("PythonDocCore","Set the baseName for the application snapshot").toLatin1().data() ,
                                                             py::arg( QCoreApplication::translate("PythonDocCore","BaseName for full application snapshots").toLatin1().data() ) );

  core.def("viewerSnapshot", static_cast<void (Core::*)()>(&Core::viewerSnapshot), QCoreApplication::translate("PythonDocCore","Take a snapshot from all viewers").toLatin1().data() );

441
442
443
444
445
446
447
448
449
450
451
452
453
454
  core.def("viewerSnapshot", static_cast<void (Core::*)(QString,bool,bool,bool,bool,int,int,bool,bool,int,bool)>(&Core::viewerSnapshot),
               QCoreApplication::translate("PythonDocCore","Create a snapshot with full control").toLatin1().data(),
               py::arg( QCoreApplication::translate("PythonDocCore","Filename of the snapshot").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Should the comments be written?").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Should only the comments of visible objects be written?").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Should only the comments of target objects be written?").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Store material info?").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Snapshot width").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Snapshot height").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Transparent background?").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Hide coordinate system?").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Multisampling count").toLatin1().data() ),
               py::arg( QCoreApplication::translate("PythonDocCore","Store the view in the metadata?").toLatin1().data() )  );

455
456
457
458
459
460
461
462
463
464
465
466

  core.def("resizeViewers", &Core::resizeViewers, QCoreApplication::translate("PythonDocCore","Resize the examinerViewer.").toLatin1().data() ,
                                                py::arg( QCoreApplication::translate("PythonDocCore","Width").toLatin1().data() ),
                                                py::arg( QCoreApplication::translate("PythonDocCore","Height").toLatin1().data() ) );

  core.def("resizeApplication", &Core::resizeApplication, QCoreApplication::translate("PythonDocCore","Resize the whole Application.").toLatin1().data() ,
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Width").toLatin1().data() ),
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Height").toLatin1().data() ) );

  core.def("writeVersionNumbers", &Core::writeVersionNumbers, QCoreApplication::translate("PythonDocCore","Write the current versions of all plugins to ini file").toLatin1().data() ,
                                                     py::arg( QCoreApplication::translate("PythonDocCore","Full path to a file where the versions should be written to.").toLatin1().data() )  );

467
468
469
//  core.def("objectList", &Core::objectList, QCoreApplication::translate("PythonDocCore","Return an id list of available object that has the given selection and type").toLatin1().data() ,
//                                   py::arg( QCoreApplication::translate("PythonDocCore","Either source or target").toLatin1().data()) ,
//                                   py::arg( QCoreApplication::translate("PythonDocCore","Object types as a stringlist").toLatin1().data() ));
470
471
472
473
474
475
476
477
478
479
480
481
482
483

//     /// return the list of available object that has the given selection and type
//     QList<int> objectList (QString _selection, QStringList _types);

  core.def("blockSceneGraphUpdates", &Core::blockSceneGraphUpdates, QCoreApplication::translate("PythonDocCore","Block the scenegraph updates for improved performance").toLatin1().data() );
  core.def("unblockSceneGraphUpdates", &Core::unblockSceneGraphUpdates, QCoreApplication::translate("PythonDocCore","Unblock the scenegraph updates").toLatin1().data() );


  core.def("setView", &Core::setView, QCoreApplication::translate("PythonDocCore","Set the encoded view for the primary viewport.").toLatin1().data() ,
                             py::arg( QCoreApplication::translate("PythonDocCore","The encoded view. (You can obtain one through \"Copy View\" in the context menu of the coordinates.)").toLatin1().data() )  );

  core.def("setViewAndWindowGeometry", &Core::setViewAndWindowGeometry, QCoreApplication::translate("PythonDocCore","Set the encoded view for the primary viewport and the full geometry of the application").toLatin1().data() ,
                                                               py::arg( QCoreApplication::translate("PythonDocCore","The encoded view. (You can obtain one through \"Copy View\" in the context menu of the coordinates.)").toLatin1().data() )  );

484
485
486
  core.def("addViewModeToolboxes", &Core::addViewModeToolboxes, QCoreApplication::translate("PythonDocCore","Set toolboxes for a viewmode  (This automatically adds the view mode if it does not exist)").toLatin1().data() ,
                                                      py::arg( QCoreApplication::translate("PythonDocCore","Name of the Viewmode").toLatin1().data() ),
                                                      py::arg( QCoreApplication::translate("PythonDocCore","';' separated list of toolboxes visible in this viewmode)").toLatin1().data() ));
487

488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
  core.def("addViewModeToolbars", &Core::addViewModeToolbars, QCoreApplication::translate("PythonDocCore","Set toolbars for a viewmode  (This automatically adds the view mode if it does not exist)").toLatin1().data() ,
                                                     py::arg( QCoreApplication::translate("PythonDocCore","Name of the Viewmode").toLatin1().data() ),
                                                     py::arg( QCoreApplication::translate("PythonDocCore","';' separated list of toolbars visible in this viewmode)").toLatin1().data() ));

  core.def("addViewModeContextMenus", &Core::addViewModeContextMenus, QCoreApplication::translate("PythonDocCore","Set context Menus for a viewmode (This automatically adds the view mode if it does not exist)").toLatin1().data() ,
                                                             py::arg( QCoreApplication::translate("PythonDocCore","Name of the Viewmode").toLatin1().data() ),
                                                             py::arg( QCoreApplication::translate("PythonDocCore","';' separated list of Context Menus visible in this viewmode)").toLatin1().data() ));

  core.def("addViewModeIcon", &Core::addViewModeIcon, QCoreApplication::translate("PythonDocCore","Set Icon for a viewmode (This automatically adds the view mode if it does not exist)").toLatin1().data() ,
                                             py::arg( QCoreApplication::translate("PythonDocCore","Name of the Viewmode").toLatin1().data() ),
                                             py::arg( QCoreApplication::translate("PythonDocCore","filename of the icon (will be taken from OpenFlippers icon directory)").toLatin1().data() ));


  core.def("setToolBoxSide", &Core::setToolBoxSide, QCoreApplication::translate("PythonDocCore","Scripting function to set the side of the main window on which the toolbox should be displayed").toLatin1().data() ,
                                           py::arg( QCoreApplication::translate("PythonDocCore","The desired side of the toolboxes (either 'left' or 'right')").toLatin1().data() ) );

  core.def("setToolBoxActive", &Core::setToolBoxActive, QCoreApplication::translate("PythonDocCore","Activate or deaktivate a toolbox").toLatin1().data() ,
                                               py::arg( QCoreApplication::translate("PythonDocCore","Name of the toolbox.").toLatin1().data() ),
                                               py::arg( QCoreApplication::translate("PythonDocCore","Activate or deaktivate?").toLatin1().data() ));

  core.def("loadObject",  static_cast<int (Core::*)(QString)>(&Core::loadObject), QCoreApplication::translate("PythonDocCore","Load an object specified in file filename. This automatically determines which file plugin to use. It returns the id of the object in the scene or -1 on failure").toLatin1().data() ,
                                                                         py::arg( QCoreApplication::translate("PythonDocCore","Filename to load.").toLatin1().data() )  );

  core.def("startVideoCapture", &Core::startVideoCapture, QCoreApplication::translate("PythonDocCore","Start video capturing.").toLatin1().data() ,
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Basename for capturing").toLatin1().data() ),
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Frames per second").toLatin1().data() ),
                                                 py::arg( QCoreApplication::translate("PythonDocCore","Should the viewers be captured or the whole application?").toLatin1().data() ) );

  core.def("stopVideoCapture", &Core::stopVideoCapture, QCoreApplication::translate("PythonDocCore","Stop video capturing").toLatin1().data() );

  core.def("saveObject",  static_cast<bool (Core::*)(int,QString)>(&Core::saveObject), QCoreApplication::translate("PythonDocCore","Save object to file. If the file exists it will be overwritten.").toLatin1().data() ,
                                                                              py::arg( QCoreApplication::translate("PythonDocCore","Id of the object)").toLatin1().data() ),
                                                                              py::arg( QCoreApplication::translate("PythonDocCore","Complete path and filename").toLatin1().data() ));

  core.def("saveObjectTo",  static_cast<bool (Core::*)(int,QString)>(&Core::saveObjectTo), QCoreApplication::translate("PythonDocCore","Save object to file. The location can be chosen in a dialog. (GUI mode only!)").toLatin1().data() ,
                                                                               py::arg( QCoreApplication::translate("PythonDocCore","Id of the object)").toLatin1().data() ),
                                                                               py::arg( QCoreApplication::translate("PythonDocCore","Initial filename in the dialog").toLatin1().data() ));
525
526
527


//  bool saveObjectsTo( IdList _ids, QString _filename );
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567


  core.def("saveAllObjects", &Core::saveAllObjects, QCoreApplication::translate("PythonDocCore","Saves all target objects. Exising files will be overriden. For new files, a dialog is shown (Only GUI Mode!)").toLatin1().data() );

  core.def("saveAllObjectsTo", &Core::saveAllObjectsTo, QCoreApplication::translate("PythonDocCore","Saves all target objects. The locations can be chosen in dialogs. (Only GUI Mode!)").toLatin1().data() );

  core.def("saveSettings",  static_cast<void (Core::*)()>(&Core::saveSettings), QCoreApplication::translate("PythonDocCore","Show the dialog to save settings. (only works if GUI is available)").toLatin1().data() );

  core.def("saveSettings",  static_cast<void (Core::*)(QString,bool,bool,bool,bool,bool,bool)>(&Core::saveSettings),
      QCoreApplication::translate("PythonDocCore","Save the current setting to the given file.").toLatin1().data(),
      py::arg( QCoreApplication::translate("PythonDocCore","Path of the file to save the settings to.").toLatin1().data() ),
      py::arg( QCoreApplication::translate("PythonDocCore","Save Object information into file?").toLatin1().data() ),
      py::arg( QCoreApplication::translate("PythonDocCore","Restrict to targeted objects?").toLatin1().data() ),
      py::arg( QCoreApplication::translate("PythonDocCore","Save objects into same path as settings file?").toLatin1().data() ),
      py::arg( QCoreApplication::translate("PythonDocCore","Prompt before overwriting files that already exist (gui mode only).").toLatin1().data() ),
      py::arg( QCoreApplication::translate("PythonDocCore","Save program settings?").toLatin1().data() ),
      py::arg( QCoreApplication::translate("PythonDocCore","Save plugin settings?").toLatin1().data() )  );

  core.def("loadObject",  static_cast<void (Core::*)()>(&Core::loadObject), QCoreApplication::translate("PythonDocCore","Show the dialog to load an object. (only works if GUI is available)").toLatin1().data() );

  core.def("loadSettings",  static_cast<void (Core::*)()>(&Core::loadSettings), QCoreApplication::translate("PythonDocCore","Show the dialog to load settings. (only works if GUI is available)").toLatin1().data() );

  core.def("loadSettings",  static_cast<void (Core::*)(QString)>(&Core::loadSettings), QCoreApplication::translate("PythonDocCore","Load settings from file.").toLatin1().data() ,
                                                                              py::arg( QCoreApplication::translate("PythonDocCore","Filename to load.").toLatin1().data() )  );

  core.def("getObjectId",  &Core::getObjectId, QCoreApplication::translate("PythonDocCore","Return identifier of object with specified name. Returns -1 if object was not found.").toLatin1().data() ,
                                      py::arg( QCoreApplication::translate("PythonDocCore","Filename or name of the object").toLatin1().data() )  );

  core.def("deserializeMaterialProperties",  &Core::deserializeMaterialProperties, QCoreApplication::translate("PythonDocCore","Deserialize the supplied material properties into the supplied object.").toLatin1().data() ,
                                                                          py::arg( QCoreApplication::translate("PythonDocCore","Id of the object").toLatin1().data() ),
                                                                          py::arg( QCoreApplication::translate("PythonDocCore","Material properties encoded as string").toLatin1().data() ) );

  core.def("serializeMaterialProperties",  &Core::serializeMaterialProperties, QCoreApplication::translate("PythonDocCore","Serialize and return the material properties of the supplied object.").toLatin1().data() ,
                                                                      py::arg( QCoreApplication::translate("PythonDocCore","Id of the object").toLatin1().data() ));

  core.def("activateToolbox", &Core::activateToolbox, QCoreApplication::translate("PythonDocCore","Expand or collapse a toolbox").toLatin1().data() ,
                                             py::arg( QCoreApplication::translate("PythonDocCore","Name of the plugin to which this toolbox gelongs").toLatin1().data() ),
                                             py::arg( QCoreApplication::translate("PythonDocCore","Name of the toolbox").toLatin1().data() ),
                                             py::arg( QCoreApplication::translate("PythonDocCore","Expand or collapse?").toLatin1().data() ) );

568
  core.def("saveOptions", &Core::saveOptions, QCoreApplication::translate("PythonDocCore","Save the current options to the standard ini file").toLatin1().data() );
569

570
571
  core.def("applyOptions", &Core::applyOptions, QCoreApplication::translate("PythonDocCore","After ini-files have been loaded and core is up or if options have been changed -> apply Options").toLatin1().data() );

572
573
574
575
576
577
  core.def("openIniFile", &Core::openIniFile, QCoreApplication::translate("PythonDocCore","Load information from an ini file").toLatin1().data() ,
                                              py::arg( QCoreApplication::translate("PythonDocCore","Name of the ini file").toLatin1().data() ),
                                              py::arg( QCoreApplication::translate("PythonDocCore","Load applications settings?").toLatin1().data() ),
                                              py::arg( QCoreApplication::translate("PythonDocCore","Load plugin settings?").toLatin1().data() ),
                                              py::arg( QCoreApplication::translate("PythonDocCore"," Load objects defined in the ini file?").toLatin1().data() ));

578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617

//  /** \brief Create an script object from a ui file
//   *
//   * This function will load an ui file, set up a qwidget from that and makes it available
//   * under _objectName for scripting.
//   * @param _objectName The name in scripting environment used for the new object
//   * @param _uiFilename ui file to load
//   */
//  void createWidget(QString _objectName, QString _uiFilename, bool _show = true);

  core.def("setViewMode", &Core::setViewMode, QCoreApplication::translate("PythonDocCore","Switch to the given viewmode").toLatin1().data() ,
                                     py::arg( QCoreApplication::translate("PythonDocCore","Name of the viewmode to enable").toLatin1().data() )  );


  core.def("getCurrentViewMode", &Core::getCurrentViewMode, QCoreApplication::translate("PythonDocCore","Get the name of the current viewMode").toLatin1().data() );

  core.def("setViewModeIcon", &Core::setViewModeIcon, QCoreApplication::translate("PythonDocCore","Set an icon for a view Mode").toLatin1().data() ,
                                               py::arg( QCoreApplication::translate("PythonDocCore","Name of the mode for the icon").toLatin1().data() ),
                                               py::arg( QCoreApplication::translate("PythonDocCore","Filename of the icon").toLatin1().data() )  );

  core.def("moveToolBoxToTop", &Core::moveToolBoxToTop, QCoreApplication::translate("PythonDocCore","Move selected toolbox to the top of side area").toLatin1().data() ,
                                               py::arg( QCoreApplication::translate("PythonDocCore","Name of the Toolbox to be moved").toLatin1().data() )  );

  core.def("moveToolBoxToBottom", &Core::moveToolBoxToBottom, QCoreApplication::translate("PythonDocCore","Move selected toolbox to the bottom of side area").toLatin1().data() ,
                                                     py::arg( QCoreApplication::translate("PythonDocCore","Name of the Toolbox to be moved").toLatin1().data() )  );

  core.def("showReducedMenuBar", &Core::showReducedMenuBar, QCoreApplication::translate("PythonDocCore","Show only a reduced menubar").toLatin1().data() ,
                                                   py::arg( QCoreApplication::translate("PythonDocCore","Reduced Menubar?").toLatin1().data() )  );

  core.def("executePythonScriptFile", &Core::executePythonScriptFile, QCoreApplication::translate("PythonDocCore","Open the given file and execute its contents as a python script").toLatin1().data() ,
                                                             py::arg( QCoreApplication::translate("PythonDocCore","Filename of the script").toLatin1().data() )  );


  core.def("executePythonScript", &Core::executePythonScript, QCoreApplication::translate("PythonDocCore","Execute a text as a python script").toLatin1().data() ,
                                                     py::arg( QCoreApplication::translate("PythonDocCore","The text of the script").toLatin1().data() )  );

  core.def("exitApplication", &Core::exitApplication, QCoreApplication::translate("PythonDocCore","Exit the application").toLatin1().data() );
  core.def("exitFailure", &Core::exitFailure, QCoreApplication::translate("PythonDocCore","Use this function in unit tests, if you detected a failure. Therefore the test functions will recognize that something went wrong.").toLatin1().data() );
  core.def("finishSplash", &Core::finishSplash, QCoreApplication::translate("PythonDocCore","Hide the splash screen").toLatin1().data() );

618
619
620
621
  core.def("objectUpdated", &Core::slotObjectUpdated, QCoreApplication::translate("PythonDocCore","Tell the core that an object has been updated").toLatin1().data(),
                                             py::arg( QCoreApplication::translate("PythonDocCore","ID of the updated object").toLatin1().data() ),
                                             py::arg( QCoreApplication::translate("PythonDocCore","What has been updated? String list separated by ; . Possible update types include: All,Visibility,Geometry,Topology,Selection,VertexSelection,EdgeSelection,HalfedgeSelection,FaceSelection,KnotSelection,Color,Texture,State  ").toLatin1().data() ) = UPDATE_ALL );

622
623
624
625
626

//    //load slots
//    emit setSlotDescription("createWidget(QString,QString)", tr("Create a widget from an ui file"),
//                            QString(tr("Object name,ui file")).split(","),
//                            QString(tr("Name of the new widget in script,ui file to load")).split(","));
627

628
629
//    emit setSlotDescription("objectList(QString,QStringList)", tr("Returns object list"),
//                            QString(tr("Selection type,Object types")).split(","),
630

631

632
633


634
635
}