optionHandling.cc 8.64 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
//=============================================================================
//
//                               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.
Jan Möbius's avatar
Jan Möbius committed
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16 17 18 19
//  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.
Jan Möbius's avatar
Jan Möbius committed
20
//
Jan Möbius's avatar
 
Jan Möbius committed
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
//  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"
51
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
Jan Möbius's avatar
 
Jan Möbius committed
52

Jan Möbius's avatar
Jan Möbius committed
53
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
54 55 56 57

void Core::applyOptions(){

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

Jan Möbius's avatar
 
Jan Möbius committed
59 60
    //Init ViewModes
    coreWidget_->initViewModes();
Jan Möbius's avatar
Jan Möbius committed
61

Jan Möbius's avatar
 
Jan Möbius committed
62 63 64 65
    //Set default Viewmode
    if (OpenFlipper::Options::defaultToolboxMode() != "")
      coreWidget_->slotChangeView(OpenFlipper::Options::defaultToolboxMode(), QStringList());
    //Set Fullscreen
Dirk Wilden's avatar
Dirk Wilden committed
66
    if ( OpenFlipper::Options::fullScreen() )
67
      coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
Dirk Wilden's avatar
Dirk Wilden committed
68
    else
69
		  coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
Jan Möbius's avatar
Jan Möbius committed
70

71 72
    // Logger
    coreWidget_->hideLogger( OpenFlipper::Options::hideLogger() );
Jan Möbius's avatar
Jan Möbius committed
73

Jan Möbius's avatar
 
Jan Möbius committed
74 75
    //animation
    coreWidget_->examiner_widget_->animation(OpenFlipper::Options::animation());
Jan Möbius's avatar
Jan Möbius committed
76

Jan Möbius's avatar
 
Jan Möbius committed
77 78
    //Backface Culling
    coreWidget_->examiner_widget_->backFaceCulling(OpenFlipper::Options::backfaceCulling());
Dirk Wilden's avatar
Dirk Wilden committed
79 80 81 82

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

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    // Picking Debugger
    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;
    } else {
      target = ACG::SceneGraph::PICK_ANYTHING;
    }
    coreWidget_->examiner_widget_->renderPicking(OpenFlipper::Options::renderPicking(), target );


Jan Möbius's avatar
 
Jan Möbius committed
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);
Jan Möbius's avatar
Jan Möbius committed
106

Jan Möbius's avatar
 
Jan Möbius committed
107
      //hide ViewMode Selection Widget
Jan Möbius's avatar
Jan Möbius committed
108
      coreWidget_->dockViewMode_->setVisible(false);
Jan Möbius's avatar
 
Jan Möbius committed
109
    }
Jan Möbius's avatar
Jan Möbius committed
110

Dirk Wilden's avatar
Dirk Wilden committed
111 112 113 114 115 116 117 118 119 120 121 122 123
    //setup logFile
    if (logFile_ != 0){

      if (OpenFlipper::Options::logFile() != logFile_->fileName() ){
        logFile_->close();
        delete logFile_;
        logFile_ = 0;
        if (logStream_ != 0){
          delete logStream_;
          logStream_ = 0;
        }
      }
    }
124

125 126 127
    //set defaultBackgroundColor
    QColor c = QColor( OpenFlipper::Options::defaultBackgroundColor() );
    PluginFunctions::setBackColor( OpenMesh::Vec4f(c.redF(),c.greenF(),c.blueF(),0.0f) );
Dirk Wilden's avatar
Dirk Wilden committed
128

Jan Möbius's avatar
 
Jan Möbius committed
129
    updateView();
Jan Möbius's avatar
Jan Möbius committed
130

Jan Möbius's avatar
 
Jan Möbius committed
131 132 133
  }
}

Dirk Wilden's avatar
Dirk Wilden committed
134
void Core::saveOptions(){
Jan Möbius's avatar
Jan Möbius committed
135
  QString inifile = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
Dirk Wilden's avatar
Dirk Wilden committed
136 137 138 139 140
                                                  OpenFlipper::Options::dirSeparator() +  "OpenFlipper.ini";

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

Dirk Wilden's avatar
Dirk Wilden committed
142 143 144 145 146 147 148 149 150
    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
151
  }
Dirk Wilden's avatar
Dirk Wilden committed
152 153
}

Jan Möbius's avatar
 
