Salome HOME
Issue #1860: fix end lines with spaces
[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   /// Fill preselection used in mouseReleased
113   void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
114
115 signals:
116   /// Signal about selection of an existing vertex from an object
117   void vertexSelected();
118
119 protected:
120   /// Saves the internal parameters to the given feature
121   /// \return True in success
122   virtual bool storeValueCustom();
123
124   /// Restore value from attribute data to the widget's control
125   virtual bool restoreValueCustom();
126
127   /// Store current value in cashed value
128   void storeCurentValue();
129
130   /// Restore cashed value in the model attribute
131   /// \return boolean state if the restored feature shoud be hidden
132   bool restoreCurentValue();
133
134   /// Fills the widget with default values
135   /// \return true if the widget current value is reset
136   virtual bool resetCustom();
137
138   /// The methiod called when widget is activated
139   virtual void activateCustom();
140
141   /// Returns true if the feature contains Point2D attribute with the same coordinates
142   /// The attribute of the widget is not processed.
143   /// \param theFeature a feature
144   /// \param theX the X coordinate
145   /// \param theY the Y coordinate
146   /// \return boolean result
147   bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
148
149 //private slots:
150   /// Process value changed event
151   //void onValuesChanged();
152
153   /// Compute the feature default value and fill the controls with it
154   /// or store the control value to the feature
155   /// The widget is not initialize the attribute value in order to avoid the
156   /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
157   /// be visualized immediatelly when the end point widget is activated.
158   virtual void initializeValueByActivate();
159
160  private:
161    /// Returns point 2d from selected vertex
162    /// \param theView a view window
163    /// \param theShape a vertex shape
164    /// \param theX an output value of X coordinate
165    /// \param theY an output value of Y coordinate
166    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
167                    double& theX, double& theY) const;
168
169    /// Create a coincidence constraint between the attribute and the parameter object
170    /// \theObject a result object
171    /// \return true if succed
172    bool setConstraintWith(const ObjectPtr& theObject);
173
174    /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
175    /// has no a coincident to other lines. It processes point, circle and arc features
176    /// In circle an arc features, only centers are processed, for other points, it returns
177    /// that the point is not an orphan.
178    /// \param theFeature a checked feature
179    /// \param theSketch a sketch
180    /// \param theX an X coordinate of the point
181    /// \param theY an Y coordinate of the point
182    /// \return boolean result
183    static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
184                              double theX, double theY);
185
186    /// Explode the given shape by vertices and found closed to the point vertes
187    /// \param theShape a shape to be exploded
188    /// \param thePoint a point
189    /// \return boolean value
190    static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
191                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
192                                   const CompositeFeaturePtr& theSketch);
193
194 protected:
195   ModuleBase_IWorkshop* myWorkshop; ///< workshop
196
197 private:
198
199   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
200   ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
201   ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
202
203    /// value used as selection in mouse release method
204   std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
205
206   /// it is important during restart operation
207   CompositeFeaturePtr mySketch;
208
209   bool myValueIsCashed; /// boolean state if the value is cashed during value state change
210   bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
211   double myXValueInCash; /// the cashed X value during value state change
212   double myYValueInCash; /// the cashed Y value during value state change
213 };
214
215 #endif