Salome HOME
"2.11 Constraint with a point from the intersection between an outer edge and plane...
[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   /// \param theParentId is Id of a parent of the current attribute
46    PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
47                                  const Config_WidgetAPI* theData,
48                                  const std::string& theParentId);
49
50   virtual ~PartSet_WidgetPoint2dDistance();
51
52   /// The methiod called when widget is deactivated
53   virtual void deactivate();
54
55   /// \returns the sketch instance
56   CompositeFeaturePtr sketch() const { return mySketch; }
57
58   /// Set sketch instance
59   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
60
61   /// Returns true if the event is processed.
62   virtual bool processEnter();
63
64 public slots:
65    /// Process of mouse move
66    /// \param theWnd a pointer to a window
67    /// \param theEvent a mouse event
68   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
69
70   protected slots:
71    /// Process of mouse release
72    /// \param theWnd a pointer to a window
73    /// \param theEvent a mouse event
74   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
75
76 protected:
77   /// The methiod called when widget is activated
78   virtual void activateCustom();
79
80   /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
81   void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
82
83   /// Compute the distance between points
84   /// \param theFirstPnt a point value of the out point attribute
85   /// \param theCurrentPnt a point of the current widget
86   /// \return a double value
87   virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
88                               const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
89
90 protected:
91   /// A reference to workshop
92   ModuleBase_IWorkshop* myWorkshop;
93   
94   /// A name of the first point
95   std::string myFirstPntName;
96
97   /// Reference to sketch
98   CompositeFeaturePtr mySketch;
99 };
100
101 #endif