Form1.cs
上传用户:tupian
上传日期:2009-05-04
资源大小:93k
文件大小:6k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Drawing.Text;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Windows;
- using System.Threading;
- using System.IO.Ports;
- using System.IO;
- using GpsTracer;
- namespace GpsTracer
- {
- public partial class Form1 : Form
- {
- private reader m_rTh;
- private Mapper m_mapper;
- private Graphics m_graphics;
- private bool m_isDemoMode = false;
- private String m_port = "COM5";
- private bool m_isRunning = false;
- private bool m_log = false;
- private StreamWriter m_logSW;
- public Form1()
- {
- InitializeComponent();
- m_graphics = this.CreateGraphics();
- m_rTh = new reader(m_port);
- m_mapper = new Mapper(m_graphics, 0, 30, 240, 300);
- m_rTh.dataReceived += new reader.DataReceivedEventHandler(parse);
- m_logSW = File.CreateText("GpsTracer.Log");
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- }
- public void parse(String readed)
- {
- if (m_log)
- {
- m_logSW.WriteLine(readed);
- m_logSW.Flush();
- }
- m_mapper.parseAndDraw(readed);
- }
- private void menuItemRunStop_Click(object sender, EventArgs e)
- {
- if (m_isRunning)
- {
- m_rTh.stop();
- }
- else
- {
- m_rTh.start(m_isDemoMode);
- }
- menuItemRunStop.Checked = !menuItemRunStop.Checked;
- m_isRunning = !m_isRunning;
- }
- private void menuItem3_Click(object sender, EventArgs e)
- {
- }
- private void menuItem4_Click(object sender, EventArgs e)
- {
- if (m_rTh != null)
- {
- m_rTh.stop();
- Thread.Sleep(1000);
- }
- Application.Exit();
- }
- private void trackBar1_ValueChanged(object sender, EventArgs e)
- {
- if (m_mapper != null)
- {
- m_mapper.Scale = (float)trackBar1.Value;
- m_mapper.clearAndDraw();
- }
- }
- private void menuItemDemo_Click(object sender, EventArgs e)
- {
- m_isDemoMode = !m_isDemoMode;
- ((MenuItem)sender).Checked = !((MenuItem)sender).Checked;
- }
- private void menuItemLog_Click(object sender, EventArgs e)
- {
- m_log = !m_log;
- menuItemLog.Checked = !menuItemLog.Checked;
- }
- #region Panning
- private Point touch;
- private void Form1_MouseMove(object sender, MouseEventArgs e)
- {
- if (m_mapper != null)
- {
- m_mapper.moveCenter(touch.X - e.X, touch.Y - e.Y);
- m_mapper.draw();
- }
- touch.X = e.X;
- touch.Y = e.Y;
- }
- private void Form1_MouseDown(object sender, MouseEventArgs e)
- {
- touch.X = e.X;
- touch.Y = e.Y;
- }
- private void Form1_MouseUp(object sender, MouseEventArgs e)
- {
- Form1_MouseMove(sender, e);
- m_mapper.clearAndDraw();
- }
- #endregion
- #region LoadSaveMenu
- private void menuItemLoadPath_Click(object sender, EventArgs e)
- {
- if (m_isRunning)
- {
- menuItemRunStop_Click(sender, e);
- }
- openFileDialog1.ShowDialog();
-
- if (openFileDialog1.FileName.Length > 0)
- {
- m_mapper.loatPath(openFileDialog1.FileName);
- }
- }
- private void menuItemSavePath_Click(object sender, EventArgs e)
- {
- if (m_isRunning)
- {
- menuItemRunStop_Click(sender, e);
- }
- saveFileDialog1.ShowDialog();
- if (saveFileDialog1.FileName.Length > 0)
- {
- m_mapper.savePath(saveFileDialog1.FileName);
- }
- }
- #endregion
- #region ComPortMenu
- private void menuItemCom1_Click(object sender, EventArgs e)
- {
- m_port = "COM1";
- comMenuItemUnchecker();
- ((MenuItem)(sender)).Checked = true;
- }
- private void menuItemCom2_Click(object sender, EventArgs e)
- {
- m_port = "COM2";
- comMenuItemUnchecker();
- ((MenuItem)(sender)).Checked = true;
- }
- private void menuItemCom3_Click(object sender, EventArgs e)
- {
- m_port = "COM3";
- comMenuItemUnchecker();
- ((MenuItem)(sender)).Checked = true;
- }
- private void menuItemCom4_Click(object sender, EventArgs e)
- {
- m_port = "COM4";
- comMenuItemUnchecker();
- ((MenuItem)(sender)).Checked = true;
- }
- private void menuItemCom5_Click(object sender, EventArgs e)
- {
- m_port = "COM5";
- comMenuItemUnchecker();
- ((MenuItem)(sender)).Checked = true;
- }
- private void comMenuItemUnchecker()
- {
- menuItemCom1.Checked = false;
- menuItemCom2.Checked = false;
- menuItemCom3.Checked = false;
- menuItemCom4.Checked = false;
- menuItemCom5.Checked = false;
- }
- #endregion
- private void menuItemCenter_Click(object sender, EventArgs e)
- {
- m_mapper.centerInTheMiddle();
- }
- }
- }