Salome HOME
Copyright update 2021
[modules/yacs.git] / src / hmi / commands.hxx
1 // Copyright (C) 2006-2021  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, or (at your option) any later version.
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
20 #ifndef _COMMANDS_HXX_
21 #define _COMMANDS_HXX_
22
23 #include "HMIExport.hxx"
24 #include <list>
25 #include <string>
26 #include <vector>
27
28 namespace YACS
29 {
30   namespace ENGINE
31   {
32     class Proc;
33     class Catalog;
34   }
35
36   namespace HMI
37   {
38     class Command
39     {
40     public:
41       Command();
42       virtual bool execute();
43       virtual bool reverse(bool isNormal=true);
44       virtual bool executeSubOnly();
45       virtual std::string dump();
46       std::string recursiveDump(int level =0);
47       void addSubCommand(Command* command);
48       bool isNormalReverse() { return _normalReverse; };
49     protected:
50       virtual bool localExecute() = 0;
51       virtual bool localReverse() = 0;
52       std::vector<Command*> _subCommands;
53       bool _normalReverse;
54     };
55     
56     class HMI_EXPORT Invocator
57     {
58       friend class Command;
59     public:
60       Invocator();
61       void add(Command* command);
62       bool undo();
63       bool redo();
64       std::list<std::string> getDone();
65       std::list<std::string> getUndone();
66       YACS::ENGINE::Proc *getUndoProc() { return _undoProc; };
67       YACS::ENGINE::Catalog *getUndoCata() { return _undoCata; };
68       bool isSpecialReverse() { return _specialReverse; };
69       static int _ctr;
70
71     protected:
72       std::vector<Command*> _commandsDone;
73       std::vector<Command*> _commandsUndone;
74       std::vector<Command*> _commandsInProgress;
75       YACS::ENGINE::Proc *_undoProc;
76       YACS::ENGINE::Catalog *_undoCata;
77       bool _isRedo;
78       bool _isUndo;
79       bool _specialReverse;
80     };
81   }
82 }
83 #endif