Salome HOME
ModuleBase_ViewerPrs is wrapped into shared_ptr.
[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   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
77
78   static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
79                                          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() const
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 theToBlock flag whether the model is blocked or unblocked
128   /// \param isActive out value if model is blocked, in value if model is unblocked
129   /// to be used to restore flush state when unblocked
130   /// \param isAttributeSetInitializedBlocked out value if model is blocked
131   /// in value if model is unblocked to be used to restore previous state when unblocked
132   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
133                               bool& isFlushesActived,
134                               bool& isAttributeSetInitializedBlocked);
135
136   /// Set the given wrapped value to the current widget
137   /// This value should be processed in the widget according to the needs
138   /// The method is called by the current operation to process the operation preselection.
139   /// It is redefined to do nothing if the plane of the sketch has been already set.
140   /// \param theValues the wrapped selection values
141   /// \param theToValidate a validation flag
142   bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
143                             const bool theToValidate);
144
145   /// Erase preview planes, disconnect widget, change the view projection
146   /// \param thePrs a selected presentation
147   void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
148
149  protected:
150   /// Activate or deactivate selection
151   void activateSelection(bool toActivate);
152
153  private slots:
154    /// Slot on change selection
155   void onSelectionChanged();
156
157   /// A slot called on set sketch plane view
158   void onSetPlaneView();
159
160   /// Emits signal about check box state changed with information about ConstraintVisibleState
161   /// \param theOn a flag show constraints or not
162   void onShowConstraint(bool theOn);
163
164  private:
165   /// Set sketch plane by shape
166   /// \param theShape a planar face
167   static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
168                                                      const TopoDS_Shape& theShape);
169
170
171 private:
172   /// class to show/hide preview planes
173   PartSet_PreviewPlanes* myPreviewPlanes;
174
175   QCheckBox* myViewInverted;
176
177   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
178
179   QStackedWidget* myStackWidget;
180 };
181
182 #endif