X2PosParamEditor.cs 11 KB

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