ParseIni.cc 32.8 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




//=============================================================================
//
//  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") ) {

80
    // TODO: Load View Mode Toolbars and Context Menu Items
81

Jan Möbius's avatar
 
Jan Möbius committed
82 83 84 85
    // load ViewModes
    int viewModeCount;
    if (_ini.get_entry(viewModeCount,"Options","ViewModeCount") )
      for (int i=0; i < viewModeCount; i++){
86

Jan Möbius's avatar
Jan Möbius committed
87 88
        QString entryToolbars;
        QString entryToolboxes;
Jan Möbius's avatar
Jan Möbius committed
89
        QString entryIcon;
90

Jan Möbius's avatar
Jan Möbius committed
91 92
        QString keyToolbars  = "ViewModeToolbars"  + QString::number(i);
        QString keyToolboxes = "ViewModeToolboxes" + QString::number(i);
Jan Möbius's avatar
Jan Möbius committed
93
        QString keyIcon      = "ViewModeIcon"      + QString::number(i);
Jan Möbius's avatar
Jan Möbius committed
94 95

        // Read the entries
Jan Möbius's avatar
Jan Möbius committed
96
        if ( !_ini.get_entry( entryToolbars  , "Options" , keyToolbars ) )  continue;
Jan Möbius's avatar
Jan Möbius committed
97
        if ( !_ini.get_entry( entryToolboxes , "Options" , keyToolboxes ) ) continue;
Jan Möbius's avatar
Jan Möbius committed
98
        if ( !_ini.get_entry( entryIcon      , "Options" , keyIcon ) )      continue;
Jan Möbius's avatar
Jan Möbius committed
99 100 101

        QStringList toolBars = entryToolbars.split(";");
        QStringList toolBoxes = entryToolboxes.split(";");
102

Jan Möbius's avatar
Jan Möbius committed
103 104
        // Get Mode name ( prepended to all toolbox/toolbar lists
        QString mode = toolBoxes.first();
105

Jan Möbius's avatar
Jan Möbius committed
106 107 108 109 110
        // Remove leading Modes
        toolBoxes.removeFirst();
        toolBars.removeFirst();

        // Check if the mode already exists
Jan Möbius's avatar
 
Jan Möbius committed
111 112 113 114
        bool found = false;
        for (int i=0; i < viewModes_.size(); i++)
          if (viewModes_[i]->name == mode)
            found = true;
115

Jan Möbius's avatar
 
Jan Möbius committed
116 117 118 119
        if (!found){
          ViewMode* vm = new ViewMode();
          vm->name = mode;
          vm->custom = true;
Jan Möbius's avatar
Jan Möbius committed
120 121
          vm->visibleToolbars  = toolBars;
          vm->visibleToolboxes = toolBoxes;
Jan Möbius's avatar
Jan Möbius committed
122
          vm->icon             = entryIcon;
Jan Möbius's avatar
 
Jan Möbius committed
123 124 125 126 127 128 129 130 131
          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
132

Jan Möbius's avatar
 
Jan Möbius committed
133 134 135 136 137
    //============================================================================
    // Load the startup dir for file dialogs
    //============================================================================
    QString startup_dir;
    if( _ini.get_entry(startup_dir, "Options", "StartupDir") )
138
      OpenFlipperSettings().setValue("Core/CurrentDir", startup_dir );
Jan Möbius's avatar
 
Jan Möbius committed
139

Dirk Wilden's avatar
Dirk Wilden committed
140 141 142 143
    //============================================================================
    // Load the default script directory
    //============================================================================
    QString script_dir;
144
    if( _ini.get_entry(script_dir, "Options", "CurrentScriptDir") )
Dirk Wilden's avatar
Dirk Wilden committed
145 146
      OpenFlipper::Options::currentScriptDir(script_dir);

147 148 149 150 151 152 153
    //============================================================================
    // 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
154 155 156
    //============================================================================
    // Load the random base color setting
    //============================================================================
157 158 159
    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
160

Dirk Wilden's avatar
 
Dirk Wilden committed
161 162 163 164 165 166 167
    //============================================================================
    // 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
168 169 170
    //============================================================================
    // Load the stereo mode setting
    //============================================================================
Jan Möbius's avatar
Jan Möbius committed
171 172 173
    //bool stereo = false;
    //if ( _ini.get_entry( stereo, "Options" , "Stereo") )
    //  OpenFlipper::Options::stereo(stereo);
Jan Möbius's avatar
 
Jan Möbius committed
174

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
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 200 201 202 203 204 205 206 207 208 209 210
    //============================================================================
    // 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
211 212 213
    //============================================================================
    // Load the setting for the loger window
    //============================================================================
Jan Möbius's avatar
Jan Möbius committed
214 215 216
    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
217

218 219 220 221 222 223 224
    //============================================================================
    // 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
225 226 227 228 229 230 231
    //============================================================================
    // Load the setting for the fullscreen option
    //============================================================================
    bool fullScreen = false;
    if ( _ini.get_entry( fullScreen, "Options" , "FullScreen") )
      OpenFlipper::Options::fullScreen(fullScreen);

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

246 247 248 249 250 251 252
    //============================================================================
    // Load the setting for the translation language
    //============================================================================
    QString translation = false;
    if ( _ini.get_entry( translation, "Options" , "Translation") )
      OpenFlipper::Options::translation(translation);

253 254 255 256 257 258 259
    //============================================================================
    // Load the setting for the gridVisibility
    //============================================================================
    bool visible = false;
    if ( _ini.get_entry( visible, "Options" , "GridVisible") )
      OpenFlipper::Options::gridVisible(visible);

260 261 262 263 264 265 266
    //============================================================================
    // 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
267
    //============================================================================
268
    // Load the viewer settings
Jan Möbius's avatar
 
Jan Möbius committed
269 270
    //============================================================================
    std::vector< QString > draw_modes;
271 272 273 274 275
    int mode;

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

      if( _ini.get_entry(draw_modes, "Options", "DefaultDrawModes" + QString::number(i) ) )
276
        OpenFlipper::Options::defaultDrawMode( ListToDrawMode(draw_modes), i );
277 278

      if( _ini.get_entry(mode, "Options", "DefaultProjectionMode" + QString::number(i) ) )
279
        OpenFlipper::Options::defaultProjectionMode( mode, i );
280 281

      if( _ini.get_entry(mode, "Options", "DefaultViewingDirection" + QString::number(i) ) )
282
        OpenFlipper::Options::defaultViewingDirection( mode, i );
283
    }
Dirk Wilden's avatar
Dirk Wilden committed
284

285 286 287 288 289 290 291 292 293 294 295 296 297
    //============================================================================
    // 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
298 299 300 301 302 303 304 305

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

306 307 308 309 310 311 312 313 314 315 316
    //============================================================================
    // 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
317 318 319 320 321 322 323 324
    //============================================================================
    // ViewerProperties
    //============================================================================

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

Dirk Wilden's avatar
Dirk Wilden committed
325
    uint viewerCount = 0;
Dirk Wilden's avatar
Dirk Wilden committed
326 327 328
    if( _ini.get_entry(viewerCount, "Options", "ViewerCount") ){
    }

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

Dirk Wilden's avatar
Dirk Wilden committed
332 333
        if (OpenFlipper::Options::examinerWidgets() < i)
          break;
Jan Möbius's avatar
Jan Möbius committed
334

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

Dirk Wilden's avatar
Dirk Wilden committed
340 341 342 343
        // 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
344

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

Dirk Wilden's avatar
Dirk Wilden committed
350 351 352 353 354 355
        // 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
356

Dirk Wilden's avatar
Dirk Wilden committed
357 358 359 360 361 362
    //============================================================================
    // Update information
    //============================================================================
    QString updateUrl = "";
    if( _ini.get_entry(updateUrl, "Options", "UpdateURL") )
      OpenFlipper::Options::updateUrl(updateUrl);
Dirk Wilden's avatar
Dirk Wilden committed
363

Dirk Wilden's avatar
Dirk Wilden committed
364 365 366
    QString updateUsername = "";
    if( _ini.get_entry(updateUsername, "Options", "UpdateUsername") )
      OpenFlipper::Options::updateUsername(updateUsername);
Dirk Wilden's avatar
Dirk Wilden committed
367

Dirk Wilden's avatar
Dirk Wilden committed
368 369 370
    QString updatePassword = "";
    if( _ini.get_entry(updatePassword, "Options", "UpdatePassword") )
      OpenFlipper::Options::updatePassword(updatePassword);
Jan Möbius's avatar
 
Jan Möbius committed
371 372 373
  }
}

