optionHandling.cc 12.4 KB
Newer Older
Jan Möbius's avatar
   
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
Jan Möbius's avatar
Jan Möbius committed
15
//
Jan Möbius's avatar
   
Jan Möbius committed
16
17
18
19
//  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.
Jan Möbius's avatar
Jan Möbius committed
20
//
Jan Möbius's avatar
   
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  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"
51
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Jan Möbius's avatar
   
Jan Möbius committed
52

Jan Möbius's avatar
Jan Möbius committed
53
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
   
Jan Möbius committed
54
55
56
57

void Core::applyOptions(){

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

Jan Möbius's avatar
   
Jan Möbius committed
59
60
    //Init ViewModes
    coreWidget_->initViewModes();
Jan Möbius's avatar
Jan Möbius committed
61

Jan Möbius's avatar
   
Jan Möbius committed
62
63
64
65
    //Set default Viewmode
    if (OpenFlipper::Options::defaultToolboxMode() != "")
      coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList());
    //Set Fullscreen
Dirk Wilden's avatar
Dirk Wilden committed
66
    if ( OpenFlipper::Options::fullScreen() )
67
      coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
Dirk Wilden's avatar
Dirk Wilden committed
68
    else
69
		  coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
Jan Möbius's avatar
Jan Möbius committed
70

71
    // Logger
Jan Möbius's avatar
Jan Möbius committed
72
    coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
Jan Möbius's avatar
Jan Möbius committed
73

Jan Möbius's avatar
Jan Möbius committed
74
    // Prepare Picking Debugger Flag
75
76
77
78
79
80
81
82
83
    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
84
85
86
87
    } 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;
88
89
90
    } else {
      target = ACG::SceneGraph::PICK_ANYTHING;
    }
Jan Möbius's avatar
Jan Möbius committed
91

92
93
94
95
96
97
98
99
100
101
102
103
    //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 );

      if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
	PluginFunctions::orthographicProjection(i);
      else
	PluginFunctions::perspectiveProjection(i);
    }

104
105
    //set defaultBackgroundColor
    QColor c = OpenFlipper::Options::defaultBackgroundColor() ;
Jan Möbius's avatar
Jan Möbius committed
106

107
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
108
      //wheel zoom factor
Dirk Wilden's avatar
Dirk Wilden committed
109
110
      PluginFunctions::viewerProperties(i).wheelZoomFactor(OpenFlipper::Options::wheelZoomFactor());
      PluginFunctions::viewerProperties(i).wheelZoomFactorShift(OpenFlipper::Options::wheelZoomFactorShift());
Jan Möbius's avatar
Jan Möbius committed
111
112

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

Jan Möbius's avatar
   
Jan Möbius committed
116
117
    //hideToolbox
    if (OpenFlipper::Options::hideToolbox()) {
118

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
119
      coreWidget_->showToolbox (false);
Jan Möbius's avatar
   
Jan Möbius committed
120
    }
Jan Möbius's avatar
Jan Möbius committed
121

Dirk Wilden's avatar
Dirk Wilden committed
122
123
124
125
126
127
128
129
130
131
132
133
134
    //setup logFile
    if (logFile_ != 0){

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

Jan Möbius's avatar
   
Jan Möbius committed
136
    updateView();
Jan Möbius's avatar
Jan Möbius committed
137

Jan Möbius's avatar
   
Jan Möbius committed
138
139
140
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
141
void Core::saveOptions(){
Jan Möbius's avatar
Jan Möbius committed
142
  QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
Dirk Wilden's avatar
Dirk Wilden committed
143
144
145
146
147
                                                  OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";

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

Dirk Wilden's avatar
Dirk Wilden committed
149
150
151
152
153
154
155
156
157
    if ( ! ini.connect( inifile,true) ) {
      emit log(LOGERR,"Can not create user ini file");
    } else {
      writeApplicationOptions(ini);
      ini.disconnect();
    }
  } else {
    writeApplicationOptions(ini);
    ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
158
  }
Dirk Wilden's avatar
Dirk Wilden committed
159
160
}

Jan Möbius's avatar
   
