1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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
20 #ifndef CURVECREATOR_UTILS_H
21 #define CURVECREATOR_UTILS_H
23 #include "CurveCreator_Macro.hxx"
24 #include "CurveCreator_ICurve.hxx"
26 #include <AIS_InteractiveContext.hxx>
27 #include <AIS_InteractiveObject.hxx> // TODO: remove
28 #include <V3d_View.hxx>
30 #include <Geom_Curve.hxx>
31 #include <TopoDS_Shape.hxx>
34 #include <vector> // TODO: remove
37 class CurveCreator_Utils
42 * \brief Returns the point clicked in 3D view.
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
49 CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint,
50 Handle(V3d_View) theView,
54 * \brief Returns the point clicked in 3D view.
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
61 CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y,
62 Handle(V3d_View) theView );
65 * Generates shape on the curve
66 * \param theCurve a curve object, that contains data
67 * \param theShape a generated shape
69 CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve,
70 TopoDS_Shape& theShape );
73 * Find selected points in the context
74 * \param theContext the viewer context
75 * \param theCurve a curve object, that contains data
77 CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
78 const CurveCreator_ICurve* theCurve,
79 CurveCreator_ICurve::SectionToPointList& thePoints );
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
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() );
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.
99 CURVECREATOR_EXPORT static void setLocalPointContext(
100 const CurveCreator_ICurve* theCurve,
101 Handle(AIS_InteractiveContext) theContext,
102 const bool theOpen );
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
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,
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
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,
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
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 );
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
155 CURVECREATOR_EXPORT static bool isEqualPoints( const gp_Pnt& thePoint,
156 const gp_Pnt& theOtherPoint );
159 #endif // CURVECREATOR_UTILS_H