X2D1GDOPParam.cs 8.8 KB

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