RHDTOParamEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. var repsSat = unitOfWork.Of<SatInfo>();
  46. listSat.AddRange(await repsSat.GetAllAsync());
  47. var repsCg = unitOfWork.Of<CgRes>();
  48. cg = await repsCg.FirstOrDefaultAsync(m => m.Id == info.CgResID);
  49. var repsCx = unitOfWork.Of<CxRes>();
  50. cx = await repsCx.FirstOrDefaultAsync(m => m.Id == info.CxResID);
  51. var repsStation = unitOfWork.Of<StationRes>();
  52. station = await repsStation.FirstOrDefaultAsync(m => m.Id == info.StationResID);
  53. if (cg != null)
  54. {
  55. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  56. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  57. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  58. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  59. this.txtSigTime.EditValue = info.SigTime;
  60. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  61. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  62. }
  63. if (cx != null)
  64. {
  65. this.txtcxFx.Text = $"{cx.Fx}";
  66. }
  67. if (station != null)
  68. {
  69. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  70. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  71. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  72. this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
  73. }
  74. }
  75. public bool CheckParam()
  76. {
  77. dxErrorProvider.ClearErrors();
  78. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  79. {
  80. return false;
  81. }
  82. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  83. {
  84. return false;
  85. }
  86. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  87. {
  88. return false;
  89. }
  90. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  91. {
  92. return false;
  93. }
  94. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  95. {
  96. return false;
  97. }
  98. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  99. {
  100. return false;
  101. }
  102. if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  103. {
  104. return false;
  105. }
  106. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  107. {
  108. return false;
  109. }
  110. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  111. {
  112. return false;
  113. }
  114. return true;
  115. }
  116. public bool CheckPosParam()
  117. {
  118. dxErrorProvider.ClearErrors();
  119. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  120. {
  121. return false;
  122. }
  123. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  124. {
  125. return false;
  126. }
  127. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  128. {
  129. return false;
  130. }
  131. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  132. {
  133. return false;
  134. }
  135. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  136. {
  137. return false;
  138. }
  139. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  140. {
  141. return false;
  142. }
  143. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  144. {
  145. return false;
  146. }
  147. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  148. {
  149. return false;
  150. }
  151. if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  152. {
  153. return false;
  154. }
  155. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  156. {
  157. return false;
  158. }
  159. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  160. {
  161. return false;
  162. }
  163. return true;
  164. }
  165. private void btnDtoLine_Click(object sender, EventArgs e)
  166. {
  167. if (!CheckParam()) { return; }
  168. try
  169. {
  170. var MsAnt = txtsatStation.GetLonLat();
  171. var CDBAnt = txtcdbStation.GetLonLat();
  172. var RefGeod = txtRefLocation.GetLonLat();
  173. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  174. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  175. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  176. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  177. double[] msEph = ucEphXYZMain.EphXYZ();
  178. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  179. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  180. dtoLineXd.MsEph = msEph;
  181. dtoLineXd.MsAnt = MsAnt;
  182. dtoLineXd.CDBAnt = CDBAnt;
  183. dtoLineXd.RefGeod = RefGeod;
  184. dtoLineXd.xdDto = DtoCdb;
  185. dtoLineXd.RefDto = YbMainDto;
  186. dtoLineXd.PosLon = info.PosLon;
  187. dtoLineXd.PosLat = info.PosLat;
  188. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  189. twoStartOption.MsEph = msEph;
  190. twoStartOption.NsEph = NsEph;
  191. twoStartOption.MsAnt = MsAnt;
  192. twoStartOption.NsAnt = MsAnt;
  193. twoStartOption.RefGeod = RefGeod;
  194. twoStartOption.TargetDto = DtoSx;
  195. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  196. twoStartOption.PosLon = info.PosLon;
  197. twoStartOption.PosLat = info.PosLat;
  198. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  199. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  200. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  201. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  202. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
  203. List<MapPolyline> polylines = new List<MapPolyline>();
  204. foreach (var dtoLine in xdDtoLine)
  205. {
  206. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]时差线", dtoLine.dtoLinePoints, true);
  207. if (mapline == null)
  208. {
  209. continue;
  210. }
  211. polylines.Add(mapline);
  212. }
  213. mapControl1.DrawDtoLine(polylines);
  214. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  215. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  216. }
  217. catch (Exception ex)
  218. {
  219. string msg = $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.Id},SigTime={info.SigTime}";
  220. logger.LogError(ex, msg);
  221. DxHelper.MsgBoxHelper.ShowError(msg);
  222. }
  223. }
  224. private async void btnEphCalc_Click(object sender, EventArgs e)
  225. {
  226. dxErrorProvider.ClearErrors();
  227. if (this.txtSigTime.DateTime == DateTime.MinValue)
  228. {
  229. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  230. return;
  231. }
  232. var sigTime = this.txtSigTime.DateTime;
  233. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  234. try
  235. {
  236. var mainxlInfo = await repsXl.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 repsXl.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. string msg = $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}";
  258. logger.LogError(ex, msg);
  259. DxHelper.MsgBoxHelper.ShowError(msg);
  260. }
  261. }
  262. private void btnPos_Click(object sender, EventArgs e)
  263. {
  264. if (!CheckPosParam()) { return; }
  265. txtPosRes.Text = " ";
  266. try
  267. {
  268. var MsAnt = txtsatStation.GetLonLat();
  269. var CDBAnt = txtcdbStation.GetLonLat();
  270. var RefGeod = txtRefLocation.GetLonLat();
  271. var cxStation = txtCxLocation.GetLonLat();
  272. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  273. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  274. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  275. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  276. var cxFx = Convert.ToDouble(this.txtcxFx.Text);
  277. double[] msEph = ucEphXYZMain.EphXYZ();
  278. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  279. var sigTime = txtSigTime.DateTime;
  280. var StationRes = new StationRes()
  281. {
  282. SatTxLon = MsAnt[0],
  283. SatTxLat = MsAnt[1],
  284. CdbTxLon = CDBAnt[0],
  285. CdbTxLat = CDBAnt[1],
  286. CxLon = cxStation[0],
  287. CxLat = cxStation[1],
  288. RefLon = RefGeod[0],
  289. RefLat = RefGeod[1],
  290. };
  291. var cgRes = new CgRes()
  292. {
  293. SigTime = sigTime,
  294. Dto1 = DtoSx,
  295. DtoCdb = DtoCdb,
  296. YbMainDto = YbMainDto,
  297. YbAdja1Dto = YbAdja1Dto,
  298. MainCode = cg.MainCode.Value,
  299. Adja1Code = cg.Adja1Code.Value,
  300. MainX = msEph[0],
  301. MainY = msEph[1],
  302. MainZ = msEph[2],
  303. Adja1X = nsEph[0],
  304. Adja1Y = nsEph[1],
  305. Adja1Z = nsEph[2],
  306. };
  307. var rhcxRes = new CxRes()
  308. {
  309. SigTime = sigTime,
  310. Fx = cxFx,
  311. };
  312. var res = PosApi.RH_Pos(cgRes, StationRes, rhcxRes, false);
  313. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  314. }
  315. catch (Exception ex)
  316. {
  317. string msg = $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.Id},SigTime={info.SigTime}";
  318. logger.LogError(ex, msg);
  319. DxHelper.MsgBoxHelper.ShowError(msg);
  320. }
  321. }
  322. }
  323. }