1 // -*- c-basic-offset: 4 -*-
2 /** @file huginapp/PanoCommand.h
3  *
4  *  @author Pablo d'Angelo <pablo.dangelo@web.de>
5  *
6  *  $Id$
7  *
8  *  This is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2 of the License, or (at your option) any later version.
12  *
13  *  This software is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public
19  *  License along with this software. If not, see
20  *  <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 #include "Command.h"
25 
26 namespace PanoCommand
27 {
28 
~PanoCommand()29 PanoCommand::~PanoCommand()
30 {
31     if (m_memento != NULL)
32     {
33         delete m_memento;
34     };
35     if (m_redoMemento != NULL)
36     {
37         delete m_redoMemento;
38     };
39 }
40 
execute()41 void PanoCommand::execute()
42 {
43     saveMemento();
44     bool success = processPanorama(m_pano);
45     setSuccessful(success);
46     if (success)
47     {
48         // notify all observers about changes
49         m_pano.changeFinished();
50         if (m_clearDirty)
51         {
52             m_pano.clearDirty();
53         };
54     }
55     else
56     {
57         // [TODO] warning!
58         m_pano.setMementoToCopyOf(m_memento);
59     };
60 }
61 
undo()62 void PanoCommand::undo()
63 {
64     DEBUG_ASSERT(m_memento != NULL);
65     saveRedoMemento();
66     m_pano.setMementoToCopyOf(m_memento);
67     m_pano.changeFinished();
68 }
69 
redo()70 void PanoCommand::redo()
71 {
72     if (m_redoMemento == NULL)
73     {
74         execute();
75     }
76     else
77     {
78         m_pano.setMementoToCopyOf(m_redoMemento);
79         m_pano.changeFinished();
80     };
81 }
82 
getName() const83 std::string PanoCommand::getName() const
84 {
85     return m_name;
86 }
87 
setName(const std::string & newName)88 void PanoCommand::setName(const std::string& newName)
89 {
90     m_name = newName;
91 }
92 
wasSuccessful()93 bool PanoCommand::wasSuccessful()
94 {
95     return m_successful;
96 }
97 
setSuccessful(bool success)98 void PanoCommand::setSuccessful(bool success)
99 {
100     m_successful = success;
101 }
102 
saveMemento()103 void PanoCommand::saveMemento()
104 {
105     if (m_memento != NULL)
106     {
107         delete m_memento;
108     };
109     m_memento = m_pano.getNewMemento();
110 };
111 
saveRedoMemento()112 void PanoCommand::saveRedoMemento()
113 {
114     if (m_redoMemento != NULL)
115     {
116         delete m_redoMemento;
117     };
118     m_redoMemento = m_pano.getNewMemento();
119 }
120 
processPanorama(HuginBase::Panorama & panoramaData)121 bool PanoCommand::processPanorama(HuginBase::Panorama& panoramaData)
122 {
123     return true;
124 }
125 
126 } // namespace
127