00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00039 WxGrid ();
00040 ~WxGrid ();
00041
00042
00043 WxGrid & Active (bool Val) { _active=Val; return (*this); }
00044 WxGrid & nHLines (int Num);
00045 WxGrid & nVLines (int Num);
00046
00047
00048 void UpdateSize (WxTransformData const & TD);
00049 void Draw (wxDC & DC);
00050 bool IsActive () const { return _active; }
00051
00052 private:
00053
00054 bool _active;
00055 int _n_h_lines;
00056 int _n_v_lines;
00057 Array<wxPoint> _h_start_points;
00058 Array<wxPoint> _h_end_points;
00059 Array<wxPoint> _v_start_points;
00060 Array<wxPoint> _v_end_points;
00061
00062 wxPoint _ori_h_line_start;
00063 wxPoint _ori_h_line_end;
00064 wxPoint _ori_v_line_start;
00065 wxPoint _ori_v_line_end;
00066
00067 };
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
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
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
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
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
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]);
00145 for (int i=0; i<_n_v_lines; ++i) DC.DrawLine(_v_start_points[i], _v_end_points[i]);
00146
00147
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