]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetSketchLabel.h
Salome HOME
1. Compound selection choice is provided for sketch selection in Extrusion operation...
[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, const Config_WidgetAPI* theData,
46                             const std::string& theParentId, bool toShowConstraints);
47
48   virtual ~PartSet_WidgetSketchLabel();
49
50   /// Set the given wrapped value to the current widget
51   /// This value should be processed in the widget according to the needs
52   /// The method is called by the current operation to process the operation preselection.
53   /// It is redefined to do nothing if the plane of the sketch has been already set.
54   /// \param theValues the wrapped selection values
55   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
56
57   virtual bool restoreValue()
58   {
59     return true;
60   }
61
62   /// Returns list of widget controls
63   /// \return a control list
64   virtual QList<QWidget*> getControls() const;
65
66   /// The methiod called when widget is deactivated
67   virtual void deactivate();
68
69   /// Returns pointer to workshop
70   XGUI_Workshop* workshop() const { return myWorkshop; }
71
72   /// Set pointer to workshop
73   /// \param theWork a pointer to workshop
74   void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
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   void showConstraints(bool theOn);
85
86 signals:
87   /// Signal on plane selection
88   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
89
90   void showConstraintToggled(bool);
91
92 protected:
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   virtual void storeAttributeValue();
97
98   /// Creates a backup of the current values of the attribute
99   /// It should be realized in the specific widget because of different
100   /// parameters of the current attribute
101   /// \param theValid a boolean flag, if restore happens for valid parameters
102   virtual void restoreAttributeValue(const bool theValid);
103
104   /// Fills the attribute with the value of the selected owner
105   /// \param theOwner a selected owner
106   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
107
108   /// Saves the internal parameters to the given feature
109   /// \return True in success
110   virtual bool storeValueCustom() const
111   {
112     return true;
113   }
114
115   /// The methiod called when widget is activated
116   virtual void activateCustom();
117
118  protected:
119   /// Activate or deactivate selection
120   void activateSelection(bool toActivate);
121
122  private slots:
123    /// Slot on change selection
124   void onSelectionChanged();
125
126  private:
127    /// Create preview of planes for sketch plane selection
128    /// \param theOrigin an origin of the plane
129    /// \param theNorm a normal vector of the plane
130    /// \param theRGB a color of plane presentation [r, g, b] array
131   AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
132                                   std::shared_ptr<GeomAPI_Dir> theNorm, 
133                                   const int theRGB[3]);
134
135   /// Set sketch plane by shape
136   /// \param theShape a planar face
137   std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
138
139   /// Erase preview planes
140   void erasePreviewPlanes();
141
142   /// Show preview planes
143   void showPreviewPlanes();
144
145
146   QLabel* myLabel;
147   QString myText;
148   QString myTooltip;
149
150   XGUI_Workshop* myWorkshop;
151
152   AISObjectPtr myYZPlane;
153   AISObjectPtr myXZPlane;
154   AISObjectPtr myXYPlane;
155   bool myPreviewDisplayed;
156
157   QCheckBox* myShowConstraints;
158 };
159
160 #endif