X2D1DTOParamEditor.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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.txtsatStation1.Text = $"{station.MSatTxLon},{station.MSatTxLat}";
  86. this.txtsatStation2.Text = $"{station.N1SatTxLon},{station.N1SatTxLat}";
  87. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  88. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  89. }
  90. if (info.PosResType == EnumPosResType.X2D1NoRef)
  91. {
  92. txtYbMain.Properties.ReadOnly = true;
  93. txtYbAdja.Properties.ReadOnly = true;
  94. txtRefLocation.Properties.ReadOnly = true;
  95. this.txtRefLocation.Text = $"{0},{0}";
  96. }
  97. //double tarLon = 122.88, tarLat = 31.29;
  98. //double recLon = 118.5, recLat = 32.1;
  99. //double refLon = 121, refLat = 30;
  100. //double cdbLon = 122, cdbLat = 30;
  101. //var refEcef = PhysicsHelper.GeoToEcef((refLon, refLat, 0));
  102. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  103. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  104. //var cdbEcef = PhysicsHelper.GeoToEcef((cdbLon, cdbLat, 0));
  105. //var xl1 = (-41338971.25, 6141819.55, 5504123.22);
  106. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1, recEcef);
  107. //var dt2 = PhysicsHelper.Dto(tarEcef, cdbEcef);
  108. //var dto1 = dt1 - dt2;
  109. //var dt3 = PhysicsHelper.Dto(refEcef, xl1, recEcef);
  110. //var dto2 = dt3 - 0;
  111. }
  112. public bool CheckParam()
  113. {
  114. dxErrorProvider.ClearErrors();
  115. if (!txtsatStation1.CheckLonLat(dxErrorProvider, "接收站"))
  116. {
  117. return false;
  118. }
  119. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  120. {
  121. return false;
  122. }
  123. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  124. {
  125. return false;
  126. }
  127. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  128. {
  129. return false;
  130. }
  131. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  132. {
  133. return false;
  134. }
  135. if (info.PosResType == EnumPosResType.X2D1 && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  136. {
  137. return false;
  138. }
  139. if (info.PosResType == EnumPosResType.X2D1 && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  140. {
  141. return false;
  142. }
  143. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  144. {
  145. return false;
  146. }
  147. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  148. {
  149. return false;
  150. }
  151. return true;
  152. }
  153. private void btnDtoLine_Click(object sender, EventArgs e)
  154. {
  155. if (!CheckParam()) { return; }
  156. try
  157. {
  158. var MsAnt = txtsatStation1.GetLonLat();
  159. var Ns1Ant = txtsatStation2.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 = Ns1Ant;
  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.DtoLineXdNew(dtoLineXd);
  194. List<MapPolyline> polylines = new List<MapPolyline>();
  195. foreach (var dtoLine in xdDtoLine)
  196. {
  197. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", dtoLine.dtoLinePoints, true);
  198. if (mapline == null)
  199. {
  200. continue;
  201. }
  202. polylines.Add(mapline);
  203. }
  204. mapControl1.DrawDtoLine(polylines);
  205. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  206. mapControl1.DrawDtoLine($"[{msat},{nsat}]带参时差线", tsDtoLine);
  207. }
  208. else
  209. {
  210. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRefNew(dtoLineXd);
  211. List<MapPolyline> polylines = new List<MapPolyline>();
  212. foreach (var dtoLine in xdDtoLine)
  213. {
  214. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]无参时差线", dtoLine.dtoLinePoints, true);
  215. if (mapline == null)
  216. {
  217. continue;
  218. }
  219. polylines.Add(mapline);
  220. }
  221. mapControl1.DrawDtoLine(polylines);
  222. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  223. mapControl1.DrawDtoLine($"[{msat},{nsat}]无参时差线", tsDtoLine);
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  229. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  230. }
  231. }
  232. private async void btnEphCalc_Click(object sender, EventArgs e)
  233. {
  234. dxErrorProvider.ClearErrors();
  235. if (this.txtSigTime.DateTime == DateTime.MinValue)
  236. {
  237. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  238. return;
  239. }
  240. var sigTime = this.txtSigTime.DateTime;
  241. try
  242. {
  243. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  244. if (mainxlInfo == null)
  245. {
  246. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  247. return;
  248. }
  249. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  250. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  251. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  252. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  253. if (adjaxlInfo == null)
  254. {
  255. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  256. return;
  257. }
  258. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  259. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  260. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  261. }
  262. catch (Exception ex)
  263. {
  264. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  265. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  266. }
  267. }
  268. private void btnPos_Click(object sender, EventArgs e)
  269. {
  270. if (!CheckParam()) { return; }
  271. txtPosRes.Text = " ";
  272. try
  273. {
  274. var MsAnt = txtsatStation1.GetLonLat();
  275. var Ns1Ant = txtsatStation2.GetLonLat();
  276. var CDBAnt = txtcdbStation.GetLonLat();
  277. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  278. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  279. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  280. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  281. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  282. double[] msEph = ucEphXYZMain.EphXYZ();
  283. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  284. var sigTime = txtSigTime.DateTime;
  285. var StationRes = new StationRes()
  286. {
  287. MSatTxLon = MsAnt[0],
  288. MSatTxLat = MsAnt[1],
  289. N1SatTxLon = Ns1Ant[0],
  290. N1SatTxLat = Ns1Ant[1],
  291. CdbTxLon = CDBAnt[0],
  292. CdbTxLat = CDBAnt[1],
  293. RefLon = RefGeod[0],
  294. RefLat = RefGeod[1],
  295. };
  296. if (info.PosResType == EnumPosResType.X2D1NoRef)
  297. {
  298. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  299. {
  300. SigTime = sigTime,
  301. MainCode = cg.MainCode.Value,
  302. AdjaCode = cg.Adja1Code.Value,
  303. SxDto = DtoSx,
  304. XdDto = DtoCdb,
  305. MainX = msEph[0],
  306. MainY = msEph[1],
  307. MainZ = msEph[2],
  308. AdjaX = nsEph[0],
  309. AdjaY = nsEph[1],
  310. AdjaZ = nsEph[2],
  311. SatTxLon = MsAnt[0],
  312. SatTxLat = MsAnt[1],
  313. CdbTxLon = CDBAnt[0],
  314. CdbTxLat = CDBAnt[1],
  315. };
  316. var cgRes = new CgRes()
  317. {
  318. SigTime = dto.SigTime,
  319. Dto1 = dto.SxDto,
  320. Dfo1 = dto.SxDfo,
  321. Snr1 = dto.SxSnr,
  322. DtoCdb = dto.XdDto,
  323. DfoCdb = dto.XdDfo,
  324. SnrCdb = dto.XdSnr,
  325. MainCode = dto.MainCode,
  326. Adja1Code = dto.AdjaCode,
  327. MainX = dto.MainX,
  328. MainY = dto.MainY,
  329. MainZ = dto.MainZ,
  330. Adja1X = dto.AdjaX,
  331. Adja1Y = dto.AdjaY,
  332. Adja1Z = dto.AdjaZ,
  333. };
  334. double[] res;
  335. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  336. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  337. }
  338. else
  339. {
  340. X2D1PosDto dto = new X2D1PosDto()
  341. {
  342. SigTime = sigTime,
  343. MainCode = cg.MainCode.Value,
  344. AdjaCode = cg.Adja1Code.Value,
  345. SxDto = DtoSx,
  346. XdDto = DtoCdb,
  347. MainYbDto = YbMainDto,
  348. AdjaYbDto = YbAdja1Dto,
  349. MainX = msEph[0],
  350. MainY = msEph[1],
  351. MainZ = msEph[2],
  352. AdjaX = nsEph[0],
  353. AdjaY = nsEph[1],
  354. AdjaZ = nsEph[2],
  355. MSatTxLon = MsAnt[0],
  356. MSatTxLat = MsAnt[1],
  357. CdbTxLon = CDBAnt[0],
  358. CdbTxLat = CDBAnt[1],
  359. RefLon = RefGeod[0],
  360. RefLat = RefGeod[1],
  361. };
  362. var cgRes = new CgRes()
  363. {
  364. SigTime = dto.SigTime,
  365. Dto1 = dto.SxDto,
  366. Dfo1 = dto.SxDfo,
  367. Snr1 = dto.SxSnr,
  368. DtoCdb = dto.XdDto,
  369. DfoCdb = dto.XdDfo,
  370. SnrCdb = dto.XdSnr,
  371. YbMainDto = dto.MainYbDto,
  372. YbAdja1Dto = dto.AdjaYbDto,
  373. //StationResID = StationRes.ID,
  374. MainCode = dto.MainCode,
  375. Adja1Code = dto.AdjaCode,
  376. // TaskID = runTask.ID,
  377. MainX = dto.MainX,
  378. MainY = dto.MainY,
  379. MainZ = dto.MainZ,
  380. Adja1X = dto.AdjaX,
  381. Adja1Y = dto.AdjaY,
  382. Adja1Z = dto.AdjaZ,
  383. };
  384. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  385. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  386. }
  387. }
  388. catch (Exception ex)
  389. {
  390. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  391. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  392. }
  393. }
  394. }
  395. }