ParseIni.cc 35 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88




//=============================================================================
//
//  CLASS Core - IMPLEMENTATION
//
//=============================================================================


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

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

#include <OpenFlipper/INIFile/INIFile.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/common/RecentFiles.hh>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>

#include <QFile>

#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>

//== IMPLEMENTATION ==========================================================


/** Load the standard options from the given Ini File
* @param _ini Inifile to use
*/
void Core::readApplicationOptions(INIFile& _ini) {
  // Parse standard options
  if ( _ini.section_exists("Options") ) {

    // load ViewModes
    int viewModeCount;
    if (_ini.get_entry(viewModeCount,"Options","ViewModeCount") )
      for (int i=0; i < viewModeCount; i++){
        QString entry;
        QString key = "ViewMode" + QString::number(i);

        if ( !_ini.get_entry( entry , "Options" , key ) ) continue;

89
        QStringList widgets = entry.split(";");
Jan Möbius's avatar
 
Jan Möbius committed
90
91
92
93
94
95
96
97
98
99
100
        QString mode = widgets.first();
        widgets.removeFirst();

        bool found = false;
        for (int i=0; i < viewModes_.size(); i++)
          if (viewModes_[i]->name == mode)
            found = true;
        if (!found){
          ViewMode* vm = new ViewMode();
          vm->name = mode;
          vm->custom = true;
Jan Möbius's avatar
Jan Möbius committed
101
          vm->visibleToolboxes = widgets;
Jan Möbius's avatar
 
Jan Möbius committed
102
103
104
105
106
107
108
109
110
          viewModes_.push_back(vm);
        }

      }

    //load default dataType
    QString type;
    if (_ini.get_entry(type, "Options" , "default_DataType" ))
      OpenFlipper::Options::lastDataType(type);
Jan Möbius's avatar
Jan Möbius committed
111

Jan Möbius's avatar
 
Jan Möbius committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    //============================================================================
    // Splash Screen
    //============================================================================
    bool splash;
    if( _ini.get_entry(splash, "Options", "Splash") )
      OpenFlipper::Options::splash(splash);

    //============================================================================
    // Load the startup dir for file dialogs
    //============================================================================
    QString startup_dir;
    if( _ini.get_entry(startup_dir, "Options", "StartupDir") )
      OpenFlipper::Options::currentDir(startup_dir);

Dirk Wilden's avatar
Dirk Wilden committed
126
127
128
129
    //============================================================================
    // Load the default script directory
    //============================================================================
    QString script_dir;
130
    if( _ini.get_entry(script_dir, "Options", "CurrentScriptDir") )
Dirk Wilden's avatar
Dirk Wilden committed
131
132
      OpenFlipper::Options::currentScriptDir(script_dir);

133
134
135
136
137
138
139
    //============================================================================
    // Load the default texture directory
    //============================================================================
    QString current_texture_dir;
    if( _ini.get_entry(current_texture_dir, "Options", "CurrentTextureDir") )
      OpenFlipper::Options::currentTextureDir(current_texture_dir);

Jan Möbius's avatar
 
Jan Möbius committed
140
141
142
    //============================================================================
    // Load the random base color setting
    //============================================================================
143
144
145
    bool random_base_color = false;
    if ( _ini.get_entry( random_base_color, "Options" , "RandomBaseColor") )
      OpenFlipper::Options::randomBaseColor( random_base_color );
Jan Möbius's avatar
 
Jan Möbius committed
146

Dirk Wilden's avatar
   
Dirk Wilden committed
147
148
149
150
151
152
153
    //============================================================================
    // Load the synchronization setting
    //============================================================================
    bool synchronization = false;
    if ( _ini.get_entry( synchronization, "Options" , "Synchronization") )
      OpenFlipper::Options::synchronization(synchronization);

Jan Möbius's avatar
 
Jan Möbius committed
154
155
156
    //============================================================================
    // Load the stereo mode setting
    //============================================================================
Jan Möbius's avatar
Jan Möbius committed
157
158
159
    //bool stereo = false;
    //if ( _ini.get_entry( stereo, "Options" , "Stereo") )
    //  OpenFlipper::Options::stereo(stereo);
Jan Möbius's avatar
 
Jan Möbius committed
160

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
161
162
163
164
165
166
167
    //============================================================================
    // Load the stereo mode setting
    //============================================================================
    int stereoMode = 0;
    if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") )
      OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode));

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
168
169
170
171
172
173
174
175
176
177
    //============================================================================
    // Load stereo view settings
    //============================================================================

    float val;
    if ( _ini.get_entry( val, "Options" , "EyeDistance") )
      OpenFlipper::Options::eyeDistance(val);
    if ( _ini.get_entry( val, "Options" , "FocalDistance") )
      OpenFlipper::Options::focalDistance(val);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
    //============================================================================
    // Load the custom anaglyph stereo mode color matrices
    //============================================================================
    std::vector<float> mat;
    if ( _ini.get_entry( mat, "Options" , "CustomAnaglyphLeftEye") && mat.size () == 9)
    {
      OpenFlipper::Options::anaglyphLeftEyeColorMatrix(mat);
    }
    else
    {
      std::vector<float> set (9,0.0);
      set[0] = 0.299;
      set[3] = 0.587;
      set[6] = 0.114;
      OpenFlipper::Options::anaglyphLeftEyeColorMatrix(set);
    }

    if ( _ini.get_entry( mat, "Options" , "CustomAnaglyphRightEye") && mat.size () == 9)
    {
      OpenFlipper::Options::anaglyphRightEyeColorMatrix(mat);
    }
    else
    {
      std::vector<float> set (9,0.0);
      set[4] = 1.0;
      set[8] = 1.0;
      OpenFlipper::Options::anaglyphRightEyeColorMatrix(set);
    }

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
    //============================================================================
    // Load stereo mouse picking behavior
    //============================================================================
    bool stereoMousePick = false;
    if ( _ini.get_entry( stereoMousePick, "Options" , "StereoMousePick") )
      OpenFlipper::Options::stereoMousePick(stereoMousePick);

    //============================================================================
    // Load gl mouse painting behavior
    //============================================================================
    bool glMouse = false;
    if ( _ini.get_entry( glMouse, "Options" , "GlMouse") )
      OpenFlipper::Options::glMouse(glMouse);

