1 // Copyright (C) 2007-2023 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_Context.cxx
25 // Created: November, 2004
27 #include "GLViewer_CoordSystem.h"
32 \param aType - type of CS
33 \param X0 - X of origin in reference CS
34 \param Y0 - Y of origin in reference CS
35 \param XUnit - X unit in reference CS
36 \param YUnit - Y unit in reference CS
37 \param Rotation - rotation relative reference CS
39 GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
40 double XUnit, double YUnit, double Rotation )
44 setUnits( XUnit, YUnit );
45 setRotation( Rotation );
49 \return origin in reference CS
51 void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
58 Sets origin in reference CS
60 void GLViewer_CoordSystem::setOrigin( double x, double y )
69 void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
78 void GLViewer_CoordSystem::setUnits( double x, double y )
94 double GLViewer_CoordSystem::getRotation() const
102 void GLViewer_CoordSystem::setRotation( double rotation )
104 myRotation = rotation;
110 GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
118 void GLViewer_CoordSystem::setType( CSType type )
124 Recalculate co-ordinates to reference co-ordinates
125 \param x, y - co-ordinates
127 void GLViewer_CoordSystem::toReference( double& x, double& y )
129 if( myType==Cartesian )
131 double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
132 newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
136 else if( myType==Polar )
138 double r = x, phi = y;
139 x = myX0 + myXUnit*r*cos(phi+myRotation);
140 y = myY0 + myXUnit*r*sin(phi+myRotation);
145 Recalculate co-ordinates from reference co-ordinates
146 \param x, y - co-ordinates
148 void GLViewer_CoordSystem::fromReference( double& x, double& y )
150 x = (x - myX0) / myXUnit;
151 y = (y - myY0) / myYUnit;
153 if( myType==Cartesian )
155 double newx = x*cos(myRotation) + y*sin(myRotation),
156 newy = -x*sin(myRotation) + y*cos(myRotation);
160 else if( myType==Polar )
162 double r = sqrt( x*x+y*y );
164 double eps = 1E-8, pi = 3.14159265;
172 if( x<0 ) // 2-nd or 4-rd quarter
187 Recalculate co-ordinates to co-ordinates of other CS
188 \param aSystem - other CS
189 \param x, y - co-ordinates
191 void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
194 aSystem.fromReference( x, y );
198 \return stretching of CS along X and Y axis
200 void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
202 theX = myXUnit / aSystem.myXUnit;
203 theY = myYUnit / aSystem.myYUnit;