RHDTOParamEditor.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. using DevExpress.XtraMap;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.CodeDom;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using DW5S.KxcApi;
  14. using DW5S.DTO;
  15. using DW5S.Entity;
  16. using DW5S.Repostory;
  17. using Microsoft.Extensions.Logging;
  18. namespace DW5S.App.EditForms
  19. {
  20. public partial class RHDTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. [Autowired]
  23. private readonly ILogger logger;
  24. [Autowired]
  25. private readonly UnitOfWork unitOfWork;
  26. private MapControl mapControl1;
  27. private PosRes info;
  28. private CgRes cg;
  29. private List<SatInfo> listSat;
  30. public RHDTOParamEditor(PosRes info, MapControl mapControl)
  31. {
  32. InitializeComponent();
  33. this.info = info;
  34. itemSigTime.Text = $"{itemSigTime.Text}";
  35. this.layoutControl1.UseDefault();
  36. txtSigTime.UseDefault();
  37. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  38. this.listSat = new List<SatInfo>();
  39. this.mapControl1 = mapControl;
  40. }
  41. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  42. {
  43. StationRes station = null;
  44. CxRes cx = null;
  45. using (RHDWContext db = new RHDWContext())
  46. {
  47. listSat = await db.SatInfos.ToListAsync();
  48. }
  49. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  50. {
  51. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  52. cx = await db?.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  53. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  54. }
  55. if (cg != null)
  56. {
  57. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  58. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  59. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  60. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  61. this.txtSigTime.EditValue = info.SigTime;
  62. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  63. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  64. }
  65. if (cx != null)
  66. {
  67. this.txtcxFx.Text = $"{cx.Fx}";
  68. }
  69. if (station != null)
  70. {
  71. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  72. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  73. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  74. this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
  75. }
  76. }
  77. public bool CheckParam()
  78. {
  79. dxErrorProvider.ClearErrors();
  80. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  81. {
  82. return false;
  83. }
  84. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  85. {
  86. return false;
  87. }
  88. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  89. {
  90. return false;
  91. }
  92. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  93. {
  94. return false;
  95. }
  96. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  97. {
  98. return false;
  99. }
  100. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  101. {
  102. return false;
  103. }
  104. if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  105. {
  106. return false;
  107. }
  108. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  109. {
  110. return false;
  111. }
  112. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  113. {
  114. return false;
  115. }
  116. return true;
  117. }
  118. public bool CheckPosParam()
  119. {
  120. dxErrorProvider.ClearErrors();
  121. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  122. {
  123. return false;
  124. }
  125. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  126. {
  127. return false;
  128. }
  129. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  130. {
  131. return false;
  132. }
  133. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  134. {
  135. return false;
  136. }
  137. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  138. {
  139. return false;
  140. }
  141. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  142. {
  143. return false;
  144. }
  145. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  146. {
  147. return false;
  148. }
  149. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  150. {
  151. return false;
  152. }
  153. if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  154. {
  155. return false;
  156. }
  157. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  158. {
  159. return false;
  160. }
  161. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  162. {
  163. return false;
  164. }
  165. return true;
  166. }
  167. private void btnDtoLine_Click(object sender, EventArgs e)
  168. {
  169. if (!CheckParam()) { return; }
  170. try
  171. {
  172. var MsAnt = txtsatStation.GetLonLat();
  173. var CDBAnt = txtcdbStation.GetLonLat();
  174. var RefGeod = txtRefLocation.GetLonLat();
  175. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  176. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  177. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  178. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  179. double[] msEph = ucEphXYZMain.EphXYZ();
  180. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  181. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  182. dtoLineXd.MsEph = msEph;
  183. dtoLineXd.MsAnt = MsAnt;
  184. dtoLineXd.CDBAnt = CDBAnt;
  185. dtoLineXd.RefGeod = RefGeod;
  186. dtoLineXd.xdDto = DtoCdb;
  187. dtoLineXd.RefDto = YbMainDto;
  188. dtoLineXd.PosLon = info.PosLon;
  189. dtoLineXd.PosLat = info.PosLat;
  190. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  191. twoStartOption.MsEph = msEph;
  192. twoStartOption.NsEph = NsEph;
  193. twoStartOption.MsAnt = MsAnt;
  194. twoStartOption.NsAnt = MsAnt;
  195. twoStartOption.RefGeod = RefGeod;
  196. twoStartOption.TargetDto = DtoSx;
  197. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  198. twoStartOption.PosLon = info.PosLon;
  199. twoStartOption.PosLat = info.PosLat;
  200. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  201. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  202. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  203. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  204. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
  205. List<MapPolyline> polylines = new List<MapPolyline>();
  206. foreach (var dtoLine in xdDtoLine)
  207. {
  208. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]时差线", dtoLine.dtoLinePoints,true);
  209. if (mapline == null)
  210. {
  211. continue;
  212. }
  213. polylines.Add(mapline);
  214. }
  215. mapControl1.DrawDtoLine(polylines);
  216. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  217. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  218. }
  219. catch (Exception ex)
  220. {
  221. DW5S.Framework.LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  222. DxHelper.MsgBoxHelper.ShowError($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  223. }
  224. }
  225. private async void btnEphCalc_Click(object sender, EventArgs e)
  226. {
  227. dxErrorProvider.ClearErrors();
  228. if (this.txtSigTime.DateTime == DateTime.MinValue)
  229. {
  230. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  231. return;
  232. }
  233. var sigTime = this.txtSigTime.DateTime;
  234. try
  235. {
  236. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  237. if (mainxlInfo == null)
  238. {
  239. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  240. return;
  241. }
  242. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  243. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  244. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  245. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  246. if (adjaxlInfo == null)
  247. {
  248. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  249. return;
  250. }
  251. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  252. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  253. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  254. }
  255. catch (Exception ex)
  256. {
  257. DW5S.Framework.LogHelper.Error($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}", ex);
  258. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  259. }
  260. }
  261. private void btnPos_Click(object sender, EventArgs e)
  262. {
  263. if (!CheckPosParam()) { return; }
  264. txtPosRes.Text = " ";
  265. try
  266. {
  267. var MsAnt = txtsatStation.GetLonLat();
  268. var CDBAnt = txtcdbStation.GetLonLat();
  269. var RefGeod = txtRefLocation.GetLonLat();
  270. var cxStation = txtCxLocation.GetLonLat();
  271. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  272. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  273. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  274. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  275. var cxFx = Convert.ToDouble(this.txtcxFx.Text);
  276. double[] msEph = ucEphXYZMain.EphXYZ();
  277. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  278. var sigTime = txtSigTime.DateTime;
  279. var StationRes = new StationRes()
  280. {
  281. SatTxLon = MsAnt[0],
  282. SatTxLat = MsAnt[1],
  283. CdbTxLon = CDBAnt[0],
  284. CdbTxLat = CDBAnt[1],
  285. CxLon = cxStation[0],
  286. CxLat = cxStation[1],
  287. RefLon = RefGeod[0],
  288. RefLat = RefGeod[1],
  289. };
  290. var cgRes = new CgRes()
  291. {
  292. SigTime = sigTime,
  293. Dto1 = DtoSx,
  294. DtoCdb = DtoCdb,
  295. YbMainDto = YbMainDto,
  296. YbAdja1Dto = YbAdja1Dto,
  297. MainCode = cg.MainCode.Value,
  298. Adja1Code = cg.Adja1Code.Value,
  299. MainX = msEph[0],
  300. MainY = msEph[1],
  301. MainZ = msEph[2],
  302. Adja1X = nsEph[0],
  303. Adja1Y = nsEph[1],
  304. Adja1Z = nsEph[2],
  305. };
  306. var rhcxRes = new CxRes()
  307. {
  308. SigTime = sigTime,
  309. Fx = cxFx,
  310. };
  311. var res = PosApi.RH_Pos(cgRes, StationRes, rhcxRes, false);
  312. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  313. }
  314. catch (Exception ex)
  315. {
  316. DW5S.Framework.LogHelper.Error($"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}", ex);
  317. DxHelper.MsgBoxHelper.ShowError($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  318. }
  319. }
  320. }
  321. }