374 375 376 377 378 379 380 381 382 383 384 385
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
386
  int mrecent = 10;
387
  if (ini.get_entry(mrecent,"Options","MaxRecent"))
388
    OpenFlipperSettings().setValue("Core/File/MaxRecent", mrecent);
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

  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
413
/** Write the standard options to the given Ini File
Jan Möbius's avatar
 
Jan Möbius committed
414 415
* @param _ini Inifile to use
*/
Dirk Wilden's avatar
Dirk Wilden committed
416
void Core::writeApplicationOptions(INIFile& _ini) {
Jan Möbius's avatar
 
Jan Möbius committed
417 418

  // Write maximum recent file count to ini
419
  _ini.add_entry("Options","MaxRecent", OpenFlipperSettings().value("Core/File/MaxRecent",10).toInt() );
Jan Möbius's avatar
 
Jan Möbius committed
420 421

  // Write list of recent files to ini
422 423 424
  QStringList recentFiles = OpenFlipperSettings().value("Core/File/RecentFiles").toStringList();
  QStringList recentTypes = OpenFlipperSettings().value("Core/File/RecentTypes").toStringList();
  
Jan Möbius's avatar
 
Jan Möbius committed
425 426 427
  for ( int j = 0 ; j < recentFiles.size(); ++j) {
    // Save filename
    QString key = "recent" + QString::number(j);
428
    QString filename = recentFiles[j];
Jan Möbius's avatar
 
Jan Möbius committed
429 430 431
    _ini.add_entry( "Options" , key , filename );
    // Save DataType
    key = "type" + QString::number(j);
432
    QString type = recentTypes[j];
Jan Möbius's avatar
 
Jan Möbius committed
433 434 435
    _ini.add_entry( "Options" , key , type );
  }

436
  // TODO: Save View Mode Toolbars and Context Menu Items
Jan Möbius's avatar
 
Jan Möbius committed
437
  // save ViewModes
Jan Möbius's avatar
Jan Möbius committed
438 439
  QVector< QString > toolboxes;
  QVector< QString > toolbars;
Jan Möbius's avatar
Jan Möbius committed
440
  QVector< QString > icons;
441

Jan Möbius's avatar
 
Jan Möbius committed
442 443 444 445 446
  if ( OpenFlipper::Options::gui() )
    for (int i=0; i < coreWidget_->viewModes_.size(); i++)
      if (coreWidget_->viewModes_[i]->custom){

        //store name
Jan Möbius's avatar
Jan Möbius committed
447
        QString entryToolboxes = coreWidget_->viewModes_[i]->name;
Jan Möbius's avatar
 
Jan Möbius committed
448 449

        //store widgets
Jan Möbius's avatar
Jan Möbius committed
450
        for (int j=0; j < coreWidget_->viewModes_[i]->visibleToolboxes.size(); j++)
Jan Möbius's avatar
Jan Möbius committed
451 452 453
          entryToolboxes += ";" + coreWidget_->viewModes_[i]->visibleToolboxes[j];

        toolboxes.push_back(entryToolboxes);
Jan Möbius's avatar
 
Jan Möbius committed
454

Jan Möbius's avatar
Jan Möbius committed
455 456
        //store name
        QString entryToolbars = coreWidget_->viewModes_[i]->name;
457

Jan Möbius's avatar
Jan Möbius committed
458 459 460
        //store widgets
        for (int j=0; j < coreWidget_->viewModes_[i]->visibleToolbars.size(); j++)
          entryToolbars += ";" + coreWidget_->viewModes_[i]->visibleToolbars[j];
461

Jan Möbius's avatar
Jan Möbius committed
462
        toolbars.push_back(entryToolbars);
463

Jan Möbius's avatar
Jan Möbius committed
464
        icons.push_back(coreWidget_->viewModes_[i]->icon);
465

Jan Möbius's avatar
 
Jan Möbius committed
466 467 468
      }

  //save viewmodes to ini
Jan Möbius's avatar
Jan Möbius committed
469 470 471 472
  _ini.add_entry("Options","ViewModeCount" ,toolboxes.size());
  for (int i=0; i < toolboxes.size(); i++) {
    _ini.add_entry("Options","ViewModeToolboxes" + QString::number(i) ,toolboxes[i]);
    _ini.add_entry("Options","ViewModeToolbars"  + QString::number(i) ,toolbars[i] );
Jan Möbius's avatar
Jan Möbius committed
473
    _ini.add_entry("Options","ViewModeIcon"      + QString::number(i) ,icons[i] );
Jan Möbius's avatar
Jan Möbius committed
474
  }
Jan Möbius's avatar
 
Jan Möbius committed
475

476 477 478 479
  //save KeyBindings
  if ( OpenFlipper::Options::gui() )
    coreWidget_->saveKeyBindings(_ini);

Jan Möbius's avatar
 
Jan Möbius committed
480 481 482 483 484 485
  //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() );

486 487 488 489 490 491 492 493
  //============================================================================
  // other
  //============================================================================
  // 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
494 495 496 497 498
  //============================================================================
  // Debugging
  //============================================================================
  _ini.add_entry("Options","SlotDebugging",OpenFlipper::Options::doSlotDebugging() );

499 500 501 502 503 504
  //============================================================================
  // Write Picking debugger state
  //============================================================================
  _ini.add_entry("Options","RenderPicking",OpenFlipper::Options::renderPicking() );
  _ini.add_entry("Options","PickingRenderMode",OpenFlipper::Options::pickingRenderMode() );

505 506 507 508 509 510 511
  //============================================================================
  // 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
512 513 514 515 516 517
  if ( !_ini.section_exists("Plugins") )
    _ini.add_section("Plugins");

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

518
  QString dir = OpenFlipperSettings().value("Core/CurrentDir").toString().toUtf8();
Jan Möbius's avatar
 
Jan Möbius committed
519
  _ini.add_entry("Options","StartupDir",dir);
Dirk Wilden's avatar
Dirk Wilden committed
520 521

  QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8();
522 523 524 525
  _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
526

527
  _ini.add_entry("Options","RandomBaseColor", OpenFlipper::Options::randomBaseColor() );
Jan Möbius's avatar
 
Jan Möbius committed
528 529 530

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

531 532
    _ini.add_entry("Options","DefaultViewerLayout", OpenFlipper::Options::defaultViewerLayout() );
    _ini.add_entry("Options","Translation", OpenFlipper::Options::translation() );
533
    _ini.add_entry("Options","GridVisible", OpenFlipper::Options::gridVisible() );
534

Dirk Wilden's avatar
Dirk Wilden committed
535 536
    _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
537

Dirk Wilden's avatar
Dirk Wilden committed
538 539
    if ( !_ini.section_exists("ViewerProperties") )
      _ini.add_section("ViewerProperties");
Jan Möbius's avatar
 
Jan Möbius committed
540

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

Dirk Wilden's avatar
Dirk Wilden committed
543 544 545 546 547 548
      _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
549
    //============================================================================
550
    // Save the current viewer properties
Jan Möbius's avatar
 
Jan Möbius committed
551 552
    //============================================================================
    std::vector< QString > draw_modes;
553 554 555 556 557 558 559 560 561

    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) );
    }
