Salome HOME
Bug #202 - Fatal error during polyline creation
[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    * \param theCurve a curve object, that contains data
76    */
77   CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
78                                          const CurveCreator_ICurve* theCurve,
79                                          CurveCreator_ICurve::SectionToPointList& thePoints );
80
81   /**
82    * Set selected points to the context
83    * \param theContext the viewer context
84    * \param theCurve a curve object, that contains data
85    * \param thePoints the curve point indices to be selected in the context
86    */
87   CURVECREATOR_EXPORT static void setSelectedPoints(
88                                          Handle(AIS_InteractiveContext) theContext,
89                                          const CurveCreator_ICurve* theCurve,
90                                          const CurveCreator_ICurve::SectionToPointList& thePoints =
91                                                CurveCreator_ICurve::SectionToPointList() );
92
93   /*!
94    * \brief Sets the local point context for the 3D viewer.
95    * \param theCurve a curve object, that contains data
96    * \param theContext the viewer context
97    * \param theOpen The flag to open or close the local context.
98    */
99   CURVECREATOR_EXPORT static void setLocalPointContext(
100                                         const CurveCreator_ICurve* theCurve,
101                                         Handle(AIS_InteractiveContext) theContext,
102                                         const bool theOpen );
103
104   /**
105    * Checks whether the point belongs to the OCC object
106    * \param theObject a line or shape with a bspline inside
107    * \param theX the X coordinate in the view.
108    * \param theY the Y coordinate in the view.
109    * \param thePoint the output point to be append to the model curve
110    * \param thePoint1 the output point to bound the line where a new point should be inserted
111    * \param thePoint2 the output point to bound the line where a new point should be inserted
112    */
113   CURVECREATOR_EXPORT static bool pointOnObject( Handle(V3d_View) theView,
114                                                  Handle(AIS_InteractiveObject) theObject,
115                                                  const int theX, const int theY,
116                                                  gp_Pnt& thePoint, gp_Pnt& thePoint1,
117                                                  gp_Pnt& thePoint2 );
118
119 protected:
120   /*
121    * Returns whether the clicked point belong to the curve or has a very near projection
122    * \param theX the X coordinate of a point clicked in the OCC viewer
123    * \param theY the Y coordinate of a point clicked in the OCC viewer
124    * \param theCurve a geometry curve
125    * \param theOutPoint a found projected point on the curve
126   */
127   CURVECREATOR_EXPORT static bool hasProjectPointOnCurve(
128                                                  Handle(V3d_View) theView,
129                                                  const int theX, const int theY,
130                                                  const Handle(Geom_Curve)& theCurve,
131                                                  Standard_Real& theParameter,
132                                                  int& theDelta );
133
134   /*
135    * Returns whether the X and Y coordinates is in the pixel tolerance
136    * \param theX the X coordinate of the first point
137    * \param theY the Y coordinate of the first point
138    * \param theOtherX the X coordinate of the second point
139    * \param theOtherY the Y coordinate of the second point
140    * \param theTolerance the tolerance to compare
141    * \param theDelta the sum of the a square of X and a square of Y
142    * \returns whether the points are provide to the pixel tolerance
143   */
144   CURVECREATOR_EXPORT static bool isEqualPixels( const int theX, const int theY,
145                                                  const int theOtherX, const int theOtherY,
146                                                  const double theTolerance, int& theDelta );
147
148
149   /*
150    * Returns whether the points are the same
151    * \param thePoint the first point
152    * \param theOtherPoint the second point
153    * \returns whether the points are provide to the pixel tolerance
154   */
155   CURVECREATOR_EXPORT static bool isEqualPoints( const gp_Pnt& thePoint,
156                                                  const gp_Pnt& theOtherPoint );
157 };
158
159 #endif // CURVECREATOR_UTILS_H