X2D1DTOParamEditor.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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.Data;
  9. using System.Data.Entity;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using XdCxRhDW.Api;
  15. using XdCxRhDW.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.App.EditForms
  18. {
  19. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private MapControl mapControl1;
  22. private PosRes info;
  23. private CgRes cg;
  24. private List<SatInfo> listSat;
  25. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.layoutControl1.UseDefault();
  29. sigTime.UseDefault();
  30. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  31. this.info = info;
  32. this.listSat = new List<SatInfo>();
  33. this.mapControl1 = mapControl;
  34. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  35. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  36. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  37. }
  38. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  39. {
  40. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  41. }
  42. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  43. {
  44. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  45. }
  46. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  47. {
  48. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  49. }
  50. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  51. {
  52. StationRes station = null;
  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:f4}";
  65. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f4}";
  66. if (info.PosResType == EnumPosResType.X2D1)
  67. {
  68. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f4}";
  69. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f4}";
  70. }
  71. this.sigTime.EditValue = info.SigTime;
  72. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  73. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  74. }
  75. if (station != null)
  76. {
  77. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  78. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  79. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  80. }
  81. if (info.PosResType == EnumPosResType.X2D1NoRef)
  82. {
  83. txtYbMain.Properties.ReadOnly = true;
  84. txtYbAdja.Properties.ReadOnly = true;
  85. txtRefLocation.Properties.ReadOnly = true;
  86. this.txtRefLocation.Text = $"{0},{0}";
  87. }
  88. double tarLon = 46, tarLat = 24;
  89. double recLon = 45.9, recLat = 23.9;
  90. var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  91. var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  92. var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value);
  93. var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value);
  94. var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef);
  95. var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef);
  96. var dto1 = (dt1 - dt2) * 1e6;
  97. var dt3 = PhysicsHelper.Dto(tarEcef, recEcef);
  98. var dto2 = (dt1 - dt3) * 1e6;
  99. }
  100. public bool CheckParam()
  101. {
  102. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  103. {
  104. return false;
  105. }
  106. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  107. {
  108. return false;
  109. }
  110. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  111. {
  112. return false;
  113. }
  114. return true;
  115. }
  116. private void btnOk_Click(object sender, EventArgs e)
  117. {
  118. if (!CheckParam()) { return; }
  119. try
  120. {
  121. var MsAnt = txtsatStation.GetLonLat();
  122. var CDBAnt = txtcdbStation.GetLonLat();
  123. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  124. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  125. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  126. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  127. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  128. double[] msEph = ucEphXYZMain.EphXYZ();
  129. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  130. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  131. dtoLineXd.MsEph = msEph;
  132. dtoLineXd.MsAnt = MsAnt;
  133. dtoLineXd.CDBAnt = CDBAnt;
  134. dtoLineXd.RefGeod = RefGeod;
  135. dtoLineXd.xdDto = DtoCdb;
  136. dtoLineXd.RefDto = YbMainDto;
  137. dtoLineXd.PosLon = info.PosLon;
  138. dtoLineXd.PosLat = info.PosLat;
  139. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  140. twoStartOption.MsEph = msEph;
  141. twoStartOption.NsEph = NsEph;
  142. twoStartOption.MsAnt = MsAnt;
  143. twoStartOption.NsAnt = MsAnt;
  144. twoStartOption.RefGeod = RefGeod;
  145. twoStartOption.TargetDto = DtoSx;
  146. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  147. twoStartOption.PosLon = info.PosLon;
  148. twoStartOption.PosLat = info.PosLat;
  149. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  150. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  151. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  152. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  153. if (info.PosResType == EnumPosResType.X2D1)
  154. {
  155. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  156. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  157. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  158. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  159. }
  160. else
  161. {
  162. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRef(dtoLineXd);
  163. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  164. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  165. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  171. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  172. }
  173. }
  174. private async void btnEphCalc_Click(object sender, EventArgs e)
  175. {
  176. if (this.sigTime.DateTime == DateTime.MinValue)
  177. {
  178. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  179. return;
  180. }
  181. var sigTime = this.sigTime.DateTime;
  182. try
  183. {
  184. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  185. if (mainxlInfo == null)
  186. {
  187. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  188. return;
  189. }
  190. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  191. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  192. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  193. if (adjaxlInfo == null)
  194. {
  195. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  196. return;
  197. }
  198. var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc());
  199. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.X, adjaeph.Y, adjaeph.Z), Color.Red);
  200. }
  201. catch (Exception ex)
  202. {
  203. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  204. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  205. }
  206. }
  207. }
  208. }