ParseIni.cc 28.2 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
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
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
//=============================================================================
//
//                               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.
//
//  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 Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  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 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);
82
      QString type;
Jan Möbius's avatar
 
Jan Möbius committed
83
84
85
86

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

87
      OpenFlipper::Options::addRecentFile(file, typeId(type) );
Jan Möbius's avatar
 
Jan Möbius committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    }

    // 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;

        QStringList widgets = entry.split(" ");
        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;
          vm->visibleWidgets = widgets;
          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
121

Jan Möbius's avatar
 
Jan Möbius committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    //============================================================================
    // 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
136
137
138
139
140
141
142
    //============================================================================
    // Load the default script directory
    //============================================================================
    QString script_dir;
    if( _ini.get_entry(script_dir, "Options", "ScriptDir") )
      OpenFlipper::Options::currentScriptDir(script_dir);

Jan Möbius's avatar
 
Jan Möbius committed
143
144
145
    //============================================================================
    // Load the random base color setting
    //============================================================================
146
147
148
    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
149

Dirk Wilden's avatar
   
Dirk Wilden committed
150
151
152
153
154
155
156
    //============================================================================
    // 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
157
158
159
    //============================================================================
    // Load the stereo mode setting
    //============================================================================
Jan Möbius's avatar
Jan Möbius committed
160
161
162
    //bool stereo = false;
    //if ( _ini.get_entry( stereo, "Options" , "Stereo") )
    //  OpenFlipper::Options::stereo(stereo);
Jan Möbius's avatar
 
Jan Möbius committed
163

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    //============================================================================
    // Load the stereo mode setting
    //============================================================================
    int stereoMode = 0;
    if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") )
      OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode));

    //============================================================================
    // 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
 
Jan Möbius committed
200
201
202
    //============================================================================
    // Load the setting for the loger window
    //============================================================================
Jan Möbius's avatar
Jan Möbius committed
203
204
205
    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
206

207
208
209
210
211
212
213
    //============================================================================
    // 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
214
215
216
217
218
219
220
    //============================================================================
    // Load the setting for the fullscreen option
    //============================================================================
    bool fullScreen = false;
    if ( _ini.get_entry( fullScreen, "Options" , "FullScreen") )
      OpenFlipper::Options::fullScreen(fullScreen);

221
    //============================================================================
222
    // Load the setting for the background color option
223
224
225
    //============================================================================
    uint backgroundColor = 0;
    if ( _ini.get_entry( backgroundColor, "Options" , "DefaultBackgroundColor") )
226
      OpenFlipper::Options::defaultBackgroundColor(QRgb(backgroundColor));
227

228
229
230
231
232
233
234
    //============================================================================
    // 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
235
236
237
238
239
240
241
242
243
244
245
246
    //============================================================================
    // Load the setting for the default Toolbox mode
    //============================================================================
    QString toolboxMode = false;
    if ( _ini.get_entry( toolboxMode, "Options" , "DefaultToolboxMode") )
      OpenFlipper::Options::defaultToolboxMode(toolboxMode);

    //============================================================================
    // Load the drawmodes
    //============================================================================
    std::vector< QString > draw_modes;
    if( _ini.get_entry(draw_modes, "Options", "StandardDrawModes") )
247
      OpenFlipper::Options::standardDrawMode( ListToDrawMode(draw_modes) );
Dirk Wilden's avatar
Dirk Wilden committed
248
249
250
251
252
253
254
255
256
257
258
259
260
261

    //============================================================================
    // 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);
262

Dirk Wilden's avatar
Dirk Wilden committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
    //============================================================================
    // 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);

277
278
279
280
281
282
283
284
285
286
287
288
289
    //============================================================================
    // Load restrictFrameRate
    //============================================================================
    bool restrictFrameRate = false;
    if( _ini.get_entry(restrictFrameRate, "Options", "RestrictFrameRate") )
      OpenFlipper::Options::restrictFrameRate(restrictFrameRate);

    //============================================================================
    // 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
290
291
292
293
294
295
296
297

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

298
299
300
301
302
303
304
305
306
307
308
    //============================================================================
    // 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
