Salome HOME
bug #155: create profile of splines
[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 #include "CurveCreator_ICurve.hxx"
25
26 #include <AIS_InteractiveContext.hxx>
27 #include <AIS_InteractiveObject.hxx> // TODO: remove
28 #include <V3d_View.hxx>
29 #include <gp_Pnt.hxx>
30 #include <Geom_Curve.hxx>
31 #include <TopoDS_Shape.hxx>
32
33 #include <list>
34 #include <vector> // TODO: remove
35
36
37 class CurveCreator_Utils
38 {
39 public:
40
41     /*!
42    * \brief Returns the point clicked in 3D view.
43    *
44    * \param x The X coordinate in the view.
45    * \param y The Y coordinate in the view.
46    * \param theView View where the given point takes place.
47    * \retval gp_Pnt Returns the point clicked in 3D view
48    */
49   CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint,
50                                                        Handle(V3d_View) theView,
51                                                        int& x, int& y );
52
53   /*!
54    * \brief Returns the point clicked in 3D view.
55    *
56    * \param x The X coordinate in the view.
57    * \param y The Y coordinate in the view.
58    * \param theView View where the given point takes place.
59    * \retval gp_Pnt Returns the point clicked in 3D view
60    */
61   CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y,
62                                                          Handle(V3d_View) theView );
63
64   /**
65    * Generates shape on the curve
66    * \param theCurve a curve object, that contains data
67    * \param theShape a generated shape
68    */
69   CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve,
70                                                   TopoDS_Shape& theShape );
71
72   /**
73    * Find selected points in the context
74    * \param theContext the viewer context
75    */
76   CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
77                                          const CurveCreator_ICurve* theCurve,
78                                          CurveCreator_ICurve::SectionToPointList& thePoints );
79
80   /**
81    * Set selected points to the context
82    * \param theContext the viewer context
83    * \param thePoints the curve point indices to be selected in the context
84    */
85   CURVECREATOR_EXPORT static void setSelectedPoints(
86                                          Handle(AIS_InteractiveContext) theContext,
87                                          const CurveCreator_ICurve* theCurve,
88                                          const CurveCreator_ICurve::SectionToPointList& thePoints =
89                                                CurveCreator_ICurve::SectionToPointList() );
90
91   /*!
92    * \brief Sets the local point context for the 3D viewer.
93    * \param theOpen The flag to open or close the local context.
94    */
95   CURVECREATOR_EXPORT static void setLocalPointContext(
96                                         Handle(AIS_InteractiveContext) theContext,
97                                         const bool theOpen );
98
99   /**
100    * Find the neighbour points by the clicked coordinates
101    * \param theContext the viewer context.
102    * \param theContext the V3D view.
103    * \param theX the X coordinate in the view.
104    * \param theY the Y coordinate in the view.
105    * \param thePoint the output point to be append to the model curve
106    * \param thePoint1 the output point to bound the line where a new point should be inserted
107    * \param thePoint2 the output point to bound the line where a new point should be inserted
108    */
109   CURVECREATOR_EXPORT static bool getNeighbourPoints(
110                                         Handle(AIS_InteractiveContext) theContext,
111                                         Handle(V3d_View) theView,
112                                         const int theX, const int theY,
113                                         gp_Pnt& thePoint, gp_Pnt& thePoint1,
114                                         gp_Pnt& thePoint2 );
115
116 protected:
117   /**
118    * Checks whether the point belongs to the OCC object
119    * \param theObject a line or shape with a bspline inside
120    * \param theX the X coordinate in the view.
121    * \param theY the Y coordinate in the view.
122    * \param thePoint the output point to be append to the model curve
123    * \param thePoint1 the output point to bound the line where a new point should be inserted
124    * \param thePoint2 the output point to bound the line where a new point should be inserted
125    */
126   CURVECREATOR_EXPORT static bool pointOnObject( Handle(V3d_View) theView,
127                                                  Handle(AIS_InteractiveObject) theObject,
128                                                  const int theX, const int theY,
129                                                  gp_Pnt& thePoint, gp_Pnt& thePoint1,
130                                                  gp_Pnt& thePoint2 );
131
132   /*
133    * Returns whether the clicked point belong to the curve or has a very near projection
134    * \param theX the X coordinate of a point clicked in the OCC viewer
135    * \param theY the Y coordinate of a point clicked in the OCC viewer
136    * \param theCurve a geometry curve
137    * \param theOutPoint a found projected point on the curve
138   */
139   CURVECREATOR_EXPORT static bool hasProjectPointOnCurve(
140                                                  Handle(V3d_View) theView,
141                                                  const int theX, const int theY,
142                                                  const Handle(Geom_Curve)& theCurve,
143                                                  Standard_Real& theParameter );
144
145 };
146
147 #endif // CURVECREATOR_UTILS_H