optionHandling.cc 11.1 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41
\*===========================================================================*/

42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58




//=============================================================================
//
//  CLASS Core - IMPLEMENTATION of Path and File Handling
//
//=============================================================================


//== INCLUDES =================================================================

// -------------------- mview
#include "Core.hh"
// -------------------- ACG
59 60


Jan Möbius's avatar
Jan Möbius committed
61
//== IMPLEMENTATION ==========================================================
62 63 64 65

void Core::applyOptions(){

  if ( OpenFlipper::Options::gui() ) {
Jan Möbius's avatar
Jan Möbius committed
66

67 68
    //Init ViewModes
    coreWidget_->initViewModes();
Jan Möbius's avatar
Jan Möbius committed
69

70 71 72 73 74 75
    //Set default Viewmode (note: This always resets all toolboxes and should be skipped
    // here. Setting the initial view mode is instead done when initializing the core
    // and reading the ini-files.)
    //if (OpenFlipper::Options::currentViewMode() != "")
    //  coreWidget_->slotChangeView(OpenFlipper::Options::currentViewMode(), QStringList(), QStringList(), QStringList());
      
76
    //Set Fullscreen
77
    if ( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() )
78
      coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
79
    else
80
      coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
Jan Möbius's avatar
Jan Möbius committed
81

82
    // Logger
83
    coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
Jan Möbius's avatar
Jan Möbius committed
84

Dirk Wilden's avatar
Dirk Wilden committed
85 86 87 88 89 90 91
    // Toolbar Size
    switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
      case 1  : coreWidget_->setIconSize( QSize(16,16) );break;
      case 2  : coreWidget_->setIconSize( QSize(32,32) );break;
      default : coreWidget_->setIconSize( coreWidget_->defaultIconSize() );
    }

Jan Möbius's avatar
Jan Möbius committed
92
    // gl mouse cursor
93
    coreWidget_->setForceNativeCursor( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
94
    
95 96 97
    //set viewer properties
    for (int i=0; i < PluginFunctions::viewers(); i++){

98
      // PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
99
      PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
100
      PluginFunctions::allowRotation(!OpenFlipper::Options::defaultLockRotation(i),i);
101

102 103
      //only switch projection here if an object is opened
      //this prevents problems when applying options on app start
104 105
      if ( PluginFunctions::objectCount() > 0 ){
        if ( OpenFlipper::Options::defaultPerspectiveProjectionMode(i)  )
106
          PluginFunctions::perspectiveProjection(i);
107 108
        else
          PluginFunctions::orthographicProjection(i);
109
      }
110 111
    }

112
    if ( OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() )
113
      coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
114

115 116

    // toolbox orientation
117
    coreWidget_->setToolBoxOrientationOnTheRight(OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool());
118

119
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
120
      //wheel zoom factor
121 122
      PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor",1).toDouble() );
      PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift",0.2).toDouble() );
123
      PluginFunctions::viewerProperties(i).wheelInvert( OpenFlipperSettings().value("Core/Mouse/Wheel/Invert",false).toBool() );
Jan Möbius's avatar
Jan Möbius committed
124
    }
125

126
    //hideToolbox
127
    if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() ) 
Jan Möbius's avatar
Jan Möbius committed
128
      coreWidget_->showToolbox (false);
Jan Möbius's avatar
Jan Möbius committed
129

Dirk Wilden's avatar
Dirk Wilden committed
130 131 132
    //setup logFile
    if (logFile_ != 0){

133
      if (  OpenFlipperSettings().value("Core/Log/logFile").toString() != logFile_->fileName() ){
Dirk Wilden's avatar
Dirk Wilden committed
134 135 136 137 138 139 140 141 142
        logFile_->close();
        delete logFile_;
        logFile_ = 0;
        if (logStream_ != 0){
          delete logStream_;
          logStream_ = 0;
        }
      }
    }
143

144
    updateView();
Jan Möbius's avatar
Jan Möbius committed
145

146 147 148
  }
}

149
void Core::saveOptions(){
Jan Möbius's avatar
Jan Möbius committed
150
  QString inifile = OpenFlipper::Options::configDirStr() +  "OpenFlipper.ini";
151 152 153

  INIFile ini;
  if ( ! ini.connect( inifile ,false) ) {
154
    emit log(LOGERR,tr("Failed to connect to users ini file"));
Jan Möbius's avatar
Jan Möbius committed
155

156
    if ( ! ini.connect( inifile,true) ) {
157
      emit log(LOGERR,tr("Can not create user ini file"));
158 159 160 161 162 163 164
    } else {
      writeApplicationOptions(ini);
      ini.disconnect();
    }
  } else {
    writeApplicationOptions(ini);
    ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
165
  }
166 167
}

168
void Core::setupOptions() {
Jan Möbius's avatar
Jan Möbius committed
169

Jan Möbius's avatar
Jan Möbius committed
170 171
  // initialize the Settings:
  OpenFlipper::Options::initializeSettings();
172

173
  QStringList optionFiles;
Jan Möbius's avatar
Jan Möbius committed
174

175 176 177 178
  // ==============================================================
  // Global ini file in the application directory
  // ==============================================================
  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
Jan Möbius's avatar
Jan Möbius committed
179 180 181
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

182 183 184 185
  // ==============================================================
  // Local ini file in the users home directory
  // ==============================================================
  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
Jan Möbius's avatar
Jan Möbius committed
186 187 188
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

189
  // Set the previously generated option files
190
  OpenFlipper::Options::optionFiles(optionFiles);
Jan Möbius's avatar
Jan Möbius committed
191

192 193 194 195 196 197 198
  // ==============================================================
  // Default File open directories
  // ==============================================================
  // Default to OpenFlippers Texture dir
  OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());

  // Default to home directory
199
  OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
Jan Möbius's avatar
Jan Möbius committed
200

201 202 203
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
Jan Möbius's avatar
Jan Möbius committed
204

205
  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
Jan Möbius's avatar
Jan Möbius committed
206

207
    INIFile _ini;
Jan Möbius's avatar
Jan Möbius committed
208

209
    if ( ! _ini.connect(optionFiles[i],false) ) {
210
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
211
      continue;
Jan Möbius's avatar
Jan Möbius committed
212 213
    }

214
    readApplicationOptions(_ini);
Jan Möbius's avatar
Jan Möbius committed
215

216 217
    _ini.disconnect();
  }
Jan Möbius's avatar
Jan Möbius committed
218

219 220
}

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
/// restore key Assignments that were saved in config files
void Core::restoreKeyBindings(){

  QStringList optionFiles;

  // ==============================================================
  // Global ini file in the application directory
  // ==============================================================
  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

  // ==============================================================
  // Local ini file in the users home directory
  // ==============================================================
  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);


  // ==============================================================
  // Load Application options from all files available
  // ==============================================================

  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {

    INIFile _ini;

    if ( ! _ini.connect(optionFiles[i],false) ) {
253
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
254 255 256 257 258 259 260 261 262 263
      continue;
    }

    if ( OpenFlipper::Options::gui() )
      coreWidget_->loadKeyBindings(_ini);

    _ini.disconnect();
  }
}

264
//=============================================================================