X1D1PosParamEditor.cs 7.3 KB

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