Salome HOME
Merge with Dev_1.5.0
[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_ParamSpinBox;
22 class ModuleBase_IViewWindow;
23 class GeomAPI_Pnt2d;
24 class ModuleBase_IWorkshop;
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 theWorkshop a current workshop
44   /// \param theData the widget configuation. The attribute of the model widget is obtained from
45   /// \param theParentId is Id of a parent of the current attribute
46   PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
47                         const Config_WidgetAPI* theData, 
48                         const std::string& theParentId);
49   /// Destructor
50   virtual ~PartSet_WidgetPoint2D();
51
52   /// Set the given wrapped value to the current widget
53   /// This value should be processed in the widget according to the needs
54   /// \param theValues the wrapped widget values
55   /// \param theToValidate a validation flag
56   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
57                             const bool theToValidate);
58
59   /// Returns list of widget controls
60   /// \return a control list
61   virtual QList<QWidget*> getControls() const;
62
63   //bool initFromPrevious(ObjectPtr theObject);
64
65   /// The methiod called when widget is deactivated
66   virtual void deactivate();
67
68   /// \returns the sketch instance
69   CompositeFeaturePtr sketch() const { return mySketch; }
70
71   /// Set sketch instance
72   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
73
74   /// Fill the widget values by given point
75   /// \param theX the X coordinate
76   /// \param theY the Y coordinate
77   /// \returns True in case of success
78   bool setPoint(double theX, double theY);
79
80   /// Returns coordinate X currently defined in the control
81   double x() const;
82
83   /// Returns coordinate Y currently defined in the control
84   double y() const;
85
86   /// Returns true if the event is processed.
87   virtual bool processEnter();
88
89 signals:
90   /// Signal about selection of an existing vertex from an object
91   void vertexSelected();
92
93 public slots:
94   /// Process mouse move event
95   /// \param theWnd a view window
96   /// \param theEvent a mouse event
97   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
98
99 protected slots:
100   /// Process mouse release event
101   /// \param theWnd a view window
102   /// \param theEvent a mouse event
103   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
104
105 protected:
106   /// Saves the internal parameters to the given feature
107   /// \return True in success
108   virtual bool storeValueCustom() const;
109
110   virtual bool restoreValueCustom();
111
112   /// Fills the widget with default values
113   /// \return true if the widget current value is reset
114   virtual bool resetCustom();
115
116   /// The methiod called when widget is activated
117   virtual void activateCustom();
118
119   /// Returns true if the feature contains Point2D attribute with the same coordinates
120   /// The attribute of the widget is not processed.
121   /// \param theFeature a feature
122   /// \param theX the X coordinate
123   /// \param theY the Y coordinate
124   /// \return boolean result
125   bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
126
127 //private slots:
128   /// Process value changed event
129   //void onValuesChanged();
130
131  private:
132    /// Returns point 2d from selected vertex
133    /// \param theView a view window
134    /// \param theShape a vertex shape
135    /// \param theX an output value of X coordinate
136    /// \param theY an output value of Y coordinate
137    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
138                    double& theX, double& theY) const;
139
140    /// Create a coincidence constraint between the attribute and the parameter object
141    /// \theObject a result object
142    void setConstraintWith(const ObjectPtr& theObject);
143
144 protected:
145   ModuleBase_IWorkshop* myWorkshop;
146
147 private:
148
149   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
150   ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
151   ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
152
153   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature
154
155   CompositeFeaturePtr mySketch;
156 };
157
158 #endif