X2D1PosParamEditor.cs 13 KB

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