Salome HOME
Issue #18905(tuleap): Restore old plane of sketcher if user cancels plane change
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef PartSet_WidgetSketchLabel_H
21 #define PartSet_WidgetSketchLabel_H
22
23 #include "PartSet.h"
24
25 #include "PartSet_Tools.h"
26
27 #include <ModuleBase_WidgetValidated.h>
28 #include <ModuleBase_ViewerFilters.h>
29
30 #include <GeomAPI_Dir.h>
31
32 #include <TopoDS_Shape.hxx>
33
34 #include <QStackedWidget>
35 #include <QMap>
36
37 class PartSet_PreviewPlanes;
38
39 class QLabel;
40 class XGUI_OperationMgr;
41 class XGUI_Workshop;
42 class QCheckBox;
43 class QStackedWidget;
44 class QLineEdit;
45 class QPushButton;
46 class QDialog;
47
48 /**
49 * \ingroup Modules
50 * A model widget implementation for a label which provides specific behaviour 
51 * for sketcher starting and launching operations
52 */
53 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
54 {
55 Q_OBJECT
56
57 public:
58   /// Constructor
59   /// \param theParent the parent object
60   /// \param theWorkshop a reference to workshop
61   /// \param theData the widget configuation. The attribute of the model widget is obtained from
62   /// \param toShowConstraints a current show constraints state
63   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
64                       const Config_WidgetAPI* theData,
65                       const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
66
67   virtual ~PartSet_WidgetSketchLabel();
68
69   /// Set the given wrapped value to the current widget
70   /// This value should be processed in the widget according to the needs
71   /// The method is called by the current operation to process the operation preselection.
72   /// It is redefined to do nothing if the plane of the sketch has been already set.
73   /// \param theValues the wrapped selection values
74   /// \param theToValidate a validation flag
75   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
76                             const bool theToValidate);
77
78   /// Fills given container with selection modes if the widget has it
79   /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
80   /// \param theModes [out] a container of modes
81   virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
82
83   /// Using widget selection filter only if plane is not defined.
84   /// \param [out] theModuleSelectionFilters module additional modes, -1 means all default modes
85   /// \param [out] selection filters
86   virtual void selectionFilters(QIntList& theModuleSelectionFilters,
87                                 SelectMgr_ListOfFilter& theSelectionFilters);
88
89   /// Returns list of widget controls
90   /// \return a control list
91   virtual QList<QWidget*> getControls() const;
92
93   /// The methiod called when widget is deactivated
94   virtual void deactivate();
95
96   /// The method called if widget should be activated always
97   virtual bool needToBeActivated() { return true; }
98
99   /// Returns sketcher plane
100   std::shared_ptr<GeomAPI_Pln> plane() const;
101
102   /// This control accepts focus
103   virtual bool focusTo();
104   virtual void setHighlighted(bool) { /*do nothing*/ };
105   virtual void enableFocusProcessing();
106
107   /// Set current state of show free points
108   /// \param theState a state of the corresponded check box
109   void setShowPointsState(bool theState);
110
111   /// Returns True if the selected presentation can be used for plane definition
112   /// \param thePrs a presentation
113   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
114
115   /// If widgets has several panels then this method has to show a page which contains information
116   /// for current feature. By default does nothing
117   virtual void showInformativePage() {
118     if (myStackWidget) myStackWidget->setCurrentIndex(1);
119   }
120
121 signals:
122   /// Signal on plane selection
123   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
124
125   /// A show constraint toggled signal
126   /// \param theType a ConstraintVisibleState value
127   /// \param theState a state of the check box
128   void showConstraintToggled(int theType, bool theState);
129
130   /// The signal is emitted when user checks "Show free points" button
131   /// \param toShow a state of the check box
132   void showFreePoints(bool toShow);
133
134   /// The signal is emitted when user checks "Automatic constraints" button
135   /// \param isOn a state of the check box
136   void autoConstraints(bool isOn);
137
138 protected:
139   /// Creates a backup of the current values of the attribute
140   /// It should be realized in the specific widget because of different
141   /// parameters of the current attribute
142   /// \param theAttribute an attribute to be stored
143   virtual void storeAttributeValue(const AttributePtr& theAttribute);
144
145   /// Creates a backup of the current values of the attribute
146   /// It should be realized in the specific widget because of different
147   /// parameters of the current attribute
148   /// \param theAttribute an attribute to be restored
149   /// \param theValid a boolean flag, if restore happens for valid parameters
150   virtual void restoreAttributeValue(const AttributePtr& theAttribute,
151                                      const bool theValid);
152
153   /// Fills the attribute with the value of the selected owner
154   /// \param thePrs a selected owner
155   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
156
157   /// Saves the internal parameters to the given feature
158   /// \return True in success
159   virtual bool storeValueCustom()
160   {
161     return true;
162   }
163
164   virtual bool restoreValueCustom();
165
166   /// The methiod called when widget is activated
167   virtual void activateCustom();
168
169   /// Block the model flush of update and intialization of attribute
170   /// In additional to curstom realization it blocks initialization for all feature attributes
171   /// as the current attribute is selection but its modification leads to other attributes change
172   /// \param theAttribute an attribute
173   /// \param theToBlock flag whether the model is blocked or unblocked
174   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
175   /// to be used to restore flush state when unblocked
176   /// \param isAttributeSetInitializedBlocked out value if model is blocked
177   /// in value if model is unblocked to be used to restore previous state when unblocked
178   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
179   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
180                               bool& isFlushesActived,
181                               bool& isAttributeSetInitializedBlocked,
182                               bool& isAttributeSendUpdatedBlocked);
183
184   /// Returns true if envent is processed.
185   virtual bool processSelection();
186
187   /// Set the given wrapped value to the current widget
188   /// This value should be processed in the widget according to the needs
189   /// The method is called by the current operation to process the operation preselection.
190   /// It is redefined to do nothing if the plane of the sketch has been already set.
191   /// \param theValues the wrapped selection values
192   /// \param theToValidate a validation flag
193   bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
194                             const bool theToValidate);
195
196   /// Erase preview planes, disconnect widget, change the view projection
197   /// \param thePrs a selected presentation
198   void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
199
200   /// Set sketch plane from selected object
201   /// \param theFeature a feature of sketch
202   /// \param thePrs a presentation
203   bool fillSketchPlaneBySelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
204
205
206   virtual void showEvent(QShowEvent* theEvent);
207
208 private slots:
209   /// A slot called on set sketch plane view
210   void onSetPlaneView();
211
212   /// Emits signal about check box state changed with information about ConstraintVisibleState
213   /// \param theOn a flag show constraints or not
214   void onShowConstraint(bool theOn);
215
216   void onChangePlane();
217
218   void onShowDOF();
219
220   void onShowPanel();
221
222 private:
223   /// Set sketch plane by shape
224   /// \param theShape a planar face
225   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
226
227   /// Set sketch plane
228   /// \param thePlane a plane
229   std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
230
231   /**
232   * Returns list of presentations which have displayed shapes with circular edges
233   * (circles, arcs) which are in pane of of the given sketch
234   * \param theSketch - the sketch
235   */
236   QList<std::shared_ptr<ModuleBase_ViewerPrs>> findCircularEdgesInPlane();
237
238 private:
239   /// class to show/hide preview planes
240   PartSet_PreviewPlanes* myPreviewPlanes;
241
242   QCheckBox* myViewInverted;
243   QCheckBox* myRemoveExternal;
244   QCheckBox* myShowPoints;
245   QCheckBox* myAutoConstraints;
246
247   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
248
249   QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
250   QLineEdit* mySizeOfView; ///< Value of square of size of View
251   QStackedWidget* myStackWidget;
252
253   QLabel* myDoFLabel;
254   QPushButton* myShowDOFBtn;
255
256   bool myOpenTransaction;
257   bool myIsSelection;
258
259   QDialog* myPartSetMessage;
260   QDialog* mySizeMessage;
261
262   GeomPlanePtr myTmpPlane;
263 };
264
265 #endif