optionHandling.cc 15.4 KB
Newer Older
1
2
3
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
39
40
41
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           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/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
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
60
61




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


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

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

#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

Jan Möbius's avatar
Jan Möbius committed
64
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
   
Jan Möbius committed
65
66
67
68

void Core::applyOptions(){

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

Jan Möbius's avatar
   
Jan Möbius committed
70
71
    //Init ViewModes
    coreWidget_->initViewModes();
Jan Möbius's avatar
Jan Möbius committed
72

Jan Möbius's avatar
   
Jan Möbius committed
73
74
    //Set default Viewmode
    if (OpenFlipper::Options::defaultToolboxMode() != "")
75
      coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList(), QStringList());
Jan Möbius's avatar
   
Jan Möbius committed
76
    //Set Fullscreen
Dirk Wilden's avatar
Dirk Wilden committed
77
    if ( OpenFlipper::Options::fullScreen() )
78
      coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
Dirk Wilden's avatar
Dirk Wilden committed
79
    else
80
      coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
Jan Möbius's avatar
Jan Möbius committed
81

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

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
85
86
87
    // gl mouse cursor
    coreWidget_->setGlCursor( OpenFlipper::Options::glMouse() );

Jan Möbius's avatar
Jan Möbius committed
88
    // Prepare Picking Debugger Flag
89
90
91
92
93
94
95
96
97
    ACG::SceneGraph::PickTarget target;
    if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
      target = ACG::SceneGraph::PICK_ANYTHING;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_VERTEX") {
      target = ACG::SceneGraph::PICK_VERTEX;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_EDGE") {
      target = ACG::SceneGraph::PICK_EDGE;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FACE") {
      target = ACG::SceneGraph::PICK_FACE;
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
98
99
100
101
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_VERTEX") {
      target = ACG::SceneGraph::PICK_FRONT_VERTEX;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_EDGE") {
      target = ACG::SceneGraph::PICK_FRONT_EDGE;
102
103
104
    } else {
      target = ACG::SceneGraph::PICK_ANYTHING;
    }
Jan Möbius's avatar
Jan Möbius committed
105

106
107
108
109
110
111
    //set viewer properties
    for (int i=0; i < PluginFunctions::viewers(); i++){

      PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
      PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );

112
113
114
      //only switch projection here if an object is opened
      //this prevents problems when applying options on app start
      if ( PluginFunctions::objectCount() > 0 ){ 
115
116
117
118
        if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
          PluginFunctions::orthographicProjection(i);
        else
          PluginFunctions::perspectiveProjection(i);
119
      }
120
121
    }

122
    if ( OpenFlipper::Options::multiView() )
123
      coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
124

125
126
127
128
//     if ( OpenFlipper::Options::gridVisible() )
//       gridNode_->show();
//     else
//       gridNode_->hide();
129

130
131
    //set defaultBackgroundColor
    QColor c = OpenFlipper::Options::defaultBackgroundColor() ;
Jan Möbius's avatar
Jan Möbius committed
132

133
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
134
      //wheel zoom factor
Dirk Wilden's avatar
Dirk Wilden committed
135
136
      PluginFunctions::viewerProperties(i).wheelZoomFactor(OpenFlipper::Options::wheelZoomFactor());
      PluginFunctions::viewerProperties(i).wheelZoomFactorShift(OpenFlipper::Options::wheelZoomFactorShift());
Jan Möbius's avatar
Jan Möbius committed
137
138

      // Picking Debugger
139
      PluginFunctions::viewerProperties(i).renderPicking(OpenFlipper::Options::renderPicking(), target );
Jan Möbius's avatar
Jan Möbius committed
140
    }
141

Jan Möbius's avatar
   
Jan Möbius committed
142
143
    //hideToolbox
    if (OpenFlipper::Options::hideToolbox()) {
144

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
145
      coreWidget_->showToolbox (false);
Jan Möbius's avatar
   
Jan Möbius committed
146
    }
Jan Möbius's avatar
Jan Möbius committed
147

Dirk Wilden's avatar
Dirk Wilden committed
148
149
150
151
152
153
154
155
156
157
158
159
160
    //setup logFile
    if (logFile_ != 0){

      if (OpenFlipper::Options::logFile() != logFile_->fileName() ){
        logFile_->close();
        delete logFile_;
        logFile_ = 0;
        if (logStream_ != 0){
          delete logStream_;
          logStream_ = 0;
        }
      }
    }
