FormRoutePlan.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using DevExpress.XtraEditors;
  7. using System.Drawing.Drawing2D;
  8. using SIASUN.Autopilot.View.Helper;
  9. using SIASUN.Autopilot.BLL;
  10. using ProjectBase.Data.BaseDAL;
  11. using SIASUN.Autopilot.Model;
  12. using ProjectBase.Data.Logs;
  13. using DevExpress.Utils;
  14. using System.Data.Common;
  15. using SIASUN.Autopilot.GNSS;
  16. using ProjectBase.Util;
  17. namespace SIASUN.Autopilot.View
  18. {
  19. public partial class FormRoutePlan : DevExpress.XtraEditors.XtraForm
  20. {
  21. #region 私有变量
  22. /// <summary>
  23. /// 画线类型
  24. /// </summary>
  25. private DrawType type = DrawType.None; //画线类型
  26. /// <summary>
  27. /// ///操作模式
  28. /// </summary>
  29. private Mode mode = Mode.None; //操作模式
  30. /// <summary>
  31. /// /在界面上画图的图元
  32. /// </summary>
  33. private DShapeList drawingList = new DShapeList(); //在界面上画图的图元
  34. /// <summary>
  35. /// /保存标准坐标的图元
  36. /// </summary>
  37. private DShapeList standardList = new DShapeList(); //保存标准坐标的图元
  38. /// <summary>
  39. /// Undo保存
  40. /// </summary>
  41. private DShapeList drawingListUndo = new DShapeList(); //Undo保存
  42. /// <summary>
  43. /// Undo保存
  44. /// </summary>
  45. private DShapeList standardListUndo = new DShapeList(); //Undo保存
  46. /// <summary>
  47. /// 下拉框选择路径的所有点
  48. /// </summary>
  49. private List<MoLocationRuleInfo> locationList = new List<MoLocationRuleInfo>(); //下拉框选择路径
  50. /// <summary>
  51. /// 自定义路径的所有点
  52. /// </summary>
  53. private BindingList<MoLocationRuleInfo> drawLocationList = new BindingList<MoLocationRuleInfo>(); //自定义路径的所有点
  54. /// <summary>
  55. /// 屏幕点
  56. /// </summary>
  57. private List<PointF> pointScreen = new List<PointF>(); //屏幕点
  58. /// <summary>
  59. /// 标准坐标
  60. /// </summary>
  61. private List<PointF> pointStandard = new List<PointF>(); //标准坐标
  62. /// <summary>
  63. /// 线的宽度
  64. /// </summary>
  65. private const int lineWidth = 3; //线的宽度
  66. /// <summary>
  67. /// 鼠标位置
  68. /// </summary>
  69. private Point mousePoint = new Point(); //鼠标位置
  70. ///// <summary>
  71. ///// 图片宽度
  72. ///// </summary>
  73. //private int ImageWidth;
  74. ///// <summary>
  75. ///// 图片高度
  76. ///// </summary>
  77. //private int ImageHeight;
  78. /// <summary>
  79. /// 坐标与经纬度转换对象
  80. /// </summary>
  81. private CoordinateConversion conversion;
  82. /// <summary>
  83. /// 行驶过程中的经纬度
  84. /// </summary>
  85. private List<PointF> pointDriving = new List<PointF>();
  86. /// <summary>
  87. /// 行驶过程中航向角度
  88. /// </summary>
  89. private List<float> angleDriving = new List<float>();
  90. /// <summary>
  91. /// 行驶过程中速度
  92. /// </summary>
  93. private List<float> speedDriving = new List<float>();
  94. ///// <summary>
  95. ///// 画线类型
  96. ///// </summary>
  97. private enum DrawType
  98. {
  99. Bezier,
  100. None
  101. }
  102. /// <summary>
  103. /// 操作模式
  104. /// </summary>
  105. private enum Mode
  106. {
  107. Drive,
  108. Draw,
  109. None
  110. }
  111. #endregion
  112. public FormRoutePlan()
  113. {
  114. InitializeComponent();
  115. }
  116. private void FormRouteManagement_Load(object sender, EventArgs e)
  117. {
  118. InitControls();
  119. //ImageWidth = global::SIASUN.Autopilot.View.Properties.Resources.地图1.Width;
  120. //ImageHeight = global::SIASUN.Autopilot.View.Properties.Resources.地图1.Height;
  121. MoLocationMap map = BLLFactory<BlLocationMap>.Instance.FindSingle(string.Format("map_id = '{0}'", System.Configuration.ConfigurationManager.AppSettings["MapId"]));
  122. WGS84Points point0 = new WGS84Points { x = map.LocationLon1, y = map.LocationLat1, z = 0 };
  123. WGS84Points point1 = new WGS84Points { x = map.LocationLon2, y = map.LocationLat2, z = 0 };
  124. PointF imagePoint0 = new PointF { X = map.LocationX1, Y = map.LocationY1 };
  125. PointF imagePoint1 = new PointF { X = map.LocationX2, Y = map.LocationY2 };
  126. conversion = new CoordinateConversion(imagePoint0, imagePoint1, point0, point1);
  127. //BlGNSSPerception.Instance.Init();
  128. BlGNSSPerception.Instance.GNSSHandler += GetDrivingInfo;
  129. }
  130. /// <summary>
  131. /// 初始化控件
  132. /// </summary>
  133. private void InitControls()
  134. {
  135. //地图控件
  136. this.picExControl1.SetImage(global::SIASUN.Autopilot.View.Properties.Resources.地图1, true);
  137. this.picExControl1.DrawOriginalPathEvent += new PicExControl.DrawPath(DrawOriginalPath);
  138. this.picExControl1.DrawDrivingPathEvent += new PicExControl.DrawPath(DrawDrivingPath);
  139. this.picExControl1.MouseMoveTooltipEvent += new SIASUN.Autopilot.View.PicExControl.MouseMoveTooltip(picExControl1_MouseMove);
  140. this.btn_SavePath.Enabled = false;
  141. //this.layoutControl_DrawLine.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  142. this.layoutControl_DrawBezier.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  143. this.layoutControl_Udo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  144. this.layoutControl_Rdo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  145. this.layoutControl_Cancel.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  146. this.layoutControl_Ok.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  147. this.layoutControl_Name.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  148. this.layoutControl_Stop.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  149. this.label_PathName.Text = null;
  150. //下拉框
  151. this.lookUp_Path.Properties.DataSource = BLLFactory<BlLocationRuleInfo>.Instance.SqlTable("SELECT rule_name FROM location_rule_info GROUP BY rule_name");
  152. this.lookUp_Path.Properties.ValueMember = "RULE_NAME";
  153. this.lookUp_Path.Properties.DisplayMember = "RULE_NAME";
  154. this.lookUp_Path.Properties.NullText = null;
  155. }
  156. /// <summary>
  157. /// 自定义路径按钮事件
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void btn_DrawPath_Click(object sender, EventArgs e)
  162. {
  163. this.btn_DrivePath.Enabled = false;
  164. this.btn_SavePath.Enabled = true;
  165. //this.layoutControl_DrawLine.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  166. this.layoutControl_DrawBezier.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  167. this.layoutControl_Udo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  168. this.layoutControl_Rdo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  169. this.layoutControl_Cancel.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  170. this.layoutControl_Ok.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  171. this.layoutControl_Name.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  172. this.lookUp_Path.Enabled = false;
  173. this.lookUp_Path.EditValue = null;
  174. this.label_PathName.Text = null;
  175. mode = Mode.Draw;
  176. }
  177. /// <summary>
  178. /// 保存路径按钮事件
  179. /// </summary>
  180. /// <param name="sender"></param>
  181. /// <param name="e"></param>
  182. private void btn_SavePath_Click(object sender, EventArgs e)
  183. {
  184. if (string.IsNullOrEmpty(this.txt_PathName.Text))
  185. {
  186. DevExpress.XtraEditors.XtraMessageBox.Show("请输入路径名称。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  187. return;
  188. }
  189. if (drawLocationList.Count == 0)
  190. {
  191. DevExpress.XtraEditors.XtraMessageBox.Show("请至少绘制一条路径。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  192. return;
  193. }
  194. bool bOK = true;
  195. DbTransaction trans = null;
  196. try
  197. {
  198. trans = BLLFactory<BlLocationRuleInfo>.Instance.CreateTransaction();
  199. foreach (MoLocationRuleInfo item in drawLocationList)
  200. {
  201. if (bOK)
  202. {
  203. item.RuleName = this.txt_PathName.Text.Trim();
  204. bOK = BLLFactory<BlLocationRuleInfo>.Instance.Insert(item,trans);
  205. }
  206. }
  207. bOK = SaveDirective(bOK,drawLocationList,trans);
  208. if (!bOK)
  209. {
  210. trans.Rollback();
  211. DevExpress.XtraEditors.XtraMessageBox.Show("保存路径失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  212. }
  213. else
  214. {
  215. trans.Commit();
  216. DevExpress.XtraEditors.XtraMessageBox.Show("保存路径成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  217. //this.btn_DrawPath.Enabled = true;
  218. //this.btn_SavePath.Enabled = false;
  219. //this.btn_DrivePath.Enabled = true;
  220. ////this.layoutControl_DrawLine.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  221. //this.layoutControl_DrawBezier.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  222. //this.layoutControl_Udo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  223. //this.layoutControl_Rdo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  224. //this.layoutControl_Cancel.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  225. //this.layoutControl_Ok.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  226. //this.layoutControl_Name.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  227. this.lookUp_Path.Properties.DataSource = BLLFactory<BlLocationRuleInfo>.Instance.SqlTable("SELECT rule_name FROM location_rule_info GROUP BY rule_name");
  228. //this.txt_PathName.Text = null;
  229. //this.lookUp_Path.Enabled = true;
  230. btn_Cancel_Click_1( sender, e);
  231. //mode = Mode.None;
  232. //type = DrawType.None;
  233. //drawingList.Clear();
  234. //standardList.Clear();
  235. //drawingListUndo.Clear();
  236. //standardListUndo.Clear();
  237. //drawLocationList.Clear();
  238. this.picExControl1.Invalidate();
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. trans.Rollback();
  244. DevExpress.XtraEditors.XtraMessageBox.Show("保存路径失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  245. LogHelper.log.Error(string.Format("插入数据库location_rule_info出现错误:{0}", ex));
  246. }
  247. finally
  248. {
  249. trans.Dispose();
  250. }
  251. }
  252. /// <summary>
  253. /// 保存动作指令集
  254. /// </summary>
  255. /// <param name="bOk"></param>
  256. /// <param name="trans"></param>
  257. /// <returns></returns>
  258. private bool SaveDirective(bool bOk , BindingList<MoLocationRuleInfo> list, DbTransaction trans)
  259. {
  260. if (!bOk)
  261. {
  262. return false;
  263. }
  264. MoActionDirective mo = new MoActionDirective();
  265. mo.RuleName = list[0].RuleName;
  266. for (int i = 1; i < list.Count; i++)
  267. {
  268. if (bOk)
  269. {
  270. mo.DirectiveId = i;
  271. if (i == 1)
  272. {
  273. mo.DirectiveInfo = string.Format("动作{0}:起步请加速到{1}KPH", i, list[i].LocationSpeed);
  274. }
  275. else
  276. {
  277. if (list[i].LocationSpeed > list[i-1].LocationSpeed)
  278. {
  279. mo.DirectiveInfo = string.Format("动作{0}:点{1}加速到{2}KPH", i,i, list[i].LocationSpeed);
  280. }
  281. else if (list[i].LocationSpeed < list[i - 1].LocationSpeed)
  282. {
  283. mo.DirectiveInfo = string.Format("动作{0}:点{1}制动至{2}KPH", i, i, list[i].LocationSpeed);
  284. }
  285. else if (list[i].LocationSpeed == list[i - 1].LocationSpeed)
  286. {
  287. mo.DirectiveInfo = string.Format("动作{0}:点{1}保持{2}KPH", i, i, list[i].LocationSpeed);
  288. }
  289. }
  290. mo.DirectiveResult = 2;
  291. bOk = BLLFactory<BlActionDirective>.Instance.Insert(mo, trans);
  292. }
  293. }
  294. return bOk;
  295. }
  296. /// <summary>
  297. /// 画直线按钮事件
  298. /// </summary>
  299. /// <param name="sender"></param>
  300. /// <param name="e"></param>
  301. //private void btn_DrawLine_Click(object sender, EventArgs e)
  302. //{
  303. // this.btn_DrawBezier.Enabled = false;
  304. // this.btn_Udo.Enabled = false;
  305. // this.btn_Rdo.Enabled = false;
  306. // this.layoutControl_Draw.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  307. // this.picExControl1.AllawDraw = true;
  308. // this.label_Message.Text = "请在地图上单击鼠标左键选择两个点";
  309. //}
  310. /// <summary>
  311. /// 画曲线按钮事件
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void btn_DrawBezier_Click(object sender, EventArgs e)
  316. {
  317. //this.btn_DrawLine.Enabled = false;
  318. if (type == DrawType.Bezier)
  319. {
  320. return;
  321. }
  322. this.btn_Udo.Enabled = false;
  323. this.btn_Rdo.Enabled = false;
  324. this.layoutControl_Draw.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  325. this.picExControl1.AllawDraw = true;
  326. this.label_Message.Text = "请在地图上单击鼠标左键选择点";
  327. type = DrawType.Bezier;
  328. }
  329. /// <summary>
  330. /// 第二行取消按钮事件
  331. /// </summary>
  332. /// <param name="sender"></param>
  333. /// <param name="e"></param>
  334. private void btn_Cancel_Click(object sender, EventArgs e)
  335. {
  336. //this.btn_DrawLine.Enabled = true;
  337. this.btn_Udo.Enabled = true;
  338. this.btn_Rdo.Enabled = true;
  339. this.btn_DrawBezier.Enabled = true;
  340. this.layoutControl_Draw.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  341. this.label_Message.Text = null;
  342. type = DrawType.None;
  343. this.picExControl1.AllawDraw = false;
  344. pointScreen.Clear();
  345. pointStandard.Clear();
  346. this.picExControl1.Invalidate();
  347. }
  348. /// <summary>
  349. /// 驾驶车画路径按钮事件
  350. /// </summary>
  351. /// <param name="sender"></param>
  352. /// <param name="e"></param>
  353. private void btn_DrivePath_Click(object sender, EventArgs e)
  354. {
  355. this.btn_DrawPath.Enabled = false;
  356. this.btn_SavePath.Enabled = false;
  357. this.lookUp_Path.Enabled = false;
  358. this.lookUp_Path.EditValue = null;
  359. this.label_PathName.Text = null;
  360. this.btn_SavePath.Enabled = true;
  361. this.layoutControl_Name.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  362. this.layoutControl_Stop.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  363. mode = Mode.Drive;
  364. BlGNSSPerception.Instance.Init();
  365. }
  366. /// <summary>
  367. /// 第一行取消按钮事件
  368. /// </summary>
  369. /// <param name="sender"></param>
  370. /// <param name="e"></param>
  371. private void btn_Cancel_Click_1(object sender, EventArgs e)
  372. {
  373. if (mode == Mode.Draw) //自定义路径模式
  374. {
  375. this.btn_DrivePath.Enabled = true;
  376. //this.btn_SavePath.Enabled = false;
  377. //this.layoutControl_DrawLine.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  378. this.layoutControl_DrawBezier.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  379. this.layoutControl_Udo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  380. this.layoutControl_Rdo.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  381. this.layoutControl_Cancel.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  382. this.layoutControl_Ok.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  383. this.layoutControl_Draw.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  384. //this.layoutControl_Name.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  385. btn_Cancel_Click(sender, e);
  386. }
  387. else if (mode == Mode.Drive) //驾驶车户路径模式
  388. {
  389. //DevExpress.XtraEditors.XtraMessageBox.Show("正在进行自定义路径操作,请取消后再操作!。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  390. this.btn_DrawPath.Enabled = true;
  391. this.layoutControl_Stop.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  392. pointDriving.Clear();
  393. angleDriving.Clear();
  394. BlGNSSPerception.Instance.Close();
  395. }
  396. this.btn_SavePath.Enabled = false;
  397. this.layoutControl_Name.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  398. this.txt_PathName.Text = null;
  399. drawingList.Clear();
  400. standardList.Clear();
  401. drawingListUndo.Clear();
  402. standardListUndo.Clear();
  403. drawLocationList.Clear();
  404. this.lookUp_Path.Enabled = true;
  405. mode = Mode.None;
  406. }
  407. /// <summary>
  408. /// 确定按钮事件
  409. /// </summary>
  410. /// <param name="sender"></param>
  411. /// <param name="e"></param>
  412. private void btn_Ok_Click(object sender, EventArgs e)
  413. {
  414. //保存画的线
  415. if (pointStandard.Count < 2)
  416. {
  417. DevExpress.XtraEditors.XtraMessageBox.Show("请最少选择两个点。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  418. return;
  419. }
  420. drawingList.Add(new DCurve(pointStandard.ToArray(), Color.Red, lineWidth));
  421. standardList.Add(new DCurve(pointStandard.ToArray(), Color.Red, lineWidth));
  422. //刷新控件状态
  423. //this.btn_DrawLine.Enabled = true;
  424. this.btn_Udo.Enabled = true;
  425. this.btn_Rdo.Enabled = true;
  426. this.btn_DrawBezier.Enabled = true;
  427. this.layoutControl_Draw.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  428. this.label_Message.Text = null;
  429. type = DrawType.None;
  430. pointScreen.Clear();
  431. pointStandard.Clear();
  432. this.picExControl1.AllawDraw = false;
  433. this.picExControl1.Invalidate();
  434. }
  435. /// <summary>
  436. /// 画原始路径
  437. /// </summary>
  438. /// <param name="g"></param>
  439. private void DrawOriginalPath(Graphics g)
  440. {
  441. try
  442. {
  443. if (mode == Mode.None) //下拉框选择路径时
  444. {
  445. if (locationList.Count <= 0)
  446. {
  447. return;
  448. }
  449. List<PointF> list = new List<PointF>();
  450. double x;
  451. double y;
  452. foreach (MoLocationRuleInfo item in locationList)
  453. {
  454. conversion.GetWGS84ToGauss(item.LocationLon, item.LocationLat,out x, out y);
  455. list.Add(new PointF((float)(x * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (float)(y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y));
  456. }
  457. g.DrawCurve(new Pen(Color.Red, lineWidth), list.ToArray());
  458. }
  459. else if (mode == Mode.Draw) //自定义路径时
  460. {
  461. if (type == DrawType.Bezier)
  462. {
  463. //在地图上选点时,显示点
  464. foreach (PointF p in pointScreen)
  465. {
  466. Region newRegion = new Region(new RectangleF(p, new Size(2 * 2, 2 * 2)));
  467. g.FillRegion(new SolidBrush(Color.Red), newRegion);
  468. }
  469. }
  470. //绘制自定义路径
  471. for (int i = 0; i < drawingList.Count; i++)
  472. {
  473. for (int j = 0; j < drawingList[i].pointlist.Length; j++)
  474. {
  475. drawingList[i].pointlist[j].X = (standardList[i].pointlist[j].X * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X;
  476. drawingList[i].pointlist[j].Y = (standardList[i].pointlist[j].Y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y;
  477. }
  478. drawingList[i].pointchange(drawingList[i].pointlist);
  479. }
  480. drawingList.DrawList(g);
  481. RefreshGrid();
  482. }
  483. }
  484. catch (Exception ex)
  485. {
  486. DevExpress.XtraEditors.XtraMessageBox.Show("绘制路径失败。" + ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  487. LogHelper.log.Error(string.Format("绘制路径失败:{0}", ex.ToString()));
  488. }
  489. }
  490. /// <summary>
  491. /// 绘制线后将点显示在表格中
  492. /// </summary>
  493. private void RefreshGrid()
  494. {
  495. drawLocationList.Clear();
  496. if (mode == Mode.Draw)
  497. {
  498. double lon;
  499. double lat;
  500. for (int i = 0; i < standardList.Count; i++)
  501. {
  502. for (int j = 0; j < standardList[i].pointlist.Length; j++)
  503. {
  504. conversion.GetGaussToWGS84(standardList[i].pointlist[j].X, standardList[i].pointlist[j].Y, out lon, out lat);
  505. MoLocationRuleInfo mo = new MoLocationRuleInfo
  506. {
  507. RuleName = this.txt_PathName.Text,
  508. LocatonId = drawLocationList.Count + 1,
  509. LocationLon = lon,
  510. LocationLat = lat
  511. //LocationHeight = 11,
  512. //LocationSpeed =11
  513. };
  514. drawLocationList.Add(mo);
  515. }
  516. }
  517. }
  518. else if (mode == Mode.Drive)
  519. {
  520. for (int i = 0; i < pointDriving.Count; i++)
  521. {
  522. MoLocationRuleInfo mo = new MoLocationRuleInfo
  523. {
  524. RuleName = this.txt_PathName.Text,
  525. LocatonId = drawLocationList.Count + 1,
  526. LocationLon = pointDriving[i].X,
  527. LocationLat = pointDriving[i].Y,
  528. //LocationHeight = 11,
  529. LocationSpeed = speedDriving[i]
  530. };
  531. drawLocationList.Add(mo);
  532. }
  533. }
  534. this.gridControl_Path.DataSource = drawLocationList;
  535. this.gridControl_Path.RefreshDataSource();
  536. }
  537. /// <summary>
  538. /// 画行驶路径
  539. /// </summary>
  540. /// <param name="g"></param>
  541. private void DrawDrivingPath(Graphics g)
  542. {
  543. if (mode == Mode.Drive)
  544. {
  545. if (pointDriving.Count < 1 || angleDriving.Count < 1)
  546. {
  547. return;
  548. }
  549. double x;
  550. double y;
  551. if (pointDriving.Count < 2)
  552. {
  553. conversion.GetWGS84ToGauss(pointDriving[0].X, pointDriving[0].Y, out x, out y);
  554. g.TranslateTransform((float)x, (float)y);
  555. g.RotateTransform(angleDriving[0]);
  556. g.DrawImage(global::SIASUN.Autopilot.View.Properties.Resources.汽车2, -7, -15, 14, 30);
  557. }
  558. else
  559. {
  560. List<PointF> list = new List<PointF>();
  561. for (int i = 0; i < pointDriving.Count; i++)
  562. {
  563. conversion.GetWGS84ToGauss(pointDriving[i].X, pointDriving[i].Y, out x, out y);
  564. list.Add(new PointF((float)(x * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (float)(y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y));
  565. }
  566. //foreach (PointF item in pointDriving)
  567. //{
  568. // conversion.GetWGS84ToGauss(item.X, item.Y, out x, out y);
  569. // list.Add(new PointF((float)(x * this.picExControl1.Wrate) + this.picExControl1.StartPoint.X, (float)(y * this.picExControl1.Hrate) + this.picExControl1.StartPoint.Y));
  570. //}
  571. g.DrawCurve(new Pen(Color.Red, lineWidth), list.ToArray());
  572. g.TranslateTransform(list[list.Count-1].X, list[list.Count-1].Y);
  573. g.RotateTransform(angleDriving[angleDriving.Count-1]);
  574. g.DrawImage(global::SIASUN.Autopilot.View.Properties.Resources.汽车2, -7, -15, 14, 30);
  575. }
  576. RefreshGrid();
  577. }
  578. }
  579. /// <summary>
  580. /// 获取行驶中经纬度和角度值
  581. /// </summary>
  582. private void GetDrivingInfo(object sender, GNSSInfoEventArgs gnss)
  583. {
  584. pointDriving.Add(new PointF { X= (float)gnss.Nmea.gprmc.Longitude,Y = (float)gnss.Nmea.gprmc.Latitude});
  585. angleDriving.Add((float)gnss.Nmea.gprmc.Deviated);
  586. speedDriving.Add((float)gnss.Nmea.gprmc.Speed);
  587. this.picExControl1.Invalidate();
  588. }
  589. /// <summary>
  590. /// 下拉框按钮点击事件
  591. /// </summary>
  592. /// <param name="sender"></param>
  593. /// <param name="e"></param>
  594. private void lookUp_Path_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  595. {
  596. if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Delete)
  597. {
  598. LookUpEdit lookUp = sender as LookUpEdit;
  599. lookUp.EditValue = null;
  600. }
  601. }
  602. /// <summary>
  603. /// 下拉框选中项改变事件
  604. /// </summary>
  605. /// <param name="sender"></param>
  606. /// <param name="e"></param>
  607. private void lookUp_Path_EditValueChanged(object sender, EventArgs e)
  608. {
  609. try
  610. {
  611. if (this.lookUp_Path.EditValue == null)
  612. {
  613. this.label_PathName.Text = null;
  614. locationList = new List<MoLocationRuleInfo>();
  615. }
  616. else
  617. {
  618. this.label_PathName.Text = this.lookUp_Path.EditValue.ToString();
  619. SysEnvironment.CurrentRuleName = this.label_PathName.Text.Trim();
  620. string condition = string.Format("rule_name = '{0}'", this.lookUp_Path.EditValue.ToString());
  621. locationList = BLLFactory<BlLocationRuleInfo>.Instance.Find(condition);
  622. }
  623. this.gridControl_Path.DataSource = locationList;
  624. this.gridControl_Path.RefreshDataSource();
  625. this.picExControl1.Invalidate();
  626. }
  627. catch (Exception ex)
  628. {
  629. DevExpress.XtraEditors.XtraMessageBox.Show("获取路径失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  630. LogHelper.log.Error(string.Format("获取路径失败:{0}", ex.ToString()));
  631. }
  632. }
  633. /// <summary>
  634. /// 地图控件鼠标点击事件
  635. /// </summary>
  636. /// <param name="sender"></param>
  637. /// <param name="e"></param>
  638. private void picExControl1_MouseClick(object sender, MouseEventArgs e)
  639. {
  640. try
  641. {
  642. if (e.Button == MouseButtons.Left)
  643. {
  644. if (type == DrawType.Bezier)
  645. {
  646. pointScreen.Add(new PointF(e.X, e.Y));
  647. pointStandard.Add(new PointF((e.X - this.picExControl1.StartPoint.X) / this.picExControl1.Wrate,
  648. (e.Y - this.picExControl1.StartPoint.Y) / this.picExControl1.Hrate));
  649. this.label_Message.Text = string.Format("已选择{0}个点", pointScreen.Count);
  650. }
  651. this.picExControl1.Invalidate();
  652. }
  653. }
  654. catch (Exception ex)
  655. {
  656. DevExpress.XtraEditors.XtraMessageBox.Show("在地图上选点失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  657. LogHelper.log.Error(string.Format("在地图上选点失败:{0}", ex.ToString()));
  658. }
  659. }
  660. /// <summary>
  661. /// 描点结束按钮事件
  662. /// </summary>
  663. /// <param name="sender"></param>
  664. /// <param name="e"></param>
  665. private void btn_Draw_Click(object sender, EventArgs e)
  666. {
  667. try
  668. {
  669. using (Graphics g = this.picExControl1.CreateGraphics())
  670. {
  671. g.SmoothingMode = SmoothingMode.HighQuality;
  672. g.CompositingQuality = CompositingQuality.HighQuality;
  673. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  674. if (pointScreen.Count < 2)
  675. {
  676. DevExpress.XtraEditors.XtraMessageBox.Show("请最少选择两个点。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  677. return;
  678. }
  679. g.DrawCurve(new Pen(Color.Red, lineWidth), pointScreen.ToArray());
  680. }
  681. }
  682. catch (Exception ex)
  683. {
  684. DevExpress.XtraEditors.XtraMessageBox.Show("绘制路线失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  685. LogHelper.log.Error(string.Format("绘制路线失败:{0}", ex.ToString()));
  686. }
  687. }
  688. /// <summary>
  689. /// 撤销按钮事件
  690. /// </summary>
  691. /// <param name="sender"></param>
  692. /// <param name="e"></param>
  693. private void btn_Udo_Click(object sender, EventArgs e)
  694. {
  695. if (standardList.Count == 0)
  696. {
  697. return;
  698. }
  699. drawingListUndo.Add(drawingList[drawingList.Count - 1]);
  700. standardListUndo.Add(standardList[standardList.Count - 1]);
  701. drawingList.RemoveAt(drawingList.Count - 1);
  702. standardList.RemoveAt(standardList.Count - 1);
  703. this.picExControl1.Invalidate();
  704. }
  705. /// <summary>
  706. /// 重做按钮事件
  707. /// </summary>
  708. /// <param name="sender"></param>
  709. /// <param name="e"></param>
  710. private void btn_Rdo_Click(object sender, EventArgs e)
  711. {
  712. if (drawingListUndo.Count == 0)
  713. return;
  714. drawingList.Add(drawingListUndo[drawingListUndo.Count - 1]);
  715. standardList.Add(standardListUndo[standardListUndo.Count - 1]);
  716. drawingListUndo.RemoveAt(drawingListUndo.Count - 1);
  717. standardListUndo.RemoveAt(standardListUndo.Count - 1);
  718. this.picExControl1.Invalidate();
  719. }
  720. /// <summary>
  721. /// /输入自定义名称后触发的事件
  722. /// </summary>
  723. /// <param name="sender"></param>
  724. /// <param name="e"></param>
  725. private void txt_PathName_TextChanged(object sender, EventArgs e)
  726. {
  727. this.label_PathName.Text = this.txt_PathName.Text;
  728. }
  729. /// <summary>
  730. /// 鼠标移动显示经纬度
  731. /// </summary>
  732. /// <param name="e"></param>
  733. private void picExControl1_MouseMove(MouseEventArgs e)
  734. {
  735. if (mousePoint.X != e.X || mousePoint.Y != e.Y)
  736. {
  737. ToolTipControllerShowEventArgs args = this.toolTip_Message.CreateShowArgs();
  738. //this.toolTip_Message.SetToolTip(this.picExControl1, string.Format("横坐标:{0}\n纵坐标:{1}", e.X.ToString(), e.Y.ToString()));
  739. //this.toolTip_Message.SetTitle(this.picExControl1,"提示");
  740. //this.toolTip_Message.SetToolTipIconType(this.picExControl1,ToolTipIconType.Exclamation);
  741. double lon;
  742. double lat;
  743. conversion.GetGaussToWGS84((e.X - this.picExControl1.StartPoint.X) / this.picExControl1.Wrate, (e.Y - this.picExControl1.StartPoint.Y) / this.picExControl1.Hrate, out lon, out lat);
  744. args.ToolTip = string.Format("经度:{0}\n纬度:{1}", lon.ToString(), lat.ToString());
  745. args.SelectedControl = this.picExControl1;
  746. //args.Title = "提示";
  747. this.toolTip_Message.ShowHint(args, System.Windows.Forms.Control.MousePosition);
  748. mousePoint.X = e.X;
  749. mousePoint.Y = e.Y;
  750. }
  751. else
  752. {
  753. mousePoint.X = e.X;
  754. mousePoint.Y = e.Y;
  755. }
  756. }
  757. private void picExControl1_MouseLeave(object sender, EventArgs e)
  758. {
  759. this.toolTip_Message.HideHint();
  760. }
  761. /// <summary>
  762. /// 窗口关闭事件
  763. /// </summary>
  764. /// <param name="sender"></param>
  765. /// <param name="e"></param>
  766. private void FormRouteManagement_FormClosing(object sender, FormClosingEventArgs e)
  767. {
  768. //BlGNSSPerception.Instance.Close();
  769. }
  770. /// <summary>
  771. /// 停止按钮事件
  772. /// </summary>
  773. /// <param name="sender"></param>
  774. /// <param name="e"></param>
  775. private void btn_Stop_Click(object sender, EventArgs e)
  776. {
  777. BlGNSSPerception.Instance.Close();
  778. }
  779. /// <summary>
  780. /// 放大按钮
  781. /// </summary>
  782. /// <param name="sender"></param>
  783. /// <param name="e"></param>
  784. private void btn_Big_Click(object sender, EventArgs e)
  785. {
  786. float rate = 1;
  787. if (Math.Max(this.picExControl1.Wrate, this.picExControl1.Hrate) <= 10)
  788. {
  789. rate = 1.15F;
  790. }
  791. Zoom(rate);
  792. }
  793. /// <summary>
  794. /// 缩小按钮
  795. /// </summary>
  796. /// <param name="sender"></param>
  797. /// <param name="e"></param>
  798. private void btn_Small_Click(object sender, EventArgs e)
  799. {
  800. float rate = 1;
  801. if (Math.Min(this.picExControl1.Wrate, this.picExControl1.Hrate) > Math.Max(0.75687, 0.75687))
  802. {
  803. rate = 0.85F;
  804. }
  805. Zoom(rate);
  806. }
  807. /// <summary>
  808. /// 地图缩放
  809. /// </summary>
  810. /// <param name="rate"></param>
  811. private void Zoom(float rate)
  812. {
  813. if (rate == 1) return;
  814. float imageX = (356F - this.picExControl1.StartPoint.X) / this.picExControl1.Wrate;
  815. float imageY = (279F - this.picExControl1.StartPoint.Y) / this.picExControl1.Hrate;
  816. this.picExControl1.Hrate *= rate;
  817. this.picExControl1.Wrate *= rate;
  818. this.picExControl1.StartPoint = new PointF(356F - imageX * this.picExControl1.Wrate, 279F - imageY * this.picExControl1.Hrate);
  819. this.picExControl1.Invalidate();
  820. }
  821. }
  822. }