X3DTOParamEditor.cs 9.8 KB

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