X3DfoPosParamEditor.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. private SysSetings settings = new SysSetings();
  28. public X3DfoPosParamEditor(PosRes info)
  29. {
  30. InitializeComponent();
  31. this.info = info;
  32. this.labelControl1.Text = $"";
  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. settings = await db.SysSetings.FirstOrDefaultAsync();
  50. }
  51. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  52. {
  53. if (db.DatabaseExist)
  54. {
  55. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  56. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  57. }
  58. }
  59. if (cg != null)
  60. {
  61. this.txtDfoSx.Text = $"{cg.Dfo1.Value:f4}";
  62. this.txtDfoSx1.Text = $"{cg.Dfo2.Value:f4}";
  63. this.txtYbMain.Text = $"{cg.YbMainDfo.Value:f4}";
  64. this.txtYbAdja.Text = $"{cg.YbAdja1Dfo.Value:f4}";
  65. this.txtYbAdja1.Text = $"{cg.YbAdja2Dfo.Value:f4}";
  66. this.sigTime.EditValue = info.SigTime;
  67. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  68. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  69. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  70. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  71. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  72. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  73. this.txtTargetFreq.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
  74. this.txtTargetDFreq.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 950;
  75. this.txtRefFreq.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
  76. this.txtRefDFreq.EditValue = cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value * 1e-6 : 950;
  77. }
  78. if (station != null)
  79. {
  80. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  81. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  82. }
  83. if (info.PosResType == EnumPosResType.X3NoRef)
  84. {
  85. txtYbMain.Properties.ReadOnly = true;
  86. txtYbAdja.Properties.ReadOnly = true;
  87. txtYbAdja1.Properties.ReadOnly = true;
  88. txtRefLocation.Properties.ReadOnly = true;
  89. this.txtRefLocation.Text = $"{0},{0}";
  90. }
  91. }
  92. public bool CheckParam()
  93. {
  94. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  95. {
  96. return false;
  97. }
  98. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  99. {
  100. return false;
  101. }
  102. return true;
  103. }
  104. private void btnOk_Click(object sender, EventArgs e)
  105. {
  106. if (!CheckParam()) { return; }
  107. try
  108. {
  109. var MsAnt = txtsatStation.GetLonLat();
  110. var RefGeod = txtRefLocation.GetLonLat();
  111. var sigTime = this.sigTime.DateTime;
  112. var DfoSx = Convert.ToDouble(this.txtDfoSx.Text);
  113. var DfoSx1 = Convert.ToDouble(this.txtDfoSx1.Text);
  114. var YbMainDfo = Convert.ToDouble(this.txtYbMain.Text);
  115. var YbAdja1Dfo = Convert.ToDouble(this.txtYbAdja.Text);
  116. var YbAdja2Dfo = Convert.ToDouble(this.txtYbAdja1.Text);
  117. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  118. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  119. var rFreq = Convert.ToDouble(this.txtRefFreq.Text) * 1e6;
  120. var rdFreq = Convert.ToDouble(this.txtRefDFreq.Text) * 1e6;
  121. var msEph = ucEphXYZMain.EphParam();
  122. var ns1Eph = ucEphXYZAdja1.EphParam();
  123. var ns2Eph = ucEphXYZAdja2.EphParam();
  124. var StationRes = new StationRes()
  125. {
  126. SatTxLon = MsAnt[0],
  127. SatTxLat = MsAnt[1],
  128. RefLon = RefGeod[0],
  129. RefLat = RefGeod[1],
  130. };
  131. var cgRes = new CgRes()
  132. {
  133. SigTime = sigTime,
  134. Dfo1 = DfoSx,
  135. Dfo2 = DfoSx1,
  136. YbMainDfo = YbMainDfo,
  137. YbAdja1Dfo = YbAdja1Dfo,
  138. YbAdja2Dfo = YbAdja2Dfo,
  139. TarFreqUp = tFreq,
  140. TarFreqDown = tdFreq,
  141. RefFreqUp = rFreq,
  142. RefFreqDown = rdFreq,
  143. MainX = msEph[0],
  144. MainY = msEph[1],
  145. MainZ = msEph[2],
  146. MainVx = msEph[3],
  147. MainVy = msEph[4],
  148. MainVz = msEph[5],
  149. Adja1X = ns1Eph[0],
  150. Adja1Y = ns1Eph[1],
  151. Adja1Z = ns1Eph[2],
  152. Adja1Vx = ns1Eph[3],
  153. Adja1Vy = ns1Eph[4],
  154. Adja1Vz = ns1Eph[5],
  155. Adja2X = ns2Eph[0],
  156. Adja2Y = ns2Eph[1],
  157. Adja2Z = ns2Eph[2],
  158. Adja2Vx = ns2Eph[3],
  159. Adja2Vy = ns2Eph[4],
  160. Adja2Vz = ns2Eph[5],
  161. };
  162. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes);
  163. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  164. }
  165. catch (Exception ex)
  166. {
  167. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  168. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  169. }
  170. }
  171. private async void btnXl_Click(object sender, EventArgs e)
  172. {
  173. if (this.sigTime.DateTime == DateTime.MinValue)
  174. {
  175. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  176. return;
  177. }
  178. var sigTime = this.sigTime.DateTime;
  179. try
  180. {
  181. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  182. if (xlInfo == null)
  183. {
  184. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  185. return;
  186. }
  187. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  188. if (xlInfo1 == null)
  189. {
  190. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  191. return;
  192. }
  193. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  194. if (xlInfo2 == null)
  195. {
  196. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  197. return;
  198. }
  199. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  200. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime);
  201. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime);
  202. var mainEph = (mEph.X, mEph.Y, mEph.Z, mEph.VX, mEph.VY, mEph.VZ);
  203. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Red);
  204. var adja1Eph = (nEph1.X, nEph1.Y, nEph1.Z, nEph1.VX, nEph1.VY, nEph1.VZ);
  205. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  206. var adja2Eph = (nEph2.X, nEph2.Y, nEph2.Z, nEph2.VX, nEph2.VY, nEph2.VZ);
  207. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  208. }
  209. catch (Exception ex)
  210. {
  211. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  212. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  213. }
  214. }
  215. }
  216. }