openFunctions.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: 8574 $                                                         *
00038  *   $Author: wilden $                                                      *
00039  *   $Date: 2010-02-17 11:53:19 +0100 (Mi, 17. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 
00047 #include "Core.hh"
00048 
00049 #include <ACG/QtWidgets/QtFileDialog.hh>
00050 
00051 #include "OpenFlipper/common/GlobalOptions.hh"
00052 #include "OpenFlipper/BasePlugin/PluginFunctions.hh"
00053 
00054 #include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
00055 #include "OpenFlipper/widgets/addEmptyWidget/addEmptyWidget.hh"
00056 
00057 #include <OpenFlipper/common/Types.hh>
00058 #include <ObjectTypes/PolyMesh/PolyMesh.hh>
00059 
00060 #include <time.h>
00061 
00062 void Core::resetScenegraph( bool _resetTrackBall  ) {
00063   if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() ) {
00064 
00065     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00066       // update scene graph (get new bounding box and set projection right, including near and far plane)
00067       PluginFunctions::viewerProperties(i).lockUpdate();
00068       coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_, _resetTrackBall );
00069       PluginFunctions::viewerProperties(i).unLockUpdate();
00070       coreWidget_->examiner_widgets_[i]->updateGL();
00071     }
00072 
00073   }
00074 
00075   // Update the draw Modes Menu
00076   if ( OpenFlipper::Options::gui() )
00077     coreWidget_->slotUpdateGlobalDrawMenu();
00078 }
00079 
00080 //========================================================================================
00081 // ===            Open/Add-Empty Functions                    ============================
00082 //========================================================================================
00083 
00084 
00085 void Core::slotGetAllFilters ( QStringList& _list){
00086 
00088   // Iterate over all types
00089   for (int i=0; i < (int)supportedTypes_.size(); i++){
00090     QString f = supportedTypes_[i].plugin->getLoadFilters();
00091     f = f.section(")",0,0).section("(",1,1).trimmed();
00092     _list << (QString::number(supportedTypes_[i].plugin->supportedType().value()) + " " + f);
00093   }
00094 }
00095 
00096 void Core::commandLineOpen(const char* _filename, bool _asPolyMesh ){
00097 
00098   QString file(_filename);
00099 
00100   // Modify filename to contain full paths if they were given as relative paths
00101   if ( !file.startsWith("/") && !file.contains(":") ) {
00102     file = QDir::currentPath();
00103     file += OpenFlipper::Options::dirSeparator();
00104     file += _filename;
00105   }
00106 
00107   // Add to the open list
00108   commandLineFileNames_.push_back(std::pair< std::string , bool >(file.toStdString(), _asPolyMesh));
00109 }
00110 
00111 void Core::commandLineScript(const char* _filename ) {
00112 
00113   QString file(_filename);
00114   
00115   // Modify filename to contain full paths if they were given as relative paths
00116   if ( !file.startsWith("/") && !file.contains(":") ) {
00117     file = QDir::currentPath();
00118     file += OpenFlipper::Options::dirSeparator();
00119     file += _filename;
00120   }
00121   
00122   // Add to the open list
00123   commandLineScriptNames_.push_back(file.toStdString());
00124 }
00125 
00126 void Core::slotExecuteAfterStartup() {
00127 
00128   //check if we have scripting support:
00129   bool scriptingSupport = false;
00130   slotPluginExists("scripting",scriptingSupport);
00131   if ( ! scriptingSupport ) {
00132     emit log(LOGERR ,tr("No scripting support available, please check if we load a scripting plugin .. Skipping script execution on startup"));
00133   }
00134 
00135   // Collect all script files from the scripting subdirectory and execute them if possible.
00136   // You can use this directory to execute scipts that modify for example modify the ui at
00137   // every startup.
00138   if ( scriptingSupport ) {
00139 
00140     // Get the files in the directory
00141     QDir scriptDir = OpenFlipper::Options::scriptDir();
00142     QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name);
00143 
00144     // Execute all files ending with ofs
00145     for ( int i = 0 ; i  < scriptFiles.size(); ++i )
00146       if ( scriptFiles[i].endsWith("ofs") )
00147         emit executeFileScript(scriptDir.path() + QDir::separator() + scriptFiles[i]);
00148 
00149   }
00150 
00151   // Open all files given at the commandline
00152   for ( uint i = 0 ; i < commandLineFileNames_.size() ; ++i ) {
00153 
00154     // Skip scripts here as they will be handled by a different function
00155     QString tmp = QString::fromStdString(commandLineFileNames_[i].first);
00156     if ( tmp.endsWith("ofs") ) {
00157       commandLineScriptNames_.push_back(commandLineFileNames_[i].first);
00158       continue;
00159     }
00160 
00161     // If the file was given with the polymesh option, open them as polymeshes.
00162     if (commandLineFileNames_[i].second)
00163       loadObject(DATA_POLY_MESH, QString::fromStdString(commandLineFileNames_[i].first));
00164     else {
00165       loadObject(QString::fromStdString(commandLineFileNames_[i].first));
00166     }
00167   }
00168 
00169   // If we have scripting support, execute the scripts given at the commandline.
00170   if ( scriptingSupport )
00171     for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) {
00172       emit executeFileScript(QString::fromStdString(commandLineScriptNames_[i]));
00173     }
00174 
00175   // If we don't have a gui and we are not under remote control,
00176   // exit the application as there would be no way to execute further commands
00177   if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl())
00178     exitApplication();
00179 }
00180 
00181 
00182 int Core::loadObject ( QString _filename ) {
00189   if (_filename.endsWith(".ini")) {
00190 
00191     // Load all information from the given ini file
00192     openIniFile(_filename,true,true,true);
00193 
00194     if ( OpenFlipper::Options::gui() )
00195       coreWidget_->addRecent(_filename, DATA_UNKNOWN);
00196 
00197     return -2;
00198   } else
00199   if (_filename.endsWith(".ofs")) {
00200      emit log(LOGINFO ,tr("Starting script execution of %1.").arg( _filename)) ;
00201      emit executeFileScript(_filename);
00202   } else {
00203     
00204     QFileInfo fi(_filename);
00205     
00206     for (int i=0; i < (int)supportedTypes_.size(); i++){
00207 
00208       QString filters = supportedTypes_[i].plugin->getLoadFilters();
00209       //check extension
00210       if ( ! filters.contains( "*." + fi.completeSuffix() ) )
00211         continue;
00212 
00213       if ( OpenFlipper::Options::gui() ) {
00214         coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
00215         if ( !OpenFlipper::Options::loadingSettings() )
00216           coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00217       }
00218 
00219       //load file
00220       int id = supportedTypes_[i].plugin->loadObject(_filename);
00221 
00222       if ( OpenFlipper::Options::gui() ) {
00223         if ( id != -1 )
00224           coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
00225         else
00226           coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
00227 
00228         if ( !OpenFlipper::Options::loadingSettings() )
00229           coreWidget_->setStatus(ApplicationStatus::READY );
00230       }
00231 
00232       return id;
00233     }
00234   }
00235 
00236   emit log(LOGERR, tr("Unable to load object (type unknown). No suitable plugin found!") );
00237 
00238   return -1;
00239 }
00240 
00242 int Core::loadObject( DataType _type, QString _filename) {
00247   if (_type == DATA_UNKNOWN)
00248     return loadObject(_filename);
00249 
00250   QFileInfo fi(_filename);
00251   
00252   for (int i=0; i < (int)supportedTypes_.size(); i++)
00253     if (supportedTypes_[i].type & _type || supportedTypes_[i].type == _type) {
00254 
00255       QString filters = supportedTypes_[i].plugin->getLoadFilters();
00256       //check extension
00257       if ( ! filters.contains( "*." + fi.completeSuffix() ) )
00258         continue;
00259         
00260       
00261       if ( OpenFlipper::Options::gui() ) {
00262         coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
00263         if ( !OpenFlipper::Options::loadingSettings() )
00264           coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00265       }
00266 
00267       int id = -1;
00268 
00269       //load file
00270       if ( checkSlot( supportedTypes_[i].object , "loadObject(QString,DataType)" ) )
00271         id = supportedTypes_[i].plugin->loadObject(_filename, _type);
00272       else
00273         id = supportedTypes_[i].plugin->loadObject(_filename);
00274 
00275       if ( OpenFlipper::Options::gui() ) {
00276         if ( id != -1 )
00277           coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
00278         else
00279           coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
00280 
00281         if ( !OpenFlipper::Options::loadingSettings() )
00282           coreWidget_->setStatus(ApplicationStatus::READY );
00283       }
00284 
00285       return id;
00286     }
00287     
00288   emit log(LOGERR, tr("Unable to load object. No suitable plugin found!") );
00289     
00290   return -1; //no plugin found
00291 }
00292 
00293 
00294 int Core::addEmptyObject( DataType _type ) {
00295   // Iterate over all plugins. The first plugin supporting the addEmpty function for the
00296   // specified type will be used to create the new object.
00297   
00298   int retCode = -1;
00299   
00300   // Type plugins
00301   for (int i=0; i < (int)supportedDataTypes_.size(); i++)
00302     if ( supportedDataTypes_[i].type & _type )
00303       retCode = supportedDataTypes_[i].plugin->addEmpty();
00304   
00305   if(retCode != -1) return retCode;
00306     
00307   // File plugins
00308   for (int i=0; i < (int)supportedTypes_.size(); i++)
00309     if ( supportedTypes_[i].type & _type ) {
00310       emit log(LOGERR, tr("File Plugins are not allowed to create empty objects anymore! Use the addEmpty call instead!") );
00311       retCode = supportedTypes_[i].plugin->addEmpty();
00312     }
00313   
00314   return retCode; // -1 if no plugin found
00315 }
00316 
00317 //========================================================================================
00318 // ===             Open/Add-Empty Slots                       ============================
00319 //========================================================================================
00320 
00322 void Core::slotAddEmptyObject( DataType _type , int& _id ) {
00323   
00324   _id = addEmptyObject( _type );
00325   
00326   if ( OpenFlipper::Options::doSlotDebugging() ) {
00327     if ( sender() != 0 ) {
00328       if ( sender()->metaObject() != 0 ) {
00329         emit log(LOGINFO,"slotAddEmptyObject( " + _type.name() + "," + QString::number(_id) +  tr(" ) called by ") +
00330         QString( sender()->metaObject()->className() ) );
00331       }
00332     } else {
00333       emit log(LOGINFO,"slotAddEmptyObject( " + _type.name() + ","  + QString::number(_id) +  tr(" ) called by Core") );
00334     }
00335   }
00336 }
00337 
00339 void Core::slotCopyObject( int _oldId , int& _newId ) {
00340 
00341   if ( _oldId == -1 ) {
00342     emit log(LOGERR,tr("Requested copy for illegal Object id: %1").arg(_oldId) );
00343     _newId = -1;
00344     return;
00345   }
00346 
00347   // get the node
00348   BaseObject* object = objectRoot_->childExists(_oldId);
00349 
00350   if ( !object ) {
00351     emit log(LOGERR,tr("Requested copy for unknown Object id: %1 ").arg(_oldId) );
00352     _newId = -1;
00353     return ;
00354   }
00355 
00356   // Copy the item
00357   BaseObject* copy = object->copy();
00358 
00359   if ( copy == 0 ) {
00360     emit log(LOGERR,tr("Unable to create a copy of the object."));
00361     return;
00362   }
00363 
00364   // Integrate into object tree
00365   copy->setParent( object->parent() );
00366 
00367   // return the new id
00368   _newId = copy->id();
00369 
00370   // tell plugins that a new object has been created
00371   slotEmptyObjectAdded(_newId);
00372 
00373   // tell plugins that the object has been updated
00374   slotObjectUpdated(_newId);
00375 
00376 }
00377 
00379 void Core::slotLoad(QString _filename, int _pluginID) {
00380 
00381   if ( OpenFlipper::Options::gui() ) {
00382     coreWidget_->statusMessage( tr("Loading %1 ... ").arg(_filename));
00383     if ( !OpenFlipper::Options::loadingSettings() )
00384       coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00385   }
00386 
00387   //load file
00388   int id = supportedTypes_[_pluginID].plugin->loadObject(_filename);
00389 
00390   if ( OpenFlipper::Options::gui() ) {
00391     if ( id != -1 )
00392       coreWidget_->statusMessage( tr("Loading %1 ... done").arg(_filename), 4000 );
00393     else
00394       coreWidget_->statusMessage( tr("Loading %1 ... failed!").arg(_filename), 4000 );
00395 
00396     if ( !OpenFlipper::Options::loadingSettings() )
00397       coreWidget_->setStatus(ApplicationStatus::READY );
00398   }
00399   
00400   // Initialize as unknown type
00401   DataType type = DATA_UNKNOWN;
00402 
00403   // An object has been added. Get it and do some processing!
00404   if ( id > 0 ) {
00405 
00406     BaseObjectData* object;
00407     PluginFunctions::getObject(id,object);
00408     
00409     if ( !object ) {
00410 
00411       BaseObject* baseObj = 0;
00412       GroupObject* group = 0;
00413       
00414       PluginFunctions::getObject(id,baseObj);
00415       
00416       if (baseObj){
00417 
00418         group = dynamic_cast< GroupObject* > (baseObj);
00419 
00420         if (group)
00421           type = DATA_GROUP;
00422       }
00423       
00424       if ( group == 0 ){
00425         emit log(LOGERR,tr("Object id returned but no object with this id has been found! Error in one of the file plugins!"));
00426         return;
00427       }
00428     }
00429     
00430     // Get the objects type
00431     if (object)
00432       type = object->dataType();
00433   }
00434   
00435   // If the id was greater than zero, add the file to the recent files.
00436   if ( id >= 0 )
00437     if ( OpenFlipper::Options::gui() )
00438       coreWidget_->addRecent(_filename, type);
00439 }
00440 
00442 void Core::slotLoad(QString _filename, DataType _type, int& _id) {
00443   _id = loadObject(_type,_filename);
00444 
00445   if ( _id < 0 )
00446     _id = -1;
00447   else
00448     if ( OpenFlipper::Options::gui() )
00449       coreWidget_->addRecent(_filename,_type);
00450 }
00451 
00453 void Core::slotObjectOpened ( int _id ) {
00454   if ( OpenFlipper::Options::doSlotDebugging() ) {
00455     if ( sender() != 0 ) {
00456       if ( sender()->metaObject() != 0 ) {
00457         emit log(LOGINFO,tr("slotObjectOpened( ") + QString::number(_id) + tr(" ) called by ") +
00458                   QString( sender()->metaObject()->className() ) );
00459       }
00460     } else {
00461       emit log(LOGINFO,tr("slotObjectOpened( ") + QString::number(_id) + tr(" ) called by Core") );
00462     }
00463   }
00464 
00465   // get the opened object
00466   BaseObjectData* object;
00467   PluginFunctions::getObject(_id,object);
00468 
00469   QColor color;
00470 
00471   if ( OpenFlipper::Options::randomBaseColor() ){
00472       //init random seed
00473       srand ( time(NULL) );
00474 
00475       QColor bckgrnd = OpenFlipperSettings().value("Core/Gui/glViewer/defaultBackgroundColor").value<QColor>();
00476       int diff;
00477 
00478       do{
00479         color.setRgb(rand()%255, rand()%255, rand()%255);
00480 
00481         diff = (bckgrnd.red()   - color.red())  *(bckgrnd.red()   - color.red())
00482               +(bckgrnd.green() - color.green())*(bckgrnd.green() - color.green())
00483               +(bckgrnd.blue()  - color.blue()) *(bckgrnd.blue()  - color.blue());
00484       }while (diff < 70000);
00485   }
00486   else{
00487       color = OpenFlipper::Options::defaultBaseColor();
00488   }
00489 
00490   ACG::Vec4f colorV;
00491   colorV[0] = color.redF();
00492   colorV[1] = color.greenF();
00493   colorV[2] = color.blueF();
00494   colorV[3] = color.alphaF();
00495 
00496   object->setBaseColor( colorV );
00497 
00498   // ================================================================================
00499   // Set defaults for DrawMode, ViewingDirection and Projection if this is the first opened object
00500   // If a plugin changes the drawmode later, this setting will be overridden!
00501   // ================================================================================
00502   if ( PluginFunctions::objectCount() == 1 && OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() )
00503     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ){
00504       PluginFunctions::viewerProperties(i).drawMode( OpenFlipper::Options::defaultDrawMode(i) );
00505 
00506       if ( OpenFlipper::Options::defaultProjectionMode(i) == 0 )
00507         PluginFunctions::orthographicProjection(i);
00508       else
00509         PluginFunctions::perspectiveProjection(i);
00510 
00511       PluginFunctions::setFixedView(OpenFlipper::Options::defaultViewingDirection(i), i );
00512     }
00513 
00514   // ================================================================================
00515   // Recompute bounding box and scenegraph info
00516   // Reset scene center here to include new object
00517   // ================================================================================
00518   resetScenegraph(true);
00519 
00520   // ================================================================================
00521   // Tell plugins, that a file has been opened
00522   // ================================================================================
00523   emit openedFile( _id );
00524   
00525   // ================================================================================
00526   // Print Info to logger
00527   // ================================================================================
00528   emit log( LOGINFO ,object->getObjectinfo() );
00529 
00530   // ================================================================================
00531   // Tell plugins, that the Object is updated and the active object has changed
00532   // ================================================================================
00533   emit signalObjectUpdated(_id);
00534 
00535   // ================================================================================
00536   // Create initial backup
00537   // ================================================================================
00538   backupRequest(_id,"Original Object");
00539 
00540   // ================================================================================
00541   // Add the file to the recent files menu
00542   // ================================================================================
00543   QString filename = object->path() + OpenFlipper::Options::dirSeparator() + object->name();
00544   BaseObject* object2;
00545   PluginFunctions::getObject(_id,object2);
00546 
00547   // ================================================================================
00548   // if this is the first object opend, reset the global view
00549   // ================================================================================
00550   if ( PluginFunctions::objectCount() == 1 && OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() )
00551     for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
00552       coreWidget_->examiner_widgets_[i]->viewAll();
00553     }
00554 
00555   // objectRoot_->dumpTree();
00556 }
00557 
00559 void Core::slotEmptyObjectAdded ( int _id ) {
00560 
00561   if ( OpenFlipper::Options::doSlotDebugging() ) {
00562     if ( sender() != 0 ) {
00563       if ( sender()->metaObject() != 0 ) {
00564         emit log(LOGINFO,tr("slotEmptyObjectAdded( ") + QString::number(_id) + tr(" ) called by ") +
00565                   QString( sender()->metaObject()->className() ) );
00566       }
00567     } else {
00568       emit log(LOGINFO,tr("slotEmptyObjectAdded( ") + QString::number(_id) + tr(" ) called by Core") );
00569     }
00570   }
00571 
00572   // get the opened object
00573   BaseObjectData* object;
00574   PluginFunctions::getObject(_id,object);
00575 
00576   
00577   emit emptyObjectAdded( _id );
00578 
00579   // Tell the Plugins that the Object List and the active object have changed
00580   emit signalObjectUpdated(_id);
00581 
00582   backupRequest(_id,"Original Object");
00583 
00585 //    QString filename = object->path() + OpenFlipper::Options::dirSeparator() + object->name();
00586 
00587 //    addRecent(filename);
00588 }
00589 
00590 //========================================================================================
00591 // ===             Menu Slots                                 ============================
00592 //========================================================================================
00593 
00595 void Core::slotAddEmptyObjectMenu() {
00596   std::vector< DataType > types;
00597   QStringList             typeNames;
00598   
00599   DataType currentType = 2;
00600   
00601   // Iterate over all Types known to the core
00602   // Start at 2:
00603   // 0 type is defined as DATA_UNKNOWN
00604   // 1 type is defined as DATA_GROUP
00605   // Therefore we have two types less then reported
00606   // 
00607   for ( uint i = 0 ; i < typeCount() - 2  ; ++i) {
00608     
00609     // Iterate over all supported types (created from plugins on load)
00610     // Check if a plugin supports addEmpty for the current type.
00611     // Only if the type is supported, add it to the addEmpty Dialog
00612     
00613     // typePlugin
00614     for ( uint j = 0 ; j < supportedDataTypes_.size(); j++) {
00615       
00616       // Check if a plugin supports the current type
00617       if ( supportedDataTypes_[j].type & currentType ) {
00618         types.push_back(currentType);
00619         typeNames.push_back( typeName( currentType ) );
00620         
00621         // Stop here as we need only one plugin supporting addEmpty for a given type
00622         break;
00623       }
00624     }
00625     
00626     // filePlugin
00627     for ( uint j = 0 ; j < supportedTypes_.size(); j++) {
00628       
00629       // Check if a plugin supports the current Type
00630       if ( supportedTypes_[j].type & currentType ) {
00631         
00632         // Avoid duplicates
00633         bool duplicate = false;
00634         for(std::vector< DataType >::iterator it = types.begin(); it != types.end(); ++it) {
00635           if(*it == currentType) {
00636             duplicate = true;
00637             break;
00638           }
00639         }
00640           
00641         if(!duplicate) {
00642           types.push_back(currentType);
00643           typeNames.push_back( typeName( currentType ) );
00644         
00645           // Stop here as we need only one plugin supporting addEmpty for a given type
00646           break;
00647         }
00648       }
00649     }
00650     
00651     // Advance to next type ( Indices are bits so multiply by to to get next bit)
00652     currentType++;
00653   }
00654   
00655   static addEmptyWidget* widget = 0;
00656   
00657   if (supportedTypes_.size() != 0) {
00658     
00659     if ( !widget ){
00660       widget = new addEmptyWidget(types,typeNames);
00661       widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00662       connect(widget,SIGNAL(chosen(DataType, int&)),this,SLOT(slotAddEmptyObject(DataType, int&)));
00663     }
00664     
00665     widget->show();
00666     
00667   } else
00668     emit log(LOGERR,tr("Could not show 'add Empty' dialog. Missing file-plugins ?"));
00669   
00670 }
00671 
00672 //========================================================================================
00673 // ===             Public Slots                                 ============================
00674 //========================================================================================
00675 
00677 void Core::loadObject() {
00678 
00679   if ( OpenFlipper::Options::gui() ){
00680 
00681     if (supportedTypes_.size() != 0){
00682       LoadWidget* widget = new LoadWidget(supportedTypes_);
00683       connect(widget,SIGNAL(load(QString, int)),this,SLOT(slotLoad(QString, int)));
00684       connect(widget,SIGNAL(save(int, QString, int)),this,SLOT(saveObject(int, QString, int)));
00685 
00686       widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00687 
00688       widget->showLoad();
00689 
00690       widget->disconnect();
00691       delete widget;
00692 
00693     }else
00694       emit log(LOGERR,tr("Could not show 'load objects' dialog. Missing file-plugins."));
00695 
00696   }
00697 }
00698 
00700 void Core::loadSettings(){
00701 
00702   if ( OpenFlipper::Options::gui() ){
00703 
00704     QString complete_name;
00705 
00706 
00707     QFileDialog fileDialog( coreWidget_,
00708                             tr("Load Settings"),
00709                             OpenFlipperSettings().value("Core/CurrentDir").toString(),
00710                             tr("INI files (*.ini)") );
00711 
00712     fileDialog.setOption (QFileDialog::DontUseNativeDialog, true);
00713     fileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
00714     fileDialog.setFileMode ( QFileDialog::AnyFile );
00715 
00716     QGridLayout *layout = (QGridLayout*)fileDialog.layout();
00717 
00718     QGroupBox* optionsBox = new QGroupBox( &fileDialog ) ;
00719     optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
00720     optionsBox->setTitle(tr("Options"));
00721     layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
00722 
00723     QCheckBox *loadProgramSettings = new QCheckBox(optionsBox);
00724     loadProgramSettings->setText(tr("Load program settings"));
00725     loadProgramSettings->setToolTip(tr("Load all current program settings from the file ( This will include view settings, colors,...) "));
00726     loadProgramSettings->setCheckState( Qt::Unchecked );
00727 
00728     QCheckBox *loadPluginSettings = new QCheckBox(optionsBox);
00729     loadPluginSettings->setText(tr("Load per Plugin Settings"));
00730     loadPluginSettings->setToolTip(tr("Plugins should load their current global settings from the file"));
00731     loadPluginSettings->setCheckState( Qt::Checked );
00732 
00733     QCheckBox *loadObjectInfo = new QCheckBox(optionsBox);
00734     loadObjectInfo->setText(tr("Load all objects defined in the file"));
00735     loadObjectInfo->setToolTip(tr("Load all objects which are defined in the file"));
00736     loadObjectInfo->setCheckState( Qt::Checked );
00737 
00738     QBoxLayout* frameLayout = new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
00739     frameLayout->addWidget( loadProgramSettings , 0 , 0);
00740     frameLayout->addWidget( loadPluginSettings  , 1 , 0);
00741     frameLayout->addWidget( loadObjectInfo      , 2 , 0);
00742     frameLayout->addStretch();
00743 
00744     fileDialog.resize(550 ,500);
00745 
00746     // ========================================================================================
00747     // show the saveSettings-Dialog and get the target file
00748     // ========================================================================================
00749     QStringList fileNames;
00750     if (fileDialog.exec()) {
00751       fileNames = fileDialog.selectedFiles();
00752     } else {
00753       return;
00754     }
00755 
00756     if ( fileNames.size() > 1 ) {
00757       std::cerr << "Too many save filenames selected" << std::endl;
00758       return;
00759     }
00760 
00761     complete_name = fileNames[0];
00762 
00763 
00764     QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
00765     OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
00766 
00767     if ( complete_name.endsWith("ini") ) {
00768       openIniFile( complete_name,
00769                    loadProgramSettings->isChecked(),
00770                    loadPluginSettings->isChecked(),
00771                    loadObjectInfo->isChecked());
00772       if ( loadProgramSettings->isChecked() )
00773         applyOptions();
00774     } 
00775     
00776     coreWidget_->addRecent(complete_name, DATA_UNKNOWN);
00777   }
00778 }
00779 
00781 void Core::loadSettings(QString _filename){
00782 
00783   if ( !QFile(_filename).exists() )
00784     return;
00785 
00786   QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
00787   OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
00788 
00789   if ( _filename.endsWith("ini") ) {
00790     // Loaded function for recent files. Load everything.
00791     openIniFile(_filename,true,true,true);
00792     applyOptions();
00793   } else if ( _filename.endsWith("obj") ) {
00794     loadObject(_filename);
00795     applyOptions();
00796   }
00797 
00798 }

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