Salome HOME
OCC functionality moving out from the widget
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Utils.h
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef CURVECREATOR_UTILS_H
21 #define CURVECREATOR_UTILS_H
22
23 #include "CurveCreator_Macro.hxx"
24
25 #include <AIS_InteractiveContext.hxx>
26 #include <V3d_View.hxx>
27 #include <gp_Pnt.hxx>
28 #include <Geom_Curve.hxx>
29
30 #include <list>
31
32 class CurveCreator_Utils
33 {
34 public:
35
36     /*!
37    * \brief Returns the point clicked in 3D view.
38    *
39    * \param x The X coordinate in the view.
40    * \param y The Y coordinate in the view.
41    * \param theView View where the given point takes place.
42    * \retval gp_Pnt Returns the point clicked in 3D view
43    */
44   CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint,
45                                                        Handle(V3d_View) theView,
46                                                        int& x, int& y );
47
48   /*!
49    * \brief Returns the point clicked in 3D view.
50    *
51    * \param x The X coordinate in the view.
52    * \param y The Y coordinate in the view.
53    * \param theView View where the given point takes place.
54    * \retval gp_Pnt Returns the point clicked in 3D view
55    */
56   CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y,
57                                                          Handle(V3d_View) theView );
58
59   /**
60    * Find selected points in the context
61    * \param theContext the viewer context
62    */
63   CURVECREATOR_EXPORT static std::list<float> getSelectedPoints(
64                                         Handle(AIS_InteractiveContext) theContext );
65
66   /*!
67    * \brief Sets the local point context for the 3D viewer.
68    * \param theOpen The flag to open or close the local context.
69    */
70   CURVECREATOR_EXPORT static void setLocalPointContext(
71                                         Handle(AIS_InteractiveContext) theContext,
72                                         const bool theOpen );
73
74   /**
75    * Find the neighbour points by the clicked coordinates
76    * \param theContext the viewer context.
77    * \param theContext the V3D view.
78    * \param theX the X coordinate in the view.
79    * \param theY the Y coordinate in the view.
80    * \param thePoint the output point to be append to the model curve
81    * \param thePoint1 the output point to bound the line where a new point should be inserted
82    * \param thePoint2 the output point to bound the line where a new point should be inserted
83    */
84   CURVECREATOR_EXPORT static bool getNeighbourPoints(
85                                         Handle(AIS_InteractiveContext) theContext,
86                                         Handle(V3d_View) theView,
87                                         const int theX, const int theY,
88                                         gp_Pnt& thePoint, gp_Pnt& thePoint1,
89                                         gp_Pnt& thePoint2 );
90
91 protected:
92   /**
93    * Checks whether the point belongs to the OCC object
94    * \param theObject a line or shape with a bspline inside
95    * \param theX the X coordinate in the view.
96    * \param theY the Y coordinate in the view.
97    * \param thePoint the output point to be append to the model curve
98    * \param thePoint1 the output point to bound the line where a new point should be inserted
99    * \param thePoint2 the output point to bound the line where a new point should be inserted
100    */
101   CURVECREATOR_EXPORT static bool pointOnObject( Handle(V3d_View) theView,
102                                                  Handle(AIS_InteractiveObject) theObject,
103                                                  const int theX, const int theY,
104                                                  gp_Pnt& thePoint, gp_Pnt& thePoint1,
105                                                  gp_Pnt& thePoint2 );
106
107   /*
108    * Returns whether the clicked point belong to the curve or has a very near projection
109    * \param theX the X coordinate of a point clicked in the OCC viewer
110    * \param theY the Y coordinate of a point clicked in the OCC viewer
111    * \param theCurve a geometry curve
112    * \param theOutPoint a found projected point on the curve
113   */
114   CURVECREATOR_EXPORT static bool hasProjectPointOnCurve(
115                                                  Handle(V3d_View) theView,
116                                                  const int theX, const int theY,
117                                                  const Handle(Geom_Curve)& theCurve,
118                                                  Standard_Real& theParameter );
119
120 };
121
122 #endif // CURVECREATOR_UTILS_H