X2DTOParamEditor.cs 7.0 KB

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