LeoX1ParamEditor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. using DevExpress.XtraMap;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.Entity;
  6. using System.Drawing;
  7. using System.Linq;
  8. using XdCxRhDW.Api;
  9. using XdCxRhDW.Dto;
  10. using XdCxRhDW.Entity;
  11. using XdCxRhDW.Repostory;
  12. namespace XdCxRhDW.App.EditForms
  13. {
  14. public partial class LeoX1ParamEditor : DevExpress.XtraEditors.XtraUserControl
  15. {
  16. private PosRes info;
  17. private CgRes cg;
  18. private MapControl mapControl1;
  19. private List<SatInfo> listSat;
  20. StationRes station;
  21. public LeoX1ParamEditor(PosRes info, MapControl mapControl)
  22. {
  23. InitializeComponent();
  24. this.info = info;
  25. this.mapControl1 = mapControl;
  26. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  27. this.layoutControl1.UseDefault();
  28. sigTime.UseDefault();
  29. this.simpleLabelItem1.Text = $" ";
  30. }
  31. private async void LeoX1ParamEditor_Load(object sender, EventArgs e)
  32. {
  33. this.layoutControl1.BestFit();
  34. using (RHDWContext db = new RHDWContext())
  35. {
  36. listSat = await db.SatInfos.ToListAsync();
  37. }
  38. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  39. {
  40. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  41. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  42. }
  43. if (cg != null)
  44. {
  45. this.txtDfo1.Text = $"{cg.Dfo1.Value}";
  46. this.txtDfo2.Text = $"{cg.Dfo2.Value}";
  47. this.sigTime.EditValue = info.SigTime;
  48. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  49. ucEphXYZMain.SetParam($"第一时刻", cg.MainCode, mainEph, Color.Black);
  50. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  51. ucEphXYZAdja1.SetParam($"第二时刻", cg.Adja1Code, adja1Eph, Color.Black);
  52. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  53. ucEphXYZAdja2.SetParam($"第三时刻", cg.Adja2Code, adja2Eph, Color.Black);
  54. this.txtTargetFreq.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 0;
  55. this.txtTargetDFreq.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 0;
  56. }
  57. }
  58. public bool CheckPosParam()
  59. {
  60. dxErrorProvider.ClearErrors();
  61. if (!txtDfo1.CheckDouble(dxErrorProvider, "主邻1频差"))
  62. {
  63. return false;
  64. }
  65. if (!txtDfo2.CheckDouble(dxErrorProvider, "主邻2频差"))
  66. {
  67. return false;
  68. }
  69. if (!txtTargetFreq.CheckDouble(dxErrorProvider, "目标上行频点"))
  70. {
  71. return false;
  72. }
  73. if (!txtTargetDFreq.CheckDouble(dxErrorProvider, "目标下行频点"))
  74. {
  75. return false;
  76. }
  77. if (!ucEphXYZMain.CheckEph(dxErrorProvider))
  78. {
  79. return false;
  80. }
  81. if (!ucEphXYZAdja1.CheckEph(dxErrorProvider))
  82. {
  83. return false;
  84. }
  85. if (!ucEphXYZAdja2.CheckEph(dxErrorProvider))
  86. {
  87. return false;
  88. }
  89. return true;
  90. }
  91. private void btnOk_Click(object sender, EventArgs e)
  92. {
  93. if (!CheckPosParam()) { return; }
  94. try
  95. {
  96. var sigTime = this.sigTime.DateTime;
  97. var DfoSx = Convert.ToDouble(this.txtDfo1.Text);
  98. var DfoSx1 = Convert.ToDouble(this.txtDfo2.Text);
  99. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  100. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  101. var msEph = ucEphXYZMain.EphParam();
  102. var ns1Eph = ucEphXYZAdja1.EphParam();
  103. var ns2Eph = ucEphXYZAdja2.EphParam();
  104. var cgRes = new CgRes()
  105. {
  106. SigTime = sigTime,
  107. Dfo1 = DfoSx,
  108. Dfo2 = DfoSx1,
  109. TarFreqUp = tFreq,
  110. TarFreqDown = tdFreq,
  111. MainX = msEph[0],
  112. MainY = msEph[1],
  113. MainZ = msEph[2],
  114. MainVx = msEph[3],
  115. MainVy = msEph[4],
  116. MainVz = msEph[5],
  117. Adja1X = ns1Eph[0],
  118. Adja1Y = ns1Eph[1],
  119. Adja1Z = ns1Eph[2],
  120. Adja1Vx = ns1Eph[3],
  121. Adja1Vy = ns1Eph[4],
  122. Adja1Vz = ns1Eph[5],
  123. Adja2X = ns2Eph[0],
  124. Adja2Y = ns2Eph[1],
  125. Adja2Z = ns2Eph[2],
  126. Adja2Vx = ns2Eph[3],
  127. Adja2Vy = ns2Eph[4],
  128. Adja2Vz = ns2Eph[5],
  129. };
  130. var res = LeoPosApi.X1_POS(cgRes, cgRes.TarFreqUp.Value);
  131. this.simpleLabelItem1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  132. }
  133. catch (Exception ex)
  134. {
  135. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  136. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  137. }
  138. }
  139. private async void btnXl_Click(object sender, EventArgs e)
  140. {
  141. dxErrorProvider.ClearErrors();
  142. if (this.sigTime.DateTime == DateTime.MinValue)
  143. {
  144. dxErrorProvider.SetError(this.sigTime, "信号时间不能为空!");
  145. return;
  146. }
  147. var sigTime = this.sigTime.DateTime;
  148. try
  149. {
  150. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  151. if (xlInfo == null)
  152. {
  153. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  154. return;
  155. }
  156. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  157. if (xlInfo1 == null)
  158. {
  159. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  160. return;
  161. }
  162. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  163. if (xlInfo2 == null)
  164. {
  165. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  166. return;
  167. }
  168. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, SigTime = sigTime };
  169. var mEph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  170. XlCalcDto.tleStr = xlInfo1.TwoLine;
  171. var nEph1 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  172. XlCalcDto.tleStr = xlInfo2.TwoLine;
  173. var nEph2 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  174. var mainEph = (mEph.data.X, mEph.data.Y, mEph.data.Z, mEph.data.VX, mEph.data.VY, mEph.data.VZ);
  175. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Red);
  176. var adja1Eph = (nEph1.data.X, nEph1.data.Y, nEph1.data.Z, nEph1.data.VX, nEph1.data.VY, nEph1.data.VZ);
  177. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  178. var adja2Eph = (nEph2.data.X, nEph2.data.Y, nEph2.data.Z, nEph2.data.VX, nEph2.data.VY, nEph2.data.VZ);
  179. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  180. }
  181. catch (Exception ex)
  182. {
  183. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  184. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败,{ex.Message}");
  185. }
  186. }
  187. private void btnDfoCalc_Click(object sender, EventArgs e)
  188. {
  189. if (!CheckPosParam()) { return; }
  190. try
  191. {
  192. var sigTime = this.sigTime.DateTime;
  193. var DfoSx = Convert.ToDouble(this.txtDfo1.Text);
  194. var DfoSx1 = Convert.ToDouble(this.txtDfo2.Text);
  195. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  196. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  197. var msEph = ucEphXYZMain.EphParam();
  198. var ns1Eph = ucEphXYZAdja1.EphParam();
  199. var ns2Eph = ucEphXYZAdja2.EphParam();
  200. var tsDtoLine= LeoPosApi.DfoLineLeoX1(msEph,ns1Eph, DfoSx, tFreq);
  201. var msat = listSat?.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  202. if (msat == null) msat = cg.MainCode.ToString();
  203. mapControl1.DrawDtoLine($"{info.PosResType.GetEnumDisplayName()}[{msat}]第一时刻频差线", tsDtoLine);
  204. var tsDtoLine1 = LeoPosApi.DfoLineLeoX1(msEph, ns2Eph, DfoSx1, tFreq);
  205. mapControl1.DrawDtoLine($"{info.PosResType.GetEnumDisplayName()}[{msat}]第二时刻频差线", tsDtoLine1);
  206. }
  207. catch (Exception ex)
  208. {
  209. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}频差线失败.PosID={info.ID},SigTime={sigTime}");
  210. DxHelper.MsgBoxHelper.ShowError($"绘制{info.PosResType.GetEnumDisplayName()}频差线失败,{ex.Message}");
  211. }
  212. }
  213. }
  214. }