Salome HOME
Issue #2299 Import of edges participating to the result of the sketch for circle...
[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     Help = 2,
65     AbortAll = 3,
66     AcceptAll = 4,
67     Preview = 5
68   };
69
70   //! Add a command in the manager.
71   //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
72   //! won't be extracted and should be added manually using the addNestedCommands method.
73   void addCommand(QAction* theCmd);
74
75   //! Sets relation between the command (with given Id) and it's nested actions.
76   void addNestedCommands(const QString& theId, const QStringList& theCommands);
77
78   //! Returns list of nested commands by parent command Id
79   //! \param theId a parent command Id
80   QStringList nestedCommands(const QString& theId) const;
81
82   /// Returns True if the given Id is an Id of nested command
83   /// \param theId an Id to check
84   bool isNested(const QString& theId) const;
85
86   /// Registers shortcut (key sequence) for the command triggering
87   /// \param theKeySequence a key sequence to register
88   QKeySequence registerShortcut(const QKeySequence& theKeySequence);
89
90   /// This is an overloaded function.
91   /// Registers shortcut (key sequence) for the command triggering
92   /// \param theKeySequence - string that contain a key sequence to register
93   QKeySequence registerShortcut(const QString& theKeySequence);
94
95   //! Redefinition of Events_Listener method
96   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
97
98   //! Return property panel's action like ok, cancel, help.
99   //! If there is no such action, it will be created.
100   QAction* operationStateAction(OperationStateActionId theId);
101
102   /// Return an action by the given id, if it was registered in the manager
103   QAction* action(const QString& theId);
104
105   /// Return info (icon, text, etc) about the action by the given id,
106   /// if it was registered in the manager
107   ActionInfo actionInfoById(const QString& theId);
108
109  private:
110   //! Update workbench actions according to OperationMgr state:
111   //! No active operations: all actions but nested are available
112   //! There is active operation: current operation + it's nested
113   //! are enabled, all the rest is disabled. All active commands is checked.
114   void updateCommandsStatus();
115
116   //! Sets all commands checked if it's operation is active.
117   void updateCheckState();
118
119   //! Updates actions according to current selection in the viewer
120   void updateOnViewSelection();
121
122   //! Sets all actions to enabled state.
123   void setAllEnabled();
124
125   //! Sets all nested actions to isEnabled state for the command with given ID.
126   //! If ID is empty - all nested actions will be affected.
127   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
128
129   //! Sets to enabled state all siblings of the given operation and it's parents recursively
130   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
131
132   //! Sets the action with theId to theChecked state.
133   void setActionChecked(const QString& theId, const bool theChecked);
134
135   //! Sets the action with theId to theEnabled state.
136   void setActionEnabled(const QString& theId, const bool theEnabled);
137
138   //! Updates actions according to their "document" tag
139   void updateByDocumentKind();
140
141   //! Asks plugins about their features state, using the Events system
142   void updateByPlugins(FeaturePtr theActiveFeature);
143
144   QStringList allNestedCommands(ModuleBase_Operation* theOperation);
145
146  private:
147
148   QMap<QString, QAction*> myActions;
149   QMap<QString, QStringList> myNestedActions;
150   QMap<OperationStateActionId, QAction*> myOperationActions;
151   QList<QKeySequence> myShortcuts;
152
153   XGUI_Workshop* myWorkshop;
154   XGUI_OperationMgr* myOperationMgr;
155
156   friend class XGUI_Workshop;
157 };
158
159 #endif /* XGUI_ACTIONSMGR_H_ */
160