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 ModelAPI_AttributeRefAttr;
23 class GeomDataAPI_Point2D;
24 class ModuleBase_IWorkshop;
25 class ModuleBase_ParamSpinBox;
26 class ModuleBase_IViewWindow;
27 class ModuleBase_LabelValue;
29 class ModuleBase_IWorkshop;
34 /**\class PartSet_WidgetPoint2D
36 * \brief Implementation of model widget to provide widget to input point 2d
37 * In XML can be defined as folloung:
39 * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
42 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget,
43 public PartSet_MouseProcessor
48 /// \param theParent the parent object
49 /// \param theWorkshop a current workshop
50 /// \param theData the widget configuation. The attribute of the model widget is obtained from
51 PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
52 const Config_WidgetAPI* theData);
54 virtual ~PartSet_WidgetPoint2D();
56 /// Checks if the selection presentation is valid in widget
57 /// \param theValue a selected presentation in the view
58 /// \return a boolean value
59 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
61 /// Checks all attribute validators returns valid. It tries on the given selection
62 /// to current attribute by setting the value inside and calling validators. After this,
63 /// the previous attribute value is restored.The valid/invalid value is cashed.
64 /// \param theValue a selected presentation in the view
65 /// \param theAttribute the attribute
66 /// \return a boolean value
67 bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
68 const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
70 /// Fills the attribute with the value of the selected owner
71 /// \param thePrs a selected owner
72 bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
74 /// Set the given wrapped value to the current widget
75 /// This value should be processed in the widget according to the needs
76 /// \param theValues the wrapped widget values
77 /// \param theToValidate a validation flag
78 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
79 const bool theToValidate);
81 /// Select the internal content if it can be selected. It is empty in the default realization
82 virtual void selectContent();
84 /// Returns list of widget controls
85 /// \return a control list
86 virtual QList<QWidget*> getControls() const;
88 //bool initFromPrevious(ObjectPtr theObject);
90 /// The methiod called when widget is deactivated
91 virtual void deactivate();
93 /// \returns the sketch instance
94 CompositeFeaturePtr sketch() const { return mySketch; }
96 /// Set sketch instance
97 void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
99 /// Fill the widget values by given point
100 /// \param theX the X coordinate
101 /// \param theY the Y coordinate
102 /// \returns True in case of success
103 bool setPoint(double theX, double theY);
105 /// Returns coordinate X currently defined in the control
108 /// Returns coordinate Y currently defined in the control
111 /// Returns true if the event is processed.
112 virtual bool processEnter();
114 /// Returns true if the attribute can be changed using the selected shapes in the viewer
115 /// and creating a coincidence constraint to them. This control use them.
116 virtual bool useSelectedShapes() const;
118 /// Processing the mouse move event in the viewer
119 /// \param theWindow a view window
120 /// \param theEvent a mouse event
121 virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
123 /// Processing the mouse release event in the viewer
124 /// \param theWindow a view window
125 /// \param theEvent a mouse event
126 virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
128 /// Fill preselection used in mouseReleased
129 //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
130 virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
131 ModuleBase_IViewWindow* theWnd,
132 QMouseEvent* theEvent);
135 /// Signal about selection of an existing vertex from an object
136 void vertexSelected();
139 /// Saves the internal parameters to the given feature
140 /// \return True in success
141 virtual bool storeValueCustom();
143 /// Restore value from attribute data to the widget's control
144 virtual bool restoreValueCustom();
146 /// Store current value in cashed value
147 void storeCurentValue();
149 /// Restore cashed value in the model attribute
150 /// \return boolean state if the restored feature shoud be hidden
151 bool restoreCurentValue();
153 /// Fills the widget with default values
154 /// \return true if the widget current value is reset
155 virtual bool resetCustom();
157 /// The methiod called when widget is activated
158 virtual void activateCustom();
160 //! Switch On/Off highlighting of the widget
161 virtual void setHighlighted(bool isHighlighted);
163 /// Returns true if the feature contains Point2D attribute with the same coordinates
164 /// The attribute of the widget is not processed.
165 /// \param theFeature a feature
166 /// \param theX the X coordinate
167 /// \param theY the Y coordinate
168 /// \return boolean result
169 bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
172 /// Process value changed event
173 //void onValuesChanged();
175 /// Compute the feature default value and fill the controls with it
176 /// or store the control value to the feature
177 /// The widget is not initialize the attribute value in order to avoid the
178 /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
179 /// be visualized immediatelly when the end point widget is activated.
180 virtual void initializeValueByActivate();
183 /// Returns point 2d from selected vertex
184 /// \param theView a view window
185 /// \param theShape a vertex shape
186 /// \param theX an output value of X coordinate
187 /// \param theY an output value of Y coordinate
188 bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
189 double& theX, double& theY) const;
191 /// Creates constrains of the clicked point
192 /// \param theClickedX the horizontal coordnate of the point
193 /// \param theClickedY the vertical coordnate of the point
194 bool setConstraintToPoint(double theClickedX, double theClickedY);
196 /// Create a coincidence constraint between the attribute and the parameter object
197 /// \theObject a result object
198 /// \return true if succed
199 bool setConstraintToObject(const ObjectPtr& theObject);
201 /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
202 /// has no a coincident to other lines. It processes point, circle and arc features
203 /// In circle an arc features, only centers are processed, for other points, it returns
204 /// that the point is not an orphan.
205 /// \param theFeature a checked feature
206 /// \param theSketch a sketch
207 /// \param theX an X coordinate of the point
208 /// \param theY an Y coordinate of the point
209 /// \return boolean result
210 static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
211 double theX, double theY);
213 /// Explode the given shape by vertices and found closed to the point vertes
214 /// \param theShape a shape to be exploded
215 /// \param thePoint a point
216 /// \return boolean value
217 static bool shapeExploreHasVertex(const std::shared_ptr<GeomAPI_Shape>& theShape,
218 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
219 const CompositeFeaturePtr& theSketch);
221 /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
222 /// \param theFeature a feature with sub-feature attributes
223 /// \param thePoint a point to provided searched coordinates
224 /// \return found point or null
225 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
226 const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
228 /// Finds in the feature first Point2D attribute with the given point coordinates
229 /// \param theFeature a feature with point attributes
230 /// \param thePoint a point to provided searched coordinates
231 /// \return found point or null
232 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
233 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
235 /// Finds in the sketch attribute point of any feature that is nearest to the given point
236 /// \param theSketch a sketch, that is a container of features
237 /// \param theSkipFeature a feature that do not participate in the search
238 /// \param thePoint a point to provided searched coordinates
239 /// \return found point or null
240 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInSketch(
241 const CompositeFeaturePtr& theSketch,
242 const FeaturePtr& theSkipFeature,
243 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
245 /// Returns attribute reference if the key is defined in XML definition of this control
246 /// \return found attribute or null
247 std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
249 /// Finds first equal point attribute in sketch and set it to reference attribute
250 /// \param theClickedX the horizontal coordnate of the point
251 /// \param theClickedY the vertical coordnate of the point
252 void fillRefAttribute(double theClickedX, double theClickedY);
253 void fillRefAttribute(const ObjectPtr& theObject);
256 ModuleBase_IWorkshop* myWorkshop; ///< workshop
259 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
260 //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
261 //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
262 ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
263 ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
265 /// value used as selection in mouse release method
266 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
268 /// it is important during restart operation
269 CompositeFeaturePtr mySketch;
271 std::string myRefAttribute; /// if not empty, coincidences are not set but attribute is filled
272 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
273 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
274 double myXValueInCash; /// the cashed X value during value state change
275 double myYValueInCash; /// the cashed Y value during value state change