X3PosParamEditor.cs 8.5 KB

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