X1D1GDOPParam.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 XdCxRhDW.Repostory;
  8. using XdCxRhDW.Entity;
  9. using XdCxRhDW.Api;
  10. using System.Drawing;
  11. using DevExpress.XtraCharts.Design;
  12. using System.Runtime.ConstrainedExecution;
  13. using XdCxRhDW.Dto;
  14. using System.Configuration;
  15. using XdCxRhDW.Framework;
  16. namespace XdCxRhDW.App.UserControl
  17. {
  18. public partial class X1D1GDOPParam : DevExpress.XtraEditors.XtraUserControl
  19. {
  20. public MapControl mapControl1;
  21. public GDOP星地一星一地接口 Model => new GDOP星地一星一地接口()
  22. {
  23. EphMain = ucEphXYZMain.EphParam(),
  24. CapTime = txtCapTime.DateTime,
  25. CDBStation = txtStationLocation1.GetLonLat(),
  26. CXStation = txtCXStation.GetLonLat(),
  27. RefStation = txtRefLocation1.GetLonLat(),
  28. DtousErr = Convert.ToDouble(txtDtousErr1.Text),
  29. SatLocErr = Convert.ToDouble(txtSatLocErr1.Text),
  30. CXErr = Convert.ToDouble(txtCxErr.Text),
  31. };
  32. private EnumPosResType PosResType;
  33. public X1D1GDOPParam(PosRes item)
  34. {
  35. InitializeComponent();
  36. this.layoutControl1.UseDefault();
  37. txtCapTime.UseDefault();
  38. txtStationLocation1.UseDoubleClickToSelectAll();
  39. txtRefLocation1.UseDoubleClickToSelectAll();
  40. txtCXStation.UseDoubleClickToSelectAll();
  41. this.txtCapTime.DateTime = item.SigTime;
  42. this.txtDtousErr1.EditValue = 1;
  43. this.txtSatLocErr1.EditValue = 10000;
  44. this.txtCxErr.EditValue = 0.001;
  45. PosResType = item.PosResType;
  46. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  47. {
  48. var cg = db?.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
  49. var station = db?.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
  50. if (station != null)
  51. {
  52. this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  53. this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
  54. this.txtCXStation.Text = $"{station.CxLon},{station.CxLat}";
  55. }
  56. if (cg != null)
  57. {
  58. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  59. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, 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 (!txtStationLocation1.CheckLonLat(dxErrorProvider, "超短波"))
  71. {
  72. return false;
  73. }
  74. if (!txtCXStation.CheckLonLat(dxErrorProvider, "测向站"))
  75. {
  76. return false;
  77. }
  78. if (!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. if (!txtCxErr.CheckDouble(dxErrorProvider, "测向误差"))
  91. {
  92. return false;
  93. }
  94. return true;
  95. }
  96. private void btnOK_Click(object sender, EventArgs e)
  97. {
  98. if (!ParamValidate()) { return; }
  99. try
  100. {
  101. mapControl1.ClearMap();
  102. bool useNewGDOP = AppConfigHelper.Get("UseNewGDOP", true);
  103. if (!useNewGDOP)
  104. {
  105. var data = GdopHelper.Gdop1Sat1DByXyz(Model.EphMain, Model.CDBStation, Model.CXStation,
  106. Model.DtousErr, Model.CXErr, Model.SatLocErr, Model.RefStation);
  107. if (data.Count == 0)
  108. {
  109. DxHelper.MsgBoxHelper.ShowInfo($"绘制{PosResType.GetEnumDisplayName()}GDOP没有{GdopParam.误差配置.误差距离km.Max()}公里以内的误差!");
  110. return;
  111. }
  112. foreach (var errLins in data)//画GDOP
  113. {
  114. mapControl1.DrawGdopLineTwo(errLins.ErrDistanceKm, errLins.MapDots, 1);
  115. }
  116. }
  117. else
  118. {
  119. var data = GdopHelper.Gdop1Sat1DByXyzNew(Model.EphMain, Model.CDBStation, Model.CXStation,
  120. Model.DtousErr, Model.CXErr, Model.SatLocErr, Model.RefStation);
  121. if (data.Count == 0)
  122. {
  123. DxHelper.MsgBoxHelper.ShowInfo($"绘制{PosResType.GetEnumDisplayName()}GDOP没有{GdopParam.误差配置.误差距离km.Max()}公里以内的误差!");
  124. return;
  125. }
  126. List<MapPolyline> polylines = new List<MapPolyline>();
  127. for (int i = 0; i < data.Count; i++)
  128. {
  129. var errLins = data[i];
  130. var mapline = mapControl1.GetLine(errLins.ErrDistanceKm, errLins.MapDots);
  131. if (mapline == null)
  132. {
  133. continue;
  134. }
  135. polylines.Add(mapline);
  136. }
  137. mapControl1.DrawDtoLine(polylines);
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. DxHelper.MsgBoxHelper.ShowError($"绘制{PosResType.GetEnumDisplayName()}GDOP失败,{ex.Message}");
  143. }
  144. }
  145. private void btnClose_Click(object sender, EventArgs e)
  146. {
  147. DxHelper.PopupHelper.HidePopup(this);
  148. }
  149. private async void btnEphCalc_Click(object sender, EventArgs e)
  150. {
  151. dxErrorProvider.ClearErrors();
  152. if (txtCapTime.DateTime == DateTime.MinValue)
  153. {
  154. dxErrorProvider.SetError(txtCapTime, "信号时间不能为空!");
  155. return;
  156. }
  157. var sigTime = txtCapTime.DateTime;
  158. try
  159. {
  160. var mainCode = ucEphXYZMain.GetSatCode();
  161. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  162. if (mainxlInfo == null)
  163. {
  164. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  165. return;
  166. }
  167. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  168. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  169. ucEphXYZMain.SetParam("主星", mainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z, maineph.data.VX, maineph.data.VY, maineph.data.VZ), Color.Red);
  170. }
  171. catch (Exception ex)
  172. {
  173. Serilog.Log.Error(ex, $"手动推算{PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  174. DxHelper.MsgBoxHelper.ShowError($"手动推算{PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  175. }
  176. }
  177. }
  178. public class GDOP星地一星一地接口
  179. {
  180. /// <summary>
  181. /// 主星星历 x y z vx vy vz
  182. /// </summary>
  183. public double[] EphMain { get; set; }
  184. /// <summary>
  185. /// 采集时刻
  186. /// </summary>
  187. public DateTime CapTime { get; set; }
  188. /// <summary>
  189. /// 超短接收站-经度 纬度 高度
  190. /// </summary>
  191. public double[] CDBStation { get; set; }
  192. /// <summary>
  193. /// 参考站位置-经度 纬度 高度
  194. /// </summary>
  195. public double[] RefStation { get; set; }
  196. /// <summary>
  197. /// 测向站位置-经度 纬度 高度
  198. /// </summary>
  199. public double[] CXStation { get; set; }
  200. /// <summary>
  201. /// 时差误差(单位us)
  202. /// </summary>
  203. public double DtousErr { get; set; } = 1;
  204. /// <summary>
  205. /// 星历位置误差(单位米)
  206. /// </summary>
  207. public double SatLocErr { get; set; } = 10000;
  208. /// <summary>
  209. /// 测向误差(单位°)
  210. /// </summary>
  211. public double CXErr { get; set; } = 0.01;
  212. }
  213. }