CtrlPosSingle.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using DevExpress.Internal;
  2. using DevExpress.Utils.Drawing.Helpers;
  3. using DevExpress.Utils.Extensions;
  4. using DevExpress.XtraEditors;
  5. using DevExpress.XtraExport.Helpers;
  6. using DevExpress.XtraGrid.Views.Grid;
  7. using DevExpress.XtraMap;
  8. using DevExpress.XtraTreeList.Data;
  9. using DxHelper;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Drawing;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. using System.Windows.Controls;
  22. using System.Windows.Documents;
  23. using System.Windows.Forms;
  24. using XdCxRhDW.App.Api.时差粗值预测;
  25. using XdCxRhDW.App.Api.时差线;
  26. using XdCxRhDW.App.DTO;
  27. using XdCxRhDW.App.UserControl;
  28. using XzXdDw.App.Api;
  29. using XzXdDw.App.Api.星地GDOP误差椭圆;
  30. using XzXdDw.App.EditForms;
  31. using XzXdDw.App.EFContext;
  32. using XzXdDw.App.Model;
  33. namespace XzXdDw.App.UserControl
  34. {
  35. /// <summary>
  36. /// 星地定位
  37. /// </summary>
  38. public partial class CtrlPosSingle : DevExpress.XtraEditors.XtraUserControl
  39. {
  40. DtXDParam dtxdctrl = null;
  41. public CtrlPosSingle()
  42. {
  43. InitializeComponent();
  44. }
  45. private async void CtrlXdPos_Load(object sender, EventArgs e)
  46. {
  47. try
  48. {
  49. gridPos.Init().UseMultiSelect().UseFilter().UseRowNumber().UseExportXlsx()
  50. .AddMenu("删除", SvgHelper.CreateClose(), async () =>
  51. {
  52. try
  53. {
  54. if (XtraMessageBox.Show("确认删除?(Ctrl+A可全选删除)", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  55. {
  56. return;
  57. }
  58. var ids = gridView1.GetSelectedRows();
  59. List<PosRes> deletePos = new List<PosRes>();
  60. using (RHDWContext db = new RHDWContext())
  61. {
  62. foreach (var id in ids)
  63. {
  64. var item = gridView1.GetRow(id) as PosRes;
  65. var delItem = await db.PosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  66. if (delItem != null)
  67. {
  68. db.PosRes.Remove(delItem);
  69. }
  70. deletePos.Add(item);
  71. }
  72. await db.SaveChangesAsync();
  73. }
  74. gridView1.DeleteSelectedRows();
  75. mapControl1.DelPosItem(deletePos);
  76. }
  77. catch (Exception ex)
  78. {
  79. Serilog.Log.Error("删除结果失败", ex);
  80. XtraMessageBox.Show("删除结果失败");
  81. }
  82. })
  83. .AddMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), LoadTestData)
  84. .AddMenu("绘制误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), DrawErrorEllipse1X)
  85. .AddMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), () => stoped = true);
  86. mapControl1.UseDefalutOptions()
  87. //.UseCluster()//定位点使用内置聚合
  88. .UseClearAll()
  89. .UseDistanceLine()
  90. .UseMarkDot()
  91. //.UseExportImg()
  92. //.UseExportXlsx()
  93. //.UseExportCsv()
  94. .UseDrawRect(rect =>
  95. {
  96. if (dtxdctrl != null)
  97. {
  98. dtxdctrl.rect = rect;
  99. }
  100. });
  101. //MapMenu为地图瓦片上右键菜单
  102. //AddPosMenu为定位点上右键菜单
  103. //RectMenu为框选的区域上右键菜单
  104. mapControl1.AddMapMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), (lon, lat) => LoadTestData())
  105. .AddMapMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), (lon, lat) => stoped = true)
  106. .AddMapMenu("GDOP分析", SvgHelper.LoadFromFile("Image\\GDOP.svg"), (lon, lat) =>
  107. {
  108. })
  109. .AddPosMenu<PosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
  110. {
  111. });
  112. //查询已有的定位记录
  113. using (RHDWContext db = new RHDWContext())
  114. {
  115. List<PosRes> list = await db.PosRes.ToListAsync();
  116. this.gridPos.DataSource = list;
  117. mapControl1.SetPosDataSource(list);
  118. }
  119. }
  120. catch (Exception ex)
  121. {
  122. Serilog.Log.Error("查询定位结果失败", ex);
  123. XtraMessageBox.Show("查询定位结果失败");
  124. }
  125. }
  126. bool stoped = false;
  127. private async void LoadTestData()
  128. {
  129. stoped = false;
  130. //在列表控件中全选+右键可以删除所有测试结果
  131. using (RHDWContext db = new RHDWContext())
  132. {
  133. var listTx = db.TxInfos.ToList();
  134. var lines = File.ReadAllLines("Simulation_Data2023.dat");
  135. Random r = new Random();
  136. foreach (var item in lines)
  137. {
  138. if (stoped) break;
  139. double[] main_eph =new double[6] { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.1580461 };
  140. double[] main_eph1 = new double[6] { -3479298.029, 5612482.078, 2187911.486, -5784.105325, -2163.505176, -3632.855383 };
  141. double[] main_eph2 = new double[6] { -5018677.726, 4714449.429, 1001437.615, -4399.327638, -3780.398104, -4206.338078 };
  142. //double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  143. double[] Ref_Station_LLH = { 115.5, 9.899, 64 }; //*****参考站的位置
  144. double[] Zone =new double[4] { -85, 85, -180, 180 };
  145. double target_dfo1 = 2.002242571242008e+02;
  146. double target_dfo2 = 4.311089914542198e+03;
  147. double fu1 = 3.1085e8;
  148. double[] target_llh = new double[6];
  149. PosApi.SingleStar_DFO_DW(main_eph, main_eph1, main_eph2, Zone, target_dfo1, target_dfo2, fu1, target_llh);
  150. PosRes posRes = new PosRes()
  151. {
  152. SigTime = DateTime.Now,
  153. CgResID = 1,
  154. TarName = "未知目标",
  155. TsName = "tar2",
  156. PosLon = target_llh[0],
  157. PosLat = target_llh[1],
  158. MirrLon = target_llh[3],
  159. MirrLat = target_llh[4],
  160. };
  161. db.PosRes.Add(posRes);//定位结果入库
  162. //更新定位结果UI列表和地图
  163. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  164. var ds = this.gridPos.DataSource as List<PosRes>;
  165. ds.Insert(0, posRes);
  166. this.Invoke(new Action(() =>
  167. {
  168. gridView1.RefreshData();
  169. mapControl1.AddPosItem(posRes);
  170. }));
  171. await Task.Delay(200);
  172. }
  173. }
  174. }
  175. private async void DrawErrorEllipse1X()
  176. {
  177. try
  178. {
  179. var ids = gridView1.GetSelectedRows();
  180. if (ids.Length <= 0)
  181. {
  182. XtraMessageBox.Show("请选择需要绘制误差椭圆线的定位数据信息!");
  183. return;
  184. }
  185. var item = gridView1.GetRow(ids[0]) as PosRes;
  186. List<TxInfo> listTx = new List<TxInfo>();
  187. List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  188. CgRes cg;
  189. using (RHDWContext db = new RHDWContext())
  190. {
  191. listTx = db.TxInfos.ToList();
  192. listSat = db.SatInfos.ToList();
  193. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  194. }
  195. if (cg == null)
  196. {
  197. XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]信息");
  198. return;
  199. }
  200. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  201. var satNTx = listTx.Find(p => p.TxType == EnumTxType.AdjaSat);
  202. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  203. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  204. XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption Option = new XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption();
  205. Option.MsEph = new double[] { cg.MainX, cg.MainY, cg.MainZ, 0, 0, 0 };
  206. Option.NsEph1 = new double[] { cg.AdjaX, cg.AdjaY, cg.AdjaZ, 0, 0, 0 };
  207. Option.NsEph2 = new double[] { cdbTx.Lon, cdbTx.Lat, 0 };
  208. Option.SelectPoint = new double[3] { item.PosLon, item.PosLat, 0 };
  209. Option.DfoErr = 1;
  210. Option.EphPosErr = 1;
  211. Option.EphVelErr = 1;
  212. Option.fu = 3.1085e8;
  213. var points = XzXdDw.App.Api.低轨GDOP误差椭圆.ErrEllipseHelper.ErrorEllipseSingleX(Option);
  214. mapControl1.DrawDtoPonit($"单星[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}]误差椭圆线", points);
  215. }
  216. catch (Exception ex)
  217. {
  218. Serilog.Log.Error("绘制误差椭圆线失败", ex);
  219. XtraMessageBox.Show($"绘制误差椭圆线失败,失败信息:{ex.Message}");
  220. }
  221. }
  222. public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
  223. {
  224. var dots = line.Line;
  225. if (dots.Count < 30) return line;
  226. var tmp = dots.Count / 30;
  227. var newLine = new XdCxRhDW.App.DTO.MapLine();
  228. for (int i = 0; i < dots.Count; i += tmp)
  229. {
  230. newLine.Line.Add(dots[i]);
  231. }
  232. if (!newLine.Line.Contains(dots.Last()))
  233. newLine.Line.Add(dots.Last());
  234. return newLine;
  235. }
  236. }
  237. }