Salome HOME
1ad54ba716ce805153f49c8ab26257b62f46a859
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.h
1 // Copyright (C) 2014-2017  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<mailto: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   /// Returns list of widget controls
76   /// \return a control list
77   virtual QList<QWidget*> getControls() const;
78
79   /// The methiod called when widget is deactivated
80   virtual void deactivate();
81
82   /// Returns sketcher plane
83   std::shared_ptr<GeomAPI_Pln> plane() const;
84
85   /// This control accepts focus
86   virtual bool focusTo();
87   virtual void setHighlighted(bool) { /*do nothing*/ };
88   virtual void enableFocusProcessing();
89
90   /// Returns True if the selected presentation can be used for plane definition
91   /// \param thePrs a presentation
92   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
93
94 signals:
95   /// Signal on plane selection
96   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
97
98   /// A show constraint toggled signal
99   /// \param theType a ConstraintVisibleState value
100   /// \param theState a state of the check box
101   void showConstraintToggled(int theType, bool theState);
102
103 protected:
104   /// Creates a backup of the current values of the attribute
105   /// It should be realized in the specific widget because of different
106   /// parameters of the current attribute
107   /// \param theAttribute an attribute to be stored
108   virtual void storeAttributeValue(const AttributePtr& theAttribute);
109
110   /// Creates a backup of the current values of the attribute
111   /// It should be realized in the specific widget because of different
112   /// parameters of the current attribute
113   /// \param theAttribute an attribute to be restored
114   /// \param theValid a boolean flag, if restore happens for valid parameters
115   virtual void restoreAttributeValue(const AttributePtr& theAttribute,
116                                      const bool theValid);
117
118   /// Fills the attribute with the value of the selected owner
119   /// \param thePrs a selected owner
120   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
121
122   /// Saves the internal parameters to the given feature
123   /// \return True in success
124   virtual bool storeValueCustom()
125   {
126     return true;
127   }
128
129   virtual bool restoreValueCustom()
130   {
131     return true;
132   }
133
134   /// The methiod called when widget is activated
135   virtual void activateCustom();
136
137   /// Block the model flush of update and intialization of attribute
138   /// In additional to curstom realization it blocks initialization for all feature attributes
139   /// as the current attribute is selection but its modification leads to other attributes change
140   /// \param theAttribute an attribute
141   /// \param theToBlock flag whether the model is blocked or unblocked
142   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
143   /// to be used to restore flush state when unblocked
144   /// \param isAttributeSetInitializedBlocked out value if model is blocked
145   /// in value if model is unblocked to be used to restore previous state when unblocked
146   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
147   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
148                               bool& isFlushesActived,
149                               bool& isAttributeSetInitializedBlocked,
150                               bool& isAttributeSendUpdatedBlocked);
151
152   /// Set the given wrapped value to the current widget
153   /// This value should be processed in the widget according to the needs
154   /// The method is called by the current operation to process the operation preselection.
155   /// It is redefined to do nothing if the plane of the sketch has been already set.
156   /// \param theValues the wrapped selection values
157   /// \param theToValidate a validation flag
158   bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
159                             const bool theToValidate);
160
161   /// Erase preview planes, disconnect widget, change the view projection
162   /// \param thePrs a selected presentation
163   void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
164
165   /// Set sketch plane from selected object
166   /// \param theFeature a feature of sketch
167   /// \param thePrs a presentation
168   bool fillSketchPlaneBySelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
169
170  protected:
171   /// Activate or deactivate selection
172   void activateSelection(bool toActivate);
173
174  private slots:
175    /// Slot on change selection
176   void onSelectionChanged();
177
178   /// A slot called on set sketch plane view
179   void onSetPlaneView();
180
181   /// Emits signal about check box state changed with information about ConstraintVisibleState
182   /// \param theOn a flag show constraints or not
183   void onShowConstraint(bool theOn);
184
185  private:
186   /// Set sketch plane by shape
187   /// \param theShape a planar face
188   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
189
190   /// Set sketch plane
191   /// \param thePlane a plane
192   std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
193
194 private:
195   /// class to show/hide preview planes
196   PartSet_PreviewPlanes* myPreviewPlanes;
197
198   QCheckBox* myViewInverted;
199
200   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
201
202   QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
203   QLineEdit* mySizeOfView; ///< Value of square of size of View
204   QStackedWidget* myStackWidget;
205 };
206
207 #endif