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