CtrlPosSingle.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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\\DfoLine.svg"), DrawDfoLine)
  85. .AddMenu("绘制误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), DrawErrorEllipse1X)
  86. .AddMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), () => stoped = true);
  87. mapControl1.UseDefalutOptions()
  88. //.UseCluster()//定位点使用内置聚合
  89. .UseClearAll()
  90. .UseDistanceLine()
  91. .UseMarkDot()
  92. //.UseExportImg()
  93. //.UseExportXlsx()
  94. //.UseExportCsv()
  95. .UseDrawRect(rect =>
  96. {
  97. if (dtxdctrl != null)
  98. {
  99. dtxdctrl.rect = rect;
  100. }
  101. });
  102. //MapMenu为地图瓦片上右键菜单
  103. //AddPosMenu为定位点上右键菜单
  104. //RectMenu为框选的区域上右键菜单
  105. mapControl1.AddMapMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), (lon, lat) => LoadTestData())
  106. .AddMapMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), (lon, lat) => stoped = true)
  107. .AddMapMenu("GDOP分析", SvgHelper.LoadFromFile("Image\\GDOP.svg"), (lon, lat) =>
  108. {
  109. })
  110. .AddPosMenu<PosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
  111. {
  112. });
  113. //查询已有的定位记录
  114. using (RHDWContext db = new RHDWContext())
  115. {
  116. List<PosRes> list = await db.PosRes.ToListAsync();
  117. this.gridPos.DataSource = list;
  118. mapControl1.SetPosDataSource(list);
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. Serilog.Log.Error("查询定位结果失败", ex);
  124. XtraMessageBox.Show("查询定位结果失败");
  125. }
  126. }
  127. bool stoped = false;
  128. private async void LoadTestData()
  129. {
  130. stoped = false;
  131. //在列表控件中全选+右键可以删除所有测试结果
  132. using (RHDWContext db = new RHDWContext())
  133. {
  134. var listTx = db.TxInfos.ToList();
  135. var lines = File.ReadAllLines("Simulation_Data2023.dat");
  136. Random r = new Random();
  137. foreach (var item in lines)
  138. {
  139. if (stoped) break;
  140. double[] main_eph =new double[6] { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.1580461 };
  141. double[] main_eph1 = new double[6] { -3479298.029, 5612482.078, 2187911.486, -5784.105325, -2163.505176, -3632.855383 };
  142. double[] main_eph2 = new double[6] { -5018677.726, 4714449.429, 1001437.615, -4399.327638, -3780.398104, -4206.338078 };
  143. //double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  144. double[] Ref_Station_LLH = { 115.5, 9.899, 64 }; //*****参考站的位置
  145. double[] Zone =new double[4] { -85, 85, -180, 180 };
  146. double target_dfo1 = 2.002242571242008e+02;
  147. double target_dfo2 = 4.311089914542198e+03;
  148. double fu1 = 3.1085e8;
  149. double[] target_llh = new double[6];
  150. PosApi.SingleStar_DFO_DW(main_eph, main_eph1, main_eph2, Zone, target_dfo1, target_dfo2, fu1, target_llh);
  151. PosRes posRes = new PosRes()
  152. {
  153. SigTime = DateTime.Now,
  154. CgResID = 1,
  155. TarName = "未知目标",
  156. TsName = "tar2",
  157. PosLon = target_llh[0],
  158. PosLat = target_llh[1],
  159. MirrLon = target_llh[3],
  160. MirrLat = target_llh[4],
  161. };
  162. db.PosRes.Add(posRes);//定位结果入库
  163. //更新定位结果UI列表和地图
  164. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  165. var ds = this.gridPos.DataSource as List<PosRes>;
  166. ds.Insert(0, posRes);
  167. this.Invoke(new Action(() =>
  168. {
  169. gridView1.RefreshData();
  170. mapControl1.AddPosItem(posRes);
  171. }));
  172. await Task.Delay(200);
  173. }
  174. }
  175. }
  176. private async void DrawErrorEllipse1X()
  177. {
  178. try
  179. {
  180. var ids = gridView1.GetSelectedRows();
  181. if (ids.Length <= 0)
  182. {
  183. XtraMessageBox.Show("请选择需要绘制误差椭圆线的定位数据信息!");
  184. return;
  185. }
  186. var item = gridView1.GetRow(ids[0]) as PosRes;
  187. List<TxInfo> listTx = new List<TxInfo>();
  188. List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  189. CgRes cg;
  190. using (RHDWContext db = new RHDWContext())
  191. {
  192. listTx = db.TxInfos.ToList();
  193. listSat = db.SatInfos.ToList();
  194. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  195. }
  196. if (cg == null)
  197. {
  198. XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]信息");
  199. return;
  200. }
  201. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  202. var satNTx = listTx.Find(p => p.TxType == EnumTxType.AdjaSat);
  203. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  204. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  205. #warning 但凡是和频差相关的 星历必须给速度
  206. double[] main_eph = new double[6] { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.1580461 };
  207. double[] main_eph1 = new double[6] { -3479298.029, 5612482.078, 2187911.486, -5784.105325, -2163.505176, -3632.855383 };
  208. double[] main_eph2 = new double[6] { -5018677.726, 4714449.429, 1001437.615, -4399.327638, -3780.398104, -4206.338078 };
  209. XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption Option = new XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption();
  210. Option.MsEph = main_eph;
  211. Option.NsEph1 = main_eph1;
  212. Option.NsEph2 = main_eph2;
  213. Option.SelectPoint =new double[2] { -180, -85}; ;//new double[3] { item.PosLon, item.PosLat, 0 };
  214. Option.DfoErr = 0.01; ;
  215. Option.EphPosErr = 1.0e3;
  216. Option.EphVelErr = 0.1;
  217. Option.fu = 3.1085e8;
  218. var points = XzXdDw.App.Api.低轨GDOP误差椭圆.ErrEllipseHelper.ErrorEllipseSingleX(Option);
  219. mapControl1.DrawDtoPonit($"单星[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}]误差椭圆线", points);
  220. }
  221. catch (Exception ex)
  222. {
  223. Serilog.Log.Error("绘制误差椭圆线失败", ex);
  224. XtraMessageBox.Show($"绘制误差椭圆线失败,失败信息:{ex.Message}");
  225. }
  226. }
  227. private async void DrawDfoLine()
  228. {
  229. try
  230. {
  231. var ids = gridView1.GetSelectedRows();
  232. if (ids.Length <= 0)
  233. {
  234. XtraMessageBox.Show("请选择需要绘制频差线的定位数据信息!");
  235. return;
  236. }
  237. var item = gridView1.GetRow(ids[0]) as PosRes;
  238. List<TxInfo> listTx = new List<TxInfo>();
  239. List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  240. CgRes cg;
  241. using (RHDWContext db = new RHDWContext())
  242. {
  243. listTx = db.TxInfos.ToList();
  244. listSat = db.SatInfos.ToList();
  245. cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  246. }
  247. if (cg == null)
  248. {
  249. XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]信息");
  250. return;
  251. }
  252. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  253. double[] main_eph = new double[6] { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.1580461 };
  254. double[] main_eph1 = new double[6] { -3479298.029, 5612482.078, 2187911.486, -5784.105325, -2163.505176, -3632.855383 };
  255. double[] main_eph2 = new double[6] { -5018677.726, 4714449.429, 1001437.615, -4399.327638, -3780.398104, -4206.338078 };
  256. //double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  257. double[] Ref_Station_LLH = { 115.5, 9.899, 64 }; //*****参考站的位置
  258. double[] Zone = new double[4] { -85, 85, -180, 180 };
  259. double target_dfo1 = 2.002242571242008e+02;
  260. double target_dfo2 = 4.311089914542198e+03;
  261. double fu1 = 3.1085e8;
  262. double[] target_llh = new double[6];
  263. var xdDtoLine = DrawDtoLineHelper.DfoLineSingleStart(main_eph, main_eph1, target_dfo1,fu1);
  264. mapControl1.DrawDtoPonit($"星地[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}时刻1频差线", xdDtoLine);
  265. var xdDtoLine1 = DrawDtoLineHelper.DfoLineSingleStart(main_eph, main_eph2, target_dfo2, fu1);
  266. mapControl1.DrawDtoPonit($"星地[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}时刻2频差线", xdDtoLine1);
  267. }
  268. catch (Exception ex)
  269. {
  270. Serilog.Log.Error("绘制频差线失败", ex);
  271. XtraMessageBox.Show($"绘制频差线失败,失败信息:{ex.Message}");
  272. }
  273. }
  274. public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
  275. {
  276. var dots = line.Line;
  277. if (dots.Count < 30) return line;
  278. var tmp = dots.Count / 30;
  279. var newLine = new XdCxRhDW.App.DTO.MapLine();
  280. for (int i = 0; i < dots.Count; i += tmp)
  281. {
  282. newLine.Line.Add(dots[i]);
  283. }
  284. if (!newLine.Line.Contains(dots.Last()))
  285. newLine.Line.Add(dots.Last());
  286. return newLine;
  287. }
  288. }
  289. }