X2D1EllipesEditor.cs 7.9 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. private List<SatInfo> listSat;
  27. public X2D1EllipesEditor(PosRes info, MapControl mapControl)
  28. {
  29. InitializeComponent();
  30. this.info = info;
  31. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  32. this.layoutControl1.UseDefault();
  33. txtSigTime.UseDefault();
  34. this.listSat = new List<SatInfo>();
  35. this.mapControl1 = mapControl;
  36. }
  37. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  38. {
  39. this.layoutControl1.BestFit();
  40. StationRes station = null;
  41. using (RHDWContext db = new RHDWContext())
  42. {
  43. listSat = await db.SatInfos.ToListAsync();
  44. }
  45. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  46. {
  47. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  48. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  49. }
  50. if (cg != null)
  51. {
  52. this.txtSigTime.EditValue = info.SigTime;
  53. txtEphMain.SetParam("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz), Color.Black);
  54. txtEphAdja.SetParam("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz), Color.Black);
  55. }
  56. if (station != null)
  57. {
  58. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  59. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  60. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  61. }
  62. if (info.PosResType == EnumPosResType.X2D1NoRef)
  63. {
  64. txtRefLocation.Properties.ReadOnly = true;
  65. this.txtRefLocation.Text = $"{0},{0}";
  66. }
  67. }
  68. public bool CheckParam()
  69. {
  70. dxErrorProvider.ClearErrors();
  71. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  72. {
  73. return false;
  74. }
  75. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  76. {
  77. return false;
  78. }
  79. if (!txtEphMain.CheckEph(dxErrorProvider))
  80. {
  81. return false;
  82. }
  83. if (!txtEphAdja.CheckEph(dxErrorProvider))
  84. {
  85. return false;
  86. }
  87. return true;
  88. }
  89. private async void btnDtoLine_Click(object sender, EventArgs e)
  90. {
  91. if (!CheckParam()) { return; }
  92. try
  93. {
  94. var MsAnt = txtsatStation.GetLonLat();
  95. var CDBAnt = txtcdbStation.GetLonLat();
  96. var pos = txtPosLocation.GetLonLat();
  97. var RefGeod = txtRefLocation.GetLonLat();
  98. double[] ephMain = txtEphMain.EphParam();
  99. double[] ephAdja = txtEphAdja.EphParam();
  100. var dto = new ErrEllipseX2D1Dto()
  101. {
  102. MainX = ephMain[0],
  103. MainY = ephMain[1],
  104. MainZ = ephMain[2],
  105. AdjaX = ephAdja[0],
  106. AdjaY = ephAdja[1],
  107. AdjaZ = ephAdja[2],
  108. CdbLon = CDBAnt[0],
  109. CdbLat = CDBAnt[1],
  110. RefLon = RefGeod[0],
  111. RefLat = RefGeod[1],
  112. PosLon = pos[0],
  113. PosLat = pos[1],
  114. DtoErrus = Convert.ToDouble(txtDtousErr1.Text),
  115. EphErr = Convert.ToDouble(txtSatLocErr1.Text),
  116. OutputErrPoint = true,
  117. };
  118. if (info.PosResType == EnumPosResType.X2D1)
  119. {
  120. dto = dto.WithRef(RefGeod[0], RefGeod[1]);
  121. }
  122. var rsp = await HttpHelper.PostRequestAsync<ErrEllipseResDto>(SysConfig.GetUrl("DetectCg/ErrorEllipse2X1D"), dto, 30);
  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, rsp.data.ShortRadius, rsp.data.GeoPoints.Select(t => (t.Lon, t.Lat)));
  131. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}误差椭圆.长半轴={rsp.data.LongRadius:f1},短半轴={rsp.data.ShortRadius:f1},倾角={rsp.data.DipAngle:f2}";
  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.SetParam("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z, maineph.data.VX, maineph.data.VY, maineph.data.VZ), 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.SetParam("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z, adjaeph.data.VX, adjaeph.data.VY, adjaeph.data.VZ), 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. }