42#define PYTHON_DEBUG true
44#include <pybind11/pybind11.h>
45#include <pybind11/embed.h>
46#include <pybind11/numpy.h>
51#include "PythonInterpreter.hh"
56#include "PythonTypeConversions.hh"
58#include <OpenFlipper/BasePlugin/PythonFunctionsCore.hh>
60namespace py = pybind11;
62static Core* core_ =
nullptr;
64static pybind11::module* mainModule_ =
nullptr;
71static PyObject* global_dict_clean_ =
nullptr;
74void setCorePointer(
Core* _core ) {
80 if (interpreter_ ==
nullptr)
90 externalLogging_(true)
95PythonInterpreter::~PythonInterpreter() {
101 return static_cast<bool>(mainModule_);
106 if (Py_IsInitialized() ) {
108 std::cerr <<
"Python already Initialized!" << std::endl;
114 std::cerr <<
"Initialize interpreter ... " ;
117 py::initialize_interpreter();
120 std::cerr <<
" Done" << std::endl;
121 std::cerr <<
"[PyInfo] Python " << Py_GetVersion() << std::endl;
122 std::wcerr <<
"[PyInfo] Binary: " << Py_GetProgramFullPath() << std::endl;
123 std::wcerr <<
"[PyInfo] Path: " << Py_GetPath() << std::endl;
124 std::cerr <<
"Initialize Threads ...";
130 std::cerr <<
" Done" << std::endl;
135 std::cerr <<
"Import __main__" ;
139 py::module* main =
new py::module( py::module::import(
"__main__") );
142 std::cerr <<
" Done" << std::endl;
143 std::cerr <<
"Redirect Outputs ...";
149 if ( OpenFlipper::Options::gui() ) {
150 tyti::pylog::redirect_stderr([
this](
const char*w) {this->
pyError(w); });
151 tyti::pylog::redirect_stdout([
this](
const char* w) {this->
pyOutput(w); });
155 std::cerr <<
" Done" << std::endl;
156 std::cerr <<
"Get __dict__ from main namespace ...";
162 py::object main_namespace = main->attr(
"__dict__");
165 std::cerr <<
" Done" << std::endl;
166 std::cerr <<
"Importing OpenFlipper core module ...";
170 py::module of_module(py::module::import(
"openflipper"));
171 main_namespace[
"openflipper"] = of_module;
173 catch (py::error_already_set &e)
180 std::cerr <<
" Done" << std::endl;
187 QStringList pythonPlugins = getPythonPlugins();
189 for (
int i = 0 ; i < pythonPlugins.size() ; ++i ) {
192 std::cerr <<
"Importing "+ pythonPlugins[i].toStdString() +
" module ...";
197 py::module om_module(py::module::import(pythonPlugins[i].toStdString().c_str()));
198 main_namespace[pythonPlugins[i].toStdString().c_str()] = om_module;
200 catch (py::error_already_set &e)
207 std::cerr <<
" Done" << std::endl;
212 std::cerr <<
"Copy dict ...";
215 global_dict_clean_ = PyDict_Copy(PyModule_GetDict(main->ptr()));
218 std::cerr <<
" Done" << std::endl;
219 std::cerr <<
"Set to validate state ...";
226 std::cerr <<
" Done" << std::endl;
246 std::cerr <<
"Python Error!!! Module numpy not found. Please install numpy in your python environment!" << std::endl;
248 emit
log(
LOGERR, QString(
"Python Error!!! Module numpy not found. Please install numpy in your python environment!"));
250 QMessageBox::critical(0,tr(
"OpenFlipper Python"),tr(
"Python Error!!! Module numpy not found. Please install numpy in your python environment!"),QMessageBox::Ok);
260 PyGILState_STATE state = PyGILState_Ensure();
261 PyObject* dict = PyModule_GetDict(mainModule_->ptr());
263 PyDict_Update(dict, global_dict_clean_);
264 PyGILState_Release(state);
271 std::cerr <<
"runScript" << std::endl;
278 QString runScriptQ = _script;
279 runScriptQ.prepend(
"core = openflipper.Core()\n");
281 QStringList pythonPlugins = getPythonPlugins();
283 for (
int i = 0 ; i < pythonPlugins.size() ; ++i ) {
284 QString
import = pythonPlugins[i].toLower() + " = " + pythonPlugins[i] +
"." + pythonPlugins[i] +
"()\n";
285 runScriptQ.prepend(
import);
293 std::cerr <<
"Initialize Python" << std::endl;
299 std::cerr <<
"Done initializing Python" << std::endl;
302 catch (py::error_already_set &e)
308 PyGILState_STATE state = PyGILState_Ensure();
311 auto locals = mainModule_->attr(
"__dict__");
315 std::string
runScript = runScriptQ.toStdString();
316 auto globals= py::globals();
321 std::cerr <<
"Now executing script:" << std::endl;
326 std::cerr <<
"Finished successfully" << std::endl;
328 catch (py::error_already_set &e)
334 catch (
const std::runtime_error &e)
337 pyOutput(
"Restarting Interpreter.");
340 state = PyGILState_Ensure();
343 PyGILState_Release(state);
351 externalLogging_ =
false;
353 externalLogging_ =
true;
354 return LogOut + LogErr;
361 if (externalLogging_) {
364 LogOut += QString::fromUtf8(w);
370 if (externalLogging_) {
371 if (OpenFlipper::Options::nogui()) {
372 std::cerr <<
"Python Error! " << w << std::endl;
377 LogErr += QString::fromUtf8(w);
384PYBIND11_EMBEDDED_MODULE(openflipper, m) {
388 py::class_<Core,std::unique_ptr<Core, py::nodelete>> core(m,
"Core");
393 core.def(py::init([]() {
return core_; }));
395 core.def(
"updateView", &
Core::updateView, QCoreApplication::translate(
"PythonDocCore",
"Redraw the contents of the viewer.").toLatin1().data() );
396 core.def(
"blockScenegraphUpdates", &
Core::blockScenegraphUpdates, QCoreApplication::translate(
"PythonDocCore",
"Disable Scenegraph Updates (e.g. before loading or adding a large number of files)").toLatin1().data() );
397 core.def(
"updateUI", &
Core::updateUI, QCoreApplication::translate(
"PythonDocCore",
"Process events during script execution to keep the ui alive").toLatin1().data() );
398 core.def(
"clearAll", &
Core::clearAll, QCoreApplication::translate(
"PythonDocCore",
"Clear all data objects.").toLatin1().data() );
399 core.def(
"deleteObject", &
Core::deleteObject, QCoreApplication::translate(
"PythonDocCore",
"Delete an object from the scene.").toLatin1().data() ,
400 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object to delete.").toLatin1().data() ) );
402 core.def(
"setObjectComment", &
Core::setObjectComment, QCoreApplication::translate(
"PythonDocCore",
"Add a comment to an object (saved e.g. in screenshot metadata).").toLatin1().data()) ,
403 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object to add comment.").toLatin1().data()),
404 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Key value").toLatin1().data()),
405 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Actual comment").toLatin1().data());
407 core.def(
"clearObjectComment", &
Core::clearObjectComment, QCoreApplication::translate(
"PythonDocCore",
"Remove a comment from an object.").toLatin1().data()) ,
408 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object to remove comment from.").toLatin1().data()),
409 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Key value to remove").toLatin1().data());
411 core.def(
"clearAllComments", &
Core::clearObjectComment, QCoreApplication::translate(
"PythonDocCore",
"Remove all comments from an object.").toLatin1().data()) ,
412 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object to remove comments from.").toLatin1().data());
414 core.def(
"fullscreen", &
Core::fullscreen, QCoreApplication::translate(
"PythonDocCore",
"Enable or disable fullscreen mode.").toLatin1().data() ,
415 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Enable or disable?").toLatin1().data() ) );
417 core.def(
"showViewModeControls", &
Core::deleteObject, QCoreApplication::translate(
"PythonDocCore",
"Show or hide the view mode control box").toLatin1().data() ,
418 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Visible?").toLatin1().data() ) );
420 core.def(
"loggerState", &
Core::loggerState, QCoreApplication::translate(
"PythonDocCore",
"Change the logger window state").toLatin1().data() ,
421 py::arg( QCoreApplication::translate(
"PythonDocCore",
"0 = In Scene , 1 = Normal, 2 = Hidden").toLatin1().data() ) );
423 core.def(
"enableOpenMeshErrorLog", &
Core::enableOpenMeshErrorLog, QCoreApplication::translate(
"PythonDocCore",
"Enable or disable OpenMesh error logging").toLatin1().data() ,
424 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Enable or Disable").toLatin1().data() ) );
426 core.def(
"showToolbox", &
Core::showToolbox, QCoreApplication::translate(
"PythonDocCore",
"Show or hide toolbox").toLatin1().data() ,
427 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Visible?").toLatin1().data() ) );
429 core.def(
"showStatusBar", &
Core::showStatusBar, QCoreApplication::translate(
"PythonDocCore",
"Show or hide status bar").toLatin1().data() ,
430 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Visible?").toLatin1().data() ) );
432 core.def(
"multiViewMode", &
Core::multiViewMode, QCoreApplication::translate(
"PythonDocCore",
"Switch MultiView Mode").toLatin1().data() ,
433 py::arg( QCoreApplication::translate(
"PythonDocCore",
"0: One Viewer, 1: Double Viewer, 2: Grid, 3: Horizontal split").toLatin1().data() ) );
435 core.def(
"restrictFrameRate", &
Core::restrictFrameRate, QCoreApplication::translate(
"PythonDocCore",
"Restrict maximal rendering FrameRate to MaxFrameRate").toLatin1().data() ,
436 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Restrict Framerate?").toLatin1().data() ) );
438 core.def(
"setMaxFrameRate", &
Core::setMaxFrameRate, QCoreApplication::translate(
"PythonDocCore",
"Set the maximal framerate (automatically enables framerate restriction)").toLatin1().data() ,
439 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Maximum frameRate").toLatin1().data() ) );
441 core.def(
"snapshotBaseFileName", &
Core::snapshotBaseFileName, QCoreApplication::translate(
"PythonDocCore",
"Set a base filename for storing snapshots. This setting is viewer dependent").toLatin1().data() ,
442 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Base filename").toLatin1().data()),
443 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Viewer ID to set the filename for").toLatin1().data() ) );
445 core.def(
"snapshotFileType", &
Core::snapshotFileType, QCoreApplication::translate(
"PythonDocCore",
"Set a filetype for storing snapshots.").toLatin1().data() ,
446 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Image type as string (e.g. jpg )").toLatin1().data()),
447 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Viewer ID to set the filetype for").toLatin1().data() ) );
449 core.def(
"snapshotCounterStart", &
Core::snapshotCounterStart, QCoreApplication::translate(
"PythonDocCore",
"Set the starting number for the snapshot counter.").toLatin1().data() ,
450 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Starting number for the counter").toLatin1().data() ),
451 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Viewer ID to set the counter for").toLatin1().data() ) );
454 core.def(
"snapshot", &
Core::snapshot, QCoreApplication::translate(
"PythonDocCore",
"Make a snapshot of the viewer with id viewerId.\n"
455 "Pass 0 as viewerId parameter to capture the current viewer. \n"
456 "The captured image will have the specified dimensions. \n"
457 "If 0 is passed as either width or height parameter, the value will \n"
458 "automatically be set to hold the right aspect ratio, respectively. \n"
459 "If 0 is passed for both width and height values, the viewport's current \n"
460 "dimension is used. Set alpha to true if you want the background to be transparent. \n"
461 "The fifth parameter is used to hide the coordinate system in the upper right corner of the screen. \n"
462 "If no filename was set using snapshotBaseFileName() the snapshot is stored \n"
463 "in snap.png in the current directory. For every snapshot \n"
464 "a counter is added to the filename.").toLatin1().data() ,
465 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of viewer").toLatin1().data() ) = 0,
466 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Width of image").toLatin1().data() )= 0,
467 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Height of image").toLatin1().data() )= 0,
468 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Transparent background?").toLatin1().data() ) =
false,
469 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Hide coordinate system?").toLatin1().data() ) =
false ,
470 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Number of samples per pixel").toLatin1().data() ) =1 );
473 core.def(
"applicationSnapshot", &
Core::applicationSnapshot, QCoreApplication::translate(
"PythonDocCore",
"Create a snapshot of the whole application").toLatin1().data() );
475 core.def(
"applicationSnapshotName", &
Core::applicationSnapshotName, QCoreApplication::translate(
"PythonDocCore",
"Set the baseName for the application snapshot").toLatin1().data() ,
476 py::arg( QCoreApplication::translate(
"PythonDocCore",
"BaseName for full application snapshots").toLatin1().data() ) );
478 core.def(
"viewerSnapshot",
static_cast<void (
Core::*)()
>(&
Core::viewerSnapshot), QCoreApplication::translate(
"PythonDocCore",
"Take a snapshot from all viewers").toLatin1().data() );
480 core.def(
"viewerSnapshot",
static_cast<void (
Core::*)(QString,
bool,
bool,
bool,
bool,
int,
int,
bool,
bool,
int,
bool)
>(&
Core::viewerSnapshot),
481 QCoreApplication::translate(
"PythonDocCore",
"Create a snapshot with full control").toLatin1().data(),
482 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Filename of the snapshot").toLatin1().data() ),
483 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Should the comments be written?").toLatin1().data() ),
484 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Should only the comments of visible objects be written?").toLatin1().data() ),
485 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Should only the comments of target objects be written?").toLatin1().data() ),
486 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Store material info?").toLatin1().data() ),
487 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Snapshot width").toLatin1().data() ),
488 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Snapshot height").toLatin1().data() ),
489 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Transparent background?").toLatin1().data() ),
490 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Hide coordinate system?").toLatin1().data() ),
491 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Multisampling count").toLatin1().data() ),
492 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Store the view in the metadata?").toLatin1().data() ) );
495 core.def(
"resizeViewers", &
Core::resizeViewers, QCoreApplication::translate(
"PythonDocCore",
"Resize the examinerViewer.").toLatin1().data() ,
496 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Width").toLatin1().data() ),
497 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Height").toLatin1().data() ) );
499 core.def(
"resizeApplication", &
Core::resizeApplication, QCoreApplication::translate(
"PythonDocCore",
"Resize the whole Application.").toLatin1().data() ,
500 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Width").toLatin1().data() ),
501 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Height").toLatin1().data() ) );
503 core.def(
"writeVersionNumbers", &
Core::writeVersionNumbers, QCoreApplication::translate(
"PythonDocCore",
"Write the current versions of all plugins to ini file").toLatin1().data() ,
504 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Full path to a file where the versions should be written to.").toLatin1().data() ) );
513 core.def(
"blockSceneGraphUpdates", &
Core::blockSceneGraphUpdates, QCoreApplication::translate(
"PythonDocCore",
"Block the scenegraph updates for improved performance").toLatin1().data() );
514 core.def(
"unblockSceneGraphUpdates", &
Core::unblockSceneGraphUpdates, QCoreApplication::translate(
"PythonDocCore",
"Unblock the scenegraph updates").toLatin1().data() );
517 core.def(
"setView", &
Core::setView, QCoreApplication::translate(
"PythonDocCore",
"Set the encoded view for the primary viewport.").toLatin1().data() ,
518 py::arg( QCoreApplication::translate(
"PythonDocCore",
"The encoded view. (You can obtain one through \"Copy View\" in the context menu of the coordinates.)").toLatin1().data() ) );
520 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() ,
521 py::arg( QCoreApplication::translate(
"PythonDocCore",
"The encoded view. (You can obtain one through \"Copy View\" in the context menu of the coordinates.)").toLatin1().data() ) );
523 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() ,
524 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the Viewmode").toLatin1().data() ),
525 py::arg( QCoreApplication::translate(
"PythonDocCore",
"';' separated list of toolboxes visible in this viewmode)").toLatin1().data() ));
527 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() ,
528 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the Viewmode").toLatin1().data() ),
529 py::arg( QCoreApplication::translate(
"PythonDocCore",
"';' separated list of toolbars visible in this viewmode)").toLatin1().data() ));
531 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() ,
532 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the Viewmode").toLatin1().data() ),
533 py::arg( QCoreApplication::translate(
"PythonDocCore",
"';' separated list of Context Menus visible in this viewmode)").toLatin1().data() ));
535 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() ,
536 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the Viewmode").toLatin1().data() ),
537 py::arg( QCoreApplication::translate(
"PythonDocCore",
"filename of the icon (will be taken from OpenFlippers icon directory)").toLatin1().data() ));
540 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() ,
541 py::arg( QCoreApplication::translate(
"PythonDocCore",
"The desired side of the toolboxes (either 'left' or 'right')").toLatin1().data() ) );
543 core.def(
"setToolBoxActive", &
Core::setToolBoxActive, QCoreApplication::translate(
"PythonDocCore",
"Activate or deaktivate a toolbox").toLatin1().data() ,
544 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the toolbox.").toLatin1().data() ),
545 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Activate or deaktivate?").toLatin1().data() ));
547 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() ,
548 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Filename to load.").toLatin1().data() ) );
550 core.def(
"startVideoCapture", &
Core::startVideoCapture, QCoreApplication::translate(
"PythonDocCore",
"Start video capturing.").toLatin1().data() ,
551 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Basename for capturing").toLatin1().data() ),
552 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Frames per second").toLatin1().data() ),
553 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Should the viewers be captured or the whole application?").toLatin1().data() ) );
555 core.def(
"stopVideoCapture", &
Core::stopVideoCapture, QCoreApplication::translate(
"PythonDocCore",
"Stop video capturing").toLatin1().data() );
557 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() ,
558 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object)").toLatin1().data() ),
559 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Complete path and filename").toLatin1().data() ));
561 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() ,
562 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object)").toLatin1().data() ),
563 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Initial filename in the dialog").toLatin1().data() ));
569 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() );
571 core.def(
"saveAllObjectsTo", &
Core::saveAllObjectsTo, QCoreApplication::translate(
"PythonDocCore",
"Saves all target objects. The locations can be chosen in dialogs. (Only GUI Mode!)").toLatin1().data() );
573 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() );
575 core.def(
"saveSettings",
static_cast<void (
Core::*)(QString,
bool,
bool,
bool,
bool,
bool,
bool)
>(&
Core::saveSettings),
576 QCoreApplication::translate(
"PythonDocCore",
"Save the current setting to the given file.").toLatin1().data(),
577 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Path of the file to save the settings to.").toLatin1().data() ),
578 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Save Object information into file?").toLatin1().data() ),
579 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Restrict to targeted objects?").toLatin1().data() ),
580 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Save objects into same path as settings file?").toLatin1().data() ),
581 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Prompt before overwriting files that already exist (gui mode only).").toLatin1().data() ),
582 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Save program settings?").toLatin1().data() ),
583 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Save plugin settings?").toLatin1().data() ) );
585 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() );
587 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() );
589 core.def(
"loadSettings",
static_cast<void (
Core::*)(QString)
>(&
Core::loadSettings), QCoreApplication::translate(
"PythonDocCore",
"Load settings from file.").toLatin1().data() ,
590 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Filename to load.").toLatin1().data() ) );
592 core.def(
"getObjectId", &
Core::getObjectId, QCoreApplication::translate(
"PythonDocCore",
"Return identifier of object with specified name. Returns -1 if object was not found.").toLatin1().data() ,
593 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Filename or name of the object").toLatin1().data() ) );
595 core.def(
"deserializeMaterialProperties", &
Core::deserializeMaterialProperties, QCoreApplication::translate(
"PythonDocCore",
"Deserialize the supplied material properties into the supplied object.").toLatin1().data() ,
596 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object").toLatin1().data() ),
597 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Material properties encoded as string").toLatin1().data() ) );
599 core.def(
"serializeMaterialProperties", &
Core::serializeMaterialProperties, QCoreApplication::translate(
"PythonDocCore",
"Serialize and return the material properties of the supplied object.").toLatin1().data() ,
600 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Id of the object").toLatin1().data() ));
602 core.def(
"activateToolbox", &
Core::activateToolbox, QCoreApplication::translate(
"PythonDocCore",
"Expand or collapse a toolbox").toLatin1().data() ,
603 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the plugin to which this toolbox gelongs").toLatin1().data() ),
604 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the toolbox").toLatin1().data() ),
605 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Expand or collapse?").toLatin1().data() ) );
607 core.def(
"saveOptions", &
Core::saveOptions, QCoreApplication::translate(
"PythonDocCore",
"Save the current options to the standard ini file").toLatin1().data() );
609 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() );
611 core.def(
"openIniFile", &
Core::openIniFile, QCoreApplication::translate(
"PythonDocCore",
"Load information from an ini file").toLatin1().data() ,
612 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the ini file").toLatin1().data() ),
613 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Load applications settings?").toLatin1().data() ),
614 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Load plugin settings?").toLatin1().data() ),
615 py::arg( QCoreApplication::translate(
"PythonDocCore",
" Load objects defined in the ini file?").toLatin1().data() ));
627 core.def(
"setViewMode", &
Core::setViewMode, QCoreApplication::translate(
"PythonDocCore",
"Switch to the given viewmode").toLatin1().data() ,
628 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the viewmode to enable").toLatin1().data() ) );
631 core.def(
"getCurrentViewMode", &
Core::getCurrentViewMode, QCoreApplication::translate(
"PythonDocCore",
"Get the name of the current viewMode").toLatin1().data() );
633 core.def(
"setViewModeIcon", &
Core::setViewModeIcon, QCoreApplication::translate(
"PythonDocCore",
"Set an icon for a view Mode").toLatin1().data() ,
634 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the mode for the icon").toLatin1().data() ),
635 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Filename of the icon").toLatin1().data() ) );
637 core.def(
"moveToolBoxToTop", &
Core::moveToolBoxToTop, QCoreApplication::translate(
"PythonDocCore",
"Move selected toolbox to the top of side area").toLatin1().data() ,
638 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the Toolbox to be moved").toLatin1().data() ) );
640 core.def(
"moveToolBoxToBottom", &
Core::moveToolBoxToBottom, QCoreApplication::translate(
"PythonDocCore",
"Move selected toolbox to the bottom of side area").toLatin1().data() ,
641 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Name of the Toolbox to be moved").toLatin1().data() ) );
643 core.def(
"showReducedMenuBar", &
Core::showReducedMenuBar, QCoreApplication::translate(
"PythonDocCore",
"Show only a reduced menubar").toLatin1().data() ,
644 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Reduced Menubar?").toLatin1().data() ) );
646 core.def(
"executePythonScriptFile", &
Core::executePythonScriptFile, QCoreApplication::translate(
"PythonDocCore",
"Open the given file and execute its contents as a python script").toLatin1().data() ,
647 py::arg( QCoreApplication::translate(
"PythonDocCore",
"Filename of the script").toLatin1().data() ) );
650 core.def(
"executePythonScript", &
Core::executePythonScript, QCoreApplication::translate(
"PythonDocCore",
"Execute a text as a python script").toLatin1().data() ,
651 py::arg( QCoreApplication::translate(
"PythonDocCore",
"The text of the script").toLatin1().data() ) );
653 core.def(
"exitApplication", &
Core::exitApplication, QCoreApplication::translate(
"PythonDocCore",
"Exit the application").toLatin1().data() );
654 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() );
655 core.def(
"finishSplash", &
Core::finishSplash, QCoreApplication::translate(
"PythonDocCore",
"Hide the splash screen").toLatin1().data() );
657 core.def(
"objectUpdated", &
Core::slotObjectUpdated, QCoreApplication::translate(
"PythonDocCore",
"Tell the core that an object has been updated").toLatin1().data(),
658 py::arg( QCoreApplication::translate(
"PythonDocCore",
"ID of the updated object").toLatin1().data() ),
659 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 );
void showStatusBar(bool _state)
Show or hide Status Bar.
void addViewModeToolbars(QString _modeName, QString _toolbarList)
Scripting function to set toolbars in a view mode.
void clearAll()
Clear all data objects.
bool saveObjectTo(int _id, QString _filename)
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options
void addViewModeToolboxes(QString _modeName, QString _toolboxList)
Scripting function to set toolboxes in a view mode.
void showToolbox(bool _state)
Show or hide toolbox.
void saveSettings()
Save current status to a settings file. Solicit file name through dialog.
void setToolBoxSide(QString _side)
Scripting function to set the side of the main window on which the toolbox should be displayed.
void snapshotBaseFileName(QString _fname, unsigned int _viewerId=0)
void resizeApplication(int _width, int _height)
resize the whole Application
void addViewModeContextMenus(QString _modeName, QString _contextMenuList)
Scripting function to set context menus in a view mode.
void setViewAndWindowGeometry(QString view)
Called when a plugin requests an update in the viewer.
void resizeViewers(int _width, int _height)
resize the examinerViewer
void deserializeMaterialProperties(int _objId, QString _props)
Serialize material properties.
void saveAllObjectsTo()
Slot for saving objects to a new location.
void blockSceneGraphUpdates()
Block the scenegraph updates.
void addViewModeIcon(QString _modeName, QString _iconName)
Scripting function to set an icon for a view mode.
void fullscreen(bool _state)
set fullscreen mode
void saveAllObjects()
Slot for saving objects from Menu.
void showReducedMenuBar(bool reduced)
Core scripting engine.
void moveToolBoxToBottom(QString _name)
Move selected toolbox to bottom of side area.
void exitFailure()
Aborts the application with an error code.
void snapshotFileType(QString _type, unsigned int _viewerId=0)
Set the file type for snapshots.
void loadObject()
Open Load Widget.
void restrictFrameRate(bool _enable)
Enable or disable framerate restriction.
void setToolBoxActive(QString _toolBoxName, bool _active)
Scripting function to activate or deactivate a toolbox.
void unblockSceneGraphUpdates()
Unblock the scenegraph updates.
void setViewModeIcon(QString _mode, QString _iconName)
Set the icon of a viewMode.
void moveToolBoxToTop(QString _name)
Move selected toolbox to top of side area.
void blockScenegraphUpdates(bool _block)
Called when a plugin wants to lock or unlock scenegraph updates.
void executePythonScriptFile(QString _filename)
Open the given file and execute its contents as a python script.
void snapshotCounterStart(const int _counter, unsigned int _viewerId=0)
Set the start index for the snapshot counter.
void finishSplash()
exit the current application
void snapshot(unsigned int _viewerId=0, int _width=0, int _height=0, bool _alpha=false, bool _hideCoordsys=false, int _numSamples=1)
void saveOptions()
Save the current options to the standard ini file.
void startVideoCapture(const QString &_baseName, int _fps, bool _captureViewers)
Start video capturing.
void enableOpenMeshErrorLog(bool _state)
Enable or disable OpenMesh error logging.
void applicationSnapshotName(QString _name)
Set the baseName for the application snapshot.
void deleteObject(int _id)
Called to delete an object.
void writeVersionNumbers(QString _filename)
write the current versions of all plugins to ini file
void viewerSnapshot()
Take a snapshot from all viewers.
void applicationSnapshot()
Take a snapshot from the whole app.
void setMaxFrameRate(int _rate)
set the maximal framerate ( automatically enables framerate restriction )
void slotObjectUpdated(int _identifier, const UpdateType &_type=UPDATE_ALL)
Called by the plugins if they changed something in the object list (deleted, added,...
void updateView()
Called when a plugin requests an update in the viewer.
void setView(QString view)
Called when a plugin requests an update in the viewer.
int getObjectId(QString _filename)
Get object id from filename.
void exitApplication()
exit the current application
void setViewMode(QString _viewMode)
Set the active ViewMode.
void activateToolbox(QString _pluginName, QString _toolboxName, bool activate)
expand or collapse a toolbox
void executePythonScript(const QString &_script)
execute the given string as a python script
void loggerState(int _state)
Change the logging window state.
void loadSettings()
Load status from file.
void multiViewMode(int _mode)
Switch the multiView Mode.
void clearObjectComment(int objId, QString key)
Called when a plugin requests an update in the viewer.
QString getCurrentViewMode()
Get current view mode.
void stopVideoCapture()
Stop video capturing.
QString serializeMaterialProperties(int _objId)
Serialize material properties.
void updateUI()
process events during script execution to keep the ui alive
bool saveObject(int _id, QString _filename)
Save an object.
void setObjectComment(int objId, QString key, QString comment)
Called when a plugin requests an update in the viewer.
void openIniFile(QString _filename, bool _coreSettings, bool _perPluginSettings, bool _loadObjects)
Load information from an ini file.
This class provides OpenFlippers Python interpreter.
void pyOutput(const char *w)
Callback to redirect cout log to OpenFlipper logger.
bool runScript(const QString &_script)
Run a script. Output is passed to the standard logging facilities of OpenFlipper.
void initPython()
Initialize OpenFlipper Python Interpreter.
QString runScriptOutput(const QString &_script)
void pyError(const char *w)
Callback to redirect cerr log to OpenFlipper logger.
bool modulesInitialized()
PythonInterpreter()
private constructor because of singleton
void log(Logtype _type, QString _message)
Log with OUT,WARN or ERR as type.
static PythonInterpreter * getInstance()
Creates or returns an instance of the interpreter.
void resetInterpreter()
Resets the interpreter and all states.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.