Jan Möbius's avatar
 
Jan Möbius committed
221
222
223
    //============================================================================
    // Load the setting for the loger window
    //============================================================================
Jan Möbius's avatar
Jan Möbius committed
224
225
226
    int loggerState = 0;
    if ( _ini.get_entry( loggerState, "Options" , "LoggerState") )
      OpenFlipper::Options::loggerState(static_cast<OpenFlipper::Options::LoggerState> (loggerState));
Jan Möbius's avatar
 
Jan Möbius committed
227

228
229
230
231
232
233
234
    //============================================================================
    // Load the setting for the toolbox window
    //============================================================================
    bool hideToolbox = false;
    if ( _ini.get_entry( hideToolbox, "Options" , "HideToolbox") )
      OpenFlipper::Options::hideToolbox(hideToolbox);

Jan Möbius's avatar
 
Jan Möbius committed
235
236
237
238
239
240
241
    //============================================================================
    // Load the setting for the fullscreen option
    //============================================================================
    bool fullScreen = false;
    if ( _ini.get_entry( fullScreen, "Options" , "FullScreen") )
      OpenFlipper::Options::fullScreen(fullScreen);

242
    //============================================================================
243
    // Load the setting for the background color option
244
245
246
    //============================================================================
    uint backgroundColor = 0;
    if ( _ini.get_entry( backgroundColor, "Options" , "DefaultBackgroundColor") )
247
      OpenFlipper::Options::defaultBackgroundColor(QRgb(backgroundColor));
248

249
250
251
252
253
254
255
    //============================================================================
    // Load the setting for the object color option
    //============================================================================
    uint baseColor = 0;
    if ( _ini.get_entry( baseColor, "Options" , "DefaultBaseColor") )
      OpenFlipper::Options::defaultBaseColor(QRgb(baseColor));

Jan Möbius's avatar
 
Jan Möbius committed
256
257
258
259
260
261
262
    //============================================================================
    // Load the setting for the default Toolbox mode
    //============================================================================
    QString toolboxMode = false;
    if ( _ini.get_entry( toolboxMode, "Options" , "DefaultToolboxMode") )
      OpenFlipper::Options::defaultToolboxMode(toolboxMode);

263
264
265
266
267
268
269
    //============================================================================
    // Load the setting for the translation language
    //============================================================================
    QString translation = false;
    if ( _ini.get_entry( translation, "Options" , "Translation") )
      OpenFlipper::Options::translation(translation);

270
271
272
273
274
275
276
    //============================================================================
    // Load the setting for the gridVisibility
    //============================================================================
    bool visible = false;
    if ( _ini.get_entry( visible, "Options" , "GridVisible") )
      OpenFlipper::Options::gridVisible(visible);

277
278
279
280
281
282
283
    //============================================================================
    // Load the setting for the viewer layout
    //============================================================================
    int viewerLayout = 0;
    if ( _ini.get_entry( viewerLayout, "Options" , "DefaultViewerLayout") )
      OpenFlipper::Options::defaultViewerLayout(viewerLayout);

Jan Möbius's avatar
 
Jan Möbius committed
284
    //============================================================================
285
    // Load the viewer settings
Jan Möbius's avatar
 
Jan Möbius committed
286
287
    //============================================================================
    std::vector< QString > draw_modes;
