1 // Copyright (C) 2007-2008 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.
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
22 // Author : OPEN CASCADE
23 // File: GLViewer_Context.cxx
24 // Created: November, 2004
26 #include "GLViewer_CoordSystem.h"
31 \param aType - type of CS
32 \param X0 - X of origin in reference CS
33 \param Y0 - Y of origin in reference CS
34 \param XUnit - X unit in reference CS
35 \param YUnit - Y unit in reference CS
36 \param Rotation - rotation relative reference CS
38 GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
39 double XUnit, double YUnit, double Rotation )
43 setUnits( XUnit, YUnit );
44 setRotation( Rotation );
48 \return origin in reference CS
50 void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
57 Sets origin in reference CS
59 void GLViewer_CoordSystem::setOrigin( double x, double y )
68 void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
77 void GLViewer_CoordSystem::setUnits( double x, double y )
93 double GLViewer_CoordSystem::getRotation() const
101 void GLViewer_CoordSystem::setRotation( double rotation )
103 myRotation = rotation;
109 GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
117 void GLViewer_CoordSystem::setType( CSType type )
123 Recalculate co-ordinates to reference co-ordinates
124 \param x, y - co-ordinates
126 void GLViewer_CoordSystem::toReference( double& x, double& y )
128 if( myType==Cartesian )
130 double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
131 newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
135 else if( myType==Polar )
137 double r = x, phi = y;
138 x = myX0 + myXUnit*r*cos(phi+myRotation);
139 y = myY0 + myXUnit*r*sin(phi+myRotation);
144 Recalculate co-ordinates from reference co-ordinates
145 \param x, y - co-ordinates
147 void GLViewer_CoordSystem::fromReference( double& x, double& y )
149 x = (x - myX0) / myXUnit;
150 y = (y - myY0) / myYUnit;
152 if( myType==Cartesian )
154 double newx = x*cos(myRotation) + y*sin(myRotation),
155 newy = -x*sin(myRotation) + y*cos(myRotation);
159 else if( myType==Polar )
161 double r = sqrt( x*x+y*y );
163 double eps = 1E-8, pi = 3.14159265;
170 if( x<0 ) // 2-nd or 4-rd quarter
184 Recalculate co-ordinates to co-ordinates of other CS
185 \param aSystem - other CS
186 \param x, y - co-ordinates
188 void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
191 aSystem.fromReference( x, y );
195 \return stretching of CS along X and Y axis
197 void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
199 theX = myXUnit / aSystem.myXUnit;
200 theY = myYUnit / aSystem.myYUnit;