[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/huginapp/PanoCommand.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _HUGINAPP_PANOCOMMAND_H
00025 #define _HUGINAPP_PANOCOMMAND_H
00026 
00027 #include <appbase/Command.h>
00028 
00029 #include <panodata/PanoramaData.h>
00030 
00031 
00032 namespace HuginBase
00033 {
00034 
00037     template <typename StringType = std::string>
00038     class PanoCommand : public AppBase::Command<StringType>
00039     {
00040     public:
00041         
00043         PanoCommand(ManagedPanoramaData& panoData)
00044             : pano(panoData), memento(NULL), redoMemento(NULL)
00045         {};
00046         
00048         PanoCommand(ManagedPanoramaData& panoData, const StringType& commandName)
00049             : AppBase::Command<StringType>(commandName), pano(panoData), memento(NULL), redoMemento(NULL)
00050         {};
00051         
00053         virtual ~PanoCommand()
00054         {
00055             if(memento != NULL)
00056                 delete memento;
00057             if(redoMemento != NULL)
00058                 delete redoMemento;
00059         };
00060         
00061         
00062     protected:
00064         virtual void saveMemento()
00065         {
00066             if(memento != NULL)
00067                 delete memento;
00068             memento = pano.getNewMemento();
00069         };
00070         
00072         virtual void saveRedoMemento()
00073         {
00074             if(redoMemento != NULL)
00075                 delete redoMemento;
00076             redoMemento = pano.getNewMemento();
00077         }
00078         
00079         
00080     public:
00086         virtual void execute()
00087         {
00088             saveMemento();
00089             
00090             bool success = processPanorama(pano);
00091             
00092             AppBase::Command<StringType>::setSuccessful(success);
00093             
00094             if(!success)
00095             {
00096                 // [TODO] warning!
00097                 pano.setMementoToCopyOf(memento);
00098             }
00099         };
00100         
00101 
00102         
00103     protected:
00104             
00109         virtual bool processPanorama(ManagedPanoramaData& panoramaData)
00110         {
00111             // [TODO] maybe a warning
00112             return true;
00113         }
00114         
00115     public:
00116         
00122         virtual void undo()
00123         {
00124             DEBUG_ASSERT(memento!=NULL);
00125             saveRedoMemento();
00126             pano.setMementoToCopyOf(memento);
00127             pano.changeFinished();
00128         }
00129         
00135         virtual void redo()
00136         {
00137             if(redoMemento==NULL) {
00138                 execute();
00139             } else {
00140                 pano.setMementoToCopyOf(redoMemento);
00141                 pano.changeFinished();
00142             }
00143         }
00144 
00145         
00146     protected:
00148         ManagedPanoramaData& pano;
00149         
00150         
00151     protected:
00153         PanoramaDataMemento* memento;
00154         
00156         PanoramaDataMemento* redoMemento;
00157         
00158     };
00159 
00160     
00161 } // namespace
00162 #endif // _H

Generated on Mon Sep 20 01:01:26 2010 for Hugintrunk by doxygen 1.3.9.1