Salome HOME
Issue #1664: In the Sketcher, add the function Split a segment: split of arc, move...
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.h
index ca95b75fd3ee11f0bd851fa1319dbc76d4a9985d..0836b20b1a22a84197fc7490dcf993e1362d8bc0 100644 (file)
 #define PartSet_WidgetPoint2dDistance_H
 
 #include "PartSet.h"
+#include "PartSet_MouseProcessor.h"
+
 #include <ModuleBase_WidgetDoubleValue.h>
 
 #include <ModelAPI_CompositeFeature.h>
 
 class GeomAPI_Pnt2d;
-class XGUI_Workshop;
+class ModuleBase_IWorkshop;
 class ModuleBase_IViewWindow;
 class QMouseEvent;
 
-class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue
+/**
+* \ingroup Modules
+* Implementation of model widget for widget which provides input of a distance between two points
+* In XML file can be defined as following:
+* \code
+* <point2ddistance id="CircleRadius" 
+*   first_point="CircleCenter" 
+*   label="Radius:" 
+*   min="0" 
+*   step="1.0" 
+*   default="0" 
+*   icon=":icons/radius.png" 
+*   tooltip="Set radius">
+*   <validator id="GeomValidators_Positive"/>
+* </point2ddistance>
+* \endcode
+*/ 
+class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetDoubleValue,
+                                                     public PartSet_MouseProcessor
 {
 Q_OBJECT
  public:
   /// Constructor
-  /// \theParent the parent object
-  /// \theData the widget configuation. The attribute of the model widget is obtained from
-  PartSet_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData,
-                                   const std::string& theParentId);
+  /// \param theParent the parent object
+  /// \param theWorkshop a current workshop
+  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+                                const Config_WidgetAPI* theData);
 
   virtual ~PartSet_WidgetPoint2dDistance();
 
-  /// The methiod called when widget is activated
-  virtual void activate();
-
-  /// The methiod called when widget is deactivated
-  virtual void deactivate();
-
-  /// Set the given wrapped value to the current widget
-  /// This value should be processed in the widget according to the needs
-  /// \param theValue the wrapped widget value
-  //virtual bool setValue(ModuleBase_WidgetValue* theValue);
-
-  XGUI_Workshop* workshop() const { return myWorkshop; }
-
-  void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
+  /// Checks if the selection presentation is valid in widget 
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
 
   /// \returns the sketch instance
   CompositeFeaturePtr sketch() const { return mySketch; }
+
+  /// Set sketch instance
   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
 
- protected slots:
-  void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
-  void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
+  /// Returns true if the event is processed.
+  virtual bool processEnter();
+
+  /// Processing the mouse move event in the viewer
+  /// \param theWindow a view window
+  /// \param theEvent a mouse event
+  virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
+
+  /// Processing the mouse release event in the viewer
+  /// \param theWindow a view window
+  /// \param theEvent a mouse event
+  virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
 
 protected:
+  /// Store current value in cashed value
+  void storeCurentValue();
+
+  /// Restore cashed value in the model attribute
+  /// \return boolean state if the restored feature shoud be hidden
+  bool restoreCurentValue();
+
+  /// Fills the widget with default values
+  /// \return true if the widget current value is reset
+  virtual bool resetCustom();
+
   /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
   void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
 
-private slots:
-  void onValuesChanged();
+  /// Compute the distance between points
+  /// \param theFirstPnt a point value of the out point attribute
+  /// \param theCurrentPnt a point of the current widget
+  /// \return a double value
+  virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
+                              const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
 
- private:
-  XGUI_Workshop* myWorkshop;
+protected:
+  /// A reference to workshop
+  ModuleBase_IWorkshop* myWorkshop;
+  
+  /// A name of the first point
   std::string myFirstPntName;
 
+  /// Reference to sketch
   CompositeFeaturePtr mySketch;
+
+  bool myValueIsCashed; ///< boolean state if the value is cashed during value state change
+  bool myIsFeatureVisibleInCash; ///< boolean value if the feature was visible when cash if filled
+  double myValueInCash; ///< the cashed X value during value state change
 };
 
 #endif