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.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using DW5S.KxcApi;
  15. using DW5S.DTO;
  16. using DW5S.Entity;
  17. using DW5S.Repostory;
  18. namespace DW5S.App.EditForms
  19. {
  20. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. private MapControl mapControl1;
  23. private PosRes info;
  24. private CgRes cg;
  25. private List<SatInfo> listSat;
  26. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  27. {
  28. InitializeComponent();
  29. this.info = info;
  30. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  31. this.layoutControl1.UseDefault();
  32. txtSigTime.UseDefault();
  33. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  34. this.listSat = new List<SatInfo>();
  35. this.mapControl1 = mapControl;
  36. }
  37. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  38. {
  39. this.layoutControl1.BestFit();
  40. StationRes station = null;
  41. using (RHDWContext db = new RHDWContext())
  42. {
  43. listSat = await db.SatInfos.ToListAsync();
  44. }
  45. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  46. {
  47. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  48. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  49. }
  50. if (cg != null)
  51. {
  52. //if (info.PosResType == EnumPosResType.X2D1NoRef)
  53. //{
  54. // cg.Dto1 = 6348.6030;
  55. // cg.DtoCdb = 246616.0330;
  56. // cg.MainX = 11265194.9906;
  57. // cg.MainY = 40486056.6399;
  58. // cg.MainZ = -2055810.5412;
  59. // cg.Adja1X = 25525328.3455;
  60. // cg.Adja1Y = 33539987.1755;
  61. // cg.Adja1Z = -49504.0378;
  62. //}
  63. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  64. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  65. if (info.PosResType == EnumPosResType.X2D1)
  66. {
  67. this.txtYbMain.Text = $"{cg.YbMainDto}";
  68. this.txtYbAdja.Text = $"{cg.YbAdja1Dto}";
  69. }
  70. this.txtSigTime.EditValue = info.SigTime;
  71. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  72. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  73. }
  74. if (station != null)
  75. {
  76. //if (info.PosResType == EnumPosResType.X2D1NoRef)
  77. //{
  78. // station.SatTxLon = 45;
  79. // station.SatTxLat =20;
  80. // station.CdbTxLon = 45;
  81. // station.CdbTxLat = 20;
  82. //}
  83. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  84. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  85. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  86. }
  87. if (info.PosResType == EnumPosResType.X2D1NoRef)
  88. {
  89. txtYbMain.Properties.ReadOnly = true;
  90. txtYbAdja.Properties.ReadOnly = true;
  91. txtRefLocation.Properties.ReadOnly = true;
  92. this.txtRefLocation.Text = $"{0},{0}";
  93. }
  94. //double tarLon = 122.88, tarLat = 31.29;
  95. //double recLon = 118.5, recLat = 32.1;
  96. //double refLon = 121, refLat = 30;
  97. //double cdbLon = 122, cdbLat = 30;
  98. //var refEcef = PhysicsHelper.GeoToEcef((refLon, refLat, 0));
  99. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  100. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  101. //var cdbEcef = PhysicsHelper.GeoToEcef((cdbLon, cdbLat, 0));
  102. //var xl1 = (-41338971.25, 6141819.55, 5504123.22);
  103. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1, recEcef);
  104. //var dt2 = PhysicsHelper.Dto(tarEcef, cdbEcef);
  105. //var dto1 = dt1 - dt2;
  106. //var dt3 = PhysicsHelper.Dto(refEcef, xl1, recEcef);
  107. //var dto2 = dt3 - 0;
  108. }
  109. public bool CheckParam()
  110. {
  111. dxErrorProvider.ClearErrors();
  112. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  113. {
  114. return false;
  115. }
  116. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  117. {
  118. return false;
  119. }
  120. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text) && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  121. {
  122. return false;
  123. }
  124. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  125. {
  126. return false;
  127. }
  128. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  129. {
  130. return false;
  131. }
  132. if (!string.IsNullOrWhiteSpace(txtYbMain.Text) && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  133. {
  134. return false;
  135. }
  136. if (!string.IsNullOrWhiteSpace(txtYbAdja.Text) && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  137. {
  138. return false;
  139. }
  140. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  141. {
  142. return false;
  143. }
  144. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  145. {
  146. return false;
  147. }
  148. return true;
  149. }
  150. private void btnDtoLine_Click(object sender, EventArgs e)
  151. {
  152. if (!CheckParam()) { return; }
  153. bool isRef = false;
  154. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  155. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  156. && !string.IsNullOrWhiteSpace(txtYbAdja.Text))
  157. {
  158. isRef = true;
  159. }
  160. try
  161. {
  162. var MsAnt = txtsatStation.GetLonLat();
  163. var CDBAnt = txtcdbStation.GetLonLat();
  164. var RefGeod = isRef ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  165. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  166. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  167. var YbMainDto = isRef ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  168. var YbAdja1Dto = isRef ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  169. double[] msEph = ucEphXYZMain.EphXYZ();
  170. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  171. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  172. dtoLineXd.MsEph = msEph;
  173. dtoLineXd.MsAnt = MsAnt;
  174. dtoLineXd.CDBAnt = CDBAnt;
  175. dtoLineXd.RefGeod = RefGeod;
  176. dtoLineXd.xdDto = DtoCdb;
  177. dtoLineXd.RefDto = YbMainDto;
  178. dtoLineXd.PosLon = info.PosLon;
  179. dtoLineXd.PosLat = info.PosLat;
  180. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  181. twoStartOption.MsEph = msEph;
  182. twoStartOption.NsEph = NsEph;
  183. twoStartOption.MsAnt = MsAnt;
  184. twoStartOption.NsAnt = MsAnt;
  185. twoStartOption.RefGeod = RefGeod;
  186. twoStartOption.TargetDto = DtoSx;
  187. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  188. twoStartOption.PosLon = info.PosLon;
  189. twoStartOption.PosLat = info.PosLat;
  190. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  191. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  192. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  193. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  194. if (isRef)
  195. {
  196. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
  197. List<MapPolyline> polylines = new List<MapPolyline>();
  198. foreach (var dtoLine in xdDtoLine)
  199. {
  200. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", dtoLine.dtoLinePoints, true);
  201. if (mapline == null)
  202. {
  203. continue;
  204. }
  205. polylines.Add(mapline);
  206. }
  207. mapControl1.DrawDtoLine(polylines);
  208. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  209. mapControl1.DrawDtoLine($"[{msat},{nsat}]带参时差线", tsDtoLine);
  210. }
  211. else
  212. {
  213. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRefNew(dtoLineXd);
  214. List<MapPolyline> polylines = new List<MapPolyline>();
  215. foreach (var dtoLine in xdDtoLine)
  216. {
  217. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]无参时差线", dtoLine.dtoLinePoints, true);
  218. if (mapline == null)
  219. {
  220. continue;
  221. }
  222. polylines.Add(mapline);
  223. }
  224. mapControl1.DrawDtoLine(polylines);
  225. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  226. mapControl1.DrawDtoLine($"[{msat},{nsat}]无参时差线", tsDtoLine);
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. DW5S.Framework.LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  232. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  233. }
  234. }
  235. private async void btnEphCalc_Click(object sender, EventArgs e)
  236. {
  237. dxErrorProvider.ClearErrors();
  238. if (this.txtSigTime.DateTime == DateTime.MinValue)
  239. {
  240. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  241. return;
  242. }
  243. var sigTime = this.txtSigTime.DateTime;
  244. try
  245. {
  246. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  247. if (mainxlInfo == null)
  248. {
  249. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  250. return;
  251. }
  252. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  253. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  254. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  255. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  256. if (adjaxlInfo == null)
  257. {
  258. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  259. return;
  260. }
  261. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  262. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  263. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  264. }
  265. catch (Exception ex)
  266. {
  267. DW5S.Framework.LogHelper.Error($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}", ex);
  268. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  269. }
  270. }
  271. private void btnPos_Click(object sender, EventArgs e)
  272. {
  273. if (!CheckParam()) { return; }
  274. txtPosRes.Text = " ";
  275. bool isRef = false;
  276. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  277. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  278. && !string.IsNullOrWhiteSpace(txtYbAdja.Text))
  279. {
  280. isRef = true;
  281. }
  282. try
  283. {
  284. var MsAnt = txtsatStation.GetLonLat();
  285. var CDBAnt = txtcdbStation.GetLonLat();
  286. var RefGeod = isRef ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  287. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  288. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  289. var YbMainDto = isRef ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  290. var YbAdja1Dto = isRef ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  291. double[] msEph = ucEphXYZMain.EphXYZ();
  292. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  293. var sigTime = txtSigTime.DateTime;
  294. var StationRes = new StationRes()
  295. {
  296. SatTxLon = MsAnt[0],
  297. SatTxLat = MsAnt[1],
  298. CdbTxLon = CDBAnt[0],
  299. CdbTxLat = CDBAnt[1],
  300. RefLon = RefGeod[0],
  301. RefLat = RefGeod[1],
  302. };
  303. if (!isRef)
  304. {
  305. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  306. {
  307. SigTime = sigTime,
  308. MainCode = cg.MainCode.Value,
  309. AdjaCode = cg.Adja1Code.Value,
  310. SxDto = DtoSx,
  311. XdDto = DtoCdb,
  312. MainX = msEph[0],
  313. MainY = msEph[1],
  314. MainZ = msEph[2],
  315. AdjaX = nsEph[0],
  316. AdjaY = nsEph[1],
  317. AdjaZ = nsEph[2],
  318. SatTxLon = MsAnt[0],
  319. SatTxLat = MsAnt[1],
  320. CdbTxLon = CDBAnt[0],
  321. CdbTxLat = CDBAnt[1],
  322. };
  323. var cgRes = new CgRes()
  324. {
  325. SigTime = dto.SigTime,
  326. Dto1 = dto.SxDto,
  327. Dfo1 = dto.SxDfo,
  328. Snr1 = dto.SxSnr,
  329. DtoCdb = dto.XdDto,
  330. DfoCdb = dto.XdDfo,
  331. SnrCdb = dto.XdSnr,
  332. MainCode = dto.MainCode,
  333. Adja1Code = dto.AdjaCode,
  334. MainX = dto.MainX,
  335. MainY = dto.MainY,
  336. MainZ = dto.MainZ,
  337. Adja1X = dto.AdjaX,
  338. Adja1Y = dto.AdjaY,
  339. Adja1Z = dto.AdjaZ,
  340. };
  341. double[] res;
  342. //res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  343. res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes, dto.CalcConfidence);
  344. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  345. }
  346. else
  347. {
  348. X2D1PosDto dto = new X2D1PosDto()
  349. {
  350. SigTime = sigTime,
  351. MainCode = cg.MainCode.Value,
  352. AdjaCode = cg.Adja1Code.Value,
  353. SxDto = DtoSx,
  354. XdDto = DtoCdb,
  355. MainYbDto = YbMainDto,
  356. AdjaYbDto = YbAdja1Dto,
  357. MainX = msEph[0],
  358. MainY = msEph[1],
  359. MainZ = msEph[2],
  360. AdjaX = nsEph[0],
  361. AdjaY = nsEph[1],
  362. AdjaZ = nsEph[2],
  363. SatTxLon = MsAnt[0],
  364. SatTxLat = MsAnt[1],
  365. CdbTxLon = CDBAnt[0],
  366. CdbTxLat = CDBAnt[1],
  367. RefLon = RefGeod[0],
  368. RefLat = RefGeod[1],
  369. };
  370. var cgRes = new CgRes()
  371. {
  372. SigTime = dto.SigTime,
  373. Dto1 = dto.SxDto,
  374. Dfo1 = dto.SxDfo,
  375. Snr1 = dto.SxSnr,
  376. DtoCdb = dto.XdDto,
  377. DfoCdb = dto.XdDfo,
  378. SnrCdb = dto.XdSnr,
  379. YbMainDto = dto.MainYbDto,
  380. YbAdja1Dto = dto.AdjaYbDto,
  381. //StationResID = StationRes.ID,
  382. MainCode = dto.MainCode,
  383. Adja1Code = dto.AdjaCode,
  384. // TaskID = runTask.ID,
  385. MainX = dto.MainX,
  386. MainY = dto.MainY,
  387. MainZ = dto.MainZ,
  388. Adja1X = dto.AdjaX,
  389. Adja1Y = dto.AdjaY,
  390. Adja1Z = dto.AdjaZ,
  391. };
  392. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  393. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  394. }
  395. }
  396. catch (Exception ex)
  397. {
  398. DW5S.Framework.LogHelper.Error($"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  399. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  400. }
  401. }
  402. }
  403. }