X2D1DTOParamEditor.cs 16 KB

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