309
310
311
312
313
314
315
316
    //============================================================================
    // ViewerProperties
    //============================================================================

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

Dirk Wilden's avatar
Dirk Wilden committed
317
    uint viewerCount = 0;
Dirk Wilden's avatar
Dirk Wilden committed
318
319
320
    if( _ini.get_entry(viewerCount, "Options", "ViewerCount") ){
    }

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

Dirk Wilden's avatar
Dirk Wilden committed
324
325
        if (OpenFlipper::Options::examinerWidgets() < i)
          break;
Jan Möbius's avatar
Jan Möbius committed
326

Dirk Wilden's avatar
Dirk Wilden committed
327
328
329
330
        // 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
331

Dirk Wilden's avatar
Dirk Wilden committed
332
333
334
335
        // 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
336

Dirk Wilden's avatar
Dirk Wilden committed
337
338
339
340
        // 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
341

Dirk Wilden's avatar
Dirk Wilden committed
342
343
344
345
346
347
        // 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
348

Dirk Wilden's avatar
Dirk Wilden committed
349
350
351
352
353
354
    //============================================================================
    // Update information
    //============================================================================
    QString updateUrl = "";
    if( _ini.get_entry(updateUrl, "Options", "UpdateURL") )
      OpenFlipper::Options::updateUrl(updateUrl);
Dirk Wilden's avatar
Dirk Wilden committed
355

Dirk Wilden's avatar
Dirk Wilden committed
356
357
358
    QString updateUsername = "";
    if( _ini.get_entry(updateUsername, "Options", "UpdateUsername") )
      OpenFlipper::Options::updateUsername(updateUsername);
Dirk Wilden's avatar
Dirk Wilden committed
359

Dirk Wilden's avatar
Dirk Wilden committed
360
361
362
    QString updatePassword = "";
    if( _ini.get_entry(updatePassword, "Options", "UpdatePassword") )
      OpenFlipper::Options::updatePassword(updatePassword);
Jan Möbius's avatar
 
Jan Möbius committed
363
364
365
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
366
/** Write the standard options to the given Ini File
Jan Möbius's avatar
 
Jan Möbius committed
367
368
* @param _ini Inifile to use
*/
Dirk Wilden's avatar
Dirk Wilden committed
369
void Core::writeApplicationOptions(INIFile& _ini) {
Jan Möbius's avatar
 
Jan Möbius committed
370
371
372
373
374
375
376
377
378
379
380
381
382

  // 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);
383
    QString type = typeName( recentFiles[j].type );
Jan Möbius's avatar
 
Jan Möbius committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    _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
        for (int j=0; j < coreWidget_->viewModes_[i]->visibleWidgets.size(); j++)
          entry += " " + coreWidget_->viewModes_[i]->visibleWidgets[j];

        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]);

408
409
410
411
  //save KeyBindings
  if ( OpenFlipper::Options::gui() )
    coreWidget_->saveKeyBindings(_ini);

Jan Möbius's avatar
 
Jan Möbius committed
412
413
414
415
  //============================================================================
  // Splash Screen
  //============================================================================
  _ini.add_entry( "Options" , "Splash" , OpenFlipper::Options::splash() );
Jan Möbius's avatar
Jan Möbius committed
416

Jan Möbius's avatar
 
Jan Möbius committed
417
418
419
420
421
422
  //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
423
424
425
426
427
428
429
  //============================================================================
  // 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
430

431
432
433
  //============================================================================
  // other
  //============================================================================
Dirk Wilden's avatar
Dirk Wilden committed
434
435
  _ini.add_entry("Options","WheelZoomFactor", OpenFlipper::Options::wheelZoomFactor() );
  _ini.add_entry("Options","WheelZoomFactorShift", OpenFlipper::Options::wheelZoomFactorShift() );
436
437
438
439
440
  // restrict Framerate
  _ini.add_entry("Options","RestrictFrameRate",OpenFlipper::Options::restrictFrameRate() );
  // max Framerate
  _ini.add_entry("Options","MaxFrameRate",OpenFlipper::Options::maxFrameRate() );

