wxcurve.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_WXCURVE_H
00023 #define MECHSYS_WXCURVE_H
00024 
00025 #include <sstream>
00026 #include <iomanip>
00027 #include <wx/dcbuffer.h>
00028 #include <wx/icon.h>
00029 
00030 #ifdef HAVE_CONFIG_H
00031   #include "config.h"
00032 #else
00033   #ifndef REAL
00034     #define REAL double
00035   #endif
00036 #endif
00037 
00038 #include "util/array.h"
00039 #include "gui/wxtransform.h"
00040 #include "gui/conrec.h"
00041 
00042 class WxCurve
00043 {
00044 public:
00045     // Point styles
00046     enum PointShape
00047     { // {{{
00048         WxCurve_PS_NONE           , 
00049         WxCurve_PS_DOT            , 
00050         WxCurve_PS_CIRC           , 
00051         WxCurve_PS_CIRC_MED       , 
00052         WxCurve_PS_CIRC_BIG       , 
00053         WxCurve_PS_CROSS_BIG      , 
00054         WxCurve_PS_SQUARE_MED     , 
00055         WxCurve_PS_SQUARE_BIG     , 
00056         WxCurve_PS_CIRC_CROSS_BIG , 
00057         WxCurve_PS_TARGET_BIG     , 
00058         WxCurve_PS_DONUT
00059     }; // enum PointShape // }}}
00060 
00061     // Constructor & Destructor
00062      WxCurve (Array<REAL> const & X, Array<REAL> const & Y);
00063      WxCurve (REAL const * X, REAL const * Y, int Size);
00064      WxCurve (REAL x_min, REAL x_max, REAL y_min, REAL y_max, int nDiv, REAL DelPctX=0.1, REAL DelPctY=0.1);
00065     ~WxCurve ();
00066 
00067     // Config Methods
00068     WxCurve & Enable        (bool             Val=true ) { _enabled=Val; return (*this); }
00069     WxCurve & LineColour    (wxString const & Clr      );
00070     WxCurve & LineStyle     (int              LineStyle);
00071     WxCurve & PointFGColour (wxString const & Clr      );
00072     WxCurve & PointBGColour (wxString const & Clr      );
00073     WxCurve & PointType     (PointShape       PS       );
00074 
00075     // Methods
00076     void   UpdateSize (WxTransformData const & TD);
00077     void   GetRange   (REAL & MinX, REAL & MaxX,  REAL & MinY, REAL & MaxY) const;
00078     void   DrawLine   (wxDC & DC);
00079     void   DrawPoints (wxDC & DC);
00080     void   ResetData  (REAL const * X, REAL const * Y, int Size);
00081     void   ResetData  (Array<REAL> const & X, Array<REAL> const & Y);
00082     void   ResetData  (REAL x_min, REAL x_max, REAL y_min, REAL y_max, int nDiv, REAL DelPctX=0.1, REAL DelPctY=0.1);
00083     int    GridSize   ()      const  { return _grid_size;    }
00084     REAL   GridX      (int i) const  { return _grid_x[i];    }
00085     REAL   GridY      (int i) const  { return _grid_y[i];    }
00086     REAL & GridFunc   (int i, int j) { return _grid_f[i][j]; }
00087     void   SetContour (int nLevels, REAL const * Levels);
00088 
00089 private:
00090     // Data - general
00091     REAL       * _x;
00092     REAL       * _y;
00093     int          _size;
00094     bool         _enabled;
00095     REAL         _min_x;
00096     REAL         _max_x;
00097     REAL         _min_y;
00098     REAL         _max_y;
00099     REAL         _x_range;
00100     REAL         _y_range;
00101     REAL         _sf_x;       // scale factor - x direction
00102     REAL         _sf_y;       // scale factor - y direction
00103     PointShape   _point_type;
00104     char      ** _point_xpm;
00105     bool         _is_contour;
00106     int          _grid_size;
00107     REAL       * _grid_x;
00108     REAL       * _grid_y;
00109     REAL      ** _grid_f;
00110 
00111     // Data - wxWidgets
00112     wxPoint    * _points;  // device coordinates
00113     wxPen        _line_pen;
00114     wxPen        _point_pen;
00115     wxBrush      _point_brush;
00116 
00117     // Private Methods
00118     void _init_pen_brush();
00119     void _bounding_box  ();
00120     void _allocate_xpm  ();
00121     void _colour_to_hex (wxColour const & Col, char * HexBufferSizeEq8);
00122 }; // class WxCurve
00123 
00124 
00126 
00127 
00128 inline WxCurve::WxCurve(Array<REAL> const & X, Array<REAL> const & Y) // {{{
00129     : _size         (X.size()),
00130       _enabled      (true),
00131       _point_xpm    (NULL),
00132       _is_contour   (false),
00133       _grid_size    (0)
00134 {
00135     // Init pens and brushes
00136     _init_pen_brush();
00137     
00138     // Allocate arrays of data
00139          _x = new REAL    [_size];
00140          _y = new REAL    [_size];
00141     _points = new wxPoint [_size];
00142     for (int i=0; i<_size; ++i)
00143     {
00144              _x[i]   = X[i];
00145              _y[i]   = Y[i];
00146         _points[i].x = 0;
00147         _points[i].y = 0;
00148     }
00149 
00150     // Get bounding box
00151     _bounding_box();
00152 
00153     // Allocate XPM
00154     _allocate_xpm();
00155 } // }}}
00156 
00157 inline WxCurve::WxCurve(REAL const * X, REAL const * Y, int Size) // {{{
00158     : _size         (Size),
00159       _enabled      (true),
00160       _point_xpm    (NULL),
00161       _is_contour   (false),
00162       _grid_size    (0)
00163 {
00164     // Init pens and brushes
00165     _init_pen_brush();
00166     
00167     // Allocate arrays of data
00168          _x = new REAL    [_size];
00169          _y = new REAL    [_size];
00170     _points = new wxPoint [_size];
00171     for (int i=0; i<_size; ++i)
00172     {
00173              _x[i]   = X[i];
00174              _y[i]   = Y[i];
00175         _points[i].x = 0;
00176         _points[i].y = 0;
00177     }
00178 
00179     // Get bounding box
00180     _bounding_box();
00181 
00182     // Allocate XPM
00183     _allocate_xpm();
00184 } // }}}
00185 
00186 inline WxCurve::WxCurve(REAL x_min, REAL x_max, REAL y_min, REAL y_max, int nDiv, REAL DelPctX, REAL DelPctY) // {{{
00187     : _size         (0),
00188       _enabled      (false),
00189       _point_xpm    (NULL),
00190       _is_contour   (true),
00191       _grid_size    (nDiv)
00192 {
00193     // Init pens and brushes
00194     _init_pen_brush();
00195     
00196     // Set limits
00197     _min_x=x_min; _max_x=x_max;
00198     _min_y=y_min; _max_y=y_max;
00199     _x_range = _max_x - _min_x;
00200     _y_range = _max_y - _min_y;
00201 
00202     // Allocate and generate grid
00203     REAL         dx = DelPctX*_x_range;
00204     REAL         dy = DelPctY*_y_range;
00205     REAL    start_x = _min_x-dx;
00206     REAL      end_x = _max_x+dx;
00207     REAL    start_y = _min_y-dy;
00208     REAL      end_y = _max_y+dy;
00209             _grid_x = new REAL [_grid_size];
00210             _grid_y = new REAL [_grid_size];
00211     REAL     step_x = (end_x-start_x)/(_grid_size-1.0);
00212     REAL     step_y = (end_y-start_y)/(_grid_size-1.0);
00213          _grid_x[0] = start_x;
00214          _grid_y[0] = start_y;
00215     for (int i=1; i<_grid_size; ++i)  _grid_x[i]=_grid_x[i-1]+step_x;
00216     for (int i=1; i<_grid_size; ++i)  _grid_y[i]=_grid_y[i-1]+step_y;
00217 
00218     // Allocate (void) function values
00219      _grid_f    = new REAL * [_grid_size];  for (int i=0; i<_grid_size; ++i)
00220      _grid_f[i] = new REAL   [_grid_size];
00221 
00222     // Allocate XPM
00223     _allocate_xpm();
00224 } // }}}
00225 
00226 inline WxCurve::~WxCurve() // {{{
00227 {
00228     // Delete arrays of data
00229     if (_size>0)
00230     {
00231         delete [] _x;
00232         delete [] _y;
00233         delete [] _points;
00234     }
00235     if (_grid_size>0)
00236     {
00237         delete [] _grid_x;
00238         delete [] _grid_y;  for (int i=0; i<_grid_size; ++i)
00239         delete [] _grid_f[i];
00240         delete [] _grid_f;
00241     }
00242 
00243     // Delete XPM
00244     delete [] _point_xpm[0]; // width height num_colors chars_per_pixel
00245     delete [] _point_xpm[1]; // colors - none
00246     delete [] _point_xpm[2]; // colors - pen
00247     delete [] _point_xpm[3]; // colors - brush
00248     for (int i=0; i<20; ++i)
00249         delete [] _point_xpm[4+i]; // pixels
00250 } // }}}
00251 
00252 inline WxCurve & WxCurve::LineColour(wxString const & Clr) // {{{
00253 {
00254     _line_pen.SetColour(Clr);
00255     return (*this);
00256 } // }}}
00257 
00258 inline WxCurve & WxCurve::LineStyle(int wxLineStyle) // {{{
00259 {
00260     _line_pen.SetStyle (wxLineStyle);
00261     return (*this);
00262 } // }}}
00263 
00264 inline WxCurve & WxCurve::PointFGColour(wxString const & Clr) // {{{
00265 {
00266     _point_pen.SetColour(Clr);
00267     return (*this);
00268 } // }}}
00269 
00270 inline WxCurve & WxCurve::PointBGColour(wxString const & Clr) // {{{
00271 {
00272     _point_brush.SetColour(Clr);
00273     return (*this);
00274 } // }}}
00275 
00276 inline WxCurve & WxCurve::PointType(WxCurve::PointShape PS) // {{{
00277 {
00278     // No change
00279     if (PS==_point_type) return (*this);
00280 
00281     // Set colour
00282     char pen_hex  [8];
00283     char brush_hex[8];
00284     _colour_to_hex(_point_pen  .GetColour(), pen_hex  );
00285     _colour_to_hex(_point_brush.GetColour(), brush_hex);
00286     std::strncpy(_point_xpm[ 2]+5, pen_hex  , 7);
00287     std::strncpy(_point_xpm[ 3]+5, brush_hex, 7);
00288     
00289     // Set pixels
00290     switch (PS)
00291     {
00292         case WxCurve_PS_NONE:
00293             break;
00294         case WxCurve_PS_DOT:
00295         {
00296             /*                           0         1         2         3         4
00297                                          01234567890123456789012345678901234567890             00 */
00298             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00299             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00300             std::strncpy(_point_xpm[ 6], "........................................", 20*2); /*  3 */
00301             std::strncpy(_point_xpm[ 7], "........................................", 20*2); /*  4 */
00302             std::strncpy(_point_xpm[ 8], "........................................", 20*2); /*  5 */
00303             std::strncpy(_point_xpm[ 9], "........................................", 20*2); /*  6 */
00304             std::strncpy(_point_xpm[10], "........................................", 20*2); /*  7 */
00305             std::strncpy(_point_xpm[11], ".................#.#.#..................", 20*2); /*  8 */
00306             std::strncpy(_point_xpm[12], "...............#.#.#.#.#................", 20*2); /*  9 */
00307             std::strncpy(_point_xpm[13], "...............#.#.#.#.#................", 20*2); /* 10 */
00308             std::strncpy(_point_xpm[14], "...............#.#.#.#.#................", 20*2); /*  1 */
00309             std::strncpy(_point_xpm[15], ".................#.#.#..................", 20*2); /*  2 */
00310             std::strncpy(_point_xpm[16], "........................................", 20*2); /*  3 */
00311             std::strncpy(_point_xpm[17], "........................................", 20*2); /*  4 */
00312             std::strncpy(_point_xpm[18], "........................................", 20*2); /*  5 */
00313             std::strncpy(_point_xpm[19], "........................................", 20*2); /*  6 */
00314             std::strncpy(_point_xpm[20], "........................................", 20*2); /*  7 */
00315             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00316             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00317             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00318             break;
00319         }
00320         case WxCurve_PS_CIRC:
00321         {
00322             /*                           0         1         2         3         4
00323                                          01234567890123456789012345678901234567890             00 */
00324             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00325             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00326             std::strncpy(_point_xpm[ 6], "........................................", 20*2); /*  3 */
00327             std::strncpy(_point_xpm[ 7], "........................................", 20*2); /*  4 */
00328             std::strncpy(_point_xpm[ 8], "........................................", 20*2); /*  5 */
00329             std::strncpy(_point_xpm[ 9], "........................................", 20*2); /*  6 */
00330             std::strncpy(_point_xpm[10], ".................#.#.#..................", 20*2); /*  7 */
00331             std::strncpy(_point_xpm[11], "...............#.......#................", 20*2); /*  8 */
00332             std::strncpy(_point_xpm[12], ".............#...........#..............", 20*2); /*  9 */
00333             std::strncpy(_point_xpm[13], ".............#...........#..............", 20*2); /* 10 */
00334             std::strncpy(_point_xpm[14], ".............#...........#..............", 20*2); /*  1 */
00335             std::strncpy(_point_xpm[15], "...............#.......#................", 20*2); /*  2 */
00336             std::strncpy(_point_xpm[16], ".................#.#.#..................", 20*2); /*  3 */
00337             std::strncpy(_point_xpm[17], "........................................", 20*2); /*  4 */
00338             std::strncpy(_point_xpm[18], "........................................", 20*2); /*  5 */
00339             std::strncpy(_point_xpm[19], "........................................", 20*2); /*  6 */
00340             std::strncpy(_point_xpm[20], "........................................", 20*2); /*  7 */
00341             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00342             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00343             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00344             break;
00345         }
00346         case WxCurve_PS_CIRC_MED:
00347         {
00348             /*                           0         1         2         3         4
00349                                          01234567890123456789012345678901234567890             00 */
00350             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00351             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00352             std::strncpy(_point_xpm[ 6], "........................................", 20*2); /*  3 */
00353             std::strncpy(_point_xpm[ 7], "........................................", 20*2); /*  4 */
00354             std::strncpy(_point_xpm[ 8], "...............#.#.#.#.#................", 20*2); /*  5 */
00355             std::strncpy(_point_xpm[ 9], "...........#.#.;.;.;.;.;.#.#............", 20*2); /*  6 */
00356             std::strncpy(_point_xpm[10], "...........#.;.;.;.;.;.;.;.#............", 20*2); /*  7 */
00357             std::strncpy(_point_xpm[11], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  8 */
00358             std::strncpy(_point_xpm[12], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  9 */
00359             std::strncpy(_point_xpm[13], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /* 10 */
00360             std::strncpy(_point_xpm[14], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  1 */
00361             std::strncpy(_point_xpm[15], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  2 */
00362             std::strncpy(_point_xpm[16], "...........#.;.;.;.;.;.;.;.#............", 20*2); /*  3 */
00363             std::strncpy(_point_xpm[17], "...........#.#.;.;.;.;.;.#.#............", 20*2); /*  4 */
00364             std::strncpy(_point_xpm[18], "...............#.#.#.#.#................", 20*2); /*  5 */
00365             std::strncpy(_point_xpm[19], "........................................", 20*2); /*  6 */
00366             std::strncpy(_point_xpm[20], "........................................", 20*2); /*  7 */
00367             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00368             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00369             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00370             break;
00371         }
00372         case WxCurve_PS_CIRC_BIG:
00373         {
00374             /*                           0         1         2         3         4
00375                                          01234567890123456789012345678901234567890             00 */
00376             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00377             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00378             std::strncpy(_point_xpm[ 6], ".............#.#.#.#.#.#.#..............", 20*2); /*  3 */
00379             std::strncpy(_point_xpm[ 7], "...........#...............#............", 20*2); /*  4 */
00380             std::strncpy(_point_xpm[ 8], ".........#...................#..........", 20*2); /*  5 */
00381             std::strncpy(_point_xpm[ 9], ".......#.......................#........", 20*2); /*  6 */
00382             std::strncpy(_point_xpm[10], ".......#.......................#........", 20*2); /*  7 */
00383             std::strncpy(_point_xpm[11], ".....#...........................#......", 20*2); /*  8 */
00384             std::strncpy(_point_xpm[12], ".....#...........................#......", 20*2); /*  9 */
00385             std::strncpy(_point_xpm[13], ".....#.............#.............#......", 20*2); /* 10 */
00386             std::strncpy(_point_xpm[14], ".....#...........................#......", 20*2); /*  1 */
00387             std::strncpy(_point_xpm[15], ".....#...........................#......", 20*2); /*  2 */
00388             std::strncpy(_point_xpm[16], ".......#.......................#........", 20*2); /*  3 */
00389             std::strncpy(_point_xpm[17], ".......#.......................#........", 20*2); /*  4 */
00390             std::strncpy(_point_xpm[18], ".........#...................#..........", 20*2); /*  5 */
00391             std::strncpy(_point_xpm[19], "...........#...............#............", 20*2); /*  6 */
00392             std::strncpy(_point_xpm[20], ".............#.#.#.#.#.#.#..............", 20*2); /*  7 */
00393             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00394             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00395             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00396             break;
00397         }
00398         case WxCurve_PS_CROSS_BIG:
00399         {
00400             /*                           0         1         2         3         4
00401                                          01234567890123456789012345678901234567890             00 */
00402             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00403             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00404             std::strncpy(_point_xpm[ 6], "...................#....................", 20*2); /*  3 */
00405             std::strncpy(_point_xpm[ 7], "...................#....................", 20*2); /*  4 */
00406             std::strncpy(_point_xpm[ 8], "...................#....................", 20*2); /*  5 */
00407             std::strncpy(_point_xpm[ 9], "...................#....................", 20*2); /*  6 */
00408             std::strncpy(_point_xpm[10], "...................#....................", 20*2); /*  7 */
00409             std::strncpy(_point_xpm[11], "...................#....................", 20*2); /*  8 */
00410             std::strncpy(_point_xpm[12], "...................#....................", 20*2); /*  9 */
00411             std::strncpy(_point_xpm[13], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#....", 20*2); /* 10 */
00412             std::strncpy(_point_xpm[14], "...................#....................", 20*2); /*  1 */
00413             std::strncpy(_point_xpm[15], "...................#....................", 20*2); /*  2 */
00414             std::strncpy(_point_xpm[16], "...................#....................", 20*2); /*  3 */
00415             std::strncpy(_point_xpm[17], "...................#....................", 20*2); /*  4 */
00416             std::strncpy(_point_xpm[18], "...................#....................", 20*2); /*  5 */
00417             std::strncpy(_point_xpm[19], "...................#....................", 20*2); /*  6 */
00418             std::strncpy(_point_xpm[20], "...................#....................", 20*2); /*  7 */
00419             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00420             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00421             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00422             break;
00423         }
00424         case WxCurve_PS_SQUARE_MED:
00425         {
00426             /*                           0         1         2         3         4
00427                                          01234567890123456789012345678901234567890             00 */
00428             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00429             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00430             std::strncpy(_point_xpm[ 6], "........................................", 20*2); /*  3 */
00431             std::strncpy(_point_xpm[ 7], "........................................", 20*2); /*  4 */
00432             std::strncpy(_point_xpm[ 8], ".........#.#.#.#.#.#.#.#.#.#.#..........", 20*2); /*  5 */
00433             std::strncpy(_point_xpm[ 9], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  6 */
00434             std::strncpy(_point_xpm[10], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  7 */
00435             std::strncpy(_point_xpm[11], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  8 */
00436             std::strncpy(_point_xpm[12], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  9 */
00437             std::strncpy(_point_xpm[13], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /* 10 */
00438             std::strncpy(_point_xpm[14], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  1 */
00439             std::strncpy(_point_xpm[15], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  2 */
00440             std::strncpy(_point_xpm[16], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  3 */
00441             std::strncpy(_point_xpm[17], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  4 */
00442             std::strncpy(_point_xpm[18], ".........#.#.#.#.#.#.#.#.#.#.#..........", 20*2); /*  5 */
00443             std::strncpy(_point_xpm[19], "........................................", 20*2); /*  6 */
00444             std::strncpy(_point_xpm[20], "........................................", 20*2); /*  7 */
00445             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00446             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00447             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00448             break;
00449         }
00450         case WxCurve_PS_SQUARE_BIG:
00451         {
00452             /*                           0         1         2         3         4
00453                                          01234567890123456789012345678901234567890             00 */
00454             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00455             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00456             std::strncpy(_point_xpm[ 6], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2); /*  3 */
00457             std::strncpy(_point_xpm[ 7], ".....#.............#.............#......", 20*2); /*  4 */
00458             std::strncpy(_point_xpm[ 8], ".....#.............#.............#......", 20*2); /*  5 */
00459             std::strncpy(_point_xpm[ 9], ".....#.............#.............#......", 20*2); /*  6 */
00460             std::strncpy(_point_xpm[10], ".....#.............#.............#......", 20*2); /*  7 */
00461             std::strncpy(_point_xpm[11], ".....#.............#.............#......", 20*2); /*  8 */
00462             std::strncpy(_point_xpm[12], ".....#.............#.............#......", 20*2); /*  9 */
00463             std::strncpy(_point_xpm[13], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2); /* 10 */
00464             std::strncpy(_point_xpm[14], ".....#.............#.............#......", 20*2); /*  1 */
00465             std::strncpy(_point_xpm[15], ".....#.............#.............#......", 20*2); /*  2 */
00466             std::strncpy(_point_xpm[16], ".....#.............#.............#......", 20*2); /*  3 */
00467             std::strncpy(_point_xpm[17], ".....#.............#.............#......", 20*2); /*  4 */
00468             std::strncpy(_point_xpm[18], ".....#.............#.............#......", 20*2); /*  5 */
00469             std::strncpy(_point_xpm[19], ".....#.............#.............#......", 20*2); /*  6 */
00470             std::strncpy(_point_xpm[20], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2); /*  7 */
00471             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00472             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00473             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00474             break;
00475         }
00476         case WxCurve_PS_CIRC_CROSS_BIG:
00477         {
00478             /*                           0         1         2         3         4
00479                                          01234567890123456789012345678901234567890             00 */
00480             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00481             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00482             std::strncpy(_point_xpm[ 6], ".............#.#.#.#.#.#.#..............", 20*2); /*  3 */
00483             std::strncpy(_point_xpm[ 7], "...........#.......#.......#............", 20*2); /*  4 */
00484             std::strncpy(_point_xpm[ 8], ".........#.........#.........#..........", 20*2); /*  5 */
00485             std::strncpy(_point_xpm[ 9], ".......#...........#...........#........", 20*2); /*  6 */
00486             std::strncpy(_point_xpm[10], ".......#...........#...........#........", 20*2); /*  7 */
00487             std::strncpy(_point_xpm[11], ".....#.............#.............#......", 20*2); /*  8 */
00488             std::strncpy(_point_xpm[12], ".....#.............#.............#......", 20*2); /*  9 */
00489             std::strncpy(_point_xpm[13], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2); /* 10 */
00490             std::strncpy(_point_xpm[14], ".....#.............#.............#......", 20*2); /*  1 */
00491             std::strncpy(_point_xpm[15], ".....#.............#.............#......", 20*2); /*  2 */
00492             std::strncpy(_point_xpm[16], ".......#...........#...........#........", 20*2); /*  3 */
00493             std::strncpy(_point_xpm[17], ".......#...........#...........#........", 20*2); /*  4 */
00494             std::strncpy(_point_xpm[18], ".........#.........#.........#..........", 20*2); /*  5 */
00495             std::strncpy(_point_xpm[19], "...........#.......#.......#............", 20*2); /*  6 */
00496             std::strncpy(_point_xpm[20], ".............#.#.#.#.#.#.#..............", 20*2); /*  7 */
00497             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00498             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00499             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00500             break;
00501         }
00502         case WxCurve_PS_TARGET_BIG:
00503         {
00504             /*                           0         1         2         3         4
00505                                          01234567890123456789012345678901234567890             00 */
00506             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00507             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00508             std::strncpy(_point_xpm[ 6], ".............#.#.#.#.#.#.#..............", 20*2); /*  3 */
00509             std::strncpy(_point_xpm[ 7], "...........#.;.;.;.;.;.;.;.#............", 20*2); /*  4 */
00510             std::strncpy(_point_xpm[ 8], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  5 */
00511             std::strncpy(_point_xpm[ 9], ".......#.;.;.;.;.;.;.;.;.;.;.;.#........", 20*2); /*  6 */
00512             std::strncpy(_point_xpm[10], ".......#.;.;.;.;.#.#.#.;.;.;.;.#........", 20*2); /*  7 */
00513             std::strncpy(_point_xpm[11], ".....#.;.;.;.;.#.;.;.;.#.;.;.;.;.#......", 20*2); /*  8 */
00514             std::strncpy(_point_xpm[12], ".....#.;.;.;.#.;.;.;.;.;.#.;.;.;.#......", 20*2); /*  9 */
00515             std::strncpy(_point_xpm[13], ".....#.;.;.;.#.;.;.;.;.;.#.;.;.;.#......", 20*2); /* 10 */
00516             std::strncpy(_point_xpm[14], ".....#.;.;.;.#.;.;.;.;.;.#.;.;.;.#......", 20*2); /*  1 */
00517             std::strncpy(_point_xpm[15], ".....#.;.;.;.;.#.;.;.;.#.;.;.;.;.#......", 20*2); /*  2 */
00518             std::strncpy(_point_xpm[16], ".......#.;.;.;.;.#.#.#.;.;.;.;.#........", 20*2); /*  3 */
00519             std::strncpy(_point_xpm[17], ".......#.;.;.;.;.;.;.;.;.;.;.;.#........", 20*2); /*  4 */
00520             std::strncpy(_point_xpm[18], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2); /*  5 */
00521             std::strncpy(_point_xpm[19], "...........#.;.;.;.;.;.;.;.#............", 20*2); /*  6 */
00522             std::strncpy(_point_xpm[20], ".............#.#.#.#.#.#.#..............", 20*2); /*  7 */
00523             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00524             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00525             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00526             break;
00527         }
00528         case WxCurve_PS_DONUT:
00529         {
00530             /*                           0         1         2         3         4
00531                                          01234567890123456789012345678901234567890             00 */
00532             std::strncpy(_point_xpm[ 4], "........................................", 20*2); /*  1 */
00533             std::strncpy(_point_xpm[ 5], "........................................", 20*2); /*  2 */
00534             std::strncpy(_point_xpm[ 6], "........................................", 20*2); /*  3 */
00535             std::strncpy(_point_xpm[ 7], "........................................", 20*2); /*  4 */
00536             std::strncpy(_point_xpm[ 8], "...............#.#.#.#.#................", 20*2); /*  5 */
00537             std::strncpy(_point_xpm[ 9], "...........#.#.#.#.#.#.#.#.#............", 20*2); /*  6 */
00538             std::strncpy(_point_xpm[10], "...........#.#.#.#.#.#.#.#.#............", 20*2); /*  7 */
00539             std::strncpy(_point_xpm[11], ".........#.#.#.#.;.;.;.#.#.#.#..........", 20*2); /*  8 */
00540             std::strncpy(_point_xpm[12], ".........#.#.#.;.;.;.;.;.#.#.#..........", 20*2); /*  9 */
00541             std::strncpy(_point_xpm[13], ".........#.#.#.;.;.;.;.;.#.#.#..........", 20*2); /* 10 */
00542             std::strncpy(_point_xpm[14], ".........#.#.#.;.;.;.;.;.#.#.#..........", 20*2); /*  1 */
00543             std::strncpy(_point_xpm[15], ".........#.#.#.#.;.;.;.#.#.#.#..........", 20*2); /*  2 */
00544             std::strncpy(_point_xpm[16], "...........#.#.#.#.#.#.#.#.#............", 20*2); /*  3 */
00545             std::strncpy(_point_xpm[17], "...........#.#.#.#.#.#.#.#.#............", 20*2); /*  4 */
00546             std::strncpy(_point_xpm[18], "...............#.#.#.#.#................", 20*2); /*  5 */
00547             std::strncpy(_point_xpm[19], "........................................", 20*2); /*  6 */
00548             std::strncpy(_point_xpm[20], "........................................", 20*2); /*  7 */
00549             std::strncpy(_point_xpm[21], "........................................", 20*2); /*  8 */
00550             std::strncpy(_point_xpm[22], "........................................", 20*2); /*  9 */
00551             std::strncpy(_point_xpm[23], "........................................", 20*2); /* 20 */
00552             break;
00553         }
00554     }
00555 
00556     // Set _point_type
00557     _point_type = PS;
00558 
00559     // Return
00560     return (*this);
00561 } // }}}
00562 
00563 inline void WxCurve::UpdateSize(WxTransformData const & TD) // {{{
00564 {
00565     for (int i=0; i<_size; ++i)
00566         WxReal2Canvas(TD, _x[i],_y[i], _points[i].x,_points[i].y);
00567 } // }}}
00568 
00569 inline void WxCurve::GetRange(REAL & MinX, REAL & MaxX,  REAL & MinY, REAL & MaxY) const // {{{
00570 {
00571     MinX = _min_x;  MaxX = _max_x;
00572     MinY = _min_y;  MaxY = _max_y;
00573 } // }}}
00574 
00575 inline void WxCurve::DrawLine(wxDC & DC) // {{{ 
00576 {
00577     if (!_enabled) return;
00578     DC.SetPen (_line_pen);
00579     if (_is_contour)
00580     {
00581         for (int i=0; i<_size-1; i+=2)
00582         {
00583             wxPoint * pts = new wxPoint [2];
00584             pts[0].x=_points[i  ].x;  pts[0].y=_points[i  ].y;
00585             pts[1].x=_points[i+1].x;  pts[1].y=_points[i+1].y;
00586             DC.DrawLines(2,pts);
00587             delete [] pts;
00588         }
00589     }
00590     else
00591         DC.DrawLines (_size, _points);
00592 } // }}}
00593 
00594 inline void WxCurve::DrawPoints(wxDC & DC) // {{{ 
00595 {
00596     if (!_enabled) return;
00597     if (_point_type==WxCurve_PS_NONE) return;
00598     wxIcon icon(_point_xpm);
00599     for (int i=0; i<_size; ++i)
00600         DC.DrawIcon(icon, _points[i].x-9, _points[i].y-9); // -9 ~ half width and half height
00601 } // }}}
00602 
00603 inline void WxCurve::ResetData(REAL const * X, REAL const * Y, int Size) // {{{ 
00604 {
00605     // Delete arrays of data
00606     if (_size>0)
00607     {
00608         delete [] _x;
00609         delete [] _y;
00610         delete [] _points;
00611     }
00612     else return;
00613 
00614     // Allocate arrays of data
00615       _size = Size;
00616          _x = new REAL    [_size];
00617          _y = new REAL    [_size];
00618     _points = new wxPoint [_size];
00619     for (int i=0; i<_size; ++i)
00620     {
00621              _x[i]   = X[i];
00622              _y[i]   = Y[i];
00623         _points[i].x = 0;
00624         _points[i].y = 0;
00625     }
00626 
00627     // Get bounding box
00628     _bounding_box();
00629 } // }}}
00630 
00631 inline void WxCurve::ResetData(Array<REAL> const & X, Array<REAL> const & Y) // {{{ 
00632 {
00633     // Delete arrays of data
00634     if (_size>0)
00635     {
00636         delete [] _x;
00637         delete [] _y;
00638         delete [] _points;
00639     }
00640     else return;
00641 
00642     // Allocate arrays of data
00643       _size = X.size();
00644          _x = new REAL    [_size];
00645          _y = new REAL    [_size];
00646     _points = new wxPoint [_size];
00647     for (int i=0; i<_size; ++i)
00648     {
00649              _x[i]   = X[i];
00650              _y[i]   = Y[i];
00651         _points[i].x = 0;
00652         _points[i].y = 0;
00653     }
00654 
00655     // Get bounding box
00656     _bounding_box();
00657 } // }}}
00658 
00659 inline void WxCurve::ResetData(REAL x_min, REAL x_max, REAL y_min, REAL y_max, int nDiv, REAL DelPctX, REAL DelPctY) // {{{
00660 {
00661     // Delete arrays of data
00662     if (_grid_size>0)
00663     {
00664         delete [] _grid_x;
00665         delete [] _grid_y;  for (int i=0; i<_grid_size; ++i)
00666         delete [] _grid_f[i];
00667         delete [] _grid_f;
00668     }
00669     else return;
00670 
00671     // New grid size
00672     _grid_size = nDiv;
00673 
00674     // Set limits
00675     _min_x=x_min; _max_x=x_max;
00676     _min_y=y_min; _max_y=y_max;
00677     _x_range = _max_x - _min_x;
00678     _y_range = _max_y - _min_y;
00679 
00680     // Allocate and generate grid
00681     REAL         dx = DelPctX*_x_range;
00682     REAL         dy = DelPctY*_y_range;
00683     REAL    start_x = _min_x-dx;
00684     REAL      end_x = _max_x+dx;
00685     REAL    start_y = _min_y-dy;
00686     REAL      end_y = _max_y+dy;
00687             _grid_x = new REAL [_grid_size];
00688             _grid_y = new REAL [_grid_size];
00689     REAL     step_x = (end_x-start_x)/(_grid_size-1.0);
00690     REAL     step_y = (end_y-start_y)/(_grid_size-1.0);
00691          _grid_x[0] = start_x;
00692          _grid_y[0] = start_y;
00693     for (int i=1; i<_grid_size; ++i)  _grid_x[i]=_grid_x[i-1]+step_x;
00694     for (int i=1; i<_grid_size; ++i)  _grid_y[i]=_grid_y[i-1]+step_y;
00695 
00696     // Allocate (void) function values
00697     _grid_f    = new REAL * [_grid_size];  for (int i=0; i<_grid_size; ++i)
00698     _grid_f[i] = new REAL   [_grid_size];
00699 
00700 } // }}}
00701 
00702 inline void WxCurve::SetContour(int nLevels, REAL const * Levels) // {{{ 
00703 {
00704     // Contour
00705     Array<REAL> X;
00706     Array<REAL> Y;
00707     conrec(_grid_f, 0,_grid_size-1,0,_grid_size-1, _grid_x,_grid_y, nLevels,Levels, X,Y);
00708 
00709     // Delete previous arrays of data
00710     if (_size>0)
00711     {
00712         delete [] _x;
00713         delete [] _y;
00714         delete [] _points;
00715     }
00716 
00717     // Allocate arrays of data
00718       _size = X.size();
00719          _x = new REAL    [_size];
00720          _y = new REAL    [_size];
00721     _points = new wxPoint [_size];
00722     for (int i=0; i<_size; ++i)
00723     {
00724              _x[i]   = X[i];
00725              _y[i]   = Y[i];
00726         _points[i].x = 0;
00727         _points[i].y = 0;
00728     }
00729 
00730     // Get bounding box
00731     _bounding_box();
00732 
00733     // Enable
00734     _enabled = true;
00735 } // }}}
00736 
00737 inline void WxCurve::_init_pen_brush() // {{{
00738 {
00739     _line_pen   .SetColour(_T("black"));
00740     _point_pen  .SetColour(_T("blue"));
00741     _point_brush.SetColour(_T("red"));
00742     _line_pen   .SetStyle (wxSOLID);
00743     _point_pen  .SetStyle (wxSOLID);
00744     _point_brush.SetStyle (wxSOLID);
00745     _line_pen   .SetWidth (1);
00746     _point_pen  .SetWidth (1);
00747 } // }}}
00748 
00749 inline void WxCurve::_bounding_box() // {{{
00750 {
00751     int i_min_x=0; int i_max_x=0;
00752     int i_min_y=0; int i_max_y=0;
00753     for (int i=1; i<_size; ++i)
00754     {
00755         if (_x[i]<_x[i_min_x]) i_min_x=i;
00756         if (_x[i]>_x[i_max_x]) i_max_x=i;
00757         if (_y[i]<_y[i_min_y]) i_min_y=i;
00758         if (_y[i]>_y[i_max_y]) i_max_y=i;
00759     }
00760     _min_x=_x[i_min_x]; _max_x=_x[i_max_x];
00761     _min_y=_y[i_min_y]; _max_y=_y[i_max_y];
00762     _x_range = _max_x - _min_x;
00763     _y_range = _max_y - _min_y;
00764 } // }}}
00765 
00766 inline void WxCurve::_allocate_xpm() // {{{
00767 {
00768     _point_xpm    = new char* [24]; // 1-setup, 3-colors, 20-pixels
00769     _point_xpm[0] = new char  [10]; // "20 20 3 2" width height num_colors chars_per_pixel
00770     _point_xpm[1] = new char  [10]; // ".. c None"     color - none
00771     _point_xpm[2] = new char  [13]; // ".# c #000000"  color - pen
00772     _point_xpm[3] = new char  [13]; // ".a c #ffffff"  color - brush
00773     std::strncpy(_point_xpm[0], "20 20 3 2"   , 9 );  _point_xpm[0][9]  = '\0';
00774     std::strncpy(_point_xpm[1], ".. c None"   , 9 );  _point_xpm[1][9]  = '\0';
00775     std::strncpy(_point_xpm[2], ".# c #000000", 12);  _point_xpm[2][12] = '\0';
00776     std::strncpy(_point_xpm[3], ".; c None   ", 12);  _point_xpm[3][12] = '\0';
00777     for (int i=0; i<20; ++i)
00778     {
00779         _point_xpm[4+i] = new char [20*2+1]; // 20(width)*2(chars_per_pixel) + '\0'
00780         std::strncpy(_point_xpm[4+i], "........................................", 20*2);  _point_xpm[4+i][20*2] = '\0';
00781     }
00782 } // }}}
00783 
00784 inline void WxCurve::_colour_to_hex(const wxColour & Col, char * HexBufferSizeEq8) // {{{
00785 {
00786     int r = Col.Red  ();
00787     int g = Col.Green();
00788     int b = Col.Blue ();
00789 
00790     std::ostringstream oss; oss<<'#';
00791     oss<<std::hex<<std::setw(2)<<std::setfill('0')<<r;
00792     oss<<std::hex<<std::setw(2)<<std::setfill('0')<<g;
00793     oss<<std::hex<<std::setw(2)<<std::setfill('0')<<b;
00794 
00795     std::strncpy(HexBufferSizeEq8, oss.str().c_str(), 7);
00796     HexBufferSizeEq8[7]='\0';
00797 } // }}}
00798 
00799 #endif // MECHSYS_WXCURVE_H
00800 
00801 // vim:fdm=marker

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