Salome HOME
Minimization of activate/deactivate calls.
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetSketchLabel.h
4 // Created:     07 July 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef PartSet_WidgetSketchLabel_H
8 #define PartSet_WidgetSketchLabel_H
9
10 #include "PartSet.h"
11
12 #include <ModuleBase_WidgetValidated.h>
13 #include <ModuleBase_ViewerFilters.h>
14
15 #include <GeomAPI_Pnt.h>
16 #include <GeomAPI_Dir.h>
17 #include <GeomAPI_AISObject.h>
18
19 #include <TopoDS_Shape.hxx>
20
21 class QLabel;
22 class XGUI_OperationMgr;
23 class XGUI_Workshop;
24 class QCheckBox;
25
26 /// the plane edge width
27 #define SKETCH_WIDTH        "4"
28
29 /// face of the square-face displayed for selection of general plane
30 #define PLANE_SIZE          "200"
31
32 /**
33 * \ingroup Modules
34 * A model widget implementation for a label which provides specific behaviour 
35 * for sketcher starting and launching operations
36 */
37 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
38 {
39 Q_OBJECT
40  public:
41   /// Constructor
42   /// \param theParent the parent object
43   /// \param theData the widget configuation. The attribute of the model widget is obtained from
44   /// \param theParentId is Id of a parent of the current attribute
45   PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData,
46                             const std::string& theParentId, bool toShowConstraints);
47
48   virtual ~PartSet_WidgetSketchLabel();
49
50   /// Set the given wrapped value to the current widget
51   /// This value should be processed in the widget according to the needs
52   /// The method is called by the current operation to process the operation preselection.
53   /// It is redefined to do nothing if the plane of the sketch has been already set.
54   /// \param theValues the wrapped selection values
55   /// \param thePosition an index in the list of values, the values should be get from the index
56   virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
57
58   virtual bool restoreValue()
59   {
60     return true;
61   }
62
63   /// Returns list of widget controls
64   /// \return a control list
65   virtual QList<QWidget*> getControls() const;
66
67   /// The methiod called when widget is deactivated
68   virtual void deactivate();
69
70   /// Returns pointer to workshop
71   XGUI_Workshop* workshop() const { return myWorkshop; }
72
73   /// Set pointer to workshop
74   /// \param theWork a pointer to workshop
75   void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
76
77   /// Returns sketcher plane
78   std::shared_ptr<GeomAPI_Pln> plane() const;
79
80   /// This control accepts focus
81   virtual bool focusTo();
82   virtual void setHighlighted(bool) { /*do nothing*/ };
83   virtual void enableFocusProcessing();
84
85   void showConstraints(bool theOn);
86
87 signals:
88   /// Signal on plane selection
89   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
90
91   void showConstraintToggled(bool);
92
93 protected:
94   /// Creates a backup of the current values of the attribute
95   /// It should be realized in the specific widget because of different
96   /// parameters of the current attribute
97   virtual void storeAttributeValue();
98
99   /// Creates a backup of the current values of the attribute
100   /// It should be realized in the specific widget because of different
101   /// parameters of the current attribute
102   /// \param theValid a boolean flag, if restore happens for valid parameters
103   virtual void restoreAttributeValue(const bool theValid);
104
105   /// Fills the attribute with the value of the selected owner
106   /// \param theOwner a selected owner
107   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
108
109   /// Saves the internal parameters to the given feature
110   /// \return True in success
111   virtual bool storeValueCustom() const
112   {
113     return true;
114   }
115
116   /// The methiod called when widget is activated
117   virtual void activateCustom();
118
119  protected:
120   /// Activate or deactivate selection
121   void activateSelection(bool toActivate);
122
123  private slots:
124    /// Slot on change selection
125   void onSelectionChanged();
126
127  private:
128    /// Create preview of planes for sketch plane selection
129    /// \param theOrigin an origin of the plane
130    /// \param theNorm a normal vector of the plane
131    /// \param theRGB a color of plane presentation [r, g, b] array
132   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
133                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
134                                   const int theRGB[3]);
135
136   /// Set sketch plane by shape
137   /// \param theShape a planar face
138   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
139
140   /// Erase preview planes
141   void erasePreviewPlanes();
142
143   /// Show preview planes
144   void showPreviewPlanes();
145
146
147   QLabel* myLabel;
148   QString myText;
149   QString myTooltip;
150
151   XGUI_Workshop* myWorkshop;
152
153   AISObjectPtr myYZPlane;
154   AISObjectPtr myXZPlane;
155   AISObjectPtr myXYPlane;
156   bool myPreviewDisplayed;
157
158   QCheckBox* myShowConstraints;
159 };
160
161 #endif