Salome HOME
Update classes documentation
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetPoint2dDistance.h
4 // Created:     23 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #ifndef PartSet_WidgetPoint2dDistance_H
8 #define PartSet_WidgetPoint2dDistance_H
9
10 #include "PartSet.h"
11 #include <ModuleBase_WidgetDoubleValue.h>
12
13 #include <ModelAPI_CompositeFeature.h>
14
15 class GeomAPI_Pnt2d;
16 class ModuleBase_IWorkshop;
17 class ModuleBase_IViewWindow;
18 class QMouseEvent;
19
20 /**
21 * \ingroup Modules
22 * Implementation of model widget for widget which provides input of a distance between two points
23 * In XML file can be defined as following:
24 * \code
25 * <point2ddistance id="CircleRadius" 
26 *   first_point="CircleCenter" 
27 *   label="Radius:" 
28 *   min="0" 
29 *   step="1.0" 
30 *   default="0" 
31 *   icon=":icons/radius.png" 
32 *   tooltip="Set radius">
33 *   <validator id="GeomValidators_Positive"/>
34 * </point2ddistance>
35 * \endcode
36 */ 
37 class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue
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_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
46                                 const Config_WidgetAPI* theData);
47
48   virtual ~PartSet_WidgetPoint2dDistance();
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   /// The methiod called when widget is deactivated
56   virtual void deactivate();
57
58   /// \returns the sketch instance
59   CompositeFeaturePtr sketch() const { return mySketch; }
60
61   /// Set sketch instance
62   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
63
64   /// Returns true if the event is processed.
65   virtual bool processEnter();
66
67 public slots:
68    /// Process of mouse move
69    /// \param theWnd a pointer to a window
70    /// \param theEvent a mouse event
71   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
72
73   protected slots:
74    /// Process of mouse release
75    /// \param theWnd a pointer to a window
76    /// \param theEvent a mouse event
77   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
78
79 protected:
80   /// Store current value in cashed value
81   void storeCurentValue();
82
83   /// Restore cashed value in the model attribute
84   /// \return boolean state if the restored feature shoud be hidden
85   bool restoreCurentValue();
86
87   /// Fills the widget with default values
88   /// \return true if the widget current value is reset
89   virtual bool resetCustom();
90
91   /// The methiod called when widget is activated
92   virtual void activateCustom();
93
94   /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
95   void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
96
97   /// Compute the distance between points
98   /// \param theFirstPnt a point value of the out point attribute
99   /// \param theCurrentPnt a point of the current widget
100   /// \return a double value
101   virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
102                               const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
103
104 protected:
105   /// A reference to workshop
106   ModuleBase_IWorkshop* myWorkshop;
107   
108   /// A name of the first point
109   std::string myFirstPntName;
110
111   /// Reference to sketch
112   CompositeFeaturePtr mySketch;
113
114   bool myValueIsCashed; ///< boolean state if the value is cashed during value state change
115   bool myIsFeatureVisibleInCash; ///< boolean value if the feature was visible when cash if filled
116   double myValueInCash; ///< the cashed X value during value state change
117 };
118
119 #endif