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

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