Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.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
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);
47
48   virtual ~PartSet_WidgetSketchLabel();
49
50   virtual bool restoreValue()
51   {
52     return true;
53   }
54
55   /// Returns list of widget controls
56   /// \return a control list
57   virtual QList<QWidget*> getControls() const;
58
59   /// The methiod called when widget is deactivated
60   virtual void deactivate();
61
62   /// Returns pointer to workshop
63   XGUI_Workshop* workshop() const { return myWorkshop; }
64
65   /// Set pointer to workshop
66   /// \param theWork a pointer to workshop
67   void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
68
69   /// Returns sketcher plane
70   std::shared_ptr<GeomAPI_Pln> plane() const;
71
72   /// This control accepts focus
73   virtual bool focusTo();
74   virtual void setHighlighted(bool) { /*do nothing*/ };
75   virtual void enableFocusProcessing();
76
77 signals:
78   /// Signal on plane selection
79   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
80
81 protected:
82   /// Creates a backup of the current values of the attribute
83   /// It should be realized in the specific widget because of different
84   /// parameters of the current attribute
85   virtual void storeAttributeValue();
86
87   /// Creates a backup of the current values of the attribute
88   /// It should be realized in the specific widget because of different
89   /// parameters of the current attribute
90   /// \param theValid a boolean flag, if restore happens for valid parameters
91   virtual void restoreAttributeValue(const bool theValid);
92
93   /// Fills the attribute with the value of the selected owner
94   /// \param theOwner a selected owner
95   virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
96
97   /// Saves the internal parameters to the given feature
98   /// \return True in success
99   virtual bool storeValueCustom() const
100   {
101     return true;
102   }
103
104   /// The methiod called when widget is activated
105   virtual void activateCustom();
106
107  private slots:
108    /// Slot on plane selection
109   void onPlaneSelected();
110
111   /// Set sketch specific mode of selection
112   void setSketchingMode();
113
114  private:
115    /// Create preview of planes for sketch plane selection
116    /// \param theOrigin an origin of the plane
117    /// \param theNorm a normal vector of the plane
118    /// \param theRGB a color of plane presentation [r, g, b] array
119   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
120                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
121                                   const int theRGB[3]);
122
123   /// Set sketch plane by shape
124   /// \param theShape a planar face
125   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
126
127   /// Erase preview planes
128   void erasePreviewPlanes();
129
130   /// Show preview planes
131   void showPreviewPlanes();
132
133
134   QLabel* myLabel;
135   QString myText;
136   QString myTooltip;
137
138   XGUI_Workshop* myWorkshop;
139
140   AISObjectPtr myYZPlane;
141   AISObjectPtr myXZPlane;
142   AISObjectPtr myXYPlane;
143   bool myPreviewDisplayed;
144
145   QTimer* mySelectionTimer;
146 };
147
148 #endif