1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef PartSet_WidgetPoint2D_H
21 #define PartSet_WidgetPoint2D_H
24 #include "PartSet_MouseProcessor.h"
26 #include <ModelAPI_CompositeFeature.h>
27 #include <ModuleBase_ModelWidget.h>
31 #include <TopoDS_Shape.hxx>
32 #include <V3d_View.hxx>
34 class ModelAPI_Feature;
35 class ModelAPI_AttributeRefAttr;
36 class GeomDataAPI_Point2D;
37 class ModuleBase_IWorkshop;
38 class ModuleBase_ParamSpinBox;
39 class ModuleBase_IViewWindow;
40 class ModuleBase_LabelValue;
41 class PartSet_ExternalObjectsMgr;
43 class ModuleBase_IWorkshop;
48 /**\class PartSet_WidgetPoint2D
50 * \brief Implementation of model widget to provide widget to input point 2d
51 * In XML can be defined as folloung:
53 * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
56 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget,
57 public PartSet_MouseProcessor
62 /// \param theParent the parent object
63 /// \param theWorkshop a current workshop
64 /// \param theData the widget configuation. The attribute of the model widget is obtained from
65 PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
66 const Config_WidgetAPI* theData);
68 virtual ~PartSet_WidgetPoint2D();
70 /// Checks if the selection presentation is valid in widget
71 /// \param theValue a selected presentation in the view
72 /// \return a boolean value
73 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
75 /// Checks all attribute validators returns valid. It tries on the given selection
76 /// to current attribute by setting the value inside and calling validators. After this,
77 /// the previous attribute value is restored.The valid/invalid value is cashed.
78 /// \param theValue a selected presentation in the view
79 /// \param theAttribute the attribute
80 /// \return a boolean value
81 bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
82 const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
84 /// Fills the attribute with the value of the selected owner
85 /// \param thePrs a selected owner
86 bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
88 /// Set the given wrapped value to the current widget
89 /// This value should be processed in the widget according to the needs
90 /// \param theValues the wrapped widget values
91 /// \param theToValidate a validation flag
92 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
93 const bool theToValidate);
95 /// Select the internal content if it can be selected. It is empty in the default realization
96 virtual void selectContent();
98 /// Returns list of widget controls
99 /// \return a control list
100 virtual QList<QWidget*> getControls() const;
102 //bool initFromPrevious(ObjectPtr theObject);
104 /// The methiod called when widget is deactivated
105 virtual void deactivate();
107 /// \returns the sketch instance
108 CompositeFeaturePtr sketch() const { return mySketch; }
110 /// Set sketch instance
111 void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
113 /// Fill the widget values by given point
114 /// \param theX the X coordinate
115 /// \param theY the Y coordinate
116 /// \returns True in case of success
117 bool setPoint(double theX, double theY);
119 /// Returns coordinate X currently defined in the control
122 /// Returns coordinate Y currently defined in the control
125 /// Returns true if the event is processed.
126 virtual bool processEnter();
128 /// Returns true if the attribute can be changed using the selected shapes in the viewer
129 /// and creating a coincidence constraint to them. This control use them.
130 virtual bool useSelectedShapes() const;
132 /// Processing the mouse move event in the viewer
133 /// \param theWindow a view window
134 /// \param theEvent a mouse event
135 virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
137 /// Processing the mouse release event in the viewer
138 /// \param theWindow a view window
139 /// \param theEvent a mouse event
140 virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
142 /// Fill preselection used in mouseReleased
143 //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
144 virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
145 ModuleBase_IViewWindow* theWnd,
146 QMouseEvent* theEvent);
148 /// Return an object and geom shape by the viewer presentation
149 /// \param thePrs a selection
150 /// \param theObject an output object
151 /// \param theShape a shape of the selection
152 void getGeomSelection_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
153 std::shared_ptr<ModelAPI_Object>& theObject,
154 std::shared_ptr<GeomAPI_Shape>& theShape);
157 /// Signal about selection of an existing vertex from an object
158 void vertexSelected();
161 /// Saves the internal parameters to the given feature
162 /// \return True in success
163 virtual bool storeValueCustom();
165 /// Restore value from attribute data to the widget's control
166 virtual bool restoreValueCustom();
168 /// Store current value in cashed value
169 void storeCurentValue();
171 /// Restore cashed value in the model attribute
172 /// \return boolean state if the restored feature shoud be hidden
173 bool restoreCurentValue();
175 /// Fills the widget with default values
176 /// \return true if the widget current value is reset
177 virtual bool resetCustom();
179 /// The methiod called when widget is activated
180 virtual void activateCustom();
182 //! Switch On/Off highlighting of the widget
183 virtual void setHighlighted(bool isHighlighted);
185 /// Returns true if the feature contains Point2D attribute with the same coordinates
186 /// The attribute of the widget is not processed.
187 /// \param theFeature a feature
188 /// \param theX the X coordinate
189 /// \param theY the Y coordinate
190 /// \return boolean result
191 bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
194 /// Process value changed event
195 //void onValuesChanged();
197 /// Compute the feature default value and fill the controls with it
198 /// or store the control value to the feature
199 /// The widget is not initialize the attribute value in order to avoid the
200 /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
201 /// be visualized immediatelly when the end point widget is activated.
202 virtual void initializeValueByActivate();
205 /// Returns point 2d from selected vertex
206 /// \param theView a view window
207 /// \param theShape a vertex shape
208 /// \param theX an output value of X coordinate
209 /// \param theY an output value of Y coordinate
210 bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
211 double& theX, double& theY) const;
213 /// Creates constrains of the clicked point
214 /// \param theClickedX the horizontal coordnate of the point
215 /// \param theClickedY the vertical coordnate of the point
216 bool setConstraintToPoint(double theClickedX, double theClickedY,
217 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
219 /// Create a coincidence constraint between the attribute and the parameter object
220 /// \theObject a result object
221 /// \return true if succed
222 bool setConstraintToObject(const ObjectPtr& theObject);
224 /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
225 /// has no a coincident to other lines. It processes point, circle and arc features
226 /// In circle an arc features, only centers are processed, for other points, it returns
227 /// that the point is not an orphan.
228 /// \param theFeature a checked feature
229 /// \param theSketch a sketch
230 /// \param theX an X coordinate of the point
231 /// \param theY an Y coordinate of the point
232 /// \return boolean result
233 static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
234 double theX, double theY);
236 /// Explode the given shape by vertices and found closed to the point vertes
237 /// \param theShape a shape to be exploded
238 /// \param thePoint a point
239 /// \return boolean value
240 static bool shapeExploreHasVertex(const std::shared_ptr<GeomAPI_Shape>& theShape,
241 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
242 const CompositeFeaturePtr& theSketch);
244 /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
245 /// \param theFeature a feature with sub-feature attributes
246 /// \param thePoint a point to provided searched coordinates
247 /// \return found point or null
248 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
249 const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
251 /// Finds in the feature first Point2D attribute with the given point coordinates
252 /// \param theFeature a feature with point attributes
253 /// \param thePoint a point to provided searched coordinates
254 /// \return found point or null
255 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
256 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
258 /// Finds in the sketch attribute point of any feature that is nearest to the given point
259 /// \param theSketch a sketch, that is a container of features
260 /// \param theSkipFeature a feature that do not participate in the search
261 /// \param thePoint a point to provided searched coordinates
262 /// \return found point or null
263 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInSketch(
264 const CompositeFeaturePtr& theSketch,
265 const FeaturePtr& theSkipFeature,
266 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
268 /// Returns attribute reference if the key is defined in XML definition of this control
269 /// \return found attribute or null
270 std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
272 /// Finds first equal point attribute in sketch and set it to reference attribute
273 /// \param theClickedX the horizontal coordnate of the point
274 /// \param theClickedY the vertical coordnate of the point
275 void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
276 void fillRefAttribute(double theClickedX, double theClickedY,
277 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
278 void fillRefAttribute(const ObjectPtr& theObject);
280 ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
283 ModuleBase_IWorkshop* myWorkshop; ///< workshop
286 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
287 //ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate
288 //ModuleBase_ParamSpinBox* myYSpin; ///< the spin box for the Y coordinate
289 ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
290 ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
291 PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
293 /// value used as selection in mouse release method
294 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
296 /// it is important during restart operation
297 CompositeFeaturePtr mySketch;
299 std::string myRefAttribute; /// if not empty, coincidences are not set but attribute is filled
300 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
301 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
302 double myXValueInCash; /// the cashed X value during value state change
303 double myYValueInCash; /// the cashed Y value during value state change