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::getLocalIniFullPath();
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 OpenFlipper::Options::initializeSettings();
171
172 QStringList optionFiles = OpenFlipper::Options::optionFiles();
173
174 // ==============================================================
175 // Default File open directories
176 // ==============================================================
177 // Default to OpenFlippers Texture dir
178 OpenFlipper::Options::currentTextureDir(OpenFlipper::Options::textureDirStr());
179
180 // Default to home directory
181 OpenFlipperSettings().setValue("Core/CurrentDir", QDir::homePath() );
182
183 // ==============================================================
184 // Load Application options from all files available
185 // ==============================================================
186
187 for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
188
189 INIFile _ini;
190
191 if ( ! _ini.connect(optionFiles[i],false) ) {
192 emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
193 continue;
194 }
195 // FIXME: at startup, `emit log` is not working, should fix that instead of resorting to cerr:
196 std::cout << tr("Loading application options from %1").arg(optionFiles[i]).toStdString() << std::endl;
197
199
200 _ini.disconnect();
201 }
202
203}
204
207{
208 QStringList optionFiles = OpenFlipper::Options::optionFiles();
209
210 // ==============================================================
211 // Load Application options from all files available
212 // ==============================================================
213
214 for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
215
216 INIFile _ini;
217
218 if ( ! _ini.connect(optionFiles[i],false) ) {
219 emit log(LOGERR,tr("Failed to connect to _ini file") + optionFiles[i]);
220 continue;
221 }
222
223 if ( OpenFlipper::Options::gui() )
225
226 _ini.disconnect();
227 }
228}
229
230//=============================================================================
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
@ LOGERR
QSize defaultIconSize()
Show logger in splitter or not.
void showToolbox(bool _state)
Show or hide toolbox.
Definition: CoreWidget.cc:759
void setViewerLayout(int _idx)
Change viewer layout that was selected in the combo box.
Definition: CoreWidget.cc:995
void initViewModes()
init ViewModes that were loaded via ini-file
Definition: viewMode.cc:54
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:414
void setForceNativeCursor(bool _state)
Use native or gl painted cursor.
Definition: CoreWidget.cc:1098
void setToolBoxOrientationOnTheRight(bool _toolBoxRight)
Set orientation of tool box (either on the right or the left side of the screen)
Definition: CoreWidget.cc:838
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options
void setupOptions()
Get all ini files and set basic paths and options.
void writeApplicationOptions(INIFile &_ini)
Write Application options to ini file.
Definition: ParseIni.cc:285
void readApplicationOptions(INIFile &_ini)
Get and set Application options from ini file.
Definition: ParseIni.cc:72
QTextStream * logStream_
stream for logging to file
Definition: Core.hh:1207
void saveOptions()
Save the current options to the standard ini file.
void updateView()
Called when a plugin requests an update in the viewer.
Definition: Core.cc:966
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
QFile * logFile_
logfile
Definition: Core.hh:1210
void restoreKeyBindings()
Restore key assignments from configs files.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
Definition: Core.hh:1652
Class for the handling of simple configuration files.
Definition: INIFile.hh:100
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:70
void disconnect()
Remove connection of this object to a file.
Definition: INIFile.cc:122
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
double wheelZoomFactorShift()
Zoom factor when using mouse wheel and pressing shift.
bool wheelInvert()
Invert mouse wheel direction?
double wheelZoomFactor()
Zoom factor when using mouse wheel.
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
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 orthographicProjection(int _viewer)
Switch to orthographic Projection.
int viewers()
Get the number of viewers.
void setFixedView(int _mode, int _viewer)
Set a fixed View for a viewer.
void allowRotation(bool _mode, int _viewer)