288
289
290
291
292
    int mode;

    for (int i=0; i < 4/*PluginFunctions::viewers()*/; i++ ){

      if( _ini.get_entry(draw_modes, "Options", "DefaultDrawModes" + QString::number(i) ) )
293
        OpenFlipper::Options::defaultDrawMode( ListToDrawMode(draw_modes), i );
294
295

      if( _ini.get_entry(mode, "Options", "DefaultProjectionMode" + QString::number(i) ) )
296
        OpenFlipper::Options::defaultProjectionMode( mode, i );
297
298

      if( _ini.get_entry(mode, "Options", "DefaultViewingDirection" + QString::number(i) ) )
299
        OpenFlipper::Options::defaultViewingDirection( mode, i );
300
    }
Dirk Wilden's avatar
Dirk Wilden committed
301
302
303
304
305
306
307
308
309
310
311
312
313
314

    //============================================================================
    // Load logFile status
    //============================================================================
    bool logFileEnabled = true;
    if( _ini.get_entry(logFileEnabled, "Options", "LogFileEnabled") )
      OpenFlipper::Options::logFileEnabled(logFileEnabled);

    //============================================================================
    // Load logFile location
    //============================================================================
    QString logFile = "";
    if( _ini.get_entry(logFile, "Options", "LogFileLocation") )
      OpenFlipper::Options::logFile(logFile);
315

Dirk Wilden's avatar
Dirk Wilden committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
    //============================================================================
    // Load the WheelZoomFactor setting
    //============================================================================
    double wheelZoomFactor = 1.0;
    if ( _ini.get_entry( wheelZoomFactor, "Options" , "WheelZoomFactor") )
      OpenFlipper::Options::wheelZoomFactor(wheelZoomFactor);

    //============================================================================
    // Load the WheelZoomFactorShift setting
    //============================================================================
    double wheelZoomFactorShift = 0.2;
    if ( _ini.get_entry( wheelZoomFactorShift, "Options" , "WheelZoomFactorShift" ) )
      OpenFlipper::Options::wheelZoomFactorShift(wheelZoomFactorShift);

330
331
332
333
334
335
336
    //============================================================================
    // Load restrictFrameRate
    //============================================================================
    bool restrictFrameRate = false;
    if( _ini.get_entry(restrictFrameRate, "Options", "RestrictFrameRate") )
      OpenFlipper::Options::restrictFrameRate(restrictFrameRate);

337
338
339
340
341
342
343
    //============================================================================
    // Load showWheelsAtStartup
    //============================================================================
    bool showWheelsAtStartup = false;
    if( _ini.get_entry(showWheelsAtStartup, "Options", "ShowWheelsAtStartup") )
      OpenFlipper::Options::showWheelsAtStartup(showWheelsAtStartup);

344
345
346
347
348
349
    //============================================================================
    // Load maxFrameRate
    //============================================================================
    int maxFrameRate = 35;
    if( _ini.get_entry(maxFrameRate, "Options", "MaxFrameRate") )
      OpenFlipper::Options::maxFrameRate(maxFrameRate);
Jan Möbius's avatar
Jan Möbius committed
350
351
352
353
354
355
356
357

    //============================================================================
    // Load slotDebugging state
    //============================================================================
    bool doSlotDebugging = false;
    if( _ini.get_entry(doSlotDebugging, "Options", "SlotDebugging") )
      OpenFlipper::Options::doSlotDebugging(doSlotDebugging);

358
359
360
361
362
363
364
365
366
367
368
    //============================================================================
    // Load Picking debugger state
    //============================================================================
    bool renderPicking = false;
    if( _ini.get_entry(renderPicking, "Options", "RenderPicking") )
      OpenFlipper::Options::renderPicking(renderPicking);

    QString pickingRenderMode = "";
    if( _ini.get_entry(renderPicking, "Options", "PickingRenderMode") )
      OpenFlipper::Options::pickingRenderMode(pickingRenderMode);

Dirk Wilden's avatar
Dirk Wilden committed
369
370
371
372
373
374
375
376
    //============================================================================
    // ViewerProperties
    //============================================================================

    bool multiView = false;
    if( _ini.get_entry(multiView, "Options", "MultiView") )
      OpenFlipper::Options::multiView(multiView);

Dirk Wilden's avatar
Dirk Wilden committed
377
    uint viewerCount = 0;
Dirk Wilden's avatar
Dirk Wilden committed
378
379
380
    if( _ini.get_entry(viewerCount, "Options", "ViewerCount") ){
    }

