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