Developer Documentation
optionHandling.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // CLASS Core - IMPLEMENTATION of Path and File Handling
50 //
51 //=============================================================================
52 
53 
54 //== INCLUDES =================================================================
55 
56 // -------------------- mview
57 #include "Core.hh"
58 // -------------------- ACG
59 
60 
61 //== IMPLEMENTATION ==========================================================
62 
64 
65  if ( OpenFlipper::Options::gui() ) {
66 
67  //Init ViewModes
69 
70  //Set default Viewmode (note: This always resets all toolboxes and should be skipped
71  // here. Setting the initial view mode is instead done when initializing the core
72  // and reading the ini-files.)
73  //if (OpenFlipper::Options::currentViewMode() != "")
74  // coreWidget_->slotChangeView(OpenFlipper::Options::currentViewMode(), QStringList(), QStringList(), QStringList());
75 
76  //Set Fullscreen
77  if ( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() )
78  coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
79  else
80  coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
81 
82  // Logger
83  coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
84 
85  // Toolbar Size
86  switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
87  case 1 : coreWidget_->setIconSize( QSize(16,16) );break;
88  case 2 : coreWidget_->setIconSize( QSize(32,32) );break;
89  default : coreWidget_->setIconSize( coreWidget_->defaultIconSize() );
90  }
91 
92  // gl mouse cursor
93  coreWidget_->setForceNativeCursor( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
94 
95  //set viewer properties
96  for (int i=0; i < PluginFunctions::viewers(); i++){
97 
98  // PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
99  PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
100  PluginFunctions::allowRotation(!OpenFlipper::Options::defaultLockRotation(i),i);
101 
102  //only switch projection here if an object is opened
103  //this prevents problems when applying options on app start
104  if ( PluginFunctions::objectCount() > 0 ){
105  if ( OpenFlipper::Options::defaultPerspectiveProjectionMode(i) )
107  else
109  }
110  }
111 
112  if ( OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() )
113  coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
114 
115 
116  // toolbox orientation
117  coreWidget_->setToolBoxOrientationOnTheRight(OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool());
118 
119  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
120  //wheel zoom factor
121  PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor",1).toDouble() );
122  PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift",0.2).toDouble() );
123  PluginFunctions::viewerProperties(i).wheelInvert( OpenFlipperSettings().value("Core/Mouse/Wheel/Invert",false).toBool() );
124  }
125 
126  //hideToolbox
127  if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() )
128  coreWidget_->showToolbox (false);
129 
130  //setup logFile
131  if (logFile_ != 0){
132 
133  if ( OpenFlipperSettings().value("Core/Log/logFile").toString() != logFile_->fileName() ){
134  logFile_->close();
135  delete logFile_;
136  logFile_ = 0;
137  if (logStream_ != 0){
138  delete logStream_;
139  logStream_ = 0;
140  }
141  }
142  }
143 
144  updateView();
145 
146  }
147 }
148 
150  QString inifile = OpenFlipper::Options::configDirStr() + "OpenFlipper.ini";
151 
152  INIFile ini;
153  if ( ! ini.connect( inifile ,false) ) {
154  emit log(LOGERR,tr("Failed to connect to users ini file"));
155 
156  if ( ! ini.connect( inifile,true) ) {
157  emit log(LOGERR,tr("Can not create user ini file"));
158  } else {
160  ini.disconnect();
161  }
162  } else {
164  ini.disconnect();
165  }
166 }
167 
169 
170  // initialize the Settings:
171  OpenFlipper::Options::initializeSettings();
172 
173  QStringList optionFiles;
174 
175  // ==============================================================
176  // Global ini file in the application directory
177  // ==============================================================
178  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
179  if ( globalIni.exists() )
180  optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
181 
182  // ==============================================================
183  // Local ini file in the users home directory
184  // ==============================================================
185  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
186  if ( localIni.exists() )
187  optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
188 
189  // Set the previously generated option files
190  OpenFlipper::Options::optionFiles(optionFiles);
191 
192  // ==============================================================
193  // Default File open directories
194  // ==============================================================
195  // Default to OpenFlippers Texture dir
196  OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
197 
198  // Default to home directory
199  OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
200 
201  // ==============================================================
202  // Load Application options from all files available
203  // ==============================================================
204 
205  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
206 
207  INIFile _ini;
208 
209  if ( ! _ini.connect(optionFiles[i],false) ) {
210  emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
211  continue;
212  }
213 
215 
216  _ini.disconnect();
217  }
218 
219 }
220 
223 
224  QStringList optionFiles;
225 
226  // ==============================================================
227  // Global ini file in the application directory
228  // ==============================================================
229  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
230  if ( globalIni.exists() )
231  optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
232 
233  // ==============================================================
234  // Local ini file in the users home directory
235  // ==============================================================
236  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
237  if ( localIni.exists() )
238  optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
239 
240  // Set the previously generated Optionfiles
241  OpenFlipper::Options::optionFiles(optionFiles);
242 
243 
244  // ==============================================================
245  // Load Application options from all files available
246  // ==============================================================
247 
248  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
249 
250  INIFile _ini;
251 
252  if ( ! _ini.connect(optionFiles[i],false) ) {
253  emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
254  continue;
255  }
256 
257  if ( OpenFlipper::Options::gui() )
259 
260  _ini.disconnect();
261  }
262 }
263 
264 //=============================================================================
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void allowRotation(bool _mode, int _viewer)
void setToolBoxOrientationOnTheRight(bool _toolBoxRight)
Set orientation of tool box (either on the right or the left side of the screen)
Definition: CoreWidget.cc:820
QTextStream * logStream_
stream for logging to file
Definition: Core.hh:1207
void setFixedView(int _mode, int _viewer)
Set a fixed View for a viewer.
void setForceNativeCursor(bool _state)
Use native or gl painted cursor.
Definition: CoreWidget.cc:1080
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
double wheelZoomFactor()
Zoom factor when using mouse wheel.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:70
void setViewerLayout(int _idx)
Change viewer layout that was selected in the combo box.
Definition: CoreWidget.cc:977
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
Definition: Core.hh:1596
int viewers()
Get the number of viewers.
void showLogger(OpenFlipper::Options::LoggerState _state)
Change visibility of the logger.
void loadKeyBindings(INIFile &_ini)
Load key assignments from a given INI file.
Definition: keyHandling.cc:396
void showToolbox(bool _state)
Show or hide toolbox.
Definition: CoreWidget.cc:741
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
QFile * logFile_
logfile
Definition: Core.hh:1210
void setupOptions()
Get all ini files and set basic paths and options.
void orthographicProjection(int _viewer)
Switch to orthographic Projection.
void updateView()
Called when a plugin requests an update in the viewer.
Definition: Core.cc:898
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options ...
bool wheelInvert()
Invert mouse wheel direction?
void restoreKeyBindings()
Restore key assignments from configs files.
void writeApplicationOptions(INIFile &_ini)
Write Application options to ini file.
Definition: ParseIni.cc:285
void saveOptions()
Save the current options to the standard ini file.
void initViewModes()
init ViewModes that were loaded via ini-file
Definition: viewMode.cc:54
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
double wheelZoomFactorShift()
Zoom factor when using mouse wheel and pressing shift.
int objectCount()
Get the number of available objects.
void readApplicationOptions(INIFile &_ini)
Get and set Application options from ini file.
Definition: ParseIni.cc:72
void disconnect()
Remove connection of this object to a file.
Definition: INIFile.cc:122
QSize defaultIconSize()
Show logger in splitter or not.
Class for the handling of simple configuration files.
Definition: INIFile.hh:99