Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom 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   /// \param isBackup a boolean flag, if true, store values from the attribute
86   /// to backup, otherwise set the backed up values to the attribute
87   virtual void backupAttributeValue(const bool isBackup);
88
89   /// Fills the attribute with the value of the selected owner
90   /// \param theOwner a selected owner
91   virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
92
93   /// Saves the internal parameters to the given feature
94   /// \return True in success
95   virtual bool storeValueCustom() const
96   {
97     return true;
98   }
99
100   /// The methiod called when widget is activated
101   virtual void activateCustom();
102
103  private slots:
104    /// Slot on plane selection
105   void onPlaneSelected();
106
107   /// Set sketch specific mode of selection
108   void setSketchingMode();
109
110  private:
111    /// Create preview of planes for sketch plane selection
112    /// \param theOrigin an origin of the plane
113    /// \param theNorm a normal vector of the plane
114    /// \param theRGB a color of plane presentation [r, g, b] array
115   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
116                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
117                                   const int theRGB[3]);
118
119   /// Set sketch plane by shape
120   /// \param theShape a planar face
121   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
122
123   /// Erase preview planes
124   void erasePreviewPlanes();
125
126   /// Show preview planes
127   void showPreviewPlanes();
128
129
130   QLabel* myLabel;
131   QString myText;
132   QString myTooltip;
133
134   XGUI_Workshop* myWorkshop;
135
136   AISObjectPtr myYZPlane;
137   AISObjectPtr myXZPlane;
138   AISObjectPtr myXYPlane;
139   bool myPreviewDisplayed;
140
141   QTimer* mySelectionTimer;
142 };
143
144 #endif