X2PosParamEditor.cs 11 KB

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