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: 6733 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 09:32:32 +0200 (Mi, 05. Aug 2009) $                   *
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 
00104 bool Core::saveObjectTo( int _id, QString _filename ) {
00105 
00106   bool result = false;
00107 
00108   if ( OpenFlipper::Options::gui() ){
00109 
00110     BaseObjectData* object;
00111     PluginFunctions::getObject(_id,object);
00112   
00113     //init widget
00114     LoadWidget* widget = new LoadWidget(supportedTypes_);
00115     widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
00116 
00117     connect(widget,SIGNAL(load(QString, DataType, int&)),this,SLOT(slotLoad(QString, DataType, int&)));
00118     connect(widget,SIGNAL(save(int, QString)),this,SLOT(saveObject(int, QString)));
00119   
00120     if (supportedTypes_.size() != 0)
00121       result = widget->showSave(_id,_filename);
00122     else
00123       emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00124 
00125     widget->disconnect();
00126     delete widget;
00127   }
00128 
00129   return result;
00130 }
00131 
00132 //-----------------------------------------------------------------------------------------------------
00133 
00135 void Core::saveAllObjects(){
00136 
00137   if ( OpenFlipper::Options::gui() ){
00138 
00139     //ensure that all options are on their default values
00140     for (int i=0; i < (int)supportedTypes_.size(); i++)
00141       supportedTypes_[i].plugin->saveOptionsWidget("");
00142   
00143     //iterate over all target objects
00144     for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
00145           o_it != PluginFunctions::objectsEnd(); ++o_it)  {
00146   
00147             if ( !QDir(o_it->path()).exists() || o_it->path().trimmed() == "" ) // if path isn't valid use 'save object to'
00148               saveObjectTo(o_it->id(),o_it->name());
00149             else{
00150               //save (existing files will be overwritten)
00151               QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name() ;
00152               saveObject(o_it->id(),filename);
00153             }
00154     }
00155   }
00156 }
00157 
00158 //-----------------------------------------------------------------------------------------------------
00159 
00161 void Core::saveAllObjectsTo(){
00162   if ( OpenFlipper::Options::gui() ){
00163     if (supportedTypes_.size() != 0){
00164       //iterate over all target objects
00165       for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS);
00166             o_it != PluginFunctions::objectsEnd(); ++o_it)  {
00167         QString filename = o_it->path() + OpenFlipper::Options::dirSeparator() + o_it->name();
00168         saveObjectTo(o_it->id(),filename);
00169       }
00170     }else
00171       emit log(LOGERR,tr("Could not show 'save objects' dialog. Missing file-plugins."));
00172   }
00173 }
00174 
00175 
00176 

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