Jan Möbius's avatar
Jan Möbius committed
441
442
443
444
445
  //============================================================================
  // Debugging
  //============================================================================
  _ini.add_entry("Options","SlotDebugging",OpenFlipper::Options::doSlotDebugging() );

446
447
448
449
450
451
  //============================================================================
  // Write Picking debugger state
  //============================================================================
  _ini.add_entry("Options","RenderPicking",OpenFlipper::Options::renderPicking() );
  _ini.add_entry("Options","PickingRenderMode",OpenFlipper::Options::pickingRenderMode() );

452
453
454
455
456
457
458
  //============================================================================
  // 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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
  //============================================================================
  //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
480
481
482
483

  QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8();
  _ini.add_entry("Options","ScriptDir",scriptDir);

484
  _ini.add_entry("Options","RandomBaseColor", OpenFlipper::Options::randomBaseColor() );
Jan Möbius's avatar
 
Jan Möbius committed
485
486
487

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

Dirk Wilden's avatar
Dirk Wilden committed
488
489
    _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
490

Dirk Wilden's avatar
Dirk Wilden committed
491
492
    if ( !_ini.section_exists("ViewerProperties") )
      _ini.add_section("ViewerProperties");
Jan Möbius's avatar
 
Jan Möbius committed
493

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

Dirk Wilden's avatar
Dirk Wilden committed
496
497
498
499
500
501
      _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
502
503
504
505
    //============================================================================
    // Save the current draw modes
    //============================================================================
    std::vector< QString > draw_modes;
506
    draw_modes = drawModeToList( OpenFlipper::Options::standardDrawMode() );
Jan Möbius's avatar
 
Jan Möbius committed
507
508
    _ini.add_entry("Options","StandardDrawModes",draw_modes);

Jan Möbius's avatar
Jan Möbius committed
509
    _ini.add_entry("Options","LoggerState", OpenFlipper::Options::loggerState() );
510
    _ini.add_entry("Options","HideToolbox", OpenFlipper::Options::hideToolbox() );
Jan Möbius's avatar
 
Jan Möbius committed
511
512

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

515
    _ini.add_entry("Options","DefaultBackgroundColor", (uint)OpenFlipper::Options::defaultBackgroundColor().rgba ()  );
516
    _ini.add_entry("Options","DefaultBaseColor", (uint)OpenFlipper::Options::defaultBaseColor().rgba ()  );
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
517
518
519
520
521

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

    _ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
    _ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
Jan Möbius's avatar
 
Jan Möbius committed
522
523
  }

Jan Möbius's avatar
Jan Möbius committed
524
  // _ini.add_entry("Options","Stereo",OpenFlipper::Options::stereo() );
Jan Möbius's avatar
 
Jan Möbius committed
525
526
}

527
528
529
530
void Core::openIniFile( QString _filename,
                        bool    _coreSettings,
                        bool    _perPluginSettings,
                        bool    _loadObjects ){
Jan Möbius's avatar
 
Jan Möbius committed
531
532
533
534
535
536
  INIFile ini;

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

Jan Möbius's avatar
 
Jan Möbius committed
538
539
540
541
542
  if ( OpenFlipper::Options::gui() ) {
    coreWidget_->statusMessage( "Loading ini File " + _filename + " ...");
    coreWidget_->setStatus(ApplicationStatus::BLOCKED );
  }

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

545
546
547
  // Load Core settings only if requested
  if ( _coreSettings )
    readApplicationOptions(ini);
Jan Möbius's avatar
 
Jan Möbius committed
548

549
550
551
  // if requested load per Plugin settings from the settings file
  if ( _perPluginSettings )
    emit iniLoadOptions( ini );
Jan Möbius's avatar
 
Jan Möbius committed
552

553
  if ( _loadObjects ) {
Jan Möbius's avatar
 
Jan Möbius committed
554

555
    QStringList openFiles;
Jan Möbius's avatar
 
Jan Möbius committed
556

557
558
    // 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
559

560
      bool newActiveObject = false;
Jan Möbius's avatar
 
Jan Möbius committed
561

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

564
565
566
567
568
569
570
571
572
573
574
575
        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
576
577
        }

578
579
        int tmpType;
        DataType type = DATA_TRIANGLE_MESH;
580

581
582
583
584
585
        if ( ini.get_entry( tmpType, sectionName , "type"  )) {
          type = DataType(tmpType);
          emit log(LOGWARN, "This ini file uses old int style ObjectType fields!" );
          emit log(LOGWARN, "Please convert it to new format! ( ... just save it )" );
        } else {
586

587
          QString typeName="";
588

589
590
591
592
593
          if ( ini.get_entry( typeName, sectionName , "type"  )) {
            type = typeId(typeName);
          } else
            emit log(LOGWARN, "Unable to get DataType for object " +  sectionName + " assuming Triangle Mesh" );
        }
Jan Möbius's avatar
 
Jan Möbius committed
594

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

597
598
599
600
601
602
603
604
605
606
607
608
609
610
        BaseObject* object = objectRoot_->childExists( newObjectId );
        if ( object == 0 )  {
          emit log(LOGERR,"Unable to open Object " + path);
          continue;
        }

        bool flag;
        if ( ini.get_entry( flag, sectionName , "target" ) ) {
          object->target(flag);
          newActiveObject = true;
        }

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

612
        emit iniLoad( ini,object->id() );
Jan Möbius's avatar
 
Jan Möbius committed
613
614
      }

