Salome HOME
Issue #1393 Angle constraint : incorrect angle displayed. solution: arc's passed...
[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   PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
46                         const Config_WidgetAPI* theData);
47   /// Destructor
48   virtual ~PartSet_WidgetPoint2D();
49
50   /// Checks if the selection presentation is valid in widget 
51   /// \param theValue a selected presentation in the view
52   /// \return a boolean value
53   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
54
55   /// Set the given wrapped value to the current widget
56   /// This value should be processed in the widget according to the needs
57   /// \param theValues the wrapped widget values
58   /// \param theToValidate a validation flag
59   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
60                             const bool theToValidate);
61
62   /// Select the internal content if it can be selected. It is empty in the default realization
63   virtual void selectContent();
64
65   /// Returns list of widget controls
66   /// \return a control list
67   virtual QList<QWidget*> getControls() const;
68
69   //bool initFromPrevious(ObjectPtr theObject);
70
71   /// Defines if the widget can be activated by mouse move.
72   /// By default it returns false
73   virtual bool canBeActivatedByMove();
74
75   /// The methiod called when widget is deactivated
76   virtual void deactivate();
77
78   /// \returns the sketch instance
79   CompositeFeaturePtr sketch() const { return mySketch; }
80
81   /// Set sketch instance
82   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
83
84   /// Fill the widget values by given point
85   /// \param theX the X coordinate
86   /// \param theY the Y coordinate
87   /// \returns True in case of success
88   bool setPoint(double theX, double theY);
89
90   /// Returns coordinate X currently defined in the control
91   double x() const;
92
93   /// Returns coordinate Y currently defined in the control
94   double y() const;
95
96   /// Returns true if the event is processed.
97   virtual bool processEnter();
98
99   /// Returns true if the attribute can be changed using the selected shapes in the viewer
100   /// and creating a coincidence constraint to them. This control use them.
101   virtual bool useSelectedShapes() const;
102
103 signals:
104   /// Signal about selection of an existing vertex from an object
105   void vertexSelected();
106
107 public slots:
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   /// Process mouse release event
114   /// \param theWnd a view window
115   /// \param theEvent a mouse event
116   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
117
118 protected:
119   /// Saves the internal parameters to the given feature
120   /// \return True in success
121   virtual bool storeValueCustom() const;
122
123   /// Restore value from attribute data to the widget's control
124   virtual bool restoreValueCustom();
125
126   /// Store current value in cashed value
127   void storeCurentValue();
128
129   /// Restore cashed value in the model attribute
130   /// \return boolean state if the restored feature shoud be hidden
131   bool restoreCurentValue();
132
133   /// Fills the widget with default values
134   /// \return true if the widget current value is reset
135   virtual bool resetCustom();
136
137   /// The methiod called when widget is activated
138   virtual void activateCustom();
139
140   /// Returns true if the feature contains Point2D attribute with the same coordinates
141   /// The attribute of the widget is not processed.
142   /// \param theFeature a feature
143   /// \param theX the X coordinate
144   /// \param theY the Y coordinate
145   /// \return boolean result
146   bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
147
148 //private slots:
149   /// Process value changed event
150   //void onValuesChanged();
151
152   /// Compute the feature default value and fill the controls with it
153   /// or store the control value to the feature
154   /// The widget is not initialize the attribute value in order to avoid the 
155   /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
156   /// be visualized immediatelly when the end point widget is activated.
157   virtual void initializeValueByActivate();
158
159  private:
160    /// Returns point 2d from selected vertex
161    /// \param theView a view window
162    /// \param theShape a vertex shape
163    /// \param theX an output value of X coordinate
164    /// \param theY an output value of Y coordinate
165    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
166                    double& theX, double& theY) const;
167
168    /// Create a coincidence constraint between the attribute and the parameter object
169    /// \theObject a result object
170    /// \return true if succed
171    bool setConstraintWith(const ObjectPtr& theObject);
172
173    /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
174    /// has no a coincident to other lines. It processes point, circle and arc features
175    /// In circle an arc features, only centers are processed, for other points, it returns
176    /// that the point is not an orphan.
177    /// \param theFeature a checked feature
178    /// \param theSketch a sketch
179    /// \param theX an X coordinate of the point
180    /// \param theY an Y coordinate of the point
181    /// \return boolean result
182    static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
183                              double theX, double theY);
184
185    /// Explode the given shape by vertices and found closed to the point vertes
186    /// \param theShape a shape to be exploded
187    /// \param thePoint a point
188    /// \return boolean value
189    static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
190                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
191                                   const CompositeFeaturePtr& theSketch);
192
193 protected:
194   ModuleBase_IWorkshop* myWorkshop; ///< workshop
195
196 private:
197
198   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
199   ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
200   ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
201
202   //std::string myOptionParam;  /// Parameter name which has to be taken from previous feature
203
204   CompositeFeaturePtr mySketch;
205
206   bool myValueIsCashed; /// boolean state if the value is cashed during value state change
207   bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
208   double myXValueInCash; /// the cashed X value during value state change
209   double myYValueInCash; /// the cashed Y value during value state change
210 };
211
212 #endif