Dirk Wilden's avatar
Dirk Wilden committed
381
382
    if ( _ini.section_exists("ViewerProperties") ){
      for ( unsigned int i = 0 ; i < viewerCount; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
383

Dirk Wilden's avatar
Dirk Wilden committed
384
385
        if (OpenFlipper::Options::examinerWidgets() < i)
          break;
Jan Möbius's avatar
Jan Möbius committed
386

Dirk Wilden's avatar
Dirk Wilden committed
387
388
389
390
        // Load the animation setting
        bool animation = false;
        if ( _ini.get_entry( animation, "ViewerProperties" , "Animation" + QString::number(i) ) )
          PluginFunctions::viewerProperties(i).animation(animation);
Jan Möbius's avatar
Jan Möbius committed
391

Dirk Wilden's avatar
Dirk Wilden committed
392
393
394
395
        // Load the twoSidedLighting setting
        bool twoSidedLighting = false;
        if ( _ini.get_entry( twoSidedLighting, "ViewerProperties" , "TwoSidedLighting" + QString::number(i)) )
          PluginFunctions::viewerProperties(i).twoSidedLighting(twoSidedLighting);
Jan Möbius's avatar
Jan Möbius committed
396

Dirk Wilden's avatar
Dirk Wilden committed
397
398
399
400
        // Load the backface culling setting
        bool backface_culling = false;
        if ( _ini.get_entry( backface_culling, "ViewerProperties" , "BackfaceCulling" + QString::number(i)) )
          PluginFunctions::viewerProperties(i).backFaceCulling(backface_culling);
Jan Möbius's avatar
Jan Möbius committed
401

Dirk Wilden's avatar
Dirk Wilden committed
402
403
404
405
406
407
        // Load the setting for the background color option
        uint viewerBackground = 0;
        if ( _ini.get_entry( viewerBackground, "ViewerProperties" , "BackgroundColor" + QString::number(i)) )
          PluginFunctions::viewerProperties(i).backgroundColor( QRgb(viewerBackground) );
      }
    }
Dirk Wilden's avatar
Dirk Wilden committed
408

Dirk Wilden's avatar
Dirk Wilden committed
409
410
411
412
413
414
    //============================================================================
    // Update information
    //============================================================================
    QString updateUrl = "";
    if( _ini.get_entry(updateUrl, "Options", "UpdateURL") )
      OpenFlipper::Options::updateUrl(updateUrl);
Dirk Wilden's avatar
Dirk Wilden committed
415

Dirk Wilden's avatar
Dirk Wilden committed
416
417
418
    QString updateUsername = "";
    if( _ini.get_entry(updateUsername, "Options", "UpdateUsername") )
      OpenFlipper::Options::updateUsername(updateUsername);
Dirk Wilden's avatar
Dirk Wilden committed
419

Dirk Wilden's avatar
Dirk Wilden committed
420
421
422
    QString updatePassword = "";
    if( _ini.get_entry(updatePassword, "Options", "UpdatePassword") )
      OpenFlipper::Options::updatePassword(updatePassword);
Jan Möbius's avatar
 
Jan Möbius committed
423
424
425
  }
}

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
void Core::readRecentFiles(QString _filename){

  INIFile ini;

  if ( ! ini.connect(_filename,false) ) {
    emit log(LOGERR,"Failed to connect to ini file" + _filename);
    return;
  }

  OpenFlipper::Options::loadingSettings(true);

  // Load maxRecent Setting
  int mrecent = 6;
  if (ini.get_entry(mrecent,"Options","MaxRecent"))
    OpenFlipper::Options::maxRecent(mrecent);

  for ( int j = mrecent-1 ; j >= 0; --j) {
    QString file;
    QString key = "recent" + QString::number(j);

    if ( !ini.get_entry( file , "Options" , key ) )
      continue;

    key = "type" + QString::number(j);
    QString type;

    if ( !ini.get_entry( type , "Options" , key ) )
      continue;

    OpenFlipper::Options::addRecentFile(file, typeId(type) );
  }

  ini.disconnect();

  OpenFlipper::Options::loadingSettings(false);

}


