X2D1PosParamEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. using DxHelper;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.Entity;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using XdCxRhDW.Dto;
  13. using XdCxRhDW.Api;
  14. using XdCxRhDW.Entity;
  15. using XdCxRhDW.Repostory;
  16. namespace XdCxRhDW.App.EditForms
  17. {
  18. public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  19. {
  20. private PosRes info;
  21. private CgRes cg;
  22. public X2D1PosParamEditor(PosRes info)
  23. {
  24. InitializeComponent();
  25. this.info = info;
  26. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  27. this.layoutControl1.UseDefault();
  28. txtSigTime.UseDefault();
  29. this.Text = $"{info.PosResType.GetEnumDisplayName()}手动定位";
  30. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  31. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  32. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  33. }
  34. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  35. {
  36. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  37. }
  38. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  39. {
  40. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  41. }
  42. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  43. {
  44. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  45. }
  46. private async void X2D1PosParamEditor_Load(object sender, EventArgs e)
  47. {
  48. StationRes station = null;
  49. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  50. {
  51. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  52. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  53. }
  54. if (cg != null)
  55. {
  56. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  57. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  58. if (info.PosResType == EnumPosResType.X2D1)
  59. {
  60. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  61. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  62. }
  63. this.txtSigTime.EditValue = info.SigTime;
  64. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  65. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  66. }
  67. if (station != null)
  68. {
  69. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  70. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  71. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  72. }
  73. if (info.PosResType == EnumPosResType.X2D1NoRef)
  74. {
  75. txtYbMain.Properties.ReadOnly = true;
  76. txtYbAdja.Properties.ReadOnly = true;
  77. txtRefLocation.Properties.ReadOnly = true;
  78. this.txtRefLocation.Text = $"{0},{0}";
  79. }
  80. //double tarLon = 46, tarLat = 24;
  81. //double recLon = 45.9, recLat = 23.9;
  82. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  83. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  84. //var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value);
  85. //var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value);
  86. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef);
  87. //var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef);
  88. //var dto1 = (dt1 - dt2) * 1e6;
  89. //var dt3 = PhysicsHelper.Dto(tarEcef, recEcef);
  90. //var dto2 = (dt1 - dt3) * 1e6;
  91. }
  92. public bool CheckParam()
  93. {
  94. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  95. {
  96. return false;
  97. }
  98. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  99. {
  100. return false;
  101. }
  102. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  103. {
  104. return false;
  105. }
  106. return true;
  107. }
  108. private void btnOk_Click(object sender, EventArgs e)
  109. {
  110. if (!CheckParam()) { return; }
  111. lblRes.Text = string.Empty;
  112. try
  113. {
  114. var MsAnt = txtsatStation.GetLonLat();
  115. var CDBAnt = txtcdbStation.GetLonLat();
  116. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  117. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  118. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  119. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  120. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  121. double[] msEph = ucEphXYZMain.EphXYZ();
  122. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  123. var sigTime = txtSigTime.DateTime;
  124. var StationRes = new StationRes()
  125. {
  126. SatTxLon = MsAnt[0],
  127. SatTxLat = MsAnt[1],
  128. CdbTxLon = CDBAnt[0],
  129. CdbTxLat = CDBAnt[1],
  130. RefLon = RefGeod[0],
  131. RefLat = RefGeod[1],
  132. };
  133. string url = string.Format("http://{0}:{1}/Api/Pos/", IpHelper.GetLocalIp(), SysConfig.Config.HttpPort);
  134. if (info.PosResType == EnumPosResType.X2D1NoRef)
  135. {
  136. url += "PosX2D1NoParAsync";
  137. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  138. {
  139. SigTime = sigTime,
  140. MainCode = cg.MainCode.Value,
  141. AdjaCode = cg.Adja1Code.Value,
  142. SxDto = DtoSx,
  143. XdDto = DtoCdb,
  144. MainX = msEph[0],
  145. MainY = msEph[1],
  146. MainZ = msEph[2],
  147. AdjaX = nsEph[0],
  148. AdjaY = nsEph[1],
  149. AdjaZ = nsEph[2],
  150. SatTxLon = MsAnt[0],
  151. SatTxLat = MsAnt[1],
  152. CdbTxLon = CDBAnt[0],
  153. CdbTxLat = CDBAnt[1],
  154. };
  155. var cgRes = new CgRes()
  156. {
  157. SigTime = dto.SigTime,
  158. Dto1 = dto.SxDto,
  159. Dfo1 = dto.SxDfo,
  160. Snr1 = dto.SxSnr,
  161. DtoCdb = dto.XdDto,
  162. DfoCdb = dto.XdDfo,
  163. SnrCdb = dto.XdSnr,
  164. //StationResID = StationRes.ID,
  165. MainCode = dto.MainCode,
  166. Adja1Code = dto.AdjaCode,
  167. //TaskID = runTask.ID,
  168. MainX = dto.MainX,
  169. MainY = dto.MainY,
  170. MainZ = dto.MainZ,
  171. Adja1X = dto.AdjaX,
  172. Adja1Y = dto.AdjaY,
  173. Adja1Z = dto.AdjaZ,
  174. };
  175. var res = PosApi.X2D1_PosNoRef(cgRes, StationRes);
  176. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  177. //var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  178. //if (result.code == 200)
  179. //{
  180. // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  181. //}
  182. }
  183. else
  184. {
  185. url += "PosX2D1Async";
  186. X2D1PosDto dto = new X2D1PosDto()
  187. {
  188. SigTime = sigTime,
  189. MainCode = cg.MainCode.Value,
  190. AdjaCode = cg.Adja1Code.Value,
  191. SxDto = DtoSx,
  192. XdDto = DtoCdb,
  193. MainYbDto = YbMainDto,
  194. AdjaYbDto = YbAdja1Dto,
  195. MainX = msEph[0],
  196. MainY = msEph[1],
  197. MainZ = msEph[2],
  198. AdjaX = nsEph[0],
  199. AdjaY = nsEph[1],
  200. AdjaZ = nsEph[2],
  201. SatTxLon = MsAnt[0],
  202. SatTxLat = MsAnt[1],
  203. CdbTxLon = CDBAnt[0],
  204. CdbTxLat = CDBAnt[1],
  205. RefLon = RefGeod[0],
  206. RefLat = RefGeod[1],
  207. };
  208. var cgRes = new CgRes()
  209. {
  210. SigTime = dto.SigTime,
  211. Dto1 = dto.SxDto,
  212. Dfo1 = dto.SxDfo,
  213. Snr1 = dto.SxSnr,
  214. DtoCdb = dto.XdDto,
  215. DfoCdb = dto.XdDfo,
  216. SnrCdb = dto.XdSnr,
  217. YbMainDto = dto.MainYbDto,
  218. YbAdja1Dto = dto.AdjaYbDto,
  219. //StationResID = StationRes.ID,
  220. MainCode = dto.MainCode,
  221. Adja1Code = dto.AdjaCode,
  222. // TaskID = runTask.ID,
  223. MainX = dto.MainX,
  224. MainY = dto.MainY,
  225. MainZ = dto.MainZ,
  226. Adja1X = dto.AdjaX,
  227. Adja1Y = dto.AdjaY,
  228. Adja1Z = dto.AdjaZ,
  229. };
  230. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  231. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  232. }
  233. }
  234. catch (Exception ex)
  235. {
  236. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  237. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败");
  238. }
  239. }
  240. private async void btnEphCalc_Click(object sender, EventArgs e)
  241. {
  242. if (this.txtSigTime.DateTime == DateTime.MinValue)
  243. {
  244. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  245. return;
  246. }
  247. var sigTime = this.txtSigTime.DateTime;
  248. try
  249. {
  250. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  251. if (mainxlInfo == null)
  252. {
  253. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  254. return;
  255. }
  256. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  257. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), SysConfig.Config.HttpPort);
  258. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  259. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  260. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  261. if (adjaxlInfo == null)
  262. {
  263. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  264. return;
  265. }
  266. XlCalcDto.tleStr = adjaxlInfo.TwoLine;
  267. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  268. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  269. }
  270. catch (Exception ex)
  271. {
  272. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  273. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  274. }
  275. }
  276. }
  277. }