X3PosParamEditor.cs 8.6 KB

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