X3DTOParamEditor.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. using DevExpress.XtraMap;
  2. using ExtensionsDev;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.Entity;
  6. using System.Drawing;
  7. using System.Linq;
  8. using XdCxRhDW.Api;
  9. using XdCxRhDW.Dto;
  10. using XdCxRhDW.Entity;
  11. using XdCxRhDW.Repostory;
  12. namespace XdCxRhDW.App.EditForms
  13. {
  14. public partial class X3DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  15. {
  16. private MapControl mapControl1;
  17. private PosRes info;
  18. private CgRes cg;
  19. private List<SatInfo> listSat;
  20. public X3DTOParamEditor(PosRes info, MapControl mapControl)
  21. {
  22. InitializeComponent();
  23. this.info = info;
  24. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  25. this.layoutControl1.UseDefault();
  26. sigTime.UseDefault();
  27. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  28. this.mapControl1 = mapControl;
  29. }
  30. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  31. {
  32. this.layoutControl1.BestFit();
  33. StationRes station = null;
  34. using (RHDWContext db = new RHDWContext())
  35. {
  36. listSat = await db.SatInfos.ToListAsync();
  37. }
  38. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  39. {
  40. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  41. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  42. }
  43. if (cg != null)
  44. {
  45. //cg.Dto1 = 0.006619721 * 1e6;
  46. //cg.Dto2 = 0.019163671 * 1e6;
  47. //cg.MainX = -42196316.05;
  48. //cg.MainY = -2576593.07;
  49. //cg.MainZ = -2106302.976;
  50. ////4796457.421 41879814.45 29663.959
  51. //cg.Adja1X = 4796457.421;
  52. //cg.Adja1Y = 41879814.45;
  53. //cg.Adja1Z = 29663.959;
  54. ////-38203751.6 17804028.76 10625.117
  55. //cg.Adja2X = -38203751.6;
  56. //cg.Adja2Y = 17804028.76;
  57. //cg.Adja2Z = 10625.117;
  58. //cg.YbMainDto = -0.274385841 * 1e6;
  59. //cg.YbAdja1Dto = -0.254401508 * 1e6;
  60. //cg.YbAdja2Dto = -0.252550478 * 1e6;
  61. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  62. this.txtDtoSx1.Text = $"{cg.Dto2.Value}";
  63. if (info.PosResType == EnumPosResType.X3TwoDto)
  64. {
  65. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  66. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  67. this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value}";
  68. }
  69. this.sigTime.EditValue = info.SigTime;
  70. var mainEph = (cg.MainX, cg.MainY, cg.MainZ);
  71. ucEphXYZMain.SetXYZ($"主星", cg.MainCode, mainEph, Color.Black);
  72. var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z);
  73. ucEphXYZAdja1.SetXYZ($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
  74. var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z);
  75. ucEphXYZAdja2.SetXYZ($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
  76. }
  77. if (station != null)
  78. {
  79. this.txtsatStation1.Text = $"{station.MSatTxLon},{station.MSatTxLat}";
  80. this.txtsatStation2.Text = $"{station.N1SatTxLon},{station.N1SatTxLat}";
  81. this.txtsatStation3.Text = $"{station.N2SatTxLon},{station.N2SatTxLat}";
  82. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  83. }
  84. if (info.PosResType != EnumPosResType.X3TwoDto)
  85. {
  86. //txtYbMain.Properties.ReadOnly = true;
  87. //txtYbAdja.Properties.ReadOnly = true;
  88. //txtYbAdja1.Properties.ReadOnly = true;
  89. //txtRefLocation.Properties.ReadOnly = true;
  90. this.txtRefLocation.Text = $"{0},{0}";
  91. }
  92. }
  93. public bool CheckParam()
  94. {
  95. dxErrorProvider.ClearErrors();
  96. if (!txtsatStation1.CheckLonLat(dxErrorProvider, "接收站"))
  97. {
  98. return false;
  99. }
  100. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text) && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  101. {
  102. return false;
  103. }
  104. if (!txtDtoSx.CheckDouble(dxErrorProvider, "主邻1时差"))
  105. {
  106. return false;
  107. }
  108. if (!txtDtoSx1.CheckDouble(dxErrorProvider, "主邻2时差"))
  109. {
  110. return false;
  111. }
  112. if (!string.IsNullOrWhiteSpace(txtYbMain.Text) && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  113. {
  114. return false;
  115. }
  116. if (!string.IsNullOrWhiteSpace(txtYbAdja.Text) && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星1时差"))
  117. {
  118. return false;
  119. }
  120. if (!string.IsNullOrWhiteSpace(txtYbAdja1.Text) && !txtYbAdja1.CheckDouble(dxErrorProvider, "样本邻星2时差"))
  121. {
  122. return false;
  123. }
  124. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  125. {
  126. return false;
  127. }
  128. if (!ucEphXYZAdja1.CheckEphXYZ(dxErrorProvider))
  129. {
  130. return false;
  131. }
  132. if (!ucEphXYZAdja2.CheckEphXYZ(dxErrorProvider))
  133. {
  134. return false;
  135. }
  136. return true;
  137. }
  138. private void btnDtoLine_Click(object sender, EventArgs e)
  139. {
  140. if (!CheckParam()) { return; }
  141. try
  142. {
  143. var MsAnt = txtsatStation1.GetLonLat();
  144. var Ns1Ant = txtsatStation2.GetLonLat();
  145. var Ns2Ant = txtsatStation3.GetLonLat();
  146. var RefGeod = string.IsNullOrWhiteSpace(txtRefLocation.Text) ? new double[3] { 0, 0, 0 } : txtRefLocation.GetLonLat();
  147. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  148. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  149. var YbMainDto = string.IsNullOrWhiteSpace(txtYbMain.Text) ? 0 : Convert.ToDouble(this.txtYbMain.Text);
  150. var YbAdja1Dto = string.IsNullOrWhiteSpace(txtYbAdja.Text) ? 0 : Convert.ToDouble(this.txtYbAdja.Text);
  151. var YbAdja2Dto = string.IsNullOrWhiteSpace(txtYbAdja1.Text) ? 0 : Convert.ToDouble(this.txtYbAdja1.Text);
  152. double[] msEph = ucEphXYZMain.EphXYZ();
  153. double[] Ns1Eph = ucEphXYZAdja1.EphXYZ();
  154. double[] Ns2Eph = ucEphXYZAdja2.EphXYZ();
  155. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  156. twoStartOption.MsEph = msEph;
  157. twoStartOption.NsEph = Ns1Eph;
  158. twoStartOption.MsAnt = MsAnt;
  159. twoStartOption.NsAnt = Ns1Ant;
  160. twoStartOption.RefGeod = RefGeod;
  161. twoStartOption.TargetDto = -DtoSx;
  162. twoStartOption.RefDto = -(YbMainDto - YbAdja1Dto);
  163. twoStartOption.PosLon = info.PosLon;
  164. twoStartOption.PosLat = info.PosLat;
  165. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  166. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  167. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  168. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  169. var ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  170. if (string.IsNullOrWhiteSpace(ad2sat)) ad2sat = cg.Adja2Code.Value.ToString();
  171. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  172. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  173. && !string.IsNullOrWhiteSpace(txtYbAdja.Text)
  174. && !string.IsNullOrWhiteSpace(txtYbAdja1.Text))
  175. {
  176. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  177. mapControl1.DrawDtoLine($"[{msat},{nsat}]带参时差线", tsDtoLine);
  178. twoStartOption.NsAnt = Ns2Ant;
  179. twoStartOption.NsEph = Ns2Eph;
  180. twoStartOption.RefDto = -(YbMainDto - YbAdja2Dto);
  181. twoStartOption.TargetDto = -DtoSx1;
  182. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  183. mapControl1.DrawDtoLine($"[{msat},{ad2sat}]带参时差线", tsDtoLine1);
  184. }
  185. else
  186. {
  187. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  188. mapControl1.DrawDtoLine($"[{msat},{nsat}]无参时差线", tsDtoLine);
  189. twoStartOption.NsAnt = Ns2Ant;
  190. twoStartOption.NsEph = Ns2Eph;
  191. twoStartOption.TargetDto = -DtoSx1;
  192. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  193. mapControl1.DrawDtoLine($"[{msat},{ad2sat}]无参时差线", tsDtoLine1);
  194. }
  195. }
  196. catch (Exception ex)
  197. {
  198. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  199. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  200. }
  201. }
  202. private async void btnEphCalc_Click(object sender, EventArgs e)
  203. {
  204. dxErrorProvider.ClearErrors();
  205. if (this.sigTime.DateTime == DateTime.MinValue)
  206. {
  207. dxErrorProvider.SetError(this.sigTime, "信号时间不能为空!");
  208. return;
  209. }
  210. var sigTime = this.sigTime.DateTime;
  211. try
  212. {
  213. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  214. if (xlInfo == null)
  215. {
  216. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  217. return;
  218. }
  219. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  220. if (xlInfo1 == null)
  221. {
  222. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  223. return;
  224. }
  225. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  226. if (xlInfo2 == null)
  227. {
  228. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  229. return;
  230. }
  231. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, SigTime = sigTime };
  232. var mEph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  233. XlCalcDto.tleStr = xlInfo1.TwoLine;
  234. var nEph1 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  235. XlCalcDto.tleStr = xlInfo2.TwoLine;
  236. var nEph2 = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  237. var mainEph = (mEph.data.X, mEph.data.Y, mEph.data.Z);
  238. ucEphXYZMain.SetXYZ($"主星", cg.MainCode, mainEph, Color.Red);
  239. var adja1Eph = (nEph1.data.X, nEph1.data.Y, nEph1.data.Z);
  240. ucEphXYZAdja1.SetXYZ($"邻星1", cg.Adja1Code, adja1Eph, Color.Red);
  241. var adja2Eph = (nEph2.data.X, nEph2.data.Y, nEph2.data.Z);
  242. ucEphXYZAdja2.SetXYZ($"邻星2", cg.Adja2Code, adja2Eph, Color.Red);
  243. }
  244. catch (Exception ex)
  245. {
  246. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  247. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败,{ex.Message}");
  248. }
  249. }
  250. private void btnPos_Click(object sender, EventArgs e)
  251. {
  252. if (!CheckParam()) { return; }
  253. try
  254. {
  255. var MsAnt = txtsatStation1.GetLonLat();
  256. var Ns1Ant = txtsatStation2.GetLonLat();
  257. var Ns2Ant = txtsatStation3.GetLonLat();
  258. var RefGeod = string.IsNullOrWhiteSpace(txtRefLocation.Text) ? new double[3] { 0, 0, 0 } : txtRefLocation.GetLonLat();
  259. var sigTime = this.sigTime.DateTime;
  260. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  261. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  262. var YbMainDto = string.IsNullOrWhiteSpace(txtYbMain.Text) ? 0 : Convert.ToDouble(this.txtYbMain.Text);
  263. var YbAdja1Dto = string.IsNullOrWhiteSpace(txtYbAdja.Text) ? 0 : Convert.ToDouble(this.txtYbAdja.Text);
  264. var YbAdja2Dto = string.IsNullOrWhiteSpace(txtYbAdja1.Text) ? 0 : Convert.ToDouble(this.txtYbAdja1.Text);
  265. double[] msEph = ucEphXYZMain.EphXYZ();
  266. double[] Ns1Eph = ucEphXYZAdja1.EphXYZ();
  267. double[] Ns2Eph = ucEphXYZAdja2.EphXYZ();
  268. var StationRes = new StationRes()
  269. {
  270. MSatTxLon = MsAnt[0],
  271. MSatTxLat = MsAnt[1],
  272. N1SatTxLon = Ns1Ant[0],
  273. N1SatTxLat = Ns1Ant[1],
  274. N2SatTxLon = Ns2Ant[0],
  275. N2SatTxLat = Ns2Ant[1],
  276. RefLon = RefGeod[0],
  277. RefLat = RefGeod[1],
  278. };
  279. var cgRes = new CgRes()
  280. {
  281. SigTime = sigTime,
  282. Dto1 = DtoSx,
  283. Dto2 = DtoSx1,
  284. YbMainDto = YbMainDto,
  285. YbAdja1Dto = YbAdja1Dto,
  286. YbAdja2Dto = YbAdja2Dto,
  287. MainX = msEph[0],
  288. MainY = msEph[1],
  289. MainZ = msEph[2],
  290. Adja1X = Ns1Eph[0],
  291. Adja1Y = Ns1Eph[1],
  292. Adja1Z = Ns1Eph[2],
  293. Adja2X = Ns2Eph[0],
  294. Adja2Y = Ns2Eph[1],
  295. Adja2Z = Ns2Eph[2],
  296. };
  297. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  298. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  299. && !string.IsNullOrWhiteSpace(txtYbAdja.Text)
  300. && !string.IsNullOrWhiteSpace(txtYbAdja1.Text))
  301. {
  302. var res = PosApi.X3_Pos(cgRes, StationRes);
  303. this.txtPosRes.Text = $"带参定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  304. }
  305. else
  306. {
  307. var res = PosApi.X3_PosNoRef(cgRes, StationRes);
  308. this.txtPosRes.Text = $"无参定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  309. }
  310. }
  311. catch (Exception ex)
  312. {
  313. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  314. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  315. }
  316. }
  317. }
  318. }