optionHandling.cc 12.9 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
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
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
   
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59




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


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

// -------------------- mview
#include "Core.hh"
// -------------------- ACG
#include <ACG/Scenegraph/DrawModes.hh>

60
61
#include <OpenFlipper/INIFile/INIFile.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
62
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Jan Möbius's avatar
   
Jan Möbius committed
63

64
65
66
#include <QCoreApplication>


Jan Möbius's avatar
Jan Möbius committed
67
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
   
Jan Möbius committed
68
69
70
71

void Core::applyOptions(){

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

Jan Möbius's avatar
   
Jan Möbius committed
73
74
    //Init ViewModes
    coreWidget_->initViewModes();
Jan Möbius's avatar
Jan Möbius committed
75

76
77
78
79
80
81
    //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());
      
Jan Möbius's avatar
   
Jan Möbius committed
82
    //Set Fullscreen
Jan Möbius's avatar
Jan Möbius committed
83
    if ( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() )
84
      coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
Dirk Wilden's avatar
Dirk Wilden committed
85
    else
86
      coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
Jan Möbius's avatar
Jan Möbius committed
87

88
    // Logger
Jan Möbius's avatar
Jan Möbius committed
89
    coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
Jan Möbius's avatar
Jan Möbius committed
90

Dirk Wilden's avatar
Dirk Wilden committed
91
92
93
94
95
96
97
    // 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
Dennis:    
Jan Möbius committed
98
    // gl mouse cursor
99
    coreWidget_->setForceNativeCursor( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
100
    
101
102
    QString pickRenderMode =  OpenFlipperSettings().value("Core/Debug/Picking/RenderPickingMode",QString("PICK_ANYTHING")).toString();
    
Jan Möbius's avatar
Jan Möbius committed
103
    // Prepare Picking Debugger Flag
104
    ACG::SceneGraph::PickTarget target;
105
    if ( pickRenderMode == "PICK_ANYTHING") {
106
      target = ACG::SceneGraph::PICK_ANYTHING;
107
    } else if ( pickRenderMode == "PICK_VERTEX") {
108
      target = ACG::SceneGraph::PICK_VERTEX;
109
    } else if ( pickRenderMode == "PICK_EDGE") {
110
      target = ACG::SceneGraph::PICK_EDGE;
Henrik Zimmer's avatar
Henrik Zimmer committed
111
112
    } else if ( pickRenderMode == "PICK_SPLINE") {
      target = ACG::SceneGraph::PICK_SPLINE;
113
    } else if ( pickRenderMode == "PICK_FACE") {
114
      target = ACG::SceneGraph::PICK_FACE;
115
    } else if ( pickRenderMode == "PICK_FRONT_VERTEX") {
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
116
      target = ACG::SceneGraph::PICK_FRONT_VERTEX;
117
    } else if ( pickRenderMode == "PICK_FRONT_EDGE") {
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
118
      target = ACG::SceneGraph::PICK_FRONT_EDGE;
119
    } else {
120
      std::cerr << "Error : optionHandling unable to find pick mode!!! " << pickRenderMode.toStdString() << std::endl;
121
122
      target = ACG::SceneGraph::PICK_ANYTHING;
    }
Jan Möbius's avatar
Jan Möbius committed
123

124
125
126
    //set viewer properties
    for (int i=0; i < PluginFunctions::viewers(); i++){

127
      // PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
128
      PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
129
      PluginFunctions::allowRotation(!OpenFlipper::Options::defaultLockRotation(i),i);
130

131
132
      //only switch projection here if an object is opened
      //this prevents problems when applying options on app start
133
134
      if ( PluginFunctions::objectCount() > 0 ){
        if ( OpenFlipper::Options::defaultPerspectiveProjectionMode(i)  )
135
          PluginFunctions::perspectiveProjection(i);
136
137
        else
          PluginFunctions::orthographicProjection(i);
138
      }
139
140
    }

Jan Möbius's avatar
Jan Möbius committed
141
    if ( OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() )
142
      coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
143

144
145

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

148
149
    // Update pick toolbar settings
    coreWidget_->updatePickToolbar();
150

151
    //set defaultBackgroundColor
152
    QColor c =  OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
Jan Möbius's avatar
Jan Möbius committed
153

154
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
155
      //wheel zoom factor
156
157
      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() );
Jan Möbius's avatar
Jan Möbius committed
158
159

      // Picking Debugger
160
      PluginFunctions::viewerProperties(i).renderPicking( OpenFlipperSettings().value("Core/Debug/Picking/RenderPicking",false).toBool() , target );
161
162
163
      
      // Depth Debugger
      PluginFunctions::viewerProperties(i).renderDepthImage( OpenFlipperSettings().value("Core/Debug/Picking/RenderDepthImage",false).toBool() );
Jan Möbius's avatar
Jan Möbius committed
164
    }
