X3GDOPParam.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using DevExpress.XtraMap;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. using DxHelper;
  8. using XdCxRhDW.Repostory;
  9. using XdCxRhDW.Entity;
  10. using XdCxRhDW.Api;
  11. using System.Drawing;
  12. namespace XdCxRhDW.App.UserControl
  13. {
  14. public partial class X3GDOPParam : DevExpress.XtraEditors.XtraUserControl
  15. {
  16. public MapControl mapControl1;
  17. public X3GDOP星地接口 Model => new X3GDOP星地接口()
  18. {
  19. EphMain = ucEphXYZMain.EphParam(),
  20. EphAdja1 = ucEphXYZAdja1.EphParam(),
  21. EphAdja2 = ucEphXYZAdja2.EphParam(),
  22. CapTime = txtCapTime.DateTime,
  23. RefLon = PosResType == EnumPosResType.X3NoRef ? 0 : Convert.ToDouble(txtRefLocation1.Text.Replace(",", ",").Split(',')[0].Trim()),
  24. RefLat = PosResType == EnumPosResType.X3NoRef ? 0 : Convert.ToDouble(txtRefLocation1.Text.Replace(",", ",").Split(',')[1].Trim()),
  25. DtousErr = Convert.ToDouble(txtDtousErr1.Text),
  26. SatLocErr = Convert.ToDouble(txtSatLocErr1.Text),
  27. };
  28. private EnumPosResType PosResType;
  29. public X3GDOPParam(PosRes item)
  30. {
  31. InitializeComponent();
  32. this.layoutControl1.UseDefault();
  33. txtCapTime.UseDefault();
  34. txtRefLocation1.UseDoubleClickToSelectAll();
  35. this.txtCapTime.DateTime = item.SigTime;
  36. this.txtDtousErr1.EditValue = 1;
  37. this.txtSatLocErr1.EditValue = 10000;
  38. PosResType = item.PosResType;
  39. if (PosResType == EnumPosResType.X3NoRef)
  40. {
  41. layoutControlItem14.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  42. }
  43. using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
  44. {
  45. var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
  46. var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
  47. if (station != null)
  48. {
  49. this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
  50. }
  51. if (cg != null)
  52. {
  53. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  54. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  55. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  56. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  57. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  58. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  59. }
  60. }
  61. }
  62. private void btnClose_Click(object sender, EventArgs e)
  63. {
  64. DxHelper.PopupHelper.HidePopup(this);
  65. }
  66. private (bool, string) ParamValidate()
  67. {
  68. var mainparam = ucEphXYZMain.ValidateParam();
  69. if (!mainparam.Item1)
  70. {
  71. return (false, mainparam.Item2);
  72. }
  73. var adja1param = ucEphXYZAdja1.ValidateParam();
  74. if (!adja1param.Item1)
  75. {
  76. return (false, adja1param.Item2);
  77. }
  78. var adja2param = ucEphXYZAdja2.ValidateParam();
  79. if (!adja2param.Item1)
  80. {
  81. return (false, adja2param.Item2);
  82. }
  83. var refsta = txtRefLocation1.CheckLonLat("参考站");
  84. if (PosResType == EnumPosResType.X3 && !refsta.Item1)
  85. {
  86. return refsta;
  87. }
  88. return (true, "");
  89. }
  90. private void btnX1D2_Click(object sender, EventArgs e)
  91. {
  92. var pv = ParamValidate();
  93. if (!pv.Item1)
  94. {
  95. DxHelper.MsgBoxHelper.ShowWarning($"{pv.Item2}");
  96. return;
  97. }
  98. try
  99. {
  100. mapControl1.ClearMap();
  101. var refs = new double[] { Model.RefLon, Model.RefLat, 0 };
  102. var data = GdopHelper.Gdop3SatByXyz(Model.EphMain, Model.EphAdja1, Model.EphAdja2
  103. , Model.DtousErr, Model.SatLocErr, PosResType == EnumPosResType.X3NoRef ? null : refs);
  104. if (data == null)
  105. {
  106. return;
  107. }
  108. foreach (var errLins in data)//画GDOP
  109. {
  110. var mapDots = errLins.MapDots.Select(p => p).Select(p => (p.Lon, p.Lat));
  111. mapControl1.DrawGdopLineTwo(errLins.ErrDistanceKm, mapDots, 1);
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. DxHelper.MsgBoxHelper.ShowError($"绘制{PosResType.GetEnumDisplayName()}GDOP失败,{ex.Message}");
  117. }
  118. }
  119. private async void btnEphCalc_Click(object sender, EventArgs e)
  120. {
  121. if (txtCapTime.DateTime == DateTime.MinValue)
  122. {
  123. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  124. return;
  125. }
  126. var sigTime = txtCapTime.DateTime;
  127. try
  128. {
  129. var mainCode = ucEphXYZMain.GetSatCode();
  130. var adja1Code = ucEphXYZAdja1.GetSatCode();
  131. var adja2Code = ucEphXYZAdja2.GetSatCode();
  132. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  133. if (mainxlInfo == null)
  134. {
  135. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  136. return;
  137. }
  138. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime);
  139. ucEphXYZMain.SetParam("主星", mainCode, (maineph.X, maineph.Y, maineph.Z, maineph.VX, maineph.VY, maineph.VZ), Color.Red);
  140. var adja1xlInfo = await XlRepository.GetLatestAsync(adja1Code, sigTime);
  141. if (adja1xlInfo == null)
  142. {
  143. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{adja1Code}未找到对应的星历信息,请导入星历");
  144. return;
  145. }
  146. var adja1eph = EphHelper.Calc(adja1xlInfo.TwoLine, sigTime);
  147. ucEphXYZAdja1.SetParam("邻星1", adja1Code, (adja1eph.X, adja1eph.Y, adja1eph.Z, adja1eph.VX, adja1eph.VY, adja1eph.VZ), Color.Red);
  148. var adja2xlInfo = await XlRepository.GetLatestAsync(adja2Code, sigTime);
  149. if (adja2xlInfo == null)
  150. {
  151. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{adja2Code}未找到对应的星历信息,请导入星历");
  152. return;
  153. }
  154. var adja2eph = EphHelper.Calc(adja2xlInfo.TwoLine, sigTime);
  155. ucEphXYZAdja2.SetParam("邻星2", adja2Code, (adja2eph.X, adja2eph.Y, adja2eph.Z, adja2eph.VX, adja2eph.VY, adja2eph.VZ), Color.Red);
  156. }
  157. catch (Exception ex)
  158. {
  159. Serilog.Log.Error(ex, $"手动推算{PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  160. DxHelper.MsgBoxHelper.ShowError($"手动推算{PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  161. }
  162. }
  163. }
  164. public class X3GDOP星地接口
  165. {
  166. /// <summary>
  167. /// 主星星历x y z vx vy vz
  168. /// </summary>
  169. public double[] EphMain { get; set; }
  170. /// <summary>
  171. /// 邻星1星历x y z vx vy vz
  172. /// </summary>
  173. public double[] EphAdja1 { get; set; }
  174. /// <summary>
  175. /// 邻星2星历x y z vx vy vz
  176. /// </summary>
  177. public double[] EphAdja2 { get; set; }
  178. /// <summary>
  179. /// 采集时刻
  180. /// </summary>
  181. public DateTime CapTime { get; set; }
  182. /// <summary>
  183. /// 参考站位置经度
  184. /// </summary>
  185. public double RefLon { get; set; }
  186. /// <summary>
  187. /// 参考站位置纬度
  188. /// </summary>
  189. public double RefLat { get; set; }
  190. /// <summary>
  191. /// 时差误差(单位us)
  192. /// </summary>
  193. public double DtousErr { get; set; } = 1;
  194. /// <summary>
  195. /// 星历位置误差(单位米)
  196. /// </summary>
  197. public double SatLocErr { get; set; } = 10000;
  198. }
  199. }