Salome HOME
30779616cf2d7830e0c04fa8af3256aa9d90f765
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Utils.cxx
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 #include "CurveCreator_Utils.h"
21
22 #include <gp_Pln.hxx>
23 #include <ProjLib.hxx>
24 #include <ElSLib.hxx>
25
26
27 //=======================================================================
28 // function : ConvertClickToPoint()
29 // purpose  : Returns the point clicked in 3D view
30 //=======================================================================
31 gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
32 {
33   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
34   aView->Eye( XEye, YEye, ZEye );
35
36   aView->At( XAt, YAt, ZAt );
37   gp_Pnt EyePoint( XEye, YEye, ZEye );
38   gp_Pnt AtPoint( XAt, YAt, ZAt );
39
40   gp_Vec EyeVector( EyePoint, AtPoint );
41   gp_Dir EyeDir( EyeVector );
42
43   gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
44   Standard_Real X, Y, Z;
45   aView->Convert( x, y, X, Y, Z );
46   gp_Pnt ConvertedPoint( X, Y, Z );
47
48   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
49   gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
50   return ResultPoint;
51 }