Salome HOME
f07c60fc9f69269f50df10c6dc5907b4b8a998a4
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetPoint2d.h
4 // Created:     25 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef PartSet_WidgetPoint2D_H
8 #define PartSet_WidgetPoint2D_H
9
10 #include "PartSet.h"
11 #include <ModelAPI_CompositeFeature.h>
12 #include <ModuleBase_ModelWidget.h>
13
14 #include <QObject>
15
16 #include <TopoDS_Shape.hxx>
17 #include <V3d_View.hxx>
18
19 class ModelAPI_Feature;
20 class ModuleBase_IWorkshop;
21 class ModuleBase_DoubleSpinBox;
22 class ModuleBase_IViewWindow;
23 class GeomAPI_Pnt2d;
24 class XGUI_Workshop;
25
26 class QGroupBox;
27 class QMouseEvent;
28
29 /**\class PartSet_WidgetPoint2D
30  * \ingroup Modules
31  * \brief Implementation of model widget to provide widget to input point 2d
32  * In XML can be defined as folloung:
33  * \code
34  * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
35  * \endcode
36  */
37 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget
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_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, 
46                         const std::string& theParentId);
47   /// Destructor
48   virtual ~PartSet_WidgetPoint2D();
49
50   /// Fills the widget with default values
51   virtual void reset();
52
53   /// Set the given wrapped value to the current widget
54   /// This value should be processed in the widget according to the needs
55   /// \param theValue the wrapped widget value
56   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
57
58   virtual bool restoreValue();
59
60   /// Returns the internal parent wiget control, that can be shown anywhere
61   /// \returns the widget
62   QWidget* getControl() const;
63
64   /// Returns list of widget controls
65   /// \return a control list
66   virtual QList<QWidget*> getControls() const;
67
68   //bool initFromPrevious(ObjectPtr theObject);
69
70   /// The methiod called when widget is deactivated
71   virtual void deactivate();
72
73   /// Return workshop
74   XGUI_Workshop* workshop() const { return myWorkshop; }
75
76   /// Set workshop
77   void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
78
79   /// \returns the sketch instance
80   CompositeFeaturePtr sketch() const { return mySketch; }
81
82   /// Set sketch instance
83   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
84
85   /// Fill the widget values by given point
86   /// \param theX the X coordinate
87   /// \param theY the Y coordinate
88   /// \returns True in case of success
89   bool setPoint(double theX, double theY);
90
91   /// Returns coordinate X currently defined in the control
92   double x() const;
93
94   /// Returns coordinate Y currently defined in the control
95   double y() const;
96
97 signals:
98   /// Signal about selection of an existing vertex from an object
99   void vertexSelected();
100
101 public slots:
102   /// Process mouse move event
103   /// \param theWnd a view window
104   /// \param theEvent a mouse event
105   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
106
107 protected slots:
108   /// Process mouse release event
109   /// \param theWnd a view window
110   /// \param theEvent a mouse event
111   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
112
113 protected:
114   /// Saves the internal parameters to the given feature
115   /// \return True in success
116   virtual bool storeValueCustom() const;
117
118   /// The methiod called when widget is activated
119   virtual void activateCustom();
120
121 private slots:
122   /// Process value changed event
123   void onValuesChanged();
124
125  private:
126    /// Returns point 2d from selected vertex
127    /// \param theView a view window
128    /// \param theShape a vertex shape
129    /// \param theX an output value of X coordinate
130    /// \param theY an output value of Y coordinate
131    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
132                    double& theX, double& theY) const;
133
134   XGUI_Workshop* myWorkshop;
135
136   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
137   ModuleBase_DoubleSpinBox* myXSpin;  ///< the spin box for the X coordinate
138   ModuleBase_DoubleSpinBox* myYSpin;  ///< the spin box for the Y coordinate
139
140   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature
141
142   CompositeFeaturePtr mySketch;
143 };
144
145 #endif