optionHandling.cc 7.44 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
//=============================================================================
//
//                               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 of Path and File Handling
//
//=============================================================================


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

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

#include "OpenFlipper/INIFile/INIFile.hh"
#include "OpenFlipper/common/GlobalOptions.hh"

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

void Core::applyOptions(){

  if ( OpenFlipper::Options::gui() ) {
    
    //Init ViewModes
    coreWidget_->initViewModes();
  
    //Set default Viewmode
    if (OpenFlipper::Options::defaultToolboxMode() != "")
      coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList());
    //Set Fullscreen
Dirk Wilden's avatar
Dirk Wilden committed
65
66
67
68
    if ( OpenFlipper::Options::fullScreen() )
      coreWidget_->setWindowState(Qt::WindowFullScreen);
    else
      coreWidget_->setWindowState(!Qt::WindowFullScreen);
Jan Möbius's avatar
   
Jan Möbius committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  
    //Hide Logger
    if (OpenFlipper::Options::hideLogger()) {
      QList<int> wsizes( coreWidget_->splitter_->sizes() );
      wsizes[0] = wsizes[0]+wsizes[1];
      wsizes[1] = 0;
      coreWidget_->splitter_->setSizes(wsizes);
    }
    
    
    //animation
    coreWidget_->examiner_widget_->animation(OpenFlipper::Options::animation());
  
    //Backface Culling
    coreWidget_->examiner_widget_->backFaceCulling(OpenFlipper::Options::backfaceCulling());
Dirk Wilden's avatar
Dirk Wilden committed
84
85
86
87

    //wheel zoom factor
    coreWidget_->examiner_widget_->setWheelZoomFactor(OpenFlipper::Options::wheelZoomFactor());
    coreWidget_->examiner_widget_->setWheelZoomFactorShift(OpenFlipper::Options::wheelZoomFactorShift());
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
    
    //hideToolbox
    if (OpenFlipper::Options::hideToolbox()) {
      //hide all toolWidgets
      for (uint p=0; p < plugins.size(); p++)
        if (plugins[p].widget)
          plugins[p].widget->setVisible(false);
  
      //hide ViewMode Selection Widget
      coreWidget_->dockViewMode_->setVisible(false);  
    }
    
    updateView();
    
  }
  
}

Dirk Wilden's avatar
Dirk Wilden committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
void Core::saveOptions(){
  QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" + 
                                                  OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";

  INIFile ini;
  if ( ! ini.connect( inifile ,false) ) {
    emit log(LOGERR,"Failed to connect to users ini file");
    
    if ( ! ini.connect( inifile,true) ) {
      emit log(LOGERR,"Can not create user ini file");
    } else {
      writeApplicationOptions(ini);
      ini.disconnect();
    }
  } else {
    writeApplicationOptions(ini);
    ini.disconnect();
  }       
}

Jan Möbius's avatar
   
Jan Möbius committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
void Core::setupOptions() {
  
  // Get the Main config dir in the home directory and possibly create it
  QDir configDir = QDir::home(); 
  
  if ( ! configDir.cd(".OpenFlipper") ) {
    emit log(LOGOUT,"Creating config Dir ~/.OpenFlipper");
    configDir.mkdir(".OpenFlipper");
    if ( ! configDir.cd(".OpenFlipper") ) {
      emit log(LOGERR,"Unable to create config dir ~/.OpenFlipper");
      return; 
    }
  }
  OpenFlipper::Options::configDir(configDir);
  
  // Remember the main application directory (assumed to be one above executable Path)
  QDir tempDir = QDir(qApp->applicationDirPath());
  tempDir.cd(".." + OpenFlipper::Options::dirSeparator() );
  OpenFlipper::Options::applicationDir(tempDir.absolutePath());
  
  // Set the standard path to the plugins
  tempDir.cd("Plugins");

  ///@todo do not check WIN32 Only 
  if ( OpenFlipper::Options::is64bit() )
    tempDir.cd("64");
    
  if ( OpenFlipper::Options::is32bit() )
      #ifdef WIN32
         tempDir.cd("win32");
      #else
	      tempDir.cd("32");
      #endif
  

   #ifdef WIN32
      #ifdef NDEBUG
              tempDir.cd("Release");
      #else
              tempDir.cd("Debug");
      #endif
   #else
      #ifdef DEBUG
              tempDir.cd("dbg");
      #else
              tempDir.cd("max");
      #endif		
   #endif    
    
  OpenFlipper::Options::pluginDir(tempDir.absolutePath());
  
  // Set the Path to the shaders
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Shaders");
  OpenFlipper::Options::shaderDir(tempDir.absolutePath());
  
  
  // Set the Path to the textures
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Textures");
  OpenFlipper::Options::textureDir(tempDir.absolutePath());
  
  // Set the Path to the Icons
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Icons");
  OpenFlipper::Options::iconDir(tempDir.absolutePath());
  
  QStringList optionFiles;
  
  // ==============================================================
  // Global ini file in the application directory
  // ==============================================================
  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
  if ( globalIni.exists() ) 
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini"); 
  
  // ==============================================================
  // Local ini file in the users home directory
  // ==============================================================
  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
  if ( localIni.exists() ) 
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini"); 
  
  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);
  
  
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
  
  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
    
    INIFile _ini;
    
    if ( ! _ini.connect(optionFiles[i],false) ) {
      emit log(LOGERR,"Failed to connect to _ini file" + optionFiles[i]);
      continue;
    } 
    
    readApplicationOptions(_ini);
    
    _ini.disconnect();
  }
  
}

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