X1D1PosParamEditor.cs 7.2 KB

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