X2DTOParamEditor.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using DevExpress.Mvvm.ModuleInjection.Native;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.DXErrorProvider;
  4. using DevExpress.XtraLayout;
  5. using DevExpress.XtraMap;
  6. using DevExpress.XtraTreeList.Data;
  7. using DxHelper;
  8. using ExtensionsDev;
  9. using System;
  10. using System.CodeDom;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Data.Entity.Migrations;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using XdCxRhDW.Api;
  21. using XdCxRhDW.Entity;
  22. using XdCxRhDW.Repostory;
  23. namespace XdCxRhDW.App.EditForms
  24. {
  25. public partial class X2DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  26. {
  27. private MapControl mapControl1;
  28. private PosRes info;
  29. private CgRes cg;
  30. private List<SatInfo> listSat;
  31. public X2DTOParamEditor(PosRes info, MapControl mapControl)
  32. {
  33. InitializeComponent();
  34. this.layoutControl1.UseDefault();
  35. sigTime.UseDefault();
  36. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  37. this.info = info;
  38. this.listSat = new List<SatInfo>();
  39. this.mapControl1 = mapControl;
  40. //this.StartPosition = FormStartPosition.CenterParent;
  41. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  42. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  43. }
  44. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  45. {
  46. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  47. }
  48. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  49. {
  50. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  51. }
  52. private async void X2DTOParamEditor_Load(object sender, EventArgs e)
  53. {
  54. StationRes station = null;
  55. using (RHDWContext db = new RHDWContext())
  56. {
  57. listSat = await db.SatInfos.ToListAsync();
  58. }
  59. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  60. {
  61. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  62. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  63. }
  64. if (cg != null)
  65. {
  66. this.txtDtoSx.Text = $"{cg.Dto1.Value:f4}";
  67. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f4}";
  68. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f4}";
  69. this.sigTime.EditValue = info.SigTime;
  70. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  71. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  72. }
  73. if (station != null)
  74. {
  75. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  76. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  77. }
  78. }
  79. public bool CheckParam()
  80. {
  81. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  82. {
  83. return false;
  84. }
  85. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  86. {
  87. return false;
  88. }
  89. return true;
  90. }
  91. private void btnOk_Click(object sender, EventArgs e)
  92. {
  93. if (!CheckParam()) { return; }
  94. try
  95. {
  96. var MsAnt = txtsatStation.GetLonLat();
  97. var RefGeod = txtRefLocation.GetLonLat();
  98. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  99. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  100. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  101. double[] msEph = ucEphXYZMain.EphXYZ();
  102. double[] Ns1Eph = ucEphXYZAdaj.EphXYZ();
  103. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  104. twoStartOption.MsEph = msEph;
  105. twoStartOption.NsEph = Ns1Eph;
  106. twoStartOption.MsAnt = MsAnt;
  107. twoStartOption.NsAnt = MsAnt;
  108. twoStartOption.RefGeod = RefGeod;
  109. twoStartOption.TargetDto = DtoSx;
  110. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  111. twoStartOption.PosLon = info.PosLon;
  112. twoStartOption.PosLat = info.PosLat;
  113. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  114. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  115. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  116. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  117. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  118. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  119. }
  120. catch (Exception ex)
  121. {
  122. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  123. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  124. }
  125. }
  126. private async void btnEphCalc_Click(object sender, EventArgs e)
  127. {
  128. if (this.sigTime.DateTime == DateTime.MinValue)
  129. {
  130. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  131. return;
  132. }
  133. var sigTime = this.sigTime.DateTime;
  134. try
  135. {
  136. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  137. if (mainxlInfo == null)
  138. {
  139. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  140. return;
  141. }
  142. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  143. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  144. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  145. if (adjaxlInfo == null)
  146. {
  147. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  148. return;
  149. }
  150. var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc());
  151. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.X, adjaeph.Y, adjaeph.Z), Color.Red);
  152. }
  153. catch (Exception ex)
  154. {
  155. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  156. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  157. }
  158. }
  159. }
  160. }