CtrlPosSingle.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. using DevExpress.Charts.Native;
  2. using DevExpress.Internal;
  3. using DevExpress.Utils.Drawing.Helpers;
  4. using DevExpress.Utils.Extensions;
  5. using DevExpress.XtraEditors;
  6. using DevExpress.XtraExport.Helpers;
  7. using DevExpress.XtraGrid.Views.Grid;
  8. using DevExpress.XtraMap;
  9. using DevExpress.XtraTreeList.Data;
  10. using DxHelper;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Data.Entity;
  16. using System.Drawing;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. using System.Windows.Controls;
  23. using System.Windows.Documents;
  24. using System.Windows.Forms;
  25. using XdCxRhDW.App.Api.时差粗值预测;
  26. using XdCxRhDW.App.Api.时差线;
  27. using XdCxRhDW.App.DTO;
  28. using XdCxRhDW.App.UserControl;
  29. using XzXdDw.App.Api;
  30. using XzXdDw.App.Api.星地GDOP误差椭圆;
  31. using XzXdDw.App.EditForms;
  32. using XzXdDw.App.EFContext;
  33. using XzXdDw.App.Model;
  34. using static DevExpress.XtraPrinting.Native.ExportOptionsPropertiesNames;
  35. namespace XzXdDw.App.UserControl
  36. {
  37. /// <summary>
  38. /// 星地定位
  39. /// </summary>
  40. public partial class CtrlPosSingle : DevExpress.XtraEditors.XtraUserControl
  41. {
  42. DtXDParam dtxdctrl = null;
  43. public CtrlPosSingle()
  44. {
  45. InitializeComponent();
  46. }
  47. private async void CtrlXdPos_Load(object sender, EventArgs e)
  48. {
  49. try
  50. {
  51. gridPos.Init().UseMultiSelect().UseFilter().UseRowNumber().UseExportXlsx()
  52. .AddMenu("删除", SvgHelper.CreateClose(), async () =>
  53. {
  54. try
  55. {
  56. if (XtraMessageBox.Show("确认删除?(Ctrl+A可全选删除)", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  57. {
  58. return;
  59. }
  60. var ids = gridView1.GetSelectedRows();
  61. List<PosRes> deletePos = new List<PosRes>();
  62. using (RHDWContext db = new RHDWContext())
  63. {
  64. foreach (var id in ids)
  65. {
  66. var item = gridView1.GetRow(id) as PosRes;
  67. var delItem = await db.PosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  68. if (delItem != null)
  69. {
  70. db.PosRes.Remove(delItem);
  71. }
  72. deletePos.Add(item);
  73. }
  74. await db.SaveChangesAsync();
  75. }
  76. gridView1.DeleteSelectedRows();
  77. mapControl1.DelPosItem(deletePos);
  78. }
  79. catch (Exception ex)
  80. {
  81. Serilog.Log.Error("删除结果失败", ex);
  82. XtraMessageBox.Show("删除结果失败");
  83. }
  84. })
  85. .AddMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), LoadSimulationData)
  86. .AddMenu("绘制频差线", SvgHelper.LoadFromFile("Image\\DfoLine.svg"), DrawDfoLine)
  87. .AddMenu("绘制误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), DrawErrorEllipse1X)
  88. .AddMenu("手动定位", SvgHelper.LoadFromFile("Image\\Pos.svg"), SinglePos)
  89. .AddMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), () => stoped = true);
  90. mapControl1.UseDefalutOptions()
  91. //.UseCluster()//定位点使用内置聚合
  92. .UseClearAll()
  93. .UseDistanceLine()
  94. .UseMarkDot()
  95. //.UseExportImg()
  96. //.UseExportXlsx()
  97. //.UseExportCsv()
  98. .UseDrawRect(rect =>
  99. {
  100. if (dtxdctrl != null)
  101. {
  102. dtxdctrl.rect = rect;
  103. }
  104. });
  105. //MapMenu为地图瓦片上右键菜单
  106. //AddPosMenu为定位点上右键菜单
  107. //RectMenu为框选的区域上右键菜单
  108. mapControl1.AddMapMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), (lon, lat) => LoadSimulationData())
  109. .AddMapMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), (lon, lat) => stoped = true)
  110. .AddMapMenu("GDOP分析", SvgHelper.LoadFromFile("Image\\GDOP.svg"), (lon, lat) =>
  111. {
  112. })
  113. .AddPosMenu<PosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
  114. {
  115. });
  116. //查询已有的定位记录
  117. using (RHDWContext db = new RHDWContext())
  118. {
  119. List<PosRes> list = await db.PosRes.ToListAsync();
  120. this.gridPos.DataSource = list;
  121. mapControl1.SetPosDataSource(list);
  122. }
  123. }
  124. catch (Exception ex)
  125. {
  126. Serilog.Log.Error("查询定位结果失败", ex);
  127. XtraMessageBox.Show("查询定位结果失败");
  128. }
  129. }
  130. bool stoped = false;
  131. private async void LoadSimulationData()
  132. {
  133. SimulationEditor editor = new SimulationEditor("Simulation_Data_DX20240115.dat");
  134. if (editor.ShowDialog() != DialogResult.OK)
  135. {
  136. return;
  137. }
  138. //"1xSimulation_Data2023.dat"
  139. string simulationFile = editor.SimulationFile;
  140. stoped = false;
  141. double fu = 3.1085e8;
  142. //在列表控件中全选+右键可以删除所有测试结果
  143. using (RHDWContext db = new RHDWContext())
  144. {
  145. var lines = File.ReadAllLines(simulationFile);
  146. Random r = new Random();
  147. foreach (var item in lines)
  148. {
  149. if (stoped) break;
  150. var items = item.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  151. if (items.Length != 20) continue;
  152. int index = 0;
  153. var target_dfo1 = Convert.ToDouble(items[index++]);
  154. var target_dfo2 = Convert.ToDouble(items[index++]);
  155. var mainX = Convert.ToDouble(items[index++]);
  156. var mainY = Convert.ToDouble(items[index++]);
  157. var mainZ = Convert.ToDouble(items[index++]);
  158. var mainVX = Convert.ToDouble(items[index++]);
  159. var mainVY = Convert.ToDouble(items[index++]);
  160. var mainVZ = Convert.ToDouble(items[index++]);
  161. var adjaX1 = Convert.ToDouble(items[index++]);
  162. var adjaY1 = Convert.ToDouble(items[index++]);
  163. var adjaZ1 = Convert.ToDouble(items[index++]);
  164. var adjaVX1 = Convert.ToDouble(items[index++]);
  165. var adjaVY1 = Convert.ToDouble(items[index++]);
  166. var adjaVZ1 = Convert.ToDouble(items[index++]);
  167. var adjaX2 = Convert.ToDouble(items[index++]);
  168. var adjaY2 = Convert.ToDouble(items[index++]);
  169. var adjaZ2 = Convert.ToDouble(items[index++]);
  170. var adjaVX2 = Convert.ToDouble(items[index++]);
  171. var adjaVY2 = Convert.ToDouble(items[index++]);
  172. var adjaVZ2 = Convert.ToDouble(items[index++]);
  173. DateTime SigTime = DateTime.Now;
  174. var cgRes = new CgRes()
  175. {
  176. SigTime = SigTime,
  177. DtoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  178. DfoSx = target_dfo1,
  179. SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
  180. MainX = mainX,
  181. MainY = mainY,
  182. MainZ = mainZ,
  183. MainVX = mainVX,
  184. MainVY = mainVY,
  185. MainVZ = mainVZ,
  186. AdjaX = adjaX1,
  187. AdjaY = adjaY1,
  188. AdjaZ = adjaZ1,
  189. AdjaVX = adjaVX1,
  190. AdjaVY = adjaVY1,
  191. AdjaVZ = adjaVZ1,
  192. };
  193. var cgRes1 = new CgRes()
  194. {
  195. SigTime = SigTime,
  196. DtoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  197. DfoSx = target_dfo2,
  198. SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
  199. MainX = mainX,
  200. MainY = mainY,
  201. MainZ = mainZ,
  202. MainVX = mainVX,
  203. MainVY = mainVY,
  204. MainVZ = mainVZ,
  205. AdjaX = adjaX2,
  206. AdjaY = adjaY2,
  207. AdjaZ = adjaZ2,
  208. AdjaVX = adjaVX2,
  209. AdjaVY = adjaVY2,
  210. AdjaVZ = adjaVZ2,
  211. };
  212. var cg = db.CgRes.Add(cgRes);//参估结果入库
  213. var cg1 = db.CgRes.Add(cgRes1);//参估结果入库
  214. await db.SaveChangesAsync();
  215. var res = PosApi.X1_POS(cg, cg1, fu);
  216. PosRes posRes = new PosRes()
  217. {
  218. UpFreq = fu,
  219. SigTime = DateTime.Now,
  220. CgResID = cg.ID,
  221. TarName = "未知目标",
  222. TsName = "tar2",
  223. PosLon = res[0],
  224. PosLat = res[1],
  225. MirrLon = res[3],
  226. MirrLat = res[4]
  227. };
  228. db.PosRes.Add(posRes);//定位结果入库
  229. //更新定位结果UI列表和地图
  230. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  231. var ds = this.gridPos.DataSource as List<PosRes>;
  232. ds.Insert(0, posRes);
  233. this.Invoke(new Action(() =>
  234. {
  235. gridView1.RefreshData();
  236. mapControl1.AddPosItem(posRes);
  237. }));
  238. await Task.Delay(200);
  239. }
  240. }
  241. }
  242. private async void DrawErrorEllipse1X()
  243. {
  244. try
  245. {
  246. var ids = gridView1.GetSelectedRows();
  247. if (ids.Length <= 0)
  248. {
  249. XtraMessageBox.Show("请选择需要绘制误差椭圆线的定位数据信息!");
  250. return;
  251. }
  252. var item = gridView1.GetRow(ids[0]) as PosRes;
  253. List<TxInfo> listTx = new List<TxInfo>();
  254. List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  255. List<CgRes> cgs;
  256. using (RHDWContext db = new RHDWContext())
  257. {
  258. listTx = db.TxInfos.ToList();
  259. listSat = db.SatInfos.ToList();
  260. var cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  261. cgs = await db.CgRes.Where(m => m.SigTime == cg.SigTime).ToListAsync();
  262. }
  263. if (cgs.Count != 2)
  264. {
  265. XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]{item.SigTime:yyyy-MM-dd HH:mm:ss}的参估信息!");
  266. return;
  267. }
  268. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  269. var cg1 = cgs.First(c => c.ID == item.CgResID);
  270. var cg2 = cgs.First(c => c.ID != item.CgResID);
  271. #warning 但凡是和频差相关的 星历必须给速度
  272. XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption Option = new XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption();
  273. Option.MsEph = new double[6] { cg1.MainX, cg1.MainY, cg1.MainZ, cg1.MainVX, cg1.MainVY, cg1.MainVZ };
  274. Option.NsEph1 = new double[6] { cg1.AdjaX, cg1.AdjaY, cg1.AdjaZ, cg1.AdjaVX, cg1.AdjaVY, cg1.AdjaVZ };
  275. Option.NsEph2 = new double[6] { cg2.AdjaX, cg2.AdjaY, cg2.AdjaZ, cg2.AdjaVX, cg2.AdjaVY, cg2.AdjaVZ };
  276. Option.SelectPoint =new double[3] { item.PosLon, item.PosLat, 0 };
  277. Option.DfoErr = 0.01; ;
  278. Option.EphPosErr = 1.0e3;
  279. Option.EphVelErr = 0.1;
  280. Option.fu = 3.1085e8;
  281. var points = XzXdDw.App.Api.低轨GDOP误差椭圆.ErrEllipseHelper.ErrorEllipseSingleX(Option);
  282. mapControl1.DrawDtoPonit($"单星[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}]误差椭圆线", points);
  283. }
  284. catch (Exception ex)
  285. {
  286. Serilog.Log.Error("绘制误差椭圆线失败", ex);
  287. XtraMessageBox.Show($"绘制误差椭圆线失败,失败信息:{ex.Message}");
  288. }
  289. }
  290. private async void DrawDfoLine()
  291. {
  292. try
  293. {
  294. var ids = gridView1.GetSelectedRows();
  295. if (ids.Length <= 0)
  296. {
  297. XtraMessageBox.Show("请选择需要绘制频差线的定位数据信息!");
  298. return;
  299. }
  300. var item = gridView1.GetRow(ids[0]) as PosRes;
  301. List<TxInfo> listTx = new List<TxInfo>();
  302. List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  303. List<CgRes> cgs;
  304. using (RHDWContext db = new RHDWContext())
  305. {
  306. listTx = db.TxInfos.ToList();
  307. listSat = db.SatInfos.ToList();
  308. var cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  309. cgs = await db.CgRes.Where(m => m.SigTime == cg.SigTime).ToListAsync();
  310. }
  311. if (cgs.Count != 2)
  312. {
  313. XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]{item.SigTime:yyyy-MM-dd HH:mm:ss}的参估信息!");
  314. return;
  315. }
  316. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  317. var cg1 = cgs.First(c=>c.ID== item.CgResID);
  318. var cg2 = cgs.First(c => c.ID != item.CgResID);
  319. double[] main_eph = new double[6] { cg1.MainX, cg1.MainY, cg1.MainZ, cg1.MainVX, cg1.MainVY, cg1.MainVZ};
  320. double[] main_eph1 = new double[6] { cg1.AdjaX, cg1.AdjaY, cg1.AdjaZ, cg1.AdjaVX, cg1.AdjaVY, cg1.AdjaVZ };
  321. double[] main_eph2 = new double[6] { cg2.AdjaX, cg2.AdjaY, cg2.AdjaZ, cg2.AdjaVX, cg2.AdjaVY, cg2.AdjaVZ };
  322. var xdDtoLine = DrawDtoLineHelper.DfoLineSingleStart(main_eph, main_eph1, cg1.DfoSx, item.UpFreq);
  323. mapControl1.DrawDtoPonit($"单星[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}时刻1频差线", xdDtoLine);
  324. var xdDtoLine1 = DrawDtoLineHelper.DfoLineSingleStart(main_eph, main_eph2, cg2.DfoSx, item.UpFreq);
  325. mapControl1.DrawDtoPonit($"单星[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}时刻2频差线", xdDtoLine1);
  326. }
  327. catch (Exception ex)
  328. {
  329. Serilog.Log.Error("单星绘制频差线失败", ex);
  330. XtraMessageBox.Show($"单星绘制频差线失败,失败信息:{ex.Message}");
  331. }
  332. }
  333. private async void SinglePos()
  334. {
  335. try
  336. {
  337. var ids = gridView1.GetSelectedRows();
  338. if (ids.Length <= 0)
  339. {
  340. XtraMessageBox.Show("请选择需要手动定位的数据信息!");
  341. return;
  342. }
  343. var item = gridView1.GetRow(ids[0]) as PosRes;
  344. List<CgRes> cgs;
  345. using (RHDWContext db = new RHDWContext())
  346. {
  347. var cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  348. cgs = await db.CgRes.Where(m => m.SigTime == cg.SigTime).ToListAsync();
  349. }
  350. if (cgs.Count != 2)
  351. {
  352. XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]{item.SigTime:yyyy-MM-dd HH:mm:ss}的参估信息!");
  353. return;
  354. }
  355. SinglePosParamEditor frm = new SinglePosParamEditor(item, cgs[0], cgs[1], () =>
  356. {
  357. gridView1.RefreshData();
  358. if (item.PosLon > 180 || item.PosLon < -180)
  359. {
  360. item.PosLon = 0;
  361. item.PosLat = 0;
  362. }
  363. mapControl1.UpdatePosItem(item);
  364. });
  365. frm.ShowDialog();
  366. }
  367. catch (Exception ex)
  368. {
  369. Serilog.Log.Error("手动定位失败", ex);
  370. XtraMessageBox.Show("手动定位失败");
  371. }
  372. }
  373. public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
  374. {
  375. var dots = line.Line;
  376. if (dots.Count < 30) return line;
  377. var tmp = dots.Count / 30;
  378. var newLine = new XdCxRhDW.App.DTO.MapLine();
  379. for (int i = 0; i < dots.Count; i += tmp)
  380. {
  381. newLine.Line.Add(dots[i]);
  382. }
  383. if (!newLine.Line.Contains(dots.Last()))
  384. newLine.Line.Add(dots.Last());
  385. return newLine;
  386. }
  387. }
  388. }