562

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

Jan Möbius's avatar
Jan Möbius committed
564
    _ini.add_entry("Options","LoggerState", OpenFlipper::Options::loggerState() );
565
    _ini.add_entry("Options","HideToolbox", OpenFlipper::Options::hideToolbox() );
Jan Möbius's avatar
 
Jan Möbius committed
566 567

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

570
    _ini.add_entry("Options","DefaultBaseColor", (uint)OpenFlipper::Options::defaultBaseColor().rgba ()  );
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
571

572
    _ini.add_entry("Options", "StereoMode",OpenFlipper::Options::stereoMode() );
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
573 574 575

    _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
576 577
  }

578 579
  emit saveOnExit(_ini);

Jan Möbius's avatar
Jan Möbius committed
580
  // _ini.add_entry("Options","Stereo",OpenFlipper::Options::stereo() );
Jan Möbius's avatar
 
Jan Möbius committed
581 582
}

583 584 585 586
void Core::openIniFile( QString _filename,
                        bool    _coreSettings,
                        bool    _perPluginSettings,
                        bool    _loadObjects ){
Jan Möbius's avatar
 
Jan Möbius committed
587 588 589
  INIFile ini;

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

Jan Möbius's avatar
 
Jan Möbius committed
594
  if ( OpenFlipper::Options::gui() ) {
595
    coreWidget_->statusMessage( tr("Loading ini File ") + _filename + " ...");
Jan Möbius's avatar
 
Jan Möbius committed
596 597 598
    coreWidget_->setStatus(ApplicationStatus::BLOCKED );
  }

599
  // Tell plugins that we are currently reading an ini file
600
  OpenFlipper::Options::loadingSettings(true);
Jan Möbius's avatar
 
Jan Möbius committed
601

602 603 604
  // Load Core settings only if requested
  if ( _coreSettings )
    readApplicationOptions(ini);
Jan Möbius's avatar
 
Jan Möbius committed
605

606 607 608
  // if requested load per Plugin settings from the settings file
  if ( _perPluginSettings )
    emit iniLoadOptions( ini );
Jan Möbius's avatar
 
Jan Möbius committed
609

610
  if ( _loadObjects ) {
Jan Möbius's avatar
 
Jan Möbius committed
611

612
    QStringList openFiles;
Jan Möbius's avatar
 
Jan Möbius committed
613

614 615
    // 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
616

617
      bool newActiveObject = false;
Jan Möbius's avatar
 
Jan Möbius committed
618

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

621
        QString sectionName = openFiles[i];
622

623 624 625 626 627 628
        // Check if the string read is empty (e.g. colon at the end of the line ...)
        // So skip trying to read files without a filename.
        if ( sectionName.isEmpty() ) {
          emit log(LOGWARN,tr("Warning from ini file parser: OpenFiles list contains empty string.") );
          continue;
        }
629

630 631 632 633 634
        // Check if the specified section exists
        if ( !ini.section_exists(sectionName) ) {
          emit log(LOGERR,tr("Error parsing ini file. OpenFiles section %1 not found in File!").arg(sectionName));
          continue;
        }
635

636
        // Get the path for the file which should be opened
637
        QString path;
638 639 640 641
        if ( !ini.get_entry( path, sectionName , "path" ) ) {
          emit log(LOGERR,tr("Error parsing ini file. Section %1 contains no path description!").arg(sectionName));
          continue;
        }
642

643
        // Check if path is relative ( The path is considered to be relative if the first character is a ".")
644
        if (path.startsWith( "." + OpenFlipper::Options::dirSeparator() )){
645

646
          // check if _filename contains a path by testing if it contains a directory separator
647 648 649 650
          if (_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) != ""){
            path.remove(0,1); // remove .
            path = _filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) + path;
          }
651

Jan Möbius's avatar
 
Jan Möbius committed
652 653
        }

