X3GDOPParam.cs 8.1 KB

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