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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS Core - IMPLEMENTATION of Path and File Handling
56 //
57 //=============================================================================
58 
59 
60 //== INCLUDES =================================================================
61 
62 // -------------------- mview
63 #include "Core.hh"
64 // -------------------- ACG
65 
66 
67 //== IMPLEMENTATION ==========================================================
68 
70 
71  if ( OpenFlipper::Options::gui() ) {
72 
73  //Init ViewModes
75 
76  //Set default Viewmode (note: This always resets all toolboxes and should be skipped
77  // here. Setting the initial view mode is instead done when initializing the core
78  // and reading the ini-files.)
79  //if (OpenFlipper::Options::currentViewMode() != "")
80  // coreWidget_->slotChangeView(OpenFlipper::Options::currentViewMode(), QStringList(), QStringList(), QStringList());
81 
82  //Set Fullscreen
83  if ( OpenFlipperSettings().value("Core/Gui/fullscreen",false).toBool() )
84  coreWidget_->setWindowState( coreWidget_->windowState() | Qt::WindowFullScreen);
85  else
86  coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen);
87 
88  // Logger
89  coreWidget_->showLogger( OpenFlipper::Options::loggerState() );
90 
91  // Toolbar Size
92  switch ( OpenFlipperSettings().value("Core/Toolbar/iconSize",0).toInt() ){
93  case 1 : coreWidget_->setIconSize( QSize(16,16) );break;
94  case 2 : coreWidget_->setIconSize( QSize(32,32) );break;
95  default : coreWidget_->setIconSize( coreWidget_->defaultIconSize() );
96  }
97 
98  // gl mouse cursor
99  coreWidget_->setForceNativeCursor( OpenFlipperSettings().value("Core/Gui/glViewer/nativeMouse",false).toBool() );
100 
101  //set viewer properties
102  for (int i=0; i < PluginFunctions::viewers(); i++){
103 
104  // PluginFunctions::setDrawMode( OpenFlipper::Options::defaultDrawMode(i), i );
105  PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
106  PluginFunctions::allowRotation(!OpenFlipper::Options::defaultLockRotation(i),i);
107 
108  //only switch projection here if an object is opened
109  //this prevents problems when applying options on app start
110  if ( PluginFunctions::objectCount() > 0 ){
111  if ( OpenFlipper::Options::defaultPerspectiveProjectionMode(i) )
113  else
115  }
116  }
117 
118  if ( OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() )
119  coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
120 
121 
122  // toolbox orientation
123  coreWidget_->setToolBoxOrientationOnTheRight(OpenFlipperSettings().value("Core/Gui/ToolBoxes/ToolBoxOnTheRight",true).toBool());
124 
125  for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
126  //wheel zoom factor
127  PluginFunctions::viewerProperties(i).wheelZoomFactor( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactor",1).toDouble() );
128  PluginFunctions::viewerProperties(i).wheelZoomFactorShift( OpenFlipperSettings().value("Core/Mouse/Wheel/ZoomFactorShift",0.2).toDouble() );
129  PluginFunctions::viewerProperties(i).wheelInvert( OpenFlipperSettings().value("Core/Mouse/Wheel/Invert",false).toBool() );
130  }
131 
132  //hideToolbox
133  if ( OpenFlipperSettings().value("Core/Gui/ToolBoxes/hidden",false).toBool() )
134  coreWidget_->showToolbox (false);
135 
136  //setup logFile
137  if (logFile_ != 0){
138 
139  if ( OpenFlipperSettings().value("Core/Log/logFile").toString() != logFile_->fileName() ){
140  logFile_->close();
141  delete logFile_;
142  logFile_ = 0;
143  if (logStream_ != 0){
144  delete logStream_;
145  logStream_ = 0;
146  }
147  }
148  }
149 
150  updateView();
151 
152  }
153 }
154 
156  QString inifile = OpenFlipper::Options::configDirStr() + "OpenFlipper.ini";
157 
158  INIFile ini;
159  if ( ! ini.connect( inifile ,false) ) {
160  emit log(LOGERR,tr("Failed to connect to users ini file"));
161 
162  if ( ! ini.connect( inifile,true) ) {
163  emit log(LOGERR,tr("Can not create user ini file"));
164  } else {
166  ini.disconnect();
167  }
168  } else {
170  ini.disconnect();
171  }
172 }
173 
175 
176  // initialize the Settings:
177  OpenFlipper::Options::initializeSettings();
178 
179  QStringList optionFiles;
180 
181  // ==============================================================
182  // Global ini file in the application directory
183  // ==============================================================
184  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
185  if ( globalIni.exists() )
186  optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
187 
188  // ==============================================================
189  // Local ini file in the users home directory
190  // ==============================================================
191  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
192  if ( localIni.exists() )
193  optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
194 
195  // Set the previously generated option files
196  OpenFlipper::Options::optionFiles(optionFiles);
197 
198  // ==============================================================
199  // Default File open directories
200  // ==============================================================
201  // Default to OpenFlippers Texture dir
202  OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
203 
204  // Default to home directory
205  OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
206 
207  // ==============================================================
208  // Load Application options from all files available
209  // ==============================================================
210 
211  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
212 
213  INIFile _ini;
214 
215  if ( ! _ini.connect(optionFiles[i],false) ) {
216  emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
217  continue;
218  }
219 
221 
222  _ini.disconnect();
223  }
224 
225 }
226 
229 
230  QStringList optionFiles;
231 
232  // ==============================================================
233  // Global ini file in the application directory
234  // ==============================================================
235  QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
236  if ( globalIni.exists() )
237  optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
238 
239  // ==============================================================
240  // Local ini file in the users home directory
241  // ==============================================================
242  QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
243  if ( localIni.exists() )
244  optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
245 
246  // Set the previously generated Optionfiles
247  OpenFlipper::Options::optionFiles(optionFiles);
248 
249 
250  // ==============================================================
251  // Load Application options from all files available
252  // ==============================================================
253 
254  for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
255 
256  INIFile _ini;
257 
258  if ( ! _ini.connect(optionFiles[i],false) ) {
259  emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
260  continue;
261  }
262 
263  if ( OpenFlipper::Options::gui() )
265 
266  _ini.disconnect();
267  }
268 }
269 
270 //=============================================================================
double wheelZoomFactorShift()
Zoom factor when using mouse wheel and pressing shift.
bool wheelInvert()
Invert mouse wheel direction?
void writeApplicationOptions(INIFile &_ini)
Write Application options to ini file.
Definition: ParseIni.cc:291
void readApplicationOptions(INIFile &_ini)
Get and set Application options from ini file.
Definition: ParseIni.cc:78
void setToolBoxOrientationOnTheRight(bool _toolBoxRight)
Set orientation of tool box (either on the right or the left side of the screen)
Definition: CoreWidget.cc:853
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
Definition: Core.hh:1553
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options ...
void showToolbox(bool _state)
Show or hide toolbox.
Definition: CoreWidget.cc:774
void setupOptions()
Get all ini files and set basic paths and options.
QTextStream * logStream_
stream for logging to file
Definition: Core.hh:1177
void setForceNativeCursor(bool _state)
Use native or gl painted cursor.
Definition: CoreWidget.cc:1109
int viewers()
Get the number of viewers.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
QSize defaultIconSize()
Show logger in splitter or not.
void showLogger(OpenFlipper::Options::LoggerState _state)
Change visibility of the logger.
void setViewerLayout(int _idx)
Change viewer layout that was selected in the combo box.
Definition: CoreWidget.cc:1006
void disconnect()
Remove connection of this object to a file.
Definition: INIFile.cc:128
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
int objectCount()
Get the number of available objects.
void setFixedView(int _mode, int _viewer)
Set a fixed View for a viewer.
void orthographicProjection(int _viewer)
Switch to orthographic Projection.
QFile * logFile_
logfile
Definition: Core.hh:1180
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:76
Class for the handling of simple configuration files.
Definition: INIFile.hh:105
void restoreKeyBindings()
Restore key assignments from configs files.
void updateView()
Called when a plugin requests an update in the viewer.
Definition: Core.cc:887
void initViewModes()
init ViewModes that were loaded via ini-file
Definition: viewMode.cc:60
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
double wheelZoomFactor()
Zoom factor when using mouse wheel.
void allowRotation(bool _mode, int _viewer)
void loadKeyBindings(INIFile &_ini)
Load key assignments from a given INI file.
Definition: keyHandling.cc:402
void saveOptions()
Save the current options to the standard ini file.