654
        int tmpType;
655
        DataType type = typeId("TriangleMesh");
656

657
        // First check for old datatype style (Only numbers .. therefore not consistent for runtime added types)
658 659
        if ( ini.get_entry( tmpType, sectionName , "type"  )) {
          type = DataType(tmpType);
660 661
          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 )") );
662
        } else {
663

664
          // Read new style type. The type is represented by its name (as a QString)
665 666 667 668
          QString typeName="";
          if ( ini.get_entry( typeName, sectionName , "type"  )) {
            type = typeId(typeName);
          } else
669
            emit log(LOGWARN, tr("Unable to get DataType for object %1 assuming Triangle Mesh!").arg(sectionName) );
670
        }
Jan Möbius's avatar
 
Jan Möbius committed
671

672
        // Now the object gets loaded based on the given datatype
673
        int newObjectId = loadObject(type, path);
Jan Möbius's avatar
 
Jan Möbius committed
674

675
        // get the new object from the object tree ( If that fails, the object was not loaded correctly)
676 677
        BaseObject* object = objectRoot_->childExists( newObjectId );
        if ( object == 0 )  {
678
          emit log(LOGERR,tr("Unable to open Object ") + path);
679 680 681
          continue;
        }

682
        // Read the target flag setting
683
        bool flag;
