X2D1DTOParamEditor.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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.Configuration;
  9. using System.Data;
  10. using System.Data.Entity;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using XdCxRhDW.Api;
  16. using XdCxRhDW.Dto;
  17. using XdCxRhDW.Entity;
  18. using XdCxRhDW.Repostory;
  19. namespace XdCxRhDW.App.EditForms
  20. {
  21. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  22. {
  23. private MapControl mapControl1;
  24. private PosRes info;
  25. private CgRes cg;
  26. private List<SatInfo> listSat;
  27. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  28. {
  29. InitializeComponent();
  30. this.info = info;
  31. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  32. this.layoutControl1.UseDefault();
  33. txtSigTime.UseDefault();
  34. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  35. this.listSat = new List<SatInfo>();
  36. this.mapControl1 = mapControl;
  37. }
  38. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  39. {
  40. this.layoutControl1.BestFit();
  41. StationRes station = null;
  42. using (RHDWContext db = new RHDWContext())
  43. {
  44. listSat = await db.SatInfos.ToListAsync();
  45. }
  46. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  47. {
  48. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  49. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  50. }
  51. if (cg != null)
  52. {
  53. //if (info.PosResType == EnumPosResType.X2D1NoRef)
  54. //{
  55. // cg.Dto1 = 6348.6030;
  56. // cg.DtoCdb = 246616.0330;
  57. // cg.MainX = 11265194.9906;
  58. // cg.MainY = 40486056.6399;
  59. // cg.MainZ = -2055810.5412;
  60. // cg.Adja1X = 25525328.3455;
  61. // cg.Adja1Y = 33539987.1755;
  62. // cg.Adja1Z = -49504.0378;
  63. //}
  64. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  65. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  66. //if (info.PosResType == EnumPosResType.X2D1)
  67. //{
  68. // this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  69. // this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  70. //}
  71. this.txtSigTime.EditValue = info.SigTime;
  72. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  73. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  74. }
  75. if (station != null)
  76. {
  77. //if (info.PosResType == EnumPosResType.X2D1NoRef)
  78. //{
  79. // station.SatTxLon = 43.7;
  80. // station.SatTxLat = 12.9;
  81. // station.CdbTxLon = 43.7;
  82. // station.CdbTxLat = 12.9;
  83. //}
  84. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  85. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  86. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  87. }
  88. if (info.PosResType == EnumPosResType.X2D1NoRef)
  89. {
  90. txtYbMain.Properties.ReadOnly = true;
  91. txtYbAdja.Properties.ReadOnly = true;
  92. txtRefLocation.Properties.ReadOnly = true;
  93. this.txtRefLocation.Text = $"{0},{0}";
  94. }
  95. //double tarLon = 122.88, tarLat = 31.29;
  96. //double recLon = 118.5, recLat = 32.1;
  97. //double refLon = 121, refLat = 30;
  98. //double cdbLon = 122, cdbLat = 30;
  99. //var refEcef = PhysicsHelper.GeoToEcef((refLon, refLat, 0));
  100. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  101. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  102. //var cdbEcef = PhysicsHelper.GeoToEcef((cdbLon, cdbLat, 0));
  103. //var xl1 = (-41338971.25, 6141819.55, 5504123.22);
  104. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1, recEcef);
  105. //var dt2 = PhysicsHelper.Dto(tarEcef, cdbEcef);
  106. //var dto1 = dt1 - dt2;
  107. //var dt3 = PhysicsHelper.Dto(refEcef, xl1, recEcef);
  108. //var dto2 = dt3 - 0;
  109. }
  110. public bool CheckParam()
  111. {
  112. dxErrorProvider.ClearErrors();
  113. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  114. {
  115. return false;
  116. }
  117. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  118. {
  119. return false;
  120. }
  121. //if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  122. //{
  123. // return false;
  124. //}
  125. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  126. {
  127. return false;
  128. }
  129. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  130. {
  131. return false;
  132. }
  133. //if (info.PosResType == EnumPosResType.X2D1 && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  134. //{
  135. // return false;
  136. //}
  137. //if (info.PosResType == EnumPosResType.X2D1 && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  138. //{
  139. // return false;
  140. //}
  141. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  142. {
  143. return false;
  144. }
  145. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  146. {
  147. return false;
  148. }
  149. return true;
  150. }
  151. private void btnDtoLine_Click(object sender, EventArgs e)
  152. {
  153. if (!CheckParam()) { return; }
  154. try
  155. {
  156. var MsAnt = txtsatStation.GetLonLat();
  157. var CDBAnt = txtcdbStation.GetLonLat();
  158. var RefGeod = info.PosResType == EnumPosResType.X2D1NoRef ? new double[3] { 0, 0, 0 } : txtRefLocation.GetLonLat();
  159. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  160. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  161. var YbMainDto = info.PosResType == EnumPosResType.X2D1NoRef ? 0 : Convert.ToDouble(this.txtYbMain.Text);
  162. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1NoRef ? 0 : Convert.ToDouble(this.txtYbAdja.Text);
  163. double[] msEph = ucEphXYZMain.EphXYZ();
  164. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  165. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  166. dtoLineXd.MsEph = msEph;
  167. dtoLineXd.MsAnt = MsAnt;
  168. dtoLineXd.CDBAnt = CDBAnt;
  169. dtoLineXd.RefGeod = RefGeod;
  170. dtoLineXd.xdDto = DtoCdb;
  171. dtoLineXd.RefDto = YbMainDto;
  172. dtoLineXd.PosLon = info.PosLon;
  173. dtoLineXd.PosLat = info.PosLat;
  174. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  175. twoStartOption.MsEph = msEph;
  176. twoStartOption.NsEph = NsEph;
  177. twoStartOption.MsAnt = MsAnt;
  178. twoStartOption.NsAnt = MsAnt;
  179. twoStartOption.RefGeod = RefGeod;
  180. twoStartOption.TargetDto = DtoSx;
  181. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  182. twoStartOption.PosLon = info.PosLon;
  183. twoStartOption.PosLat = info.PosLat;
  184. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  185. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  186. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  187. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  188. string useNewGDOP = ConfigurationManager.AppSettings["UseNewGDOP"];
  189. if (info.PosResType == EnumPosResType.X2D1NoRef)
  190. {
  191. if (useNewGDOP == null || useNewGDOP == "0")
  192. {
  193. var xdDtoLine1 = DrawDtoLineHelper.DtoLineXdNoRefEx(dtoLineXd);
  194. mapControl1.DrawDtoLineTwo($"[{msat},超短{CDBAnt[0]}°]无参时差线", xdDtoLine1);
  195. }
  196. else
  197. {
  198. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRefNew(dtoLineXd);
  199. List<MapPolyline> polylines = new List<MapPolyline>();
  200. foreach (var dtoLine in xdDtoLine)
  201. {
  202. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]无参时差线", dtoLine.dtoLinePoints, true);
  203. if (mapline == null)
  204. {
  205. continue;
  206. }
  207. polylines.Add(mapline);
  208. }
  209. mapControl1.DrawDtoLine(polylines);
  210. }
  211. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  212. mapControl1.DrawDtoLine($"[{msat},{nsat}]无参时差线", tsDtoLine);
  213. }
  214. }
  215. catch (Exception ex)
  216. {
  217. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  218. DxHelper.MsgBoxHelper.ShowWarning($"绘制{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. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  254. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  255. }
  256. }
  257. private void btnPos_Click(object sender, EventArgs e)
  258. {
  259. if (!CheckParam()) { return; }
  260. txtPosRes.Text = " ";
  261. try
  262. {
  263. var MsAnt = txtsatStation.GetLonLat();
  264. var CDBAnt = txtcdbStation.GetLonLat();
  265. var RefGeod = info.PosResType == EnumPosResType.X2D1NoRef ? new double[3] { 0, 0, 0 } : txtRefLocation.GetLonLat();
  266. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  267. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  268. var YbMainDto = info.PosResType == EnumPosResType.X2D1NoRef ? 0 : Convert.ToDouble(this.txtYbMain.Text);
  269. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1NoRef ? 0 : Convert.ToDouble(this.txtYbAdja.Text);
  270. double[] msEph = ucEphXYZMain.EphXYZ();
  271. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  272. var sigTime = txtSigTime.DateTime;
  273. var StationRes = new StationRes()
  274. {
  275. SatTxLon = MsAnt[0],
  276. SatTxLat = MsAnt[1],
  277. CdbTxLon = CDBAnt[0],
  278. CdbTxLat = CDBAnt[1],
  279. RefLon = RefGeod[0],
  280. RefLat = RefGeod[1],
  281. };
  282. if (info.PosResType == EnumPosResType.X2D1NoRef)
  283. {
  284. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  285. {
  286. SigTime = sigTime,
  287. MainCode = cg.MainCode.Value,
  288. AdjaCode = cg.Adja1Code.Value,
  289. SxDto = DtoSx,
  290. XdDto = DtoCdb,
  291. MainX = msEph[0],
  292. MainY = msEph[1],
  293. MainZ = msEph[2],
  294. AdjaX = nsEph[0],
  295. AdjaY = nsEph[1],
  296. AdjaZ = nsEph[2],
  297. SatTxLon = MsAnt[0],
  298. SatTxLat = MsAnt[1],
  299. CdbTxLon = CDBAnt[0],
  300. CdbTxLat = CDBAnt[1],
  301. };
  302. var cgRes = new CgRes()
  303. {
  304. SigTime = dto.SigTime,
  305. Dto1 = dto.SxDto,
  306. Dfo1 = dto.SxDfo,
  307. Snr1 = dto.SxSnr,
  308. DtoCdb = dto.XdDto,
  309. DfoCdb = dto.XdDfo,
  310. SnrCdb = dto.XdSnr,
  311. //StationResID = StationRes.ID,
  312. MainCode = dto.MainCode,
  313. Adja1Code = dto.AdjaCode,
  314. //TaskID = runTask.ID,
  315. MainX = dto.MainX,
  316. MainY = dto.MainY,
  317. MainZ = dto.MainZ,
  318. Adja1X = dto.AdjaX,
  319. Adja1Y = dto.AdjaY,
  320. Adja1Z = dto.AdjaZ,
  321. };
  322. double[] res;
  323. if (ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"] != null
  324. && ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"].ToLower() != "false"
  325. && ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"].ToLower() != "0")
  326. {
  327. res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes);
  328. }
  329. else
  330. {
  331. res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  332. }
  333. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  334. }
  335. }
  336. catch (Exception ex)
  337. {
  338. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  339. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  340. }
  341. }
  342. }
  343. }