Salome HOME
Merge branch 'BR_EDF_2018_Lot1'
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_ActionsMgr_H
22 #define XGUI_ActionsMgr_H
23
24 #include "XGUI.h"
25
26 #include <Events_Listener.h>
27 #include <ModelAPI_Feature.h>
28
29 #include <ModuleBase_ActionInfo.h>
30
31 #include <QObject>
32 #include <QMap>
33 #include <QList>
34 #include <QStringList>
35 #include <QKeySequence>
36
37 class XGUI_Workshop;
38 class XGUI_OperationMgr;
39 class ModuleBase_Operation;
40 class QAction;
41
42 /// class XGUI_ActionsMgr
43 /// \ingroup GUI
44 /// A class for management of actions (features) activation/deactivation
45 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
46 {
47   Q_OBJECT
48
49  public:
50   /// Constructor
51   /// \param theWorkshop an instance of workshop
52   XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
53   virtual ~XGUI_ActionsMgr();
54
55   /// Actions on operations
56   enum OperationStateActionId {
57     Abort = 0,
58     Accept = 1,
59     AcceptPlus = 2,
60     Help = 3,
61     AbortAll = 4,
62     AcceptAll = 5,
63     Preview = 6
64   };
65
66   /// Add a command in the manager.
67   /// Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
68   /// won't be extracted and should be added manually using the addNestedCommands method.
69   void addCommand(QAction* theCmd);
70
71   /// Sets relation between the command (with given Id) and it's nested actions.
72   void addNestedCommands(const QString& theId, const QStringList& theCommands);
73
74   /// Returns list of nested commands by parent command Id
75   /// \param theId a parent command Id
76   QStringList nestedCommands(const QString& theId) const;
77
78   /// Returns True if the given Id is an Id of nested command
79   /// \param theId an Id to check
80   bool isNested(const QString& theId) const;
81
82   /// Registers shortcut (key sequence) for the command triggering
83   /// \param theKeySequence a key sequence to register
84   QKeySequence registerShortcut(const QKeySequence& theKeySequence);
85
86   /// This is an overloaded function.
87   /// Registers shortcut (key sequence) for the command triggering
88   /// \param theKeySequence - string that contain a key sequence to register
89   QKeySequence registerShortcut(const QString& theKeySequence);
90
91   /// Redefinition of Events_Listener method
92   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
93
94   /// Return property panel's action like ok, cancel, help.
95   /// If there is no such action, it will be created.
96   QAction* operationStateAction(OperationStateActionId theId);
97
98   /// Return an action by the given id, if it was registered in the manager
99   QAction* action(const QString& theId);
100
101   /// Return info (icon, text, etc) about the action by the given id,
102   /// if it was registered in the manager
103   ActionInfo actionInfoById(const QString& theId);
104
105  private:
106   /// Update workbench actions according to OperationMgr state:
107   /// No active operations: all actions but nested are available
108   /// There is active operation: current operation + it's nested
109   /// are enabled, all the rest is disabled. All active commands is checked.
110   void updateCommandsStatus();
111
112   /// Sets all commands checked if it's operation is active.
113   void updateCheckState();
114
115   /// Updates actions according to current selection in the viewer
116   void updateOnViewSelection();
117
118   /// Sets all actions to enabled state.
119   void setAllEnabled();
120
121   /// Sets all nested actions to isEnabled state for the command with given ID.
122   /// If ID is empty - all nested actions will be affected.
123   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
124
125   /// Sets to enabled state all siblings of the given operation and it's parents recursively
126   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
127
128   /// Sets the action with theId to theChecked state.
129   void setActionChecked(const QString& theId, const bool theChecked);
130
131   /// Sets the action with theId to theEnabled state.
132   void setActionEnabled(const QString& theId, const bool theEnabled);
133
134   /// Updates actions according to their "document" tag
135   void updateByDocumentKind();
136
137   /// Asks plugins about their features state, using the Events system
138   void updateByPlugins(FeaturePtr theActiveFeature);
139
140   /// Returns names of nested action for the feature of given operation
141   /// \param theOperation an operation
142   QStringList allNestedCommands(ModuleBase_Operation* theOperation);
143
144  private:
145
146   QMap<QString, QAction*> myActions;
147   QMap<QString, QStringList> myNestedActions;
148   QMap<OperationStateActionId, QAction*> myOperationActions;
149   QList<QKeySequence> myShortcuts;
150
151   XGUI_Workshop* myWorkshop;
152   XGUI_OperationMgr* myOperationMgr;
153
154   friend class XGUI_Workshop;
155 };
156
157 #endif /* XGUI_ActionsMgr_H */
158