Dirk Wilden's avatar
Dirk Wilden committed
465
/** Write the standard options to the given Ini File
Jan Möbius's avatar
 
Jan Möbius committed
466
467
* @param _ini Inifile to use
*/
Dirk Wilden's avatar
Dirk Wilden committed
468
void Core::writeApplicationOptions(INIFile& _ini) {
Jan Möbius's avatar
 
Jan Möbius committed
469
470
471
472
473
474
475
476
477
478
479
480
481

  // Write maximum recent file count to ini
  _ini.add_entry("Options","MaxRecent",OpenFlipper::Options::maxRecent());

  // Write list of recent files to ini
  QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
  for ( int j = 0 ; j < recentFiles.size(); ++j) {
    // Save filename
    QString key = "recent" + QString::number(j);
    QString filename = recentFiles[j].filename;
    _ini.add_entry( "Options" , key , filename );
    // Save DataType
    key = "type" + QString::number(j);
482
    QString type = typeName( recentFiles[j].type );
Jan Möbius's avatar
 
Jan Möbius committed
483
484
485
486
487
488
489
490
491
492
493
494
495
    _ini.add_entry( "Options" , key , type );
  }

  // save ViewModes
  QVector< QString > entries;
  if ( OpenFlipper::Options::gui() )
    for (int i=0; i < coreWidget_->viewModes_.size(); i++)
      if (coreWidget_->viewModes_[i]->custom){

        //store name
        QString entry = coreWidget_->viewModes_[i]->name;

        //store widgets
Jan Möbius's avatar
Jan Möbius committed
496
497
        for (int j=0; j < coreWidget_->viewModes_[i]->visibleToolboxes.size(); j++)
          entry += ";" + coreWidget_->viewModes_[i]->visibleToolboxes[j];
Jan Möbius's avatar
 
Jan Möbius committed
498
499
500
501
502
503
504
505
506

        entries.push_back(entry);
      }

  //save viewmodes to ini
  _ini.add_entry("Options","ViewModeCount" ,entries.size());
  for (int i=0; i < entries.size(); i++)
    _ini.add_entry("Options","ViewMode" + QString::number(i) ,entries[i]);

507
508
509
510
  //save KeyBindings
  if ( OpenFlipper::Options::gui() )
    coreWidget_->saveKeyBindings(_ini);

Jan Möbius's avatar
 
Jan Möbius committed
511
512
513
514
  //============================================================================
  // Splash Screen
  //============================================================================
  _ini.add_entry( "Options" , "Splash" , OpenFlipper::Options::splash() );
Jan Möbius's avatar
Jan Möbius committed
515

Jan Möbius's avatar
 
Jan Möbius committed
516
517
518
519
520
521
  //write default dataType to INI
  _ini.add_entry( "Options" , "default_DataType" , OpenFlipper::Options::lastDataType() );

  //write default ToolboxMode
  _ini.add_entry("Options","DefaultToolboxMode",OpenFlipper::Options::defaultToolboxMode() );

Dirk Wilden's avatar
Dirk Wilden committed
522
523
524
525
526
527
528
  //============================================================================
  // logfile
  //============================================================================
  //write logfile status
  _ini.add_entry("Options","LogFileEnabled",OpenFlipper::Options::logFileEnabled() );
  //write logfile location
  _ini.add_entry("Options","LogFileLocation",OpenFlipper::Options::logFile() );
Jan Möbius's avatar
 
Jan Möbius committed
529

530
531
532
  //============================================================================
  // other
  //============================================================================
Dirk Wilden's avatar
Dirk Wilden committed
533
534
  _ini.add_entry("Options","WheelZoomFactor", OpenFlipper::Options::wheelZoomFactor() );
  _ini.add_entry("Options","WheelZoomFactorShift", OpenFlipper::Options::wheelZoomFactorShift() );
535
536
  // restrict Framerate
  _ini.add_entry("Options","RestrictFrameRate",OpenFlipper::Options::restrictFrameRate() );
537
538
  // Show wheels on startup
  _ini.add_entry("Options","ShowWheelsAtStartup",OpenFlipper::Options::showWheelsAtStartup() );
539
540
541
  // max Framerate
  _ini.add_entry("Options","MaxFrameRate",OpenFlipper::Options::maxFrameRate() );

Jan Möbius's avatar
Jan Möbius committed
542
543
544
545
546
  //============================================================================
  // Debugging
  //============================================================================
  _ini.add_entry("Options","SlotDebugging",OpenFlipper::Options::doSlotDebugging() );

547
548
549
550
551
552
  //============================================================================
  // Write Picking debugger state
  //============================================================================
  _ini.add_entry("Options","RenderPicking",OpenFlipper::Options::renderPicking() );
  _ini.add_entry("Options","PickingRenderMode",OpenFlipper::Options::pickingRenderMode() );

553
554
555
556
557
558
559
  //============================================================================
  // Update information
  //============================================================================
  _ini.add_entry("Options","UpdateURL",OpenFlipper::Options::updateUrl() );
  _ini.add_entry("Options","UpdateUsername",OpenFlipper::Options::updateUsername() );
  _ini.add_entry("Options","UpdatePassword",OpenFlipper::Options::updatePassword() );

Jan Möbius's avatar
 
Jan Möbius committed
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
  //============================================================================
  //dontLoad Plugins
  //============================================================================
  QString dontLoad;
  for (int i=0; i < dontLoadPlugins_.size(); i++)
    if (!dontLoad.contains(dontLoadPlugins_[i].trimmed() + ";"))
      dontLoad += dontLoadPlugins_[i].trimmed() + ";";

  if ( !_ini.section_exists("Plugins") )
    _ini.add_section("Plugins");

  //write dontLoad Plugins
  _ini.add_entry("Plugins","DontLoad", dontLoad);



  if ( !_ini.section_exists("Options") )
    _ini.add_section("Options");

  QString dir = OpenFlipper::Options::currentDirStr().toUtf8();
  _ini.add_entry("Options","StartupDir",dir);
Dirk Wilden's avatar
Dirk Wilden committed
581
582

  QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8();
583
584
585
586
  _ini.add_entry("Options","CurrentScriptDir",scriptDir);

  QString current_texture_dir = OpenFlipper::Options::currentTextureDirStr().toUtf8();
  _ini.add_entry("Options","CurrentTextureDir",current_texture_dir);
Dirk Wilden's avatar
Dirk Wilden committed
587

588
  _ini.add_entry("Options","RandomBaseColor", OpenFlipper::Options::randomBaseColor() );
Jan Möbius's avatar
 
Jan Möbius committed
589
590
591

  if ( OpenFlipper::Options::gui() ) {

592
593
    _ini.add_entry("Options","DefaultViewerLayout", OpenFlipper::Options::defaultViewerLayout() );
    _ini.add_entry("Options","Translation", OpenFlipper::Options::translation() );
594
    _ini.add_entry("Options","GridVisible", OpenFlipper::Options::gridVisible() );
595

Dirk Wilden's avatar
Dirk Wilden committed
596
597
    _ini.add_entry("Options","MultiView", OpenFlipper::Options::multiView() );
    _ini.add_entry("Options","ViewerCount", OpenFlipper::Options::examinerWidgets() );
Jan Möbius's avatar
Jan Möbius committed
598

Dirk Wilden's avatar
Dirk Wilden committed
599
600
    if ( !_ini.section_exists("ViewerProperties") )
      _ini.add_section("ViewerProperties");
Jan Möbius's avatar
 
Jan Möbius committed
601

Dirk Wilden's avatar
Dirk Wilden committed
602
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
Dirk Wilden's avatar
Dirk Wilden committed
603

Dirk Wilden's avatar
Dirk Wilden committed
604
605
606
607
608
609
      _ini.add_entry("ViewerProperties","Animation" + QString::number(i),       PluginFunctions::viewerProperties(i).animation());
      _ini.add_entry("ViewerProperties","BackfaceCulling" + QString::number(i), PluginFunctions::viewerProperties(i).backFaceCulling());
      _ini.add_entry("ViewerProperties","TwoSidedLighting" + QString::number(i),PluginFunctions::viewerProperties(i).twoSidedLighting());
      _ini.add_entry("ViewerProperties","BackgroundColor" + QString::number(i),
                     (uint)PluginFunctions::viewerProperties(i).backgroundColorRgb() );
    }
Jan Möbius's avatar
 
Jan Möbius committed
610
    //============================================================================
611
    // Save the current viewer properties
Jan Möbius's avatar
 
Jan Möbius committed
612
613
    //============================================================================
    std::vector< QString > draw_modes;
614
615
616
617
618
619
620
621
622
623
    int mode;

    for (int i=0; i < PluginFunctions::viewers(); i++ ){

      draw_modes = drawModeToList( OpenFlipper::Options::defaultDrawMode(i) );
      _ini.add_entry("Options","DefaultDrawModes" + QString::number(i), draw_modes);

      _ini.add_entry("Options","DefaultProjectionMode" + QString::number(i), OpenFlipper::Options::defaultProjectionMode(i) );
      _ini.add_entry("Options","DefaultViewingDirection" + QString::number(i), OpenFlipper::Options::defaultViewingDirection(i) );
    }
624

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

Jan Möbius's avatar
Jan Möbius committed
626
    _ini.add_entry("Options","LoggerState", OpenFlipper::Options::loggerState() );
627
    _ini.add_entry("Options","HideToolbox", OpenFlipper::Options::hideToolbox() );
Jan Möbius's avatar
 
Jan Möbius committed
628
629

    // check if we are in fullscreen mode:
630
    _ini.add_entry("Options","FullScreen", OpenFlipper::Options::fullScreen() );
631

632
    _ini.add_entry("Options","DefaultBackgroundColor", (uint)OpenFlipper::Options::defaultBackgroundColor().rgba ()  );
633
    _ini.add_entry("Options","DefaultBaseColor", (uint)OpenFlipper::Options::defaultBaseColor().rgba ()  );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
634
635
636

    _ini.add_entry("Options","StereoMode",OpenFlipper::Options::stereoMode() );

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
637
638
639
    _ini.add_entry("Options" , "EyeDistance", OpenFlipper::Options::eyeDistance());
    _ini.add_entry("Options" , "FocalDistance", OpenFlipper::Options::focalDistance());

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
640
641
    _ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
    _ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
642
643
644
645

    _ini.add_entry("Options", "StereoMousePick", OpenFlipper::Options::stereoMousePick() );

    _ini.add_entry("Options", "GlMouse", OpenFlipper::Options::glMouse() );
Jan Möbius's avatar
 
Jan Möbius committed
646
647
  }

