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