Salome HOME
070a43acce98997dad5dd79affaeb9b2a17377bf
[modules/shaper.git] / src / PartSet / PartSet_MenuMgr.h
1 // Copyright (C) 2014-2023  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   /// Activates all not loaded parts
104   void onActivateAllParts();
105
106 protected:
107   /// Redefinition of virtual method
108   /// \param theObj an object
109   /// \param theEvent an event
110   virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
111
112 private:
113   /// Returns true if the current operation is sketch entity create operation
114   /// \param theValue the current auxiliary value
115   /// \return the boolean result
116   bool canSetAuxiliary(bool& theValue) const;
117
118   /// Changes the sketcher entity construction argument value
119   /// \param isChecked if true, the feature is a construction
120   void setAuxiliary(const bool isChecked);
121
122   /// Create all actions for context menus. It is called on creation of module
123   /// Put the created actions into an internal map
124   void createActions();
125
126   /// Add action to the internal map
127   /// \param theId - string ID of the item
128   /// \param theAction - action to add
129   void addAction(const QString& theId, QAction* theAction);
130
131   /// Set color on presentation of result listed in myCoinsideLines
132   /// \param theId object Id in myCoinsideLines list
133   /// \param theColor a color which has to be set
134   /// \param theUpdate update viewer flag
135   /// \return previously defined color on the object
136   QColor setLineColor(int theId, const QColor theColor, bool theUpdate);
137
138   /// Reference to a parent module
139   PartSet_Module* myModule;
140
141   /// the popup menu actions
142   QMap<QString, QAction*> myActions;
143
144   /// List of lines coincided in a one point
145   mutable QList<FeaturePtr> myCoinsideLines;
146
147   /// A Coincedence feature selected by user for detaching
148   mutable FeaturePtr mySelectedFeature;
149
150   /// Id of menu item in Detach menu previously selected
151   int myPrevId;
152
153   /// Original color of highlighted line
154   QColor myColor;
155 };
156
157 #endif