]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetSketchLabel.h
Salome HOME
Shape plane filter should process shapes of objects selected in object browser.
[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 <ModuleBase_WidgetValidated.h>
13 #include <ModuleBase_ViewerFilters.h>
14
15 #include <GeomAPI_Pnt.h>
16 #include <GeomAPI_Dir.h>
17 #include <GeomAPI_AISObject.h>
18
19 #include <TopoDS_Shape.hxx>
20
21 class QLabel;
22 class XGUI_OperationMgr;
23 class XGUI_Workshop;
24 class QCheckBox;
25
26 /// the plane edge width
27 #define SKETCH_WIDTH        "4"
28
29 /// face of the square-face displayed for selection of general plane
30 #define PLANE_SIZE          "200"
31
32 /**
33 * \ingroup Modules
34 * A model widget implementation for a label which provides specific behaviour 
35 * for sketcher starting and launching operations
36 */
37 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
38 {
39 Q_OBJECT
40  public:
41   /// Constructor
42   /// \param theParent the parent object
43   /// \param theData the widget configuation. The attribute of the model widget is obtained from
44   /// \param theParentId is Id of a parent of the current attribute
45   PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
46                             const Config_WidgetAPI* theData,
47                             const std::string& theParentId, bool toShowConstraints);
48
49   virtual ~PartSet_WidgetSketchLabel();
50
51   /// Set the given wrapped value to the current widget
52   /// This value should be processed in the widget according to the needs
53   /// The method is called by the current operation to process the operation preselection.
54   /// It is redefined to do nothing if the plane of the sketch has been already set.
55   /// \param theValues the wrapped selection values
56   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
57                             const bool theToValidate);
58
59   virtual bool restoreValue()
60   {
61     return true;
62   }
63
64   /// Returns list of widget controls
65   /// \return a control list
66   virtual QList<QWidget*> getControls() const;
67
68   /// The methiod called when widget is deactivated
69   virtual void deactivate();
70
71   /// Returns sketcher plane
72   std::shared_ptr<GeomAPI_Pln> plane() const;
73
74   /// This control accepts focus
75   virtual bool focusTo();
76   virtual void setHighlighted(bool) { /*do nothing*/ };
77   virtual void enableFocusProcessing();
78
79   void showConstraints(bool theOn);
80
81 signals:
82   /// Signal on plane selection
83   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
84
85   void showConstraintToggled(bool);
86
87 protected:
88   /// Creates a backup of the current values of the attribute
89   /// It should be realized in the specific widget because of different
90   /// parameters of the current attribute
91   virtual void storeAttributeValue();
92
93   /// Creates a backup of the current values of the attribute
94   /// It should be realized in the specific widget because of different
95   /// parameters of the current attribute
96   /// \param theValid a boolean flag, if restore happens for valid parameters
97   virtual void restoreAttributeValue(const bool theValid);
98
99   /// Fills the attribute with the value of the selected owner
100   /// \param theOwner a selected owner
101   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
102
103   /// Saves the internal parameters to the given feature
104   /// \return True in success
105   virtual bool storeValueCustom() const
106   {
107     return true;
108   }
109
110   /// The methiod called when widget is activated
111   virtual void activateCustom();
112
113  protected:
114   /// Activate or deactivate selection
115   void activateSelection(bool toActivate);
116
117  private slots:
118    /// Slot on change selection
119   void onSelectionChanged();
120
121  private:
122    /// Create preview of planes for sketch plane selection
123    /// \param theOrigin an origin of the plane
124    /// \param theNorm a normal vector of the plane
125    /// \param theRGB a color of plane presentation [r, g, b] array
126   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
127                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
128                                   const int theRGB[3]);
129
130   //! Returns workshop
131   XGUI_Workshop* workshop() const;
132
133   /// Set sketch plane by shape
134   /// \param theShape a planar face
135   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
136
137   /// Erase preview planes
138   void erasePreviewPlanes();
139
140   /// Show preview planes
141   void showPreviewPlanes();
142
143
144   QLabel* myLabel;
145   QString myText;
146   QString myTooltip;
147
148   AISObjectPtr myYZPlane;
149   AISObjectPtr myXZPlane;
150   AISObjectPtr myXYPlane;
151   bool myPreviewDisplayed;
152
153   QCheckBox* myShowConstraints;
154 };
155
156 #endif