wxtransform.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #ifndef MECHSYS_WXTRANSFORMDATA_H
00023 #define MECHSYS_WXTRANSFORMDATA_H
00024 
00025 #include <wx/gdicmn.h> // for wxRect
00026 
00027 struct WxTransformData
00028 {
00029     // used for transformation:
00030     wxRect CanvasRect;
00031     REAL   xMin;
00032     REAL   yMin;
00033     REAL   xSF;       // scale factor
00034     REAL   ySF;       // scale factor
00035     // used to calculate scale factors:
00036     bool   EqScales;
00037     REAL   xMax;
00038     REAL   yMax;
00039     REAL   xRange;
00040     REAL   yRange;
00041 }; // struct TransformData //
00042 
00043 inline void WxCalcScaleFactor(WxTransformData & TD)
00044 { // {{{
00045     if (TD.xRange==0) { TD.xSF=0; TD.ySF=0; return; } // TODO: devise a better check here
00046     if (TD.yRange==0) { TD.xSF=0; TD.ySF=0; return; }
00047     TD.xSF = static_cast<REAL>(TD.CanvasRect.width ) / TD.xRange;
00048     TD.ySF = static_cast<REAL>(TD.CanvasRect.height) / TD.yRange;
00049     if (TD.EqScales)
00050     {
00051         TD.xSF = (TD.xSF<TD.ySF ? TD.xSF : TD.ySF);
00052         TD.ySF = TD.xSF;
00053     }
00054 } // }}}
00055 
00056 inline void WxReal2Canvas(WxTransformData const & TD     , // In:
00057                           REAL            const & xReal  , // In:
00058                           REAL            const & yReal  , // In:
00059                           int                   & xCanvas, // Out:
00060                           int                   & yCanvas) // Out:
00061 { // {{{
00062     xCanvas = TD.CanvasRect.x +                        static_cast<int>( (xReal-TD.xMin)*TD.xSF );
00063     yCanvas = TD.CanvasRect.y + TD.CanvasRect.height - static_cast<int>( (yReal-TD.yMin)*TD.ySF );
00064 } // }}}
00065 
00066 #endif // MECHSYS_WXTRANSFORMDATA_H
00067 
00068 // vim:fdm=marker

Generated on Wed Jan 24 15:56:26 2007 for MechSys by  doxygen 1.4.7