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: 8662 $                                                         *
00038  *   $Author: wilden $                                                      *
00039  *   $Date: 2010-03-03 16:54:58 +0100 (Mi, 03. Mär 2010) $                   *
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 #include <QCoreApplication>
00065 
00066 
00067 //== IMPLEMENTATION ==========================================================
00068 
00069 void Core::applyOptions(){
00070 
00071   if ( OpenFlipper::Options::gui() ) {
00072 
00073     //Init ViewModes
00074     coreWidget_->initViewModes();
00075 
00076     //Set default Viewmode
00077     if (OpenFlipper::Options::defaultToolboxMode() != "")
00078       coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList(), QStringList());
00079     //Set Fullscreen
00080     if ( OpenFlipper::Options::fullScreen() )
00081       coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
00082     else
00083       coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
00084 
00085     // Logger
00086     coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
00087 
00088     // Toolbar Size
00089     switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
00090       case 1  : coreWidget_->setIconSize( QSize(16,16) );break;
00091       case 2  : coreWidget_->setIconSize( QSize(32,32) );break;
00092       default : coreWidget_->setIconSize( coreWidget_->defaultIconSize() );
00093     }
00094 
00095     // gl mouse cursor
00096     coreWidget_->setForceNativeCursor( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
00097     
00098     // Prepare Picking Debugger Flag
00099     ACG::SceneGraph::PickTarget target;
00100     if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
00101       target = ACG::SceneGraph::PICK_ANYTHING;
00102     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_VERTEX") {
00103       target = ACG::SceneGraph::PICK_VERTEX;
00104     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_EDGE") {
00105       target = ACG::SceneGraph::PICK_EDGE;
00106     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FACE") {
00107       target = ACG::SceneGraph::PICK_FACE;
00108     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_VERTEX") {
00109       target = ACG::SceneGraph::PICK_FRONT_VERTEX;
00110     } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_EDGE") {
00111       target = ACG::SceneGraph::PICK_FRONT_EDGE;
00112     } else {
00113       target = ACG::SceneGraph::PICK_ANYTHING;
00114     }
00115 
00116     //set viewer properties
00117     for (int i=0; i < PluginFunctions::viewers(); i++){
00118 
00119       PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
00120       PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
00121 
00122       //only switch projection here if an object is opened
00123       //this prevents problems when applying options on app start
00124       if ( PluginFunctions::objectCount() > 0 ){ 
00125         if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
00126           PluginFunctions::orthographicProjection(i);
00127         else
00128           PluginFunctions::perspectiveProjection(i);
00129       }
00130     }
00131 
00132     if ( OpenFlipper::Options::multiView() )
00133       coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
00134 
00135 //     if ( OpenFlipper::Options::gridVisible() )
00136 //       gridNode_->show();
00137 //     else
00138 //       gridNode_->hide();
00139 
00140     //set defaultBackgroundColor
00141     QColor c =  OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
00142 
00143     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00144       //wheel zoom factor
00145       PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor").toDouble() );
00146       PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift").toDouble() );
00147 
00148       // Picking Debugger
00149       PluginFunctions::viewerProperties(i).renderPicking(OpenFlipper::Options::renderPicking(), target );
00150     }
00151 
00152     //hideToolbox
00153     if (OpenFlipper::Options::hideToolbox()) {
00154 
00155       coreWidget_->showToolbox (false);
00156     }
00157 
00158     //setup logFile
00159     if (logFile_ != 0){
00160 
00161       if (  OpenFlipperSettings().value("Core/Log/logFile").toString() != logFile_->fileName() ){
00162         logFile_->close();
00163         delete logFile_;
00164         logFile_ = 0;
00165         if (logStream_ != 0){
00166           delete logStream_;
00167           logStream_ = 0;
00168         }
00169       }
00170     }
00171 
00172     updateView();
00173 
00174   }
00175 }
00176 
00177 void Core::saveOptions(){
00178   QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
00179                                                   OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";
00180 
00181   INIFile ini;
00182   if ( ! ini.connect( inifile ,false) ) {
00183     emit log(LOGERR,tr("Failed to connect to users ini file"));
00184 
00185     if ( ! ini.connect( inifile,true) ) {
00186       emit log(LOGERR,tr("Can not create user ini file"));
00187     } else {
00188       writeApplicationOptions(ini);
00189       ini.disconnect();
00190     }
00191   } else {
00192     writeApplicationOptions(ini);
00193     ini.disconnect();
00194   }
00195 }
00196 
00197 void Core::setupOptions() {
00198 
00199   // initialize the Settings:
00200   OpenFlipper::Options::initializeSettings();
00201 
00202   QStringList optionFiles;
00203 
00204   // ==============================================================
00205   // Global ini file in the application directory
00206   // ==============================================================
00207   QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00208   if ( globalIni.exists() )
00209     optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00210 
00211   // ==============================================================
00212   // Local ini file in the users home directory
00213   // ==============================================================
00214   QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00215   if ( localIni.exists() )
00216     optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00217 
00218   // Set the previously generated Optionfiles
00219   OpenFlipper::Options::optionFiles(optionFiles);
00220 
00221   // ==============================================================
00222   // Default File open directories
00223   // ==============================================================
00224   // Default to OpenFlippers Texture dir
00225   OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
00226 
00227   // Default to home directory
00228   OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
00229 
00230   // ==============================================================
00231   // Load Application options from all files available
00232   // ==============================================================
00233 
00234   for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00235 
00236     INIFile _ini;
00237 
00238     if ( ! _ini.connect(optionFiles[i],false) ) {
00239       emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
00240       continue;
00241     }
00242 
00243     readApplicationOptions(_ini);
00244 
00245     _ini.disconnect();
00246   }
00247 
00248 }
00249 
00251 void Core::restoreKeyBindings(){
00252 
00253   QStringList optionFiles;
00254 
00255   // ==============================================================
00256   // Global ini file in the application directory
00257   // ==============================================================
00258   QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00259   if ( globalIni.exists() )
00260     optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00261 
00262   // ==============================================================
00263   // Local ini file in the users home directory
00264   // ==============================================================
00265   QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00266   if ( localIni.exists() )
00267     optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
00268 
00269   // Set the previously generated Optionfiles
00270   OpenFlipper::Options::optionFiles(optionFiles);
00271 
00272 
00273   // ==============================================================
00274   // Load Application options from all files available
00275   // ==============================================================
00276 
00277   for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
00278 
00279     INIFile _ini;
00280 
00281     if ( ! _ini.connect(optionFiles[i],false) ) {
00282       emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
00283       continue;
00284     }
00285 
00286     if ( OpenFlipper::Options::gui() )
00287       coreWidget_->loadKeyBindings(_ini);
00288 
00289     _ini.disconnect();
00290   }
00291 }
00292 
00293 //=============================================================================

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