X2D1PosParamEditor.cs 13 KB

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