X2DTOParamEditor.cs 7.2 KB

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