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