Developer Documentation
Loading...
Searching...
No Matches
GlobalOptions.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// Options used throughout the System
46//
47//=============================================================================
48
49#include <QDir>
50
51#include "GlobalOptions.hh"
52#include <iostream>
53#include <ACG/GL/ShaderGenerator.hh>
54#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
55#include <QCoreApplication>
56
57namespace OpenFlipper {
58namespace Options {
59
61static QString compilerInfo_ = "";
62
64static OpenFlipperQSettings* settings_ = 0;
65
67static QDir applicationDir_;
68
70static QDir configDir_;
71
73static QDir pluginDir_;
74
76static QDir shaderDir_;
77
79static QDir textureDir_;
80
82static QDir licenseDir_;
83
85static QDir scriptDir_;
86
88static QDir iconDir_;
89
91static QIcon* OpenFlipperIcon_ = 0;
92
94static QDir translationsDir_;
95
97static QDir fontsDir_;
98
100static QDir helpDir_;
101
103static QDir dataDir_;
104
106static QDir currentDir_;
107
109static QDir currentScriptDir_;
110
112static QDir currentTextureDir_;
113
115static bool startup_ = false;
116
118static bool deleteIniFile_ = false;
119
121static bool nogui_ = false;
122
124static bool stereo_ = true;
125
127static bool coreProfile_ = false;
128static bool profileOverride_ = false;
129
131static QPair<int,int> version_ {4,6};
132static bool versionOverride_ = false;
133
135static int samples_ = 4;
136static bool samplesOverride_ = false;
137
139static bool glStereo_ = true;
140static bool overrideGLStereo_ = false;
141static bool requestedGLStereo = false;
142static bool GLStereoSet = false;
143
145static StereoMode stereoMode_ = OpenGL;
146
148static std::vector<float> anaglyphLeftEyeColors_ = std::vector<float> (9, 0.0);
149static std::vector<float> anaglyphRightEyeColors_ = std::vector<float> (9, 0.0);
150
152static bool synchronization_ = false;
153
155static std::vector<ACG::SceneGraph::DrawModes::DrawMode> defaultDrawMode_ = std::vector<ACG::SceneGraph::DrawModes::DrawMode> (4, ACG::SceneGraph::DrawModes::SOLID_SMOOTH_SHADED);
156
158static int defaultViewerLayout_ = 0;
159
161static int redrawDisabled_ = 0;
162
164static bool drawModesInContextMenu_ = true;
165
167static QString currentViewMode_ = "";
168
169static QString title_ = TOSTRING(PRODUCT_NAME)" v?";
170
172static QColor defaultColor_ = QColor("white");
173
175static bool randomDefaultColor_ = false;
176
178static bool scripting_ = false;
179
181static bool logToConsole_ = false;
182
184static bool debug_ = false;
185
187static bool doSlotDebugging_ = false;
188
190static QString lastDataType_ = "Triangle Mesh";
191
193static bool enableBackup_ = true;
194
196static int sceneGraphUpdatesBlocked_ = 0;
197
199static bool loadingRecentFile_ = false;
200
202static bool savingSettings_ = false;
203
204static int* argc_;
205
206static char *** argv_;
207
208static bool remoteControl_ = false;
209
210static int remoteControlPort_ = 2000;
211
212# if __WORDSIZE == 64
213 const bool is64 = true;
214#else
215 const bool is64 = false;
216#endif
217
218#if defined(WIN32)
219 const bool linux_ = false;
220 const bool windows_ = true;
221 const bool darwin_ = false;
222#elif defined(ARCH_DARWIN)
223 const bool darwin_ = true;
224 const bool linux_ = false;
225 const bool windows_ = false;
226#else
227 const bool darwin_ = false;
228 const bool linux_ = true;
229 const bool windows_ = false;
230#endif
231
232bool is64bit() { return is64; };
233bool is32bit() { return !is64; };
234
235bool isLinux() {
236 return linux_;
237}
238
239bool isWindows() {
240 return windows_;
241}
242
243bool isDarwin() {
244 return darwin_;
245}
246
247
248QString lang() {
249 QString lang = getenv( "LANG" ) ;
250 return lang;
251}
252
253QString dirSeparator() {
254// if (windows_)
255// return QString("\\");
256// if (linux_)
257// return QString("/");
258
259 return QString("/");
260}
261
262QDir applicationDir() { return applicationDir_; }
263QDir configDir() { return configDir_; }
264QDir pluginDir() { return pluginDir_; }
265QDir shaderDir() { return shaderDir_; }
266QDir textureDir() { return textureDir_; }
267QDir licenseDir() { return licenseDir_; }
268QDir scriptDir() { return scriptDir_; }
269QDir iconDir() { return iconDir_; }
270QDir translationsDir() { return translationsDir_; }
271QDir fontsDir() { return fontsDir_; }
272QDir helpDir() { return helpDir_; }
273QDir dataDir() { return dataDir_; }
274QDir currentDir() { return currentDir_; }
275QDir currentScriptDir() { return currentScriptDir_; }
276QDir currentTextureDir(){ return currentTextureDir_; }
277
278QString applicationDirStr() { return applicationDir_.absolutePath(); }
279QString configDirStr() { return configDir_.absolutePath(); }
280QString pluginDirStr() { return pluginDir_.absolutePath(); }
281QString shaderDirStr() { return shaderDir_.absolutePath(); }
282QString textureDirStr() { return textureDir_.absolutePath(); }
283QString licenseDirStr() { return licenseDir_.absolutePath(); }
284QString scriptDirStr() { return scriptDir_.absolutePath(); }
285QString iconDirStr() { return iconDir_.absolutePath(); }
286QString translationsDirStr() { return translationsDir_.absolutePath(); }
287QString fontsDirStr() { return fontsDir_.absolutePath(); }
288QString helpDirStr() { return helpDir_.absolutePath(); }
289QString dataDirStr() { return dataDir_.absolutePath(); }
290QString currentDirStr() { return currentDir_.absolutePath(); }
291QString currentScriptDirStr() { return currentScriptDir_.absolutePath(); }
292QString currentTextureDirStr() { return currentTextureDir_.absolutePath(); }
293
294
295QString getGlobalIniFullPath()
296{
297 return OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini";
298}
299
300QString getLocalIniFullPath()
301{
302 return OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini";
303}
304
305QStringList optionFiles()
306{
307 QStringList names;
308 for (const auto &filename: {getGlobalIniFullPath(), getLocalIniFullPath()}) {
309 if (QFile(filename).exists()) {
310 names.push_back(filename);
311 }
312 }
313 return names;
314}
315
316bool startup() { return startup_; };
317
318void finishedStartup() { startup_ = false;};
319
320QIcon& OpenFlipperIcon() {
321
322 if (OpenFlipperIcon_ == 0){
323 OpenFlipperIcon_ = new QIcon( iconDirStr() + dirSeparator() + "OpenFlipper_Icon_128x128x32.png");
324 OpenFlipperIcon_->addFile( iconDirStr() + dirSeparator() + "OpenFlipper_Icon_48x48x32.png", QSize(48,48) );
325 OpenFlipperIcon_->addFile( iconDirStr() + dirSeparator() + "OpenFlipper_Icon_32x32x32.png", QSize(32,32) );
326 OpenFlipperIcon_->addFile( iconDirStr() + dirSeparator() + "OpenFlipper_Icon_16x16x32.png", QSize(16,16) );
327 }
328
329 return *OpenFlipperIcon_;
330}
331
332void currentDir(QDir _dir) {
333 currentDir_ = _dir;
334}
335
336bool currentDir(QString _dir) {
337 QDir tmp(_dir);
338 if (tmp.exists()) {
339 currentDir_ = tmp;
340 return true;
341 }
342 return false;
343}
344
345
346bool currentScriptDir(QString _dir) {
347 QDir tmp(_dir);
348 if (tmp.exists()) {
349 currentScriptDir_ = tmp;
350 return true;
351 }
352 return false;
353}
354
355bool currentTextureDir(QString _dir) {
356 QDir tmp(_dir);
357 if (tmp.exists()) {
358 currentTextureDir_ = tmp;
359 return true;
360 }
361 return false;
362}
363
364void deleteIniFile(bool _delete) {
365 deleteIniFile_ = _delete;
366}
367
368bool deleteIniFile() {
369 return deleteIniFile_;
370}
371
373void nogui( bool _nogui ) {
374 nogui_ = _nogui;
375}
376
378bool nogui( ) {
379 return nogui_;
380}
381
383bool gui( ) {
384 return !nogui_;
385}
386
388void stereo( bool _stereo ) {
389 stereo_ = _stereo;
390}
391
393bool stereo( ) {
394 return stereo_;
395}
396
398void coreProfile( bool _enableCoreProfile, bool _temporary ) {
399 if(_temporary)
400 {
401 profileOverride_ = true;
402 coreProfile_ = _enableCoreProfile;
403 }
404 else
405 OpenFlipperSettings().setValue("Core/OpenGL/CoreProfile",_enableCoreProfile);
406}
407
409bool coreProfile( ) {
410 if(profileOverride_)
411 return coreProfile_;
412 else
413 return OpenFlipperSettings().value("Core/OpenGL/CoreProfile", false).toBool();
414}
415
417QPair<int,int> glVersion(){
418 if(versionOverride_)
419 return version_;
420 else
421 {
422 // unfortunately QVariant cant store QPair directly, we could try std::pair but its good for now
423 int major = OpenFlipperSettings().value("Core/OpenGL/VersionMajor", 1).value<int>();
424 int minor = OpenFlipperSettings().value("Core/OpenGL/VersionMinor", 0).value<int>();
425 return QPair<int, int>(major,minor);
426 }
427}
428
430void glVersion(const QPair<int,int> & _version, bool _temporary)
431{
432 //possible enhancement: check for validity
433 if(_temporary)
434 {
435 version_ = _version;
436 versionOverride_ = true;
437 }
438 else
439 {
440 OpenFlipperSettings().setValue("Core/OpenGL/VersionMajor",_version.first);
441 OpenFlipperSettings().setValue("Core/OpenGL/VersionMinor",_version.second);
442 }
443}
445void samples(int _samples, bool _temporary) {
446 if(_temporary)
447 {
448 samples_ = _samples;
449 samplesOverride_ = true;
450 }
451 else
452 OpenFlipperSettings().setValue("Core/OpenGL/Samples",_samples);
453}
454
456int samples() {
457 if(samplesOverride_)
458 return samples_;
459 else
460 return OpenFlipperSettings().value("Core/OpenGL/Samples",4).toInt();
461}
462
464void glStereo( bool _glStereo, bool _temporary ) {
465 if(!GLStereoSet) // store the first set value because it is used to create the context
466 { // so we can display it properly later on in options
467 requestedGLStereo = _glStereo;
468 GLStereoSet = true;
469 }
470 if(_temporary)
471 {
472 glStereo_ = _glStereo;
473 overrideGLStereo_ = true;
474 }
475 else
476 OpenFlipperSettings().setValue("Core/OpenGL/Stereo",_glStereo);
477}
478
480bool glStereo( ) {
481 if(overrideGLStereo_)
482 return glStereo_;
483 else
484 return OpenFlipperSettings().value("Core/OpenGL/Stereo",false).toBool();
485}
486
488bool glStereoRequested( ) {
489 return requestedGLStereo;
490}
491
493void stereoMode( StereoMode _mode ) {
494 stereoMode_ = _mode;
495}
496
498StereoMode stereoMode( ) {
499 return stereoMode_;
500}
501
503void eyeDistance( double _eye ) {
504 settings_->setValue("Core/Stereo/EyeDistance",_eye);
505}
506
508double eyeDistance( )
509{
510 return settings_->value("Core/Stereo/EyeDistance",0.07f).toDouble();
511}
512
514void focalDistance( float _focal )
515{
516 settings_->setValue("Core/Stereo/FocalDistance",_focal);
517}
518
520float focalDistance( )
521{
522 return settings_->value("Core/Stereo/FocalDistance",0.5f).toDouble();
523}
524
526void anaglyphLeftEyeColorMatrix( std::vector<float> _mat )
527{
528 for (int i = 0; i < 9; i++)
529 anaglyphLeftEyeColors_[i] = _mat[i];
530}
531
533std::vector<float> anaglyphLeftEyeColorMatrix( )
534{
535 return anaglyphLeftEyeColors_;
536}
537
539void anaglyphRightEyeColorMatrix( std::vector<float> _mat )
540{
541 for (int i = 0; i < 9; i++)
542 anaglyphRightEyeColors_[i] = _mat[i];
543}
544
546std::vector<float> anaglyphRightEyeColorMatrix( )
547{
548 return anaglyphRightEyeColors_;
549}
550
552void synchronization( bool _synchronization ) {
553 synchronization_ = _synchronization;
554}
555
557bool synchronization( ) {
558 return synchronization_;
559}
560
561void defaultDrawMode( ACG::SceneGraph::DrawModes::DrawMode _mode, int _viewer){
562 defaultDrawMode_[_viewer] = _mode;
563}
564
565ACG::SceneGraph::DrawModes::DrawMode defaultDrawMode(int _viewer){
566 return defaultDrawMode_[_viewer];
567}
568
569void defaultPerspectiveProjectionMode( bool _mode, int _viewer){
570
571 // Core/Gui/glViewer<viewer> Orthogonal = false,Perspective = true (bool)\n
572
573 QString entry = "Viewer" + QString::number(_viewer) + "/perspectiveProjection";
574 OpenFlipperSettings().setValue(entry,_mode);
575
576}
577
578bool defaultPerspectiveProjectionMode(int _viewer){
579
580 QString entry = "Viewer" + QString::number(_viewer) + "/perspectiveProjection";
581
582 switch (_viewer) {
583 case 0:
584 return OpenFlipperSettings().value(entry,true).toBool();
585 case 1:
586 return OpenFlipperSettings().value(entry,false).toBool();
587 case 2:
588 return OpenFlipperSettings().value(entry,false).toBool();
589 case 3:
590 return OpenFlipperSettings().value(entry,false).toBool();
591 default:
592 std::cerr << "defaultProjectionMode: illegal viewer id: " << _viewer << std::endl;
593 break;
594 }
595
596 return true;
597}
598
599void defaultViewingDirection( int _mode, int _viewer){
600 QString entry = "Viewer" + QString::number(_viewer) + "/defaultViewingDirection";
601 OpenFlipperSettings().setValue(entry,_mode);
602}
603
604int defaultViewingDirection(int _viewer){
605
606 QString entry = "Viewer" + QString::number(_viewer) + "/defaultViewingDirection";
607
608 switch (_viewer) {
609 case 0:
610 return OpenFlipperSettings().value(entry,PluginFunctions::VIEW_FREE).toInt();
611 case 1:
612 return OpenFlipperSettings().value(entry,PluginFunctions::VIEW_FRONT).toInt();
613 case 2:
614 return OpenFlipperSettings().value(entry,PluginFunctions::VIEW_RIGHT).toInt();
615 case 3:
616 return OpenFlipperSettings().value(entry,PluginFunctions::VIEW_TOP).toInt();
617 default:
618 std::cerr << "defaultViewingDirection: illegal viewer id: " << _viewer << std::endl;
619 break;
620 }
621
622 return PluginFunctions::VIEW_FREE;
623}
624
625void defaultLockRotation( bool _lock, int _viewer ) {
626 QString entry = "Viewer" + QString::number(_viewer) + "/defaultLockRotation";
627 OpenFlipperSettings().setValue(entry,_lock);
628}
629
630bool defaultLockRotation( int _viewer ) {
631
632 QString entry = "Viewer" + QString::number(_viewer) + "/defaultLockRotation";
633
634 switch (_viewer) {
635 case 0:
636 return OpenFlipperSettings().value(entry,false).toBool();
637 case 1:
638 return OpenFlipperSettings().value(entry,true).toBool();
639 case 2:
640 return OpenFlipperSettings().value(entry,true).toBool();
641 case 3:
642 return OpenFlipperSettings().value(entry,true).toBool();
643 default:
644 std::cerr << "defaultViewingDirection: illegal viewer id: " << _viewer << std::endl;
645 break;
646 }
647
648 return false;
649}
650
651
652void defaultViewerLayout( int _layout ){
653 defaultViewerLayout_ = _layout;
654}
655
656int defaultViewerLayout(){
657 return defaultViewerLayout_;
658}
659
660void redrawDisabled( bool disable ){
661 if ( disable )
662 redrawDisabled_++;
663 else
664 if ( redrawDisabled_ == 0 )
665 std::cerr << "Mismatch of redraw enable/disable!!" << std::endl;
666 else
667 redrawDisabled_--;
668}
669
670bool redrawDisabled( ){
671 return (redrawDisabled_ > 0);
672}
673
674bool drawModesInContextMenu() {
675 return drawModesInContextMenu_;
676}
677
678void drawModesInContextMenu(bool _show) {
679 drawModesInContextMenu_ = _show;
680}
681
682unsigned int examinerWidgets() {
683 if ( OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() )
684 return 4;
685 else
686 return 1;
687}
688
690void loggerState( LoggerState _state) {
691 OpenFlipperSettings().setValue("Core/Gui/LogWindow/LogWindowMode",_state);
692}
693
695LoggerState loggerState( ) {
696 LoggerState state = static_cast<OpenFlipper::Options::LoggerState> (OpenFlipperSettings().value("Core/Gui/LogWindow/LogWindowMode",0).toInt() );
697 // workaround for windows issue with drawing logger in scene using coreProfile (thank you Qt)
698#ifdef WIN32
699 if(coreProfile_ && state == LoggerState::InScene)
700 return LoggerState::Normal;
701#endif
703 return state;
704}
705
707QString currentViewMode( ) {
708 return currentViewMode_;
709}
710
712void currentViewMode( QString _mode ) {
713 currentViewMode_ = _mode;
714}
715
716
717QString windowTitle( ) {
718 return title_;
719}
720
721void windowTitle( QString _titel ) {
722 title_ = _titel;
723}
724
725void defaultColor( QColor _color ) {
726 defaultColor_ = _color;
727}
728
729QColor defaultColor() {
730 return defaultColor_;
731}
732
733void randomDefaultColor(bool _random) {
734 randomDefaultColor_ = _random;
735}
736
737bool randomDefaultColor() {
738 return randomDefaultColor_;
739}
740
742QString lastDataType(){
743 return lastDataType_;
744}
745
747void lastDataType(QString _type){
748 lastDataType_ = _type;
749}
750
751bool scripting( ) {
752 return scripting_;
753}
754
755void scripting(bool _status ) {
756 scripting_ = _status;
757}
758
759bool logToConsole( ) {
760 return logToConsole_;
761}
762
763void logToConsole(bool _logToConsole ) {
764 logToConsole_ = _logToConsole;
765}
766
767bool debug() {
768 return debug_;
769}
770
771void debug(bool _debug ) {
772 debug_ = _debug;
773}
774
775bool backupEnabled( ) {
776 return enableBackup_;
777}
778
779void enableBackup(bool _enableBackup ) {
780 enableBackup_ = _enableBackup;
781}
782
783void blockSceneGraphUpdates( ) {
784 ++sceneGraphUpdatesBlocked_;
785}
786
787void unblockSceneGraphUpdates() {
788 if ( sceneGraphUpdatesBlocked_ <= 0)
789 std::cerr << "Error: More unblocks than blocks! Ignoring this request" << std::endl;
790 else
791 --sceneGraphUpdatesBlocked_;
792}
793
794bool sceneGraphUpdatesBlocked( ) {
795 if ( sceneGraphUpdatesBlocked_ < 0)
796 std::cerr << "Error: updates blocked < 0 ... more unblocks than blocks" << std::endl;
797
798 return (sceneGraphUpdatesBlocked_ > 0);
799}
800
801bool savingSettings( ) {
802 return savingSettings_;
803}
804
805void savingSettings(bool _savingSettings ) {
806 savingSettings_ = _savingSettings;
807}
808
809bool loadingRecentFile( ) {
810 return loadingRecentFile_;
811}
812
813void loadingRecentFile(bool _loadingRecentFile ) {
814 loadingRecentFile_ = _loadingRecentFile;
815}
816
817int* argc() {
818 return argc_;
819}
820
821char *** argv() {
822 return argv_;
823}
824
825void argc( int* _argc ) {
826 argc_ = _argc;
827}
828
829void argv( char*** _argv) {
830 argv_ = _argv;
831}
832
833bool remoteControl(){
834 return remoteControl_;
835}
836
837void remoteControl(bool _remote){
838 remoteControl_ = _remote;
839}
840
841int remoteControlPort(){
842 return remoteControlPort_;
843}
844
845void remoteControlPort(int _remotePort){
846 remoteControlPort_ = _remotePort;
847}
848
849void doSlotDebugging( bool _debugging ) {
850 doSlotDebugging_ = _debugging;
851}
852
853bool doSlotDebugging( ) {
854 return doSlotDebugging_;
855}
856
857QString coreVersion() {
858 #ifndef CORE_VERSION
859 #define CORE_VERSION "5.1.0"
860 #endif
861 return QString(CORE_VERSION);
862}
863
864static const char * const CONFIG_DIR = "." TOSTRING(PRODUCT_STRING);
865
866bool initializeSettings() {
867 if (OpenFlipper::Options::settings_ == nullptr)
868 {
869
870#if defined(__INTEL_COMPILER)
871 compilerInfo_ = "Intel: " + QString(TOSTRING(__INTEL_COMPILER)) + "." + QString(TOSTRING(__GNUC_MINOR__));
872#if defined(__INTEL_COMPILER_BUILD_DATE)
873 compilerInfo_ += " BuildDate " + QString(TOSTRING(__INTEL_COMPILER_BUILD_DATE));
874#endif
875#elif defined(__GNUC__)
876 compilerInfo_ = "Gnu CC: " + QString(TOSTRING(__GNUC__)) + "." + QString(TOSTRING(__GNUC_MINOR__));
877#if defined(__GNUC_PATCHLEVEL__)
878 compilerInfo_ += "." + QString(TOSTRING(__GNUC_PATCHLEVEL__));
879#endif
880#elif defined (_MSC_FULL_VER)
881 compilerInfo_ = "MSVC: " + QString(TOSTRING(_MSC_FULL_VER));
882#else
883 compilerInfo_ = "Unknown Compiler";
884#endif
885
886
887 //==================================================================================================
888 // Get the Main config dir in the home directory and possibly create it
889 //==================================================================================================
890#if defined(ARCH_DARWIN)
891 configDir_ = QDir::home();
892
893 if (!configDir_.cd("Library"))
894 configDir_.mkdir("Library");
895
896 if (!configDir_.cd("Application Support"))
897 configDir_.mkdir("Application Support");
898
899 if (!configDir_.cd("de.rwth-aachen.graphics.openflipper")) {
900 configDir_.mkdir("de.rwth-aachen.graphics.openflipper");
901 if (!configDir_.cd("de.rwth-aachen.graphics.openflipper")) {
902 std::cerr << "Unable to create config dir ~/Library/de.rwth-aachen.graphics.openflipper" << std::endl;
903 return false;
904 }
905 }
906#else
907 configDir_ = QDir::home();
908 if (!configDir_.cd(CONFIG_DIR)) {
909 std::cerr << "Creating config Dir ~/" << CONFIG_DIR << std::endl;;
910 configDir_.mkdir(CONFIG_DIR);
911 if (!configDir_.cd(CONFIG_DIR)) {
912 std::cerr << "Unable to create config dir ~/" << CONFIG_DIR << std::endl;
913 return false;
914 }
915 }
916
917#endif
918
919
920 //==================================================================================================
921 // Setup settings.
922 //==================================================================================================
923 // This has to be done as early as possible to set the program options right
924
925 // Force ini format on all platforms
926 QSettings::setDefaultFormat(QSettings::IniFormat);
927
928 // Force settings to be stored in the OpenFlipper config directory
929 QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, configDir_.absolutePath());
930
931 // Finally attach the settings object.
932 settings_ = new OpenFlipperQSettings(QSettings::IniFormat, QSettings::UserScope, "VCI", "OpenFlipper");
933
934 //==================================================================================================
935 // Now create special directories in th OpenFlipper config dir
936 //==================================================================================================
937
938 // Create a personal Icon cache dir to save for example user added icons
939 if (!configDir_.exists("Icons")) {
940 configDir_.mkdir("Icons");
941 std::cerr << "Creating Icon Cache Dir ~/" << CONFIG_DIR << "/Icons" << std::endl;
942 }
943
944 //==================================================================================================
945 // Setup main application dir
946 //==================================================================================================
947
948 // Remember the main application directory (assumed to be one above executable Path)
949 applicationDir_.setPath( QCoreApplication::applicationDirPath() );
950
951 // When using cmake, we get the absolute path to the Application directory via a define
952 applicationDir_.cd(OPENFLIPPER_APPDIR);
953
954 //==================================================================================================
955 // Setup directory containing plugins
956 //==================================================================================================
957
958 // start at application directory
959 pluginDir_ = applicationDir_;
960
961 // cmake style: Path is directly given from define!
962 pluginDir_.cd(OPENFLIPPER_PLUGINDIR);
963
964 dataDir_ = OpenFlipper::Options::applicationDir();
965
966#ifdef OPENFLIPPER_DATADIR
967 dataDir_.cd(OPENFLIPPER_DATADIR);
968#else
969 dataDir_ = OpenFlipper::Options::applicationDir();
970#endif
971
972 // Set the Path to the Shaders
973 shaderDir_ = dataDir_;
974 shaderDir_.cd("Shaders");
975 ACG::ShaderProgGenerator::setShaderDir(OpenFlipper::Options::shaderDirStr());
976
977 // Set the Path to the textures
978 textureDir_ = dataDir_;
979 textureDir_.cd("Textures");
980
981 // Set the Path to the Scripts
982 scriptDir_ = dataDir_;
983 scriptDir_.cd("Scripts");
984
985
986 // Set the Path to the Icons
987 iconDir_ = dataDir_;
988 iconDir_.cd("Icons");
989
990 // Set the Path to the translations
991 translationsDir_ = dataDir_;
992 translationsDir_.cd("Translations");
993
994 // Set the Path to the Fonts
995 fontsDir_ = dataDir_;
996 fontsDir_.cd("Fonts");
997
998 // Set the Path to the License files
999 licenseDir_ = dataDir_;
1000 licenseDir_.cd("Licenses");
1001
1002 // Set the Path to the Help
1003 helpDir_ = dataDir_;
1004 helpDir_.cd("Help");
1005
1006 //==================================================================================================
1007 // Initialize with default values if not already set
1008 //==================================================================================================
1009
1010 // User Interface Settings
1011 if (!settings_->contains("Core/Gui/glViewer/defaultBackgroundColor"))
1012 settings_->setValue("Core/Gui/glViewer/defaultBackgroundColor", QColor("black"));
1013
1014 if (!settings_->contains("Core/Gui/glViewer/showControlWheels"))
1015 settings_->setValue("Core/Gui/glViewer/showControlWheels", false);
1016
1017
1018 // Mouse Controls
1019 if (!settings_->contains("Core/Mouse/Wheel/ZoomFactor"))
1020 settings_->setValue("Core/Mouse/Wheel/ZoomFactor", 1.0);
1021
1022 if (!settings_->contains("Core/Mouse/Wheel/ZoomFactorShift"))
1023 settings_->setValue("Core/Mouse/Wheel/ZoomFactorShift", 0.2);
1024
1025 if (!settings_->contains("Core/Mouse/Wheel/Invert"))
1026 settings_->setValue("Core/Mouse/Wheel/Invert", false);
1027
1028 // General Stereo Settings
1029 if (!settings_->contains("Core/Stereo/FocalLength"))
1030 settings_->setValue("Core/Stereo/FocalLength", 0.5);
1031
1032 if (!settings_->contains("Core/Stereo/EyeDistance"))
1033 settings_->setValue("Core/Stereo/EyeDistance", 0.07);
1034
1035 return true;
1036 }
1037 return true;
1038}
1039
1040void closeSettings() {
1041
1042 // Delete the settings object. This will flush all data to the disk.
1043 delete settings_;
1044}
1045
1046QString compilerInfo() {
1047 return compilerInfo_;
1048}
1049
1050}
1051}
1052
1053OpenFlipperQSettings& OpenFlipperSettings() {
1054 // Empty standard settings object if the right settings are not available!
1055 static OpenFlipperQSettings emptySettings;
1056
1057 if ( OpenFlipper::Options::settings_ != nullptr )
1058 return *OpenFlipper::Options::settings_;
1059 else
1060 return emptySettings;
1061}
1062
1063
1064
1065//=============================================================================
1066
#define TOSTRING(x)
QSettings object containing all program settings of OpenFlipper.
LoggerState
State of the logging widget.
static void setShaderDir(QString _dir)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition DrawModes.cc:82