X3DfoParamEditor.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. using DevExpress.XtraMap;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Linq;
  7. using DW5S.KxcApi;
  8. using DW5S.DTO;
  9. using DW5S.Entity;
  10. using DW5S.Repostory;
  11. using Microsoft.EntityFrameworkCore;
  12. namespace DW5S.App.EditForms
  13. {
  14. public partial class X3DfoParamEditor : DevExpress.XtraEditors.XtraUserControl
  15. {
  16. private PosRes info;
  17. private CgRes cg;
  18. private MapControl mapControl1;
  19. private List<SatInfo> listSat;
  20. StationRes station;
  21. public X3DfoParamEditor(PosRes info, MapControl mapControl)
  22. {
  23. InitializeComponent();
  24. this.info = info;
  25. this.mapControl1 = mapControl;
  26. itemSigTime.Text = $"{itemSigTime.Text}";
  27. this.layoutControl1.UseDefault();
  28. sigTime.UseDefault();
  29. this.simpleLabelItem1.Text = $" ";
  30. }
  31. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  32. {
  33. this.layoutControl1.BestFit();
  34. using (OracleContext db = new OracleContext())
  35. {
  36. listSat = await db.SatInfos.ToListAsync();
  37. cg = await db?.CgRes.Where(m =>m.TaskID==info.TaskInfoID&& m.Id == info.CgResID).FirstOrDefaultAsync();
  38. station = await db?.StationRes.Where(m => m.TaskID == info.TaskInfoID && m.Id == info.StationResID).FirstOrDefaultAsync();
  39. }
  40. if (cg != null)
  41. {
  42. this.txtDfo1.Text = $"{cg.Dfo1.Value}";
  43. this.txtDfo2.Text = $"{cg.Dfo2.Value}";
  44. this.txtYbDfo1.Text = $"{cg.YbMainDfo.Value}";
  45. this.txtYbDfo2.Text = $"{cg.YbAdja1Dfo.Value}";
  46. this.txtYbDfo3.Text = $"{cg.YbAdja2Dfo.Value}";
  47. this.sigTime.EditValue = info.SigTime;
  48. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  49. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  50. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  51. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  52. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
  53. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  54. this.txtTargetFreq.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 0;
  55. this.txtTargetDFreq.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 0;
  56. this.txtRefFreq.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 0;
  57. this.txtRefDFreq.EditValue = cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value * 1e-6 : 0;
  58. this.txtDto1.Text = cg.Dto1?.ToString();
  59. this.txtDto2.Text = cg.Dto2?.ToString();
  60. this.txtYbDto1.Text = cg.YbMainDto?.ToString();
  61. this.txtYbDto2.Text = cg.YbAdja1Dto?.ToString();
  62. this.txtYbDto3.Text = cg.YbAdja2Dto?.ToString();
  63. }
  64. if (station != null)
  65. {
  66. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  67. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  68. }
  69. if (info.PosResType == EnumPosResType.X3NoRef)
  70. {
  71. txtYbDfo1.Properties.ReadOnly = true;
  72. txtYbDfo2.Properties.ReadOnly = true;
  73. txtYbDfo3.Properties.ReadOnly = true;
  74. txtRefLocation.Properties.ReadOnly = true;
  75. this.txtRefLocation.Text = $"{0},{0}";
  76. }
  77. }
  78. public bool CheckDtoLineParam()
  79. {
  80. dxErrorProvider.ClearErrors();
  81. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  82. {
  83. return false;
  84. }
  85. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  86. {
  87. return false;
  88. }
  89. if (!txtDto1.CheckDouble(dxErrorProvider, "主邻1时差"))
  90. {
  91. return false;
  92. }
  93. if (!txtDto2.CheckDouble(dxErrorProvider, "主邻2时差"))
  94. {
  95. return false;
  96. }
  97. if (!txtYbDto1.CheckDouble(dxErrorProvider, "样本主星时差"))
  98. {
  99. return false;
  100. }
  101. if (!txtYbDto2.CheckDouble(dxErrorProvider, "样本邻星1时差"))
  102. {
  103. return false;
  104. }
  105. if (!txtYbDto3.CheckDouble(dxErrorProvider, "样本邻星2时差"))
  106. {
  107. return false;
  108. }
  109. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  110. {
  111. return false;
  112. }
  113. if (!ucEphXYZAdja1.CheckEphXYZ(dxErrorProvider))
  114. {
  115. return false;
  116. }
  117. if (!ucEphXYZAdja2.CheckEphXYZ(dxErrorProvider))
  118. {
  119. return false;
  120. }
  121. return true;
  122. }
  123. public bool CheckPosParam()
  124. {
  125. dxErrorProvider.ClearErrors();
  126. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  127. {
  128. return false;
  129. }
  130. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  131. {
  132. return false;
  133. }
  134. if (!txtDfo1.CheckDouble(dxErrorProvider, "主邻1频差"))
  135. {
  136. return false;
  137. }
  138. if (!txtDfo2.CheckDouble(dxErrorProvider, "主邻2频差"))
  139. {
  140. return false;
  141. }
  142. if (!txtYbDfo1.CheckDouble(dxErrorProvider, "样本主星频差"))
  143. {
  144. return false;
  145. }
  146. if (!txtYbDfo2.CheckDouble(dxErrorProvider, "样本邻星1频差"))
  147. {
  148. return false;
  149. }
  150. if (!txtYbDfo3.CheckDouble(dxErrorProvider, "样本邻星2频差"))
  151. {
  152. return false;
  153. }
  154. if (!txtTargetFreq.CheckDouble(dxErrorProvider, "目标上行频点"))
  155. {
  156. return false;
  157. }
  158. if (!txtTargetDFreq.CheckDouble(dxErrorProvider, "目标下行频点"))
  159. {
  160. return false;
  161. }
  162. if (!txtRefFreq.CheckDouble(dxErrorProvider, "参考上行频点"))
  163. {
  164. return false;
  165. }
  166. if (!txtRefDFreq.CheckDouble(dxErrorProvider, "参考下行频点"))
  167. {
  168. return false;
  169. }
  170. if (!ucEphXYZMain.CheckEph(dxErrorProvider))
  171. {
  172. return false;
  173. }
  174. if (!ucEphXYZAdja1.CheckEph(dxErrorProvider))
  175. {
  176. return false;
  177. }
  178. if (!ucEphXYZAdja2.CheckEph(dxErrorProvider))
  179. {
  180. return false;
  181. }
  182. return true;
  183. }
  184. private void btnOk_Click(object sender, EventArgs e)
  185. {
  186. if (!CheckPosParam()) { return; }
  187. try
  188. {
  189. var MsAnt = txtsatStation.GetLonLat();
  190. var RefGeod = txtRefLocation.GetLonLat();
  191. var sigTime = this.sigTime.DateTime;
  192. var DfoSx = Convert.ToDouble(this.txtDfo1.Text);
  193. var DfoSx1 = Convert.ToDouble(this.txtDfo2.Text);
  194. var YbMainDfo = Convert.ToDouble(this.txtYbDfo1.Text);
  195. var YbAdja1Dfo = Convert.ToDouble(this.txtYbDfo2.Text);
  196. var YbAdja2Dfo = Convert.ToDouble(this.txtYbDfo3.Text);
  197. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  198. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  199. var rFreq = Convert.ToDouble(this.txtRefFreq.Text) * 1e6;
  200. var rdFreq = Convert.ToDouble(this.txtRefDFreq.Text) * 1e6;
  201. var msEph = ucEphXYZMain.EphParam();
  202. var ns1Eph = ucEphXYZAdja1.EphParam();
  203. var ns2Eph = ucEphXYZAdja2.EphParam();
  204. var StationRes = new StationRes()
  205. {
  206. SatTxLon = MsAnt[0],
  207. SatTxLat = MsAnt[1],
  208. RefLon = RefGeod[0],
  209. RefLat = RefGeod[1],
  210. };
  211. var cgRes = new CgRes()
  212. {
  213. SigTime = sigTime,
  214. Dfo1 = DfoSx,
  215. Dfo2 = DfoSx1,
  216. YbMainDfo = YbMainDfo,
  217. YbAdja1Dfo = YbAdja1Dfo,
  218. YbAdja2Dfo = YbAdja2Dfo,
  219. TarFreqUp = tFreq,
  220. TarFreqDown = tdFreq,
  221. RefFreqUp = rFreq,
  222. RefFreqDown = rdFreq,
  223. MainX = msEph[0],
  224. MainY = msEph[1],
  225. MainZ = msEph[2],
  226. MainVx = msEph[3],
  227. MainVy = msEph[4],
  228. MainVz = msEph[5],
  229. Adja1X = ns1Eph[0],
  230. Adja1Y = ns1Eph[1],
  231. Adja1Z = ns1Eph[2],
  232. Adja1Vx = ns1Eph[3],
  233. Adja1Vy = ns1Eph[4],
  234. Adja1Vz = ns1Eph[5],
  235. Adja2X = ns2Eph[0],
  236. Adja2Y = ns2Eph[1],
  237. Adja2Z = ns2Eph[2],
  238. Adja2Vx = ns2Eph[3],
  239. Adja2Vy = ns2Eph[4],
  240. Adja2Vz = ns2Eph[5],
  241. };
  242. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes);
  243. this.simpleLabelItem1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  244. }
  245. catch (Exception ex)
  246. {
  247. DW5S.Framework.LogHelper.Error($"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  248. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  249. }
  250. }
  251. private async void btnXl_Click(object sender, EventArgs e)
  252. {
  253. dxErrorProvider.ClearErrors();
  254. if (this.sigTime.DateTime == DateTime.MinValue)
  255. {
  256. dxErrorProvider.SetError(this.sigTime, "信号时间不能为空!");
  257. return;
  258. }
  259. var sigTime = this.sigTime.DateTime;
  260. try
  261. {
  262. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  263. if (xlInfo == null)
  264. {
  265. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  266. return;
  267. }
  268. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  269. if (xlInfo1 == null)
  270. {
  271. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  272. return;
  273. }
  274. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  275. if (xlInfo2 == null)
  276. {
  277. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  278. return;
  279. }
  280. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, SigTime = sigTime };
  281. var mEph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  282. XlCalcDto.tleStr = xlInfo1.TwoLine;
  283. var nEph1 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  284. XlCalcDto.tleStr = xlInfo2.TwoLine;
  285. var nEph2 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  286. var mainEph = (mEph.data.X, mEph.data.Y, mEph.data.Z, mEph.data.VX, mEph.data.VY, mEph.data.VZ);
  287. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Red);
  288. var adja1Eph = (nEph1.data.X, nEph1.data.Y, nEph1.data.Z, nEph1.data.VX, nEph1.data.VY, nEph1.data.VZ);
  289. ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  290. var adja2Eph = (nEph2.data.X, nEph2.data.Y, nEph2.data.Z, nEph2.data.VX, nEph2.data.VY, nEph2.data.VZ);
  291. ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  292. }
  293. catch (Exception ex)
  294. {
  295. DW5S.Framework.LogHelper.Error($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  296. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败,{ex.Message}");
  297. }
  298. }
  299. private void btnDtoCalc_Click(object sender, EventArgs e)
  300. {
  301. if (!CheckDtoLineParam()) { return; }
  302. try
  303. {
  304. var MsAnt = txtsatStation.GetLonLat();
  305. var RefGeod = txtRefLocation.GetLonLat();
  306. var DtoSx = Convert.ToDouble(this.txtDto1.Text);
  307. var DtoSx1 = Convert.ToDouble(this.txtDto2.Text);
  308. var YbMainDto = Convert.ToDouble(this.txtYbDto1.Text);
  309. var YbAdja1Dto = Convert.ToDouble(this.txtYbDto2.Text);
  310. var YbAdja2Dto = Convert.ToDouble(this.txtYbDto3.Text);
  311. double[] msEph = ucEphXYZMain.EphXYZ();
  312. double[] Ns1Eph = ucEphXYZAdja1.EphXYZ();
  313. double[] Ns2Eph = ucEphXYZAdja2.EphXYZ();
  314. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  315. twoStartOption.MsEph = msEph;
  316. twoStartOption.NsEph = Ns1Eph;
  317. twoStartOption.MsAnt = MsAnt;
  318. twoStartOption.NsAnt = MsAnt;
  319. twoStartOption.RefGeod = RefGeod;
  320. twoStartOption.TargetDto = DtoSx;
  321. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  322. twoStartOption.PosLon = info.PosLon;
  323. twoStartOption.PosLat = info.PosLat;
  324. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  325. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  326. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  327. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  328. var ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  329. if (string.IsNullOrWhiteSpace(ad2sat)) ad2sat = cg.Adja2Code.Value.ToString();
  330. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  331. mapControl1.DrawDtoLine($"[{msat},{nsat}]带参时差线", tsDtoLine);
  332. twoStartOption.NsEph = Ns2Eph;
  333. twoStartOption.RefDto = YbMainDto - YbAdja2Dto;
  334. twoStartOption.TargetDto = DtoSx1;
  335. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  336. mapControl1.DrawDtoLine($"[{msat},{ad2sat}]带参时差线", tsDtoLine1);
  337. }
  338. catch (Exception ex)
  339. {
  340. DW5S.Framework.LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  341. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  342. }
  343. }
  344. private void btnDfoCalc_Click(object sender, EventArgs e)
  345. {
  346. if (!CheckPosParam()) { return; }
  347. try
  348. {
  349. var MsAnt = txtsatStation.GetLonLat();
  350. var RefGeod = txtRefLocation.GetLonLat();
  351. var sigTime = this.sigTime.DateTime;
  352. var DfoSx = Convert.ToDouble(this.txtDfo1.Text);
  353. var DfoSx1 = Convert.ToDouble(this.txtDfo2.Text);
  354. var YbMainDfo = Convert.ToDouble(this.txtYbDfo1.Text);
  355. var YbAdja1Dfo = Convert.ToDouble(this.txtYbDfo2.Text);
  356. var YbAdja2Dfo = Convert.ToDouble(this.txtYbDfo3.Text);
  357. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  358. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  359. var rFreq = Convert.ToDouble(this.txtRefFreq.Text) * 1e6;
  360. var rdFreq = Convert.ToDouble(this.txtRefDFreq.Text) * 1e6;
  361. var msEph = ucEphXYZMain.EphParam();
  362. var ns1Eph = ucEphXYZAdja1.EphParam();
  363. var ns2Eph = ucEphXYZAdja2.EphParam();
  364. DfoLineTwoStartOption twoStartOption = new DfoLineTwoStartOption();
  365. twoStartOption.Freq = tFreq;
  366. twoStartOption.RefFreq = rFreq;
  367. twoStartOption.MsEph = msEph;
  368. twoStartOption.NsEph = ns1Eph;
  369. twoStartOption.MsAnt = MsAnt;
  370. twoStartOption.NsAnt = MsAnt;
  371. twoStartOption.RefGeod = RefGeod;
  372. twoStartOption.TargetDfo = DfoSx;
  373. twoStartOption.Turn1 = Math.Abs(twoStartOption.Freq - tdFreq);
  374. twoStartOption.Turn2 = Math.Abs(twoStartOption.RefFreq - rdFreq);
  375. twoStartOption.RefDfo = YbMainDfo - YbAdja1Dfo;
  376. var tsDtoLine = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  377. var msat = listSat?.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat; ;
  378. var ad1sat = listSat?.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  379. if (msat == null) msat = cg.MainCode.ToString();
  380. if (ad1sat == null) ad1sat = cg.Adja1Code.ToString();
  381. mapControl1.DrawDtoLine($"{info.PosResType.GetEnumDisplayName()}[{msat},{ad1sat}]频差线", tsDtoLine);
  382. twoStartOption.NsEph = ns2Eph;
  383. twoStartOption.TargetDfo = DfoSx1;
  384. twoStartOption.RefDfo = YbMainDfo - YbAdja2Dfo;
  385. var tsDtoLine1 = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
  386. string ad2sat = string.Empty;
  387. if (cg.Adja2Code.HasValue)
  388. {
  389. ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  390. }
  391. mapControl1.DrawDtoLine($"{info.PosResType.GetEnumDisplayName()}[{msat},{ad2sat}]频差线", tsDtoLine1);
  392. }
  393. catch (Exception ex)
  394. {
  395. DW5S.Framework.LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}频差线失败.PosID={info.ID},SigTime={sigTime}", ex);
  396. DxHelper.MsgBoxHelper.ShowError($"绘制{info.PosResType.GetEnumDisplayName()}频差线失败,{ex.Message}");
  397. }
  398. }
  399. }
  400. }