CtrlPosXz.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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.DTO;
  26. using XdCxRhDW.App.UserControl;
  27. using XzXdDw.App.Api;
  28. using XzXdDw.App.Api.低轨GDOP误差椭圆;
  29. using XzXdDw.App.EFContext;
  30. using XzXdDw.App.Model;
  31. namespace XzXdDw.App.UserControl
  32. {
  33. /// <summary>
  34. /// 星地定位
  35. /// </summary>
  36. public partial class CtrlPosXz : DevExpress.XtraEditors.XtraUserControl
  37. {
  38. /// <summary>
  39. /// 时差初值 范围计算
  40. /// </summary>
  41. DtSXLParam dtsxlctrl = null;
  42. public CtrlPosXz()
  43. {
  44. InitializeComponent();
  45. }
  46. private async void CtrlXdPos_Load(object sender, EventArgs e)
  47. {
  48. try
  49. {
  50. gridPos.Init().UseMultiSelect().UseFilter().UseRowNumber().UseExportXlsx()
  51. .AddMenu("删除", SvgHelper.CreateClose(), async () =>
  52. {
  53. try
  54. {
  55. if (XtraMessageBox.Show("确认删除?(Ctrl+A可全选删除)", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  56. {
  57. return;
  58. }
  59. var ids = gridView1.GetSelectedRows();
  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. }
  71. await db.SaveChangesAsync();
  72. }
  73. gridView1.DeleteSelectedRows();
  74. }
  75. catch (Exception ex)
  76. {
  77. Serilog.Log.Error("删除结果失败", ex);
  78. XtraMessageBox.Show("删除结果失败");
  79. }
  80. })
  81. .AddMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), LoadTestData)
  82. .AddMenu("绘制时差线", SvgHelper.LoadFromFile("Image\\DrawLine.svg"), DrawDtoLine)
  83. .AddMenu("绘制频差线", SvgHelper.LoadFromFile("Image\\DfoLine.svg"), DrawDfoLine)
  84. .AddMenu("绘制误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), DrawErrorEllipseDTFO)
  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 (dtsxlctrl != null)
  97. {
  98. dtsxlctrl.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. })
  110. .AddPosMenu<PosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
  111. {
  112. //参考星地的
  113. })
  114. .AddRectMenu<PosRes>("时差初值预估", SvgHelper.LoadFromFile("Image\\初值预估.svg"), items =>
  115. {
  116. var rect = mapControl1.GetCurrentRect();
  117. if (dtsxlctrl == null)
  118. {
  119. dtsxlctrl = new DtSXLParam();
  120. }
  121. dtsxlctrl.rect = rect;
  122. PopupHelper.ShowPopup(dtsxlctrl, mapControl1, mapControl1.Width / 4);
  123. });
  124. //查询已有的定位记录
  125. using (RHDWContext db = new RHDWContext())
  126. {
  127. List<PosRes> list = await db.PosRes.ToListAsync();
  128. this.gridPos.DataSource = list;
  129. mapControl1.SetPosDataSource(list);
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. Serilog.Log.Error("查询定位结果失败", ex);
  135. XtraMessageBox.Show("查询定位结果失败");
  136. }
  137. }
  138. bool stoped = false;
  139. private async void LoadTestData()
  140. {
  141. stoped = false;
  142. //在列表控件中全选+右键可以删除所有测试结果
  143. using (RHDWContext db = new RHDWContext())
  144. {
  145. var listTx = db.TxInfos.ToList();
  146. var lines = File.ReadAllLines("Simulation_Data2023.dat");
  147. Random r = new Random();
  148. foreach (var item in lines)
  149. {
  150. if (stoped) break;
  151. //var items = item.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  152. //var sxDto = Convert.ToDouble(items[0]);
  153. //var xdDto = Convert.ToDouble(items[1]);
  154. //var mainYbDto = Convert.ToDouble(items[2]);
  155. //var adjaYbDto = Convert.ToDouble(items[3]);
  156. //var mainX = Convert.ToDouble(items[7]);
  157. //var mainY = Convert.ToDouble(items[8]);
  158. //var mainZ = Convert.ToDouble(items[9]);
  159. //var adjaX = Convert.ToDouble(items[10]);
  160. //var adjaY = Convert.ToDouble(items[11]);
  161. //var adjaZ = Convert.ToDouble(items[12]);
  162. //var cgRes = new CgRes()
  163. //{
  164. // SigTime = DateTime.Now,
  165. // DtoSx = sxDto * 1e6,
  166. // DfoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  167. // SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
  168. // DtoCdb = xdDto * 1e6,
  169. // DfoCdb = 600 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  170. // SnrCdb = r.Next(22, 32) + Math.Round(r.NextDouble(), 1),
  171. // YbMain = mainYbDto * 1e6,
  172. // YbAdja = adjaYbDto * 1e6,
  173. // MainX = mainX,
  174. // MainY = mainY,
  175. // MainZ = mainZ,
  176. // AdjaX = adjaX,
  177. // AdjaY = adjaY,
  178. // AdjaZ = adjaZ,
  179. //};
  180. //db.CgRes.Add(cgRes);//参估结果入库
  181. //var res = PosApi.X2D1_POS(cgRes, listTx);
  182. //PosRes posRes = new PosRes()
  183. //{
  184. // SigTime = cgRes.SigTime,
  185. // CgResID = cgRes.ID,
  186. // TarName = "未知目标",
  187. // TsName = "tar2",
  188. // PosLon = res[0],
  189. // PosLat = res[1],
  190. // MirrLon = res[3],
  191. // MirrLat = res[4],
  192. //};
  193. //db.PosRes.Add(posRes);//定位结果入库
  194. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  195. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  196. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  197. double[] Zone = { -80, 80, -150, 150 };
  198. double target_dto = -0.010246009710722;
  199. double target_dfo = 1.595360344349182e+03;
  200. double ref_dto = 0.002823291225258;
  201. double ref_dfo = 1.132007974492508e+04;
  202. double fu1 = 3.1085e8;
  203. double fu2 = 2.95e8;
  204. double[] target_llh = new double[6];
  205. PosApi.TwoStar_DTFO_DW(main_sat, neigh_sat, Ref_Station_LLH, Zone, target_dto, target_dfo, ref_dto, ref_dfo, fu1, fu2, target_llh);
  206. PosRes posRes = new PosRes()
  207. {
  208. SigTime = DateTime.Now,
  209. CgResID = 1,
  210. TarName = "未知目标",
  211. TsName = "tar2",
  212. PosLon = target_llh[0],
  213. PosLat = target_llh[1],
  214. MirrLon = target_llh[3],
  215. MirrLat = target_llh[4],
  216. };
  217. db.PosRes.Add(posRes);//定位结果入库
  218. //更新定位结果UI列表和地图
  219. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  220. var ds = this.gridPos.DataSource as List<PosRes>;
  221. ds.Insert(0, posRes);
  222. this.Invoke(new Action(() =>
  223. {
  224. gridView1.RefreshData();
  225. mapControl1.AddPosItem(posRes);
  226. }));
  227. await Task.Delay(200);
  228. }
  229. }
  230. }
  231. private void DrawDtoLine()
  232. {
  233. try
  234. {
  235. var ids = gridView1.GetSelectedRows();
  236. if (ids.Length <= 0)
  237. {
  238. XtraMessageBox.Show("请选择需要绘制时差线的定位数据信息!");
  239. return;
  240. }
  241. var item = gridView1.GetRow(ids[0]) as PosRes;
  242. //List<TxInfo> listTx = new List<TxInfo>();
  243. //List<Model.SatInfo> listSat = new List<Model.SatInfo>();
  244. //CgRes cg;
  245. //using (RHDWContext db = new RHDWContext())
  246. //{
  247. // listTx = db.TxInfos.ToList();
  248. // listSat = db.SatInfos.ToList();
  249. // cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
  250. //}
  251. //if (cg == null)
  252. //{
  253. // XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]信息");
  254. // return;
  255. //}
  256. //var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  257. //var satNTx = listTx.Find(p => p.TxType == EnumTxType.AdjaSat);
  258. //var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  259. //var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  260. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  261. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  262. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  263. double[] Zone = { -80, 80, -150, 150 };
  264. double target_dto = -0.010246009710722;
  265. double ref_dto = 0.002823291225258;
  266. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  267. twoStartOption.MsEph = main_sat;
  268. twoStartOption.NsEph = neigh_sat;
  269. twoStartOption.RefGeod = Ref_Station_LLH;
  270. twoStartOption.TargetDto = target_dto * 1e6;
  271. twoStartOption.RefDto = ref_dto * 1e6;
  272. var tsDtoLine = DrawDtoLineHelper.DtoLineXZTwoStart(twoStartOption);
  273. mapControl1.DrawDtoPonit($"双星时差线", tsDtoLine);
  274. }
  275. catch (Exception ex)
  276. {
  277. Serilog.Log.Error("绘制时差线失败", ex);
  278. XtraMessageBox.Show($"绘制时差线失败,失败信息:{ex.Message}");
  279. }
  280. }
  281. private void DrawDfoLine()
  282. {
  283. try
  284. {
  285. var ids = gridView1.GetSelectedRows();
  286. if (ids.Length <= 0)
  287. {
  288. XtraMessageBox.Show("请选择需要绘制频差线的定位数据信息!");
  289. return;
  290. }
  291. var item = gridView1.GetRow(ids[0]) as PosRes;
  292. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  293. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  294. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  295. double[] Zone = { -80, 80, -150, 150 };
  296. double target_dfo = 1.595360344349182e+03;
  297. double ref_dfo = 1.132007974492508e+04;
  298. double fu1 = 3.1085e8;
  299. double fu2 = 2.95e8;
  300. DfoLineTwoStartOption twoStartOption = new DfoLineTwoStartOption();
  301. twoStartOption.MsEph = main_sat;
  302. twoStartOption.NsEph = neigh_sat;
  303. twoStartOption.RefGeod = Ref_Station_LLH;
  304. twoStartOption.TargetDfo = target_dfo;
  305. twoStartOption.RefDfo = ref_dfo;
  306. twoStartOption.fu1 = fu1;
  307. twoStartOption.fu2 = fu2;
  308. var tsDtoLine = DrawDtoLineHelper.DfoLineXZTwoStart(twoStartOption);
  309. mapControl1.DrawDtoPonit($"双星频差线", tsDtoLine);
  310. }
  311. catch (Exception ex)
  312. {
  313. Serilog.Log.Error("绘制频差线失败", ex);
  314. XtraMessageBox.Show($"绘制频差线失败,失败信息:{ex.Message}");
  315. }
  316. }
  317. private void DrawErrorEllipseDTFO()
  318. {
  319. try
  320. {
  321. var ids = gridView1.GetSelectedRows();
  322. if (ids.Length <= 0)
  323. {
  324. XtraMessageBox.Show("请选择需要绘制误差椭圆线的定位数据信息!");
  325. return;
  326. }
  327. var item = gridView1.GetRow(ids[0]) as PosRes;
  328. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  329. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  330. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  331. double fu1 = 3.1085e8;
  332. double fu2 = 2.95e8;
  333. ErrorEllipseDTFOTSOption twoStartOption = new ErrorEllipseDTFOTSOption();
  334. twoStartOption.MsEph = main_sat;
  335. twoStartOption.NsEph = neigh_sat;
  336. twoStartOption.RefGeod = Ref_Station_LLH;
  337. twoStartOption.SelectPoint = new double[3] { item.PosLon,item.PosLat,0 };
  338. twoStartOption.DtoErr =1;
  339. twoStartOption.DfoErr =1;
  340. twoStartOption.EphPosErr = 1;
  341. twoStartOption.EphVelErr = 1;
  342. twoStartOption.fu1 = fu1;
  343. twoStartOption.fu2 = fu2;
  344. var points = ErrEllipseHelper.ErrorEllipseDTFOTwoStart(twoStartOption);
  345. mapControl1.DrawDtoPonit($"双星误差椭圆线", points);
  346. }
  347. catch (Exception ex)
  348. {
  349. Serilog.Log.Error("绘制误差椭圆线失败", ex);
  350. XtraMessageBox.Show($"绘制误差椭圆线失败,失败信息:{ex.Message}");
  351. }
  352. }
  353. public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
  354. {
  355. var dots = line.Line;
  356. if (dots.Count < 30) return line;
  357. var tmp = dots.Count / 30;
  358. var newLine = new XdCxRhDW.App.DTO.MapLine();
  359. for (int i = 0; i < dots.Count; i += tmp)
  360. {
  361. newLine.Line.Add(dots[i]);
  362. }
  363. if (!newLine.Line.Contains(dots.Last()))
  364. newLine.Line.Add(dots.Last());
  365. return newLine;
  366. }
  367. }
  368. }