X2D1EllipesEditor.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.Configuration;
  9. using System.Data;
  10. using System.Data.Entity;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using XdCxRhDW.Api;
  16. using XdCxRhDW.Dto;
  17. using XdCxRhDW.Entity;
  18. using XdCxRhDW.Repostory;
  19. namespace XdCxRhDW.App.EditForms
  20. {
  21. public partial class X2D1EllipesEditor : DevExpress.XtraEditors.XtraUserControl
  22. {
  23. private MapControl mapControl1;
  24. private PosRes info;
  25. private CgRes cg;
  26. public X2D1EllipesEditor(PosRes info, MapControl mapControl)
  27. {
  28. InitializeComponent();
  29. this.info = info;
  30. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  31. this.layoutControl1.UseDefault();
  32. txtSigTime.UseDefault();
  33. this.mapControl1 = mapControl;
  34. }
  35. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  36. {
  37. this.layoutControl1.BestFit();
  38. StationRes station = null;
  39. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  40. {
  41. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  42. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  43. }
  44. if (cg != null)
  45. {
  46. this.txtSigTime.EditValue = info.SigTime;
  47. txtEphMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  48. txtEphAdja.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  49. }
  50. if (station != null)
  51. {
  52. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  53. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  54. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  55. }
  56. if (info.PosResType == EnumPosResType.X2D1NoRef)
  57. {
  58. txtRefLocation.Properties.ReadOnly = true;
  59. this.txtRefLocation.Text = $"{0},{0}";
  60. }
  61. }
  62. public bool CheckParam()
  63. {
  64. dxErrorProvider.ClearErrors();
  65. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  66. {
  67. return false;
  68. }
  69. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  70. {
  71. return false;
  72. }
  73. if (!txtEphMain.CheckEphXYZ(dxErrorProvider))
  74. {
  75. return false;
  76. }
  77. if (!txtEphAdja.CheckEphXYZ(dxErrorProvider))
  78. {
  79. return false;
  80. }
  81. return true;
  82. }
  83. private async void btnEllipes_Click(object sender, EventArgs e)
  84. {
  85. if (!CheckParam()) { return; }
  86. try
  87. {
  88. var MsAnt = txtsatStation.GetLonLat();
  89. var CDBAnt = txtcdbStation.GetLonLat();
  90. var pos = txtPosLocation.GetLonLat();
  91. var RefGeod = txtRefLocation.GetLonLat();
  92. double[] ephMain = txtEphMain.EphXYZ();
  93. double[] ephAdja = txtEphAdja.EphXYZ();
  94. var dto = new ErrEllipseX2D1Dto()
  95. {
  96. MainX = ephMain[0],
  97. MainY = ephMain[1],
  98. MainZ = ephMain[2],
  99. AdjaX = ephAdja[0],
  100. AdjaY = ephAdja[1],
  101. AdjaZ = ephAdja[2],
  102. CdbLon = CDBAnt[0],
  103. CdbLat = CDBAnt[1],
  104. RefLon = RefGeod[0],
  105. RefLat = RefGeod[1],
  106. PosLon = pos[0],
  107. PosLat = pos[1],
  108. DtoErrus = Convert.ToDouble(txtDtousErr1.Text),
  109. EphErr = Convert.ToDouble(txtSatLocErr1.Text),
  110. Pe = Convert.ToDouble(txtPE.Text),
  111. OutputErrPoint = true,
  112. };
  113. AjaxResult<ErrEllipseResDto> rsp;
  114. if (info.PosResType != EnumPosResType.X2D1)
  115. {
  116. dto = dto.WithRef(112, 11);
  117. rsp = await HttpHelper.PostRequestAsync<ErrEllipseResDto>(SysConfig.GetUrl("Ellipse/X2D1"), dto, 30);
  118. }
  119. else
  120. {
  121. rsp = await HttpHelper.PostRequestAsync<ErrEllipseResDto>(SysConfig.GetUrl("Ellipse/X2D1NoRef"), dto, 30);
  122. }
  123. if (rsp.code != 200)
  124. {
  125. await LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{rsp.msg}");
  126. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{rsp.msg}");
  127. }
  128. else
  129. {
  130. this.mapControl1.DrawErrEllipse(rsp.data.LongRadius / 1e3, rsp.data.ShortRadius / 1e3, rsp.data.GeoPoints.Select(t => (t.Lon, t.Lat)));
  131. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}误差椭圆.长半轴={rsp.data.LongRadius:f0}m,短半轴={rsp.data.ShortRadius:f0}m,倾角={rsp.data.DipAngle:f1}°";
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  137. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  138. }
  139. }
  140. private async void btnEphCalc_Click(object sender, EventArgs e)
  141. {
  142. dxErrorProvider.ClearErrors();
  143. if (this.txtSigTime.DateTime == DateTime.MinValue)
  144. {
  145. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  146. return;
  147. }
  148. var sigTime = this.txtSigTime.DateTime;
  149. try
  150. {
  151. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  152. if (mainxlInfo == null)
  153. {
  154. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  155. return;
  156. }
  157. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  158. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  159. txtEphMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  160. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  161. if (adjaxlInfo == null)
  162. {
  163. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  164. return;
  165. }
  166. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  167. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  168. txtEphAdja.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  169. }
  170. catch (Exception ex)
  171. {
  172. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  173. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  174. }
  175. }
  176. }
  177. }