X1D1PosParamEditor.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using DevExpress.XtraMap;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Data.Entity;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using XdCxRhDW.Api;
  14. using XdCxRhDW.App.App.Properties;
  15. using XdCxRhDW.Dto;
  16. using XdCxRhDW.Entity;
  17. using XdCxRhDW.Repostory;
  18. namespace XdCxRhDW.App.EditForms
  19. {
  20. public partial class X1D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. private PosRes info;
  23. private CgRes cg;
  24. private SysSetings settings = new SysSetings();
  25. public X1D1PosParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.info = info;
  29. this.labelControl1.Text = $"";
  30. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  31. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  32. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  33. txtCxLocation.EditValueChanged += TxtCxLocation_EditValueChanged;
  34. }
  35. private void TxtCxLocation_EditValueChanged(object sender, EventArgs e)
  36. {
  37. txtCxLocation.CheckLonLat(dxErrorProvider, "测向站");
  38. }
  39. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  40. {
  41. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  42. }
  43. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  44. {
  45. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  46. }
  47. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  48. {
  49. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  50. }
  51. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  52. {
  53. StationRes station;
  54. using (RHDWContext db = new RHDWContext())
  55. {
  56. settings = await db.SysSetings.FirstOrDefaultAsync();
  57. }
  58. CxRes cx;
  59. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  60. {
  61. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  62. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  63. cx = await db.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  64. }
  65. if (cg != null)
  66. {
  67. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  68. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  69. this.sigTime.EditValue = info.SigTime;
  70. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  71. }
  72. if (cx != null)
  73. {
  74. this.txtcxFx.Text = $"{cx.Fx:f3}";
  75. }
  76. if (station != null)
  77. {
  78. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  79. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  80. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  81. this.txtCxLocation.Text = $"{station.CxLon:f3},{station.CxLat:f3}";
  82. }
  83. }
  84. public bool CheckParam()
  85. {
  86. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  87. {
  88. return false;
  89. }
  90. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  91. {
  92. return false;
  93. }
  94. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  95. {
  96. return false;
  97. }
  98. return true;
  99. }
  100. private void btnOk_Click(object sender, EventArgs e)
  101. {
  102. if (!CheckParam()) { return; }
  103. try
  104. {
  105. var MsAnt = txtsatStation.GetLonLat();
  106. var CDBAnt = txtcdbStation.GetLonLat();
  107. var RefGeod = txtRefLocation.GetLonLat();
  108. var CXStation = txtCxLocation.GetLonLat();
  109. var sigTime = this.sigTime.DateTime;
  110. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  111. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  112. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  113. double[] msEph = ucEphXYZMain.EphXYZ();
  114. var StationRes = new StationRes()
  115. {
  116. SatTxLon = MsAnt[0],
  117. SatTxLat = MsAnt[1],
  118. CdbTxLon = CDBAnt[0],
  119. CdbTxLat = CDBAnt[1],
  120. CxLon = CXStation[0],
  121. CxLat = CXStation[1],
  122. RefLon = RefGeod[0],
  123. RefLat = RefGeod[1],
  124. };
  125. var cgRes = new CgRes()
  126. {
  127. SigTime = sigTime,
  128. DtoCdb = DtoCdb,
  129. YbMainDto = YbMainDto,
  130. MainX = msEph[0],
  131. MainY = msEph[1],
  132. MainZ = msEph[2],
  133. };
  134. var cxRes = new CxRes()
  135. {
  136. SigTime = sigTime,
  137. Fx = Fx,
  138. };
  139. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  140. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  141. }
  142. catch (Exception ex)
  143. {
  144. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  145. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  146. }
  147. }
  148. private async void btnCalcXl_Click(object sender, EventArgs e)
  149. {
  150. if (this.sigTime.DateTime == DateTime.MinValue)
  151. {
  152. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  153. return;
  154. }
  155. try
  156. {
  157. var sigTime = this.sigTime.DateTime;
  158. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  159. if (xlInfo == null)
  160. {
  161. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  162. return;
  163. }
  164. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = sigTime };
  165. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  166. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  167. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  168. }
  169. catch (Exception ex)
  170. {
  171. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  172. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  173. }
  174. }
  175. }
  176. }