wxgrid.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_WXGRID_H
00023 #define MECHSYS_WXGRID_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026   #include "config.h"
00027 #else
00028   #ifndef REAL
00029     #define REAL double
00030   #endif
00031 #endif
00032 
00033 #include "gui/wxtransform.h"
00034 
00035 class WxGrid
00036 {
00037 public:
00038     // Constructor & Destructor
00039      WxGrid ();
00040     ~WxGrid ();
00041 
00042     // Config Methods
00043     WxGrid & Active  (bool Val) { _active=Val; return (*this); }
00044     WxGrid & nHLines (int  Num);
00045     WxGrid & nVLines (int  Num);
00046 
00047     // Methods
00048     void UpdateSize (WxTransformData const & TD);
00049     void Draw       (wxDC & DC);
00050     bool IsActive   () const { return _active; }
00051 
00052 private:
00053     // Grid
00054     bool           _active;
00055     int            _n_h_lines;      // number of horizontal lines
00056     int            _n_v_lines;      // number of vertical lines
00057     Array<wxPoint> _h_start_points; // horizontal lines
00058     Array<wxPoint> _h_end_points;   // horizontal lines
00059     Array<wxPoint> _v_start_points; // vertical lines
00060     Array<wxPoint> _v_end_points;   // vertical lines
00061     // Origin (cross)
00062     wxPoint        _ori_h_line_start; // horizontal passing by origin
00063     wxPoint        _ori_h_line_end;   
00064     wxPoint        _ori_v_line_start; // vertical passing by origin
00065     wxPoint        _ori_v_line_end;   
00066 
00067 }; // class WxGrid
00068 
00069 
00071 
00072 inline WxGrid::WxGrid() // {{{
00073     : _active(true)
00074 {
00075     nHLines(10);
00076     nVLines(10);
00077 } // }}}
00078 
00079 inline WxGrid::~WxGrid() // {{{
00080 {
00081 } // }}}
00082 
00083 inline WxGrid & WxGrid::nHLines(int Num) // {{{
00084 {
00085     _n_h_lines = Num;
00086     _h_start_points.resize(_n_h_lines);
00087     _h_end_points  .resize(_n_h_lines);
00088     return (*this);
00089 } // }}}
00090 
00091 inline WxGrid & WxGrid::nVLines(int Num) // {{{
00092 {
00093     _n_v_lines = Num;
00094     _v_start_points.resize(_n_v_lines);
00095     _v_end_points  .resize(_n_v_lines);
00096     return (*this);
00097 } // }}}
00098 
00099 inline void WxGrid::UpdateSize(WxTransformData const & TD) // {{{
00100 {
00101     // Horizontal lines
00102     int h_step = TD.CanvasRect.height/_n_h_lines;
00103     _h_start_points[0].x = TD.CanvasRect.x;
00104     _h_start_points[0].y = TD.CanvasRect.y;
00105     _h_end_points  [0].x = _h_start_points[0].x + TD.CanvasRect.width;
00106     _h_end_points  [0].y = _h_start_points[0].y;
00107     for (int i=1; i<_n_h_lines; ++i)
00108     {
00109         _h_start_points[i].x = TD.CanvasRect.x;
00110         _h_start_points[i].y = _h_start_points[i-1].y + h_step;
00111         _h_end_points  [i].x = _h_start_points[i].x + TD.CanvasRect.width;
00112         _h_end_points  [i].y = _h_start_points[i].y;
00113     }
00114 
00115     // Vertical lines
00116     int v_step = TD.CanvasRect.width /_n_v_lines;
00117     _v_start_points[0].x = TD.CanvasRect.x;
00118     _v_start_points[0].y = TD.CanvasRect.y;
00119     _v_end_points  [0].x = _v_start_points[0].x;
00120     _v_end_points  [0].y = _v_start_points[0].y + TD.CanvasRect.height;
00121     for (int i=1; i<_n_v_lines; ++i)
00122     {
00123         _v_start_points[i].x = _v_start_points[i-1].x + v_step;
00124         _v_start_points[i].y = TD.CanvasRect.y;
00125         _v_end_points  [i].x = _v_start_points[i].x;
00126         _v_end_points  [i].y = _v_start_points[i].y + TD.CanvasRect.height;
00127     }
00128 
00129     // Horizontal line passing by origin (cross)
00130     WxReal2Canvas(TD, TD.xMin,0.0, _ori_h_line_start.x, _ori_h_line_start.y);
00131     WxReal2Canvas(TD, TD.xMax,0.0, _ori_h_line_end  .x, _ori_h_line_end  .y);
00132 
00133     // Vertical line passing by origin (cross)
00134     WxReal2Canvas(TD, 0.0,TD.yMin, _ori_v_line_start.x, _ori_v_line_start.y);
00135     WxReal2Canvas(TD, 0.0,TD.yMax, _ori_v_line_end  .x, _ori_v_line_end  .y);
00136 } // }}}
00137 
00138 inline void WxGrid::Draw(wxDC & DC) // {{{
00139 {
00140     if (_active)
00141     {
00142         // Grid lines
00143         DC.SetPen(wxPen(_T("gray"), 1, wxDOT));
00144         for (int i=0; i<_n_h_lines; ++i) DC.DrawLine(_h_start_points[i], _h_end_points[i]); // Horizontal lines
00145         for (int i=0; i<_n_v_lines; ++i) DC.DrawLine(_v_start_points[i], _v_end_points[i]); // Vertical lines
00146 
00147         // Cross lines
00148         DC.SetPen(wxPen(_T("black")));
00149         DC.DrawLine(_ori_h_line_start, _ori_h_line_end);
00150         DC.DrawLine(_ori_v_line_start, _ori_v_line_end);
00151     }
00152 } // }}}
00153 
00154 #endif // MECHSYS_WXGRID_H
00155 
00156 // vim:fdm=marker

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