optionHandling.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: 7334 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-10-07 15:12:17 +0200 (Mi, 07. Okt 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS Core - IMPLEMENTATION of Path and File Handling
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 // -------------------- mview
00056 #include "Core.hh"
00057 // -------------------- ACG
00058 #include <ACG/Scenegraph/DrawModes.hh>
00059 
00060 #include "OpenFlipper/INIFile/INIFile.hh"
00061 #include "OpenFlipper/common/GlobalOptions.hh"
00062 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00063 
00064 //== IMPLEMENTATION ==========================================================
00065 
00066 void Core::applyOptions(){
00067 
00068   if ( OpenFlipper::Options::gui() ) {
00069 
00070     //Init ViewModes
00071     coreWidget_->initViewModes();
00072 
00073     //Set default Viewmode
00074     if (OpenFlipper::Options::defaultToolboxMode() != "")
00075       coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList(), QStringList());
00076     //Set Fullscreen
00077     if ( OpenFlipper::Options::fullScreen() )
00078       coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
00079     else
00080       coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
00081 
00082     // Logger
00083     coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
00084 
00085     // gl mouse cursor
00086     coreWidget_->setGlCursor( OpenFlipper::Options::glMouse() );
00087 
00088     // Prepare Picking Debugger Flag
00089     ACG::SceneGraph::PickTarget target;
00090     if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
00091       target = ACG::SceneGraph::PICK_ANYTHING;
00092     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_VERTEX") {
00093       target = ACG::SceneGraph::PICK_VERTEX;
00094     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_EDGE") {
00095       target = ACG::SceneGraph::PICK_EDGE;
00096     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FACE") {
00097       target = ACG::SceneGraph::PICK_FACE;
00098     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_VERTEX") {
00099       target = ACG::SceneGraph::PICK_FRONT_VERTEX;
00100     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_EDGE") {
00101       target = ACG::SceneGraph::PICK_FRONT_EDGE;
00102     } else {
00103       target = ACG::SceneGraph::PICK_ANYTHING;
00104     }
00105 
00106     //set viewer properties
00107     for (int i=0; i < PluginFunctions::viewers(); i++){
00108 
00109       PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
00110       PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
00111 
00112       //only switch projection here if an object is opened
00113       //this prevents problems when applying options on app start
00114       if ( PluginFunctions::objectCount() > 0 ){ 
00115         if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
00116           PluginFunctions::orthographicProjection(i);
00117         else
00118           PluginFunctions::perspectiveProjection(i);
00119       }
00120     }
00121 
00122     if ( OpenFlipper::Options::multiView() )
00123       coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
00124 
00125 //     if ( OpenFlipper::Options::gridVisible() )
00126 //       gridNode_->show();
00127 //     else
00128 //       gridNode_->hide();
00129 
00130     //set defaultBackgroundColor
00131     QColor c = OpenFlipper::Options::defaultBackgroundColor() ;
00132 
00133     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00134       //wheel zoom factor
00135       PluginFunctions::viewerProperties(i).wheelZoomFactor(OpenFlipper::Options::wheelZoomFactor());
00136       PluginFunctions::viewerProperties(i).wheelZoomFactorShift(OpenFlipper::Options::wheelZoomFactorShift());
00137 
00138       // Picking Debugger
00139       PluginFunctions::viewerProperties(i).renderPicking(OpenFlipper::Options::renderPicking(), target );
00140     }
00141 
00142     //hideToolbox
00143     if (OpenFlipper::Options::hideToolbox()) {
00144 
00145       coreWidget_->showToolbox (false);
00146     }
00147 
00148     //setup logFile
00149     if (logFile_ != 0){
00150 
00151       if (OpenFlipper::Options::logFile() != logFile_->fileName() ){
00152         logFile_->close();
00153         delete logFile_;
00154         logFile_ = 0;
00155         if (logStream_ != 0){
00156           delete logStream_;
00157           logStream_ = 0;
00158         }
00159       }
00160     }
00161 
00162     updateView();
00163 
00164   }
00165 }
00166 
00167 void Core::saveOptions(){
00168   QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00169                                                   OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";
00170 
00171   INIFile ini;
00172   if ( ! ini.connect( inifile ,false) ) {
00173     emit log(LOGERR,tr("Failed to connect to users ini file"));
00174 
00175     if ( ! ini.connect( inifile,true) ) {
00176       emit log(LOGERR,tr("Can not create user ini file"));
00177     } else {
00178       writeApplicationOptions(ini);
00179       ini.disconnect();
00180     }
00181   } else {
00182     writeApplicationOptions(ini);
00183     ini.disconnect();
00184   }
00185 }
00186 
00187 void Core::setupOptions() {
00188 
00189   // Get the Main config dir in the home directory and possibly create it
00190   QDir configDir = QDir::home();
00191 
00192   if ( ! configDir.cd(".OpenFlipper") ) {
00193     emit log(LOGOUT,tr("Creating config Dir ~/.OpenFlipper"));
00194     configDir.mkdir(".OpenFlipper");
00195     if ( ! configDir.cd(".OpenFlipper") ) {
00196       emit log(LOGERR,tr("Unable to create config dir ~/.OpenFlipper"));
00197       return;
00198     }
00199     
00200   }
00201   
00202   // Create a local directory to cache icons
00203   QDir iconCacheDir = configDir;
00204 
00205   // Create a personal Icon cache dir to save for example user added icons
00206   if ( ! iconCacheDir.exists("Icons") ){
00207     configDir.mkdir("Icons");
00208     emit log(LOGOUT,tr("Creating Icon Cache Dir ~/.OpenFlipper/Icons"));    
00209   }
00210   
00211   OpenFlipper::Options::configDir(configDir);
00212 
00213   // Remember the main application directory (assumed to be one above executable Path)
00214   QDir tempDir = QDir(qApp->applicationDirPath());
00215   #ifdef OPENFLIPPER_APPDIR
00216     tempDir.cd(OPENFLIPPER_APPDIR);
00217   #else
00218     tempDir.cd(".." + OpenFlipper::Options::dirSeparator() );
00219   #endif
00220   OpenFlipper::Options::applicationDir(tempDir.absolutePath());
00221 
00222   // Set the standard path to the plugins
00223   #ifdef OPENFLIPPER_PLUGINDIR
00224     tempDir.cd(OPENFLIPPER_PLUGINDIR);
00225   #else
00226     tempDir.cd("Plugins");
00227 
00228     #if defined(WIN32)
00229       tempDir.cd("Windows");
00230     #elif defined(ARCH_DARWIN)
00231       tempDir.cd("Darwin");
00232     #else
00233       tempDir.cd("Linux");
00234     #endif
00235 
00236     if ( OpenFlipper::Options::is64bit() )
00237       tempDir.cd("64");
00238     else
00239       tempDir.cd("32");
00240 
00241     #ifdef WIN32
00242         #ifndef NDEBUG
00243           #define DEBUG
00244         #endif
00245     #endif
00246 
00247     #ifdef DEBUG
00248             tempDir.cd("Debug");
00249     #else
00250             tempDir.cd("Release");
00251     #endif
00252   #endif
00253 
00254   OpenFlipper::Options::pluginDir(tempDir.absolutePath());
00255 
00256   // Set the Path to the shaders
00257   tempDir = QDir(OpenFlipper::Options::applicationDir());
00258   #ifdef OPENFLIPPER_DATADIR
00259     tempDir.cd(OPENFLIPPER_DATADIR);
00260   #endif
00261   tempDir.cd("Shaders");
00262   OpenFlipper::Options::shaderDir(tempDir.absolutePath());
00263 
00264 
00265   // Set the Path to the textures
00266   tempDir = QDir(OpenFlipper::Options::applicationDir());
00267   #ifdef OPENFLIPPER_DATADIR
00268     tempDir.cd(OPENFLIPPER_DATADIR);
00269   #endif
00270   tempDir.cd("Textures");
00271   OpenFlipper::Options::textureDir(tempDir.absolutePath());
00272 
00273   // Set the Path to the Scripts
00274   tempDir = QDir(OpenFlipper::Options::applicationDir());
00275   #ifdef OPENFLIPPER_DATADIR
00276     tempDir.cd(OPENFLIPPER_DATADIR);
00277   #endif
00278   tempDir.cd("Scripts");
00279   OpenFlipper::Options::scriptDir(tempDir.absolutePath());
00280 
00281   // Set the Path to the Icons
00282   tempDir = QDir(OpenFlipper::Options::applicationDir());
00283   #ifdef OPENFLIPPER_DATADIR
00284     tempDir.cd(OPENFLIPPER_DATADIR);
00285   #endif
00286   tempDir.cd("Icons");
00287   OpenFlipper::Options::iconDir(tempDir.absolutePath());
00288   
00289   // Set the Path to the translations
00290   tempDir = QDir(OpenFlipper::Options::applicationDir());
00291   #ifdef OPENFLIPPER_DATADIR
00292     tempDir.cd(OPENFLIPPER_DATADIR);
00293   #endif
00294   tempDir.cd("Translations");
00295   OpenFlipper::Options::translationsDir(tempDir.absolutePath());  
00296 
00297   // Set the Path to the Fonts
00298   tempDir = QDir(OpenFlipper::Options::applicationDir());
00299   #ifdef OPENFLIPPER_DATADIR
00300     tempDir.cd(OPENFLIPPER_DATADIR);
00301   #endif
00302   tempDir.cd("Fonts");
00303   OpenFlipper::Options::fontsDir(tempDir.absolutePath());
00304 
00305   // Set the Path to the License files
00306   tempDir = QDir(OpenFlipper::Options::applicationDir());
00307   #ifdef OPENFLIPPER_DATADIR
00308     tempDir.cd(OPENFLIPPER_DATADIR);
00309   #endif
00310   tempDir.cd("Licenses");
00311   OpenFlipper::Options::licenseDir(tempDir.absolutePath());
00312 
00313   // Set the Path to the Help
00314   tempDir = QDir(OpenFlipper::Options::applicationDir());
00315   #ifdef OPENFLIPPER_DATADIR
00316     tempDir.cd(OPENFLIPPER_DATADIR);
00317   #endif
00318   tempDir.cd("Help");
00319   OpenFlipper::Options::helpDir(tempDir.absolutePath());
00320 
00321   // Set the Path to the main data directory
00322   tempDir = QDir(OpenFlipper::Options::applicationDir());
00323   #ifdef OPENFLIPPER_DATADIR
00324     tempDir.cd(OPENFLIPPER_DATADIR);
00325   #endif
00326   OpenFlipper::Options::dataDir(tempDir.absolutePath());
00327 
00328   QStringList optionFiles;
00329 
00330   // ==============================================================
00331   // Global ini file in the application directory
00332   // ==============================================================
00333   QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00334   if ( globalIni.exists() )
00335     optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00336 
00337   // ==============================================================
00338   // Local ini file in the users home directory
00339   // ==============================================================
00340   QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00341   if ( localIni.exists() )
00342     optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00343 
00344   // Set the previously generated Optionfiles
00345   OpenFlipper::Options::optionFiles(optionFiles);
00346 
00347   // ==============================================================
00348   // Default File open directories
00349   // ==============================================================
00350   // Default to OpenFlippers Texture dir
00351   OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
00352 
00353   // Default to home directory
00354   OpenFlipper::Options::currentDir( QDir::home() );
00355 
00356 
00357   // ==============================================================
00358   // Load Application options from all files available
00359   // ==============================================================
00360 
00361   for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00362 
00363     INIFile _ini;
00364 
00365     if ( ! _ini.connect(optionFiles[i],false) ) {
00366       emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
00367       continue;
00368     }
00369 
00370     readApplicationOptions(_ini);
00371 
00372     _ini.disconnect();
00373   }
00374 
00375 }
00376 
00378 void Core::restoreKeyBindings(){
00379 
00380   QStringList optionFiles;
00381 
00382   // ==============================================================
00383   // Global ini file in the application directory
00384   // ==============================================================
00385   QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00386   if ( globalIni.exists() )
00387     optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00388 
00389   // ==============================================================
00390   // Local ini file in the users home directory
00391   // ==============================================================
00392   QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00393   if ( localIni.exists() )
00394     optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00395 
00396   // Set the previously generated Optionfiles
00397   OpenFlipper::Options::optionFiles(optionFiles);
00398 
00399 
00400   // ==============================================================
00401   // Load Application options from all files available
00402   // ==============================================================
00403 
00404   for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00405 
00406     INIFile _ini;
00407 
00408     if ( ! _ini.connect(optionFiles[i],false) ) {
00409       emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
00410       continue;
00411     }
00412 
00413     if ( OpenFlipper::Options::gui() )
00414       coreWidget_->loadKeyBindings(_ini);
00415 
00416     _ini.disconnect();
00417   }
00418 }
00419 
00420 //=============================================================================

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