Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: selection processing...
[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 "PartSet_Tools.h"
13
14 #include <ModuleBase_WidgetValidated.h>
15 #include <ModuleBase_ViewerFilters.h>
16
17 #include <GeomAPI_Pnt.h>
18 #include <GeomAPI_Dir.h>
19 #include <GeomAPI_AISObject.h>
20
21 #include <TopoDS_Shape.hxx>
22
23 #include <QMap>
24
25 class QLabel;
26 class XGUI_OperationMgr;
27 class XGUI_Workshop;
28 class QCheckBox;
29 class QStackedWidget;
30
31 /// the plane edge width
32 #define SKETCH_WIDTH        "4"
33
34 /// face of the square-face displayed for selection of general plane
35 #define PLANE_SIZE          "200"
36
37 /**
38 * \ingroup Modules
39 * A model widget implementation for a label which provides specific behaviour 
40 * for sketcher starting and launching operations
41 */
42 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
43 {
44 Q_OBJECT
45
46 public:
47   /// Constructor
48   /// \param theParent the parent object
49   /// \param theWorkshop a reference to workshop
50   /// \param theData the widget configuation. The attribute of the model widget is obtained from
51   /// \param toShowConstraints a current show constraints state
52   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
53                       const Config_WidgetAPI* theData,
54                       const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
55
56   virtual ~PartSet_WidgetSketchLabel();
57
58   /// Set the given wrapped value to the current widget
59   /// This value should be processed in the widget according to the needs
60   /// The method is called by the current operation to process the operation preselection.
61   /// It is redefined to do nothing if the plane of the sketch has been already set.
62   /// \param theValues the wrapped selection values
63   /// \param theToValidate a validation flag
64   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
65                             const bool theToValidate);
66
67   /// Returns list of widget controls
68   /// \return a control list
69   virtual QList<QWidget*> getControls() const;
70
71   /// The methiod called when widget is deactivated
72   virtual void deactivate();
73
74   /// Returns sketcher plane
75   std::shared_ptr<GeomAPI_Pln> plane() const;
76
77   /// This control accepts focus
78   virtual bool focusTo();
79   virtual void setHighlighted(bool) { /*do nothing*/ };
80   virtual void enableFocusProcessing();
81
82   static bool canFillSketch(const ModuleBase_ViewerPrs& thePrs);
83
84   static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
85                                          const ModuleBase_ViewerPrs& thePrs);
86
87 signals:
88   /// Signal on plane selection
89   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
90
91   /// A show constraint toggled signal
92   /// \param theType a ConstraintVisibleState value
93   /// \param theState a state of the check box
94   void showConstraintToggled(int theType, bool theState);
95
96 protected:
97   /// Creates a backup of the current values of the attribute
98   /// It should be realized in the specific widget because of different
99   /// parameters of the current attribute
100   virtual void storeAttributeValue();
101
102   /// Creates a backup of the current values of the attribute
103   /// It should be realized in the specific widget because of different
104   /// parameters of the current attribute
105   /// \param theValid a boolean flag, if restore happens for valid parameters
106   virtual void restoreAttributeValue(const bool theValid);
107
108   /// Fills the attribute with the value of the selected owner
109   /// \param thePrs a selected owner
110   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
111
112   /// Saves the internal parameters to the given feature
113   /// \return True in success
114   virtual bool storeValueCustom() const
115   {
116     return true;
117   }
118
119   virtual bool restoreValueCustom()
120   {
121     return true;
122   }
123
124   /// The methiod called when widget is activated
125   virtual void activateCustom();
126
127   /// Block the model flush of update and intialization of attribute
128   /// In additional to curstom realization it blocks initialization for all feature attributes
129   /// as the current attribute is selection but its modification leads to other attributes change
130   /// \param theToBlock flag whether the model is blocked or unblocked
131   /// \param isActive out value if model is blocked, in value if model is unblocked
132   /// to be used to restore flush state when unblocked
133   /// \param isAttributeSetInitializedBlocked out value if model is blocked
134   /// in value if model is unblocked to be used to restore previous state when unblocked
135   virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
136                               bool& isAttributeSetInitializedBlocked);
137
138   /// Erase preview planes, disconnect widget, change the view projection
139   /// \param thePrs a selected presentation
140   void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
141
142  protected:
143   /// Activate or deactivate selection
144   void activateSelection(bool toActivate);
145
146  private slots:
147    /// Slot on change selection
148   void onSelectionChanged();
149
150   /// A slot called on set sketch plane view
151   void onSetPlaneView();
152
153   /// Emits signal about check box state changed with information about ConstraintVisibleState
154   /// \param theOn a flag show constraints or not
155   void onShowConstraint(bool theOn);
156
157  private:
158    /// Create preview of planes for sketch plane selection
159    /// \param theOrigin an origin of the plane
160    /// \param theNorm a normal vector of the plane
161    /// \param theRGB a color of plane presentation [r, g, b] array
162   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
163                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
164                                   const int theRGB[3]);
165
166   //! Returns workshop
167   XGUI_Workshop* workshop() const;
168
169   /// Set sketch plane by shape
170   /// \param theShape a planar face
171   static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
172                                                      const TopoDS_Shape& theShape);
173
174   /// Erase preview planes
175   void erasePreviewPlanes();
176
177   /// Show preview planes
178   void showPreviewPlanes();
179
180
181   AISObjectPtr myYZPlane;
182   AISObjectPtr myXZPlane;
183   AISObjectPtr myXYPlane;
184   bool myPreviewDisplayed;
185
186   QCheckBox* myViewInverted;
187
188   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
189
190   QStackedWidget* myStackWidget;
191 };
192
193 #endif