RHDTOParamEditor.cs 13 KB

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