Salome HOME
Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules...
[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 XGUI_OperationMgr;
23 class XGUI_Workshop;
24 class QCheckBox;
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 theWorkshop a reference to workshop
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   /// \param toShowConstraints a current show constraints state
47   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
48                             const Config_WidgetAPI* theData,
49                             const std::string& theParentId, bool toShowConstraints);
50
51   virtual ~PartSet_WidgetSketchLabel();
52
53   /// Set the given wrapped value to the current widget
54   /// This value should be processed in the widget according to the needs
55   /// The method is called by the current operation to process the operation preselection.
56   /// It is redefined to do nothing if the plane of the sketch has been already set.
57   /// \param theValues the wrapped selection values
58   /// \param theToValidate a validation flag
59   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
60                             const bool theToValidate);
61
62   /// Returns list of widget controls
63   /// \return a control list
64   virtual QList<QWidget*> getControls() const;
65
66   /// The methiod called when widget is deactivated
67   virtual void deactivate();
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   /// Set show constraints state
78   /// \param theOn a flag show constraints or not
79   void showConstraints(bool theOn);
80
81 signals:
82   /// Signal on plane selection
83   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
84
85   /// A show constraint toggled signal
86   void showConstraintToggled(bool);
87
88 protected:
89   /// Creates a backup of the current values of the attribute
90   /// It should be realized in the specific widget because of different
91   /// parameters of the current attribute
92   virtual void storeAttributeValue();
93
94   /// Creates a backup of the current values of the attribute
95   /// It should be realized in the specific widget because of different
96   /// parameters of the current attribute
97   /// \param theValid a boolean flag, if restore happens for valid parameters
98   virtual void restoreAttributeValue(const bool theValid);
99
100   /// Fills the attribute with the value of the selected owner
101   /// \param thePrs a selected owner
102   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
103
104   /// Saves the internal parameters to the given feature
105   /// \return True in success
106   virtual bool storeValueCustom() const
107   {
108     return true;
109   }
110
111   virtual bool restoreValueCustom()
112   {
113     return true;
114   }
115
116   /// The methiod called when widget is activated
117   virtual void activateCustom();
118
119   /// Erase preview planes, disconnect widget, change the view projection
120   /// \param thePrs a selected presentation
121   void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
122
123  protected:
124   /// Activate or deactivate selection
125   void activateSelection(bool toActivate);
126
127  private slots:
128    /// Slot on change selection
129   void onSelectionChanged();
130
131  private:
132    /// Create preview of planes for sketch plane selection
133    /// \param theOrigin an origin of the plane
134    /// \param theNorm a normal vector of the plane
135    /// \param theRGB a color of plane presentation [r, g, b] array
136   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
137                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
138                                   const int theRGB[3]);
139
140   //! Returns workshop
141   XGUI_Workshop* workshop() const;
142
143   /// Set sketch plane by shape
144   /// \param theShape a planar face
145   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
146
147   /// Erase preview planes
148   void erasePreviewPlanes();
149
150   /// Show preview planes
151   void showPreviewPlanes();
152
153
154   QLabel* myLabel;
155   QString myText;
156   QString myTooltip;
157
158   AISObjectPtr myYZPlane;
159   AISObjectPtr myXZPlane;
160   AISObjectPtr myXYPlane;
161   bool myPreviewDisplayed;
162
163   QCheckBox* myShowConstraints;
164 };
165
166 #endif