using DevExpress.Utils; using SIASUN.Autopilot.BLL.Controler; using SIASUN.Autopilot.Device.Message; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace SIASUN.Autopilot.View { public partial class FormTest : Form { private Point mousePoint = new Point(); //鼠标位置 private Point[] points = new Point[] { new Point (116,131), new Point(215,131), new Point(291,131), new Point(291,182), new Point(402,182), new Point(517,182), new Point(534,182), new Point(534,232), new Point(647,232), new Point(777,232) }; private Point[] points2 = new Point[] { new Point (116,141), new Point(215,141), new Point(281,141), new Point(281,232), new Point(392,232), new Point(507,232), new Point(524,232), new Point(524,282), new Point(637,282), new Point(777,282) }; private List list = new List(); private int i = 0; public FormTest() { InitializeComponent(); } private void FormTest_Load(object sender, EventArgs e) { this.picExControl1.SetImage(global::SIASUN.Autopilot.View.Properties.Resources.地图1, true); this.picExControl1.MouseMoveTooltipEvent += new SIASUN.Autopilot.View.PicExControl.MouseMoveTooltip(picExControl1_MouseMove); this.picExControl1.DrawOriginalPathEvent += new PicExControl.DrawPath(DrawOriginalPath); this.picExControl1.DrawDrivingPathEvent += new PicExControl.DrawPath(DrawDrivingPath); } private void picExControl1_MouseMove(MouseEventArgs e) { if (mousePoint.X != e.X || mousePoint.Y != e.Y) { ToolTipControllerShowEventArgs args = this.toolTipController1.CreateShowArgs(); //this.toolTip_Message.SetToolTip(this.picExControl1, string.Format("横坐标:{0}\n纵坐标:{1}", e.X.ToString(), e.Y.ToString())); //this.toolTip_Message.SetTitle(this.picExControl1,"提示"); //this.toolTip_Message.SetToolTipIconType(this.picExControl1,ToolTipIconType.Exclamation); args.ToolTip = string.Format("横坐标:{0}\n纵坐标:{1}", e.X.ToString(), e.Y.ToString()); args.SelectedControl = this.picExControl1; //args.Title = "提示"; this.toolTipController1.ShowHint(args, System.Windows.Forms.Control.MousePosition); mousePoint.X = e.X; mousePoint.Y = e.Y; } else { //this.toolTip1.Hide(this.pictureBox1); mousePoint.X = e.X; mousePoint.Y = e.Y; } } /// /// 画原始路径 /// /// private void DrawOriginalPath(Graphics g) { GraphicsPath path = new GraphicsPath(); for (int i = 1; i < points.Length; i++) { path.AddLine(new PointF((points[i - 1].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (points[i - 1].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y), new PointF((points[i].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (points[i].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y)); } g.DrawPath(new Pen(Color.Red), path); } /// /// 画行驶路径 /// /// private void DrawDrivingPath(Graphics g) { if (list.Count < 1) { return; } if (list.Count < 2) { g.TranslateTransform((list[0].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (list[0].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y); g.RotateTransform(90); //e.Graphics.TranslateTransform(-this.pictureBox1.Width / 2, -this.pictureBox1.Height / 2); g.DrawImage(global::SIASUN.Autopilot.View.Properties.Resources.汽车2, -7, -15, 14, 30); } else { Point[] array = list.ToArray(); GraphicsPath path = new GraphicsPath(); for (int i = 1; i < array.Length; i++) { path.AddLine(new PointF((array[i - 1].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (array[i - 1].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y), new PointF((array[i].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (array[i].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y)); } g.DrawPath(new Pen(Color.Blue, 2), path); g.TranslateTransform((array[array.Length - 1].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (array[array.Length - 1].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y); g.RotateTransform(90); g.DrawImage(global::SIASUN.Autopilot.View.Properties.Resources.汽车2, -7, -15, 14, 30); } } /// /// 测试行驶路线 /// /// /// private void button5_Click(object sender, EventArgs e) { if (list.Count == 10) { return; } list.Add(points2[i]); i++; this.picExControl1.Invalidate(); BlControler bl = new BlControler(); //bl.RCUEnableRequest("1"); 控制器上电命令 aa = new 控制器上电命令(); int a = -1; byte[] b = System.Text.Encoding.Default.GetBytes(a.ToString()); } private void btn_Add_Click(object sender, EventArgs e) { float acc = Convert.ToSingle(txt_Add.Text); //BeckhoffDrive.Accelerator(acc); } private void btn_Angle_Click(object sender, EventArgs e) { float ang = Convert.ToSingle(txt_Stree.Text); //BeckhoffDrive.Accelerator(ang); } } }