optionHandling.cc 12 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




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


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

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

60
61
#include <OpenFlipper/INIFile/INIFile.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
62
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Jan Möbius's avatar
   
Jan Möbius committed
63

64
65
66
#include <QCoreApplication>


Jan Möbius's avatar
Jan Möbius committed
67
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
   
Jan Möbius committed
68
69
70
71

void Core::applyOptions(){

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

Jan Möbius's avatar
   
Jan Möbius committed
73
74
    //Init ViewModes
    coreWidget_->initViewModes();
Jan Möbius's avatar
Jan Möbius committed
75

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

85
    // Logger
Jan Möbius's avatar
Jan Möbius committed
86
    coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
Jan Möbius's avatar
Jan Möbius committed
87

Dirk Wilden's avatar
Dirk Wilden committed
88
89
90
91
92
93
94
    // Toolbar Size
    switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
      case 1  : coreWidget_->setIconSize( QSize(16,16) );break;
      case 2  : coreWidget_->setIconSize( QSize(32,32) );break;
      default : coreWidget_->setIconSize( coreWidget_->defaultIconSize() );
    }

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
95
    // gl mouse cursor
96
    coreWidget_->setForceNativeCursor( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
97
    
Jan Möbius's avatar
Jan Möbius committed
98
    // Prepare Picking Debugger Flag
99
100
101
102
103
104
105
106
107
    ACG::SceneGraph::PickTarget target;
    if ( OpenFlipper::Options::pickingRenderMode() == "PICK_ANYHING") {
      target = ACG::SceneGraph::PICK_ANYTHING;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_VERTEX") {
      target = ACG::SceneGraph::PICK_VERTEX;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_EDGE") {
      target = ACG::SceneGraph::PICK_EDGE;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FACE") {
      target = ACG::SceneGraph::PICK_FACE;
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
108
109
110
111
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_VERTEX") {
      target = ACG::SceneGraph::PICK_FRONT_VERTEX;
    } else if ( OpenFlipper::Options::pickingRenderMode() == "PICK_FRONT_EDGE") {
      target = ACG::SceneGraph::PICK_FRONT_EDGE;
112
113
114
    } else {
      target = ACG::SceneGraph::PICK_ANYTHING;
    }
Jan Möbius's avatar
Jan Möbius committed
115

116
117
118
119
120
121
    //set viewer properties
    for (int i=0; i < PluginFunctions::viewers(); i++){

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

122
123
124
      //only switch projection here if an object is opened
      //this prevents problems when applying options on app start
      if ( PluginFunctions::objectCount() > 0 ){ 
125
126
127
128
        if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
          PluginFunctions::orthographicProjection(i);
        else
          PluginFunctions::perspectiveProjection(i);
129
      }
130
131
    }

132
    if ( OpenFlipper::Options::multiView() )
133
      coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
134

135
136
137
138
//     if ( OpenFlipper::Options::gridVisible() )
//       gridNode_->show();
//     else
//       gridNode_->hide();
139

140
    //set defaultBackgroundColor
141
    QColor c =  OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
Jan Möbius's avatar
Jan Möbius committed
142

143
    for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
Jan Möbius's avatar
Jan Möbius committed
144
      //wheel zoom factor
Jan Möbius's avatar
Jan Möbius committed
145
146
      PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor").toDouble() );
      PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift").toDouble() );
Jan Möbius's avatar
Jan Möbius committed
147
148

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

Jan Möbius's avatar
   
Jan Möbius committed
152
153
    //hideToolbox
    if (OpenFlipper::Options::hideToolbox()) {
154

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
155
      coreWidget_->showToolbox (false);
Jan Möbius's avatar
   
Jan Möbius committed
156
    }
Jan Möbius's avatar
Jan Möbius committed
157

Dirk Wilden's avatar
Dirk Wilden committed
158
159
160
    //setup logFile
    if (logFile_ != 0){

Jan Möbius's avatar
Jan Möbius committed
161
      if (  OpenFlipperSettings().value("Core/Log/logFile").toString() != logFile_->fileName() ){
Dirk Wilden's avatar
Dirk Wilden committed
162
163
164
165
166
167
168
169
170
        logFile_->close();
        delete logFile_;
        logFile_ = 0;
        if (logStream_ != 0){
          delete logStream_;
          logStream_ = 0;
        }
      }
    }
171

Jan Möbius's avatar
   
Jan Möbius committed
172
    updateView();
Jan Möbius's avatar
Jan Möbius committed
173

Jan Möbius's avatar
   
Jan Möbius committed
174
175
176
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
177
void Core::saveOptions(){
Jan Möbius's avatar
Jan Möbius committed
178
  QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
Dirk Wilden's avatar
Dirk Wilden committed
179
180
181
182
                                                  OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";

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

Dirk Wilden's avatar
Dirk Wilden committed
185
    if ( ! ini.connect( inifile,true) ) {
186
      emit log(LOGERR,tr("Can not create user ini file"));
Dirk Wilden's avatar
Dirk Wilden committed
187
188
189
190
191
192
193
    } else {
      writeApplicationOptions(ini);
      ini.disconnect();
    }
  } else {
    writeApplicationOptions(ini);
    ini.disconnect();
Jan Möbius's avatar
Jan Möbius committed
194
  }
Dirk Wilden's avatar
Dirk Wilden committed
195
196
}

