X2D1DTOParamEditor.cs 19 KB

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