X2D1EllipesEditor.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. this.txtPosLocation.Text = $"{info.PosLon},{info.PosLat}";
  62. }
  63. public bool CheckParam()
  64. {
  65. dxErrorProvider.ClearErrors();
  66. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  67. {
  68. return false;
  69. }
  70. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  71. {
  72. return false;
  73. }
  74. if (!txtEphMain.CheckEphXYZ(dxErrorProvider))
  75. {
  76. return false;
  77. }
  78. if (!txtEphAdja.CheckEphXYZ(dxErrorProvider))
  79. {
  80. return false;
  81. }
  82. return true;
  83. }
  84. private async void btnEllipes_Click(object sender, EventArgs e)
  85. {
  86. if (!CheckParam()) { return; }
  87. try
  88. {
  89. var MsAnt = txtsatStation.GetLonLat();
  90. var CDBAnt = txtcdbStation.GetLonLat();
  91. var pos = txtPosLocation.GetLonLat();
  92. var RefGeod = txtRefLocation.GetLonLat();
  93. double[] ephMain = txtEphMain.EphXYZ();
  94. double[] ephAdja = txtEphAdja.EphXYZ();
  95. var dto = new ErrEllipseX2D1Dto()
  96. {
  97. MainX = ephMain[0],
  98. MainY = ephMain[1],
  99. MainZ = ephMain[2],
  100. AdjaX = ephAdja[0],
  101. AdjaY = ephAdja[1],
  102. AdjaZ = ephAdja[2],
  103. CdbLon = CDBAnt[0],
  104. CdbLat = CDBAnt[1],
  105. RefLon = RefGeod[0],
  106. RefLat = RefGeod[1],
  107. PosLon = pos[0],
  108. PosLat = pos[1],
  109. DtoErrus = Convert.ToDouble(txtDtousErr1.Text),
  110. EphErr = Convert.ToDouble(txtSatLocErr1.Text),
  111. Pe = Convert.ToDouble(txtPe.Text),
  112. OutputErrPoint = true,
  113. };
  114. AjaxResult<ErrEllipseResDto> rsp;
  115. if (info.PosResType != EnumPosResType.X2D1)
  116. {
  117. dto = dto.WithRef(112, 11);
  118. rsp = await HttpHelper.PostRequestAsync<ErrEllipseResDto>(SysConfig.GetUrl("Ellipse/X2D1"), dto, 30);
  119. }
  120. else
  121. {
  122. rsp = await HttpHelper.PostRequestAsync<ErrEllipseResDto>(SysConfig.GetUrl("Ellipse/X2D1NoRef"), dto, 30);
  123. }
  124. if (rsp.code != 200)
  125. {
  126. await LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{rsp.msg}");
  127. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{rsp.msg}");
  128. }
  129. else
  130. {
  131. this.mapControl1.DrawErrEllipse(rsp.data.LongRadius / 1e3, rsp.data.ShortRadius / 1e3, rsp.data.GeoPoints.Select(t => (t.Lon, t.Lat)));
  132. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}误差椭圆.长半轴={rsp.data.LongRadius:f0}m,短半轴={rsp.data.ShortRadius:f0}m,倾角={rsp.data.DipAngle:f1}°";
  133. }
  134. }
  135. catch (Exception ex)
  136. {
  137. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败.PosID={info.ID},SigTime={info.SigTime}");
  138. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{ex.Message}");
  139. }
  140. }
  141. private async void btnEphCalc_Click(object sender, EventArgs e)
  142. {
  143. dxErrorProvider.ClearErrors();
  144. if (this.txtSigTime.DateTime == DateTime.MinValue)
  145. {
  146. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  147. return;
  148. }
  149. var sigTime = this.txtSigTime.DateTime;
  150. try
  151. {
  152. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  153. if (mainxlInfo == null)
  154. {
  155. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  156. return;
  157. }
  158. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  159. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  160. txtEphMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  161. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  162. if (adjaxlInfo == null)
  163. {
  164. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  165. return;
  166. }
  167. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  168. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  169. txtEphAdja.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  170. }
  171. catch (Exception ex)
  172. {
  173. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  174. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  175. }
  176. }
  177. }
  178. }