X2D1DTOParamEditor.cs 16 KB

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