Salome HOME
Issue #690 Application hangs up when Create Arc after Rotation
[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 class PartSet_LockApplyMgr;
26
27 class QGroupBox;
28 class QMouseEvent;
29
30 /**\class PartSet_WidgetPoint2D
31  * \ingroup Modules
32  * \brief Implementation of model widget to provide widget to input point 2d
33  * In XML can be defined as folloung:
34  * \code
35  * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
36  * \endcode
37  */
38 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget
39 {
40 Q_OBJECT
41  public:
42   /// Constructor
43   /// \param theParent the parent object
44   /// \param theWorkshop a current workshop
45   /// \param theData the widget configuation. The attribute of the model widget is obtained from
46   /// \param theParentId is Id of a parent of the current attribute
47   PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
48                         const Config_WidgetAPI* theData, 
49                         const std::string& theParentId);
50   /// Destructor
51   virtual ~PartSet_WidgetPoint2D();
52
53   /// Fills the widget with default values
54   virtual bool reset();
55
56   /// Set the given wrapped value to the current widget
57   /// This value should be processed in the widget according to the needs
58   /// \param theValues the wrapped widget values
59   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
60
61   virtual bool restoreValue();
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 deactivated
70   virtual void deactivate();
71
72   /// \returns the sketch instance
73   CompositeFeaturePtr sketch() const { return mySketch; }
74
75   /// Set sketch instance
76   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
77
78   /// Fill the widget values by given point
79   /// \param theX the X coordinate
80   /// \param theY the Y coordinate
81   /// \returns True in case of success
82   bool setPoint(double theX, double theY);
83
84   /// Returns coordinate X currently defined in the control
85   double x() const;
86
87   /// Returns coordinate Y currently defined in the control
88   double y() const;
89
90 signals:
91   /// Signal about selection of an existing vertex from an object
92   void vertexSelected();
93
94 public slots:
95   /// Process mouse move event
96   /// \param theWnd a view window
97   /// \param theEvent a mouse event
98   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
99
100 protected slots:
101   /// Process mouse release event
102   /// \param theWnd a view window
103   /// \param theEvent a mouse event
104   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
105
106 protected:
107   /// Saves the internal parameters to the given feature
108   /// \return True in success
109   virtual bool storeValueCustom() const;
110
111   /// The methiod called when widget is activated
112   virtual void activateCustom();
113
114 private slots:
115   /// Process value changed event
116   void onValuesChanged();
117
118  private:
119    /// Returns point 2d from selected vertex
120    /// \param theView a view window
121    /// \param theShape a vertex shape
122    /// \param theX an output value of X coordinate
123    /// \param theY an output value of Y coordinate
124    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
125                    double& theX, double& theY) const;
126
127    /// Create a coincidence constraint between the attribute and the parameter object
128    /// \theObject a result object
129    void setConstraintWith(const ObjectPtr& theObject);
130
131   ModuleBase_IWorkshop* myWorkshop;
132   PartSet_LockApplyMgr* myLockApplyMgr; ///< a manager to lock/unlock Apply button in PP
133
134   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
135   ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
136   ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
137
138   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature
139
140   CompositeFeaturePtr mySketch;
141 };
142
143 #endif