saveFunctions.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: 8520 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-10 15:56:59 +0100 (Mi, 10. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 #include "Core.hh"
00045 
00046 #include "OpenFlipper/common/GlobalOptions.hh"
00047 
00048 #include "OpenFlipper/BasePlugin/PluginFunctions.hh"
00049 
00050 #include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
00051 
00052 //========================================================================================
00053 // ===  Public Slots (called by CoreWidget's File-Menu / Scripting / Plugins)    =========
00054 //========================================================================================
00055 
00059 bool Core::saveObject( int _id, QString _filename ) {
00060   BaseObjectData* object;
00061   PluginFunctions::getObject(_id,object);
00062 
00063   for (int i=0; i < (int)supportedTypes_.size(); i++)
00064     if (object->dataType() == supportedTypes_[i].type) {
00065 
00066       if ( OpenFlipper::Options::gui() ) {
00067         coreWidget_->statusMessage( tr("Saving ") + _filename + " ...");
00068         if ( !OpenFlipper::Options::savingSettings() )
00069           coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00070       }
00071 
00072       //save object
00073       bool ok = supportedTypes_[i].plugin->saveObject(_id,_filename);
00074     
00075       if ( OpenFlipper::Options::gui() ) {
00076         if (ok)
00077           coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... done"), 4000 );
00078         else
00079           coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
00080     
00081         if ( !OpenFlipper::Options::savingSettings() )
00082           coreWidget_->setStatus(ApplicationStatus::READY );
00083       }
00084 
00085       //add to recent files
00086       if (ok && !OpenFlipper::Options::savingSettings()
00087              &&  OpenFlipper::Options::gui() )
00088         coreWidget_->addRecent( _filename, object->dataType() );
00089 
00090       return ok;
00091     }
00092 
00093   // no plugin found
00094   if ( OpenFlipper::Options::gui() )
00095       coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
00096 
00097   return false;
00098 }
00099 
00100 //-----------------------------------------------------------------------------------------------------
00101 
00105 void Core::saveObject( int _id, QString _filename, int _pluginID ) {
00106   BaseObjectData* object;
00107   PluginFunctions::getObject(_id,object);
00108 
00109 
00110   if ( OpenFlipper::Options::gui() ) {
00111     coreWidget_->statusMessage( tr("Saving ") + _filename + " ...");
00112     if ( !OpenFlipper::Options::savingSettings() )
00113       coreWidget_->setStatus(ApplicationStatus::PROCESSING );
00114   }
00115 
00116   //save object
00117   bool ok = supportedTypes_[_pluginID].plugin->saveObject(_id,_filename);
00118 
00119   if ( OpenFlipper::Options::gui() ) {
00120     if (ok)
00121       coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... done"), 4000 );
00122     else
00123       coreWidget_->statusMessage( tr("Saving ") + _filename + tr(" ... failed!"), 4000 );
00124 
00125     if ( !OpenFlipper::Options::savingSettings() )
00126       coreWidget_->setStatus(ApplicationStatus::READY );
00127   }
00128 
00129   //add to recent files
00130   if (ok && !OpenFlipper::Options::savingSettings()
00131           &&  OpenFlipper::Options::gui() )
00132     coreWidget_->addRecent( _filename, object->dataType() );
00133 
00134 }
00135 
00136 //-----------------------------------------------------------------------------------------------------
00137 
00140 bool Core::saveObjectTo( int _id, QString _filename ) {
00141 
00142   bool result = false;
00143 
00144   if ( OpenFlipper::Options::gui() ){
00145 
00146     BaseObjectData* object;
00147     PluginFunctions::getObject(_id,object);
00148   
00149     //init widget
00150     LoadWidget* widget = new LoadWidget(supportedTypes_);
00151     widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00152 
00153     connect(widget,SIGNAL(load(QString, int)),this,SLOT(slotLoad(QString, int)));
00154     connect(widget,SIGNAL(save(int, QString, int)),this,SLOT(saveObject(int, QString, int)));
00155   
00156     if (supportedTypes_.size() != 0)
00157       result = widget->showSave(_id,_filename);
00158     else
00159       emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00160 
00161     widget->disconnect();
00162     delete widget;
00163   }
00164 
00165   return result;
00166 }
00167 
00168 //-----------------------------------------------------------------------------------------------------
00169 
00171 void Core::saveAllObjects(){
00172 
00173   if ( OpenFlipper::Options::gui() ){
00174 
00175     //ensure that all options are on their default values
00176     for (int i=0; i < (int)supportedTypes_.size(); i++)
00177       supportedTypes_[i].plugin->saveOptionsWidget("");
00178   
00179     //iterate over all target objects
00180     for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
00181           o_it != PluginFunctions::objectsEnd(); ++o_it)  {
00182   
00183             if ( !QDir(o_it->path()).exists() || o_it->path().trimmed() == "" ) // if path isn't valid use 'save object to'
00184               saveObjectTo(o_it->id(),o_it->name());
00185             else{
00186               //save (existing files will be overwritten)
00187               QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name() ;
00188               saveObject(o_it->id(),filename);
00189             }
00190     }
00191   }
00192 }
00193 
00194 //-----------------------------------------------------------------------------------------------------
00195 
00197 void Core::saveAllObjectsTo(){
00198   if ( OpenFlipper::Options::gui() ){
00199     if (supportedTypes_.size() != 0){
00200       //iterate over all target objects
00201       for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
00202             o_it != PluginFunctions::objectsEnd(); ++o_it)  {
00203         QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
00204         saveObjectTo(o_it->id(),filename);
00205       }
00206     }else
00207       emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00208   }
00209 }
00210 
00211 
00212 

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