Salome HOME
Fix for the issue #2401
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.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 PartSet_MenuMgr_H
22 #define PartSet_MenuMgr_H
23
24 #include <ModelAPI_Feature.h>
25 #include <ModelAPI_ResultPart.h>
26
27 #include <QObject>
28 #include <QMap>
29 #include <QString>
30 #include <QList>
31 #include <QColor>
32
33 class ModuleBase_Operation;
34 class PartSet_Module;
35 class QAction;
36 class QMenu;
37
38 /**
39 * \ingroup Modules
40 * A class for management of module specific menu
41 */
42 class PartSet_MenuMgr: public QObject
43 {
44   Q_OBJECT
45 public:
46   /// Constructor
47   /// \param theModule a parent module
48   PartSet_MenuMgr(PartSet_Module* theModule);
49
50
51   /// Returns action according to the given ID
52   /// \param theId an action identifier, it should be uniqued in the bounds of the module
53   QAction* action(const QString& theId) const;
54
55   /// Add menu items for viewer into the actions map
56   /// \param theStdActions a map of standard actions
57   /// \param theParent a parent widget for the
58   /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
59   /// \return true if items are added and there is no necessity to provide standard menu
60   bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
61                      QWidget* theParent,
62                      QMap<int, QAction*>& theMenuActions) const;
63
64   /// Update state of pop-up menu items in viewer
65   /// \param theStdActions - a map of standard actions
66   void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
67
68   /// Activates a PartSet document
69   void activatePartSet() const;
70
71   /// Returns list of granted operation indices
72   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
73
74   /// Activates a Part document
75   void activatePart(ResultPartPtr thePart) const;
76
77 public slots:
78   /// Processes the context menu action click
79   /// \param isChecked a state of toggle if the action is checkable
80   void onAction(bool isChecked);
81
82 private slots:
83
84   /// A slot which is called on selection of menu item coresponding to line with coincedence
85   /// \param theAction an action of the selected item
86   void onLineHighlighted(QAction* theAction);
87
88   /// A slot which is called on hiding Detach menu
89   void onDetachMenuHide();
90
91   /// A slot which is called on selection an Item in Detach menu
92   /// \param theAction an action of the selected item
93   void onLineDetach(QAction* theAction);
94
95   /// A slot called on Part activation command
96   void onActivatePart(bool);
97
98   /// A slot called on PartSet activation command
99   void onActivatePartSet(bool);
100
101   /// A slot called on edit of feature
102   void onEdit(bool);
103
104 protected:
105   /// Redefinition of virtual method
106   /// \param theObj an object
107   /// \param theEvent an event
108   virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
109
110 private:
111   /// Returns true if the current operation is sketch entity create operation
112   /// \param theValue the current auxiliary value
113   /// \return the boolean result
114   bool canSetAuxiliary(bool& theValue) const;
115
116   /// Changes the sketcher entity construction argument value
117   /// \param isChecked if true, the feature is a construction
118   void setAuxiliary(const bool isChecked);
119
120   /// Create all actions for context menus. It is called on creation of module
121   /// Put the created actions into an internal map
122   void createActions();
123
124   /// Add action to the internal map
125   /// \param theId - string ID of the item
126   /// \param theAction - action to add
127   void addAction(const QString& theId, QAction* theAction);
128
129   /// Set color on presentation of result listed in myCoinsideLines
130   /// \param theId object Id in myCoinsideLines list
131   /// \param theColor a color which has to be set
132   /// \param theUpdate update viewer flag
133   /// \return previously defined color on the object
134   QColor setLineColor(int theId, const QColor theColor, bool theUpdate);
135
136   /// Reference to a parent module
137   PartSet_Module* myModule;
138
139   /// the popup menu actions
140   QMap<QString, QAction*> myActions;
141
142   /// List of lines coincided in a one point
143   mutable QList<FeaturePtr> myCoinsideLines;
144
145   /// A Coincedence feature selected by user for detaching
146   mutable FeaturePtr mySelectedFeature;
147
148   /// Id of menu item in Detach menu previously selected
149   int myPrevId;
150
151   /// Original color of highlighted line
152   QColor myColor;
153 };
154
155 #endif