Jan Möbius committed
154
void Core::setupOptions() {
Jan Möbius's avatar
Jan Möbius committed
155

Jan Möbius's avatar
 
Jan Möbius committed
156
  // Get the Main config dir in the home directory and possibly create it
Jan Möbius's avatar
Jan Möbius committed
157 158
  QDir configDir = QDir::home();

Jan Möbius's avatar
 
Jan Möbius committed
159 160 161 162 163
  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");
Jan Möbius's avatar
Jan Möbius committed
164
      return;
Jan Möbius's avatar
 
Jan Möbius committed
165 166 167
    }
  }
  OpenFlipper::Options::configDir(configDir);
Jan Möbius's avatar
Jan Möbius committed
168

Jan Möbius's avatar
 
Jan Möbius committed
169 170 171 172
  // 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());
Jan Möbius's avatar
Jan Möbius committed
173

Jan Möbius's avatar
 
Jan Möbius committed
174 175 176
  // Set the standard path to the plugins
  tempDir.cd("Plugins");

Jan Möbius's avatar
Jan Möbius committed
177
  ///@todo do not check WIN32 Only
Jan Möbius's avatar
 
Jan Möbius committed
178 179
  if ( OpenFlipper::Options::is64bit() )
    tempDir.cd("64");
Jan Möbius's avatar
Jan Möbius committed
180

Jan Möbius's avatar
 
Jan Möbius committed
181 182 183 184 185 186
  if ( OpenFlipper::Options::is32bit() )
      #ifdef WIN32
         tempDir.cd("win32");
      #else
	      tempDir.cd("32");
      #endif
Jan Möbius's avatar
Jan Möbius committed
187

Jan Möbius's avatar
 
Jan Möbius committed
188 189 190 191 192 193 194 195 196 197 198 199

   #ifdef WIN32
      #ifdef NDEBUG
              tempDir.cd("Release");
      #else
              tempDir.cd("Debug");
      #endif
   #else
      #ifdef DEBUG
              tempDir.cd("dbg");
      #else
              tempDir.cd("max");
Jan Möbius's avatar
Jan Möbius committed
200 201 202
      #endif
   #endif

Jan Möbius's avatar
 
Jan Möbius committed
203
  OpenFlipper::Options::pluginDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
204

Jan Möbius's avatar
 
Jan Möbius committed
205 206 207 208
  // Set the Path to the shaders
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Shaders");
  OpenFlipper::Options::shaderDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
209 210


Jan Möbius's avatar
 
Jan Möbius committed
211 212 213 214
  // Set the Path to the textures
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Textures");
  OpenFlipper::Options::textureDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
215

Jan Möbius's avatar
 
Jan Möbius committed
216 217 218 219
  // Set the Path to the Icons
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Icons");
  OpenFlipper::Options::iconDir(tempDir.absolutePath());
Jan Möbius's avatar
Jan Möbius committed
220

Jan Möbius's avatar
Jan Möbius committed
221 222 223 224 225
  // Set the Path to the Fonts
  tempDir = QDir(OpenFlipper::Options::applicationDir());
  tempDir.cd("Fonts");
  OpenFlipper::Options::fontsDir(tempDir.absolutePath());

Jan Möbius's avatar
 
Jan Möbius committed
226
  QStringList optionFiles;
Jan Möbius's avatar
Jan Möbius committed
227

Jan Möbius's avatar
 
Jan Möbius committed
228 229 230 231
  // ==============================================================
  // 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
232 233 234
  if ( globalIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
 
Jan Möbius committed
235 236 237 238
  // ==============================================================
  // 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
239 240 241
  if ( localIni.exists() )
    optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");

Jan Möbius's avatar
 
Jan Möbius committed
242 243
  // Set the previously generated Optionfiles
  OpenFlipper::Options::optionFiles(optionFiles);
Jan Möbius's avatar
Jan Möbius committed
244 245


Jan Möbius's avatar
 
Jan Möbius committed
246 247 248
  // ==============================================================
  // Load Application options from all files available
  // ==============================================================
Jan Möbius's avatar
Jan Möbius committed
249

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

Jan Möbius's avatar
 
Jan Möbius committed
252
    INIFile _ini;
Jan Möbius's avatar
Jan Möbius committed
253

Jan Möbius's avatar
 
Jan Möbius committed
254 255 256
    if ( ! _ini.connect(optionFiles[i],false) ) {
      emit log(LOGERR,"Failed to connect to _ini file" + optionFiles[i]);
      continue;
Jan Möbius's avatar
Jan Möbius committed
257 258
    }

Jan Möbius's avatar
 
Jan Möbius committed
259
    readApplicationOptions(_ini);
Jan Möbius's avatar
Jan Möbius committed
260

Jan Möbius's avatar
 
Jan Möbius committed
261 262
    _ini.disconnect();
  }
Jan Möbius's avatar
Jan Möbius committed
263

Jan Möbius's avatar
 
Jan Möbius committed
264 265 266
}

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