X2D1DTOParamEditor.cs 18 KB

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