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