1 // Copyright (C) 2013-2015 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, 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
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>
32 #include <TColgp_HArray1OfPnt.hxx>
33 #include <Geom_BSplineCurve.hxx>
36 #include <vector> // TODO: remove
38 class CurveCreator_Curve;
41 class CurveCreator_Utils
46 * \brief Returns the point clicked in 3D view.
48 * \param x The X coordinate in the view.
49 * \param y The Y coordinate in the view.
50 * \param theView View where the given point takes place.
51 * \retval gp_Pnt Returns the point clicked in 3D view
53 CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint,
54 Handle(V3d_View) theView,
58 * \brief Returns the point clicked in 3D view.
60 * \param x The X coordinate in the view.
61 * \param y The Y coordinate in the view.
62 * \param theView View where the given point takes place.
63 * \retval gp_Pnt Returns the point clicked in 3D view
65 CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y,
66 Handle(V3d_View) theView );
69 * Generates shape on the curve
70 * \param theCurve a curve object, that contains data
71 * \param theShape a generated shape
73 CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve,
74 TopoDS_Shape& theShape );
77 * Generates a curve from a shape.
78 * \param theShape a shape to be converted to curve.
79 * \param theCurve a curve object to be initialized.
80 * \param theLocalCS the local coordinate system of the curve.
81 * \return true in case of success; false otherwise. Warning: the curve can
82 * be modified even if the shape is not valid for curve construction.
84 CURVECREATOR_EXPORT static bool constructCurve
85 (const TopoDS_Shape theShape,
86 CurveCreator_Curve *theCurve,
90 * Find selected points in the context
91 * \param theContext the viewer context
92 * \param theCurve a curve object, that contains data
94 CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
95 const CurveCreator_ICurve* theCurve,
96 CurveCreator_ICurve::SectionToPointList& thePoints );
99 * Set selected points to the context
100 * \param theContext the viewer context
101 * \param theCurve a curve object, that contains data
102 * \param thePoints the curve point indices to be selected in the context
104 CURVECREATOR_EXPORT static void setSelectedPoints(
105 Handle(AIS_InteractiveContext) theContext,
106 const CurveCreator_ICurve* theCurve,
107 const CurveCreator_ICurve::SectionToPointList& thePoints =
108 CurveCreator_ICurve::SectionToPointList() );
111 * \brief Sets the local point context for the 3D viewer.
112 * \param theCurve a curve object, that contains data
113 * \param theContext the viewer context
114 * \param theOpen The flag to open or close the local context.
116 CURVECREATOR_EXPORT static void setLocalPointContext(
117 const CurveCreator_ICurve* theCurve,
118 Handle(AIS_InteractiveContext) theContext,
119 const bool theOpen );
122 * Checks whether the point belongs to the OCC object
123 * \param theObject a line or shape with a bspline inside
124 * \param theX the X coordinate in the view.
125 * \param theY the Y coordinate in the view.
126 * \param thePoint the output point to be append to the model curve
127 * \param thePoint1 the output point to bound the line where a new point should be inserted
128 * \param thePoint2 the output point to bound the line where a new point should be inserted
130 CURVECREATOR_EXPORT static bool pointOnObject( Handle(V3d_View) theView,
131 Handle(AIS_InteractiveObject) theObject,
132 const int theX, const int theY,
133 gp_Pnt& thePoint, gp_Pnt& thePoint1,
136 CURVECREATOR_EXPORT static bool constructBSpline( const Handle(TColgp_HArray1OfPnt)& thePoints,
137 const Standard_Boolean theIsClosed,
138 Handle(Geom_BSplineCurve)& theBSpline );
142 * Returns whether the clicked point belong to the curve or has a very near projection
143 * \param theX the X coordinate of a point clicked in the OCC viewer
144 * \param theY the Y coordinate of a point clicked in the OCC viewer
145 * \param theCurve a geometry curve
146 * \param theOutPoint a found projected point on the curve
148 static bool hasProjectPointOnCurve(
149 Handle(V3d_View) theView,
150 const int theX, const int theY,
151 const Handle(Geom_Curve)& theCurve,
152 Standard_Real& theParameter,
156 * Returns whether the X and Y coordinates is in the pixel tolerance
157 * \param theX the X coordinate of the first point
158 * \param theY the Y coordinate of the first point
159 * \param theOtherX the X coordinate of the second point
160 * \param theOtherY the Y coordinate of the second point
161 * \param theTolerance the tolerance to compare
162 * \param theDelta the sum of the a square of X and a square of Y
163 * \returns whether the points are provide to the pixel tolerance
165 static bool isEqualPixels( const int theX, const int theY,
166 const int theOtherX, const int theOtherY,
167 const double theTolerance, int& theDelta );
171 * Returns whether the points are the same
172 * \param thePoint the first point
173 * \param theOtherPoint the second point
174 * \returns whether the points are provide to the pixel tolerance
176 static bool isEqualPoints( const gp_Pnt& thePoint,
177 const gp_Pnt& theOtherPoint );
180 * Returns the array of points of a shape to construct a curve section. The
181 * shape can be either a wire or a vertex. For vertex a single point in the
184 * \param theShape the shape. Can be either a wire or a vertex.
185 * \param IsClosed closed flag. Output parameter.
186 * \param IsBSpline BSpline flag. Output parameter.
187 * \return the array of points. Null handle in case of failure.
189 static Handle_TColgp_HArray1OfPnt getPoints
190 (const TopoDS_Shape &theShape,
195 * This method computes a plane using the input points. The plane is defined
196 * by gp_Pln object and the status. The status can have one of the following
198 * - 0 plane is not set.<BR>
199 * - 1 origin of the plane is fixed. The plane is defined by 1 or several
200 * coincident points.<BR>
201 * - 2 origin + OX axis of the plane is fixed. The plane is defined by 2
202 * or more points that lie on a particular line.<BR>
203 * - 3 plane is fixed. Plane is defined by 3 not coincident points.<BR>
205 * \param thePoints the points.
206 * \param thePlane the current plane on input. It can be modified on output.
207 * \param thePlnStatus the current status on input. It can be modified on
210 static void FindPlane(const Handle_TColgp_HArray1OfPnt &thePoints,
212 Standard_Integer &thePlnStatus);
216 #endif // CURVECREATOR_UTILS_H