161

Jan Möbius's avatar
   
Jan Möbius committed
162
    updateView();
Jan Möbius's avatar
Jan Möbius committed
163

Jan Möbius's avatar
   
Jan Möbius committed
164
165
166
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
167
void Core::saveOptions(){
Jan Möbius's avatar
Jan Möbius committed
168
  QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
Dirk Wilden's avatar
Dirk Wilden committed
169
170
171
172
                                                  OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";

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

Dirk Wilden's avatar
Dirk Wilden committed
175
    if ( ! ini.connect( inifile,true) ) {
176
      emit log(LOGERR,tr("Can not create user ini file"));
Dirk Wilden's avatar
Dirk Wilden committed
177
178
179
180
181
182
183
    } else {
      writeApplicationOptions(ini);
      ini.disconnect();
    }
  } else {
    writeApplicationOptions(ini);
    ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
184
  }
Dirk Wilden's avatar
Dirk Wilden committed
185
186
}

Jan Möbius's avatar
   
Jan Möbius committed
187
void Core::setupOptions() {
Jan Möbius's avatar
Jan Möbius committed
188

Jan Möbius's avatar
Jan Möbius committed
189
190
191
  // initialize the Settings:
  OpenFlipper::Options::initializeSettings();
  
Jan Möbius's avatar
   
Jan Möbius committed
192
  // Get the Main config dir in the home directory and possibly create it
Jan Möbius's avatar
Jan Möbius committed
193
194
  QDir configDir = QDir::home();

Jan Möbius's avatar
   
Jan Möbius committed
195
  if ( ! configDir.cd(".OpenFlipper") ) {
196
    emit log(LOGOUT,tr("Creating config Dir ~/.OpenFlipper"));
Jan Möbius's avatar
   
Jan Möbius committed
197
198
    configDir.mkdir(".OpenFlipper");
    if ( ! configDir.cd(".OpenFlipper") ) {
199
      emit log(LOGERR,tr("Unable to create config dir ~/.OpenFlipper"));
Jan Möbius's avatar
Jan Möbius committed
200
      return;
Jan Möbius's avatar
   
Jan Möbius committed
201
    }
202
    
Jan Möbius's avatar
   
Jan Möbius committed
203
  }
204
205
206
207
208
209
210
211
212
213
  
  // Create a local directory to cache icons
  QDir iconCacheDir = configDir;

  // Create a personal Icon cache dir to save for example user added icons
  if ( ! iconCacheDir.exists("Icons") ){
    configDir.mkdir("Icons");
    emit log(LOGOUT,tr("Creating Icon Cache Dir ~/.OpenFlipper/Icons"));    
  }
  
Jan Möbius's avatar
   
Jan Möbius committed
214
  OpenFlipper::Options::configDir(configDir);
Jan Möbius's avatar
Jan Möbius committed
215

Jan Möbius's avatar
   
Jan Möbius committed
216
217
  // Remember the main application directory (assumed to be one above executable Path)
  QDir tempDir = QDir(qApp->applicationDirPath());
218
219
220
221
222
  #ifdef OPENFLIPPER_APPDIR
    tempDir.cd(OPENFLIPPER_APPDIR);
  #else
    tempDir.cd(".." + OpenFlipper::Options::dirSeparator() );
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
223
  OpenFlipper::Options::applicationDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
224

Jan Möbius's avatar
   
Jan Möbius committed
225
  // Set the standard path to the plugins
226
227
228
229
230
  #ifdef OPENFLIPPER_PLUGINDIR
    tempDir.cd(OPENFLIPPER_PLUGINDIR);
  #else
    tempDir.cd("Plugins");

231
232
233
234
235
236
237
238
    #if defined(WIN32)
      tempDir.cd("Windows");
    #elif defined(ARCH_DARWIN)
      tempDir.cd("Darwin");
    #else
      tempDir.cd("Linux");
    #endif

239
240
    if ( OpenFlipper::Options::is64bit() )
      tempDir.cd("64");
241
242
    else
      tempDir.cd("32");
243
244

    #ifdef WIN32
245
246
        #ifndef NDEBUG
          #define DEBUG
247
        #endif
248
249
250
251
    #endif

    #ifdef DEBUG
            tempDir.cd("Debug");
252
    #else
253
            tempDir.cd("Release");
254
255
    #endif
  #endif
Jan Möbius's avatar
Jan Möbius committed
256

Jan Möbius's avatar
   
Jan Möbius committed
257
  OpenFlipper::Options::pluginDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
258

Jan Möbius's avatar
   
Jan Möbius committed
259
260
  // Set the Path to the shaders
  tempDir = QDir(OpenFlipper::Options::applicationDir());
261
262
263
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
264
265
  tempDir.cd("Shaders");
  OpenFlipper::Options::shaderDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
266
267


Jan Möbius's avatar
   
Jan Möbius committed
268
269
  // Set the Path to the textures
  tempDir = QDir(OpenFlipper::Options::applicationDir());
270
271
272
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
273
274
  tempDir.cd("Textures");
  OpenFlipper::Options::textureDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
275

Jan Möbius's avatar
Jan Möbius committed
276
277
278
279
280
281
282
283
  // Set the Path to the Scripts
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
  tempDir.cd("Scripts");
  OpenFlipper::Options::scriptDir(tempDir.absolutePath());

Jan Möbius's avatar
   
Jan Möbius committed
284
285
  // Set the Path to the Icons
  tempDir = QDir(OpenFlipper::Options::applicationDir());
286
287
288
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
289
290
  tempDir.cd("Icons");
  OpenFlipper::Options::iconDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
291
292
293
294
295
296
297
  
  // Set the Path to the translations
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
  tempDir.cd("Translations");
Jan Möbius's avatar
Jan Möbius committed
298
  OpenFlipper::Options::translationsDir(tempDir.absolutePath());  
Jan Möbius's avatar
Jan Möbius committed
299

Jan Möbius's avatar
Jan Möbius committed
300
301
  // Set the Path to the Fonts
  tempDir = QDir(OpenFlipper::Options::applicationDir());
302
303
304
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
Jan Möbius committed
305
306
307
  tempDir.cd("Fonts");
  OpenFlipper::Options::fontsDir(tempDir.absolutePath());

308
309
310
311
312
313
314
315
  // Set the Path to the License files
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
  tempDir.cd("Licenses");
  OpenFlipper::Options::licenseDir(tempDir.absolutePath());

316
317
318
319
320
321
322
323
  // Set the Path to the Help
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
  tempDir.cd("Help");
  OpenFlipper::Options::helpDir(tempDir.absolutePath());

324
325
326
327
328
329
330
  // Set the Path to the main data directory
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
  OpenFlipper::Options::dataDir(tempDir.absolutePath());

Jan Möbius's avatar
   
Jan Möbius committed
331
  QStringList optionFiles;
Jan Möbius's avatar
Jan Möbius committed
332

Jan Möbius's avatar
   
Jan Möbius committed
333
334
335
336
  // ==============================================================
  // 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
337
338
339
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
340
341
342
343
  // ==============================================================
  // 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
344
345
346
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
347
348
  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);
