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