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