Salome HOME
Merge branch 'master' into cgt/devCEA
[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_Dir.h>
18
19 #include <TopoDS_Shape.hxx>
20
21 #include <QMap>
22
23 class PartSet_PreviewPlanes;
24
25 class QLabel;
26 class XGUI_OperationMgr;
27 class XGUI_Workshop;
28 class QCheckBox;
29 class QStackedWidget;
30 class QLineEdit;
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
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 toShowConstraints a current show constraints state
47   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
48                       const Config_WidgetAPI* theData,
49                       const QMap<PartSet_Tools::ConstraintVisibleState, 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<std::shared_ptr<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   /// Returns True if the selected presentation can be used for plane definition
78   /// \param thePrs a presentation
79   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
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   /// \param theType a ConstraintVisibleState value
87   /// \param theState a state of the check box
88   void showConstraintToggled(int theType, bool theState);
89
90 protected:
91   /// Creates a backup of the current values of the attribute
92   /// It should be realized in the specific widget because of different
93   /// parameters of the current attribute
94   /// \param theAttribute an attribute to be stored
95   virtual void storeAttributeValue(const AttributePtr& theAttribute);
96
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   /// \param theAttribute an attribute to be restored
101   /// \param theValid a boolean flag, if restore happens for valid parameters
102   virtual void restoreAttributeValue(const AttributePtr& theAttribute,
103                                      const bool theValid);
104
105   /// Fills the attribute with the value of the selected owner
106   /// \param thePrs a selected owner
107   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
108
109   /// Saves the internal parameters to the given feature
110   /// \return True in success
111   virtual bool storeValueCustom()
112   {
113     return true;
114   }
115
116   virtual bool restoreValueCustom()
117   {
118     return true;
119   }
120
121   /// The methiod called when widget is activated
122   virtual void activateCustom();
123
124   /// Block the model flush of update and intialization of attribute
125   /// In additional to curstom realization it blocks initialization for all feature attributes
126   /// as the current attribute is selection but its modification leads to other attributes change
127   /// \param theAttribute an attribute
128   /// \param theToBlock flag whether the model is blocked or unblocked
129   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
130   /// to be used to restore flush state when unblocked
131   /// \param isAttributeSetInitializedBlocked out value if model is blocked
132   /// in value if model is unblocked to be used to restore previous state when unblocked
133   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
134   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
135                               bool& isFlushesActived,
136                               bool& isAttributeSetInitializedBlocked,
137                               bool& isAttributeSendUpdatedBlocked);
138
139   /// Set the given wrapped value to the current widget
140   /// This value should be processed in the widget according to the needs
141   /// The method is called by the current operation to process the operation preselection.
142   /// It is redefined to do nothing if the plane of the sketch has been already set.
143   /// \param theValues the wrapped selection values
144   /// \param theToValidate a validation flag
145   bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
146                             const bool theToValidate);
147
148   /// Erase preview planes, disconnect widget, change the view projection
149   /// \param thePrs a selected presentation
150   void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
151
152   /// Set sketch plane from selected object
153   /// \param theFeature a feature of sketch
154   /// \param thePrs a presentation
155   bool fillSketchPlaneBySelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
156
157  protected:
158   /// Activate or deactivate selection
159   void activateSelection(bool toActivate);
160
161  private slots:
162    /// Slot on change selection
163   void onSelectionChanged();
164
165   /// A slot called on set sketch plane view
166   void onSetPlaneView();
167
168   /// Emits signal about check box state changed with information about ConstraintVisibleState
169   /// \param theOn a flag show constraints or not
170   void onShowConstraint(bool theOn);
171
172  private:
173   /// Set sketch plane by shape
174   /// \param theShape a planar face
175   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
176
177   /// Set sketch plane
178   /// \param thePlane a plane
179   std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
180
181 private:
182   /// class to show/hide preview planes
183   PartSet_PreviewPlanes* myPreviewPlanes;
184
185   QCheckBox* myViewInverted;
186
187   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
188
189   QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
190   QLineEdit* mySizeOfView; ///< Value of square of size of View
191   QStackedWidget* myStackWidget;
192 };
193
194 #endif