X2D1DTOParamEditor.cs 18 KB

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