Salome HOME
Update code documentation
[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 Module
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   /// Set the given wrapped value to the current widget
51   /// This value should be processed in the widget according to the needs
52   /// \param theValue the wrapped widget value
53   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
54
55   virtual bool storeValue() const;
56
57   virtual bool restoreValue();
58
59   /// Returns the internal parent wiget control, that can be shown anywhere
60   /// \returns the widget
61   QWidget* getControl() const;
62
63   /// Returns list of widget controls
64   /// \return a control list
65   virtual QList<QWidget*> getControls() const;
66
67   //bool initFromPrevious(ObjectPtr theObject);
68
69   /// The methiod called when widget is activated
70   virtual void activate();
71
72   /// The methiod called when widget is deactivated
73   virtual void deactivate();
74
75   /// Return workshop
76   XGUI_Workshop* workshop() const { return myWorkshop; }
77
78   /// Set workshop
79   void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
80
81   /// \returns the sketch instance
82   CompositeFeaturePtr sketch() const { return mySketch; }
83
84   /// Set sketch instance
85   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
86
87   /// Fill the widget values by given point
88   /// \param theX the X coordinate
89   /// \param theY the Y coordinate
90   void setPoint(double theX, double theY);
91
92   /// Returns coordinate X currently defined in the control
93   double x() const;
94
95   /// Returns coordinate Y currently defined in the control
96   double y() const;
97
98 signals:
99   /// Signal about selection of an existing vertex from an object
100   void vertexSelected();
101
102 protected slots:
103   /// Process mouse release event
104   /// \param theWnd a view window
105   /// \param theEvent a mouse event
106   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
107
108   /// Process mouse move event
109   /// \param theWnd a view window
110   /// \param theEvent a mouse event
111   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
112
113 private slots:
114   /// Process value changed event
115   void onValuesChanged();
116
117  private:
118    /// Returns point 2d from selected vertex
119    /// \param theView a view window
120    /// \param theShape a vertex shape
121    /// \param theX an output value of X coordinate
122    /// \param theY an output value of Y coordinate
123    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
124                    double& theX, double& theY) const;
125
126   XGUI_Workshop* myWorkshop;
127
128   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
129   ModuleBase_DoubleSpinBox* myXSpin;  ///< the spin box for the X coordinate
130   ModuleBase_DoubleSpinBox* myYSpin;  ///< the spin box for the Y coordinate
131
132   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature
133
134   CompositeFeaturePtr mySketch;
135 };
136
137 #endif