X3DfoPosParamEditor.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using DevExpress.XtraMap;
  2. using DevExpress.XtraTreeList.Data;
  3. using DxHelper;
  4. using ExtensionsDev;
  5. using System;
  6. using System.CodeDom;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Data.Entity;
  11. using System.Data.Entity.Migrations;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Documents;
  17. using System.Windows.Forms;
  18. using XdCxRhDW.Api;
  19. using XdCxRhDW.Entity;
  20. using XdCxRhDW.Repostory;
  21. namespace XdCxRhDW.App.EditForms
  22. {
  23. public partial class X3DfoPosParamEditor : DevExpress.XtraEditors.XtraUserControl
  24. {
  25. private PosRes info;
  26. private CgRes cg;
  27. public X3DfoPosParamEditor(PosRes info)
  28. {
  29. InitializeComponent();
  30. this.info = info;
  31. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  32. this.layoutControl1.UseDefault();
  33. sigTime.UseDefault();
  34. this.labelControl1.Text = $"";
  35. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  36. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  37. }
  38. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  39. {
  40. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  41. }
  42. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  43. {
  44. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  45. }
  46. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  47. {
  48. StationRes station = null;
  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.txtDfoSx.Text = $"{cg.Dfo1.Value:f4}";
  57. this.txtDfoSx1.Text = $"{cg.Dfo2.Value:f4}";
  58. this.txtYbMain.Text = $"{cg.YbMainDfo.Value:f4}";
  59. this.txtYbAdja.Text = $"{cg.YbAdja1Dfo.Value:f4}";
  60. this.txtYbAdja1.Text = $"{cg.YbAdja2Dfo.Value:f4}";
  61. this.sigTime.EditValue = info.SigTime;
  62. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  63. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  64. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  65. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  66. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  67. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  68. this.txtTargetFreq.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
  69. this.txtTargetDFreq.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 950;
  70. this.txtRefFreq.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
  71. this.txtRefDFreq.EditValue = cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value * 1e-6 : 950;
  72. }
  73. if (station != null)
  74. {
  75. this.txtsatStation.Text = $"{station.SatTxLon:f4},{station.SatTxLat:f4}";
  76. this.txtRefLocation.Text = $"{station.RefLon:f4},{station.RefLat:f4}";
  77. }
  78. if (info.PosResType == EnumPosResType.X3NoRef)
  79. {
  80. txtYbMain.Properties.ReadOnly = true;
  81. txtYbAdja.Properties.ReadOnly = true;
  82. txtYbAdja1.Properties.ReadOnly = true;
  83. txtRefLocation.Properties.ReadOnly = true;
  84. this.txtRefLocation.Text = $"{0},{0}";
  85. }
  86. }
  87. public bool CheckParam()
  88. {
  89. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  90. {
  91. return false;
  92. }
  93. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  94. {
  95. return false;
  96. }
  97. return true;
  98. }
  99. private void btnOk_Click(object sender, EventArgs e)
  100. {
  101. if (!CheckParam()) { return; }
  102. try
  103. {
  104. var MsAnt = txtsatStation.GetLonLat();
  105. var RefGeod = txtRefLocation.GetLonLat();
  106. var sigTime = this.sigTime.DateTime;
  107. var DfoSx = Convert.ToDouble(this.txtDfoSx.Text);
  108. var DfoSx1 = Convert.ToDouble(this.txtDfoSx1.Text);
  109. var YbMainDfo = Convert.ToDouble(this.txtYbMain.Text);
  110. var YbAdja1Dfo = Convert.ToDouble(this.txtYbAdja.Text);
  111. var YbAdja2Dfo = Convert.ToDouble(this.txtYbAdja1.Text);
  112. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  113. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  114. var rFreq = Convert.ToDouble(this.txtRefFreq.Text) * 1e6;
  115. var rdFreq = Convert.ToDouble(this.txtRefDFreq.Text) * 1e6;
  116. var msEph = ucEphXYZMain.EphParam();
  117. var ns1Eph = ucEphXYZAdja1.EphParam();
  118. var ns2Eph = ucEphXYZAdja2.EphParam();
  119. var StationRes = new StationRes()
  120. {
  121. SatTxLon = MsAnt[0],
  122. SatTxLat = MsAnt[1],
  123. RefLon = RefGeod[0],
  124. RefLat = RefGeod[1],
  125. };
  126. var cgRes = new CgRes()
  127. {
  128. SigTime = sigTime,
  129. Dfo1 = DfoSx,
  130. Dfo2 = DfoSx1,
  131. YbMainDfo = YbMainDfo,
  132. YbAdja1Dfo = YbAdja1Dfo,
  133. YbAdja2Dfo = YbAdja2Dfo,
  134. TarFreqUp = tFreq,
  135. TarFreqDown = tdFreq,
  136. RefFreqUp = rFreq,
  137. RefFreqDown = rdFreq,
  138. MainX = msEph[0],
  139. MainY = msEph[1],
  140. MainZ = msEph[2],
  141. MainVx = msEph[3],
  142. MainVy = msEph[4],
  143. MainVz = msEph[5],
  144. Adja1X = ns1Eph[0],
  145. Adja1Y = ns1Eph[1],
  146. Adja1Z = ns1Eph[2],
  147. Adja1Vx = ns1Eph[3],
  148. Adja1Vy = ns1Eph[4],
  149. Adja1Vz = ns1Eph[5],
  150. Adja2X = ns2Eph[0],
  151. Adja2Y = ns2Eph[1],
  152. Adja2Z = ns2Eph[2],
  153. Adja2Vx = ns2Eph[3],
  154. Adja2Vy = ns2Eph[4],
  155. Adja2Vz = ns2Eph[5],
  156. };
  157. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes);
  158. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  159. }
  160. catch (Exception ex)
  161. {
  162. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  163. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  164. }
  165. }
  166. private async void btnXl_Click(object sender, EventArgs e)
  167. {
  168. if (this.sigTime.DateTime == DateTime.MinValue)
  169. {
  170. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  171. return;
  172. }
  173. var sigTime = this.sigTime.DateTime;
  174. try
  175. {
  176. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  177. if (xlInfo == null)
  178. {
  179. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  180. return;
  181. }
  182. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  183. if (xlInfo1 == null)
  184. {
  185. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  186. return;
  187. }
  188. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  189. if (xlInfo2 == null)
  190. {
  191. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  192. return;
  193. }
  194. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime.ToUtc());
  195. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime.ToUtc());
  196. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime.ToUtc());
  197. var mainEph = (mEph.X, mEph.Y, mEph.Z, mEph.VX, mEph.VY, mEph.VZ);
  198. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Red);
  199. var adja1Eph = (nEph1.X, nEph1.Y, nEph1.Z, nEph1.VX, nEph1.VY, nEph1.VZ);
  200. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  201. var adja2Eph = (nEph2.X, nEph2.Y, nEph2.Z, nEph2.VX, nEph2.VY, nEph2.VZ);
  202. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  203. }
  204. catch (Exception ex)
  205. {
  206. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  207. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  208. }
  209. }
  210. }
  211. }