Salome HOME
Task 5.2.5 Add some warnings (tooltips) to critical places
[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 <QMap>
35
36 class PartSet_PreviewPlanes;
37
38 class QLabel;
39 class XGUI_OperationMgr;
40 class XGUI_Workshop;
41 class QCheckBox;
42 class QStackedWidget;
43 class QLineEdit;
44 class QDialog;
45
46 /**
47 * \ingroup Modules
48 * A model widget implementation for a label which provides specific behaviour 
49 * for sketcher starting and launching operations
50 */
51 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
52 {
53 Q_OBJECT
54
55 public:
56   /// Constructor
57   /// \param theParent the parent object
58   /// \param theWorkshop a reference to workshop
59   /// \param theData the widget configuation. The attribute of the model widget is obtained from
60   /// \param toShowConstraints a current show constraints state
61   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
62                       const Config_WidgetAPI* theData,
63                       const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
64
65   virtual ~PartSet_WidgetSketchLabel();
66
67   /// Set the given wrapped value to the current widget
68   /// This value should be processed in the widget according to the needs
69   /// The method is called by the current operation to process the operation preselection.
70   /// It is redefined to do nothing if the plane of the sketch has been already set.
71   /// \param theValues the wrapped selection values
72   /// \param theToValidate a validation flag
73   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
74                             const bool theToValidate);
75
76   /// Fills given container with selection modes if the widget has it
77   /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
78   /// \param theModes [out] a container of modes
79   virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
80
81   /// Using widget selection filter only if plane is not defined.
82   /// \param [out] theModuleSelectionFilters module additional modes, -1 means all default modes
83   /// \param [out] selection filters
84   virtual void selectionFilters(QIntList& theModuleSelectionFilters,
85                                 SelectMgr_ListOfFilter& theSelectionFilters);
86
87   /// Returns list of widget controls
88   /// \return a control list
89   virtual QList<QWidget*> getControls() const;
90
91   /// The methiod called when widget is deactivated
92   virtual void deactivate();
93
94   /// The method called if widget should be activated always
95   virtual bool needToBeActivated() { return true; }
96
97   /// Returns sketcher plane
98   std::shared_ptr<GeomAPI_Pln> plane() const;
99
100   /// This control accepts focus
101   virtual bool focusTo();
102   virtual void setHighlighted(bool) { /*do nothing*/ };
103   virtual void enableFocusProcessing();
104
105   /// Set current state of show free points
106   /// \param theState a state of the corresponded check box
107   void setShowPointsState(bool theState);
108
109   /// Returns True if the selected presentation can be used for plane definition
110   /// \param thePrs a presentation
111   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
112
113 signals:
114   /// Signal on plane selection
115   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
116
117   /// A show constraint toggled signal
118   /// \param theType a ConstraintVisibleState value
119   /// \param theState a state of the check box
120   void showConstraintToggled(int theType, bool theState);
121
122   /// The signal is emitted when user checks "Show free points" button
123   /// \param toShow a state of the check box
124   void showFreePoints(bool toShow);
125
126   /// The signal is emitted when user checks "Automatic constraints" button
127   /// \param isOn a state of the check box
128   void autoConstraints(bool isOn);
129
130 protected:
131   /// Creates a backup of the current values of the attribute
132   /// It should be realized in the specific widget because of different
133   /// parameters of the current attribute
134   /// \param theAttribute an attribute to be stored
135   virtual void storeAttributeValue(const AttributePtr& theAttribute);
136
137   /// Creates a backup of the current values of the attribute
138   /// It should be realized in the specific widget because of different
139   /// parameters of the current attribute
140   /// \param theAttribute an attribute to be restored
141   /// \param theValid a boolean flag, if restore happens for valid parameters
142   virtual void restoreAttributeValue(const AttributePtr& theAttribute,
143                                      const bool theValid);
144
145   /// Fills the attribute with the value of the selected owner
146   /// \param thePrs a selected owner
147   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
148
149   /// Saves the internal parameters to the given feature
150   /// \return True in success
151   virtual bool storeValueCustom()
152   {
153     return true;
154   }
155
156   virtual bool restoreValueCustom();
157
158   /// The methiod called when widget is activated
159   virtual void activateCustom();
160
161   /// Block the model flush of update and intialization of attribute
162   /// In additional to curstom realization it blocks initialization for all feature attributes
163   /// as the current attribute is selection but its modification leads to other attributes change
164   /// \param theAttribute an attribute
165   /// \param theToBlock flag whether the model is blocked or unblocked
166   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
167   /// to be used to restore flush state when unblocked
168   /// \param isAttributeSetInitializedBlocked out value if model is blocked
169   /// in value if model is unblocked to be used to restore previous state when unblocked
170   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
171   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
172                               bool& isFlushesActived,
173                               bool& isAttributeSetInitializedBlocked,
174                               bool& isAttributeSendUpdatedBlocked);
175
176   /// Returns true if envent is processed.
177   virtual bool processSelection();
178
179   /// Set the given wrapped value to the current widget
180   /// This value should be processed in the widget according to the needs
181   /// The method is called by the current operation to process the operation preselection.
182   /// It is redefined to do nothing if the plane of the sketch has been already set.
183   /// \param theValues the wrapped selection values
184   /// \param theToValidate a validation flag
185   bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
186                             const bool theToValidate);
187
188   /// Erase preview planes, disconnect widget, change the view projection
189   /// \param thePrs a selected presentation
190   void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
191
192   /// Set sketch plane from selected object
193   /// \param theFeature a feature of sketch
194   /// \param thePrs a presentation
195   bool fillSketchPlaneBySelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
196
197
198   virtual void showEvent(QShowEvent* theEvent);
199
200 private slots:
201   /// A slot called on set sketch plane view
202   void onSetPlaneView();
203
204   /// Emits signal about check box state changed with information about ConstraintVisibleState
205   /// \param theOn a flag show constraints or not
206   void onShowConstraint(bool theOn);
207
208   void onChangePlane();
209
210 private:
211   /// Set sketch plane by shape
212   /// \param theShape a planar face
213   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
214
215   /// Set sketch plane
216   /// \param thePlane a plane
217   std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
218
219   /**
220   * Returns list of presentations which have displayed shapes with circular edges
221   * (circles, arcs) which are in pane of of the given sketch
222   * \param theSketch - the sketch
223   */
224   QList<std::shared_ptr<ModuleBase_ViewerPrs>> findCircularEdgesInPlane();
225
226 private:
227   /// class to show/hide preview planes
228   PartSet_PreviewPlanes* myPreviewPlanes;
229
230   QCheckBox* myViewInverted;
231   QCheckBox* myRemoveExternal;
232   QCheckBox* myShowPoints;
233   QCheckBox* myAutoConstraints;
234
235   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
236
237   QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
238   QLineEdit* mySizeOfView; ///< Value of square of size of View
239   QStackedWidget* myStackWidget;
240
241   QLabel* myDoFLabel;
242
243   bool myOpenTransaction;
244   bool myIsSelection;
245
246   QDialog* myPartSetMessage;
247   QDialog* mySizeMessage;
248 };
249
250 #endif