Salome HOME
63fe24778f7b285cd31143a814dec69e4537575f
[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 "PartSet_MouseProcessor.h"
12
13 #include <ModuleBase_WidgetDoubleValue.h>
14
15 #include <ModelAPI_CompositeFeature.h>
16
17 class GeomAPI_Pnt2d;
18 class ModuleBase_IWorkshop;
19 class ModuleBase_IViewWindow;
20 class QMouseEvent;
21
22 /**
23 * \ingroup Modules
24 * Implementation of model widget for widget which provides input of a distance between two points
25 * In XML file can be defined as following:
26 * \code
27 * <point2ddistance id="CircleRadius" 
28 *   first_point="CircleCenter" 
29 *   label="Radius:" 
30 *   min="0" 
31 *   step="1.0" 
32 *   default="0" 
33 *   icon=":icons/radius.png" 
34 *   tooltip="Set radius">
35 *   <validator id="GeomValidators_Positive"/>
36 * </point2ddistance>
37 * \endcode
38 */ 
39 class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue,
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_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
49                                 const Config_WidgetAPI* theData);
50
51   virtual ~PartSet_WidgetPoint2dDistance();
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   /// \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   /// Processing the mouse move event in the viewer
68   /// \param theWindow a view window
69   /// \param theEvent a mouse event
70   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
71
72   /// Processing the mouse release event in the viewer
73   /// \param theWindow a view window
74   /// \param theEvent a mouse event
75   virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
76
77 protected:
78   /// Store current value in cashed value
79   void storeCurentValue();
80
81   /// Restore cashed value in the model attribute
82   /// \return boolean state if the restored feature shoud be hidden
83   bool restoreCurentValue();
84
85   /// Fills the widget with default values
86   /// \return true if the widget current value is reset
87   virtual bool resetCustom();
88
89   /// Set the second point which defines a value in the widget as 
90   /// a distance with a first point defined by feature
91   void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
92
93   /// Compute the distance between points
94   /// \param theFirstPnt a point value of the out point attribute
95   /// \param theCurrentPnt a point of the current widget
96   /// \return a double value
97   virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
98                               const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
99
100 protected:
101   /// A reference to workshop
102   ModuleBase_IWorkshop* myWorkshop;
103   
104   /// A name of the first point
105   std::string myFirstPntName;
106
107   /// Reference to sketch
108   CompositeFeaturePtr mySketch;
109
110   bool myValueIsCashed; ///< boolean state if the value is cashed during value state change
111   bool myIsFeatureVisibleInCash; ///< boolean value if the feature was visible when cash if filled
112   double myValueInCash; ///< the cashed X value during value state change
113 };
114
115 #endif