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