Salome HOME
Sketch should stop contour in origin point if the contour is closed.
[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   /// Select the internal content if it can be selected. It is empty in the default realization
60   virtual void selectContent();
61
62   /// Returns list of widget controls
63   /// \return a control list
64   virtual QList<QWidget*> getControls() const;
65
66   //bool initFromPrevious(ObjectPtr theObject);
67
68   /// Defines if the widget can be activated by mouse move.
69   /// By default it returns false
70   virtual bool canBeActivatedByMove();
71
72   /// The methiod called when widget is deactivated
73   virtual void deactivate();
74
75   /// \returns the sketch instance
76   CompositeFeaturePtr sketch() const { return mySketch; }
77
78   /// Set sketch instance
79   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
80
81   /// Fill the widget values by given point
82   /// \param theX the X coordinate
83   /// \param theY the Y coordinate
84   /// \returns True in case of success
85   bool setPoint(double theX, double theY);
86
87   /// Returns coordinate X currently defined in the control
88   double x() const;
89
90   /// Returns coordinate Y currently defined in the control
91   double y() const;
92
93   /// Returns true if the event is processed.
94   virtual bool processEnter();
95
96   /// Returns true if the attribute can be changed using the selected shapes in the viewer
97   /// and creating a coincidence constraint to them. This control use them.
98   virtual bool useSelectedShapes() const;
99
100 signals:
101   /// Signal about selection of an existing vertex from an object
102   void vertexSelected();
103
104 public slots:
105   /// Process mouse move event
106   /// \param theWnd a view window
107   /// \param theEvent a mouse event
108   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
109
110   /// Process mouse release event
111   /// \param theWnd a view window
112   /// \param theEvent a mouse event
113   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
114
115 protected:
116   /// Saves the internal parameters to the given feature
117   /// \return True in success
118   virtual bool storeValueCustom() const;
119
120   virtual bool restoreValueCustom();
121
122   /// Fills the widget with default values
123   /// \return true if the widget current value is reset
124   virtual bool resetCustom();
125
126   /// The methiod called when widget is activated
127   virtual void activateCustom();
128
129   /// Returns true if the feature contains Point2D attribute with the same coordinates
130   /// The attribute of the widget is not processed.
131   /// \param theFeature a feature
132   /// \param theX the X coordinate
133   /// \param theY the Y coordinate
134   /// \return boolean result
135   bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
136
137 //private slots:
138   /// Process value changed event
139   //void onValuesChanged();
140
141   /// Compute the feature default value and fill the controls with it
142   /// or store the control value to the feature
143   /// The widget is not initialize the attribute value in order to avoid the 
144   /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
145   /// be visualized immediatelly when the end point widget is activated.
146   virtual void initializeValueByActivate();
147
148  private:
149    /// Returns point 2d from selected vertex
150    /// \param theView a view window
151    /// \param theShape a vertex shape
152    /// \param theX an output value of X coordinate
153    /// \param theY an output value of Y coordinate
154    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
155                    double& theX, double& theY) const;
156
157    /// Create a coincidence constraint between the attribute and the parameter object
158    /// \theObject a result object
159    void setConstraintWith(const ObjectPtr& theObject);
160
161    /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
162    /// has no a coincident to other lines. It processes point, circle and arc features
163    /// In circle an arc features, only centers are processed, for other points, it returns
164    /// that the point is not an orphan.
165    /// \param theFeature a checked feature
166    /// \param theSketch a sketch
167    /// \param theX an X coordinate of the point
168    /// \param theY an Y coordinate of the point
169    /// \return boolean result
170    static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
171                              double theX, double theY, const bool theSearchInResults = false);
172
173 protected:
174   ModuleBase_IWorkshop* myWorkshop; ///< workshop
175
176 private:
177
178   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
179   ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
180   ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
181
182   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature
183
184   CompositeFeaturePtr mySketch;
185 };
186
187 #endif