X2D1DTOParamEditor.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. using DevExpress.XtraMap;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.CodeDom;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Data.Entity;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using XdCxRhDW.Api;
  15. using XdCxRhDW.Dto;
  16. using XdCxRhDW.Entity;
  17. using XdCxRhDW.Repostory;
  18. namespace XdCxRhDW.App.EditForms
  19. {
  20. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. private MapControl mapControl1;
  23. private PosRes info;
  24. private CgRes cg;
  25. private List<SatInfo> listSat;
  26. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  27. {
  28. InitializeComponent();
  29. this.info = info;
  30. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  31. this.layoutControl1.UseDefault();
  32. txtSigTime.UseDefault();
  33. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  34. this.listSat = new List<SatInfo>();
  35. this.mapControl1 = mapControl;
  36. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  37. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  38. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  39. }
  40. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  41. {
  42. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  43. }
  44. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  45. {
  46. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  47. }
  48. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  49. {
  50. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  51. }
  52. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  53. {
  54. StationRes station = null;
  55. using (RHDWContext db = new RHDWContext())
  56. {
  57. listSat = await db.SatInfos.ToListAsync();
  58. }
  59. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  60. {
  61. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  62. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  63. }
  64. if (cg != null)
  65. {
  66. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  67. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  68. if (info.PosResType == EnumPosResType.X2D1)
  69. {
  70. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  71. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  72. }
  73. this.txtSigTime.EditValue = info.SigTime;
  74. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  75. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  76. }
  77. if (station != null)
  78. {
  79. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  80. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  81. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  82. }
  83. if (info.PosResType == EnumPosResType.X2D1NoRef)
  84. {
  85. txtYbMain.Properties.ReadOnly = true;
  86. txtYbAdja.Properties.ReadOnly = true;
  87. txtRefLocation.Properties.ReadOnly = true;
  88. this.txtRefLocation.Text = $"{0},{0}";
  89. }
  90. //double tarLon = 46, tarLat = 24;
  91. //double recLon = 45.9, recLat = 23.9;
  92. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  93. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  94. //var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value);
  95. //var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value);
  96. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef);
  97. //var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef);
  98. //var dto1 = (dt1 - dt2) * 1e6;
  99. //var dt3 = PhysicsHelper.Dto(tarEcef, recEcef);
  100. //var dto2 = (dt1 - dt3) * 1e6;
  101. }
  102. public bool CheckDtoLineParam()
  103. {
  104. dxErrorProvider.ClearErrors();
  105. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  106. {
  107. return false;
  108. }
  109. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  110. {
  111. return false;
  112. }
  113. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  114. {
  115. return false;
  116. }
  117. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  118. {
  119. return false;
  120. }
  121. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  122. {
  123. return false;
  124. }
  125. if (info.PosResType == EnumPosResType.X2D1 && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  126. {
  127. return false;
  128. }
  129. if (info.PosResType == EnumPosResType.X2D1 && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  130. {
  131. return false;
  132. }
  133. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  134. {
  135. return false;
  136. }
  137. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  138. {
  139. return false;
  140. }
  141. return true;
  142. }
  143. public bool CheckPosParam()
  144. {
  145. dxErrorProvider.ClearErrors();
  146. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  147. {
  148. return false;
  149. }
  150. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  151. {
  152. return false;
  153. }
  154. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  155. {
  156. return false;
  157. }
  158. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  159. {
  160. return false;
  161. }
  162. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  163. {
  164. return false;
  165. }
  166. if (info.PosResType == EnumPosResType.X2D1 && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  167. {
  168. return false;
  169. }
  170. if (info.PosResType == EnumPosResType.X2D1 && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  171. {
  172. return false;
  173. }
  174. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  175. {
  176. return false;
  177. }
  178. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  179. {
  180. return false;
  181. }
  182. return true;
  183. }
  184. private void btnDtoLine_Click(object sender, EventArgs e)
  185. {
  186. if (!CheckDtoLineParam()) { return; }
  187. try
  188. {
  189. var MsAnt = txtsatStation.GetLonLat();
  190. var CDBAnt = txtcdbStation.GetLonLat();
  191. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  192. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  193. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  194. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  195. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  196. double[] msEph = ucEphXYZMain.EphXYZ();
  197. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  198. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  199. dtoLineXd.MsEph = msEph;
  200. dtoLineXd.MsAnt = MsAnt;
  201. dtoLineXd.CDBAnt = CDBAnt;
  202. dtoLineXd.RefGeod = RefGeod;
  203. dtoLineXd.xdDto = DtoCdb;
  204. dtoLineXd.RefDto = YbMainDto;
  205. dtoLineXd.PosLon = info.PosLon;
  206. dtoLineXd.PosLat = info.PosLat;
  207. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  208. twoStartOption.MsEph = msEph;
  209. twoStartOption.NsEph = NsEph;
  210. twoStartOption.MsAnt = MsAnt;
  211. twoStartOption.NsAnt = MsAnt;
  212. twoStartOption.RefGeod = RefGeod;
  213. twoStartOption.TargetDto = DtoSx;
  214. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  215. twoStartOption.PosLon = info.PosLon;
  216. twoStartOption.PosLat = info.PosLat;
  217. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  218. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  219. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  220. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  221. if (info.PosResType == EnumPosResType.X2D1)
  222. {
  223. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  224. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  225. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  226. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  227. }
  228. else
  229. {
  230. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRef(dtoLineXd);
  231. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  232. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  233. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  239. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  240. }
  241. }
  242. private async void btnEphCalc_Click(object sender, EventArgs e)
  243. {
  244. dxErrorProvider.ClearErrors();
  245. if (this.txtSigTime.DateTime == DateTime.MinValue)
  246. {
  247. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  248. return;
  249. }
  250. var sigTime = this.txtSigTime.DateTime;
  251. try
  252. {
  253. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  254. if (mainxlInfo == null)
  255. {
  256. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  257. return;
  258. }
  259. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  260. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  261. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  262. if (adjaxlInfo == null)
  263. {
  264. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  265. return;
  266. }
  267. var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc());
  268. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.X, adjaeph.Y, adjaeph.Z), Color.Red);
  269. }
  270. catch (Exception ex)
  271. {
  272. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  273. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  274. }
  275. }
  276. private void btnPos_Click(object sender, EventArgs e)
  277. {
  278. if (!CheckPosParam()) { return; }
  279. txtPosRes.Text = " ";
  280. try
  281. {
  282. var MsAnt = txtsatStation.GetLonLat();
  283. var CDBAnt = txtcdbStation.GetLonLat();
  284. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  285. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  286. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  287. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  288. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  289. double[] msEph = ucEphXYZMain.EphXYZ();
  290. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  291. var sigTime = txtSigTime.DateTime;
  292. var StationRes = new StationRes()
  293. {
  294. SatTxLon = MsAnt[0],
  295. SatTxLat = MsAnt[1],
  296. CdbTxLon = CDBAnt[0],
  297. CdbTxLat = CDBAnt[1],
  298. RefLon = RefGeod[0],
  299. RefLat = RefGeod[1],
  300. };
  301. if (info.PosResType == EnumPosResType.X2D1NoRef)
  302. {
  303. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  304. {
  305. SigTime = sigTime,
  306. MainCode = cg.MainCode.Value,
  307. AdjaCode = cg.Adja1Code.Value,
  308. SxDto = DtoSx,
  309. XdDto = DtoCdb,
  310. MainX = msEph[0],
  311. MainY = msEph[1],
  312. MainZ = msEph[2],
  313. AdjaX = nsEph[0],
  314. AdjaY = nsEph[1],
  315. AdjaZ = nsEph[2],
  316. SatTxLon = MsAnt[0],
  317. SatTxLat = MsAnt[1],
  318. CdbTxLon = CDBAnt[0],
  319. CdbTxLat = CDBAnt[1],
  320. };
  321. var cgRes = new CgRes()
  322. {
  323. SigTime = dto.SigTime,
  324. Dto1 = dto.SxDto,
  325. Dfo1 = dto.SxDfo,
  326. Snr1 = dto.SxSnr,
  327. DtoCdb = dto.XdDto,
  328. DfoCdb = dto.XdDfo,
  329. SnrCdb = dto.XdSnr,
  330. //StationResID = StationRes.ID,
  331. MainCode = dto.MainCode,
  332. Adja1Code = dto.AdjaCode,
  333. //TaskID = runTask.ID,
  334. MainX = dto.MainX,
  335. MainY = dto.MainY,
  336. MainZ = dto.MainZ,
  337. Adja1X = dto.AdjaX,
  338. Adja1Y = dto.AdjaY,
  339. Adja1Z = dto.AdjaZ,
  340. };
  341. var res = PosApi.X2D1_PosNoRef(cgRes, StationRes);
  342. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  343. }
  344. else
  345. {
  346. X2D1PosDto dto = new X2D1PosDto()
  347. {
  348. SigTime = sigTime,
  349. MainCode = cg.MainCode.Value,
  350. AdjaCode = cg.Adja1Code.Value,
  351. SxDto = DtoSx,
  352. XdDto = DtoCdb,
  353. MainYbDto = YbMainDto,
  354. AdjaYbDto = YbAdja1Dto,
  355. MainX = msEph[0],
  356. MainY = msEph[1],
  357. MainZ = msEph[2],
  358. AdjaX = nsEph[0],
  359. AdjaY = nsEph[1],
  360. AdjaZ = nsEph[2],
  361. SatTxLon = MsAnt[0],
  362. SatTxLat = MsAnt[1],
  363. CdbTxLon = CDBAnt[0],
  364. CdbTxLat = CDBAnt[1],
  365. RefLon = RefGeod[0],
  366. RefLat = RefGeod[1],
  367. };
  368. var cgRes = new CgRes()
  369. {
  370. SigTime = dto.SigTime,
  371. Dto1 = dto.SxDto,
  372. Dfo1 = dto.SxDfo,
  373. Snr1 = dto.SxSnr,
  374. DtoCdb = dto.XdDto,
  375. DfoCdb = dto.XdDfo,
  376. SnrCdb = dto.XdSnr,
  377. YbMainDto = dto.MainYbDto,
  378. YbAdja1Dto = dto.AdjaYbDto,
  379. //StationResID = StationRes.ID,
  380. MainCode = dto.MainCode,
  381. Adja1Code = dto.AdjaCode,
  382. // TaskID = runTask.ID,
  383. MainX = dto.MainX,
  384. MainY = dto.MainY,
  385. MainZ = dto.MainZ,
  386. Adja1X = dto.AdjaX,
  387. Adja1Y = dto.AdjaY,
  388. Adja1Z = dto.AdjaZ,
  389. };
  390. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  391. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  392. }
  393. }
  394. catch (Exception ex)
  395. {
  396. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  397. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  398. }
  399. }
  400. }
  401. }