X2PosParamEditor.cs 11 KB

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