684
        if ( ini.get_entry( flag, sectionName , "target" ) )
685 686
          object->target(flag);

687
        // Read the source flag setting
688 689
        if ( ini.get_entry( flag, sectionName , "source" ) )
          object->source(flag);
Jan Möbius's avatar
 
Jan Möbius committed
690

691
        // Tell plugins to load their per object settings
692
        emit iniLoad( ini,object->id() );
Jan Möbius's avatar
 
Jan Möbius committed
693

694
      }
Jan Möbius's avatar
 
Jan Möbius committed
695 696 697 698
    }

  }

699
  // Tell Plugins that all objects are loaded and they should read the remaining parts if necessary
700
  if ( _perPluginSettings )
701
    emit iniLoadOptionsLast( ini );
Jan Möbius's avatar
 
Jan Möbius committed
702

703
  // close ini file
Jan Möbius's avatar
 
Jan Möbius committed
704 705
  ini.disconnect();

706
  // As the reading has been completed, tell plugins that we do not read an ini file anymore.
707
  OpenFlipper::Options::loadingSettings(false);
Jan Möbius's avatar
 
Jan Möbius committed
708

709
  // Reset scenegraph and reset trackball center
710
  // This will also recompute the bounding boxes as well as the near and far plane
711
  resetScenegraph(true);
