]> SALOME platform Git repositories - modules/yacs.git/blob - src/hmi/commands.cxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / hmi / commands.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "commands.hxx"
20
21 //#define _DEVDEBUG_
22 #include "YacsTrace.hxx"
23
24 using namespace std;
25
26 using namespace YACS;
27 using namespace YACS::HMI;
28
29 Command::Command()
30 {
31   _subCommands.clear();
32 }
33
34 bool Command::execute()
35 {
36   bool ret=true;
37   ret = localExecute();
38   if (! _subCommands.empty())
39     {
40       list<Command*>::iterator it;
41       for (it=_subCommands.begin(); it!=_subCommands.end(); it++)
42         {
43           if (!ret) break;
44           ret = (*it)->execute();
45         }
46     }
47   return ret;
48 }
49
50 bool Command::reverse()
51 {
52   bool ret=true;
53   if (! _subCommands.empty())
54     {
55       list<Command*>::reverse_iterator it;
56       for (it=_subCommands.rbegin(); it!=_subCommands.rend(); it++)
57         {
58           ret =(*it)->execute();
59           if (!ret) break;
60         }
61     }
62   if (ret) ret = localReverse();
63   return ret;
64 }
65
66 void Command::addSubCommand(Command* command)
67 {
68   _subCommands.push_back(command); 
69 }
70
71 Invocator::Invocator()
72 {
73 }
74
75 void Invocator::add(Command* command)
76 {
77   _commandsDone.push(command); // to do after execute ok
78 }
79
80 bool Invocator::undo()
81 {
82   bool ret = true;
83   if (! _commandsDone.empty())
84     {
85       _commandsDone.pop();
86       ret = _commandsDone.top()->reverse();
87       _commandsUndone.push(_commandsDone.top());
88     }
89   return ret;
90 }
91
92 bool Invocator::redo()
93 {
94   bool ret = true;
95   if (! _commandsUndone.empty())
96     {
97       _commandsUndone.pop();
98       ret = _commandsUndone.top()->execute();
99       _commandsDone.push(_commandsUndone.top());
100     }
101   return ret;
102 }
103