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_ModelWidget.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 <StdSelect_FaceFilter.hxx>
20 #include <TopoDS_Shape.hxx>
21
22 class QLabel;
23 class QTimer;
24 class XGUI_OperationMgr;
25 class XGUI_Workshop;
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_ModelWidget
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);
48
49   virtual ~PartSet_WidgetSketchLabel();
50
51   virtual bool storeValue() const
52   {
53     return true;
54   }
55
56   virtual bool restoreValue()
57   {
58     return true;
59   }
60
61   /// Returns list of widget controls
62   /// \return a control list
63   virtual QList<QWidget*> getControls() const;
64
65   QWidget* getControl() 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 signals:
81   /// Signal on plane selection
82   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
83
84 protected:
85   /// The methiod called when widget is activated
86   virtual void activateCustom();
87
88  private slots:
89    /// Slot on plane selection
90   void onPlaneSelected();
91
92   /// Set sketch specific mode of selection
93   void setSketchingMode();
94
95  private:
96    /// Create preview of planes for sketch plane selection
97    /// \param theOrigin an origin of the plane
98    /// \param theNorm a normal vector of the plane
99    /// \param theRGB a color of plane presentation [r, g, b] array
100   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
101                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
102                                   const int theRGB[3]);
103
104   /// Set sketch plane by shape
105   /// \param theShape a planar face
106   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
107
108   /// Erase preview planes
109   void erasePreviewPlanes();
110
111   /// Show preview planes
112   void showPreviewPlanes();
113
114
115   QLabel* myLabel;
116   QString myText;
117   QString myTooltip;
118
119   XGUI_Workshop* myWorkshop;
120
121   AISObjectPtr myYZPlane;
122   AISObjectPtr myXZPlane;
123   AISObjectPtr myXYPlane;
124   bool myPreviewDisplayed;
125
126   Handle(StdSelect_FaceFilter) myFaceFilter;
127
128   QTimer* mySelectionTimer;
129 };
130
131 #endif