Jan Möbius's avatar
Jan Möbius committed
349

350
351
352
353
354
355
356
357
358
  // ==============================================================
  // Default File open directories
  // ==============================================================
  // Default to OpenFlippers Texture dir
  OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());

  // Default to home directory
  OpenFlipper::Options::currentDir( QDir::home() );

Jan Möbius's avatar
Jan Möbius committed
359

Jan Möbius's avatar
   
Jan Möbius committed
360
361
362
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
Jan Möbius's avatar
Jan Möbius committed
363

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

Jan Möbius's avatar
   
Jan Möbius committed
366
    INIFile _ini;
Jan Möbius's avatar
Jan Möbius committed
367

Jan Möbius's avatar
   
Jan Möbius committed
368
    if ( ! _ini.connect(optionFiles[i],false) ) {
369
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
Jan Möbius's avatar
   
Jan Möbius committed
370
      continue;
Jan Möbius's avatar
Jan Möbius committed
371
372
    }

Jan Möbius's avatar
   
Jan Möbius committed
373
    readApplicationOptions(_ini);
Jan Möbius's avatar
Jan Möbius committed
374

Jan Möbius's avatar
   
Jan Möbius committed
375
376
    _ini.disconnect();
  }
Jan Möbius's avatar
Jan Möbius committed
377

Jan Möbius's avatar
   
Jan Möbius committed
378
379
}

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/// 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) ) {
412
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
413
414
415
416
417
418
419
420
421
422
      continue;
    }

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

    _ini.disconnect();
  }
}

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