X3DfoPosParamEditor.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.layoutControl1.UseDefault();
  31. sigTime.UseDefault();
  32. this.info = info;
  33. this.labelControl1.Text = $"";
  34. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  35. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  36. }
  37. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  38. {
  39. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  40. }
  41. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  42. {
  43. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  44. }
  45. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  46. {
  47. StationRes station = null;
  48. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  49. {
  50. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  51. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  52. }
  53. if (cg != null)
  54. {
  55. this.txtDfoSx.Text = $"{cg.Dfo1.Value:f4}";
  56. this.txtDfoSx1.Text = $"{cg.Dfo2.Value:f4}";
  57. this.txtYbMain.Text = $"{cg.YbMainDfo.Value:f4}";
  58. this.txtYbAdja.Text = $"{cg.YbAdja1Dfo.Value:f4}";
  59. this.txtYbAdja1.Text = $"{cg.YbAdja2Dfo.Value:f4}";
  60. this.sigTime.EditValue = info.SigTime;
  61. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  62. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  63. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  64. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  65. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  66. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  67. this.txtTargetFreq.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
  68. this.txtTargetDFreq.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 950;
  69. this.txtRefFreq.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
  70. this.txtRefDFreq.EditValue = cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value * 1e-6 : 950;
  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 = txtRefLocation.GetLonLat();
  105. var sigTime = this.sigTime.DateTime;
  106. var DfoSx = Convert.ToDouble(this.txtDfoSx.Text);
  107. var DfoSx1 = Convert.ToDouble(this.txtDfoSx1.Text);
  108. var YbMainDfo = Convert.ToDouble(this.txtYbMain.Text);
  109. var YbAdja1Dfo = Convert.ToDouble(this.txtYbAdja.Text);
  110. var YbAdja2Dfo = Convert.ToDouble(this.txtYbAdja1.Text);
  111. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  112. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  113. var rFreq = Convert.ToDouble(this.txtRefFreq.Text) * 1e6;
  114. var rdFreq = Convert.ToDouble(this.txtRefDFreq.Text) * 1e6;
  115. var msEph = ucEphXYZMain.EphParam();
  116. var ns1Eph = ucEphXYZAdja1.EphParam();
  117. var ns2Eph = ucEphXYZAdja2.EphParam();
  118. var StationRes = new StationRes()
  119. {
  120. SatTxLon = MsAnt[0],
  121. SatTxLat = MsAnt[1],
  122. RefLon = RefGeod[0],
  123. RefLat = RefGeod[1],
  124. };
  125. var cgRes = new CgRes()
  126. {
  127. SigTime = sigTime,
  128. Dfo1 = DfoSx,
  129. Dfo2 = DfoSx1,
  130. YbMainDfo = YbMainDfo,
  131. YbAdja1Dfo = YbAdja1Dfo,
  132. YbAdja2Dfo = YbAdja2Dfo,
  133. TarFreqUp = tFreq,
  134. TarFreqDown = tdFreq,
  135. RefFreqUp = rFreq,
  136. RefFreqDown = rdFreq,
  137. MainX = msEph[0],
  138. MainY = msEph[1],
  139. MainZ = msEph[2],
  140. MainVx = msEph[3],
  141. MainVy = msEph[4],
  142. MainVz = msEph[5],
  143. Adja1X = ns1Eph[0],
  144. Adja1Y = ns1Eph[1],
  145. Adja1Z = ns1Eph[2],
  146. Adja1Vx = ns1Eph[3],
  147. Adja1Vy = ns1Eph[4],
  148. Adja1Vz = ns1Eph[5],
  149. Adja2X = ns2Eph[0],
  150. Adja2Y = ns2Eph[1],
  151. Adja2Z = ns2Eph[2],
  152. Adja2Vx = ns2Eph[3],
  153. Adja2Vy = ns2Eph[4],
  154. Adja2Vz = ns2Eph[5],
  155. };
  156. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes);
  157. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  158. }
  159. catch (Exception ex)
  160. {
  161. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  162. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  163. }
  164. }
  165. private async void btnXl_Click(object sender, EventArgs e)
  166. {
  167. if (this.sigTime.DateTime == DateTime.MinValue)
  168. {
  169. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  170. return;
  171. }
  172. var sigTime = this.sigTime.DateTime;
  173. try
  174. {
  175. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  176. if (xlInfo == null)
  177. {
  178. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  179. return;
  180. }
  181. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  182. if (xlInfo1 == null)
  183. {
  184. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  185. return;
  186. }
  187. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  188. if (xlInfo2 == null)
  189. {
  190. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  191. return;
  192. }
  193. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime.ToUtc());
  194. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime.ToUtc());
  195. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime.ToUtc());
  196. var mainEph = (mEph.X, mEph.Y, mEph.Z, mEph.VX, mEph.VY, mEph.VZ);
  197. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Red);
  198. var adja1Eph = (nEph1.X, nEph1.Y, nEph1.Z, nEph1.VX, nEph1.VY, nEph1.VZ);
  199. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  200. var adja2Eph = (nEph2.X, nEph2.Y, nEph2.Z, nEph2.VX, nEph2.VY, nEph2.VZ);
  201. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  202. }
  203. catch (Exception ex)
  204. {
  205. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  206. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  207. }
  208. }
  209. }
  210. }