X2D1DTOParamEditor.cs 21 KB

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