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