X2D1DTOParamEditor.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. using Microsoft.Extensions.Logging;
  19. namespace DW5S.App.EditForms
  20. {
  21. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  22. {
  23. [Autowired]
  24. private readonly ILogger logger;
  25. [Autowired]
  26. private readonly UnitOfWork unitOfWork;
  27. private MapControl mapControl1;
  28. private PosRes info;
  29. private CgRes cg;
  30. private List<SatInfo> listSat;
  31. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  32. {
  33. InitializeComponent();
  34. this.info = info;
  35. itemSigTime.Text = $"{itemSigTime.Text}";
  36. this.layoutControl1.UseDefault();
  37. txtSigTime.UseDefault();
  38. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  39. this.listSat = new List<SatInfo>();
  40. this.mapControl1 = mapControl;
  41. }
  42. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  43. {
  44. this.layoutControl1.BestFit();
  45. StationRes station = null;
  46. var repsSat = unitOfWork.Of<SatInfo>();
  47. listSat.AddRange(await repsSat.GetAllAsync());
  48. var repsCg = unitOfWork.Of<CgRes>();
  49. cg = await repsCg.FirstOrDefaultAsync(m => m.Id == info.CgResID);
  50. var repsStation = unitOfWork.Of<StationRes>();
  51. station = await repsStation.FirstOrDefaultAsync(m => m.Id == info.StationResID);
  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}";
  70. this.txtYbAdja.Text = $"{cg.YbAdja1Dto}";
  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. string msg = $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.Id},SigTime={info.SigTime}";
  234. logger.LogError(ex, msg);
  235. DxHelper.MsgBoxHelper.ShowError(msg);
  236. }
  237. }
  238. private async void btnEphCalc_Click(object sender, EventArgs e)
  239. {
  240. dxErrorProvider.ClearErrors();
  241. if (this.txtSigTime.DateTime == DateTime.MinValue)
  242. {
  243. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  244. return;
  245. }
  246. var sigTime = this.txtSigTime.DateTime;
  247. try
  248. {
  249. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  250. var mainxlInfo = await repsXl.GetLatestAsync(cg.MainCode.Value, sigTime);
  251. if (mainxlInfo == null)
  252. {
  253. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  254. return;
  255. }
  256. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  257. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  258. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  259. var adjaxlInfo = await repsXl.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  260. if (adjaxlInfo == null)
  261. {
  262. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  263. return;
  264. }
  265. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  266. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  267. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  268. }
  269. catch (Exception ex)
  270. {
  271. string msg = $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}";
  272. logger.LogError(ex, msg);
  273. DxHelper.MsgBoxHelper.ShowError(msg);
  274. }
  275. }
  276. private void btnPos_Click(object sender, EventArgs e)
  277. {
  278. if (!CheckParam()) { return; }
  279. txtPosRes.Text = " ";
  280. bool isRef = false;
  281. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  282. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  283. && !string.IsNullOrWhiteSpace(txtYbAdja.Text))
  284. {
  285. isRef = true;
  286. }
  287. try
  288. {
  289. var MsAnt = txtsatStation.GetLonLat();
  290. var CDBAnt = txtcdbStation.GetLonLat();
  291. var RefGeod = isRef ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  292. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  293. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  294. var YbMainDto = isRef ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  295. var YbAdja1Dto = isRef ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  296. double[] msEph = ucEphXYZMain.EphXYZ();
  297. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  298. var sigTime = txtSigTime.DateTime;
  299. var StationRes = new StationRes()
  300. {
  301. SatTxLon = MsAnt[0],
  302. SatTxLat = MsAnt[1],
  303. CdbTxLon = CDBAnt[0],
  304. CdbTxLat = CDBAnt[1],
  305. RefLon = RefGeod[0],
  306. RefLat = RefGeod[1],
  307. };
  308. if (!isRef)
  309. {
  310. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  311. {
  312. SigTime = sigTime,
  313. MainCode = cg.MainCode.Value,
  314. AdjaCode = cg.Adja1Code.Value,
  315. SxDto = DtoSx,
  316. XdDto = DtoCdb,
  317. MainX = msEph[0],
  318. MainY = msEph[1],
  319. MainZ = msEph[2],
  320. AdjaX = nsEph[0],
  321. AdjaY = nsEph[1],
  322. AdjaZ = nsEph[2],
  323. SatTxLon = MsAnt[0],
  324. SatTxLat = MsAnt[1],
  325. CdbTxLon = CDBAnt[0],
  326. CdbTxLat = CDBAnt[1],
  327. };
  328. var cgRes = new CgRes()
  329. {
  330. SigTime = dto.SigTime,
  331. Dto1 = dto.SxDto,
  332. Dfo1 = dto.SxDfo,
  333. Snr1 = dto.SxSnr,
  334. DtoCdb = dto.XdDto,
  335. DfoCdb = dto.XdDfo,
  336. SnrCdb = dto.XdSnr,
  337. MainCode = dto.MainCode,
  338. Adja1Code = dto.AdjaCode,
  339. MainX = dto.MainX,
  340. MainY = dto.MainY,
  341. MainZ = dto.MainZ,
  342. Adja1X = dto.AdjaX,
  343. Adja1Y = dto.AdjaY,
  344. Adja1Z = dto.AdjaZ,
  345. };
  346. double[] res;
  347. //res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  348. res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes, dto.CalcConfidence);
  349. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  350. }
  351. else
  352. {
  353. X2D1PosDto dto = new X2D1PosDto()
  354. {
  355. SigTime = sigTime,
  356. MainCode = cg.MainCode.Value,
  357. AdjaCode = cg.Adja1Code.Value,
  358. SxDto = DtoSx,
  359. XdDto = DtoCdb,
  360. MainYbDto = YbMainDto,
  361. AdjaYbDto = YbAdja1Dto,
  362. MainX = msEph[0],
  363. MainY = msEph[1],
  364. MainZ = msEph[2],
  365. AdjaX = nsEph[0],
  366. AdjaY = nsEph[1],
  367. AdjaZ = nsEph[2],
  368. SatTxLon = MsAnt[0],
  369. SatTxLat = MsAnt[1],
  370. CdbTxLon = CDBAnt[0],
  371. CdbTxLat = CDBAnt[1],
  372. RefLon = RefGeod[0],
  373. RefLat = RefGeod[1],
  374. };
  375. var cgRes = new CgRes()
  376. {
  377. SigTime = dto.SigTime,
  378. Dto1 = dto.SxDto,
  379. Dfo1 = dto.SxDfo,
  380. Snr1 = dto.SxSnr,
  381. DtoCdb = dto.XdDto,
  382. DfoCdb = dto.XdDfo,
  383. SnrCdb = dto.XdSnr,
  384. YbMainDto = dto.MainYbDto,
  385. YbAdja1Dto = dto.AdjaYbDto,
  386. //StationResID = StationRes.ID,
  387. MainCode = dto.MainCode,
  388. Adja1Code = dto.AdjaCode,
  389. // TaskID = runTask.ID,
  390. MainX = dto.MainX,
  391. MainY = dto.MainY,
  392. MainZ = dto.MainZ,
  393. Adja1X = dto.AdjaX,
  394. Adja1Y = dto.AdjaY,
  395. Adja1Z = dto.AdjaZ,
  396. };
  397. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  398. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  399. }
  400. }
  401. catch (Exception ex)
  402. {
  403. string msg = $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.Id},SigTime={info.SigTime}";
  404. logger.LogError(ex, msg);
  405. DxHelper.MsgBoxHelper.ShowError(msg);
  406. }
  407. }
  408. }
  409. }