1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "commands.hxx"
22 #include "YacsTrace.hxx"
27 using namespace YACS::HMI;
34 bool Command::execute()
38 if (! _subCommands.empty())
40 list<Command*>::iterator it;
41 for (it=_subCommands.begin(); it!=_subCommands.end(); it++)
44 ret = (*it)->execute();
50 bool Command::reverse()
53 if (! _subCommands.empty())
55 list<Command*>::reverse_iterator it;
56 for (it=_subCommands.rbegin(); it!=_subCommands.rend(); it++)
58 ret =(*it)->execute();
62 if (ret) ret = localReverse();
66 void Command::addSubCommand(Command* command)
68 _subCommands.push_back(command);
71 Invocator::Invocator()
75 void Invocator::add(Command* command)
77 _commandsDone.push(command); // to do after execute ok
80 bool Invocator::undo()
83 if (! _commandsDone.empty())
86 ret = _commandsDone.top()->reverse();
87 _commandsUndone.push(_commandsDone.top());
92 bool Invocator::redo()
95 if (! _commandsUndone.empty())
97 _commandsUndone.pop();
98 ret = _commandsUndone.top()->execute();
99 _commandsDone.push(_commandsUndone.top());