X2D1PosParamEditor.cs 13 KB

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