]> SALOME platform Git repositories - modules/geom.git/blob - src/CurveCreator/CurveCreator_Utils.hxx
Salome HOME
0494fceeffe9c70c110c283622d2dc77467dbc6d
[modules/geom.git] / src / CurveCreator / CurveCreator_Utils.hxx
1 // Copyright (C) 2013-2015  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, or (at your option) any later version.
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 #include <TColgp_HArray1OfPnt.hxx>
33 #include <Geom_BSplineCurve.hxx>
34
35 #include <list>
36 #include <vector> // TODO: remove
37
38 class CurveCreator_Curve;
39
40
41 class CurveCreator_Utils
42 {
43 public:
44
45     /*!
46    * \brief Returns the point clicked in 3D view.
47    *
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
52    */
53   CURVECREATOR_EXPORT static void ConvertPointToClick( const gp_Pnt& thePoint,
54                                                        Handle(V3d_View) theView,
55                                                        int& x, int& y );
56
57   /*!
58    * \brief Returns the point clicked in 3D view.
59    *
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
64    */
65   CURVECREATOR_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y,
66                                                          Handle(V3d_View) theView );
67
68   /**
69    * Generates shape on the curve
70    * \param theCurve a curve object, that contains data
71    * \param theShape a generated shape
72    */
73   CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve,
74                                                   TopoDS_Shape& theShape );
75
76   /**
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.
83    */
84   CURVECREATOR_EXPORT static bool constructCurve
85                       (const TopoDS_Shape        theShape,
86                              CurveCreator_Curve *theCurve,
87                              gp_Ax3             &theLocalCS);
88
89   /**
90    * Find selected points in the context
91    * \param theContext the viewer context
92    * \param theCurve a curve object, that contains data
93    */
94   CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
95                                          const CurveCreator_ICurve* theCurve,
96                                          CurveCreator_ICurve::SectionToPointList& thePoints );
97
98   /**
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
103    */
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() );
109
110   /*!
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.
115    */
116   CURVECREATOR_EXPORT static void setLocalPointContext(
117                                         const CurveCreator_ICurve* theCurve,
118                                         Handle(AIS_InteractiveContext) theContext,
119                                         const bool theOpen );
120
121   /**
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
129    */
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,
134                                                  gp_Pnt& thePoint2 );
135
136   CURVECREATOR_EXPORT static bool constructBSpline( const Handle(TColgp_HArray1OfPnt)& thePoints,
137                                                     const Standard_Boolean theIsClosed,
138                                                     Handle(Geom_BSplineCurve)& theBSpline );
139
140 protected:
141   /*
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
147   */
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,
153                              int& theDelta );
154
155   /*
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
164   */
165   static bool isEqualPixels( const int theX, const int theY,
166                              const int theOtherX, const int theOtherY,
167                              const double theTolerance, int& theDelta );
168
169
170   /*
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
175   */
176   static bool isEqualPoints( const gp_Pnt& thePoint,
177                              const gp_Pnt& theOtherPoint );
178
179   /**
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
182    * array is returned.
183    *
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.
188    */
189   static Handle_TColgp_HArray1OfPnt getPoints
190                            (const TopoDS_Shape &theShape,
191                                   bool         &IsClosed,
192                                   bool         &IsBSpline);
193
194   /**
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
197    * values:
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>
204    *
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
208    *        output.
209    */
210   static void FindPlane(const Handle_TColgp_HArray1OfPnt &thePoints,
211                               gp_Pln                     &thePlane,
212                               Standard_Integer           &thePlnStatus);
213
214 };
215
216 #endif // CURVECREATOR_UTILS_H