X2D1DTOParamEditor.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. string useNewGDOP = ConfigurationManager.AppSettings["UseNewGDOP"];
  192. if (info.PosResType == EnumPosResType.X2D1)
  193. {
  194. //var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  195. //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  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, true);
  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. if (useNewGDOP == null || useNewGDOP == "0")
  222. {
  223. var xdDtoLine1 = DrawDtoLineHelper.DtoLineXdNoRefEx(dtoLineXd);
  224. mapControl1.DrawDtoLineTwo($"[{msat},超短{CDBAnt[0]}°]无参时差线", xdDtoLine1);
  225. }
  226. else
  227. {
  228. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRefNew(dtoLineXd);
  229. List<MapPolyline> polylines = new List<MapPolyline>();
  230. foreach (var dtoLine in xdDtoLine)
  231. {
  232. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]无参时差线", dtoLine.dtoLinePoints, true);
  233. if (mapline == null)
  234. {
  235. continue;
  236. }
  237. polylines.Add(mapline);
  238. }
  239. mapControl1.DrawDtoLine(polylines);
  240. }
  241. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  242. mapControl1.DrawDtoLine($"[{msat},{nsat}]无参时差线", tsDtoLine);
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  248. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  249. }
  250. }
  251. private async void btnEphCalc_Click(object sender, EventArgs e)
  252. {
  253. dxErrorProvider.ClearErrors();
  254. if (this.txtSigTime.DateTime == DateTime.MinValue)
  255. {
  256. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  257. return;
  258. }
  259. var sigTime = this.txtSigTime.DateTime;
  260. try
  261. {
  262. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  263. if (mainxlInfo == null)
  264. {
  265. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  266. return;
  267. }
  268. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  269. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  270. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  271. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  272. if (adjaxlInfo == null)
  273. {
  274. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  275. return;
  276. }
  277. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  278. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  279. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  280. }
  281. catch (Exception ex)
  282. {
  283. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  284. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  285. }
  286. }
  287. private void btnPos_Click(object sender, EventArgs e)
  288. {
  289. if (!CheckParam()) { return; }
  290. txtPosRes.Text = " ";
  291. try
  292. {
  293. var MsAnt = txtsatStation.GetLonLat();
  294. var CDBAnt = txtcdbStation.GetLonLat();
  295. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  296. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  297. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  298. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  299. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  300. double[] msEph = ucEphXYZMain.EphXYZ();
  301. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  302. var sigTime = txtSigTime.DateTime;
  303. var StationRes = new StationRes()
  304. {
  305. SatTxLon = MsAnt[0],
  306. SatTxLat = MsAnt[1],
  307. CdbTxLon = CDBAnt[0],
  308. CdbTxLat = CDBAnt[1],
  309. RefLon = RefGeod[0],
  310. RefLat = RefGeod[1],
  311. };
  312. if (info.PosResType == EnumPosResType.X2D1NoRef)
  313. {
  314. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  315. {
  316. SigTime = sigTime,
  317. MainCode = cg.MainCode.Value,
  318. AdjaCode = cg.Adja1Code.Value,
  319. SxDto = DtoSx,
  320. XdDto = DtoCdb,
  321. MainX = msEph[0],
  322. MainY = msEph[1],
  323. MainZ = msEph[2],
  324. AdjaX = nsEph[0],
  325. AdjaY = nsEph[1],
  326. AdjaZ = nsEph[2],
  327. SatTxLon = MsAnt[0],
  328. SatTxLat = MsAnt[1],
  329. CdbTxLon = CDBAnt[0],
  330. CdbTxLat = CDBAnt[1],
  331. };
  332. var cgRes = new CgRes()
  333. {
  334. SigTime = dto.SigTime,
  335. Dto1 = dto.SxDto,
  336. Dfo1 = dto.SxDfo,
  337. Snr1 = dto.SxSnr,
  338. DtoCdb = dto.XdDto,
  339. DfoCdb = dto.XdDfo,
  340. SnrCdb = dto.XdSnr,
  341. //StationResID = StationRes.ID,
  342. MainCode = dto.MainCode,
  343. Adja1Code = dto.AdjaCode,
  344. //TaskID = runTask.ID,
  345. MainX = dto.MainX,
  346. MainY = dto.MainY,
  347. MainZ = dto.MainZ,
  348. Adja1X = dto.AdjaX,
  349. Adja1Y = dto.AdjaY,
  350. Adja1Z = dto.AdjaZ,
  351. };
  352. double[] res;
  353. if (ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"] != null
  354. && ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"].ToLower() != "false"
  355. && ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"].ToLower() != "0")
  356. {
  357. res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes);
  358. }
  359. else
  360. {
  361. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  362. }
  363. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  364. }
  365. else
  366. {
  367. X2D1PosDto dto = new X2D1PosDto()
  368. {
  369. SigTime = sigTime,
  370. MainCode = cg.MainCode.Value,
  371. AdjaCode = cg.Adja1Code.Value,
  372. SxDto = DtoSx,
  373. XdDto = DtoCdb,
  374. MainYbDto = YbMainDto,
  375. AdjaYbDto = YbAdja1Dto,
  376. MainX = msEph[0],
  377. MainY = msEph[1],
  378. MainZ = msEph[2],
  379. AdjaX = nsEph[0],
  380. AdjaY = nsEph[1],
  381. AdjaZ = nsEph[2],
  382. SatTxLon = MsAnt[0],
  383. SatTxLat = MsAnt[1],
  384. CdbTxLon = CDBAnt[0],
  385. CdbTxLat = CDBAnt[1],
  386. RefLon = RefGeod[0],
  387. RefLat = RefGeod[1],
  388. };
  389. var cgRes = new CgRes()
  390. {
  391. SigTime = dto.SigTime,
  392. Dto1 = dto.SxDto,
  393. Dfo1 = dto.SxDfo,
  394. Snr1 = dto.SxSnr,
  395. DtoCdb = dto.XdDto,
  396. DfoCdb = dto.XdDfo,
  397. SnrCdb = dto.XdSnr,
  398. YbMainDto = dto.MainYbDto,
  399. YbAdja1Dto = dto.AdjaYbDto,
  400. //StationResID = StationRes.ID,
  401. MainCode = dto.MainCode,
  402. Adja1Code = dto.AdjaCode,
  403. // TaskID = runTask.ID,
  404. MainX = dto.MainX,
  405. MainY = dto.MainY,
  406. MainZ = dto.MainZ,
  407. Adja1X = dto.AdjaX,
  408. Adja1Y = dto.AdjaY,
  409. Adja1Z = dto.AdjaZ,
  410. };
  411. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  412. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  418. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  419. }
  420. }
  421. }
  422. }