Salome HOME
Merge branch 'Dev_1.1.1' of newgeom:newgeom into Dev_1.2.0
[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 QTimer;
23 class XGUI_OperationMgr;
24 class XGUI_Workshop;
25 class QCheckBox;
26
27 /// the plane edge width
28 #define SKETCH_WIDTH        "4"
29
30 /// face of the square-face displayed for selection of general plane
31 #define PLANE_SIZE          "200"
32
33 /**
34 * \ingroup Modules
35 * A model widget implementation for a label which provides specific behaviour 
36 * for sketcher starting and launching operations
37 */
38 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
39 {
40 Q_OBJECT
41  public:
42   /// Constructor
43   /// \param theParent the parent object
44   /// \param theData the widget configuation. The attribute of the model widget is obtained from
45   /// \param theParentId is Id of a parent of the current attribute
46   PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData,
47                             const std::string& theParentId, bool toShowConstraints);
48
49   virtual ~PartSet_WidgetSketchLabel();
50
51   /// Set the given wrapped value to the current widget
52   /// This value should be processed in the widget according to the needs
53   /// The method is called by the current operation to process the operation preselection.
54   /// It is redefined to do nothing if the plane of the sketch has been already set.
55   /// \param theValues the wrapped selection values
56   /// \param thePosition an index in the list of values, the values should be get from the index
57   virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
58
59   virtual bool restoreValue()
60   {
61     return true;
62   }
63
64   /// Returns list of widget controls
65   /// \return a control list
66   virtual QList<QWidget*> getControls() const;
67
68   /// The methiod called when widget is deactivated
69   virtual void deactivate();
70
71   /// Returns pointer to workshop
72   XGUI_Workshop* workshop() const { return myWorkshop; }
73
74   /// Set pointer to workshop
75   /// \param theWork a pointer to workshop
76   void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
77
78   /// Returns sketcher plane
79   std::shared_ptr<GeomAPI_Pln> plane() const;
80
81   /// This control accepts focus
82   virtual bool focusTo();
83   virtual void setHighlighted(bool) { /*do nothing*/ };
84   virtual void enableFocusProcessing();
85
86   void showConstraints(bool theOn);
87
88 signals:
89   /// Signal on plane selection
90   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
91
92   void showConstraintToggled(bool);
93
94 protected:
95   /// Creates a backup of the current values of the attribute
96   /// It should be realized in the specific widget because of different
97   /// parameters of the current attribute
98   virtual void storeAttributeValue();
99
100   /// Creates a backup of the current values of the attribute
101   /// It should be realized in the specific widget because of different
102   /// parameters of the current attribute
103   /// \param theValid a boolean flag, if restore happens for valid parameters
104   virtual void restoreAttributeValue(const bool theValid);
105
106   /// Fills the attribute with the value of the selected owner
107   /// \param theOwner a selected owner
108   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
109
110   /// Saves the internal parameters to the given feature
111   /// \return True in success
112   virtual bool storeValueCustom() const
113   {
114     return true;
115   }
116
117   /// The methiod called when widget is activated
118   virtual void activateCustom();
119
120  private slots:
121    /// Slot on change selection
122   void onSelectionChanged();
123
124   /// Set sketch specific mode of selection
125   //void setSketchingMode();
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   //QTimer* mySelectionTimer;
159
160   QCheckBox* myShowConstraints;
161 };
162
163 #endif