00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Data;
00005 using System.Drawing;
00006 using System.Linq;
00007 using System.Text;
00008 using System.Windows.Forms;
00009
00010 namespace RacePlotter {
00011 public partial class RacePlotterForm : Form {
00012 bool _addFiducials = false;
00013 bool _addWaypoints = false;
00014 bool _editFiducials = false;
00015 bool _editWaypoints = false;
00016 RacePlotterStrategy _strategy;
00017 PointSelector _pointPicker;
00018 PointEditor _pointEditor;
00019 public RacePlotterForm() {
00020 InitializeComponent();
00021 _strategy = new RacePlotterStrategy(".\\maps\\videra\\");
00022 raceMapPictureBox.Image = _strategy.RaceMap;
00023 redrawMap();
00024 }
00025
00026 private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
00027 this.Close();
00028 }
00029
00030 private void redrawMap() {
00031 _strategy.redrawMap();
00032 raceMapPictureBox.Image = _strategy.RaceMap;
00033 raceMapPictureBox.Invalidate();
00034 }
00035
00036 private void raceMapPictureBox_MouseClick(object sender, MouseEventArgs e) {
00037 if (_addFiducials) {
00038 Bitmap b = new Bitmap(raceMapPictureBox.Image);
00039 _strategy.drawClickedWaypoint(ref b, (int)(e.X * ((double)(b.Width)
00040 / (double)(raceMapPictureBox.Width)))
00041 , (int)(e.Y * ((double)(b.Height) / (double)(raceMapPictureBox.Height))));
00042 raceMapPictureBox.Image = b;
00043 raceMapPictureBox.Invalidate();
00044 _pointPicker = new PointSelector(_strategy.Fiducials);
00045 _pointPicker.pointSelectEvent += onFiducialtAddSelect;
00046
00047 _pointPicker.Show();
00048 } else if(_addWaypoints) {
00049 _pointEditor = new PointEditor(getUtmPointFromScreen(e));
00050 _pointEditor.pointEditEvent += onWaypointAdd;
00051 _pointEditor.Show();
00052 } else if (_editWaypoints) {
00053
00054 }
00055 }
00056
00057
00058 private void onWaypointAdd() {
00059 _strategy.Waypoints.Add(_pointEditor.getEditedPoint());
00060 _pointEditor.Close();
00061 redrawMap();
00062 }
00063
00064 private void onWaypointEditSelect() {
00065 _pointEditor = new PointEditor(_pointPicker.getSelectedPoint());
00066 _pointEditor.pointEditEvent += onWaypointEdit;
00067 _pointEditor.Show();
00068 }
00069
00070 private void onWaypointEdit() {
00071 redrawMap();
00072 }
00073
00074 private void onFiducialtAddSelect() {
00075 if (_strategy.Fiducial1.Handle == "")
00076 _strategy.Fiducial1 = _pointPicker.getSelectedPoint();
00077 else
00078 _strategy.Fiducial2 = _pointPicker.getSelectedPoint();
00079 if (_strategy.Fiducial2.Handle != "") {
00080 _strategy.setScale();
00081 raceMapPictureBox.Image = _strategy.RaceMap;
00082 raceMapPictureBox.Invalidate();
00083 _addFiducials = false;
00084 fiducialsToolStripMenuItem.Enabled = true;
00085 }
00086 }
00087
00088 private void onWaypointSelectCancel() {
00089 }
00090
00091 private UtmConvert.UtmPoint getUtmPointFromScreen(MouseEventArgs e) {
00092 double mouseX = (double)e.X * ((double)raceMapPictureBox.Image.Width
00093 / (double)raceMapPictureBox.Width);
00094 double mouseY = (double)e.Y * ((double)raceMapPictureBox.Image.Height
00095 / (double)raceMapPictureBox.Height);
00096 double x = (double)_strategy.Click1.X / _strategy.ScaleX + (mouseX
00097 - (double)_strategy.Click1.X) / _strategy.ScaleDeltaX;
00098 double y = (double)_strategy.Click1.Y / _strategy.ScaleY + (mouseY
00099 - (double)_strategy.Click1.Y) / _strategy.ScaleDeltaY;
00100 return new UtmConvert.UtmPoint(new UtmConvert.Point(x, y), "", "", "");
00101
00102 }
00103
00104 private void raceMapPictureBox_MouseMove(object sender, MouseEventArgs e) {
00105 if (_strategy.Fiducial2.Handle != "" && RacePlotterForm.ActiveForm != null) {
00106 toolStripStatusLabel1.Text = Math.Round(getUtmPointFromScreen(e).Point.X, 4).ToString()
00107 + ", " + Math.Round(getUtmPointFromScreen(e).Point.Y, 4).ToString();
00108 }
00109 }
00110
00111 private void addToolStripMenuItem1_Click(object sender, EventArgs e) {
00112 _addFiducials = true;
00113 fiducialsToolStripMenuItem.Enabled = false;
00114 _strategy.resetFiducial();
00115 }
00116
00117 private void addToolStripMenuItem2_Click(object sender, EventArgs e) {
00118 _addFiducials = false;
00119 fiducialsToolStripMenuItem.Enabled = false;
00120 _addWaypoints = true;
00121 }
00122
00123 private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
00124 _strategy.saveWaypoints();
00125 }
00126
00127 private void editToolStripMenuItem2_Click(object sender, EventArgs e) {
00128 _pointPicker = new PointSelector(_strategy.Waypoints);
00129 _pointPicker.pointSelectEvent += onWaypointEditSelect;
00130 _pointPicker.Show();
00131 }
00132
00133 }
00134 }