Command.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #include "Command.h"
00025 
00026 namespace PanoCommand
00027 {
00028 
00029 PanoCommand::~PanoCommand()
00030 {
00031     if (m_memento != NULL)
00032     {
00033         delete m_memento;
00034     };
00035     if (m_redoMemento != NULL)
00036     {
00037         delete m_redoMemento;
00038     };
00039 }
00040 
00041 void PanoCommand::execute()
00042 {
00043     saveMemento();
00044     bool success = processPanorama(m_pano);
00045     setSuccessful(success);
00046     if (success)
00047     {
00048         // notify all observers about changes
00049         m_pano.changeFinished();
00050         if (m_clearDirty)
00051         {
00052             m_pano.clearDirty();
00053         };
00054     }
00055     else
00056     {
00057         // [TODO] warning!
00058         m_pano.setMementoToCopyOf(m_memento);
00059     };
00060 }
00061 
00062 void PanoCommand::undo()
00063 {
00064     DEBUG_ASSERT(m_memento != NULL);
00065     saveRedoMemento();
00066     m_pano.setMementoToCopyOf(m_memento);
00067     m_pano.changeFinished();
00068 }
00069 
00070 void PanoCommand::redo()
00071 {
00072     if (m_redoMemento == NULL)
00073     {
00074         execute();
00075     }
00076     else
00077     {
00078         m_pano.setMementoToCopyOf(m_redoMemento);
00079         m_pano.changeFinished();
00080     };
00081 }
00082 
00083 std::string PanoCommand::getName() const
00084 {
00085     return m_name;
00086 }
00087 
00088 void PanoCommand::setName(const std::string& newName)
00089 {
00090     m_name = newName;
00091 }
00092 
00093 bool PanoCommand::wasSuccessful()
00094 {
00095     return m_successful;
00096 }
00097 
00098 void PanoCommand::setSuccessful(bool success)
00099 {
00100     m_successful = success;
00101 }
00102 
00103 void PanoCommand::saveMemento()
00104 {
00105     if (m_memento != NULL)
00106     {
00107         delete m_memento;
00108     };
00109     m_memento = m_pano.getNewMemento();
00110 };
00111 
00112 void PanoCommand::saveRedoMemento()
00113 {
00114     if (m_redoMemento != NULL)
00115     {
00116         delete m_redoMemento;
00117     };
00118     m_redoMemento = m_pano.getNewMemento();
00119 }
00120 
00121 bool PanoCommand::processPanorama(HuginBase::Panorama& panoramaData)
00122 {
00123     return true;
00124 }
00125 
00126 } // namespace

Generated on 20 Apr 2018 for Hugintrunk by  doxygen 1.4.7