X2D1PosParamEditor.cs 13 KB

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