X3DTOParamEditor.cs 9.6 KB

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