X1D1DTOParamEditor.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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=null;
  51. using (RHDWContext db = new RHDWContext())
  52. {
  53. listSat = await db.SatInfos.ToListAsync();
  54. }
  55. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  56. {
  57. if (db.DatabaseExist)
  58. {
  59. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  60. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  61. }
  62. }
  63. if (cg != null)
  64. {
  65. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  66. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  67. this.sigTime.EditValue = info.SigTime;
  68. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  69. }
  70. if (station != null)
  71. {
  72. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  73. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  74. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  75. }
  76. }
  77. public bool CheckParam()
  78. {
  79. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  80. {
  81. return false;
  82. }
  83. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  84. {
  85. return false;
  86. }
  87. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  88. {
  89. return false;
  90. }
  91. return true;
  92. }
  93. private void btnOk_Click(object sender, EventArgs e)
  94. {
  95. if (!CheckParam()) { return; }
  96. try
  97. {
  98. var MsAnt = txtsatStation.GetLonLat();
  99. var CDBAnt = txtcdbStation.GetLonLat();
  100. var RefGeod = txtRefLocation.GetLonLat();
  101. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  102. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  103. double[] msEph = ucEphXYZMain.EphXYZ();
  104. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  105. dtoLineXd.MsEph = msEph;
  106. dtoLineXd.MsAnt = MsAnt;
  107. dtoLineXd.CDBAnt = CDBAnt;
  108. dtoLineXd.RefGeod = RefGeod;
  109. dtoLineXd.xdDto = DtoCdb;
  110. dtoLineXd.RefDto = YbMainDto;
  111. dtoLineXd.PosLon = info.PosLon;
  112. dtoLineXd.PosLat = info.PosLat;
  113. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  114. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  115. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  116. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine);
  117. }
  118. catch (Exception ex)
  119. {
  120. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  121. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  122. }
  123. }
  124. private async void btnEphCalc_Click(object sender, EventArgs e)
  125. {
  126. if (this.sigTime.DateTime == DateTime.MinValue)
  127. {
  128. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  129. return;
  130. }
  131. var sigTime = this.sigTime.DateTime;
  132. try
  133. {
  134. var mainCode = ucEphXYZMain.GetSatCode();
  135. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  136. if (mainxlInfo == null)
  137. {
  138. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  139. return;
  140. }
  141. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime);
  142. ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  143. }
  144. catch (Exception ex)
  145. {
  146. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  147. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  148. }
  149. }
  150. }
  151. }