X2D1DTOParamEditor.cs 20 KB

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