Core.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 7344 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-10-08 11:06:20 +0200 (Do, 08. Okt 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 
00047 //=============================================================================
00048 //
00049 //  CLASS Core - IMPLEMENTATION
00050 //
00051 //=============================================================================
00052 
00053 
00054 //== INCLUDES =================================================================
00055 
00056 // -------------------- mview
00057 #include "Core.hh"
00058 // -------------------- ACG
00059 #include <ACG/Scenegraph/DrawModes.hh>
00060 #include <ACG/Scenegraph/SceneGraph.hh>
00061 
00062 #include <ACG/QtWidgets/QtFileDialog.hh>
00063 // -------------------- Qt
00064 
00065 #include <QKeyEvent>
00066 #include <QSplitter>
00067 #include <QMenuBar>
00068 #include <QToolBox>
00069 #include <QApplication>
00070 #include <QStatusBar>
00071 #include <QMessageBox>
00072 #include <QFile>
00073 #include <QSettings>
00074 
00075 #include <QPluginLoader>
00076 #include "OpenFlipper/BasePlugin/BaseInterface.hh"
00077 #include "OpenFlipper/BasePlugin/KeyInterface.hh"
00078 #include "OpenFlipper/BasePlugin/MouseInterface.hh"
00079 #include "OpenFlipper/BasePlugin/PickingInterface.hh"
00080 #include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
00081 #include "OpenFlipper/BasePlugin/TextureInterface.hh"
00082 #include "OpenFlipper/BasePlugin/MenuInterface.hh"
00083 #include "OpenFlipper/BasePlugin/INIInterface.hh"
00084 
00085 #include "OpenFlipper/INIFile/INIFile.hh"
00086 
00087 #include "OpenFlipper/common/GlobalOptions.hh"
00088 #include <OpenFlipper/common/RecentFiles.hh>
00089 #include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
00090 
00091 #include <QStringList>
00092 #include <QtScript/QScriptValueIterator>
00093 
00094 #include <ACG/Scenegraph/SeparatorNode.hh>
00095 
00096 #include "OpenFlipper/BasePlugin/PluginFunctions.hh"
00097 #include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
00098 
00099 #include "OpenFlipper/BasePlugin/RPCWrappers.hh"
00100 
00101 #include <OpenMesh/Core/System/omstream.hh>
00102 
00103 #define WIDGET_HEIGHT 800
00104 #define WIDGET_WIDTH  800
00105 
00106 //== IMPLEMENTATION ==========================================================
00107 
00116 Core::
00117 Core() :
00118   QObject(),
00119   capture_(false),
00120   nextBackupId_(0),
00121   coreWidget_(0)
00122 {
00123   //init logFile
00124   logStream_ = 0;
00125   logFile_ = 0;
00126   OpenFlipper::Options::logFileEnabled(true);
00127 
00128   //init nodes
00129   root_node_scenegraph_ = new ACG::SceneGraph::SeparatorNode(0, "SceneGraph Root Node");
00130   
00131   // This seperator will manage the cores nodes
00132   core_nodes_ = new ACG::SceneGraph::SeparatorNode(root_node_scenegraph_, "Core Nodes");
00133   
00134   // Coordsys rendering nodes
00135   coordsysMaterialNode_ = new ACG::SceneGraph::MaterialNode(core_nodes_,"Coordsys Material Node");
00136   coordsysNode_ = new ACG::SceneGraph::CoordsysNode(coordsysMaterialNode_,"Core Coordsys Node");  
00137   coordsysNode_->setTraverseMode (BaseNode::NodeFirst | BaseNode::SecondPass);
00138   
00139   // seperator handling the nodes for data
00140   dataSeparatorNode_ = new ACG::SceneGraph::SeparatorNode(root_node_scenegraph_, "Data Separator Root Node");
00141   
00142   // seperator handling the nodes for data
00143   dataRootNode_      = new ACG::SceneGraph::SeparatorNode(dataSeparatorNode_, "Data Root Node");
00144   
00145   
00146 //   gridNode_ = new ACG::SceneGraph::GridNode(core_nodes_,"Grid Node");
00147 //   gridNode_->hide();
00148 
00149    // Add ViewMode All
00150   ViewMode* vm = new ViewMode();
00151   vm->name = "All";
00152   vm->icon = "viewmode_all.png";
00153   vm->custom = false;
00154   vm->visibleToolboxes = QStringList();
00155 
00156   viewModes_.push_front(vm);
00157 
00158   //init ViewerProperties (always for 4 Viewers!)
00159   std::vector< Viewer::ViewerProperties* > viewerProperties;
00160 
00161   for (int i=0; i < 4; i++) {
00162     Viewer::ViewerProperties* viewerProperty = new Viewer::ViewerProperties();
00163     viewerProperty->snapshotBaseFileName("snap-Viewer-" + QString::number(i) + ".png");
00164     viewerProperties.push_back( viewerProperty );
00165   }
00166 
00167   PluginFunctions::setViewerProperties(viewerProperties);
00168 
00169   //set viewer defaults
00170   OpenFlipper::Options::defaultProjectionMode( 1, 0 );
00171   OpenFlipper::Options::defaultProjectionMode( 0, 1 );
00172   OpenFlipper::Options::defaultProjectionMode( 0, 2 );
00173   OpenFlipper::Options::defaultProjectionMode( 0, 3 );
00174   OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_FREE,  0 );
00175   OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_TOP,   1 );
00176   OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_LEFT,  2 );
00177   OpenFlipper::Options::defaultViewingDirection( PluginFunctions::VIEW_FRONT, 3 );
00178 
00179   // Get all relevant Paths and Options from option files
00180   setupOptions();
00181 
00182   // set discriptions for scriptable slots
00183   setDescriptions();
00184 }
00185 
00195 void
00196 Core::init() {
00197 
00198   // Make root_node available to the plugins ( defined in PluginFunctions.hh)
00199   PluginFunctions::setDataSeparatorNodes( dataSeparatorNode_ );
00200 
00201   PluginFunctions::setSceneGraphRootNode( root_node_scenegraph_ );
00202 
00203   // Initialize the first object as the root Object for the object tree
00204   objectRoot_ =  dynamic_cast< BaseObject* > ( new GroupObject("ObjectRoot") );
00205   PluginFunctions::setDataRoot( objectRoot_ );
00206 
00207 
00208   if ( OpenFlipper::Options::gui() ) {
00209 
00210     // Initialize redraw timer. Will be used to restrict the rendering framerate.
00211     redrawTimer_ = new QTimer();
00212     redrawTimer_->setSingleShot(true);
00213     connect(redrawTimer_, SIGNAL(timeout()), this, SLOT(updateView()),Qt::DirectConnection);
00214 
00215     // Initialice scenegraph check timer. Will be used to check for changes in the scenegraph
00216     scenegraphCheckTimer_ = new QTimer();
00217     scenegraphCheckTimer_->setSingleShot(false);
00218     connect(scenegraphCheckTimer_, SIGNAL(timeout()), this, SLOT(checkScenegraphDirty()),Qt::DirectConnection);
00219 
00220     // Will measure the time between redraws
00221     redrawTime_ = new QTime();
00222     redrawTime_->start ();
00223 
00224     if ( OpenFlipper::Options::splash() ) {
00225       QPixmap splashPixmap(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "splash.png");
00226 
00227       splash_ = new QSplashScreen(splashPixmap);
00228       splash_->show();
00229 
00230       splash_->showMessage(tr("Initializing mainwindow") ,
00231                           Qt::AlignBottom | Qt::AlignLeft , Qt::white);
00232       QApplication::processEvents();
00233     }
00234 
00235     coreWidget_ = new CoreWidget(viewModes_ , plugins, coreSlots_);
00236 
00237     connect(coreWidget_, SIGNAL(clearAll())           , this, SLOT(clearAll()));
00238     connect(coreWidget_, SIGNAL(loadMenu())           , this, SLOT(loadObject()));
00239     connect(coreWidget_, SIGNAL(addEmptyObjectMenu()) , this, SLOT(slotAddEmptyObjectMenu()));
00240     connect(coreWidget_, SIGNAL(saveMenu())           , this, SLOT(saveAllObjects()));
00241     connect(coreWidget_, SIGNAL(saveToMenu())         , this, SLOT(saveAllObjectsTo()));
00242     connect(coreWidget_, SIGNAL(loadIniMenu())        , this, SLOT(loadSettings()));
00243     connect(coreWidget_, SIGNAL(saveIniMenu())        , this, SLOT(saveSettings()));
00244     connect(coreWidget_, SIGNAL(applyOptions())       , this, SLOT(applyOptions()));
00245     connect(coreWidget_, SIGNAL(saveOptions())        , this, SLOT(saveOptions()));
00246     connect(coreWidget_, SIGNAL(recentOpen(QAction*)) , this, SLOT(slotRecentOpen(QAction*)));
00247     connect(coreWidget_, SIGNAL(exit())               , this, SLOT(slotExit()));
00248 
00249 
00250     connect( coreWidget_, SIGNAL( resizeViewers(int,int) ), this, SLOT( resizeViewers(int,int) ) );
00251     connect( coreWidget_, SIGNAL( resizeApplication(int,int) ), this, SLOT( resizeApplication(int,int) ) );
00252     connect( coreWidget_, SIGNAL( stopVideoCapture() ), this, SLOT( stopVideoCapture() ) );
00253     connect( coreWidget_, SIGNAL( startVideoCapture(QString,int,bool) ), this, SLOT( startVideoCapture(QString,int,bool) ) );
00254 
00255     connect(coreWidget_, SIGNAL(showPlugins())       , this, SLOT(slotShowPlugins()));
00256 
00257     connect(coreWidget_, SIGNAL(call(QString,bool&)), this, SLOT(slotCall(QString,bool&)));
00258 
00259     QRect rect = QApplication::desktop()->screenGeometry();
00260 
00261     uint width = rect.width();
00262     if ( width > 1000 ) {
00263       width = 1000;
00264     }
00265 
00266     uint height = rect.height();
00267     if ( height > 1000 ) {
00268       height = 1000;
00269     }
00270 
00271 #ifdef ARCH_DARWIN
00272     width = rect.width() - 300;
00273     height = rect.height() - 150;
00274 
00275 //     coreWidget_->setMaximumSize( width, height  );
00276 #endif
00277 
00278     coreWidget_->resize(width,height);
00279 
00280     coreWidget_->setWindowTitle( OpenFlipper::Options::windowTitle() );
00281 
00282   }
00283 
00284   // ======================================================================
00285   // Create intermediate logger class for Core which will mangle the output
00286   // ======================================================================
00287   PluginLogger* newlog = new PluginLogger("Core");
00288 
00289   loggers_.push_back(newlog);
00290   connect(this,SIGNAL(log(Logtype, QString )),newlog,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00291   connect(this,SIGNAL(log(QString )),newlog,SLOT(slotLog(QString )),Qt::DirectConnection);
00292 
00293   // Connect it to the Master logger
00294   if ( OpenFlipper::Options::gui() )
00295     connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00296 
00297   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00298 
00299   // connection to file logger
00300   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
00301 
00302   // ======================================================================
00303   // Create a logger class for CoreWidget
00304   // ======================================================================
00305 
00306   if ( OpenFlipper::Options::gui() ){
00307     PluginLogger* widgetlog = new PluginLogger("CoreWidget");
00308 
00309     loggers_.push_back(widgetlog);
00310     connect(coreWidget_,SIGNAL(log(Logtype, QString )),widgetlog,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00311     connect(coreWidget_,SIGNAL(log(QString )),widgetlog,SLOT(slotLog(QString )),Qt::DirectConnection);
00312 
00313     // Connect it to the Master logger
00314     connect(widgetlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00315     connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00316     // connection to file logger
00317     connect(widgetlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
00318   }
00319 
00320   // ======================================================================
00321   // Catch OpenMesh Error logs with an own Logger
00322   // ======================================================================
00323   newlog = new PluginLogger("Core ( OpenMesh )",LOGERR);
00324   omerr().connect(*newlog);
00325   omerr().disconnect(std::cerr);
00326 
00327   loggers_.push_back(newlog);
00328 
00329   // Connect it to the Master logger
00330   if ( OpenFlipper::Options::gui() )
00331     connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00332 
00333   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00334   // connection to file logger
00335   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
00336 
00337   // ======================================================================
00338   // Catch OpenMesh omout logs with an own Logger
00339   // ======================================================================
00340   newlog = new PluginLogger("Core ( OpenMesh )",LOGINFO);
00341   omout().connect(*newlog);
00342   omout().disconnect(std::cout);
00343 
00344   loggers_.push_back(newlog);
00345 
00346   // Connect it to the Master logger
00347   if ( OpenFlipper::Options::gui() )
00348     connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00349 
00350   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00351   // connection to file logger
00352   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
00353 
00354   // ======================================================================
00355   // Catch OpenMesh omlog logs with an own Logger
00356   // ======================================================================
00357   newlog = new PluginLogger("Core ( OpenMesh )",LOGOUT);
00358   omlog().connect(*newlog);
00359 
00360   loggers_.push_back(newlog);
00361 
00362   // Connect it to the Master logger
00363   if ( OpenFlipper::Options::gui() )
00364     connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00365 
00366   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00367   // connection to file logger
00368   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
00369 
00370   // ======================================================================
00371   // Log Scripting stuff through a separate logger
00372   // ======================================================================
00373   newlog = new PluginLogger("Scripting",LOGOUT);
00374 
00375   loggers_.push_back(newlog);
00376 
00377   // Connect it to the Master logger
00378   if ( OpenFlipper::Options::gui() )
00379     connect(newlog,SIGNAL(log(Logtype, QString )),coreWidget_,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00380 
00381   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLog(Logtype, QString )),Qt::DirectConnection);
00382   // connection to file logger
00383   connect(newlog,SIGNAL(log(Logtype, QString )),this,SLOT(slotLogToFile(Logtype, QString )),Qt::DirectConnection);
00384 
00385   // connect signal to logger
00386   connect(this,SIGNAL(scriptLog(QString )),newlog,SLOT(slotLog(QString )),Qt::DirectConnection);
00387 
00388   
00389   // ======================================================================
00390   // Set up QtScript Environment
00391   // ======================================================================
00392   
00393   // Set a reference to the scriptengine for simple rpc calls
00394   RPC::setScriptEngine(&scriptEngine_);
00395 
00396   // process Events every 500 msecs during script execution
00397   scriptEngine_.setProcessEventsInterval( 500 );
00398 
00399   // Register own print function :
00400   QScriptValue printFunction = scriptEngine_.newFunction(myPrintFunction);
00401   printFunction.setProperty("textedit",scriptEngine_.newQObject(this));
00402   scriptEngine_.globalObject().setProperty("print", printFunction);
00403 
00404   // Register Vector Type to ScriptEngine ( is Vec3d )
00405   qScriptRegisterMetaType(&scriptEngine_,
00406                           toScriptValueVector,
00407                           fromScriptValueVector,
00408                           scriptEngine_.newQObject(&vec3dPrototype_));
00409 
00410   // set a constructor to allow creation via Vector(x,y,z)
00411   QScriptValue ctor = scriptEngine_.newFunction(createVector);
00412   scriptEngine_.globalObject().setProperty("Vector", ctor);
00413 
00414 
00415 //    // Register ObjectId Type to ScriptEngine ( is int )
00416 //   qScriptRegisterMetaType(&scriptEngine_,
00417 //                           toScriptValueObjectId,
00418 //                           fromScriptValueObjectId);
00419 //
00420 //   // set a constructor to allow creation via Vector(x,y,z)
00421 //   ctor = scriptEngine_.newFunction(createObjectId);
00422 //   scriptEngine_.globalObject().setProperty("ObjectId", ctor);
00423 
00424 
00425   // Register idList Type to scripting Engine
00426   qScriptRegisterSequenceMetaType< idList >(&scriptEngine_);
00427 
00428   qScriptRegisterSequenceMetaType< QVector< int > >(&scriptEngine_);
00429 
00430 
00431   // Register Matrix Type to scripting Engine ( is ACG::Matrix4x4d )
00432   qScriptRegisterMetaType(&scriptEngine_,
00433                           toScriptValueMatrix4x4 ,
00434                           fromScriptValueMatrix4x4,
00435                           scriptEngine_.newQObject(&matrix4x4Prototype_));
00436 
00437   // set a constructor to allow creation via Matrix(x,y,z)
00438   QScriptValue matrix4x4ctor = scriptEngine_.newFunction(createMatrix4x4);
00439   scriptEngine_.globalObject().setProperty("Matrix4x4", matrix4x4ctor);
00440 
00441   // Collect Core scripting information
00442   QScriptValue scriptInstance = scriptEngine_.newQObject(this,
00443                                                          QScriptEngine::QtOwnership,
00444                                                          QScriptEngine::ExcludeChildObjects |
00445                                                          QScriptEngine::ExcludeSuperClassMethods |
00446                                                          QScriptEngine::ExcludeSuperClassProperties
00447                                                          );
00448 
00449   scriptEngine_.globalObject().setProperty("core", scriptInstance);
00450 
00451   QScriptValueIterator it(scriptInstance);
00452   while (it.hasNext()) {
00453     it.next();
00454 
00456     if ( checkSignal( this, it.name().toAscii() ) )
00457       continue;
00458 
00459     scriptingFunctions_.push_back( "core." + it.name() );
00460 
00461   }
00462 
00463   loadPlugins();
00464 
00465   if ( OpenFlipper::Options::gui() ) {
00466 
00467     //register keyBinding for all scripting slots
00468     coreWidget_->slotRegisterSlotKeyBindings();
00469 
00470     //get keyAssignments from config files
00471     restoreKeyBindings();
00472 
00473     if ( OpenFlipper::Options::defaultToolboxMode( ) != "" )
00474       coreWidget_->setViewMode( OpenFlipper::Options::defaultToolboxMode() );
00475     else
00476       coreWidget_->setViewMode("All");
00477 
00478     for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00479       connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEvent(QMouseEvent*)),
00480               this                              , SLOT(slotMouseEvent(QMouseEvent*)));
00481       connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEventIdentify(QMouseEvent*)),
00482               this                              , SLOT(slotMouseEventIdentify(QMouseEvent*)));
00483       connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalWheelEvent(QWheelEvent *, const std::string &)),
00484               this                              , SLOT(slotWheelEvent(QWheelEvent *, const std::string &)));
00485 
00486       connect( coreWidget_->examiner_widgets_[i], SIGNAL( viewUpdated() ),
00487                this, SLOT( viewUpdated()) ,Qt::DirectConnection);
00488 
00489       connect( coreWidget_->examiner_widgets_[i], SIGNAL( viewChanged() ),
00490                this, SIGNAL( pluginViewChanged() ) ,Qt::DirectConnection);
00491     }
00492 
00493   }
00494 
00495   // ===============================================================================================
00496   // Load Settings from configuration files
00497   // ===============================================================================================
00498 
00499   QStringList optionFiles = OpenFlipper::Options::optionFiles();
00500   for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00501 
00502     if ( OpenFlipper::Options::gui() && OpenFlipper::Options::splash() ) {
00503       splash_->showMessage(tr("Loading Configuration File ") + QString::number(i) + "/"  + QString::number(optionFiles.size()) ,
00504                            Qt::AlignBottom | Qt::AlignLeft , Qt::white);
00505       QApplication::processEvents();
00506     }
00507 
00508     // Load global ini files. Use only plugin global options from these files as the
00509     // rest has been loaded at the beginning.
00510     readRecentFiles( optionFiles[i] );
00511     if ( OpenFlipper::Options::gui() )
00512       coreWidget_->updateRecent();
00513 
00514     openIniFile( optionFiles[i] ,false,true,false);
00515   }
00516 
00517   // ===============================================================================================
00518   // Load Settings from configuration files
00519   // ===============================================================================================
00520 
00521   if ( OpenFlipper::Options::lang().contains("UTF") || OpenFlipper::Options::lang().contains("utf") ) {
00522     emit log(LOGWARN,tr("UTF8-Locale used!"));
00523 //     emit log(LOGWARN,"Only OFF files are fully supported with UTF8. Others might fail.");
00524 //     emit log(LOGWARN,"You can change your locale by :");
00525 //     emit log(LOGWARN,"export LANG=C");
00526 //     emit log(LOGWARN,"Work is in progress to resolve this issue.");
00527   }
00528 
00529   if ( OpenFlipper::Options::gui() ) {
00530 
00531     QSettings windowStates(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00532                            OpenFlipper::Options::dirSeparator() +  "WindowStates.dat", QSettings::IniFormat);
00533 
00534     //try to restore the windowState
00535     coreWidget_->restoreState (windowStates.value("Core/Window/State").toByteArray ());
00536     //try to restore the geometry
00537     coreWidget_->restoreGeometry (windowStates.value("Core/Window/Geometry").toByteArray ());
00538 
00539     coreWidget_->toolSplitter_->restoreState (windowStates.value("Core/ToolSplitter").toByteArray ());
00540     coreWidget_->splitter_->restoreState (windowStates.value("Core/LogSplitter").toByteArray ());
00541 
00542     coreWidget_->show();
00543 
00544     applyOptions();
00545 
00546     windowStates.beginGroup ("Core");
00547     windowStates.beginGroup ("LogSlider");
00548     coreWidget_->slidingLogger_->restoreState (windowStates);
00549     windowStates.endGroup ();
00550     coreWidget_->toolBox_->restoreState (windowStates);
00551     windowStates.endGroup ();
00552 
00553     if ( OpenFlipper::Options::splash() ) {
00554       splash_->finish(coreWidget_);
00555     }
00556 
00557     // start checking for scenegraph changes
00558     scenegraphCheckTimer_->setInterval (1000 / OpenFlipper::Options::maxFrameRate());
00559     scenegraphCheckTimer_->start ();
00560   }
00561 
00562 
00563   QTimer::singleShot(100, this, SLOT(slotExecuteAfterStartup()));
00564 }
00565 
00566 
00567 //-----------------------------------------------------------------------------
00568 
00569 Core::~Core()
00570 {
00571    for ( uint i = 0 ; i < plugins.size() ; ++i ){
00572      BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugins[i].plugin);
00573 
00574      // Dont call exit if we cannot get the Plugin
00575      if ( basePlugin )
00576        if ( checkSlot( plugins[i].plugin , "exit()" ) )
00577           QMetaObject::invokeMethod(plugins[i].plugin, "exit",  Qt::DirectConnection);
00578   }
00579 
00580   objectRoot_->deleteSubtree();
00581   delete objectRoot_;
00582 
00583   // Clean up loggers
00584   for ( uint i = 0 ; i < loggers_.size(); ++i )
00585     delete loggers_[i];
00586 
00587 }
00588 
00589 //-----------------------------------------------------------------------------
00590 
00591 void
00592 Core::slotMouseEventIdentify( QMouseEvent* _event )
00593 {
00594 //   // Dont do anything as a context Menu will popup on right button click
00595 //   if ( _event->button() == Qt::RightButton )
00596 //     return;
00597 
00598   const QObject* senderPointer = sender();
00599   unsigned int examinerId = 0;
00600 
00601   if ( senderPointer == 0 ) {
00602     std::cerr << "Error : slotMouseEventIdentify directly called! This should only be called by an examiner" << std::endl;
00603   } else {
00604     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00605       if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
00606         examinerId = i;
00607         if ( OpenFlipper::Options::doSlotDebugging() )
00608               emit log(LOGINFO,tr("slotMouseEventIdentify from examiner ") + QString::number(i) );
00609         break;
00610       }
00611     }
00612 
00613   }
00614 
00615   PluginFunctions::setActiveExaminer( examinerId );
00616 
00617   emit PluginMouseEventIdentify( _event );
00618 
00619 
00620 }
00621 
00622 //-----------------------------------------------------------------------------
00623 
00624 
00625 void
00626 Core::slotMouseEvent( QMouseEvent* _event )
00627 {
00628 //   // Dont do anything as a context Menu will popup on right button click
00629 //   if ( _event->button() == Qt::RightButton )
00630 //     return;
00631 
00632   const QObject* senderPointer = sender();
00633   unsigned int examinerId = 0;
00634 
00635   if ( senderPointer == 0 ) {
00636     std::cerr << "Error : slotMouseEvent directly called! This should only be called by an examiner" << std::endl;
00637   } else {
00638     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00639       if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
00640         examinerId = i;
00641         if ( OpenFlipper::Options::doSlotDebugging() ) {
00642           QString message = tr("slotMouseEvent from examiner ") + QString::number(i) + " with ";
00643 
00644           if ( _event->type() == QEvent::MouseButtonRelease )
00645             message += " MouseButtonRelease";
00646           else if ( _event->type() == QEvent::MouseButtonPress )
00647             message += " MouseButtonRelease";
00648           else if ( _event->type() == QEvent::MouseButtonDblClick )
00649             message += " MouseButtonDblClick";
00650           else if ( _event->type() == QEvent::MouseMove )
00651             message += " MouseMove";
00652           else
00653             message += tr("unknown event type");
00654 
00655           emit log(LOGINFO,message );
00656         }
00657 
00658         break;
00659 
00660       }
00661     }
00662 
00663   }
00664 
00665   PluginFunctions::setActiveExaminer( examinerId );
00666 
00667   emit PluginMouseEvent(_event );
00668 }
00669 
00670 //-----------------------------------------------------------------------------
00671 
00672 void
00673 Core::slotWheelEvent( QWheelEvent * _event, const std::string & _mode)
00674 {
00675   const QObject* senderPointer = sender();
00676   unsigned int examinerId = 0;
00677 
00678   if ( senderPointer == 0 ) {
00679     std::cerr << "Error : slotWheelEvent directly called! This should only be called by an examiner" << std::endl;
00680   } else {
00681     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00682       if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
00683         examinerId = i;
00684         break;
00685       }
00686     }
00687 
00688   }
00689 
00690   PluginFunctions::setActiveExaminer( examinerId );
00691 
00692   emit PluginWheelEvent(_event , _mode );
00693 }
00694 
00695 //-----------------------------------------------------------------------------
00696 
00697 void
00698 Core::slotAddPickMode( const std::string _mode ) {
00699   if ( OpenFlipper::Options::gui() )
00700     coreWidget_->addPickMode(_mode);
00701 
00702 }
00703 
00704 //-----------------------------------------------------------------------------
00705 
00706 void
00707 Core::slotAddHiddenPickMode( const std::string _mode ) {
00708 
00709   if ( OpenFlipper::Options::gui() )
00710     coreWidget_->addPickMode(_mode,false,1000,false);
00711 
00712 }
00713 
00714 //-----------------------------------------------------------------------------
00715 
00718 void Core::updateView() {
00719 
00720   if ( OpenFlipper::Options::doSlotDebugging() ) {
00721     if ( sender() != 0 ) {
00722       if ( sender()->metaObject() != 0 ) {
00723         emit log(LOGINFO,tr("updateView() called by ") + QString( sender()->metaObject()->className() ) );
00724       }
00725     }
00726   }
00727 
00728   if ( !OpenFlipper::Options::gui() )
00729     return;
00730 
00731   if ( OpenFlipper::Options::restrictFrameRate() ) {
00732 
00733     int elapsed = redrawTime_->elapsed ();
00734 
00735     if ( elapsed < 1000 / OpenFlipper::Options::maxFrameRate() )
00736     {
00737       // redraw time not reached ... waiting for timer event for next redraw
00738       if ( redrawTimer_->isActive() ) {
00739         if ( OpenFlipper::Options::doSlotDebugging() )
00740           emit log(LOGINFO,tr("Too early for redraw! Delaying request from ") +
00741                            QString( sender()->metaObject()->className() ) );
00742         return;
00743       }
00744 
00745       // Start the timer
00746       redrawTimer_->start( (1000 / OpenFlipper::Options::maxFrameRate()) - elapsed);
00747       return;
00748     }
00749     else if ( redrawTimer_->isActive() )
00750         redrawTimer_->stop ();
00751 
00752   }
00753 
00754   redrawTime_->restart ();
00755 
00756   if ( !OpenFlipper::Options::loadingSettings() && !OpenFlipper::Options::redrawDisabled() ) {
00757 
00758     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00759       coreWidget_->examiner_widgets_[i]->updateGL();
00760   }
00761 }
00762 
00763 
00764 
00765 //-----------------------------------------------------------------------------
00766 
00769 void Core::checkScenegraphDirty() {
00770   if ( true )
00771   {
00772     ACG::SceneGraph::CheckDirtyAction action;
00773     ACG::SceneGraph::traverse( root_node_scenegraph_, action );
00774     if ( action.isDirty () )
00775       emit updateView ();
00776   }
00777 }
00778 
00779 //-----------------------------------------------------------------------------
00780 
00781 void Core::restrictFrameRate( bool _enable ) {
00782   OpenFlipper::Options::restrictFrameRate( _enable );
00783 }
00784 
00785 //-----------------------------------------------------------------------------
00786 
00787 void Core::setMaxFrameRate( int _rate ) {
00788   OpenFlipper::Options::maxFrameRate( _rate );
00789   OpenFlipper::Options::restrictFrameRate( true );
00790 
00791   // update Timer to new framerate
00792   scenegraphCheckTimer_->setInterval (1000 / OpenFlipper::Options::maxFrameRate());
00793 }
00794 
00795 //-----------------------------------------------------------------------------
00796 
00797 void
00798 Core::clearAll()
00799 {
00800 
00801   slotDeleteAllObjects();
00802 
00803   emit allCleared();
00804 
00805   slotScriptInfo( "core" , "clearAll()"  );
00806 }
00807 
00808 //-----------------------------------------------------------------------------
00809 
00810 void
00811 Core::exitApplication()
00812 {
00813   QTimer* timer = new QTimer();
00814   connect(timer, SIGNAL(timeout()), this, SLOT(slotExit()));
00815   timer->start(100);
00816 
00817   QApplication::quit();
00818 }
00819 
00820 //-----------------------------------------------------------------------------
00821 
00822 void Core::fullscreen( bool _state ) {
00823   if ( OpenFlipper::Options::gui() )
00824     coreWidget_->setFullscreen(_state);
00825 }
00826 
00827 //-----------------------------------------------------------------------------
00828 
00829 void Core::loggerState(int _state) {
00830   OpenFlipper::Options::LoggerState state = static_cast<OpenFlipper::Options::LoggerState> (_state);
00831   if ( OpenFlipper::Options::gui() &&
00832        (state == OpenFlipper::Options::Hidden ||
00833         state == OpenFlipper::Options::InScene ||
00834         state == OpenFlipper::Options::Normal))
00835     coreWidget_->showLogger(state);
00836 }
00837 
00838 //-----------------------------------------------------------------------------
00839 
00840 void Core::showToolbox( bool _state ) {
00841   if ( OpenFlipper::Options::gui() )
00842     coreWidget_->showToolbox(_state);
00843 }
00844 
00845 void Core::multiViewMode( int _mode ) {
00846   if ( !OpenFlipper::Options::gui() || !OpenFlipper::Options::multiView() )
00847     return;
00848 
00849   switch (_mode)
00850   {
00851     case 0:
00852       coreWidget_->baseLayout_->setMode (QtMultiViewLayout::SingleView);
00853       PluginFunctions::setActiveExaminer(0);
00854       break;
00855     case 1:
00856       coreWidget_->baseLayout_->setMode (QtMultiViewLayout::Grid);
00857       break;
00858     case 2:
00859       coreWidget_->baseLayout_->setMode (QtMultiViewLayout::HSplit);
00860       break;
00861 
00862     default:
00863       emit log(LOGERR,tr("Requested illegal multiview mode!"));
00864   }
00865 
00866 }
00867 
00868 
00869 
00870 
00871 //-----------------------------------------------------------------------------
00872 
00873 void
00874 Core::slotRecentOpen(QAction* _action)
00875 {
00876   QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
00877   for (int i = 0 ; i < recentFiles.size() ; ++i )
00878     if ( recentFiles[i].filename == _action->text() ){
00879       if (recentFiles[i].type == DATA_UNKNOWN)
00880         loadSettings( recentFiles[i].filename );
00881       else{
00882         OpenFlipper::Options::loadingRecentFile(true);
00883         loadObject(recentFiles[i].type, recentFiles[i].filename);
00884         OpenFlipper::Options::loadingRecentFile(false);
00885       }
00886       break;
00887     }
00888 }
00889 
00890 
00891 void
00892 Core::writeOnExit() {
00893   QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00894                                                   OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";
00895 
00896   INIFile ini;
00897   if ( ! ini.connect( inifile ,false) ) {
00898     emit log(LOGERR,tr("Failed to connect to users ini file"));
00899 
00900     if ( ! ini.connect( inifile,true) ) {
00901       emit log(LOGERR,tr("Can not create user ini file"));
00902     } else {
00903       writeApplicationOptions(ini);
00904       ini.disconnect();
00905     }
00906   } else {
00907     writeApplicationOptions(ini);
00908     ini.disconnect();
00909   }
00910 
00911   //store the windowState
00912   if ( OpenFlipper::Options::gui() ) {
00913 
00914     QSettings windowStates(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00915                            OpenFlipper::Options::dirSeparator() +  "WindowStates.dat", QSettings::IniFormat);
00916 
00917     windowStates.setValue("Core/Window/State", coreWidget_->saveState ());
00918     windowStates.setValue("Core/Window/Geometry", coreWidget_->saveGeometry ());
00919 
00920     windowStates.setValue ("Core/ToolSplitter", coreWidget_->toolSplitter_->saveState ());
00921     windowStates.setValue ("Core/LogSplitter", coreWidget_->splitter_->saveState ());
00922 
00923     windowStates.beginGroup ("Core");
00924     windowStates.beginGroup ("LogSlider");
00925     coreWidget_->slidingLogger_->saveState (windowStates);
00926     windowStates.endGroup ();
00927     coreWidget_->toolBox_->saveState (windowStates);
00928     windowStates.endGroup ();
00929   }
00930 
00931   // Call exit for all plugins
00932    for (uint i = 0 ; i < plugins.size() ; ++i) {
00933       BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugins[i].plugin);
00934       if ( basePlugin )
00935           if ( checkSlot( plugins[i].plugin , "exit()" ) )
00936             QMetaObject::invokeMethod(plugins[i].plugin, "exit",  Qt::DirectConnection);
00937    }
00938 }
00939 
00940 void Core::slotExit() {
00941   writeOnExit();
00942 
00943   if (logFile_)
00944     logFile_->close();
00945 
00946   qApp->quit();
00947 }
00948 
00950 void Core::slotLogToFile(Logtype _type, QString _message){
00951 
00952   if (!OpenFlipper::Options::logFileEnabled())
00953     return;
00954 
00955   if (logStream_ == 0){
00956     //check if a logfile has been specified and if the path is valid
00957 
00958     QFileInfo fi( OpenFlipper::Options::logFile() );
00959 
00960     if (OpenFlipper::Options::logFile() == "" || !fi.dir().exists() )
00961         OpenFlipper::Options::logFile(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00962                                                   OpenFlipper::Options::dirSeparator() +  "OpenFlipper.log");
00963 
00964     logFile_ = new QFile( OpenFlipper::Options::logFile() );
00965     if ( logFile_->open(QFile::WriteOnly) ) {
00966         logStream_ = new QTextStream (logFile_);
00967     }else{
00968       emit log(LOGERR, tr("Unable to open logfile!"));
00969       return;
00970     }
00971   }
00972 
00973   switch (_type) {
00974     case LOGINFO:
00975       (*logStream_) << "INFO:"; break;
00976     case LOGOUT:
00977       (*logStream_) << "OUT :"; break;
00978     case LOGWARN:
00979       (*logStream_) << "WARN:"; break;
00980     case LOGERR:
00981       (*logStream_) << "ERR :"; break;
00982   }
00983 
00984   (*logStream_) << _message << "\n" << flush;
00985 
00986 }
00987 
00989 void Core::slotSetSlotDescription(QString      _slotName,   QString _slotDescription,
00990                               QStringList _parameters, QStringList _descriptions)
00991 {
00992   //handle core slots
00993   if (sender() == this){
00994     SlotInfo info;
00995     info.slotName = _slotName;
00996     info.slotDescription = _slotDescription;
00997     info.parameters = _parameters;
00998     info.descriptions = _descriptions;
00999 
01000     coreSlots_.push_back( info );
01001     return;
01002   }
01003 
01004   //handle plugin slots
01005 
01006   //find plugin
01007  PluginInfo* pluginInfo = 0;
01008 
01009   for (uint i=0; i < plugins.size(); i++)
01010     if (plugins[i].plugin == sender())
01011       pluginInfo = &plugins[i];
01012 
01013     if (pluginInfo == 0){
01014       emit log(LOGERR, tr("Unable to set slot-description. Plugin not found!"));
01015     return;
01016   }
01017 
01018   SlotInfo info;
01019   info.slotName = _slotName;
01020   info.slotDescription = _slotDescription;
01021   info.parameters = _parameters;
01022   info.descriptions = _descriptions;
01023 
01024   pluginInfo->slotInfos.append( info );
01025 }
01026 
01028 void Core::slotGetDescription(QString      _function,   QString&     _fnDescription,
01029                               QStringList& _parameters, QStringList& _descriptions )
01030 {
01031   QString pluginName = _function.section(".", 0, 0);
01032   QString slotName   = _function.section(".", 1, 1);
01033 
01034   //handle core slots
01035   if (pluginName == "core"){
01036 
01037     _fnDescription = "";
01038     _parameters.clear();
01039     _descriptions.clear();
01040 
01041     for (int i=0; i < coreSlots_.count(); i++)
01042       if (coreSlots_[i].slotName == slotName){
01043       _fnDescription = coreSlots_[i].slotDescription;
01044       _parameters    = coreSlots_[i].parameters;
01045       _descriptions  = coreSlots_[i].descriptions;
01046       return;
01047       }
01048     return;
01049   }
01050 
01051   //handle plugin slots
01052 
01053   //find plugin
01054   PluginInfo* pluginInfo = 0;
01055 
01056   for (uint i=0; i < plugins.size(); i++)
01057     if (plugins[i].rpcName == pluginName)
01058       pluginInfo = &plugins[i];
01059 
01060   if (pluginInfo == 0){
01061     emit log(LOGERR, tr("Unable to get slot-description. Plugin not found!"));
01062     return;
01063   }
01064 
01065   _fnDescription = "";
01066   _parameters.clear();
01067   _descriptions.clear();
01068 
01069   //find slot
01070   for (int i=0; i < pluginInfo->slotInfos.count(); i++)
01071     if (pluginInfo->slotInfos[i].slotName == slotName){
01072       _fnDescription = pluginInfo->slotInfos[i].slotDescription;
01073       _parameters    = pluginInfo->slotInfos[i].parameters;
01074       _descriptions  = pluginInfo->slotInfos[i].descriptions;
01075       return;
01076     }
01077 }
01078 
01079 void Core::snapshotBaseFileName(const QString& _fname, unsigned int _viewerId ){
01080 
01081   if ( OpenFlipper::Options::gui() ) {
01082     if ( _viewerId >= OpenFlipper::Options::examinerWidgets() ) {
01083       emit log(LOGERR,tr("Unable to snapshotBaseFileName for viewer ") + QString::number(_viewerId) );
01084       return;
01085     }
01086 
01087     PluginFunctions::viewerProperties(_viewerId).snapshotBaseFileName( _fname );
01088   }
01089 
01090 }
01091 
01092 void Core::snapshot( unsigned int _viewerId ){
01093 
01094 
01095   if ( OpenFlipper::Options::gui() ) {
01096     if ( _viewerId >= OpenFlipper::Options::examinerWidgets() ) {
01097       emit log(LOGERR,tr("Unable to create snapshot for viewer ") + QString::number(_viewerId) );
01098       return;
01099     }
01100     coreWidget_->examiner_widgets_[_viewerId]->snapshot();
01101   }
01102 
01103 }
01104 
01105 void Core::applicationSnapshot(){
01106 
01107   if ( OpenFlipper::Options::gui() )
01108     coreWidget_->applicationSnapshot();
01109 }
01110 
01111 void Core::applicationSnapshotName(QString _name){
01112 
01113   if ( OpenFlipper::Options::gui() )
01114     coreWidget_->applicationSnapshotName(_name);
01115 }
01116 
01117 void Core::viewerSnapshot(){
01118 
01119   if ( OpenFlipper::Options::gui() )
01120     coreWidget_->viewerSnapshot();
01121 }
01122 
01123 void Core::resizeViewers(int _width, int _height ){
01124   if ( OpenFlipper::Options::gui() ){
01125 
01126     lastWidth_  = coreWidget_->glView_->width();
01127     lastHeight_ = coreWidget_->glView_->height();
01128 
01129 
01130     //+4,+20 to to get the correct dimension when using snapshotFunction
01131     coreWidget_->glView_->resize(_width+4, _height+20);
01132   }
01133 }
01134 
01135 void Core::resizeApplication(int _width, int _height ){
01136  if ( OpenFlipper::Options::gui() ){
01137 
01138     lastWidth_  = coreWidget_->glView_->width();
01139     lastHeight_ = coreWidget_->glView_->height();
01140 
01141     coreWidget_->resize(_width, _height);
01142  }
01143 }
01144 
01145 void Core::writeVersionNumbers(QString _filename){
01146 
01147 INIFile ini;
01148 
01149   if ( ! ini.connect(_filename,true) ) {
01150     emit log(LOGERR,tr("Failed to connect to _ini file") + _filename);
01151       return;
01152   }
01153 
01154   //add coreVersion
01155   ini.add_section( "Core" );
01156   if ( OpenFlipper::Options::isWindows() )
01157     ini.add_entry( "Core" , "VersionWindows" , OpenFlipper::Options::coreVersion() );
01158   else
01159     ini.add_entry( "Core" , "VersionLinux"   , OpenFlipper::Options::coreVersion() );
01160 
01161   //add pluginVersions
01162   for (uint i=0; i < plugins.size(); i++){
01163     ini.add_section( plugins[i].name );
01164 
01165     if ( OpenFlipper::Options::isWindows() )
01166       ini.add_entry( plugins[i].name , "VersionWindows" , plugins[i].version );
01167     else
01168       ini.add_entry( plugins[i].name , "VersionLinux"   , plugins[i].version );
01169   }
01170 
01171   ini.disconnect();
01172 }
01173 
01174 QList<int> Core::objectList (QString _selection, QStringList _types)
01175 {
01176   QList<int> rv;
01177   DataType ids = 0;
01178   PluginFunctions::IteratorRestriction selection = PluginFunctions::ALL_OBJECTS;
01179 
01180   foreach (QString s, _types)
01181     if (!s.isEmpty ())
01182       ids = typeId (s);
01183   if (_selection == "source")
01184     selection = PluginFunctions::SOURCE_OBJECTS;
01185   else if (_selection == "target")
01186     selection = PluginFunctions::TARGET_OBJECTS;
01187 
01188   for ( PluginFunctions::ObjectIterator o_it(selection, ids) ;
01189                                         o_it != PluginFunctions::objectsEnd(); ++o_it)
01190     rv.append (o_it->id ());
01191   return rv;
01192 }
01193 
01195 void Core::setDescriptions(){
01196 
01197   connect(this, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
01198           this,   SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
01199 
01200   emit setSlotDescription("updateView()", tr("Redraw the contents of the viewer."), QStringList(), QStringList());
01201   emit setSlotDescription("clearAll()", tr("Clear all data objects."), QStringList(), QStringList());
01202   emit setSlotDescription("exitApplication()", tr("Quit OpenFlipper"), QStringList(), QStringList());
01203   emit setSlotDescription("fullscreen(bool)", tr("Enable or disable fullscreen mode"),
01204                            QStringList(tr("enabled")) ,
01205                            QStringList(tr("Enable or disable fullscreen mode")));
01206   emit setSlotDescription("loggerState(int)", tr("Change the logger window state"), QStringList(tr("Change the logger window state")), QStringList());
01207   emit setSlotDescription("showToolbox(bool)", tr("Show or hide toolbox"), QStringList(tr("Show or hide the toolbox")), QStringList());
01208   emit setSlotDescription("multiViewMode(int)", tr("Switch MultiView Mode"),
01209                           QStringList(tr("Mode")), QStringList(tr("0: One Viewer\n 1: Grid \n 2: Horizontal split")));
01210 
01211   emit setSlotDescription("restrictFrameRate(bool)", tr("Restrict FrameRate to MaxFrameRate"),
01212                         QStringList(tr("enabled")), QStringList(tr("restriction switch")));
01213   emit setSlotDescription("setMaxFrameRate(int)", tr("set the maximal framerate (automatically enables framerate restriction)"),
01214                         QStringList(tr("frameRate")), QStringList(tr("Maximum frameRate")));
01215   emit setSlotDescription("snapshotBaseFileName(QString&)", tr("Set a filename for storing snapshots.")
01216                           , QStringList(), QStringList());
01217   emit setSlotDescription("snapshot()", tr("Make a snapshot of the viewer. If no filename"
01218                           " was set using snapshotBaseFileName() the snapshot is stored"
01219                           " in snap.png in the current directory. For every snapshot"
01220                           " a counter is added to the filename."), QStringList(), QStringList());
01221   emit setSlotDescription("resizeViewer(int,int)", tr("Resize the viewer"),
01222                            QString(tr("width,height")).split(","),
01223                            QString(tr("new width for the viewer,new height for the viewer")).split(","));
01224   emit setSlotDescription("writeVersionNumbers(QString)", tr("write the current versions of all plugins to INI file"),
01225                            QStringList(tr("filename")),
01226                            QStringList(tr("fullpath to a file where the versions should be written to.")));
01227   //save slots
01228   emit setSlotDescription("saveObject(int,QString)", tr("Save object to file. If the file exists it will be overwritten."),
01229                            QString(tr("object-id,filename")).split(","),
01230                            QString(tr("id of the object, complete path and filename")).split(","));
01231   emit setSlotDescription("saveObjectTo(int,QString)", tr("Save object to file. The location can be chosen in a dialog. "
01232                           "(only works if GUI is available)"),
01233                            QString(tr("object-id,filename")).split(","),
01234                            QString(tr("id of the object, initial filename for the dialog")).split(","));
01235   emit setSlotDescription("saveAllObjects()", tr("Saves all target objects. "
01236                           "If no filename is available a dialog is shown. (only works if GUI is available)"),QStringList(), QStringList());
01237   emit setSlotDescription("saveAllObjectsTo()", tr("Saves all target objects. The locations can be chosen in dialogs. "
01238                           "(only works if GUI is available)"),QStringList(), QStringList());
01239   emit setSlotDescription("saveSettings()", tr("Show the dialog to save the current setting. (only works if GUI is available)"),QStringList(), QStringList());
01240   //load slots
01241   emit setSlotDescription("loadObject()", tr("Show the dialog to load an object. (only works if GUI is available)"),QStringList(), QStringList());
01242   emit setSlotDescription("getObjectId(QString)", tr("Return identifier of object with specified name. Returns -1 if object was not found."),QStringList(), QStringList());
01243   emit setSlotDescription("loadSettings()", tr("Show the dialog to load settings. (only works if GUI is available)"),QStringList(), QStringList());
01244   emit setSlotDescription("loadSettings(QString)", tr("load settings from file."),QStringList(), QStringList());
01245 
01246   emit setSlotDescription("createWidget(QString,QString)", tr("Create a widget from an ui file"),
01247                           QString(tr("Object name,ui file")).split(","),
01248                           QString(tr("Name of the new widget in script,ui file to load")).split(","));
01249 
01250   emit setSlotDescription("addToolbox(QString,QWidget*)", tr("Add a widget as a toolbox"),
01251                           QString(tr("Toolbox Entry name,Widget")).split(","),
01252                           QString(tr("Name of the new widget in the toolbox,Pointer to the new widget")).split(","));
01253 
01254   emit setSlotDescription("addViewModeToolboxes(QString,QString)", tr("Set toolboxes for a viewmode (This automatically adds the view mode if it does not exist)"),
01255                           QString(tr("Name,Toolbox List")).split(","),
01256                           QString(tr("Name of the Viewmode, ; seperated list of toolboxes visible in this viewmode")).split(","));
01257 
01258   emit setSlotDescription("addViewModeToolbars(QString,QString)", tr("Set toolbars for a viewmode (This automatically adds the view mode if it does not exist)"),
01259                           QString(tr("Name,Toolbar List")).split(","),
01260                           QString(tr("Name of the Viewmode, ; seperated list of toolbars visible in this viewmode")).split(","));
01261 
01262   emit setSlotDescription("objectList(QString,QStringList)", tr("Returns object list"),
01263                           QString(tr("Selection type,Object types")).split(","),
01264                           QString(tr("Type of object selection (all,source,target),Object type (All,PolyMesh,TriangleMesh,...)")).split(";"));
01265 }
01266 
01267 void Core::slotDeleteObject( int _id ){
01268 
01269   if ( _id == -1 )
01270     return;
01271 
01272   // get the node
01273   BaseObject* object = objectRoot_->childExists(_id);
01274 
01275   if ( !object || object == objectRoot_ ) {
01276     std::cerr << "Error while deleting object, does not exist!!" << std::endl;
01277     return;
01278   }
01279 
01280   // remove the whole subtree below this item
01281   object->deleteSubtree();
01282 
01283   // remove the item itself from the parent
01284   object->parent()->removeChild(object);
01285 
01286   // delete it
01287   delete object;
01288 
01289   emit objectDeleted(_id);
01290 
01291   slotObjectUpdated(-1);
01292 }
01293 
01294 void Core::slotDeleteAllObjects( ){
01295 
01296   // Remember ids
01297   std::vector< int > ids;
01298 
01299   BaseObject* current = objectRoot_->next();
01300 
01301   while( current != objectRoot_ ){
01302     ids.push_back( current->id() );
01303     current = current->next();
01304   }
01305 
01306   // remove the whole subtree below the root
01307   objectRoot_->deleteSubtree();
01308 
01309   for ( uint i = 0 ; i < ids.size(); ++i ) {
01310     emit objectDeleted(ids[i]);
01311   }
01312 
01313   slotObjectUpdated(-1);
01314 }
01315 
01316 // //-----------------------------------------------------------------------------
01317 //
01318 // void Core::slotGetPlugin(QString _name, QObject* & _plugin ){
01319 //   for (uint i=0; i < plugins.size(); i++)
01320 //     if (plugins[i].name == _name){
01321 //       _plugin = plugins[i].plugin;
01322 //       return;
01323 //     }
01324 //
01325 //   _plugin = 0;
01326 //   return;
01327 // }
01328 
01329 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .