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