648
649
  emit saveOnExit(_ini);

Jan Möbius's avatar
Jan Möbius committed
650
  // _ini.add_entry("Options","Stereo",OpenFlipper::Options::stereo() );
Jan Möbius's avatar
 
Jan Möbius committed
651
652
}

653
654
655
656
void Core::openIniFile( QString _filename,
                        bool    _coreSettings,
                        bool    _perPluginSettings,
                        bool    _loadObjects ){
Jan Möbius's avatar
 
Jan Möbius committed
657
658
659
  INIFile ini;

  if ( ! ini.connect(_filename,false) ) {
660
    emit log(LOGERR,tr("Failed to connect to ini file") + _filename);
Jan Möbius's avatar
 
Jan Möbius committed
661
662
    return;
  }
Jan Möbius's avatar
Jan Möbius committed
663

Jan Möbius's avatar
 
Jan Möbius committed
664
  if ( OpenFlipper::Options::gui() ) {
665
    coreWidget_->statusMessage( tr("Loading ini File ") + _filename + " ...");
Jan Möbius's avatar
 
Jan Möbius committed
666
667
668
    coreWidget_->setStatus(ApplicationStatus::BLOCKED );
  }

669
  OpenFlipper::Options::loadingSettings(true);
Jan Möbius's avatar
 
Jan Möbius committed
670

671
672
673
  // Load Core settings only if requested
  if ( _coreSettings )
    readApplicationOptions(ini);
Jan Möbius's avatar
 
Jan Möbius committed
674

675
676
677
  // if requested load per Plugin settings from the settings file
  if ( _perPluginSettings )
    emit iniLoadOptions( ini );
Jan Möbius's avatar
 
Jan Möbius committed
678

679
  if ( _loadObjects ) {
Jan Möbius's avatar
 
Jan Möbius committed
680

681
    QStringList openFiles;
Jan Möbius's avatar
 
Jan Möbius committed
682

683
684
    // Parse File section for files to open
    if ( ini.section_exists("OpenFiles") && ini.get_entry(openFiles,"OpenFiles","open") ) {
Jan Möbius's avatar
 
Jan Möbius committed
685

686
      bool newActiveObject = false;
Jan Möbius's avatar
 
Jan Möbius committed
687

688
      for ( int i = 0 ; i < openFiles.size(); ++i ) {
Jan Möbius's avatar
 
Jan Möbius committed
689

690
691
692
693
694
695
696
697
698
699
700
701
        QString sectionName = openFiles[i];

        QString path;
        ini.get_entry( path, sectionName , "path" );

        //check if path is relative
        if (path.startsWith( "." + OpenFlipper::Options::dirSeparator() )){
          //check if _filename contains a path
          if (_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) != ""){
            path.remove(0,1); // remove .
            path = _filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) + path;
          }
Jan Möbius's avatar
 
Jan Möbius committed
702
703
        }

704
705
        int tmpType;
        DataType type = DATA_TRIANGLE_MESH;
706

707
708
        if ( ini.get_entry( tmpType, sectionName , "type"  )) {
          type = DataType(tmpType);
709
710
          emit log(LOGWARN, tr("This ini file uses old int style ObjectType fields!") );
          emit log(LOGWARN, tr("Please convert it to new format! ( ... just save it )") );
711
        } else {
712

713
          QString typeName="";
714

715
716
717
          if ( ini.get_entry( typeName, sectionName , "type"  )) {
            type = typeId(typeName);
          } else
718
            emit log(LOGWARN, tr("Unable to get DataType for object ") +  sectionName + tr(" assuming Triangle Mesh") );
719
        }
Jan Möbius's avatar
 
Jan Möbius committed
720

721
        int newObjectId = loadObject(type, path);
Jan Möbius's avatar
 
Jan Möbius committed
722

723
724
        BaseObject* object = objectRoot_->childExists( newObjectId );
        if ( object == 0 )  {
725
          emit log(LOGERR,tr("Unable to open Object ") + path);
726
727
728
729
          continue;
        }

        bool flag;
730
        if ( ini.get_entry( flag, sectionName , "target" ) )
731
732
733
734
          object->target(flag);

        if ( ini.get_entry( flag, sectionName , "source" ) )
          object->source(flag);
Jan Möbius's avatar
 
Jan Möbius committed
735

736
        emit iniLoad( ini,object->id() );
Jan Möbius's avatar
 
Jan Möbius committed
737

738
739
        emit objectSelectionChanged( object->id() );
      }
Jan Möbius's avatar
 
Jan Möbius committed
740
741
742
743
    }

  }

