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 "PartSet_MouseProcessor.h"
13 #include <ModelAPI_CompositeFeature.h>
14 #include <ModuleBase_ModelWidget.h>
18 #include <TopoDS_Shape.hxx>
19 #include <V3d_View.hxx>
21 class ModelAPI_Feature;
22 class ModuleBase_IWorkshop;
23 class ModuleBase_ParamSpinBox;
24 class ModuleBase_IViewWindow;
25 class ModuleBase_LabelValue;
27 class ModuleBase_IWorkshop;
32 /**\class PartSet_WidgetPoint2D
34 * \brief Implementation of model widget to provide widget to input point 2d
35 * In XML can be defined as folloung:
37 * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
40 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget,
41 public PartSet_MouseProcessor
46 /// \param theParent the parent object
47 /// \param theWorkshop a current workshop
48 /// \param theData the widget configuation. The attribute of the model widget is obtained from
49 PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
50 const Config_WidgetAPI* theData);
52 virtual ~PartSet_WidgetPoint2D();
54 /// Checks if the selection presentation is valid in widget
55 /// \param theValue a selected presentation in the view
56 /// \return a boolean value
57 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
59 /// Set the given wrapped value to the current widget
60 /// This value should be processed in the widget according to the needs
61 /// \param theValues the wrapped widget values
62 /// \param theToValidate a validation flag
63 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
64 const bool theToValidate);
66 /// Select the internal content if it can be selected. It is empty in the default realization
67 virtual void selectContent();
69 /// Returns list of widget controls
70 /// \return a control list
71 virtual QList<QWidget*> getControls() const;
73 //bool initFromPrevious(ObjectPtr theObject);
75 /// The methiod called when widget is deactivated
76 virtual void deactivate();
78 /// \returns the sketch instance
79 CompositeFeaturePtr sketch() const { return mySketch; }
81 /// Set sketch instance
82 void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
84 /// Fill the widget values by given point
85 /// \param theX the X coordinate
86 /// \param theY the Y coordinate
87 /// \returns True in case of success
88 bool setPoint(double theX, double theY);
90 /// Returns coordinate X currently defined in the control
93 /// Returns coordinate Y currently defined in the control
96 /// Returns true if the event is processed.
97 virtual bool processEnter();
99 /// Returns true if the attribute can be changed using the selected shapes in the viewer
100 /// and creating a coincidence constraint to them. This control use them.
101 virtual bool useSelectedShapes() const;
103 /// Processing the mouse move event in the viewer
104 /// \param theWindow a view window
105 /// \param theEvent a mouse event
106 virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
108 /// Processing the mouse release event in the viewer
109 /// \param theWindow a view window
110 /// \param theEvent a mouse event
111 virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
113 /// Fill preselection used in mouseReleased
114 //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
115 virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
116 ModuleBase_IViewWindow* theWnd,
117 QMouseEvent* theEvent);
120 /// Signal about selection of an existing vertex from an object
121 void vertexSelected();
124 /// Saves the internal parameters to the given feature
125 /// \return True in success
126 virtual bool storeValueCustom();
128 /// Restore value from attribute data to the widget's control
129 virtual bool restoreValueCustom();
131 /// Store current value in cashed value
132 void storeCurentValue();
134 /// Restore cashed value in the model attribute
135 /// \return boolean state if the restored feature shoud be hidden
136 bool restoreCurentValue();
138 /// Fills the widget with default values
139 /// \return true if the widget current value is reset
140 virtual bool resetCustom();
142 /// The methiod called when widget is activated
143 virtual void activateCustom();
145 //! Switch On/Off highlighting of the widget
146 virtual void setHighlighted(bool isHighlighted);
148 /// Returns true if the feature contains Point2D attribute with the same coordinates
149 /// The attribute of the widget is not processed.
150 /// \param theFeature a feature
151 /// \param theX the X coordinate
152 /// \param theY the Y coordinate
153 /// \return boolean result
154 bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
157 /// Process value changed event
158 //void onValuesChanged();
160 /// Compute the feature default value and fill the controls with it
161 /// or store the control value to the feature
162 /// The widget is not initialize the attribute value in order to avoid the
163 /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
164 /// be visualized immediatelly when the end point widget is activated.
165 virtual void initializeValueByActivate();
168 /// Returns point 2d from selected vertex
169 /// \param theView a view window
170 /// \param theShape a vertex shape
171 /// \param theX an output value of X coordinate
172 /// \param theY an output value of Y coordinate
173 bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
174 double& theX, double& theY) const;
176 /// Create a coincidence constraint between the attribute and the parameter object
177 /// \theObject a result object
178 /// \return true if succed
179 bool setConstraintWith(const ObjectPtr& theObject);
181 /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
182 /// has no a coincident to other lines. It processes point, circle and arc features
183 /// In circle an arc features, only centers are processed, for other points, it returns
184 /// that the point is not an orphan.
185 /// \param theFeature a checked feature
186 /// \param theSketch a sketch
187 /// \param theX an X coordinate of the point
188 /// \param theY an Y coordinate of the point
189 /// \return boolean result
190 static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
191 double theX, double theY);
193 /// Explode the given shape by vertices and found closed to the point vertes
194 /// \param theShape a shape to be exploded
195 /// \param thePoint a point
196 /// \return boolean value
197 static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
198 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
199 const CompositeFeaturePtr& theSketch);
202 ModuleBase_IWorkshop* myWorkshop; ///< workshop
206 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
207 //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
208 //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
209 ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
210 ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
212 /// value used as selection in mouse release method
213 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
215 /// it is important during restart operation
216 CompositeFeaturePtr mySketch;
218 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
219 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
220 double myXValueInCash; /// the cashed X value during value state change
221 double myYValueInCash; /// the cashed Y value during value state change