Jan Möbius committed
161
void Core::setupOptions() {
Jan Möbius's avatar
Jan Möbius committed
162

Jan Möbius's avatar
   
Jan Möbius committed
163
  // Get the Main config dir in the home directory and possibly create it
Jan Möbius's avatar
Jan Möbius committed
164
165
  QDir configDir = QDir::home();

Jan Möbius's avatar
   
Jan Möbius committed
166
167
168
169
170
  if ( ! configDir.cd(".OpenFlipper") ) {
    emit log(LOGOUT,"Creating config Dir ~/.OpenFlipper");
    configDir.mkdir(".OpenFlipper");
    if ( ! configDir.cd(".OpenFlipper") ) {
      emit log(LOGERR,"Unable to create config dir ~/.OpenFlipper");
Jan Möbius's avatar
Jan Möbius committed
171
      return;
Jan Möbius's avatar
   
Jan Möbius committed
172
173
174
    }
  }
  OpenFlipper::Options::configDir(configDir);
Jan Möbius's avatar
Jan Möbius committed
175

Jan Möbius's avatar
   
Jan Möbius committed
176
177
  // Remember the main application directory (assumed to be one above executable Path)
  QDir tempDir = QDir(qApp->applicationDirPath());
178
179
180
181
182
  #ifdef OPENFLIPPER_APPDIR
    tempDir.cd(OPENFLIPPER_APPDIR);
  #else
    tempDir.cd(".." + OpenFlipper::Options::dirSeparator() );
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
183
  OpenFlipper::Options::applicationDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
184

Jan Möbius's avatar
   
Jan Möbius committed
185
  // Set the standard path to the plugins
186
187
188
189
190
  #ifdef OPENFLIPPER_PLUGINDIR
    tempDir.cd(OPENFLIPPER_PLUGINDIR);
  #else
    tempDir.cd("Plugins");

191
192
193
194
195
196
197
198
    #if defined(WIN32)
      tempDir.cd("Windows");
    #elif defined(ARCH_DARWIN)
      tempDir.cd("Darwin");
    #else
      tempDir.cd("Linux");
    #endif

199
200
    if ( OpenFlipper::Options::is64bit() )
      tempDir.cd("64");
201
202
    else
      tempDir.cd("32");
203
204

    #ifdef WIN32
205
206
        #ifndef NDEBUG
          #define DEBUG
207
        #endif
208
209
210
211
    #endif

    #ifdef DEBUG
            tempDir.cd("Debug");
212
    #else
213
            tempDir.cd("Release");
214
215
    #endif
  #endif
Jan Möbius's avatar
Jan Möbius committed
216

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

Jan Möbius's avatar
   
Jan Möbius committed
219
220
  // Set the Path to the shaders
  tempDir = QDir(OpenFlipper::Options::applicationDir());
221
222
223
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
224
225
  tempDir.cd("Shaders");
  OpenFlipper::Options::shaderDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
226
227


Jan Möbius's avatar
   
Jan Möbius committed
228
229
  // Set the Path to the textures
  tempDir = QDir(OpenFlipper::Options::applicationDir());
230
231
232
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
233
234
  tempDir.cd("Textures");
  OpenFlipper::Options::textureDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
235

Jan Möbius's avatar
Jan Möbius committed
236
237
238
239
240
241
242
243
  // 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
244
245
  // Set the Path to the Icons
  tempDir = QDir(OpenFlipper::Options::applicationDir());
246
247
248
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
   
Jan Möbius committed
249
250
  tempDir.cd("Icons");
  OpenFlipper::Options::iconDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
251

Jan Möbius's avatar
Jan Möbius committed
252
253
  // Set the Path to the Fonts
  tempDir = QDir(OpenFlipper::Options::applicationDir());
254
255
256
  #ifdef OPENFLIPPER_DATADIR
    tempDir.cd(OPENFLIPPER_DATADIR);
  #endif
Jan Möbius's avatar
Jan Möbius committed
257
258
259
  tempDir.cd("Fonts");
  OpenFlipper::Options::fontsDir(tempDir.absolutePath());

260
261
262
263
264
265
266
267
  // 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());

268
269
270
271
272
273
274
275
  // 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());

276
277
278
279
280
281
282
  // 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
283
  QStringList optionFiles;
Jan Möbius's avatar
Jan Möbius committed
284

Jan Möbius's avatar
   
Jan Möbius committed
285
286
287
288
  // ==============================================================
  // 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
289
290
291
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
292
293
294
295
  // ==============================================================
  // 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
296
297
298
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
299
300
  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);
Jan Möbius's avatar
Jan Möbius committed
301

302
303
304
305
306
307
308
309
310
  // ==============================================================
  // 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
311

Jan Möbius's avatar
   
Jan Möbius committed
312
313
314
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
Jan Möbius's avatar
Jan Möbius committed
315

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

Jan Möbius's avatar
   
Jan Möbius committed
318
    INIFile _ini;
Jan Möbius's avatar
Jan Möbius committed
319

Jan Möbius's avatar
   
Jan Möbius committed
320
321
322
    if ( ! _ini.connect(optionFiles[i],false) ) {
      emit log(LOGERR,"Failed to connect to _ini file" + optionFiles[i]);
      continue;
Jan Möbius's avatar
Jan Möbius committed
323
324
    }

Jan Möbius's avatar
   
Jan Möbius committed
325
    readApplicationOptions(_ini);
Jan Möbius's avatar
Jan Möbius committed
326

Jan Möbius's avatar
   
Jan Möbius committed
327
328
    _ini.disconnect();
  }
Jan Möbius's avatar
Jan Möbius committed
329

Jan Möbius's avatar
   
Jan Möbius committed
330
331
}

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/// 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) ) {
      emit log(LOGERR,"Failed to connect to _ini file" + optionFiles[i]);
      continue;
    }

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

    _ini.disconnect();
  }
}

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