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