1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetPoint2d.h
4 // Created: 25 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef PartSet_WidgetPoint2D_H
8 #define PartSet_WidgetPoint2D_H
11 #include <ModelAPI_CompositeFeature.h>
12 #include <ModuleBase_ModelWidget.h>
16 #include <TopoDS_Shape.hxx>
17 #include <V3d_View.hxx>
19 class ModelAPI_Feature;
20 class ModuleBase_IWorkshop;
21 class ModuleBase_ParamSpinBox;
22 class ModuleBase_IViewWindow;
24 class ModuleBase_IWorkshop;
29 /**\class PartSet_WidgetPoint2D
31 * \brief Implementation of model widget to provide widget to input point 2d
32 * In XML can be defined as folloung:
34 * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
37 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget
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_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
47 const Config_WidgetAPI* theData,
48 const std::string& theParentId);
50 virtual ~PartSet_WidgetPoint2D();
52 /// Set the given wrapped value to the current widget
53 /// This value should be processed in the widget according to the needs
54 /// \param theValues the wrapped widget values
55 /// \param theToValidate a validation flag
56 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
57 const bool theToValidate);
59 /// Returns list of widget controls
60 /// \return a control list
61 virtual QList<QWidget*> getControls() const;
63 //bool initFromPrevious(ObjectPtr theObject);
65 /// Defines if the widget can be activated by mouse move.
66 /// By default it returns false
67 virtual bool canBeActivatedByMove();
69 /// The methiod called when widget is deactivated
70 virtual void deactivate();
72 /// \returns the sketch instance
73 CompositeFeaturePtr sketch() const { return mySketch; }
75 /// Set sketch instance
76 void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
78 /// Fill the widget values by given point
79 /// \param theX the X coordinate
80 /// \param theY the Y coordinate
81 /// \returns True in case of success
82 bool setPoint(double theX, double theY);
84 /// Returns coordinate X currently defined in the control
87 /// Returns coordinate Y currently defined in the control
90 /// Returns true if the event is processed.
91 virtual bool processEnter();
94 /// Signal about selection of an existing vertex from an object
95 void vertexSelected();
98 /// Process mouse move event
99 /// \param theWnd a view window
100 /// \param theEvent a mouse event
101 void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
103 /// Process mouse release event
104 /// \param theWnd a view window
105 /// \param theEvent a mouse event
106 void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
109 /// Saves the internal parameters to the given feature
110 /// \return True in success
111 virtual bool storeValueCustom() const;
113 virtual bool restoreValueCustom();
115 /// Fills the widget with default values
116 /// \return true if the widget current value is reset
117 virtual bool resetCustom();
119 /// The methiod called when widget is activated
120 virtual void activateCustom();
122 /// Returns true if the feature contains Point2D attribute with the same coordinates
123 /// The attribute of the widget is not processed.
124 /// \param theFeature a feature
125 /// \param theX the X coordinate
126 /// \param theY the Y coordinate
127 /// \return boolean result
128 bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
131 /// Process value changed event
132 //void onValuesChanged();
135 /// Returns point 2d from selected vertex
136 /// \param theView a view window
137 /// \param theShape a vertex shape
138 /// \param theX an output value of X coordinate
139 /// \param theY an output value of Y coordinate
140 bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
141 double& theX, double& theY) const;
143 /// Create a coincidence constraint between the attribute and the parameter object
144 /// \theObject a result object
145 void setConstraintWith(const ObjectPtr& theObject);
148 ModuleBase_IWorkshop* myWorkshop;
152 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
153 ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
154 ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
156 //std::string myOptionParam; /// Parameter name which has to be taken from previous feature
158 CompositeFeaturePtr mySketch;