X2D1DTOParamEditor.cs 19 KB

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