744
  // Tell Plugins that all objects are
745
  if ( _perPluginSettings )
746
    emit iniLoadOptionsLast( ini );
Jan Möbius's avatar
 
Jan Möbius committed
747
748
749

  ini.disconnect();

750
  OpenFlipper::Options::loadingSettings(false);
Jan Möbius's avatar
 
Jan Möbius committed
751

752
753
  // Reset scenegraph and recompute scene center containing all new objects
  resetScenegraph(true);
Jan Möbius's avatar
Jan Möbius committed
754

Dirk Wilden's avatar
Dirk Wilden committed
755
756
  if ( OpenFlipper::Options::gui() ){
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
757
      PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
Dirk Wilden's avatar
Dirk Wilden committed
758
759
      coreWidget_->examiner_widgets_[i]->viewAll();
    }
Jan Möbius's avatar
Jan Möbius committed
760

761
    coreWidget_->statusMessage( tr("Loading ini File ") + _filename + tr(" ... Done"), 4000);
Jan Möbius's avatar
 
Jan Möbius committed
762
763
764
765
766
    coreWidget_->setStatus(ApplicationStatus::READY );
  }

}

767
768
769
770
771
772
void Core::writeIniFile(QString _filename,
                        bool _relativePaths,
                        bool _targetOnly,
                        bool _saveSystemSettings,
                        bool _savePluginSettings ,
                        bool _saveObjectInfo ) {
Jan Möbius's avatar
Jan Möbius committed
773

Jan Möbius's avatar
 
Jan Möbius committed
774
775
776
  INIFile ini;

  if ( ! ini.connect(_filename,true) ) {
777
    emit log(LOGERR,tr("Failed to connect to _ini file") + _filename);
Jan Möbius's avatar
 
Jan Möbius committed
778
779
      return;
  }
Jan Möbius's avatar
Jan Möbius committed
780

Jan Möbius's avatar
 
Jan Möbius committed
781
  if ( OpenFlipper::Options::gui() ) {
782
    coreWidget_->statusMessage( tr("Saving ini File ") + _filename + " ...");
Jan Möbius's avatar
 
Jan Möbius committed
783
784
785
    coreWidget_->setStatus(ApplicationStatus::BLOCKED );
  }

786
  // Only save application settings when requested
787
  if ( _saveSystemSettings )
788
    writeApplicationOptions(ini);
Jan Möbius's avatar
 
Jan Möbius committed
789

790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
  if ( _savePluginSettings )
    emit iniSaveOptions( ini );

  if ( _saveObjectInfo ) {
    // This vector will hold the file sections to open
    QStringList openFiles;


    PluginFunctions::IteratorRestriction restriction;
    if ( _targetOnly )
      restriction = PluginFunctions::TARGET_OBJECTS;
    else
      restriction = PluginFunctions::ALL_OBJECTS;

    QString keyName;
    QString sectionName;
    for ( PluginFunctions::ObjectIterator o_it(restriction) ;
Jan Möbius's avatar
   
Jan Möbius committed
807
                                          o_it != PluginFunctions::objectsEnd(); ++o_it) {
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
      QString file = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
      if (QFile(file).exists()){
        // Add a section for this object
        sectionName = o_it->name();
        ini.add_section( sectionName );
        openFiles.push_back( sectionName );

        //modify filename if relativePaths are wanted
        if (_relativePaths){
          int prefixLen = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2).length();
          file.remove(0, prefixLen);
          file = "." + file;
        }
        // Add the path of this object to the section
        ini.add_entry( sectionName , "path" , file );
        ini.add_entry( sectionName , "type" , typeName(o_it->dataType() ) );
        ini.add_entry( sectionName , "target" , o_it->target() );
        ini.add_entry( sectionName , "source" , o_it->source() );
Jan Möbius's avatar
 
Jan Möbius committed
826

827
      }
Jan Möbius's avatar
 
Jan Möbius committed
828
829
    }

830
    ini.add_entry("OpenFiles","open",openFiles);
Jan Möbius's avatar
 
Jan Möbius committed
831

832
833
    // Tell plugins to save their information for the given object
    for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
   
Jan Möbius committed
834
                                          o_it != PluginFunctions::objectsEnd(); ++o_it)
835
836
      emit iniSave(  ini , o_it->id() );
  }
Jan Möbius's avatar
 
Jan Möbius committed
837
838
839
840



  ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
841

Jan Möbius's avatar
 
Jan Möbius committed
842
  if ( OpenFlipper::Options::gui() ) {
843
    coreWidget_->statusMessage( tr("Saving ini File ") + _filename + tr(" ... Done"), 4000);
Jan Möbius's avatar
 
Jan Möbius committed
844
845
846
847
848
849
    coreWidget_->setStatus(ApplicationStatus::READY );
  }
}


//=============================================================================