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>
32 #include <TColgp_HArray1OfPnt.hxx>
35 #include <vector> // TODO: remove
37 class CurveCreator_Curve;
40 class CurveCreator_Utils
45 * \brief Returns the point clicked in 3D view.
47 * \param x The X coordinate in the view.
48 * \param y The Y coordinate in the view.
49 * \param theView View where the given point takes place.
50 * \retval gp_Pnt Returns the point clicked in 3D view
52 CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint,
53 Handle(V3d_View) theView,
57 * \brief Returns the point clicked in 3D view.
59 * \param x The X coordinate in the view.
60 * \param y The Y coordinate in the view.
61 * \param theView View where the given point takes place.
62 * \retval gp_Pnt Returns the point clicked in 3D view
64 CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y,
65 Handle(V3d_View) theView );
68 * Generates shape on the curve
69 * \param theCurve a curve object, that contains data
70 * \param theShape a generated shape
72 CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve,
73 TopoDS_Shape& theShape );
76 * Generates a curve from a shape.
77 * \param theShape a shape to be converted to curve.
78 * \param theCurve a curve object to be initialized.
79 * \param theLocalCS the local coordinate system of the curve.
80 * \return true in case of success; false otherwise. Warning: the curve can
81 * be modified even if the shape is not valid for curve construction.
83 CURVECREATOR_EXPORT static bool constructCurve
84 (const TopoDS_Shape theShape,
85 CurveCreator_Curve *theCurve,
89 * Find selected points in the context
90 * \param theContext the viewer context
91 * \param theCurve a curve object, that contains data
93 CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
94 const CurveCreator_ICurve* theCurve,
95 CurveCreator_ICurve::SectionToPointList& thePoints );
98 * Set selected points to the context
99 * \param theContext the viewer context
100 * \param theCurve a curve object, that contains data
101 * \param thePoints the curve point indices to be selected in the context
103 CURVECREATOR_EXPORT static void setSelectedPoints(
104 Handle(AIS_InteractiveContext) theContext,
105 const CurveCreator_ICurve* theCurve,
106 const CurveCreator_ICurve::SectionToPointList& thePoints =
107 CurveCreator_ICurve::SectionToPointList() );
110 * \brief Sets the local point context for the 3D viewer.
111 * \param theCurve a curve object, that contains data
112 * \param theContext the viewer context
113 * \param theOpen The flag to open or close the local context.
115 CURVECREATOR_EXPORT static void setLocalPointContext(
116 const CurveCreator_ICurve* theCurve,
117 Handle(AIS_InteractiveContext) theContext,
118 const bool theOpen );
121 * Checks whether the point belongs to the OCC object
122 * \param theObject a line or shape with a bspline inside
123 * \param theX the X coordinate in the view.
124 * \param theY the Y coordinate in the view.
125 * \param thePoint the output point to be append to the model curve
126 * \param thePoint1 the output point to bound the line where a new point should be inserted
127 * \param thePoint2 the output point to bound the line where a new point should be inserted
129 CURVECREATOR_EXPORT static bool pointOnObject( Handle(V3d_View) theView,
130 Handle(AIS_InteractiveObject) theObject,
131 const int theX, const int theY,
132 gp_Pnt& thePoint, gp_Pnt& thePoint1,
137 * Returns whether the clicked point belong to the curve or has a very near projection
138 * \param theX the X coordinate of a point clicked in the OCC viewer
139 * \param theY the Y coordinate of a point clicked in the OCC viewer
140 * \param theCurve a geometry curve
141 * \param theOutPoint a found projected point on the curve
143 static bool hasProjectPointOnCurve(
144 Handle(V3d_View) theView,
145 const int theX, const int theY,
146 const Handle(Geom_Curve)& theCurve,
147 Standard_Real& theParameter,
151 * Returns whether the X and Y coordinates is in the pixel tolerance
152 * \param theX the X coordinate of the first point
153 * \param theY the Y coordinate of the first point
154 * \param theOtherX the X coordinate of the second point
155 * \param theOtherY the Y coordinate of the second point
156 * \param theTolerance the tolerance to compare
157 * \param theDelta the sum of the a square of X and a square of Y
158 * \returns whether the points are provide to the pixel tolerance
160 static bool isEqualPixels( const int theX, const int theY,
161 const int theOtherX, const int theOtherY,
162 const double theTolerance, int& theDelta );
166 * Returns whether the points are the same
167 * \param thePoint the first point
168 * \param theOtherPoint the second point
169 * \returns whether the points are provide to the pixel tolerance
171 static bool isEqualPoints( const gp_Pnt& thePoint,
172 const gp_Pnt& theOtherPoint );
175 * Returns the array of points of a shape to construct a curve section. The
176 * shape can be either a wire or a vertex. For vertex a single point in the
179 * \param theShape the shape. Can be either a wire or a vertex.
180 * \param IsClosed closed flag. Output parameter.
181 * \param IsBSpline BSpline flag. Output parameter.
182 * \return the array of points. Null handle in case of failure.
184 static Handle_TColgp_HArray1OfPnt getPoints
185 (const TopoDS_Shape &theShape,
190 * This method computes a plane using the input points. The plane is defined
191 * by gp_Pln object and the status. The status can have one of the following
193 * - 0 plane is not set.<BR>
194 * - 1 origin of the plane is fixed. The plane is defined by 1 or several
195 * coincident points.<BR>
196 * - 2 origin + OX axis of the plane is fixed. The plane is defined by 2
197 * or more points that lie on a particular line.<BR>
198 * - 3 plane is fixed. Plane is defined by 3 not coincident points.<BR>
200 * \param thePoints the points.
201 * \param thePlane the current plane on input. It can be modified on output.
202 * \param thePlnStatus the current status on input. It can be modified on
205 static void FindPlane(const Handle_TColgp_HArray1OfPnt &thePoints,
207 Standard_Integer &thePlnStatus);
211 #endif // CURVECREATOR_UTILS_H