X1D1DTOParamEditor.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using DevExpress.XtraMap;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.CodeDom;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Data.Entity;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using XdCxRhDW.Api;
  15. using XdCxRhDW.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.App.EditForms
  18. {
  19. public partial class X1D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private MapControl mapControl1;
  22. private PosRes info;
  23. private CgRes cg;
  24. private List<SatInfo> listSat;
  25. public X1D1DTOParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  29. this.info = info;
  30. this.listSat = new List<SatInfo>();
  31. this.mapControl1 = mapControl;
  32. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  33. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  34. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  35. }
  36. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  37. {
  38. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  39. }
  40. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  41. {
  42. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  43. }
  44. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  45. {
  46. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  47. }
  48. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  49. {
  50. StationRes station;
  51. using (RHDWContext db = new RHDWContext())
  52. {
  53. listSat = await db.SatInfos.ToListAsync();
  54. }
  55. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  56. {
  57. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  58. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  59. }
  60. if (cg != null)
  61. {
  62. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  63. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  64. this.sigTime.EditValue = info.SigTime;
  65. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  66. }
  67. if (station != null)
  68. {
  69. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  70. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  71. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  72. }
  73. }
  74. public bool CheckParam()
  75. {
  76. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  77. {
  78. return false;
  79. }
  80. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  81. {
  82. return false;
  83. }
  84. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  85. {
  86. return false;
  87. }
  88. return true;
  89. }
  90. private void btnOk_Click(object sender, EventArgs e)
  91. {
  92. if (!CheckParam()) { return; }
  93. try
  94. {
  95. var MsAnt = txtsatStation.GetLonLat();
  96. var CDBAnt = txtcdbStation.GetLonLat();
  97. var RefGeod = txtRefLocation.GetLonLat();
  98. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  99. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  100. double[] msEph = ucEphXYZMain.EphXYZ();
  101. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  102. dtoLineXd.MsEph = msEph;
  103. dtoLineXd.MsAnt = MsAnt;
  104. dtoLineXd.CDBAnt = CDBAnt;
  105. dtoLineXd.RefGeod = RefGeod;
  106. dtoLineXd.xdDto = DtoCdb;
  107. dtoLineXd.RefDto = YbMainDto;
  108. dtoLineXd.PosLon = info.PosLon;
  109. dtoLineXd.PosLat = info.PosLat;
  110. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  111. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  112. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  113. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine);
  114. }
  115. catch (Exception ex)
  116. {
  117. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  118. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  119. }
  120. }
  121. private async void btnEphCalc_Click(object sender, EventArgs e)
  122. {
  123. if (this.sigTime.DateTime == DateTime.MinValue)
  124. {
  125. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  126. return;
  127. }
  128. var sigTime = this.sigTime.DateTime;
  129. try
  130. {
  131. var mainCode = ucEphXYZMain.GetSatCode();
  132. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  133. if (mainxlInfo == null)
  134. {
  135. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  136. return;
  137. }
  138. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime);
  139. ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  140. }
  141. catch (Exception ex)
  142. {
  143. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  144. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  145. }
  146. }
  147. }
  148. }