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