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