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