Salome HOME
526207a8a3dd1a6574b1063569422991e617296e
[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
31 /**
32 * \ingroup Modules
33 * A model widget implementation for a label which provides specific behaviour 
34 * for sketcher starting and launching operations
35 */
36 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
37 {
38 Q_OBJECT
39
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 toShowConstraints a current show constraints state
46   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
47                       const Config_WidgetAPI* theData,
48                       const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
49
50   virtual ~PartSet_WidgetSketchLabel();
51
52   /// Set the given wrapped value to the current widget
53   /// This value should be processed in the widget according to the needs
54   /// The method is called by the current operation to process the operation preselection.
55   /// It is redefined to do nothing if the plane of the sketch has been already set.
56   /// \param theValues the wrapped selection values
57   /// \param theToValidate a validation flag
58   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
59                             const bool theToValidate);
60
61   /// Returns list of widget controls
62   /// \return a control list
63   virtual QList<QWidget*> getControls() const;
64
65   /// The methiod called when widget is deactivated
66   virtual void deactivate();
67
68   /// Returns sketcher plane
69   std::shared_ptr<GeomAPI_Pln> plane() const;
70
71   /// This control accepts focus
72   virtual bool focusTo();
73   virtual void setHighlighted(bool) { /*do nothing*/ };
74   virtual void enableFocusProcessing();
75
76   /// Returns True if the selected presentation can be used for plane definition
77   /// \param thePrs a presentation
78   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
79
80   /// Set sketch plane from selected object
81   /// \param theFeature a feature of sketch
82   /// \param thePrs a presentation
83   static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
84                                          const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
85
86 signals:
87   /// Signal on plane selection
88   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
89
90   /// A show constraint toggled signal
91   /// \param theType a ConstraintVisibleState value
92   /// \param theState a state of the check box
93   void showConstraintToggled(int theType, bool theState);
94
95 protected:
96   /// Creates a backup of the current values of the attribute
97   /// It should be realized in the specific widget because of different
98   /// parameters of the current attribute
99   /// \param theAttribute an attribute to be stored
100   virtual void storeAttributeValue(const AttributePtr& theAttribute);
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 theAttribute an attribute to be restored
106   /// \param theValid a boolean flag, if restore happens for valid parameters
107   virtual void restoreAttributeValue(const AttributePtr& theAttribute,
108                                      const bool theValid);
109
110   /// Fills the attribute with the value of the selected owner
111   /// \param thePrs a selected owner
112   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
113
114   /// Saves the internal parameters to the given feature
115   /// \return True in success
116   virtual bool storeValueCustom()
117   {
118     return true;
119   }
120
121   virtual bool restoreValueCustom()
122   {
123     return true;
124   }
125
126   /// The methiod called when widget is activated
127   virtual void activateCustom();
128
129   /// Block the model flush of update and intialization of attribute
130   /// In additional to curstom realization it blocks initialization for all feature attributes
131   /// as the current attribute is selection but its modification leads to other attributes change
132   /// \param theAttribute an attribute
133   /// \param theToBlock flag whether the model is blocked or unblocked
134   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
135   /// to be used to restore flush state when unblocked
136   /// \param isAttributeSetInitializedBlocked out value if model is blocked
137   /// in value if model is unblocked to be used to restore previous state when unblocked
138   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
139                               bool& isFlushesActived,
140                               bool& isAttributeSetInitializedBlocked);
141
142   /// Set the given wrapped value to the current widget
143   /// This value should be processed in the widget according to the needs
144   /// The method is called by the current operation to process the operation preselection.
145   /// It is redefined to do nothing if the plane of the sketch has been already set.
146   /// \param theValues the wrapped selection values
147   /// \param theToValidate a validation flag
148   bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
149                             const bool theToValidate);
150
151   /// Erase preview planes, disconnect widget, change the view projection
152   /// \param thePrs a selected presentation
153   void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
154
155  protected:
156   /// Activate or deactivate selection
157   void activateSelection(bool toActivate);
158
159  private slots:
160    /// Slot on change selection
161   void onSelectionChanged();
162
163   /// A slot called on set sketch plane view
164   void onSetPlaneView();
165
166   /// Emits signal about check box state changed with information about ConstraintVisibleState
167   /// \param theOn a flag show constraints or not
168   void onShowConstraint(bool theOn);
169
170  private:
171   /// Set sketch plane by shape
172   /// \param theShape a planar face
173   static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
174                                                      const TopoDS_Shape& theShape);
175
176
177 private:
178   /// class to show/hide preview planes
179   PartSet_PreviewPlanes* myPreviewPlanes;
180
181   QCheckBox* myViewInverted;
182
183   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
184
185   QStackedWidget* myStackWidget;
186 };
187
188 #endif