X2D1GDOPParam.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using DevExpress.XtraMap;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. using DxHelper;
  8. using XdCxRhDW.Repostory;
  9. using XdCxRhDW.Entity;
  10. using XdCxRhDW.Api;
  11. using System.Drawing;
  12. using DevExpress.Utils.About;
  13. using DevExpress.XtraEditors.DXErrorProvider;
  14. namespace XdCxRhDW.App.UserControl
  15. {
  16. public partial class X2D1GDOPParam : DevExpress.XtraEditors.XtraUserControl
  17. {
  18. public MapControl mapControl1;
  19. public GDOP星地两星一地接口 Model => new GDOP星地两星一地接口()
  20. {
  21. EphMain = ucEphXYZMain.EphParam(),
  22. EphAdja = ucEphXYZAdja.EphParam(),
  23. CapTime = txtCapTime.DateTime,
  24. CDBStation = txtStationLocation1.GetLonLat(),
  25. RefStation = PosResType == EnumPosResType.X2D1NoRef ? new double[3] { 0, 0, 0 } : txtRefLocation1.GetLonLat(),
  26. DtousErr = Convert.ToDouble(txtDtousErr1.Text),
  27. SatLocErr = Convert.ToDouble(txtSatLocErr1.Text),
  28. };
  29. private EnumPosResType PosResType;
  30. public X2D1GDOPParam(PosRes item)
  31. {
  32. InitializeComponent();
  33. this.layoutControl1.UseDefault();
  34. txtCapTime.UseDefault();
  35. txtStationLocation1.UseDoubleClickToSelectAll();
  36. txtRefLocation1.UseDoubleClickToSelectAll();
  37. this.txtCapTime.DateTime = item.SigTime;
  38. this.txtDtousErr1.EditValue = 1;
  39. this.txtSatLocErr1.EditValue = 10000;
  40. PosResType = item.PosResType;
  41. if (PosResType == EnumPosResType.X2D1NoRef)
  42. {
  43. layoutControlItem14.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  44. }
  45. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  46. {
  47. var cg = db?.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
  48. var station = db?.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
  49. if (station != null)
  50. {
  51. this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  52. this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
  53. }
  54. if (cg != null)
  55. {
  56. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  57. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  58. var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  59. ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
  60. }
  61. }
  62. }
  63. private bool ParamValidate()
  64. {
  65. dxErrorProvider.ClearErrors();
  66. if (!ucEphXYZMain.CheckEph(dxErrorProvider))
  67. {
  68. return false;
  69. }
  70. if (!ucEphXYZAdja.CheckEph(dxErrorProvider))
  71. {
  72. return false;
  73. }
  74. if (!txtStationLocation1.CheckLonLat(dxErrorProvider, "超短波"))
  75. {
  76. return false;
  77. }
  78. if (PosResType == EnumPosResType.X2D1&&!txtRefLocation1.CheckLonLat(dxErrorProvider, "参考站"))
  79. {
  80. return false;
  81. }
  82. if (!txtDtousErr1.CheckDouble(dxErrorProvider, "时差误差"))
  83. {
  84. return false;
  85. }
  86. if (!txtSatLocErr1.CheckDouble(dxErrorProvider, "星历位置误差"))
  87. {
  88. return false;
  89. }
  90. return true;
  91. }
  92. private void btnOK_Click(object sender, EventArgs e)
  93. {
  94. if (!ParamValidate()) { return; }
  95. try
  96. {
  97. mapControl1.ClearMap();
  98. var data = GdopHelper.Gdop2Sat1DByXyz(Model.EphMain, Model.EphAdja, Model.CDBStation
  99. , Model.DtousErr, Model.SatLocErr, PosResType == EnumPosResType.X2D1NoRef ? null : Model.RefStation);
  100. if (data == null)
  101. {
  102. return;
  103. }
  104. foreach (var errLins in data)//画GDOP
  105. {
  106. var mapDots = errLins.MapDots.Select(p => p).Select(p => (p.Lon, p.Lat));
  107. mapControl1.DrawGdopLineTwo(errLins.ErrDistanceKm, mapDots, 1);
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. DxHelper.MsgBoxHelper.ShowError($"绘制{PosResType.GetEnumDisplayName()}GDOP失败,{ex.Message}");
  113. }
  114. }
  115. private void btnClose_Click(object sender, EventArgs e)
  116. {
  117. DxHelper.PopupHelper.HidePopup(this);
  118. }
  119. private async void btnEphCalc_Click(object sender, EventArgs e)
  120. {
  121. dxErrorProvider.ClearErrors();
  122. if (txtCapTime.DateTime == DateTime.MinValue)
  123. {
  124. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  125. return;
  126. }
  127. var sigTime = txtCapTime.DateTime;
  128. try
  129. {
  130. var mainCode = ucEphXYZMain.GetSatCode();
  131. var adjaCode = ucEphXYZAdja.GetSatCode();
  132. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  133. if (mainxlInfo == null)
  134. {
  135. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  136. return;
  137. }
  138. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  139. ucEphXYZMain.SetParam("主星", mainCode, (maineph.X, maineph.Y, maineph.Z, maineph.VX, maineph.VY, maineph.VZ), Color.Red);
  140. var adjaxlInfo = await XlRepository.GetLatestAsync(adjaCode, sigTime);
  141. if (adjaxlInfo == null)
  142. {
  143. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{adjaCode}未找到对应的星历信息,请导入星历");
  144. return;
  145. }
  146. var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc());
  147. ucEphXYZAdja.SetParam("邻星", adjaCode, (adjaeph.X, adjaeph.Y, adjaeph.Z, adjaeph.VX, adjaeph.VY, adjaeph.VZ), Color.Red);
  148. }
  149. catch (Exception ex)
  150. {
  151. Serilog.Log.Error(ex, $"手动推算{PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  152. DxHelper.MsgBoxHelper.ShowError($"手动推算{PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  153. }
  154. }
  155. }
  156. public class GDOP星地两星一地接口
  157. {
  158. /// <summary>
  159. /// 主星x y z vx vy vz
  160. /// </summary>
  161. public double[] EphMain { get; set; }
  162. /// <summary>
  163. /// 邻星x y z vx vy vz
  164. /// </summary>
  165. public double[] EphAdja { get; set; }
  166. /// <summary>
  167. /// 采集时刻
  168. /// </summary>
  169. public DateTime CapTime { get; set; }
  170. /// <summary>
  171. /// 超短接收站-经度 纬度 高度
  172. /// </summary>
  173. public double[] CDBStation { get; set; }
  174. /// <summary>
  175. /// 参考站位置-经度 纬度 高度
  176. /// </summary>
  177. public double[] RefStation { get; set; }
  178. /// <summary>
  179. /// 时差误差(单位us)
  180. /// </summary>
  181. public double DtousErr { get; set; } = 1;
  182. /// <summary>
  183. /// 星历位置误差(单位米)
  184. /// </summary>
  185. public double SatLocErr { get; set; } = 10000;
  186. /// <summary>
  187. /// 定位类型
  188. /// </summary>
  189. public EnumPosResType PosResType { get; set; }
  190. }
  191. }