X2D1DTOParamEditor.cs 9.7 KB

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