Jan Möbius's avatar
   
Jan Möbius committed
197
void Core::setupOptions() {
Jan Möbius's avatar
Jan Möbius committed
198

Jan Möbius's avatar
Jan Möbius committed
199
200
  // initialize the Settings:
  OpenFlipper::Options::initializeSettings();
201

Jan Möbius's avatar
   
Jan Möbius committed
202
  QStringList optionFiles;
Jan Möbius's avatar
Jan Möbius committed
203

Jan Möbius's avatar
   
Jan Möbius committed
204
205
206
207
  // ==============================================================
  // Global ini file in the application directory
  // ==============================================================
  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
Jan Möbius's avatar
Jan Möbius committed
208
209
210
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
211
212
213
214
  // ==============================================================
  // Local ini file in the users home directory
  // ==============================================================
  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
Jan Möbius's avatar
Jan Möbius committed
215
216
217
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
   
Jan Möbius committed
218
219
  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);
Jan Möbius's avatar
Jan Möbius committed
220

221
222
223
224
225
226
227
  // ==============================================================
  // Default File open directories
  // ==============================================================
  // Default to OpenFlippers Texture dir
  OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());

  // Default to home directory
228
  OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
Jan Möbius's avatar
Jan Möbius committed
229

Jan Möbius's avatar
   
Jan Möbius committed
230
231
232
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
Jan Möbius's avatar
Jan Möbius committed
233

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

Jan Möbius's avatar
   
Jan Möbius committed
236
    INIFile _ini;
Jan Möbius's avatar
Jan Möbius committed
237

Jan Möbius's avatar
   
Jan Möbius committed
238
    if ( ! _ini.connect(optionFiles[i],false) ) {
239
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
Jan Möbius's avatar
   
Jan Möbius committed
240
      continue;
Jan Möbius's avatar
Jan Möbius committed
241
242
    }

Jan Möbius's avatar
   
Jan Möbius committed
243
    readApplicationOptions(_ini);
Jan Möbius's avatar
Jan Möbius committed
244

Jan Möbius's avatar
   
Jan Möbius committed
245
246
    _ini.disconnect();
  }
Jan Möbius's avatar
Jan Möbius committed
247

Jan Möbius's avatar
   
Jan Möbius committed
248
249
}

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/// restore key Assignments that were saved in config files
void Core::restoreKeyBindings(){

  QStringList optionFiles;

  // ==============================================================
  // Global ini file in the application directory
  // ==============================================================
  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

  // ==============================================================
  // Local ini file in the users home directory
  // ==============================================================
  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);


  // ==============================================================
  // Load Application options from all files available
  // ==============================================================

  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {

    INIFile _ini;

    if ( ! _ini.connect(optionFiles[i],false) ) {
282
      emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
283
284
285
286
287
288
289
290
291
292
      continue;
    }

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

    _ini.disconnect();
  }
}

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