X2D1DTOParamEditor.cs 18 KB

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