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 void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
117 /// Signal about selection of an existing vertex from an object
118 void vertexSelected();
121 /// Saves the internal parameters to the given feature
122 /// \return True in success
123 virtual bool storeValueCustom();
125 /// Restore value from attribute data to the widget's control
126 virtual bool restoreValueCustom();
128 /// Store current value in cashed value
129 void storeCurentValue();
131 /// Restore cashed value in the model attribute
132 /// \return boolean state if the restored feature shoud be hidden
133 bool restoreCurentValue();
135 /// Fills the widget with default values
136 /// \return true if the widget current value is reset
137 virtual bool resetCustom();
139 /// The methiod called when widget is activated
140 virtual void activateCustom();
142 //! Switch On/Off highlighting of the widget
143 virtual void setHighlighted(bool isHighlighted);
145 /// Returns true if the feature contains Point2D attribute with the same coordinates
146 /// The attribute of the widget is not processed.
147 /// \param theFeature a feature
148 /// \param theX the X coordinate
149 /// \param theY the Y coordinate
150 /// \return boolean result
151 bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
154 /// Process value changed event
155 //void onValuesChanged();
157 /// Compute the feature default value and fill the controls with it
158 /// or store the control value to the feature
159 /// The widget is not initialize the attribute value in order to avoid the
160 /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
161 /// be visualized immediatelly when the end point widget is activated.
162 virtual void initializeValueByActivate();
165 /// Returns point 2d from selected vertex
166 /// \param theView a view window
167 /// \param theShape a vertex shape
168 /// \param theX an output value of X coordinate
169 /// \param theY an output value of Y coordinate
170 bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
171 double& theX, double& theY) const;
173 /// Create a coincidence constraint between the attribute and the parameter object
174 /// \theObject a result object
175 /// \return true if succed
176 bool setConstraintWith(const ObjectPtr& theObject);
178 /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
179 /// has no a coincident to other lines. It processes point, circle and arc features
180 /// In circle an arc features, only centers are processed, for other points, it returns
181 /// that the point is not an orphan.
182 /// \param theFeature a checked feature
183 /// \param theSketch a sketch
184 /// \param theX an X coordinate of the point
185 /// \param theY an Y coordinate of the point
186 /// \return boolean result
187 static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
188 double theX, double theY);
190 /// Explode the given shape by vertices and found closed to the point vertes
191 /// \param theShape a shape to be exploded
192 /// \param thePoint a point
193 /// \return boolean value
194 static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
195 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
196 const CompositeFeaturePtr& theSketch);
199 ModuleBase_IWorkshop* myWorkshop; ///< workshop
203 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
204 //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
205 //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
206 ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
207 ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
209 /// value used as selection in mouse release method
210 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
212 /// it is important during restart operation
213 CompositeFeaturePtr mySketch;
215 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
216 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
217 double myXValueInCash; /// the cashed X value during value state change
218 double myYValueInCash; /// the cashed Y value during value state change