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), m_clearDirty(false)
00045         {};
00046         
00048         PanoCommand(ManagedPanoramaData& panoData, const StringType& commandName)
00049             : AppBase::Command<StringType>(commandName), pano(panoData), memento(NULL), redoMemento(NULL), m_clearDirty(false)
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                 // notify all observers about changes
00097                 pano.changeFinished();
00098                 if(m_clearDirty)
00099                 {
00100                     pano.clearDirty();
00101                 };
00102             }
00103             else
00104             {
00105                 // [TODO] warning!
00106                 pano.setMementoToCopyOf(memento);
00107             }
00108         };
00109         
00110 
00111         
00112     protected:
00113             
00118         virtual bool processPanorama(ManagedPanoramaData& panoramaData)
00119         {
00120             // [TODO] maybe a warning
00121             return true;
00122         }
00123         
00124     public:
00125         
00131         virtual void undo()
00132         {
00133             DEBUG_ASSERT(memento!=NULL);
00134             saveRedoMemento();
00135             pano.setMementoToCopyOf(memento);
00136             pano.changeFinished();
00137         }
00138         
00144         virtual void redo()
00145         {
00146             if(redoMemento==NULL) {
00147                 execute();
00148             } else {
00149                 pano.setMementoToCopyOf(redoMemento);
00150                 pano.changeFinished();
00151             }
00152         }
00153 
00154         
00155     protected:
00157         ManagedPanoramaData& pano;
00158         
00159         
00160     protected:
00162         PanoramaDataMemento* memento;
00163         
00165         PanoramaDataMemento* redoMemento;
00166 
00167         // if true, the dirty tag is cleared, otherwise it is keep
00168         bool m_clearDirty;
00169     };
00170 
00171 } // namespace
00172 #endif // _H

Generated on 31 Oct 2014 for Hugintrunk by  doxygen 1.4.7