Salome HOME
Issue 812:
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetSketchLabel.h
4 // Created:     07 July 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef PartSet_WidgetSketchLabel_H
8 #define PartSet_WidgetSketchLabel_H
9
10 #include "PartSet.h"
11
12 #include "PartSet_Tools.h"
13
14 #include <ModuleBase_WidgetValidated.h>
15 #include <ModuleBase_ViewerFilters.h>
16
17 #include <GeomAPI_Pnt.h>
18 #include <GeomAPI_Dir.h>
19 #include <GeomAPI_AISObject.h>
20
21 #include <TopoDS_Shape.hxx>
22
23 #include <QMap>
24
25 class QLabel;
26 class XGUI_OperationMgr;
27 class XGUI_Workshop;
28 class QCheckBox;
29 class QStackedWidget;
30
31 /// the plane edge width
32 #define SKETCH_WIDTH        "4"
33
34 /// face of the square-face displayed for selection of general plane
35 #define PLANE_SIZE          "200"
36
37 /**
38 * \ingroup Modules
39 * A model widget implementation for a label which provides specific behaviour 
40 * for sketcher starting and launching operations
41 */
42 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
43 {
44 Q_OBJECT
45
46 public:
47   /// Constructor
48   /// \param theParent the parent object
49   /// \param theWorkshop a reference to workshop
50   /// \param theData the widget configuation. The attribute of the model widget is obtained from
51   /// \param theParentId is Id of a parent of the current attribute
52   /// \param toShowConstraints a current show constraints state
53   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
54                       const Config_WidgetAPI* theData,
55                       const std::string& theParentId,
56                       const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
57
58   virtual ~PartSet_WidgetSketchLabel();
59
60   /// Set the given wrapped value to the current widget
61   /// This value should be processed in the widget according to the needs
62   /// The method is called by the current operation to process the operation preselection.
63   /// It is redefined to do nothing if the plane of the sketch has been already set.
64   /// \param theValues the wrapped selection values
65   /// \param theToValidate a validation flag
66   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
67                             const bool theToValidate);
68
69   /// Returns list of widget controls
70   /// \return a control list
71   virtual QList<QWidget*> getControls() const;
72
73   /// The methiod called when widget is deactivated
74   virtual void deactivate();
75
76   /// Returns sketcher plane
77   std::shared_ptr<GeomAPI_Pln> plane() const;
78
79   /// This control accepts focus
80   virtual bool focusTo();
81   virtual void setHighlighted(bool) { /*do nothing*/ };
82   virtual void enableFocusProcessing();
83
84 signals:
85   /// Signal on plane selection
86   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
87
88   /// A show constraint toggled signal
89   /// \param theState a state of the check box
90   /// \param theType a ConstraintVisibleState value
91   void showConstraintToggled(bool theState, int theType);
92
93 protected:
94   /// Creates a backup of the current values of the attribute
95   /// It should be realized in the specific widget because of different
96   /// parameters of the current attribute
97   virtual void storeAttributeValue();
98
99   /// Creates a backup of the current values of the attribute
100   /// It should be realized in the specific widget because of different
101   /// parameters of the current attribute
102   /// \param theValid a boolean flag, if restore happens for valid parameters
103   virtual void restoreAttributeValue(const bool theValid);
104
105   /// Fills the attribute with the value of the selected owner
106   /// \param thePrs a selected owner
107   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
108
109   /// Saves the internal parameters to the given feature
110   /// \return True in success
111   virtual bool storeValueCustom() const
112   {
113     return true;
114   }
115
116   virtual bool restoreValueCustom()
117   {
118     return true;
119   }
120
121   /// The methiod called when widget is activated
122   virtual void activateCustom();
123
124   /// Erase preview planes, disconnect widget, change the view projection
125   /// \param thePrs a selected presentation
126   void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
127
128  protected:
129   /// Activate or deactivate selection
130   void activateSelection(bool toActivate);
131
132  private slots:
133    /// Slot on change selection
134   void onSelectionChanged();
135
136   /// A slot called on set sketch plane view
137   void onSetPlaneView();
138
139   /// Emits signal about check box state changed with information about ConstraintVisibleState
140   /// \param theOn a flag show constraints or not
141   void onShowConstraint(bool theOn);
142
143  private:
144    /// Create preview of planes for sketch plane selection
145    /// \param theOrigin an origin of the plane
146    /// \param theNorm a normal vector of the plane
147    /// \param theRGB a color of plane presentation [r, g, b] array
148   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
149                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
150                                   const int theRGB[3]);
151
152   //! Returns workshop
153   XGUI_Workshop* workshop() const;
154
155   /// Set sketch plane by shape
156   /// \param theShape a planar face
157   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
158
159   /// Erase preview planes
160   void erasePreviewPlanes();
161
162   /// Show preview planes
163   void showPreviewPlanes();
164
165
166   AISObjectPtr myYZPlane;
167   AISObjectPtr myXZPlane;
168   AISObjectPtr myXYPlane;
169   bool myPreviewDisplayed;
170
171   QCheckBox* myViewInverted;
172
173   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
174
175   QStackedWidget* myStackWidget;
176 };
177
178 #endif