Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: preview planes visual...
[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<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 ModuleBase_ViewerPrs& thePrs);
77
78   static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
79                                          const 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   virtual void storeAttributeValue();
95
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 theValid a boolean flag, if restore happens for valid parameters
100   virtual void restoreAttributeValue(const bool theValid);
101
102   /// Fills the attribute with the value of the selected owner
103   /// \param thePrs a selected owner
104   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
105
106   /// Saves the internal parameters to the given feature
107   /// \return True in success
108   virtual bool storeValueCustom() const
109   {
110     return true;
111   }
112
113   virtual bool restoreValueCustom()
114   {
115     return true;
116   }
117
118   /// The methiod called when widget is activated
119   virtual void activateCustom();
120
121   /// Block the model flush of update and intialization of attribute
122   /// In additional to curstom realization it blocks initialization for all feature attributes
123   /// as the current attribute is selection but its modification leads to other attributes change
124   /// \param theToBlock flag whether the model is blocked or unblocked
125   /// \param isActive out value if model is blocked, in value if model is unblocked
126   /// to be used to restore flush state when unblocked
127   /// \param isAttributeSetInitializedBlocked out value if model is blocked
128   /// in value if model is unblocked to be used to restore previous state when unblocked
129   virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
130                               bool& isAttributeSetInitializedBlocked);
131
132   /// Erase preview planes, disconnect widget, change the view projection
133   /// \param thePrs a selected presentation
134   void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
135
136  protected:
137   /// Activate or deactivate selection
138   void activateSelection(bool toActivate);
139
140  private slots:
141    /// Slot on change selection
142   void onSelectionChanged();
143
144   /// A slot called on set sketch plane view
145   void onSetPlaneView();
146
147   /// Emits signal about check box state changed with information about ConstraintVisibleState
148   /// \param theOn a flag show constraints or not
149   void onShowConstraint(bool theOn);
150
151  private:
152   /// Set sketch plane by shape
153   /// \param theShape a planar face
154   static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
155                                                      const TopoDS_Shape& theShape);
156
157
158 private:
159   /// class to show/hide preview planes
160   PartSet_PreviewPlanes* myPreviewPlanes;
161
162   QCheckBox* myViewInverted;
163
164   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
165
166   QStackedWidget* myStackWidget;
167 };
168
169 #endif