165

Jan Möbius's avatar
   
Jan Möbius committed
166
    //hideToolbox
Jan Möbius's avatar
Jan Möbius committed
167
    if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() ) 
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
168
      coreWidget_->showToolbox (false);
Jan Möbius's avatar
Jan Möbius committed
169

Dirk Wilden's avatar
Dirk Wilden committed
170
171
172
    //setup logFile
    if (logFile_ != 0){

Jan Möbius's avatar
Jan Möbius committed
173
      if (  OpenFlipperSettings().value("Core/Log/logFile").toString() != logFile_->fileName() ){
Dirk Wilden's avatar
Dirk Wilden committed
174
175
176
177
178
179
180
181
182
        logFile_->close();
        delete logFile_;
        logFile_ = 0;
        if (logStream_ != 0){
          delete logStream_;
          logStream_ = 0;
        }
      }
    }
183

Jan Möbius's avatar
   
Jan Möbius committed
184
    updateView();
Jan Möbius's avatar
Jan Möbius committed
185

Jan Möbius's avatar
   
Jan Möbius committed
186
187
188
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
189
void Core::saveOptions(){
Jan Möbius's avatar
Jan Möbius committed
190
  QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
Dirk Wilden's avatar
Dirk Wilden committed
191
192
193
194
                                                  OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";

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

Dirk Wilden's avatar
Dirk Wilden committed
197
    if ( ! ini.connect( inifile,true) ) {
198
      emit log(LOGERR,tr("Can not create user ini file"));
Dirk Wilden's avatar
Dirk Wilden committed
199
200
201
202
203
204
205
    } else {
      writeApplicationOptions(ini);
      ini.disconnect();
    }
  } else {
    writeApplicationOptions(ini);
    ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
206
  }
Dirk Wilden's avatar
Dirk Wilden committed
207
208
}

Jan Möbius's avatar
   
Jan Möbius committed
209
void Core::setupOptions() {
Jan Möbius's avatar
Jan Möbius committed
210

Jan Möbius's avatar
Jan Möbius committed
211
212
  // initialize the Settings:
  OpenFlipper::Options::initializeSettings();
213

Jan Möbius's avatar
   
Jan Möbius committed
214
  QStringList optionFiles;
Jan Möbius's avatar
Jan Möbius committed
215

Jan Möbius's avatar
   
Jan Möbius committed
216
217
218
219
  // ==============================================================
  // 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
220
221
222
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
223
224
225
226
  // ==============================================================
  // 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
227
228
229
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
230
231
  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);
Jan Möbius's avatar
Jan Möbius committed
232

233
234
235
236
237
238
239
  // ==============================================================
  // Default File open directories
  // ==============================================================
  // Default to OpenFlippers Texture dir
  OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());

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

Jan Möbius's avatar
   
Jan Möbius committed
242
243
244
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
Jan Möbius's avatar
Jan Möbius committed
245

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

Jan Möbius's avatar
   
Jan Möbius committed
248
    INIFile _ini;
Jan Möbius's avatar
Jan Möbius committed
249

Jan Möbius's avatar
   
Jan Möbius committed
250
    if ( ! _ini.connect(optionFiles[i],false) ) {
251
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
Jan Möbius's avatar
   
Jan Möbius committed
252
      continue;
Jan Möbius's avatar
Jan Möbius committed
253
254
    }

Jan Möbius's avatar
   
Jan Möbius committed
255
    readApplicationOptions(_ini);
Jan Möbius's avatar
Jan Möbius committed
256

Jan Möbius's avatar
   
Jan Möbius committed
257
258
    _ini.disconnect();
  }
Jan Möbius's avatar
Jan Möbius committed
259

Jan Möbius's avatar
   
Jan Möbius committed
260
261
}

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/// 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) ) {
294
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
295
296
297
298
299
300
301
302
303
304
      continue;
    }

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

    _ini.disconnect();
  }
}

Jan Möbius's avatar
   
Jan Möbius committed
305
//=============================================================================