X2PosParamEditor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using DevExpress.Mvvm.ModuleInjection.Native;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.DXErrorProvider;
  4. using DevExpress.XtraLayout;
  5. using DevExpress.XtraMap;
  6. using DevExpress.XtraTreeList.Data;
  7. using DxHelper;
  8. using ExtensionsDev;
  9. using System;
  10. using System.CodeDom;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Data.Entity.Migrations;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Security.Policy;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows.Documents;
  22. using System.Windows.Forms;
  23. using XdCxRhDW.Dto;
  24. using XdCxRhDW.Repostory;
  25. using XdCxRhDW.Entity;
  26. using XdCxRhDW.Api;
  27. namespace XdCxRhDW.App.EditForms
  28. {
  29. public partial class X2PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  30. {
  31. private PosRes info;
  32. private CgRes cg;
  33. public X2PosParamEditor(PosRes info)
  34. {
  35. InitializeComponent();
  36. this.info = info;
  37. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  38. this.layoutControl1.UseDefault();
  39. txtSigTime.UseDefault();
  40. this.Text = $"{info.PosResType.GetEnumDisplayName()}手动定位";
  41. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  42. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  43. }
  44. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  45. {
  46. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  47. }
  48. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  49. {
  50. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  51. }
  52. private async void X2DTOParamEditor_Load(object sender, EventArgs e)
  53. {
  54. StationRes station = null;
  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:f4}";
  63. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f4}";
  64. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f4}";
  65. this.txtSigTime.EditValue = info.SigTime;
  66. var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
  67. ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
  68. var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
  69. ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
  70. this.txtDfo.Text = $"{cg.Dfo1.Value:f4}";
  71. this.txtYbMainDfo.Text = $"{cg.YbMainDfo.Value:f4}";
  72. this.txtYbAdjaDfo.Text = $"{cg.YbAdja1Dfo.Value:f4}";
  73. this.txtTarFreqUp.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
  74. this.txtTarFreqDown.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 950;
  75. this.txtRefFreqUp.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
  76. this.txtRefFreqDown.EditValue = cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value * 1e-6 : 950;
  77. }
  78. if (station != null)
  79. {
  80. this.txtsatStation.Text = $"{station.SatTxLon:f4},{station.SatTxLat:f4}";
  81. this.txtRefLocation.Text = $"{station.RefLon:f4},{station.RefLat:f4}";
  82. }
  83. }
  84. public bool CheckParam()
  85. {
  86. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  87. {
  88. return false;
  89. }
  90. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  91. {
  92. return false;
  93. }
  94. return true;
  95. }
  96. private void btnOk_Click(object sender, EventArgs e)
  97. {
  98. if (!CheckParam()) { return; }
  99. try
  100. {
  101. var MsAnt = txtsatStation.GetLonLat();
  102. var RefGeod = txtRefLocation.GetLonLat();
  103. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  104. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  105. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  106. var msEph = ucEphXYZMain.EphParam();
  107. var ns1Eph = ucEphXYZAdja.EphParam();
  108. var Dfo = Convert.ToDouble(this.txtDfo.Text);
  109. var YbMainDfo = Convert.ToDouble(this.txtYbMainDfo.Text);
  110. var YbAdja1Dfo = Convert.ToDouble(this.txtYbAdjaDfo.Text);
  111. var TarFreqUp = Convert.ToDouble(this.txtTarFreqUp.Text) * 1e6;
  112. var TarFreqDown = Convert.ToDouble(this.txtTarFreqDown.Text) * 1e6;
  113. var RefFreqUp = Convert.ToDouble(this.txtRefFreqUp.Text) * 1e6;
  114. var RefFreqDown = Convert.ToDouble(this.txtRefFreqDown.Text) * 1e6;
  115. var sigTime = txtSigTime.DateTime;
  116. var StationRes = new StationRes()
  117. {
  118. SatTxLon = MsAnt[0],
  119. SatTxLat = MsAnt[1],
  120. RefLon = RefGeod[0],
  121. RefLat = RefGeod[1],
  122. };
  123. X2DtoDfoPosDto dto = new X2DtoDfoPosDto()
  124. {
  125. SigTime = sigTime,
  126. MainCode = cg.MainCode.Value,
  127. AdjaCode = cg.Adja1Code.Value,
  128. Dto = DtoSx,
  129. Dfo = Dfo,
  130. YbMainDto = YbMainDto,
  131. YbAdjaDto = YbAdja1Dto,
  132. YbMainDfo = YbMainDfo,
  133. YbAdjaDfo = YbAdja1Dfo,
  134. TarFreqUp = TarFreqUp,
  135. TarFreqDown = TarFreqDown,
  136. RefFreqUp = RefFreqUp,
  137. RefFreqDown = RefFreqDown,
  138. MainX = msEph[0],
  139. MainY = msEph[1],
  140. MainZ = msEph[2],
  141. MainVx = msEph[3],
  142. MainVy = msEph[4],
  143. MainVz = msEph[5],
  144. AdjaX = ns1Eph[0],
  145. AdjaY = ns1Eph[1],
  146. AdjaZ = ns1Eph[2],
  147. AdjaVx = ns1Eph[3],
  148. AdjaVy = ns1Eph[4],
  149. AdjaVz = ns1Eph[5],
  150. SatTxLon = MsAnt[0],
  151. SatTxLat = MsAnt[1],
  152. RefLon = RefGeod[0],
  153. RefLat = RefGeod[1],
  154. };
  155. var cgRes = new CgRes()
  156. {
  157. SigTime = dto.SigTime,
  158. Dto1 = dto.Dto,
  159. Dfo1 = dto.Dfo,
  160. Snr1 = dto.Snr,
  161. YbMainDto = dto.YbMainDto,
  162. YbAdja1Dto = dto.YbAdjaDto,
  163. YbMainDfo = dto.YbMainDfo,
  164. YbAdja1Dfo = dto.YbAdjaDfo,
  165. TarFreqUp = dto.TarFreqUp,
  166. TarFreqDown = dto.TarFreqDown,
  167. RefFreqUp = dto.RefFreqUp,
  168. RefFreqDown = dto.RefFreqDown,
  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. MainVx = dto.MainVx,
  177. MainVy = dto.MainVy,
  178. MainVz = dto.MainVz,
  179. Adja1X = dto.AdjaX,
  180. Adja1Y = dto.AdjaY,
  181. Adja1Z = dto.AdjaZ,
  182. Adja1Vx = dto.AdjaVx,
  183. Adja1Vy = dto.AdjaVy,
  184. Adja1Vz = dto.AdjaVz,
  185. };
  186. var res = PosApi.X2_PosDtoDfo(cgRes, StationRes);
  187. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  188. //string url = string.Format("http://{0}:{1}/Api/Pos/PosX2DtoDfoAsync", IpHelper.GetLocalIp(), settings.HttpPort);
  189. //var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2DtoDfoPos);
  190. //if (result.code == 200)
  191. //{
  192. // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  193. //}
  194. }
  195. catch (Exception ex)
  196. {
  197. Serilog.Log.Error(ex, $"定位{info.PosResType.GetEnumDisplayName()}失败.PosID={info.ID},SigTime={info.SigTime}");
  198. DxHelper.MsgBoxHelper.ShowWarning($"定位{info.PosResType.GetEnumDisplayName()}失败");
  199. }
  200. }
  201. private async void txtEphCalc_Click(object sender, EventArgs e)
  202. {
  203. if (txtSigTime.DateTime == DateTime.MinValue)
  204. {
  205. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  206. return;
  207. }
  208. var sigTime = txtSigTime.DateTime;
  209. try
  210. {
  211. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  212. if (mainxlInfo == null)
  213. {
  214. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  215. return;
  216. }
  217. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  218. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), SysConfig.Config.HttpPort);
  219. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  220. ucEphXYZMain.SetParam("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z, maineph.data.VX, maineph.data.VY, maineph.data.VZ), Color.Red);
  221. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  222. if (adjaxlInfo == null)
  223. {
  224. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  225. return;
  226. }
  227. XlCalcDto.tleStr = adjaxlInfo.TwoLine;
  228. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(url, XlCalcDto);
  229. ucEphXYZAdja.SetParam("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z, adjaeph.data.VX, adjaeph.data.VY, adjaeph.data.VZ), Color.Red);
  230. }
  231. catch (Exception ex)
  232. {
  233. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  234. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  235. }
  236. }
  237. }
  238. }