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