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;
28 class PartSet_ExternalObjectsMgr;
30 class ModuleBase_IWorkshop;
35 /**\class PartSet_WidgetPoint2D
37 * \brief Implementation of model widget to provide widget to input point 2d
38 * In XML can be defined as folloung:
40 * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
43 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget,
44 public PartSet_MouseProcessor
49 /// \param theParent the parent object
50 /// \param theWorkshop a current workshop
51 /// \param theData the widget configuation. The attribute of the model widget is obtained from
52 PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
53 const Config_WidgetAPI* theData);
55 virtual ~PartSet_WidgetPoint2D();
57 /// Checks if the selection presentation is valid in widget
58 /// \param theValue a selected presentation in the view
59 /// \return a boolean value
60 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
62 /// Checks all attribute validators returns valid. It tries on the given selection
63 /// to current attribute by setting the value inside and calling validators. After this,
64 /// the previous attribute value is restored.The valid/invalid value is cashed.
65 /// \param theValue a selected presentation in the view
66 /// \param theAttribute the attribute
67 /// \return a boolean value
68 bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
69 const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
71 /// Fills the attribute with the value of the selected owner
72 /// \param thePrs a selected owner
73 bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
75 /// Set the given wrapped value to the current widget
76 /// This value should be processed in the widget according to the needs
77 /// \param theValues the wrapped widget values
78 /// \param theToValidate a validation flag
79 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
80 const bool theToValidate);
82 /// Select the internal content if it can be selected. It is empty in the default realization
83 virtual void selectContent();
85 /// Returns list of widget controls
86 /// \return a control list
87 virtual QList<QWidget*> getControls() const;
89 //bool initFromPrevious(ObjectPtr theObject);
91 /// The methiod called when widget is deactivated
92 virtual void deactivate();
94 /// \returns the sketch instance
95 CompositeFeaturePtr sketch() const { return mySketch; }
97 /// Set sketch instance
98 void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
100 /// Fill the widget values by given point
101 /// \param theX the X coordinate
102 /// \param theY the Y coordinate
103 /// \returns True in case of success
104 bool setPoint(double theX, double theY);
106 /// Returns coordinate X currently defined in the control
109 /// Returns coordinate Y currently defined in the control
112 /// Returns true if the event is processed.
113 virtual bool processEnter();
115 /// Returns true if the attribute can be changed using the selected shapes in the viewer
116 /// and creating a coincidence constraint to them. This control use them.
117 virtual bool useSelectedShapes() const;
119 /// Processing the mouse move event in the viewer
120 /// \param theWindow a view window
121 /// \param theEvent a mouse event
122 virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
124 /// Processing the mouse release event in the viewer
125 /// \param theWindow a view window
126 /// \param theEvent a mouse event
127 virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
129 /// Fill preselection used in mouseReleased
130 //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
131 virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
132 ModuleBase_IViewWindow* theWnd,
133 QMouseEvent* theEvent);
135 /// Return an object and geom shape by the viewer presentation
136 /// \param thePrs a selection
137 /// \param theObject an output object
138 /// \param theShape a shape of the selection
139 void getGeomSelection_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
140 std::shared_ptr<ModelAPI_Object>& theObject,
141 std::shared_ptr<GeomAPI_Shape>& theShape);
144 /// Signal about selection of an existing vertex from an object
145 void vertexSelected();
148 /// Saves the internal parameters to the given feature
149 /// \return True in success
150 virtual bool storeValueCustom();
152 /// Restore value from attribute data to the widget's control
153 virtual bool restoreValueCustom();
155 /// Store current value in cashed value
156 void storeCurentValue();
158 /// Restore cashed value in the model attribute
159 /// \return boolean state if the restored feature shoud be hidden
160 bool restoreCurentValue();
162 /// Fills the widget with default values
163 /// \return true if the widget current value is reset
164 virtual bool resetCustom();
166 /// The methiod called when widget is activated
167 virtual void activateCustom();
169 //! Switch On/Off highlighting of the widget
170 virtual void setHighlighted(bool isHighlighted);
172 /// Returns true if the feature contains Point2D attribute with the same coordinates
173 /// The attribute of the widget is not processed.
174 /// \param theFeature a feature
175 /// \param theX the X coordinate
176 /// \param theY the Y coordinate
177 /// \return boolean result
178 bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
181 /// Process value changed event
182 //void onValuesChanged();
184 /// Compute the feature default value and fill the controls with it
185 /// or store the control value to the feature
186 /// The widget is not initialize the attribute value in order to avoid the
187 /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
188 /// be visualized immediatelly when the end point widget is activated.
189 virtual void initializeValueByActivate();
192 /// Returns point 2d from selected vertex
193 /// \param theView a view window
194 /// \param theShape a vertex shape
195 /// \param theX an output value of X coordinate
196 /// \param theY an output value of Y coordinate
197 bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
198 double& theX, double& theY) const;
200 /// Creates constrains of the clicked point
201 /// \param theClickedX the horizontal coordnate of the point
202 /// \param theClickedY the vertical coordnate of the point
203 bool setConstraintToPoint(double theClickedX, double theClickedY,
204 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
206 /// Create a coincidence constraint between the attribute and the parameter object
207 /// \theObject a result object
208 /// \return true if succed
209 bool setConstraintToObject(const ObjectPtr& theObject);
211 /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
212 /// has no a coincident to other lines. It processes point, circle and arc features
213 /// In circle an arc features, only centers are processed, for other points, it returns
214 /// that the point is not an orphan.
215 /// \param theFeature a checked feature
216 /// \param theSketch a sketch
217 /// \param theX an X coordinate of the point
218 /// \param theY an Y coordinate of the point
219 /// \return boolean result
220 static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
221 double theX, double theY);
223 /// Explode the given shape by vertices and found closed to the point vertes
224 /// \param theShape a shape to be exploded
225 /// \param thePoint a point
226 /// \return boolean value
227 static bool shapeExploreHasVertex(const std::shared_ptr<GeomAPI_Shape>& theShape,
228 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
229 const CompositeFeaturePtr& theSketch);
231 /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
232 /// \param theFeature a feature with sub-feature attributes
233 /// \param thePoint a point to provided searched coordinates
234 /// \return found point or null
235 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
236 const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
238 /// Finds in the feature first Point2D attribute with the given point coordinates
239 /// \param theFeature a feature with point attributes
240 /// \param thePoint a point to provided searched coordinates
241 /// \return found point or null
242 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
243 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
245 /// Finds in the sketch attribute point of any feature that is nearest to the given point
246 /// \param theSketch a sketch, that is a container of features
247 /// \param theSkipFeature a feature that do not participate in the search
248 /// \param thePoint a point to provided searched coordinates
249 /// \return found point or null
250 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInSketch(
251 const CompositeFeaturePtr& theSketch,
252 const FeaturePtr& theSkipFeature,
253 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
255 /// Returns attribute reference if the key is defined in XML definition of this control
256 /// \return found attribute or null
257 std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
259 /// Finds first equal point attribute in sketch and set it to reference attribute
260 /// \param theClickedX the horizontal coordnate of the point
261 /// \param theClickedY the vertical coordnate of the point
262 void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
263 void fillRefAttribute(double theClickedX, double theClickedY,
264 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
265 void fillRefAttribute(const ObjectPtr& theObject);
267 ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
270 ModuleBase_IWorkshop* myWorkshop; ///< workshop
273 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
274 //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
275 //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
276 ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
277 ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
278 PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
280 /// value used as selection in mouse release method
281 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
283 /// it is important during restart operation
284 CompositeFeaturePtr mySketch;
286 std::string myRefAttribute; /// if not empty, coincidences are not set but attribute is filled
287 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
288 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
289 double myXValueInCash; /// the cashed X value during value state change
290 double myYValueInCash; /// the cashed Y value during value state change