X3DfoPosParamEditor.cs 9.7 KB

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