00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using UtmConvert; 00006 using System.Drawing; 00007 00008 namespace system_controller { 00009 class RacePlotterStrategy { 00010 00011 List<UtmPoint> _fiducials; 00012 List<UtmPoint> _waypoints; 00013 00014 System.Drawing.Point _click1, _click2; 00015 UtmPoint _utmPoint1, _utmPoint2; 00016 00017 float _scaleDeltaX; 00018 public float ScaleDeltaX { 00019 get { return _scaleDeltaX; } 00020 } 00021 00022 float _scaleDeltaY; 00023 public float ScaleDeltaY { 00024 get { return _scaleDeltaY; } 00025 } 00026 00027 float _scaleX; 00028 public float ScaleX { 00029 get { return _scaleX; } 00030 } 00031 00032 float _scaleY; 00033 public float ScaleY { 00034 get { return _scaleY; } 00035 } 00036 00037 public RacePlotterStrategy() { 00038 _click1 = new System.Drawing.Point(); 00039 _click2 = new System.Drawing.Point(); 00040 _utmPoint1 = new UtmPoint(); 00041 _utmPoint2 = new UtmPoint(); 00042 } 00043 00044 public void drawRacePath(ref Bitmap map) { 00045 float deltaClickX = (float)_click2.X - (float)_click1.X; 00046 float deltaClickY = (float)_click2.Y - (float)_click1.Y; 00047 float deltaUtmX = (float)(_utmPoint2.Point.X - _utmPoint1.Point.X); 00048 float deltaUtmY = (float)(_utmPoint2.Point.Y - _utmPoint1.Point.Y); 00049 _scaleDeltaX = deltaClickX / deltaUtmX; 00050 _scaleDeltaY = deltaClickY / deltaUtmY; 00051 _scaleX = (float)_click1.X / (float)_utmPoint1.Point.X; 00052 _scaleY = (float)_click1.Y / (float)_utmPoint1.Point.Y; 00053 Graphics g = Graphics.FromImage(map); 00054 Pen pen = new Pen(Color.Red, 8); 00055 SolidBrush brush = new SolidBrush(Color.Orange); 00056 SolidBrush gBrush = new SolidBrush(Color.Gray); 00057 float nextX = 0, nextY = 0; 00058 for (int i = 0; i < _parser.UtmPointSetList[0].Points.Count; ++i) { 00059 float deltaX = (float)(_parser.UtmPointSetList[0].Points[i].Point.X) 00060 - (float)(_utmPoint1.Point.X); 00061 float deltaY = (float)(_parser.UtmPointSetList[0].Points[i].Point.Y) 00062 - (float)(_utmPoint1.Point.Y); 00063 float x1 = (float)(_parser.UtmPointSetList[0].Points[i].Point.X); 00064 float y1 = (float)(_parser.UtmPointSetList[0].Points[i].Point.Y); 00065 if (_parser.UtmPointSetList[0].Points[i].Note == "dummy") 00066 g.FillEllipse(gBrush, x1 * _scaleX + deltaX * _scaleDeltaX 00067 - 16, y1 * _scaleY + deltaY * _scaleDeltaY - 16, 32, 32); 00068 else 00069 g.FillEllipse(brush, x1 * _scaleX + deltaX * _scaleDeltaX 00070 - 16, y1 * _scaleY + deltaY * _scaleDeltaY - 16, 32, 32); 00071 g.DrawLine(pen, x1 * _scaleX + nextX, y1 * _scaleY + nextY 00072 , x1 * _scaleX + deltaX * _scaleDeltaX 00073 , y1 * _scaleY + deltaY * _scaleDeltaY); 00074 nextX = _scaleX + deltaX * _scaleDeltaX; 00075 nextY = _scaleY + deltaY * _scaleDeltaY; 00076 } 00077 } 00078 00079 public void drawClickedWaypoint(ref Bitmap map, int x, int y) { 00080 if (_click1.IsEmpty) { _click1.X = x; _click1.Y = y; } else { _click2.X = x; _click2.Y = y; } 00081 Graphics g = Graphics.FromImage(map); 00082 SolidBrush brush = new SolidBrush(Color.Green); 00083 g.FillEllipse(brush, x - 16, y - 16, 32, 32); 00084 } 00085 00086 } 00087 }