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