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