X2D1DTOParamEditor.cs 9.8 KB

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