X2D1GDOPParam.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.Utils.About;
  13. using DevExpress.XtraEditors.DXErrorProvider;
  14. using DW5S.DTO;
  15. using System.Configuration;
  16. using Serilog;
  17. using DW5S.Service;
  18. namespace DW5S.App.UserControl
  19. {
  20. public partial class X2D1GDOPParam : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. public MapControl mapControl1;
  23. public GDOP星地两星一地接口 Model => new GDOP星地两星一地接口()
  24. {
  25. EphMain = ucEphXYZMain.EphParam(),
  26. EphAdja = ucEphXYZAdja.EphParam(),
  27. CapTime = txtCapTime.DateTime,
  28. CDBStation = txtStationLocation1.GetLonLat(),
  29. RefStation = PosResType == EnumPosResType.X2D1NoRef ? new double[3] { 0, 0, 0 } : txtRefLocation1.GetLonLat(),
  30. DtousErr = Convert.ToDouble(txtDtousErr1.Text),
  31. SatLocErr = Convert.ToDouble(txtSatLocErr1.Text),
  32. };
  33. private EnumPosResType PosResType;
  34. public X2D1GDOPParam(PosRes item)
  35. {
  36. InitializeComponent();
  37. this.layoutControl1.UseDefault();
  38. txtCapTime.UseDefault();
  39. txtStationLocation1.UseDoubleClickToSelectAll();
  40. txtRefLocation1.UseDoubleClickToSelectAll();
  41. this.txtCapTime.DateTime = item.SigTime;
  42. this.txtDtousErr1.EditValue = 1;
  43. this.txtSatLocErr1.EditValue = 10000;
  44. PosResType = item.PosResType;
  45. if (PosResType == EnumPosResType.X2D1NoRef)
  46. {
  47. layoutControlItem14.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  48. }
  49. var unitOfWork = IocContainer.UnitOfWork;
  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.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  57. this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
  58. }
  59. if (cg != null)
  60. {
  61. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  62. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  63. var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  64. ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
  65. }
  66. }
  67. private bool ParamValidate()
  68. {
  69. dxErrorProvider.ClearErrors();
  70. if (!ucEphXYZMain.CheckEph(dxErrorProvider))
  71. {
  72. return false;
  73. }
  74. if (!ucEphXYZAdja.CheckEph(dxErrorProvider))
  75. {
  76. return false;
  77. }
  78. if (!txtStationLocation1.CheckLonLat(dxErrorProvider, "超短波"))
  79. {
  80. return false;
  81. }
  82. if (PosResType == EnumPosResType.X2D1 && !txtRefLocation1.CheckLonLat(dxErrorProvider, "参考站"))
  83. {
  84. return false;
  85. }
  86. if (!txtDtousErr1.CheckDouble(dxErrorProvider, "时差误差"))
  87. {
  88. return false;
  89. }
  90. if (!txtSatLocErr1.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. var data = GdopHelper.Gdop2Sat1DByXyzNew(Model.EphMain, Model.EphAdja, Model.CDBStation
  103. , Model.DtousErr, Model.SatLocErr, PosResType == EnumPosResType.X2D1NoRef ? null : Model.RefStation);
  104. if (data.Count == 0)
  105. {
  106. DxHelper.MsgBoxHelper.ShowInfo($"绘制{PosResType.GetEnumDisplayName()}GDOP没有{GdopParam.误差配置.误差距离km.Max()}公里以内的误差!");
  107. return;
  108. }
  109. List<MapPolyline> polylines = new List<MapPolyline>();
  110. for (int i = 0; i < data.Count; i++)
  111. {
  112. var errLins = data[i];
  113. var mapline = mapControl1.GetLine(errLins.ErrDistanceKm, errLins.MapDots);
  114. if (mapline == null)
  115. {
  116. continue;
  117. }
  118. polylines.Add(mapline);
  119. }
  120. mapControl1.DrawDtoLine(polylines);
  121. }
  122. catch (Exception ex)
  123. {
  124. string msg = $"绘制{PosResType.GetEnumDisplayName()}GDOP失败";
  125. IocContainer.Logger.Error(ex, msg);
  126. DxHelper.MsgBoxHelper.ShowError(msg);
  127. }
  128. }
  129. private void btnClose_Click(object sender, EventArgs e)
  130. {
  131. DxHelper.PopupHelper.HidePopup(this);
  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 adjaCode = ucEphXYZAdja.GetSatCode();
  146. var unitOfWork = IocContainer.UnitOfWork;
  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 adjaxlInfo = await repsXl.GetLatestAsync(adjaCode, sigTime);
  158. if (adjaxlInfo == null)
  159. {
  160. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{adjaCode}未找到对应的星历信息,请导入星历");
  161. return;
  162. }
  163. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  164. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  165. ucEphXYZAdja.SetParam("邻星", adjaCode, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z, adjaeph.data.VX, adjaeph.data.VY, adjaeph.data.VZ), Color.Red);
  166. }
  167. catch (Exception ex)
  168. {
  169. string msg = $"手动推算{PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}";
  170. IocContainer.Logger.Error(ex, msg);
  171. DxHelper.MsgBoxHelper.ShowError(msg);
  172. }
  173. }
  174. }
  175. public class GDOP星地两星一地接口
  176. {
  177. /// <summary>
  178. /// 主星x y z vx vy vz
  179. /// </summary>
  180. public double[] EphMain { get; set; }
  181. /// <summary>
  182. /// 邻星x y z vx vy vz
  183. /// </summary>
  184. public double[] EphAdja { get; set; }
  185. /// <summary>
  186. /// 采集时刻
  187. /// </summary>
  188. public DateTime CapTime { get; set; }
  189. /// <summary>
  190. /// 超短接收站-经度 纬度 高度
  191. /// </summary>
  192. public double[] CDBStation { get; set; }
  193. /// <summary>
  194. /// 参考站位置-经度 纬度 高度
  195. /// </summary>
  196. public double[] RefStation { get; set; }
  197. /// <summary>
  198. /// 时差误差(单位us)
  199. /// </summary>
  200. public double DtousErr { get; set; } = 1;
  201. /// <summary>
  202. /// 星历位置误差(单位米)
  203. /// </summary>
  204. public double SatLocErr { get; set; } = 10000;
  205. /// <summary>
  206. /// 定位类型
  207. /// </summary>
  208. public EnumPosResType PosResType { get; set; }
  209. }
  210. }