X3PosParamEditor.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 X3PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private PosRes info;
  22. private CgRes cg;
  23. public X3PosParamEditor(PosRes info, MapControl mapControl)
  24. {
  25. InitializeComponent();
  26. this.info = info;
  27. this.labelControl1.Text = $"";
  28. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  29. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  30. }
  31. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  32. {
  33. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  34. }
  35. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  36. {
  37. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  38. }
  39. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  40. {
  41. StationRes station;
  42. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  43. {
  44. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  45. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  46. }
  47. if (cg != null)
  48. {
  49. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  50. this.txtDtoSx1.Text = $"{cg.Dto2.Value:f3}";
  51. if (info.PosResType == EnumPosResType.X3)
  52. {
  53. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  54. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  55. this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value:f3}";
  56. }
  57. this.sigTime.EditValue = info.SigTime;
  58. var mainEph = (cg.MainX, cg.MainY, cg.MainZ);
  59. ucEphXYZMain.SetXYZ($"主星", cg.MainCode, mainEph, Color.Black);
  60. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z);
  61. ucEphXYZAdja1.SetXYZ($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  62. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z);
  63. ucEphXYZAdja2.SetXYZ($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  64. }
  65. if (station != null)
  66. {
  67. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  68. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  69. }
  70. if (info.PosResType == EnumPosResType.X3NoRef)
  71. {
  72. txtYbMain.Properties.ReadOnly = true;
  73. txtYbAdja.Properties.ReadOnly = true;
  74. txtYbAdja1.Properties.ReadOnly = true;
  75. txtRefLocation.Properties.ReadOnly = true;
  76. this.txtRefLocation.Text = $"{0},{0}";
  77. }
  78. }
  79. public bool CheckParam()
  80. {
  81. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  82. {
  83. return false;
  84. }
  85. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  86. {
  87. return false;
  88. }
  89. return true;
  90. }
  91. private void btnOk_Click(object sender, EventArgs e)
  92. {
  93. if (!CheckParam()) { return; }
  94. try
  95. {
  96. var MsAnt = txtsatStation.GetLonLat();
  97. var RefGeod = info.PosResType == EnumPosResType.X3 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  98. var sigTime = this.sigTime.DateTime;
  99. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  100. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  101. var YbMainDto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  102. var YbAdja1Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  103. var YbAdja2Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja1.Text) : 0;
  104. double[] msEph = ucEphXYZMain.EphXYZ();
  105. double[] Ns1Eph = ucEphXYZAdja1.EphXYZ();
  106. double[] Ns2Eph = ucEphXYZAdja2.EphXYZ();
  107. var StationRes = new StationRes()
  108. {
  109. SatTxLon = MsAnt[0],
  110. SatTxLat = MsAnt[1],
  111. RefLon = RefGeod[0],
  112. RefLat = RefGeod[1],
  113. };
  114. var cgRes = new CgRes()
  115. {
  116. SigTime = sigTime,
  117. Dto1 = DtoSx,
  118. Dto2 = DtoSx1,
  119. YbMainDto = YbMainDto,
  120. YbAdja1Dto = YbAdja1Dto,
  121. YbAdja2Dto = YbAdja2Dto,
  122. MainX = msEph[0],
  123. MainY = msEph[1],
  124. MainZ = msEph[2],
  125. Adja1X = Ns1Eph[0],
  126. Adja1Y = Ns1Eph[1],
  127. Adja1Z = Ns1Eph[2],
  128. Adja2X = Ns2Eph[0],
  129. Adja2Y = Ns2Eph[1],
  130. Adja2Z = Ns2Eph[2],
  131. };
  132. var res = info.PosResType == EnumPosResType.X3 ? PosApi.X3_Pos(cgRes, StationRes) : PosApi.X3_PosNoRef(cgRes, StationRes);
  133. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  134. }
  135. catch (Exception ex)
  136. {
  137. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  138. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  139. }
  140. }
  141. private async void btnXl_Click(object sender, EventArgs e)
  142. {
  143. if (this.sigTime.DateTime == DateTime.MinValue)
  144. {
  145. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  146. return;
  147. }
  148. try
  149. {
  150. var sigTime = this.sigTime.DateTime;
  151. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  152. if (xlInfo == null)
  153. {
  154. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  155. return;
  156. }
  157. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  158. if (xlInfo1 == null)
  159. {
  160. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  161. return;
  162. }
  163. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  164. if (xlInfo2 == null)
  165. {
  166. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  167. return;
  168. }
  169. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  170. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime);
  171. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime);
  172. var mainEph = (mEph.X, mEph.Y, mEph.Z);
  173. ucEphXYZMain.SetXYZ($"主星", cg.MainCode, mainEph, Color.Red);
  174. var adja1Eph = (nEph1.X, nEph1.Y, nEph1.Z);
  175. ucEphXYZAdja1.SetXYZ($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  176. var adja2Eph = (nEph2.X, nEph2.Y, nEph2.Z);
  177. ucEphXYZAdja2.SetXYZ($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  178. }
  179. catch (Exception ex)
  180. {
  181. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  182. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  183. }
  184. }
  185. }
  186. }