1 // Copyright (C) 2005 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_Context.cxx
23 // Created: November, 2004
25 #include "GLViewer_CoordSystem.h"
30 \param aType - type of CS
31 \param X0 - X of origin in reference CS
32 \param Y0 - Y of origin in reference CS
33 \param XUnit - X unit in reference CS
34 \param YUnit - Y unit in reference CS
35 \param Rotation - rotation relative reference CS
37 GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
38 double XUnit, double YUnit, double Rotation )
42 setUnits( XUnit, YUnit );
43 setRotation( Rotation );
47 \return origin in reference CS
49 void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
56 Sets origin in reference CS
58 void GLViewer_CoordSystem::setOrigin( double x, double y )
67 void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
76 void GLViewer_CoordSystem::setUnits( double x, double y )
92 double GLViewer_CoordSystem::getRotation() const
100 void GLViewer_CoordSystem::setRotation( double rotation )
102 myRotation = rotation;
108 GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
116 void GLViewer_CoordSystem::setType( CSType type )
122 Recalculate co-ordinates to reference co-ordinates
123 \param x, y - co-ordinates
125 void GLViewer_CoordSystem::toReference( double& x, double& y )
127 if( myType==Cartesian )
129 double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
130 newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
134 else if( myType==Polar )
136 double r = x, phi = y;
137 x = myX0 + myXUnit*r*cos(phi+myRotation);
138 y = myY0 + myXUnit*r*sin(phi+myRotation);
143 Recalculate co-ordinates from reference co-ordinates
144 \param x, y - co-ordinates
146 void GLViewer_CoordSystem::fromReference( double& x, double& y )
148 x = (x - myX0) / myXUnit;
149 y = (y - myY0) / myYUnit;
151 if( myType==Cartesian )
153 double newx = x*cos(myRotation) + y*sin(myRotation),
154 newy = -x*sin(myRotation) + y*cos(myRotation);
158 else if( myType==Polar )
160 double r = sqrt( x*x+y*y );
162 double eps = 1E-8, pi = 3.14159265;
169 if( x<0 ) // 2-nd or 4-rd quarter
183 Recalculate co-ordinates to co-ordinates of other CS
184 \param aSystem - other CS
185 \param x, y - co-ordinates
187 void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
190 aSystem.fromReference( x, y );
194 \return stretching of CS along X and Y axis
196 void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
198 theX = myXUnit / aSystem.myXUnit;
199 theY = myYUnit / aSystem.myYUnit;