X1D1PosParamEditor.cs 7.3 KB

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