ParseIni.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 7357 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-10-09 15:05:31 +0200 (Fr, 09. Okt 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS Core - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 // -------------------- mview
00056 #include "Core.hh"
00057 // -------------------- ACG
00058 #include <ACG/Scenegraph/DrawModes.hh>
00059 
00060 #include <OpenFlipper/INIFile/INIFile.hh>
00061 #include <OpenFlipper/common/GlobalOptions.hh>
00062 #include <OpenFlipper/common/RecentFiles.hh>
00063 
00064 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00065 
00066 #include <QFile>
00067 
00068 #include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
00069 
00070 //== IMPLEMENTATION ==========================================================
00071 
00072 
00076 void Core::readApplicationOptions(INIFile& _ini) {
00077   // Parse standard options
00078   if ( _ini.section_exists("Options") ) {
00079 
00080     // TODO: Load View Mode Toolbars and Context Menu Items
00081     
00082     // load ViewModes
00083     int viewModeCount;
00084     if (_ini.get_entry(viewModeCount,"Options","ViewModeCount") )
00085       for (int i=0; i < viewModeCount; i++){
00086         
00087         QString entryToolbars;
00088         QString entryToolboxes;
00089         QString entryIcon;
00090         
00091         QString keyToolbars  = "ViewModeToolbars"  + QString::number(i);
00092         QString keyToolboxes = "ViewModeToolboxes" + QString::number(i);
00093         QString keyIcon      = "ViewModeIcon"      + QString::number(i);
00094 
00095         // Read the entries
00096         if ( !_ini.get_entry( entryToolbars  , "Options" , keyToolbars ) )  continue;
00097         if ( !_ini.get_entry( entryToolboxes , "Options" , keyToolboxes ) ) continue;
00098         if ( !_ini.get_entry( entryIcon      , "Options" , keyIcon ) )      continue;
00099 
00100         QStringList toolBars = entryToolbars.split(";");
00101         QStringList toolBoxes = entryToolboxes.split(";");
00102         
00103         // Get Mode name ( prepended to all toolbox/toolbar lists
00104         QString mode = toolBoxes.first();
00105         
00106         // Remove leading Modes
00107         toolBoxes.removeFirst();
00108         toolBars.removeFirst();
00109 
00110         // Check if the mode already exists
00111         bool found = false;
00112         for (int i=0; i < viewModes_.size(); i++)
00113           if (viewModes_[i]->name == mode)
00114             found = true;
00115           
00116         if (!found){
00117           ViewMode* vm = new ViewMode();
00118           vm->name = mode;
00119           vm->custom = true;
00120           vm->visibleToolbars  = toolBars;
00121           vm->visibleToolboxes = toolBoxes;
00122           vm->icon             = entryIcon;
00123           viewModes_.push_back(vm);
00124         }
00125 
00126       }
00127 
00128     //load default dataType
00129     QString type;
00130     if (_ini.get_entry(type, "Options" , "default_DataType" ))
00131       OpenFlipper::Options::lastDataType(type);
00132 
00133     //============================================================================
00134     // Splash Screen
00135     //============================================================================
00136     bool splash;
00137     if( _ini.get_entry(splash, "Options", "Splash") )
00138       OpenFlipper::Options::splash(splash);
00139 
00140     //============================================================================
00141     // Load the startup dir for file dialogs
00142     //============================================================================
00143     QString startup_dir;
00144     if( _ini.get_entry(startup_dir, "Options", "StartupDir") )
00145       OpenFlipper::Options::currentDir(startup_dir);
00146 
00147     //============================================================================
00148     // Load the default script directory
00149     //============================================================================
00150     QString script_dir;
00151     if( _ini.get_entry(script_dir, "Options", "CurrentScriptDir") )
00152       OpenFlipper::Options::currentScriptDir(script_dir);
00153 
00154     //============================================================================
00155     // Load the default texture directory
00156     //============================================================================
00157     QString current_texture_dir;
00158     if( _ini.get_entry(current_texture_dir, "Options", "CurrentTextureDir") )
00159       OpenFlipper::Options::currentTextureDir(current_texture_dir);
00160 
00161     //============================================================================
00162     // Load the random base color setting
00163     //============================================================================
00164     bool random_base_color = false;
00165     if ( _ini.get_entry( random_base_color, "Options" , "RandomBaseColor") )
00166       OpenFlipper::Options::randomBaseColor( random_base_color );
00167 
00168     //============================================================================
00169     // Load the synchronization setting
00170     //============================================================================
00171     bool synchronization = false;
00172     if ( _ini.get_entry( synchronization, "Options" , "Synchronization") )
00173       OpenFlipper::Options::synchronization(synchronization);
00174 
00175     //============================================================================
00176     // Load the stereo mode setting
00177     //============================================================================
00178     //bool stereo = false;
00179     //if ( _ini.get_entry( stereo, "Options" , "Stereo") )
00180     //  OpenFlipper::Options::stereo(stereo);
00181 
00182     //============================================================================
00183     // Load the stereo mode setting
00184     //============================================================================
00185     int stereoMode = 0;
00186     if ( _ini.get_entry( stereoMode, "Options" , "StereoMode") )
00187       OpenFlipper::Options::stereoMode(static_cast<OpenFlipper::Options::StereoMode> (stereoMode));
00188 
00189     //============================================================================
00190     // Load stereo view settings
00191     //============================================================================
00192 
00193     float val;
00194     if ( _ini.get_entry( val, "Options" , "EyeDistance") )
00195       OpenFlipper::Options::eyeDistance(val);
00196     if ( _ini.get_entry( val, "Options" , "FocalDistance") )
00197       OpenFlipper::Options::focalDistance(val);
00198 
00199     //============================================================================
00200     // Load the custom anaglyph stereo mode color matrices
00201     //============================================================================
00202     std::vector<float> mat;
00203     if ( _ini.get_entry( mat, "Options" , "CustomAnaglyphLeftEye") && mat.size () == 9)
00204     {
00205       OpenFlipper::Options::anaglyphLeftEyeColorMatrix(mat);
00206     }
00207     else
00208     {
00209       std::vector<float> set (9,0.0);
00210       set[0] = 0.299;
00211       set[3] = 0.587;
00212       set[6] = 0.114;
00213       OpenFlipper::Options::anaglyphLeftEyeColorMatrix(set);
00214     }
00215 
00216     if ( _ini.get_entry( mat, "Options" , "CustomAnaglyphRightEye") && mat.size () == 9)
00217     {
00218       OpenFlipper::Options::anaglyphRightEyeColorMatrix(mat);
00219     }
00220     else
00221     {
00222       std::vector<float> set (9,0.0);
00223       set[4] = 1.0;
00224       set[8] = 1.0;
00225       OpenFlipper::Options::anaglyphRightEyeColorMatrix(set);
00226     }
00227 
00228     //============================================================================
00229     // Load stereo mouse picking behavior
00230     //============================================================================
00231     bool stereoMousePick = false;
00232     if ( _ini.get_entry( stereoMousePick, "Options" , "StereoMousePick") )
00233       OpenFlipper::Options::stereoMousePick(stereoMousePick);
00234 
00235     //============================================================================
00236     // Load gl mouse painting behavior
00237     //============================================================================
00238     bool glMouse = false;
00239     if ( _ini.get_entry( glMouse, "Options" , "GlMouse") )
00240       OpenFlipper::Options::glMouse(glMouse);
00241 
00242     //============================================================================
00243     // Load the setting for the loger window
00244     //============================================================================
00245     int loggerState = 0;
00246     if ( _ini.get_entry( loggerState, "Options" , "LoggerState") )
00247       OpenFlipper::Options::loggerState(static_cast<OpenFlipper::Options::LoggerState> (loggerState));
00248 
00249     //============================================================================
00250     // Load the setting for the toolbox window
00251     //============================================================================
00252     bool hideToolbox = false;
00253     if ( _ini.get_entry( hideToolbox, "Options" , "HideToolbox") )
00254       OpenFlipper::Options::hideToolbox(hideToolbox);
00255 
00256     //============================================================================
00257     // Load the setting for the fullscreen option
00258     //============================================================================
00259     bool fullScreen = false;
00260     if ( _ini.get_entry( fullScreen, "Options" , "FullScreen") )
00261       OpenFlipper::Options::fullScreen(fullScreen);
00262 
00263     //============================================================================
00264     // Load the setting for the background color option
00265     //============================================================================
00266     uint backgroundColor = 0;
00267     if ( _ini.get_entry( backgroundColor, "Options" , "DefaultBackgroundColor") )
00268       OpenFlipper::Options::defaultBackgroundColor(QRgb(backgroundColor));
00269 
00270     //============================================================================
00271     // Load the setting for the object color option
00272     //============================================================================
00273     uint baseColor = 0;
00274     if ( _ini.get_entry( baseColor, "Options" , "DefaultBaseColor") )
00275       OpenFlipper::Options::defaultBaseColor(QRgb(baseColor));
00276 
00277     //============================================================================
00278     // Load the setting for the default Toolbox mode
00279     //============================================================================
00280     QString toolboxMode = false;
00281     if ( _ini.get_entry( toolboxMode, "Options" , "DefaultToolboxMode") )
00282       OpenFlipper::Options::defaultToolboxMode(toolboxMode);
00283 
00284     //============================================================================
00285     // Load the setting for the translation language
00286     //============================================================================
00287     QString translation = false;
00288     if ( _ini.get_entry( translation, "Options" , "Translation") )
00289       OpenFlipper::Options::translation(translation);
00290 
00291     //============================================================================
00292     // Load the setting for the gridVisibility
00293     //============================================================================
00294     bool visible = false;
00295     if ( _ini.get_entry( visible, "Options" , "GridVisible") )
00296       OpenFlipper::Options::gridVisible(visible);
00297 
00298     //============================================================================
00299     // Load the setting for the viewer layout
00300     //============================================================================
00301     int viewerLayout = 0;
00302     if ( _ini.get_entry( viewerLayout, "Options" , "DefaultViewerLayout") )
00303       OpenFlipper::Options::defaultViewerLayout(viewerLayout);
00304 
00305     //============================================================================
00306     // Load the viewer settings
00307     //============================================================================
00308     std::vector< QString > draw_modes;
00309     int mode;
00310 
00311     for (int i=0; i < 4/*PluginFunctions::viewers()*/; i++ ){
00312 
00313       if( _ini.get_entry(draw_modes, "Options", "DefaultDrawModes" + QString::number(i) ) )
00314         OpenFlipper::Options::defaultDrawMode( ListToDrawMode(draw_modes), i );
00315 
00316       if( _ini.get_entry(mode, "Options", "DefaultProjectionMode" + QString::number(i) ) )
00317         OpenFlipper::Options::defaultProjectionMode( mode, i );
00318 
00319       if( _ini.get_entry(mode, "Options", "DefaultViewingDirection" + QString::number(i) ) )
00320         OpenFlipper::Options::defaultViewingDirection( mode, i );
00321     }
00322 
00323     //============================================================================
00324     // Load logFile status
00325     //============================================================================
00326     bool logFileEnabled = true;
00327     if( _ini.get_entry(logFileEnabled, "Options", "LogFileEnabled") )
00328       OpenFlipper::Options::logFileEnabled(logFileEnabled);
00329 
00330     //============================================================================
00331     // Load logFile location
00332     //============================================================================
00333     QString logFile = "";
00334     if( _ini.get_entry(logFile, "Options", "LogFileLocation") )
00335       OpenFlipper::Options::logFile(logFile);
00336 
00337     //============================================================================
00338     // Load the WheelZoomFactor setting
00339     //============================================================================
00340     double wheelZoomFactor = 1.0;
00341     if ( _ini.get_entry( wheelZoomFactor, "Options" , "WheelZoomFactor") )
00342       OpenFlipper::Options::wheelZoomFactor(wheelZoomFactor);
00343 
00344     //============================================================================
00345     // Load the WheelZoomFactorShift setting
00346     //============================================================================
00347     double wheelZoomFactorShift = 0.2;
00348     if ( _ini.get_entry( wheelZoomFactorShift, "Options" , "WheelZoomFactorShift" ) )
00349       OpenFlipper::Options::wheelZoomFactorShift(wheelZoomFactorShift);
00350 
00351     //============================================================================
00352     // Load restrictFrameRate
00353     //============================================================================
00354     bool restrictFrameRate = false;
00355     if( _ini.get_entry(restrictFrameRate, "Options", "RestrictFrameRate") )
00356       OpenFlipper::Options::restrictFrameRate(restrictFrameRate);
00357 
00358     //============================================================================
00359     // Load showWheelsAtStartup
00360     //============================================================================
00361     bool showWheelsAtStartup = false;
00362     if( _ini.get_entry(showWheelsAtStartup, "Options", "ShowWheelsAtStartup") )
00363       OpenFlipper::Options::showWheelsAtStartup(showWheelsAtStartup);
00364 
00365     //============================================================================
00366     // Load maxFrameRate
00367     //============================================================================
00368     int maxFrameRate = 35;
00369     if( _ini.get_entry(maxFrameRate, "Options", "MaxFrameRate") )
00370       OpenFlipper::Options::maxFrameRate(maxFrameRate);
00371 
00372     //============================================================================
00373     // Load slotDebugging state
00374     //============================================================================
00375     bool doSlotDebugging = false;
00376     if( _ini.get_entry(doSlotDebugging, "Options", "SlotDebugging") )
00377       OpenFlipper::Options::doSlotDebugging(doSlotDebugging);
00378 
00379     //============================================================================
00380     // Load Picking debugger state
00381     //============================================================================
00382     bool renderPicking = false;
00383     if( _ini.get_entry(renderPicking, "Options", "RenderPicking") )
00384       OpenFlipper::Options::renderPicking(renderPicking);
00385 
00386     QString pickingRenderMode = "";
00387     if( _ini.get_entry(renderPicking, "Options", "PickingRenderMode") )
00388       OpenFlipper::Options::pickingRenderMode(pickingRenderMode);
00389 
00390     //============================================================================
00391     // ViewerProperties
00392     //============================================================================
00393 
00394     bool multiView = false;
00395     if( _ini.get_entry(multiView, "Options", "MultiView") )
00396       OpenFlipper::Options::multiView(multiView);
00397 
00398     uint viewerCount = 0;
00399     if( _ini.get_entry(viewerCount, "Options", "ViewerCount") ){
00400     }
00401 
00402     if ( _ini.section_exists("ViewerProperties") ){
00403       for ( unsigned int i = 0 ; i < viewerCount; ++i ) {
00404 
00405         if (OpenFlipper::Options::examinerWidgets() < i)
00406           break;
00407 
00408         // Load the animation setting
00409         bool animation = false;
00410         if ( _ini.get_entry( animation, "ViewerProperties" , "Animation" + QString::number(i) ) )
00411           PluginFunctions::viewerProperties(i).animation(animation);
00412 
00413         // Load the twoSidedLighting setting
00414         bool twoSidedLighting = false;
00415         if ( _ini.get_entry( twoSidedLighting, "ViewerProperties" , "TwoSidedLighting" + QString::number(i)) )
00416           PluginFunctions::viewerProperties(i).twoSidedLighting(twoSidedLighting);
00417 
00418         // Load the backface culling setting
00419         bool backface_culling = false;
00420         if ( _ini.get_entry( backface_culling, "ViewerProperties" , "BackfaceCulling" + QString::number(i)) )
00421           PluginFunctions::viewerProperties(i).backFaceCulling(backface_culling);
00422 
00423         // Load the setting for the background color option
00424         uint viewerBackground = 0;
00425         if ( _ini.get_entry( viewerBackground, "ViewerProperties" , "BackgroundColor" + QString::number(i)) )
00426           PluginFunctions::viewerProperties(i).backgroundColor( QRgb(viewerBackground) );
00427       }
00428     }
00429 
00430     //============================================================================
00431     // Update information
00432     //============================================================================
00433     QString updateUrl = "";
00434     if( _ini.get_entry(updateUrl, "Options", "UpdateURL") )
00435       OpenFlipper::Options::updateUrl(updateUrl);
00436 
00437     QString updateUsername = "";
00438     if( _ini.get_entry(updateUsername, "Options", "UpdateUsername") )
00439       OpenFlipper::Options::updateUsername(updateUsername);
00440 
00441     QString updatePassword = "";
00442     if( _ini.get_entry(updatePassword, "Options", "UpdatePassword") )
00443       OpenFlipper::Options::updatePassword(updatePassword);
00444   }
00445 }
00446 
00447 void Core::readRecentFiles(QString _filename){
00448 
00449   INIFile ini;
00450 
00451   if ( ! ini.connect(_filename,false) ) {
00452     emit log(LOGERR,"Failed to connect to ini file" + _filename);
00453     return;
00454   }
00455 
00456   OpenFlipper::Options::loadingSettings(true);
00457 
00458   // Load maxRecent Setting
00459   int mrecent = 6;
00460   if (ini.get_entry(mrecent,"Options","MaxRecent"))
00461     OpenFlipper::Options::maxRecent(mrecent);
00462 
00463   for ( int j = mrecent-1 ; j >= 0; --j) {
00464     QString file;
00465     QString key = "recent" + QString::number(j);
00466 
00467     if ( !ini.get_entry( file , "Options" , key ) )
00468       continue;
00469 
00470     key = "type" + QString::number(j);
00471     QString type;
00472 
00473     if ( !ini.get_entry( type , "Options" , key ) )
00474       continue;
00475 
00476     OpenFlipper::Options::addRecentFile(file, typeId(type) );
00477   }
00478 
00479   ini.disconnect();
00480 
00481   OpenFlipper::Options::loadingSettings(false);
00482 
00483 }
00484 
00485 
00489 void Core::writeApplicationOptions(INIFile& _ini) {
00490 
00491   // Write maximum recent file count to ini
00492   _ini.add_entry("Options","MaxRecent",OpenFlipper::Options::maxRecent());
00493 
00494   // Write list of recent files to ini
00495   QVector< OpenFlipper::Options::RecentFile > recentFiles = OpenFlipper::Options::recentFiles();
00496   for ( int j = 0 ; j < recentFiles.size(); ++j) {
00497     // Save filename
00498     QString key = "recent" + QString::number(j);
00499     QString filename = recentFiles[j].filename;
00500     _ini.add_entry( "Options" , key , filename );
00501     // Save DataType
00502     key = "type" + QString::number(j);
00503     QString type = typeName( recentFiles[j].type );
00504     _ini.add_entry( "Options" , key , type );
00505   }
00506 
00507   // TODO: Save View Mode Toolbars and Context Menu Items
00508   // save ViewModes
00509   QVector< QString > toolboxes;
00510   QVector< QString > toolbars;
00511   QVector< QString > icons;
00512   
00513   if ( OpenFlipper::Options::gui() )
00514     for (int i=0; i < coreWidget_->viewModes_.size(); i++)
00515       if (coreWidget_->viewModes_[i]->custom){
00516 
00517         //store name
00518         QString entryToolboxes = coreWidget_->viewModes_[i]->name;
00519 
00520         //store widgets
00521         for (int j=0; j < coreWidget_->viewModes_[i]->visibleToolboxes.size(); j++)
00522           entryToolboxes += ";" + coreWidget_->viewModes_[i]->visibleToolboxes[j];
00523 
00524         toolboxes.push_back(entryToolboxes);
00525 
00526         //store name
00527         QString entryToolbars = coreWidget_->viewModes_[i]->name;
00528         
00529         //store widgets
00530         for (int j=0; j < coreWidget_->viewModes_[i]->visibleToolbars.size(); j++)
00531           entryToolbars += ";" + coreWidget_->viewModes_[i]->visibleToolbars[j];
00532         
00533         toolbars.push_back(entryToolbars);
00534         
00535         icons.push_back(coreWidget_->viewModes_[i]->icon);
00536         
00537       }
00538 
00539   //save viewmodes to ini
00540   _ini.add_entry("Options","ViewModeCount" ,toolboxes.size());
00541   for (int i=0; i < toolboxes.size(); i++) {
00542     _ini.add_entry("Options","ViewModeToolboxes" + QString::number(i) ,toolboxes[i]);
00543     _ini.add_entry("Options","ViewModeToolbars"  + QString::number(i) ,toolbars[i] );
00544     _ini.add_entry("Options","ViewModeIcon"      + QString::number(i) ,icons[i] );
00545   }
00546 
00547   //save KeyBindings
00548   if ( OpenFlipper::Options::gui() )
00549     coreWidget_->saveKeyBindings(_ini);
00550 
00551   //============================================================================
00552   // Splash Screen
00553   //============================================================================
00554   _ini.add_entry( "Options" , "Splash" , OpenFlipper::Options::splash() );
00555 
00556   //write default dataType to INI
00557   _ini.add_entry( "Options" , "default_DataType" , OpenFlipper::Options::lastDataType() );
00558 
00559   //write default ToolboxMode
00560   _ini.add_entry("Options","DefaultToolboxMode",OpenFlipper::Options::defaultToolboxMode() );
00561 
00562   //============================================================================
00563   // logfile
00564   //============================================================================
00565   //write logfile status
00566   _ini.add_entry("Options","LogFileEnabled",OpenFlipper::Options::logFileEnabled() );
00567   //write logfile location
00568   _ini.add_entry("Options","LogFileLocation",OpenFlipper::Options::logFile() );
00569 
00570   //============================================================================
00571   // other
00572   //============================================================================
00573   _ini.add_entry("Options","WheelZoomFactor", OpenFlipper::Options::wheelZoomFactor() );
00574   _ini.add_entry("Options","WheelZoomFactorShift", OpenFlipper::Options::wheelZoomFactorShift() );
00575   // restrict Framerate
00576   _ini.add_entry("Options","RestrictFrameRate",OpenFlipper::Options::restrictFrameRate() );
00577   // Show wheels on startup
00578   _ini.add_entry("Options","ShowWheelsAtStartup",OpenFlipper::Options::showWheelsAtStartup() );
00579   // max Framerate
00580   _ini.add_entry("Options","MaxFrameRate",OpenFlipper::Options::maxFrameRate() );
00581 
00582   //============================================================================
00583   // Debugging
00584   //============================================================================
00585   _ini.add_entry("Options","SlotDebugging",OpenFlipper::Options::doSlotDebugging() );
00586 
00587   //============================================================================
00588   // Write Picking debugger state
00589   //============================================================================
00590   _ini.add_entry("Options","RenderPicking",OpenFlipper::Options::renderPicking() );
00591   _ini.add_entry("Options","PickingRenderMode",OpenFlipper::Options::pickingRenderMode() );
00592 
00593   //============================================================================
00594   // Update information
00595   //============================================================================
00596   _ini.add_entry("Options","UpdateURL",OpenFlipper::Options::updateUrl() );
00597   _ini.add_entry("Options","UpdateUsername",OpenFlipper::Options::updateUsername() );
00598   _ini.add_entry("Options","UpdatePassword",OpenFlipper::Options::updatePassword() );
00599 
00600   //============================================================================
00601   //dontLoad Plugins
00602   //============================================================================
00603   QString dontLoad;
00604   for (int i=0; i < dontLoadPlugins_.size(); i++)
00605     if (!dontLoad.contains(dontLoadPlugins_[i].trimmed() + ";"))
00606       dontLoad += dontLoadPlugins_[i].trimmed() + ";";
00607 
00608   if ( !_ini.section_exists("Plugins") )
00609     _ini.add_section("Plugins");
00610 
00611   //write dontLoad Plugins
00612   _ini.add_entry("Plugins","DontLoad", dontLoad);
00613 
00614 
00615 
00616   if ( !_ini.section_exists("Options") )
00617     _ini.add_section("Options");
00618 
00619   QString dir = OpenFlipper::Options::currentDirStr().toUtf8();
00620   _ini.add_entry("Options","StartupDir",dir);
00621 
00622   QString scriptDir = OpenFlipper::Options::currentScriptDirStr().toUtf8();
00623   _ini.add_entry("Options","CurrentScriptDir",scriptDir);
00624 
00625   QString current_texture_dir = OpenFlipper::Options::currentTextureDirStr().toUtf8();
00626   _ini.add_entry("Options","CurrentTextureDir",current_texture_dir);
00627 
00628   _ini.add_entry("Options","RandomBaseColor", OpenFlipper::Options::randomBaseColor() );
00629 
00630   if ( OpenFlipper::Options::gui() ) {
00631 
00632     _ini.add_entry("Options","DefaultViewerLayout", OpenFlipper::Options::defaultViewerLayout() );
00633     _ini.add_entry("Options","Translation", OpenFlipper::Options::translation() );
00634     _ini.add_entry("Options","GridVisible", OpenFlipper::Options::gridVisible() );
00635 
00636     _ini.add_entry("Options","MultiView", OpenFlipper::Options::multiView() );
00637     _ini.add_entry("Options","ViewerCount", OpenFlipper::Options::examinerWidgets() );
00638 
00639     if ( !_ini.section_exists("ViewerProperties") )
00640       _ini.add_section("ViewerProperties");
00641 
00642     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
00643 
00644       _ini.add_entry("ViewerProperties","Animation" + QString::number(i),       PluginFunctions::viewerProperties(i).animation());
00645       _ini.add_entry("ViewerProperties","BackfaceCulling" + QString::number(i), PluginFunctions::viewerProperties(i).backFaceCulling());
00646       _ini.add_entry("ViewerProperties","TwoSidedLighting" + QString::number(i),PluginFunctions::viewerProperties(i).twoSidedLighting());
00647       _ini.add_entry("ViewerProperties","BackgroundColor" + QString::number(i),
00648                      (uint)PluginFunctions::viewerProperties(i).backgroundColorRgb() );
00649     }
00650     //============================================================================
00651     // Save the current viewer properties
00652     //============================================================================
00653     std::vector< QString > draw_modes;
00654 
00655     for (int i=0; i < PluginFunctions::viewers(); i++ ){
00656 
00657       draw_modes = drawModeToList( OpenFlipper::Options::defaultDrawMode(i) );
00658       _ini.add_entry("Options","DefaultDrawModes" + QString::number(i), draw_modes);
00659 
00660       _ini.add_entry("Options","DefaultProjectionMode" + QString::number(i), OpenFlipper::Options::defaultProjectionMode(i) );
00661       _ini.add_entry("Options","DefaultViewingDirection" + QString::number(i), OpenFlipper::Options::defaultViewingDirection(i) );
00662     }
00663 
00664 
00665     _ini.add_entry("Options","LoggerState", OpenFlipper::Options::loggerState() );
00666     _ini.add_entry("Options","HideToolbox", OpenFlipper::Options::hideToolbox() );
00667 
00668     // check if we are in fullscreen mode:
00669     _ini.add_entry("Options","FullScreen", OpenFlipper::Options::fullScreen() );
00670 
00671     _ini.add_entry("Options","DefaultBackgroundColor", (uint)OpenFlipper::Options::defaultBackgroundColor().rgba ()  );
00672     _ini.add_entry("Options","DefaultBaseColor", (uint)OpenFlipper::Options::defaultBaseColor().rgba ()  );
00673 
00674     _ini.add_entry("Options","StereoMode",OpenFlipper::Options::stereoMode() );
00675 
00676     _ini.add_entry("Options" , "EyeDistance", OpenFlipper::Options::eyeDistance());
00677     _ini.add_entry("Options" , "FocalDistance", OpenFlipper::Options::focalDistance());
00678 
00679     _ini.add_entry("Options" , "CustomAnaglyphLeftEye", OpenFlipper::Options::anaglyphLeftEyeColorMatrix() );
00680     _ini.add_entry("Options" , "CustomAnaglyphRightEye", OpenFlipper::Options::anaglyphRightEyeColorMatrix() );
00681 
00682     _ini.add_entry("Options", "StereoMousePick", OpenFlipper::Options::stereoMousePick() );
00683 
00684     _ini.add_entry("Options", "GlMouse", OpenFlipper::Options::glMouse() );
00685   }
00686 
00687   emit saveOnExit(_ini);
00688 
00689   // _ini.add_entry("Options","Stereo",OpenFlipper::Options::stereo() );
00690 }
00691 
00692 void Core::openIniFile( QString _filename,
00693                         bool    _coreSettings,
00694                         bool    _perPluginSettings,
00695                         bool    _loadObjects ){
00696   INIFile ini;
00697 
00698   if ( ! ini.connect(_filename,false) ) {
00699     emit log(LOGERR,tr("Failed to connect to ini file") + _filename);
00700     return;
00701   }
00702 
00703   if ( OpenFlipper::Options::gui() ) {
00704     coreWidget_->statusMessage( tr("Loading ini File ") + _filename + " ...");
00705     coreWidget_->setStatus(ApplicationStatus::BLOCKED );
00706   }
00707 
00708   OpenFlipper::Options::loadingSettings(true);
00709 
00710   // Load Core settings only if requested
00711   if ( _coreSettings )
00712     readApplicationOptions(ini);
00713 
00714   // if requested load per Plugin settings from the settings file
00715   if ( _perPluginSettings )
00716     emit iniLoadOptions( ini );
00717 
00718   if ( _loadObjects ) {
00719 
00720     QStringList openFiles;
00721 
00722     // Parse File section for files to open
00723     if ( ini.section_exists("OpenFiles") && ini.get_entry(openFiles,"OpenFiles","open") ) {
00724 
00725       bool newActiveObject = false;
00726 
00727       for ( int i = 0 ; i < openFiles.size(); ++i ) {
00728 
00729         QString sectionName = openFiles[i];
00730 
00731         QString path;
00732         ini.get_entry( path, sectionName , "path" );
00733 
00734         //check if path is relative
00735         if (path.startsWith( "." + OpenFlipper::Options::dirSeparator() )){
00736           //check if _filename contains a path
00737           if (_filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) != ""){
00738             path.remove(0,1); // remove .
00739             path = _filename.section(OpenFlipper::Options::dirSeparator(), 0, -2) + path;
00740           }
00741         }
00742 
00743         int tmpType;
00744         DataType type = DATA_TRIANGLE_MESH;
00745 
00746         if ( ini.get_entry( tmpType, sectionName , "type"  )) {
00747           type = DataType(tmpType);
00748           emit log(LOGWARN, tr("This ini file uses old int style ObjectType fields!") );
00749           emit log(LOGWARN, tr("Please convert it to new format! ( ... just save it )") );
00750         } else {
00751 
00752           QString typeName="";
00753 
00754           if ( ini.get_entry( typeName, sectionName , "type"  )) {
00755             type = typeId(typeName);
00756           } else
00757             emit log(LOGWARN, tr("Unable to get DataType for object ") +  sectionName + tr(" assuming Triangle Mesh") );
00758         }
00759 
00760         int newObjectId = loadObject(type, path);
00761 
00762         BaseObject* object = objectRoot_->childExists( newObjectId );
00763         if ( object == 0 )  {
00764           emit log(LOGERR,tr("Unable to open Object ") + path);
00765           continue;
00766         }
00767 
00768         bool flag;
00769         if ( ini.get_entry( flag, sectionName , "target" ) )
00770           object->target(flag);
00771 
00772         if ( ini.get_entry( flag, sectionName , "source" ) )
00773           object->source(flag);
00774 
00775         emit iniLoad( ini,object->id() );
00776 
00777         emit objectSelectionChanged( object->id() );
00778       }
00779     }
00780 
00781   }
00782 
00783   // Tell Plugins that all objects are
00784   if ( _perPluginSettings )
00785     emit iniLoadOptionsLast( ini );
00786 
00787   ini.disconnect();
00788 
00789   OpenFlipper::Options::loadingSettings(false);
00790 
00791   // Reset scenegraph and recompute scene center containing all new objects
00792   resetScenegraph(true);
00793 
00794   if ( OpenFlipper::Options::gui() ){
00795     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00796       PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
00797       coreWidget_->examiner_widgets_[i]->viewAll();
00798     }
00799 
00800     coreWidget_->statusMessage( tr("Loading ini File ") + _filename + tr(" ... Done"), 4000);
00801     coreWidget_->setStatus(ApplicationStatus::READY );
00802   }
00803 
00804 }
00805 
00806 void Core::writeIniFile(QString _filename,
00807                         bool _relativePaths,
00808                         bool _targetOnly,
00809                         bool _saveSystemSettings,
00810                         bool _savePluginSettings ,
00811                         bool _saveObjectInfo ) {
00812 
00813   INIFile ini;
00814 
00815   if ( ! ini.connect(_filename,true) ) {
00816     emit log(LOGERR,tr("Failed to connect to _ini file") + _filename);
00817       return;
00818   }
00819 
00820   if ( OpenFlipper::Options::gui() ) {
00821     coreWidget_->statusMessage( tr("Saving ini File ") + _filename + " ...");
00822     coreWidget_->setStatus(ApplicationStatus::BLOCKED );
00823   }
00824 
00825   // Only save application settings when requested
00826   if ( _saveSystemSettings )
00827     writeApplicationOptions(ini);
00828 
00829   if ( _savePluginSettings )
00830     emit iniSaveOptions( ini );
00831 
00832   if ( _saveObjectInfo ) {
00833     // This vector will hold the file sections to open
00834     QStringList openFiles;
00835 
00836 
00837     PluginFunctions::IteratorRestriction restriction;
00838     if ( _targetOnly )
00839       restriction = PluginFunctions::TARGET_OBJECTS;
00840     else
00841       restriction = PluginFunctions::ALL_OBJECTS;
00842 
00843     QString keyName;
00844     QString sectionName;
00845     for ( PluginFunctions::ObjectIterator o_it(restriction) ;
00846                                           o_it != PluginFunctions::objectsEnd(); ++o_it) {
00847       QString file = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
00848       if (QFile(file).exists()){
00849         // Add a section for this object
00850         sectionName = o_it->name();
00851         ini.add_section( sectionName );
00852         openFiles.push_back( sectionName );
00853 
00854         //modify filename if relativePaths are wanted
00855         if (_relativePaths){
00856           int prefixLen = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2).length();
00857           file.remove(0, prefixLen);
00858           file = "." + file;
00859         }
00860         // Add the path of this object to the section
00861         ini.add_entry( sectionName , "path" , file );
00862         ini.add_entry( sectionName , "type" , typeName(o_it->dataType() ) );
00863         ini.add_entry( sectionName , "target" , o_it->target() );
00864         ini.add_entry( sectionName , "source" , o_it->source() );
00865 
00866       }
00867     }
00868 
00869     ini.add_entry("OpenFiles","open",openFiles);
00870 
00871     // Tell plugins to save their information for the given object
00872     for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
00873                                           o_it != PluginFunctions::objectsEnd(); ++o_it)
00874       emit iniSave(  ini , o_it->id() );
00875   }
00876 
00877 
00878 
00879   ini.disconnect();
00880 
00881   if ( OpenFlipper::Options::gui() ) {
00882     coreWidget_->statusMessage( tr("Saving ini File ") + _filename + tr(" ... Done"), 4000);
00883     coreWidget_->setStatus(ApplicationStatus::READY );
00884   }
00885 }
00886 
00887 
00888 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .