CtrlPosXz.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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.DTO;
  25. using XdCxRhDW.App.UserControl;
  26. using XzXdDw.App.Api;
  27. using XzXdDw.App.Api.低轨GDOP误差椭圆;
  28. using XzXdDw.App.EFContext;
  29. using XzXdDw.App.Model;
  30. namespace XzXdDw.App.UserControl
  31. {
  32. /// <summary>
  33. /// 星地定位
  34. /// </summary>
  35. public partial class CtrlPosXz : DevExpress.XtraEditors.XtraUserControl
  36. {
  37. /// <summary>
  38. /// 时差初值 范围计算
  39. /// </summary>
  40. DtSXLParam dtsxlctrl = null;
  41. public CtrlPosXz()
  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. using (RHDWContext db = new RHDWContext())
  60. {
  61. foreach (var id in ids)
  62. {
  63. var item = gridView1.GetRow(id) as PosRes;
  64. var delItem = await db.PosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  65. if (delItem != null)
  66. {
  67. db.PosRes.Remove(delItem);
  68. }
  69. }
  70. await db.SaveChangesAsync();
  71. }
  72. gridView1.DeleteSelectedRows();
  73. }
  74. catch (Exception ex)
  75. {
  76. Serilog.Log.Error("删除结果失败", ex);
  77. XtraMessageBox.Show("删除结果失败");
  78. }
  79. })
  80. .AddMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), LoadTestData)
  81. .AddMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), () => stoped = true);
  82. mapControl1.UseDefalutOptions()
  83. //.UseCluster()//定位点使用内置聚合
  84. .UseClearAll()
  85. .UseDistanceLine()
  86. .UseMarkDot()
  87. //.UseExportImg()
  88. //.UseExportXlsx()
  89. //.UseExportCsv()
  90. .UseDrawRect(rect =>
  91. {
  92. if (dtsxlctrl != null)
  93. {
  94. dtsxlctrl.rect = rect;
  95. }
  96. });
  97. //MapMenu为地图瓦片上右键菜单
  98. //AddPosMenu为定位点上右键菜单
  99. //RectMenu为框选的区域上右键菜单
  100. mapControl1.AddMapMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), (lon, lat) => LoadTestData())
  101. .AddMapMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), (lon, lat) => stoped = true)
  102. .AddMapMenu("GDOP分析", SvgHelper.LoadFromFile("Image\\GDOP.svg"), (lon, lat) =>
  103. {
  104. //参考星地的
  105. })
  106. .AddPosMenu<PosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
  107. {
  108. //参考星地的
  109. })
  110. .AddRectMenu<PosRes>("时差初值预估", SvgHelper.LoadFromFile("Image\\初值预估.svg"), items =>
  111. {
  112. var rect = mapControl1.GetCurrentRect();
  113. if (dtsxlctrl == null)
  114. {
  115. dtsxlctrl = new DtSXLParam();
  116. }
  117. dtsxlctrl.rect = rect;
  118. PopupHelper.ShowPopup(dtsxlctrl, mapControl1, mapControl1.Width / 4);
  119. });
  120. //查询已有的定位记录
  121. using (RHDWContext db = new RHDWContext())
  122. {
  123. List<PosRes> list = await db.PosRes.ToListAsync();
  124. this.gridPos.DataSource = list;
  125. mapControl1.SetPosDataSource(list);
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. Serilog.Log.Error("查询定位结果失败", ex);
  131. XtraMessageBox.Show("查询定位结果失败");
  132. }
  133. }
  134. bool stoped = false;
  135. private async void LoadTestData()
  136. {
  137. stoped = false;
  138. //在列表控件中全选+右键可以删除所有测试结果
  139. using (RHDWContext db = new RHDWContext())
  140. {
  141. var listTx = db.TxInfos.ToList();
  142. var lines = File.ReadAllLines("Simulation_Data2023.dat");
  143. Random r = new Random();
  144. foreach (var item in lines)
  145. {
  146. if (stoped) break;
  147. //var items = item.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  148. //var sxDto = Convert.ToDouble(items[0]);
  149. //var xdDto = Convert.ToDouble(items[1]);
  150. //var mainYbDto = Convert.ToDouble(items[2]);
  151. //var adjaYbDto = Convert.ToDouble(items[3]);
  152. //var mainX = Convert.ToDouble(items[7]);
  153. //var mainY = Convert.ToDouble(items[8]);
  154. //var mainZ = Convert.ToDouble(items[9]);
  155. //var adjaX = Convert.ToDouble(items[10]);
  156. //var adjaY = Convert.ToDouble(items[11]);
  157. //var adjaZ = Convert.ToDouble(items[12]);
  158. //var cgRes = new CgRes()
  159. //{
  160. // SigTime = DateTime.Now,
  161. // DtoSx = sxDto * 1e6,
  162. // DfoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  163. // SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
  164. // DtoCdb = xdDto * 1e6,
  165. // DfoCdb = 600 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  166. // SnrCdb = r.Next(22, 32) + Math.Round(r.NextDouble(), 1),
  167. // YbMain = mainYbDto * 1e6,
  168. // YbAdja = adjaYbDto * 1e6,
  169. // MainX = mainX,
  170. // MainY = mainY,
  171. // MainZ = mainZ,
  172. // AdjaX = adjaX,
  173. // AdjaY = adjaY,
  174. // AdjaZ = adjaZ,
  175. //};
  176. //db.CgRes.Add(cgRes);//参估结果入库
  177. //var res = PosApi.X2D1_POS(cgRes, listTx);
  178. //PosRes posRes = new PosRes()
  179. //{
  180. // SigTime = cgRes.SigTime,
  181. // CgResID = cgRes.ID,
  182. // TarName = "未知目标",
  183. // TsName = "tar2",
  184. // PosLon = res[0],
  185. // PosLat = res[1],
  186. // MirrLon = res[3],
  187. // MirrLat = res[4],
  188. //};
  189. //db.PosRes.Add(posRes);//定位结果入库
  190. double[] main_sat = { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.158046 };
  191. double[] neigh_sat = { -4629566.829, 4978943.601, 1487242.596, -4890.245126, -3337.702797, -4031.339975 };
  192. double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
  193. double[] Zone = { -80, 80, -150, 150 };
  194. double target_dto = -0.010246009710722;
  195. double target_dfo = 1.595360344349182e+03;
  196. double ref_dto = 0.002823291225258;
  197. double ref_dfo = 1.132007974492508e+04;
  198. double fu1 = 3.1085e8;
  199. double fu2 = 2.95e8;
  200. double[] target_llh = new double[6];
  201. PosApi.TwoStar_DTFO_DW(main_sat, neigh_sat, Ref_Station_LLH, Zone, target_dto, target_dfo, ref_dto, ref_dfo, fu1, fu2, target_llh);
  202. PosRes posRes = new PosRes()
  203. {
  204. SigTime = DateTime.Now,
  205. CgResID = 1,
  206. TarName = "未知目标",
  207. TsName = "tar2",
  208. PosLon = target_llh[0],
  209. PosLat = target_llh[1],
  210. MirrLon = target_llh[3],
  211. MirrLat = target_llh[4],
  212. };
  213. db.PosRes.Add(posRes);//定位结果入库
  214. //更新定位结果UI列表和地图
  215. var currentTask = gridView1.GetFocusedRow() as TaskInfo;
  216. var ds = this.gridPos.DataSource as List<PosRes>;
  217. ds.Insert(0, posRes);
  218. this.Invoke(new Action(() =>
  219. {
  220. gridView1.RefreshData();
  221. mapControl1.AddPosItem(posRes);
  222. }));
  223. await Task.Delay(200);
  224. }
  225. }
  226. }
  227. public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
  228. {
  229. var dots = line.Line;
  230. if (dots.Count < 30) return line;
  231. var tmp = dots.Count / 30;
  232. var newLine = new XdCxRhDW.App.DTO.MapLine();
  233. for (int i = 0; i < dots.Count; i += tmp)
  234. {
  235. newLine.Line.Add(dots[i]);
  236. }
  237. if (!newLine.Line.Contains(dots.Last()))
  238. newLine.Line.Add(dots.Last());
  239. return newLine;
  240. }
  241. }
  242. }