1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetPoint2dDistance.h
4 // Created: 23 June 2014
5 // Author: Vitaly Smetannikov
7 #ifndef PartSet_WidgetPoint2dDistance_H
8 #define PartSet_WidgetPoint2dDistance_H
11 #include <ModuleBase_WidgetDoubleValue.h>
13 #include <ModelAPI_CompositeFeature.h>
16 class ModuleBase_IWorkshop;
17 class ModuleBase_IViewWindow;
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:
25 * <point2ddistance id="CircleRadius"
26 * first_point="CircleCenter"
31 * icon=":icons/radius.png"
32 * tooltip="Set radius">
33 * <validator id="GeomValidators_Positive"/>
37 class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue
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);
48 virtual ~PartSet_WidgetPoint2dDistance();
50 /// The methiod called when widget is deactivated
51 virtual void deactivate();
53 /// \returns the sketch instance
54 CompositeFeaturePtr sketch() const { return mySketch; }
56 /// Set sketch instance
57 void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
59 /// Returns true if the event is processed.
60 virtual bool processEnter();
63 /// Process of mouse move
64 /// \param theWnd a pointer to a window
65 /// \param theEvent a mouse event
66 void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
69 /// Process of mouse release
70 /// \param theWnd a pointer to a window
71 /// \param theEvent a mouse event
72 void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
75 /// Store current value in cashed value
76 void storeCurentValue();
78 /// Restore cashed value in the model attribute
79 /// \return boolean state if the restored feature shoud be hidden
80 bool restoreCurentValue();
82 /// Fills the widget with default values
83 /// \return true if the widget current value is reset
84 virtual bool resetCustom();
86 /// The methiod called when widget is activated
87 virtual void activateCustom();
89 /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
90 void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
92 /// Compute the distance between points
93 /// \param theFirstPnt a point value of the out point attribute
94 /// \param theCurrentPnt a point of the current widget
95 /// \return a double value
96 virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
97 const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
100 /// A reference to workshop
101 ModuleBase_IWorkshop* myWorkshop;
103 /// A name of the first point
104 std::string myFirstPntName;
106 /// Reference to sketch
107 CompositeFeaturePtr mySketch;
109 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
110 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
111 double myValueInCash; /// the cashed X value during value state change