Jan Möbius's avatar
Jan Möbius committed
712

Dirk Wilden's avatar
Dirk Wilden committed
713 714
  if ( OpenFlipper::Options::gui() ){
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
715
      PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
Dirk Wilden's avatar
Dirk Wilden committed
716 717
      coreWidget_->examiner_widgets_[i]->viewAll();
    }
Jan Möbius's avatar
Jan Möbius committed
718

719
    coreWidget_->statusMessage( tr("Loading ini File ") + _filename + tr(" ... Done"), 4000);
Jan Möbius's avatar
 
Jan Möbius committed
720 721 722 723 724
    coreWidget_->setStatus(ApplicationStatus::READY );
  }

}

725 726 727 728 729 730
void Core::writeIniFile(QString _filename,
                        bool _relativePaths,
                        bool _targetOnly,
                        bool _saveSystemSettings,
                        bool _savePluginSettings ,
                        bool _saveObjectInfo ) {
Jan Möbius's avatar
Jan Möbius committed
731

Jan Möbius's avatar
 
Jan Möbius committed
732 733 734
  INIFile ini;

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

Jan Möbius's avatar
 
Jan Möbius committed
739
  if ( OpenFlipper::Options::gui() ) {
740
    coreWidget_->statusMessage( tr("Saving ini File ") + _filename + " ...");
Jan Möbius's avatar
 
Jan Möbius committed
741 742 743
    coreWidget_->setStatus(ApplicationStatus::BLOCKED );
  }

744
  // Only save application settings when requested
745
  if ( _saveSystemSettings )
746
    writeApplicationOptions(ini);
Jan Möbius's avatar
 
Jan Möbius committed
747

748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
  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
765
                                          o_it != PluginFunctions::objectsEnd(); ++o_it) {
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
      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
784

785
      }
Jan Möbius's avatar
 
Jan Möbius committed
786 787
    }

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

790 791
    // 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
792
                                          o_it != PluginFunctions::objectsEnd(); ++o_it)
793 794
      emit iniSave(  ini , o_it->id() );
  }
Jan Möbius's avatar
 
Jan Möbius committed
795 796 797 798



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

Jan Möbius's avatar
 
Jan Möbius committed
800
  if ( OpenFlipper::Options::gui() ) {
801
    coreWidget_->statusMessage( tr("Saving ini File ") + _filename + tr(" ... Done"), 4000);
Jan Möbius's avatar
 
Jan Möbius committed
802 803 804 805 806 807
    coreWidget_->setStatus(ApplicationStatus::READY );
  }
}


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