X2D1DTOParamEditor.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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 = 46, tarLat = 24;
  102. //double recLon = 45.9, recLat = 23.9;
  103. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  104. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  105. //var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value);
  106. //var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value);
  107. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef);
  108. //var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef);
  109. //var dto1 = (dt1 - dt2) * 1e6;
  110. //var dt3 = PhysicsHelper.Dto(tarEcef, recEcef);
  111. //var dto2 = (dt1 - dt3) * 1e6;
  112. }
  113. public bool CheckParam()
  114. {
  115. dxErrorProvider.ClearErrors();
  116. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  117. {
  118. return false;
  119. }
  120. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  121. {
  122. return false;
  123. }
  124. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  125. {
  126. return false;
  127. }
  128. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  129. {
  130. return false;
  131. }
  132. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  133. {
  134. return false;
  135. }
  136. if (info.PosResType == EnumPosResType.X2D1 && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  137. {
  138. return false;
  139. }
  140. if (info.PosResType == EnumPosResType.X2D1 && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  141. {
  142. return false;
  143. }
  144. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  145. {
  146. return false;
  147. }
  148. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  149. {
  150. return false;
  151. }
  152. return true;
  153. }
  154. private void btnDtoLine_Click(object sender, EventArgs e)
  155. {
  156. if (!CheckParam()) { return; }
  157. try
  158. {
  159. var MsAnt = txtsatStation.GetLonLat();
  160. var CDBAnt = txtcdbStation.GetLonLat();
  161. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  162. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  163. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  164. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  165. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  166. double[] msEph = ucEphXYZMain.EphXYZ();
  167. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  168. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  169. dtoLineXd.MsEph = msEph;
  170. dtoLineXd.MsAnt = MsAnt;
  171. dtoLineXd.CDBAnt = CDBAnt;
  172. dtoLineXd.RefGeod = RefGeod;
  173. dtoLineXd.xdDto = DtoCdb;
  174. dtoLineXd.RefDto = YbMainDto;
  175. dtoLineXd.PosLon = info.PosLon;
  176. dtoLineXd.PosLat = info.PosLat;
  177. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  178. twoStartOption.MsEph = msEph;
  179. twoStartOption.NsEph = NsEph;
  180. twoStartOption.MsAnt = MsAnt;
  181. twoStartOption.NsAnt = MsAnt;
  182. twoStartOption.RefGeod = RefGeod;
  183. twoStartOption.TargetDto = DtoSx;
  184. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  185. twoStartOption.PosLon = info.PosLon;
  186. twoStartOption.PosLat = info.PosLat;
  187. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  188. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  189. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  190. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  191. if (info.PosResType == EnumPosResType.X2D1)
  192. {
  193. //var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  194. //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  195. string useNewGDOP = ConfigurationManager.AppSettings["UseNewGDOP"];
  196. if (useNewGDOP == null || useNewGDOP == "0")
  197. {
  198. var xdDtoLine1 = DrawDtoLineHelper.DtoLineXdEx(dtoLineXd);
  199. mapControl1.DrawDtoLineTwo($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine1);
  200. }
  201. else
  202. {
  203. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
  204. List<MapPolyline> polylines = new List<MapPolyline>();
  205. foreach (var dtoLine in xdDtoLine)
  206. {
  207. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", dtoLine.dtoLinePoints);
  208. if (mapline == null)
  209. {
  210. continue;
  211. }
  212. polylines.Add(mapline);
  213. }
  214. mapControl1.DrawDtoLine(polylines);
  215. }
  216. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  217. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  218. }
  219. else
  220. {
  221. string useNewGDOP = ConfigurationManager.AppSettings["UseNewGDOP"];
  222. if (useNewGDOP == null || useNewGDOP == "0")
  223. {
  224. var xdDtoLine1 = DrawDtoLineHelper.DtoLineXdNoRefEx(dtoLineXd);
  225. mapControl1.DrawDtoLineTwo($"[{msat},超短{CDBAnt[0]}°]无参时差线", xdDtoLine1);
  226. }
  227. else
  228. {
  229. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRefNew(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);
  234. if (mapline == null)
  235. {
  236. continue;
  237. }
  238. polylines.Add(mapline);
  239. }
  240. mapControl1.DrawDtoLine(polylines);
  241. }
  242. //var xdDtoLine2 = DrawDtoLineHelper.DtoLineXdNoRefZl(dtoLineXd);
  243. //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]无参时差线zl", xdDtoLine2);
  244. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  245. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  246. //var tsDtoLine2 = DrawDtoLineHelper.DtoLine2XNoRefStartZl(twoStartOption);
  247. //mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线zl", tsDtoLine2);
  248. }
  249. }
  250. catch (Exception ex)
  251. {
  252. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  253. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  254. }
  255. }
  256. private async void btnEphCalc_Click(object sender, EventArgs e)
  257. {
  258. dxErrorProvider.ClearErrors();
  259. if (this.txtSigTime.DateTime == DateTime.MinValue)
  260. {
  261. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  262. return;
  263. }
  264. var sigTime = this.txtSigTime.DateTime;
  265. try
  266. {
  267. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  268. if (mainxlInfo == null)
  269. {
  270. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  271. return;
  272. }
  273. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  274. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  275. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  276. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  277. if (adjaxlInfo == null)
  278. {
  279. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  280. return;
  281. }
  282. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  283. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  284. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  285. }
  286. catch (Exception ex)
  287. {
  288. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  289. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  290. }
  291. }
  292. private void btnPos_Click(object sender, EventArgs e)
  293. {
  294. if (!CheckParam()) { return; }
  295. txtPosRes.Text = " ";
  296. try
  297. {
  298. var MsAnt = txtsatStation.GetLonLat();
  299. var CDBAnt = txtcdbStation.GetLonLat();
  300. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  301. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  302. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  303. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  304. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  305. double[] msEph = ucEphXYZMain.EphXYZ();
  306. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  307. var sigTime = txtSigTime.DateTime;
  308. var StationRes = new StationRes()
  309. {
  310. SatTxLon = MsAnt[0],
  311. SatTxLat = MsAnt[1],
  312. CdbTxLon = CDBAnt[0],
  313. CdbTxLat = CDBAnt[1],
  314. RefLon = RefGeod[0],
  315. RefLat = RefGeod[1],
  316. };
  317. if (info.PosResType == EnumPosResType.X2D1NoRef)
  318. {
  319. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  320. {
  321. SigTime = sigTime,
  322. MainCode = cg.MainCode.Value,
  323. AdjaCode = cg.Adja1Code.Value,
  324. SxDto = DtoSx,
  325. XdDto = DtoCdb,
  326. MainX = msEph[0],
  327. MainY = msEph[1],
  328. MainZ = msEph[2],
  329. AdjaX = nsEph[0],
  330. AdjaY = nsEph[1],
  331. AdjaZ = nsEph[2],
  332. SatTxLon = MsAnt[0],
  333. SatTxLat = MsAnt[1],
  334. CdbTxLon = CDBAnt[0],
  335. CdbTxLat = CDBAnt[1],
  336. };
  337. var cgRes = new CgRes()
  338. {
  339. SigTime = dto.SigTime,
  340. Dto1 = dto.SxDto,
  341. Dfo1 = dto.SxDfo,
  342. Snr1 = dto.SxSnr,
  343. DtoCdb = dto.XdDto,
  344. DfoCdb = dto.XdDfo,
  345. SnrCdb = dto.XdSnr,
  346. //StationResID = StationRes.ID,
  347. MainCode = dto.MainCode,
  348. Adja1Code = dto.AdjaCode,
  349. //TaskID = runTask.ID,
  350. MainX = dto.MainX,
  351. MainY = dto.MainY,
  352. MainZ = dto.MainZ,
  353. Adja1X = dto.AdjaX,
  354. Adja1Y = dto.AdjaY,
  355. Adja1Z = dto.AdjaZ,
  356. };
  357. double[] res;
  358. if (ConfigurationManager.AppSettings["UseNewPosX2D1"] != null
  359. && ConfigurationManager.AppSettings["UseNewPosX2D1"].ToLower() != "false"
  360. && ConfigurationManager.AppSettings["UseNewPosX2D1"].ToLower() != "0")
  361. {
  362. res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes);
  363. }
  364. else
  365. {
  366. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  367. }
  368. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  369. }
  370. else
  371. {
  372. X2D1PosDto dto = new X2D1PosDto()
  373. {
  374. SigTime = sigTime,
  375. MainCode = cg.MainCode.Value,
  376. AdjaCode = cg.Adja1Code.Value,
  377. SxDto = DtoSx,
  378. XdDto = DtoCdb,
  379. MainYbDto = YbMainDto,
  380. AdjaYbDto = YbAdja1Dto,
  381. MainX = msEph[0],
  382. MainY = msEph[1],
  383. MainZ = msEph[2],
  384. AdjaX = nsEph[0],
  385. AdjaY = nsEph[1],
  386. AdjaZ = nsEph[2],
  387. SatTxLon = MsAnt[0],
  388. SatTxLat = MsAnt[1],
  389. CdbTxLon = CDBAnt[0],
  390. CdbTxLat = CDBAnt[1],
  391. RefLon = RefGeod[0],
  392. RefLat = RefGeod[1],
  393. };
  394. var cgRes = new CgRes()
  395. {
  396. SigTime = dto.SigTime,
  397. Dto1 = dto.SxDto,
  398. Dfo1 = dto.SxDfo,
  399. Snr1 = dto.SxSnr,
  400. DtoCdb = dto.XdDto,
  401. DfoCdb = dto.XdDfo,
  402. SnrCdb = dto.XdSnr,
  403. YbMainDto = dto.MainYbDto,
  404. YbAdja1Dto = dto.AdjaYbDto,
  405. //StationResID = StationRes.ID,
  406. MainCode = dto.MainCode,
  407. Adja1Code = dto.AdjaCode,
  408. // TaskID = runTask.ID,
  409. MainX = dto.MainX,
  410. MainY = dto.MainY,
  411. MainZ = dto.MainZ,
  412. Adja1X = dto.AdjaX,
  413. Adja1Y = dto.AdjaY,
  414. Adja1Z = dto.AdjaZ,
  415. };
  416. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  417. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  418. }
  419. }
  420. catch (Exception ex)
  421. {
  422. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  423. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  424. }
  425. }
  426. }
  427. }