00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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 };
00060
00061
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
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
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
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;
00102 REAL _sf_y;
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
00112 wxPoint * _points;
00113 wxPen _line_pen;
00114 wxPen _point_pen;
00115 wxBrush _point_brush;
00116
00117
00118 void _init_pen_brush();
00119 void _bounding_box ();
00120 void _allocate_xpm ();
00121 void _colour_to_hex (wxColour const & Col, char * HexBufferSizeEq8);
00122 };
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
00136 _init_pen_brush();
00137
00138
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
00151 _bounding_box();
00152
00153
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
00165 _init_pen_brush();
00166
00167
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
00180 _bounding_box();
00181
00182
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
00194 _init_pen_brush();
00195
00196
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
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
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
00223 _allocate_xpm();
00224 }
00225
00226 inline WxCurve::~WxCurve()
00227 {
00228
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
00244 delete [] _point_xpm[0];
00245 delete [] _point_xpm[1];
00246 delete [] _point_xpm[2];
00247 delete [] _point_xpm[3];
00248 for (int i=0; i<20; ++i)
00249 delete [] _point_xpm[4+i];
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
00279 if (PS==_point_type) return (*this);
00280
00281
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
00290 switch (PS)
00291 {
00292 case WxCurve_PS_NONE:
00293 break;
00294 case WxCurve_PS_DOT:
00295 {
00296
00297
00298 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00299 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00300 std::strncpy(_point_xpm[ 6], "........................................", 20*2);
00301 std::strncpy(_point_xpm[ 7], "........................................", 20*2);
00302 std::strncpy(_point_xpm[ 8], "........................................", 20*2);
00303 std::strncpy(_point_xpm[ 9], "........................................", 20*2);
00304 std::strncpy(_point_xpm[10], "........................................", 20*2);
00305 std::strncpy(_point_xpm[11], ".................#.#.#..................", 20*2);
00306 std::strncpy(_point_xpm[12], "...............#.#.#.#.#................", 20*2);
00307 std::strncpy(_point_xpm[13], "...............#.#.#.#.#................", 20*2);
00308 std::strncpy(_point_xpm[14], "...............#.#.#.#.#................", 20*2);
00309 std::strncpy(_point_xpm[15], ".................#.#.#..................", 20*2);
00310 std::strncpy(_point_xpm[16], "........................................", 20*2);
00311 std::strncpy(_point_xpm[17], "........................................", 20*2);
00312 std::strncpy(_point_xpm[18], "........................................", 20*2);
00313 std::strncpy(_point_xpm[19], "........................................", 20*2);
00314 std::strncpy(_point_xpm[20], "........................................", 20*2);
00315 std::strncpy(_point_xpm[21], "........................................", 20*2);
00316 std::strncpy(_point_xpm[22], "........................................", 20*2);
00317 std::strncpy(_point_xpm[23], "........................................", 20*2);
00318 break;
00319 }
00320 case WxCurve_PS_CIRC:
00321 {
00322
00323
00324 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00325 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00326 std::strncpy(_point_xpm[ 6], "........................................", 20*2);
00327 std::strncpy(_point_xpm[ 7], "........................................", 20*2);
00328 std::strncpy(_point_xpm[ 8], "........................................", 20*2);
00329 std::strncpy(_point_xpm[ 9], "........................................", 20*2);
00330 std::strncpy(_point_xpm[10], ".................#.#.#..................", 20*2);
00331 std::strncpy(_point_xpm[11], "...............#.......#................", 20*2);
00332 std::strncpy(_point_xpm[12], ".............#...........#..............", 20*2);
00333 std::strncpy(_point_xpm[13], ".............#...........#..............", 20*2);
00334 std::strncpy(_point_xpm[14], ".............#...........#..............", 20*2);
00335 std::strncpy(_point_xpm[15], "...............#.......#................", 20*2);
00336 std::strncpy(_point_xpm[16], ".................#.#.#..................", 20*2);
00337 std::strncpy(_point_xpm[17], "........................................", 20*2);
00338 std::strncpy(_point_xpm[18], "........................................", 20*2);
00339 std::strncpy(_point_xpm[19], "........................................", 20*2);
00340 std::strncpy(_point_xpm[20], "........................................", 20*2);
00341 std::strncpy(_point_xpm[21], "........................................", 20*2);
00342 std::strncpy(_point_xpm[22], "........................................", 20*2);
00343 std::strncpy(_point_xpm[23], "........................................", 20*2);
00344 break;
00345 }
00346 case WxCurve_PS_CIRC_MED:
00347 {
00348
00349
00350 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00351 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00352 std::strncpy(_point_xpm[ 6], "........................................", 20*2);
00353 std::strncpy(_point_xpm[ 7], "........................................", 20*2);
00354 std::strncpy(_point_xpm[ 8], "...............#.#.#.#.#................", 20*2);
00355 std::strncpy(_point_xpm[ 9], "...........#.#.;.;.;.;.;.#.#............", 20*2);
00356 std::strncpy(_point_xpm[10], "...........#.;.;.;.;.;.;.;.#............", 20*2);
00357 std::strncpy(_point_xpm[11], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00358 std::strncpy(_point_xpm[12], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00359 std::strncpy(_point_xpm[13], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00360 std::strncpy(_point_xpm[14], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00361 std::strncpy(_point_xpm[15], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00362 std::strncpy(_point_xpm[16], "...........#.;.;.;.;.;.;.;.#............", 20*2);
00363 std::strncpy(_point_xpm[17], "...........#.#.;.;.;.;.;.#.#............", 20*2);
00364 std::strncpy(_point_xpm[18], "...............#.#.#.#.#................", 20*2);
00365 std::strncpy(_point_xpm[19], "........................................", 20*2);
00366 std::strncpy(_point_xpm[20], "........................................", 20*2);
00367 std::strncpy(_point_xpm[21], "........................................", 20*2);
00368 std::strncpy(_point_xpm[22], "........................................", 20*2);
00369 std::strncpy(_point_xpm[23], "........................................", 20*2);
00370 break;
00371 }
00372 case WxCurve_PS_CIRC_BIG:
00373 {
00374
00375
00376 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00377 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00378 std::strncpy(_point_xpm[ 6], ".............#.#.#.#.#.#.#..............", 20*2);
00379 std::strncpy(_point_xpm[ 7], "...........#...............#............", 20*2);
00380 std::strncpy(_point_xpm[ 8], ".........#...................#..........", 20*2);
00381 std::strncpy(_point_xpm[ 9], ".......#.......................#........", 20*2);
00382 std::strncpy(_point_xpm[10], ".......#.......................#........", 20*2);
00383 std::strncpy(_point_xpm[11], ".....#...........................#......", 20*2);
00384 std::strncpy(_point_xpm[12], ".....#...........................#......", 20*2);
00385 std::strncpy(_point_xpm[13], ".....#.............#.............#......", 20*2);
00386 std::strncpy(_point_xpm[14], ".....#...........................#......", 20*2);
00387 std::strncpy(_point_xpm[15], ".....#...........................#......", 20*2);
00388 std::strncpy(_point_xpm[16], ".......#.......................#........", 20*2);
00389 std::strncpy(_point_xpm[17], ".......#.......................#........", 20*2);
00390 std::strncpy(_point_xpm[18], ".........#...................#..........", 20*2);
00391 std::strncpy(_point_xpm[19], "...........#...............#............", 20*2);
00392 std::strncpy(_point_xpm[20], ".............#.#.#.#.#.#.#..............", 20*2);
00393 std::strncpy(_point_xpm[21], "........................................", 20*2);
00394 std::strncpy(_point_xpm[22], "........................................", 20*2);
00395 std::strncpy(_point_xpm[23], "........................................", 20*2);
00396 break;
00397 }
00398 case WxCurve_PS_CROSS_BIG:
00399 {
00400
00401
00402 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00403 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00404 std::strncpy(_point_xpm[ 6], "...................#....................", 20*2);
00405 std::strncpy(_point_xpm[ 7], "...................#....................", 20*2);
00406 std::strncpy(_point_xpm[ 8], "...................#....................", 20*2);
00407 std::strncpy(_point_xpm[ 9], "...................#....................", 20*2);
00408 std::strncpy(_point_xpm[10], "...................#....................", 20*2);
00409 std::strncpy(_point_xpm[11], "...................#....................", 20*2);
00410 std::strncpy(_point_xpm[12], "...................#....................", 20*2);
00411 std::strncpy(_point_xpm[13], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#....", 20*2);
00412 std::strncpy(_point_xpm[14], "...................#....................", 20*2);
00413 std::strncpy(_point_xpm[15], "...................#....................", 20*2);
00414 std::strncpy(_point_xpm[16], "...................#....................", 20*2);
00415 std::strncpy(_point_xpm[17], "...................#....................", 20*2);
00416 std::strncpy(_point_xpm[18], "...................#....................", 20*2);
00417 std::strncpy(_point_xpm[19], "...................#....................", 20*2);
00418 std::strncpy(_point_xpm[20], "...................#....................", 20*2);
00419 std::strncpy(_point_xpm[21], "........................................", 20*2);
00420 std::strncpy(_point_xpm[22], "........................................", 20*2);
00421 std::strncpy(_point_xpm[23], "........................................", 20*2);
00422 break;
00423 }
00424 case WxCurve_PS_SQUARE_MED:
00425 {
00426
00427
00428 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00429 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00430 std::strncpy(_point_xpm[ 6], "........................................", 20*2);
00431 std::strncpy(_point_xpm[ 7], "........................................", 20*2);
00432 std::strncpy(_point_xpm[ 8], ".........#.#.#.#.#.#.#.#.#.#.#..........", 20*2);
00433 std::strncpy(_point_xpm[ 9], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00434 std::strncpy(_point_xpm[10], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00435 std::strncpy(_point_xpm[11], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00436 std::strncpy(_point_xpm[12], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00437 std::strncpy(_point_xpm[13], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00438 std::strncpy(_point_xpm[14], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00439 std::strncpy(_point_xpm[15], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00440 std::strncpy(_point_xpm[16], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00441 std::strncpy(_point_xpm[17], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00442 std::strncpy(_point_xpm[18], ".........#.#.#.#.#.#.#.#.#.#.#..........", 20*2);
00443 std::strncpy(_point_xpm[19], "........................................", 20*2);
00444 std::strncpy(_point_xpm[20], "........................................", 20*2);
00445 std::strncpy(_point_xpm[21], "........................................", 20*2);
00446 std::strncpy(_point_xpm[22], "........................................", 20*2);
00447 std::strncpy(_point_xpm[23], "........................................", 20*2);
00448 break;
00449 }
00450 case WxCurve_PS_SQUARE_BIG:
00451 {
00452
00453
00454 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00455 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00456 std::strncpy(_point_xpm[ 6], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2);
00457 std::strncpy(_point_xpm[ 7], ".....#.............#.............#......", 20*2);
00458 std::strncpy(_point_xpm[ 8], ".....#.............#.............#......", 20*2);
00459 std::strncpy(_point_xpm[ 9], ".....#.............#.............#......", 20*2);
00460 std::strncpy(_point_xpm[10], ".....#.............#.............#......", 20*2);
00461 std::strncpy(_point_xpm[11], ".....#.............#.............#......", 20*2);
00462 std::strncpy(_point_xpm[12], ".....#.............#.............#......", 20*2);
00463 std::strncpy(_point_xpm[13], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2);
00464 std::strncpy(_point_xpm[14], ".....#.............#.............#......", 20*2);
00465 std::strncpy(_point_xpm[15], ".....#.............#.............#......", 20*2);
00466 std::strncpy(_point_xpm[16], ".....#.............#.............#......", 20*2);
00467 std::strncpy(_point_xpm[17], ".....#.............#.............#......", 20*2);
00468 std::strncpy(_point_xpm[18], ".....#.............#.............#......", 20*2);
00469 std::strncpy(_point_xpm[19], ".....#.............#.............#......", 20*2);
00470 std::strncpy(_point_xpm[20], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2);
00471 std::strncpy(_point_xpm[21], "........................................", 20*2);
00472 std::strncpy(_point_xpm[22], "........................................", 20*2);
00473 std::strncpy(_point_xpm[23], "........................................", 20*2);
00474 break;
00475 }
00476 case WxCurve_PS_CIRC_CROSS_BIG:
00477 {
00478
00479
00480 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00481 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00482 std::strncpy(_point_xpm[ 6], ".............#.#.#.#.#.#.#..............", 20*2);
00483 std::strncpy(_point_xpm[ 7], "...........#.......#.......#............", 20*2);
00484 std::strncpy(_point_xpm[ 8], ".........#.........#.........#..........", 20*2);
00485 std::strncpy(_point_xpm[ 9], ".......#...........#...........#........", 20*2);
00486 std::strncpy(_point_xpm[10], ".......#...........#...........#........", 20*2);
00487 std::strncpy(_point_xpm[11], ".....#.............#.............#......", 20*2);
00488 std::strncpy(_point_xpm[12], ".....#.............#.............#......", 20*2);
00489 std::strncpy(_point_xpm[13], ".....#.#.#.#.#.#.#.#.#.#.#.#.#.#.#......", 20*2);
00490 std::strncpy(_point_xpm[14], ".....#.............#.............#......", 20*2);
00491 std::strncpy(_point_xpm[15], ".....#.............#.............#......", 20*2);
00492 std::strncpy(_point_xpm[16], ".......#...........#...........#........", 20*2);
00493 std::strncpy(_point_xpm[17], ".......#...........#...........#........", 20*2);
00494 std::strncpy(_point_xpm[18], ".........#.........#.........#..........", 20*2);
00495 std::strncpy(_point_xpm[19], "...........#.......#.......#............", 20*2);
00496 std::strncpy(_point_xpm[20], ".............#.#.#.#.#.#.#..............", 20*2);
00497 std::strncpy(_point_xpm[21], "........................................", 20*2);
00498 std::strncpy(_point_xpm[22], "........................................", 20*2);
00499 std::strncpy(_point_xpm[23], "........................................", 20*2);
00500 break;
00501 }
00502 case WxCurve_PS_TARGET_BIG:
00503 {
00504
00505
00506 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00507 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00508 std::strncpy(_point_xpm[ 6], ".............#.#.#.#.#.#.#..............", 20*2);
00509 std::strncpy(_point_xpm[ 7], "...........#.;.;.;.;.;.;.;.#............", 20*2);
00510 std::strncpy(_point_xpm[ 8], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00511 std::strncpy(_point_xpm[ 9], ".......#.;.;.;.;.;.;.;.;.;.;.;.#........", 20*2);
00512 std::strncpy(_point_xpm[10], ".......#.;.;.;.;.#.#.#.;.;.;.;.#........", 20*2);
00513 std::strncpy(_point_xpm[11], ".....#.;.;.;.;.#.;.;.;.#.;.;.;.;.#......", 20*2);
00514 std::strncpy(_point_xpm[12], ".....#.;.;.;.#.;.;.;.;.;.#.;.;.;.#......", 20*2);
00515 std::strncpy(_point_xpm[13], ".....#.;.;.;.#.;.;.;.;.;.#.;.;.;.#......", 20*2);
00516 std::strncpy(_point_xpm[14], ".....#.;.;.;.#.;.;.;.;.;.#.;.;.;.#......", 20*2);
00517 std::strncpy(_point_xpm[15], ".....#.;.;.;.;.#.;.;.;.#.;.;.;.;.#......", 20*2);
00518 std::strncpy(_point_xpm[16], ".......#.;.;.;.;.#.#.#.;.;.;.;.#........", 20*2);
00519 std::strncpy(_point_xpm[17], ".......#.;.;.;.;.;.;.;.;.;.;.;.#........", 20*2);
00520 std::strncpy(_point_xpm[18], ".........#.;.;.;.;.;.;.;.;.;.#..........", 20*2);
00521 std::strncpy(_point_xpm[19], "...........#.;.;.;.;.;.;.;.#............", 20*2);
00522 std::strncpy(_point_xpm[20], ".............#.#.#.#.#.#.#..............", 20*2);
00523 std::strncpy(_point_xpm[21], "........................................", 20*2);
00524 std::strncpy(_point_xpm[22], "........................................", 20*2);
00525 std::strncpy(_point_xpm[23], "........................................", 20*2);
00526 break;
00527 }
00528 case WxCurve_PS_DONUT:
00529 {
00530
00531
00532 std::strncpy(_point_xpm[ 4], "........................................", 20*2);
00533 std::strncpy(_point_xpm[ 5], "........................................", 20*2);
00534 std::strncpy(_point_xpm[ 6], "........................................", 20*2);
00535 std::strncpy(_point_xpm[ 7], "........................................", 20*2);
00536 std::strncpy(_point_xpm[ 8], "...............#.#.#.#.#................", 20*2);
00537 std::strncpy(_point_xpm[ 9], "...........#.#.#.#.#.#.#.#.#............", 20*2);
00538 std::strncpy(_point_xpm[10], "...........#.#.#.#.#.#.#.#.#............", 20*2);
00539 std::strncpy(_point_xpm[11], ".........#.#.#.#.;.;.;.#.#.#.#..........", 20*2);
00540 std::strncpy(_point_xpm[12], ".........#.#.#.;.;.;.;.;.#.#.#..........", 20*2);
00541 std::strncpy(_point_xpm[13], ".........#.#.#.;.;.;.;.;.#.#.#..........", 20*2);
00542 std::strncpy(_point_xpm[14], ".........#.#.#.;.;.;.;.;.#.#.#..........", 20*2);
00543 std::strncpy(_point_xpm[15], ".........#.#.#.#.;.;.;.#.#.#.#..........", 20*2);
00544 std::strncpy(_point_xpm[16], "...........#.#.#.#.#.#.#.#.#............", 20*2);
00545 std::strncpy(_point_xpm[17], "...........#.#.#.#.#.#.#.#.#............", 20*2);
00546 std::strncpy(_point_xpm[18], "...............#.#.#.#.#................", 20*2);
00547 std::strncpy(_point_xpm[19], "........................................", 20*2);
00548 std::strncpy(_point_xpm[20], "........................................", 20*2);
00549 std::strncpy(_point_xpm[21], "........................................", 20*2);
00550 std::strncpy(_point_xpm[22], "........................................", 20*2);
00551 std::strncpy(_point_xpm[23], "........................................", 20*2);
00552 break;
00553 }
00554 }
00555
00556
00557 _point_type = PS;
00558
00559
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);
00601 }
00602
00603 inline void WxCurve::ResetData(REAL const * X, REAL const * Y, int Size)
00604 {
00605
00606 if (_size>0)
00607 {
00608 delete [] _x;
00609 delete [] _y;
00610 delete [] _points;
00611 }
00612 else return;
00613
00614
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
00628 _bounding_box();
00629 }
00630
00631 inline void WxCurve::ResetData(Array<REAL> const & X, Array<REAL> const & Y)
00632 {
00633
00634 if (_size>0)
00635 {
00636 delete [] _x;
00637 delete [] _y;
00638 delete [] _points;
00639 }
00640 else return;
00641
00642
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
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
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
00672 _grid_size = nDiv;
00673
00674
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
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
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
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
00710 if (_size>0)
00711 {
00712 delete [] _x;
00713 delete [] _y;
00714 delete [] _points;
00715 }
00716
00717
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
00731 _bounding_box();
00732
00733
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];
00769 _point_xpm[0] = new char [10];
00770 _point_xpm[1] = new char [10];
00771 _point_xpm[2] = new char [13];
00772 _point_xpm[3] = new char [13];
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];
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