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