X3GDOPParam.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 DW5S.Repostory;
  9. using DW5S.Entity;
  10. using DW5S.KxcApi;
  11. using System.Drawing;
  12. using DevExpress.XtraEditors.DXErrorProvider;
  13. using DW5S.DTO;
  14. using System.Configuration;
  15. using Microsoft.Extensions.Logging;
  16. namespace DW5S.App.UserControl
  17. {
  18. public partial class X3GDOPParam : DevExpress.XtraEditors.XtraUserControl
  19. {
  20. [Autowired]
  21. private readonly ILogger logger;
  22. [Autowired]
  23. private readonly UnitOfWork unitOfWork;
  24. public MapControl mapControl1;
  25. public X3GDOP星地接口 Model => new X3GDOP星地接口()
  26. {
  27. EphMain = ucEphXYZMain.EphParam(),
  28. EphAdja1 = ucEphXYZAdja1.EphParam(),
  29. EphAdja2 = ucEphXYZAdja2.EphParam(),
  30. CapTime = txtCapTime.DateTime,
  31. RefStation = PosResType == EnumPosResType.X3NoRef ? new double[3] { 0, 0, 0 } : txtRefLocation1.GetLonLat(),
  32. DtousErr = Convert.ToDouble(txtDtousErr1.Text),
  33. SatLocErr = Convert.ToDouble(txtSatLocErr1.Text),
  34. };
  35. private EnumPosResType PosResType;
  36. public X3GDOPParam(PosRes item)
  37. {
  38. InitializeComponent();
  39. this.layoutControl1.UseDefault();
  40. txtCapTime.UseDefault();
  41. txtRefLocation1.UseDoubleClickToSelectAll();
  42. this.txtCapTime.DateTime = item.SigTime;
  43. this.txtDtousErr1.EditValue = 1;
  44. this.txtSatLocErr1.EditValue = 10000;
  45. PosResType = item.PosResType;
  46. if (PosResType == EnumPosResType.X3NoRef)
  47. {
  48. layoutControlItem14.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  49. }
  50. var repsCg = unitOfWork.Of<CgRes>();
  51. var repsStation = unitOfWork.Of<StationRes>();
  52. var cg = repsCg.FirstOrDefaultAsync(m => m.Id == item.CgResID).Result;
  53. var station = repsStation.FirstOrDefaultAsync(m => m.Id == item.StationResID).Result;
  54. if (station != null)
  55. {
  56. this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
  57. }
  58. if (cg != null)
  59. {
  60. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  61. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  62. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  63. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  64. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  65. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  66. }
  67. }
  68. private void btnClose_Click(object sender, EventArgs e)
  69. {
  70. DxHelper.PopupHelper.HidePopup(this);
  71. }
  72. private bool ParamValidate()
  73. {
  74. if (!ucEphXYZMain.CheckEph(dxErrorProvider))
  75. {
  76. return false;
  77. }
  78. if (!ucEphXYZAdja1.CheckEph(dxErrorProvider))
  79. {
  80. return false;
  81. }
  82. if (!ucEphXYZAdja2.CheckEph(dxErrorProvider))
  83. {
  84. return false;
  85. }
  86. if (PosResType == EnumPosResType.X3 && !txtRefLocation1.CheckLonLat(dxErrorProvider, "参考站"))
  87. {
  88. return false;
  89. }
  90. if (!txtDtousErr1.CheckDouble(dxErrorProvider, "时差误差"))
  91. {
  92. return false;
  93. }
  94. if (!txtSatLocErr1.CheckDouble(dxErrorProvider, "星历位置误差"))
  95. {
  96. return false;
  97. }
  98. return true;
  99. }
  100. private void btnX1D2_Click(object sender, EventArgs e)
  101. {
  102. if (!ParamValidate()) { return; }
  103. try
  104. {
  105. mapControl1.ClearMap();
  106. var data = GdopHelper.Gdop3SatByXyzNew(Model.EphMain, Model.EphAdja1, Model.EphAdja2
  107. , Model.DtousErr, Model.SatLocErr, PosResType == EnumPosResType.X3NoRef ? null : Model.RefStation);
  108. if (data.Count == 0)
  109. {
  110. DxHelper.MsgBoxHelper.ShowInfo($"绘制{PosResType.GetEnumDisplayName()}GDOP没有{GdopParam.误差配置.误差距离km.Max()}公里以内的误差!");
  111. return;
  112. }
  113. List<MapPolyline> polylines = new List<MapPolyline>();
  114. for (int i = 0; i < data.Count; i++)
  115. {
  116. var errLins = data[i];
  117. var mapline = mapControl1.GetLine(errLins.ErrDistanceKm, errLins.MapDots);
  118. if (mapline == null)
  119. {
  120. continue;
  121. }
  122. polylines.Add(mapline);
  123. }
  124. mapControl1.DrawDtoLine(polylines);
  125. }
  126. catch (Exception ex)
  127. {
  128. string msg = $"绘制{PosResType.GetEnumDisplayName()}GDOP失败";
  129. logger.LogError(ex, msg);
  130. DxHelper.MsgBoxHelper.ShowError(msg);
  131. }
  132. }
  133. private async void btnEphCalc_Click(object sender, EventArgs e)
  134. {
  135. dxErrorProvider.ClearErrors();
  136. if (txtCapTime.DateTime == DateTime.MinValue)
  137. {
  138. dxErrorProvider.SetError(txtCapTime, "信号时间不能为空!");
  139. return;
  140. }
  141. var sigTime = txtCapTime.DateTime;
  142. try
  143. {
  144. var mainCode = ucEphXYZMain.GetSatCode();
  145. var adja1Code = ucEphXYZAdja1.GetSatCode();
  146. var adja2Code = ucEphXYZAdja2.GetSatCode();
  147. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  148. var mainxlInfo = await repsXl.GetLatestAsync(mainCode, sigTime);
  149. if (mainxlInfo == null)
  150. {
  151. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  152. return;
  153. }
  154. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  155. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  156. ucEphXYZMain.SetParam("主星", mainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z, maineph.data.VX, maineph.data.VY, maineph.data.VZ), Color.Red);
  157. var adja1xlInfo = await repsXl.GetLatestAsync(adja1Code, sigTime);
  158. if (adja1xlInfo == null)
  159. {
  160. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{adja1Code}未找到对应的星历信息,请导入星历");
  161. return;
  162. }
  163. XlCalcDto = new XlCalcDto() { tleStr = adja1xlInfo.TwoLine, SigTime = sigTime };
  164. var adja1eph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  165. ucEphXYZAdja1.SetParam("邻星1", adja1Code, (adja1eph.data.X, adja1eph.data.Y, adja1eph.data.Z, adja1eph.data.VX, adja1eph.data.VY, adja1eph.data.VZ), Color.Red);
  166. var adja2xlInfo = await repsXl.GetLatestAsync(adja2Code, sigTime);
  167. if (adja2xlInfo == null)
  168. {
  169. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{adja2Code}未找到对应的星历信息,请导入星历");
  170. return;
  171. }
  172. XlCalcDto = new XlCalcDto() { tleStr = adja2xlInfo.TwoLine, SigTime = sigTime };
  173. var adja2eph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  174. ucEphXYZAdja2.SetParam("邻星2", adja2Code, (adja2eph.data.X, adja2eph.data.Y, adja2eph.data.Z, adja2eph.data.VX, adja2eph.data.VY, adja2eph.data.VZ), Color.Red);
  175. }
  176. catch (Exception ex)
  177. {
  178. string msg = $"手动推算{PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}";
  179. logger.LogError(ex, msg);
  180. DxHelper.MsgBoxHelper.ShowError(msg);
  181. }
  182. }
  183. }
  184. public class X3GDOP星地接口
  185. {
  186. /// <summary>
  187. /// 主星星历x y z vx vy vz
  188. /// </summary>
  189. public double[] EphMain { get; set; }
  190. /// <summary>
  191. /// 邻星1星历x y z vx vy vz
  192. /// </summary>
  193. public double[] EphAdja1 { get; set; }
  194. /// <summary>
  195. /// 邻星2星历x y z vx vy vz
  196. /// </summary>
  197. public double[] EphAdja2 { get; set; }
  198. /// <summary>
  199. /// 采集时刻
  200. /// </summary>
  201. public DateTime CapTime { get; set; }
  202. /// <summary>
  203. /// 参考站位置-经度 纬度 高度
  204. /// </summary>
  205. public double[] RefStation { get; set; }
  206. /// <summary>
  207. /// 时差误差(单位us)
  208. /// </summary>
  209. public double DtousErr { get; set; } = 1;
  210. /// <summary>
  211. /// 星历位置误差(单位米)
  212. /// </summary>
  213. public double SatLocErr { get; set; } = 10000;
  214. }
  215. }