CtrlPosXz.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. using DevExpress.Utils.Drawing.Helpers;
  2. using DevExpress.Utils.Extensions;
  3. using DevExpress.XtraEditors;
  4. using DevExpress.XtraExport.Helpers;
  5. using DevExpress.XtraGrid.Views.Grid;
  6. using DevExpress.XtraMap;
  7. using DevExpress.XtraTreeList.Data;
  8. using DxHelper;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Data.Entity;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. using System.Windows.Controls;
  21. using System.Windows.Documents;
  22. using System.Windows.Forms;
  23. using XdCxRhDW.App.Api.时差粗值预测;
  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.EFContext;
  31. using XzXdDw.App.Model;
  32. namespace XzXdDw.App.UserControl
  33. {
  34. /// <summary>
  35. /// 星地定位
  36. /// </summary>
  37. public partial class CtrlPosXz : DevExpress.XtraEditors.XtraUserControl
  38. {
  39. /// <summary>
  40. /// 时差初值 范围计算
  41. /// </summary>
  42. DtSXLParam dtsxlctrl = null;
  43. public CtrlPosXz()
  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. using (RHDWContext db = new RHDWContext())
  62. {
  63. foreach (var id in ids)
  64. {
  65. var item = gridView1.GetRow(id) as XZPosRes;
  66. var delItem = await db.XZPosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  67. if (delItem != null)
  68. {
  69. db.XZPosRes.Remove(delItem);
  70. }
  71. }
  72. await db.SaveChangesAsync();
  73. }
  74. gridView1.DeleteSelectedRows();
  75. }
  76. catch (Exception ex)
  77. {
  78. Serilog.Log.Error("删除结果失败", ex);
  79. XtraMessageBox.Show("删除结果失败");
  80. }
  81. })
  82. .AddMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), LoadTestData)
  83. .AddMenu("绘制时差线", SvgHelper.LoadFromFile("Image\\DrawLine.svg"), DrawDtoLine)
  84. .AddMenu("绘制频差线", SvgHelper.LoadFromFile("Image\\DfoLine.svg"), DrawDfoLine)
  85. .AddMenu("绘制误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), ()=> {
  86. var ctrl = new XZErrEllipseParam();
  87. PopupHelper.ShowPopup(ctrl, mapControl1, mapControl1.Width / 4, onHide: hideReason =>
  88. {
  89. if (hideReason == HideReason.Defalut) return;
  90. var model = ctrl.Model;
  91. var currentPos = gridView1.GetFocusedRow() as XZPosRes;
  92. double[] main_sat = Tle2XYZ.GetXyz(model.TleMain, model.CapTime);
  93. double[] adja_sat = Tle2XYZ.GetXyz(model.TleAdja, model.CapTime);
  94. DrawErrorEllipseDTFO(currentPos, main_sat, adja_sat, new double[] { model.RefLon, model.RefLat, 0 }, model.fu1, model.fu2);
  95. });
  96. })
  97. .AddMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), () => stoped = true);
  98. mapControl1.UseDefalutOptions()
  99. //.UseCluster()//定位点使用内置聚合
  100. .UseClearAll()
  101. .UseDistanceLine()
  102. .UseMarkDot()
  103. //.UseExportImg()
  104. //.UseExportXlsx()
  105. //.UseExportCsv()
  106. .UseDrawRect(rect =>
  107. {
  108. if (dtsxlctrl != null)
  109. {
  110. dtsxlctrl.rect = rect;
  111. }
  112. });
  113. //MapMenu为地图瓦片上右键菜单
  114. //AddPosMenu为定位点上右键菜单
  115. //RectMenu为框选的区域上右键菜单
  116. mapControl1.AddMapMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), (lon, lat) => LoadTestData())
  117. .AddMapMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), (lon, lat) => stoped = true)
  118. .AddMapMenu("GDOP分析", SvgHelper.LoadFromFile("Image\\GDOP.svg"), (lon, lat) =>
  119. {
  120. })
  121. .AddPosMenu<XZPosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
  122. {
  123. var ctrl = new XZErrEllipseParam();
  124. PopupHelper.ShowPopup(ctrl, mapControl1, mapControl1.Width / 4, onHide: hideReason =>
  125. {
  126. if (hideReason == HideReason.Defalut) return;
  127. var model = ctrl.Model;
  128. double[] main_sat = Tle2XYZ.GetXyz(model.TleMain, model.CapTime);
  129. double[] adja_sat = Tle2XYZ.GetXyz(model.TleAdja, model.CapTime);
  130. DrawErrorEllipseDTFO(item, main_sat, adja_sat, new double[] { model.RefLon,model.RefLat,0},model.fu1,model.fu2);
  131. });
  132. })
  133. .AddRectMenu<XZPosRes>("时差初值预估", SvgHelper.LoadFromFile("Image\\初值预估.svg"), items =>
  134. {
  135. var rect = mapControl1.GetCurrentRect();
  136. if (dtsxlctrl == null)
  137. {
  138. dtsxlctrl = new DtSXLParam();
  139. }
  140. dtsxlctrl.rect = rect;
  141. PopupHelper.ShowPopup(dtsxlctrl, mapControl1, mapControl1.Width / 4);
  142. });
  143. //查询已有的定位记录
  144. using (RHDWContext db = new RHDWContext())
  145. {
  146. List<XZPosRes> list = await db.XZPosRes.ToListAsync();
  147. this.gridPos.DataSource = list;
  148. mapControl1.SetPosDataSource(list);
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. Serilog.Log.Error("查询定位结果失败", ex);
  154. XtraMessageBox.Show("查询定位结果失败");
  155. }
  156. }
  157. bool stoped = false;
  158. private async void LoadTestData()
  159. {
  160. stoped = false;
  161. //在列表控件中全选+右键可以删除所有测试结果
  162. using (RHDWContext db = new RHDWContext())
  163. {
  164. var listTx = db.TxInfos.ToList();
  165. var lines = File.ReadAllLines("Simulation_Data2023.dat");
  166. Random r = new Random();
  167. foreach (var item in lines)
  168. {
  169. if (stoped) break;
  170. //var items = item.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  171. //var sxDto = Convert.ToDouble(items[0]);
  172. //var xdDto = Convert.ToDouble(items[1]);
  173. //var mainYbDto = Convert.ToDouble(items[2]);
  174. //var adjaYbDto = Convert.ToDouble(items[3]);
  175. //var mainX = Convert.ToDouble(items[7]);
  176. //var mainY = Convert.ToDouble(items[8]);
  177. //var mainZ = Convert.ToDouble(items[9]);
  178. //var adjaX = Convert.ToDouble(items[10]);
  179. //var adjaY = Convert.ToDouble(items[11]);
  180. //var adjaZ = Convert.ToDouble(items[12]);
  181. //var cgRes = new CgRes()
  182. //{
  183. // SigTime = DateTime.Now,
  184. // DtoSx = sxDto * 1e6,
  185. // DfoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  186. // SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
  187. // DtoCdb = xdDto * 1e6,
  188. // DfoCdb = 600 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  189. // SnrCdb = r.Next(22, 32) + Math.Round(r.NextDouble(), 1),
  190. // YbMain = mainYbDto * 1e6,
  191. // YbAdja = adjaYbDto * 1e6,
  192. // MainX = mainX,
  193. // MainY = mainY,
  194. // MainZ = mainZ,
  195. // AdjaX = adjaX,
  196. // AdjaY = adjaY,
  197. // AdjaZ = adjaZ,
  198. //};
  199. //db.CgRes.Add(cgRes);//参估结果入库
  200. //var res = PosApi.X2D1_POS(cgRes, listTx);
  201. //PosRes posRes = new PosRes()
  202. //{
  203. // SigTime = cgRes.SigTime,
  204. // CgResID = cgRes.ID,
  205. // TarName = "未知目标",
  206. // TsName = "tar2",
  207. // PosLon = res[0],
  208. // PosLat = res[1],
  209. // MirrLon = res[3],
  210. // MirrLat = res[4],
  211. //};
  212. //db.PosRes.Add(posRes);//定位结果入库
  213. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  214. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  215. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  216. double[] Zone = { -80, 80, -150, 150 };
  217. double target_dto = -0.010246009710722;
  218. double target_dfo = 1.595360344349182e+03;
  219. double ref_dto = 0.002823291225258;
  220. double ref_dfo = 1.132007974492508e+04;
  221. double fu1 = 3.1085e8;
  222. double fu2 = 2.95e8;
  223. double[] target_llh = new double[6];
  224. PosApi.TwoStar_DTFO_DW(main_sat, neigh_sat, Ref_Station_LLH, Zone, target_dto, target_dfo, ref_dto, ref_dfo, fu1, fu2, target_llh);
  225. XZPosRes posRes = new XZPosRes()
  226. {
  227. SigTime = DateTime.Now,
  228. CgResID = 1,
  229. TarName = "未知目标",
  230. TsName = "tar2",
  231. PosLon = target_llh[0],
  232. PosLat = target_llh[1],
  233. MirrLon = target_llh[3],
  234. MirrLat = target_llh[4],
  235. };
  236. db.XZPosRes.Add(posRes);//定位结果入库
  237. //更新定位结果UI列表和地图
  238. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  239. var ds = this.gridPos.DataSource as List<XZPosRes>;
  240. ds.Insert(0, posRes);
  241. this.Invoke(new Action(() =>
  242. {
  243. gridView1.RefreshData();
  244. mapControl1.AddPosItem(posRes);
  245. }));
  246. await Task.Delay(200);
  247. }
  248. }
  249. }
  250. private void DrawDtoLine()
  251. {
  252. try
  253. {
  254. var ids = gridView1.GetSelectedRows();
  255. if (ids.Length <= 0)
  256. {
  257. XtraMessageBox.Show("请选择需要绘制时差线的定位数据信息!");
  258. return;
  259. }
  260. var item = gridView1.GetRow(ids[0]) as XZPosRes;
  261. //List<TxInfo> listTx = new List<TxInfo>();
  262. //List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  263. //CgRes cg;
  264. //using (RHDWContext db = new RHDWContext())
  265. //{
  266. // listTx = db.TxInfos.ToList();
  267. // listSat = db.SatInfos.ToList();
  268. // cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  269. //}
  270. //if (cg == null)
  271. //{
  272. // XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]信息");
  273. // return;
  274. //}
  275. //var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  276. //var satNTx = listTx.Find(p => p.TxType == EnumTxType.AdjaSat);
  277. //var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  278. //var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  279. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  280. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  281. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  282. double[] Zone = { -80, 80, -150, 150 };
  283. double target_dto = -0.010246009710722;
  284. double ref_dto = 0.002823291225258;
  285. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  286. twoStartOption.MsEph = main_sat;
  287. twoStartOption.NsEph = neigh_sat;
  288. twoStartOption.RefGeod = Ref_Station_LLH;
  289. twoStartOption.TargetDto = target_dto * 1e6;
  290. twoStartOption.RefDto = ref_dto * 1e6;
  291. var tsDtoLine = DrawDtoLineHelper.DtoLineXZTwoStart(twoStartOption);
  292. mapControl1.DrawDtoPonit($"双星时差线", tsDtoLine);
  293. }
  294. catch (Exception ex)
  295. {
  296. Serilog.Log.Error("绘制时差线失败", ex);
  297. XtraMessageBox.Show($"绘制时差线失败,失败信息:{ex.Message}");
  298. }
  299. }
  300. private void DrawDfoLine()
  301. {
  302. try
  303. {
  304. var ids = gridView1.GetSelectedRows();
  305. if (ids.Length <= 0)
  306. {
  307. XtraMessageBox.Show("请选择需要绘制频差线的定位数据信息!");
  308. return;
  309. }
  310. var item = gridView1.GetRow(ids[0]) as XZPosRes;
  311. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  312. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  313. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  314. double[] Zone = { -80, 80, -150, 150 };
  315. double target_dfo = 1.595360344349182e+03;
  316. double ref_dfo = 1.132007974492508e+04;
  317. double fu1 = 3.1085e8;
  318. double fu2 = 2.95e8;
  319. DfoLineTwoStartOption twoStartOption = new DfoLineTwoStartOption();
  320. twoStartOption.MsEph = main_sat;
  321. twoStartOption.NsEph = neigh_sat;
  322. twoStartOption.RefGeod = Ref_Station_LLH;
  323. twoStartOption.TargetDfo = target_dfo;
  324. twoStartOption.RefDfo = ref_dfo;
  325. twoStartOption.fu1 = fu1;
  326. twoStartOption.fu2 = fu2;
  327. var tsDtoLine = DrawDtoLineHelper.DfoLineXZTwoStart(twoStartOption);
  328. mapControl1.DrawDtoPonit($"双星频差线", tsDtoLine);
  329. }
  330. catch (Exception ex)
  331. {
  332. Serilog.Log.Error("绘制频差线失败", ex);
  333. XtraMessageBox.Show($"绘制频差线失败,失败信息:{ex.Message}");
  334. }
  335. }
  336. private void DrawErrorEllipseDTFO(XZPosRes item, double[] main_sat, double[] neigh_sat, double[] Ref_Station_LLH, double fu1, double fu2)
  337. {
  338. try
  339. {
  340. var ids = gridView1.GetSelectedRows();
  341. if (ids.Length <= 0)
  342. {
  343. XtraMessageBox.Show("请选择需要绘制误差椭圆线的定位数据信息!");
  344. return;
  345. }
  346. //var item = gridView1.GetRow(ids[0]) as XZPosRes;
  347. //double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  348. //double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  349. //double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  350. //double fu1 = 3.1085e8;
  351. //double fu2 = 2.95e8;
  352. ErrorEllipseDTFOTSOption twoStartOption = new ErrorEllipseDTFOTSOption();
  353. twoStartOption.MsEph = main_sat;
  354. twoStartOption.NsEph = neigh_sat;
  355. twoStartOption.RefGeod = Ref_Station_LLH;
  356. twoStartOption.SelectPoint = new double[3] { item.PosLon,item.PosLat,0 };
  357. twoStartOption.DtoErr =1;
  358. twoStartOption.DfoErr =1;
  359. twoStartOption.EphPosErr = 1;
  360. twoStartOption.EphVelErr = 1;
  361. twoStartOption.fu1 = fu1;
  362. twoStartOption.fu2 = fu2;
  363. var points = ErrEllipseHelper.ErrorEllipseDTFOTwoStart(twoStartOption);
  364. mapControl1.DrawDtoPonit($"双星误差椭圆线", points);
  365. }
  366. catch (Exception ex)
  367. {
  368. Serilog.Log.Error("绘制误差椭圆线失败", ex);
  369. XtraMessageBox.Show($"绘制误差椭圆线失败,失败信息:{ex.Message}");
  370. }
  371. }
  372. public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
  373. {
  374. var dots = line.Line;
  375. if (dots.Count < 30) return line;
  376. var tmp = dots.Count / 30;
  377. var newLine = new XdCxRhDW.App.DTO.MapLine();
  378. for (int i = 0; i < dots.Count; i += tmp)
  379. {
  380. newLine.Line.Add(dots[i]);
  381. }
  382. if (!newLine.Line.Contains(dots.Last()))
  383. newLine.Line.Add(dots.Last());
  384. return newLine;
  385. }
  386. }
  387. }