615
      if ( newActiveObject )
616
        emit objectSelectionChanged(-1);
Jan Möbius's avatar
 
Jan Möbius committed
617
618
619
620
621

    }

  }

622
  // Tell Plugins that all objects are
623
  if ( _perPluginSettings )
624
    emit iniLoadOptionsLast( ini );
Jan Möbius's avatar
 
Jan Möbius committed
625
626
627

  ini.disconnect();

628
  OpenFlipper::Options::loadingSettings(false);
Jan Möbius's avatar
 
Jan Möbius committed
629
630

  resetScenegraph();
Jan Möbius's avatar
Jan Möbius committed
631

Dirk Wilden's avatar
Dirk Wilden committed
632
633
634
635
636
  if ( OpenFlipper::Options::gui() ){
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
      PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::standardDrawMode() );
      coreWidget_->examiner_widgets_[i]->viewAll();
    }
Jan Möbius's avatar
Jan Möbius committed
637

Jan Möbius's avatar
 
Jan Möbius committed
638
639
640
641
642
643
    coreWidget_->statusMessage( "Loading ini File " + _filename + " ... Done", 4000);
    coreWidget_->setStatus(ApplicationStatus::READY );
  }

}

644
645
646
647
648
649
void Core::writeIniFile(QString _filename,
                        bool _relativePaths,
                        bool _targetOnly,
                        bool _saveSystemSettings,
                        bool _savePluginSettings ,
                        bool _saveObjectInfo ) {
Jan Möbius's avatar
Jan Möbius committed
650

Jan Möbius's avatar
 
Jan Möbius committed
651
652
653
654
655
656
  INIFile ini;

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

Jan Möbius's avatar
 
Jan Möbius committed
658
659
660
661
662
  if ( OpenFlipper::Options::gui() ) {
    coreWidget_->statusMessage( "Saving ini File " + _filename + " ...");
    coreWidget_->setStatus(ApplicationStatus::BLOCKED );
  }

663
  // Only save application settings when requested
664
  if ( _saveSystemSettings )
665
    writeApplicationOptions(ini);
Jan Möbius's avatar
 
Jan Möbius committed
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
  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
684
                                          o_it != PluginFunctions::objectsEnd(); ++o_it) {
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
      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
703

704
      }
Jan Möbius's avatar
 
Jan Möbius committed
705
706
    }

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

709
710
    // 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
711
                                          o_it != PluginFunctions::objectsEnd(); ++o_it)
712
713
      emit iniSave(  ini , o_it->id() );
  }
Jan Möbius's avatar
 
Jan Möbius committed
714
715
716
717



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

Jan Möbius's avatar
 
Jan Möbius committed
719
720
721
722
723
724
725
726
  if ( OpenFlipper::Options::gui() ) {
    coreWidget_->statusMessage( "Saving ini File " + _filename + " ... Done", 4000);
    coreWidget_->setStatus(ApplicationStatus::READY );
  }
}


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