X2D1PosParamEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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.Dto;
  15. using XdCxRhDW.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.App.EditForms
  18. {
  19. public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private List<SatInfo> listSat;
  22. private PosRes info;
  23. private CgRes cg;
  24. private SysSetings settings = new SysSetings();
  25. public X2D1PosParamEditor(PosRes info)
  26. {
  27. InitializeComponent();
  28. this.Text = $"{info.PosResType.GetEnumDisplayName()}手动定位";
  29. this.info = info;
  30. this.listSat = new List<SatInfo>();
  31. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  32. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  33. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  34. }
  35. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  36. {
  37. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  38. }
  39. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  40. {
  41. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  42. }
  43. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  44. {
  45. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  46. }
  47. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  48. {
  49. StationRes station;
  50. using (RHDWContext db = new RHDWContext())
  51. {
  52. listSat = await db.SatInfos.ToListAsync();
  53. settings = await db.SysSetings.FirstOrDefaultAsync();
  54. }
  55. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  56. {
  57. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  58. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  59. }
  60. if (cg != null)
  61. {
  62. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  63. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  64. if (info.PosResType == EnumPosResType.X2D1)
  65. {
  66. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  67. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  68. }
  69. this.txtSigTime.EditValue = info.SigTime;
  70. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  71. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  72. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  73. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  74. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  75. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  76. }
  77. if (station != null)
  78. {
  79. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  80. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  81. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  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 btnOk_Click(object sender, EventArgs e)
  119. {
  120. if (!CheckParam()) { return; }
  121. lblRes.Text = string.Empty;
  122. try
  123. {
  124. var MsAnt = txtsatStation.GetLonLat();
  125. var CDBAnt = txtcdbStation.GetLonLat();
  126. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  127. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  128. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  129. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  130. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  131. var MainX = Convert.ToDouble(this.txtMainX.Text);
  132. var MainY = Convert.ToDouble(this.txtMainY.Text);
  133. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  134. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  135. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  136. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  137. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  138. double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  139. var sigTime = txtSigTime.DateTime;
  140. var StationRes = new StationRes()
  141. {
  142. SatTxLon = MsAnt[0],
  143. SatTxLat = MsAnt[1],
  144. CdbTxLon = CDBAnt[0],
  145. CdbTxLat = CDBAnt[1],
  146. RefLon = RefGeod[0],
  147. RefLat = RefGeod[1],
  148. };
  149. string url = string.Format("http://{0}:{1}/Api/Pos/", IpHelper.GetLocalIp(), settings.HttpPort);
  150. if (info.PosResType == EnumPosResType.X2D1NoRef)
  151. {
  152. url += "PosX2D1NoParAsync";
  153. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  154. {
  155. SigTime = sigTime,
  156. MainCode = cg.MainCode.Value,
  157. AdjaCode = cg.Adja1Code.Value,
  158. SxDto = DtoSx,
  159. XdDto = DtoCdb,
  160. MainX = MainX,
  161. MainY = MainY,
  162. MainZ = MainZ,
  163. AdjaX = AdjaX,
  164. AdjaY = AdjaY,
  165. AdjaZ = AdjaZ,
  166. SatTxLon = MsAnt[0],
  167. SatTxLat = MsAnt[1],
  168. CdbTxLon = CDBAnt[0],
  169. CdbTxLat = CDBAnt[1],
  170. };
  171. var cgRes = new CgRes()
  172. {
  173. SigTime = dto.SigTime,
  174. Dto1 = dto.SxDto,
  175. Dfo1 = dto.SxDfo,
  176. Snr1 = dto.SxSnr,
  177. DtoCdb = dto.XdDto,
  178. DfoCdb = dto.XdDfo,
  179. SnrCdb = dto.XdSnr,
  180. //StationResID = StationRes.ID,
  181. MainCode = dto.MainCode,
  182. Adja1Code = dto.AdjaCode,
  183. //TaskID = runTask.ID,
  184. MainX = dto.MainX,
  185. MainY = dto.MainY,
  186. MainZ = dto.MainZ,
  187. Adja1X = dto.AdjaX,
  188. Adja1Y = dto.AdjaY,
  189. Adja1Z = dto.AdjaZ,
  190. };
  191. var res = PosApi.X2D1_PosNoRef(cgRes, StationRes);
  192. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  193. //var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  194. //if (result.code == 200)
  195. //{
  196. // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  197. //}
  198. }
  199. else
  200. {
  201. url += "PosX2D1Async";
  202. X2D1PosDto dto = new X2D1PosDto()
  203. {
  204. SigTime = sigTime,
  205. MainCode = cg.MainCode.Value,
  206. AdjaCode = cg.Adja1Code.Value,
  207. SxDto = DtoSx,
  208. XdDto = DtoCdb,
  209. MainYbDto = YbMainDto,
  210. AdjaYbDto = YbAdja1Dto,
  211. MainX = MainX,
  212. MainY = MainY,
  213. MainZ = MainZ,
  214. AdjaX = AdjaX,
  215. AdjaY = AdjaY,
  216. AdjaZ = AdjaZ,
  217. SatTxLon = MsAnt[0],
  218. SatTxLat = MsAnt[1],
  219. CdbTxLon = CDBAnt[0],
  220. CdbTxLat = CDBAnt[1],
  221. RefLon = RefGeod[0],
  222. RefLat = RefGeod[1],
  223. };
  224. var cgRes = new CgRes()
  225. {
  226. SigTime = dto.SigTime,
  227. Dto1 = dto.SxDto,
  228. Dfo1 = dto.SxDfo,
  229. Snr1 = dto.SxSnr,
  230. DtoCdb = dto.XdDto,
  231. DfoCdb = dto.XdDfo,
  232. SnrCdb = dto.XdSnr,
  233. YbMainDto = dto.MainYbDto,
  234. YbAdja1Dto = dto.AdjaYbDto,
  235. //StationResID = StationRes.ID,
  236. MainCode = dto.MainCode,
  237. Adja1Code = dto.AdjaCode,
  238. // TaskID = runTask.ID,
  239. MainX = dto.MainX,
  240. MainY = dto.MainY,
  241. MainZ = dto.MainZ,
  242. Adja1X = dto.AdjaX,
  243. Adja1Y = dto.AdjaY,
  244. Adja1Z = dto.AdjaZ,
  245. };
  246. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  247. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  248. //var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  249. //if (result.code == 200)
  250. //{
  251. // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  252. //}
  253. }
  254. }
  255. catch (Exception ex)
  256. {
  257. Serilog.Log.Error(ex, $"定位{info.PosResType.GetEnumDisplayName()}失败.PosID={info.ID},SigTime={info.SigTime}");
  258. DxHelper.MsgBoxHelper.ShowWarning($"定位{info.PosResType.GetEnumDisplayName()}失败");
  259. }
  260. }
  261. private async void btnMainXl_Click(object sender, EventArgs e)
  262. {
  263. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, txtSigTime.DateTime);
  264. if (xlInfo == null)
  265. {
  266. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  267. return;
  268. }
  269. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime };
  270. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  271. var ephMain = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  272. this.txtMainX.Text = ephMain.data.X.ToString("f3");
  273. this.txtMainY.Text = ephMain.data.Y.ToString("f3");
  274. this.txtMainZ.Text = ephMain.data.Z.ToString("f3");
  275. }
  276. private async void btnAdjaXl_Click(object sender, EventArgs e)
  277. {
  278. var xlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, txtSigTime.DateTime);
  279. if (xlInfo == null)
  280. {
  281. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  282. return;
  283. }
  284. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime };
  285. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  286. var ephAdja = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  287. this.txtAdjaX.Text = ephAdja.data.X.ToString("f3");
  288. this.txtAdjaY.Text = ephAdja.data.Y.ToString("f3");
  289. this.txtAdjaZ.Text = ephAdja.data.Z.ToString("f3");
  290. }
  291. }
  292. }