using DevExpress.XtraMap; using DxHelper; using ExtensionsDev; using System; using System.CodeDom; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using DW5S.KxcApi; using DW5S.DTO; using DW5S.Entity; using DW5S.Repostory; using Microsoft.Extensions.Logging; namespace DW5S.App.EditForms { public partial class RHDTOParamEditor : DevExpress.XtraEditors.XtraUserControl { [Autowired] private readonly ILogger logger; [Autowired] private readonly UnitOfWork unitOfWork; private MapControl mapControl1; private PosRes info; private CgRes cg; private List listSat; public RHDTOParamEditor(PosRes info, MapControl mapControl) { InitializeComponent(); this.info = info; itemSigTime.Text = $"{itemSigTime.Text}"; this.layoutControl1.UseDefault(); txtSigTime.UseDefault(); this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数"; this.listSat = new List(); this.mapControl1 = mapControl; } private async void X2D1DTOParamEditor_Load(object sender, EventArgs e) { StationRes station = null; CxRes cx = null; var repsSat = unitOfWork.Of(); listSat.AddRange(await repsSat.GetAllAsync()); var repsCg = unitOfWork.Of(); cg = await repsCg.FirstOrDefaultAsync(m => m.Id == info.CgResID); var repsCx = unitOfWork.Of(); cx = await repsCx.FirstOrDefaultAsync(m => m.Id == info.CxResID); var repsStation = unitOfWork.Of(); station = await repsStation.FirstOrDefaultAsync(m => m.Id == info.StationResID); if (cg != null) { this.txtDtoSx.Text = $"{cg.Dto1.Value}"; this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}"; this.txtYbMain.Text = $"{cg.YbMainDto.Value}"; this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}"; this.txtSigTime.EditValue = info.SigTime; ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black); ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black); } if (cx != null) { this.txtcxFx.Text = $"{cx.Fx}"; } if (station != null) { this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}"; this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}"; this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}"; this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}"; } } public bool CheckParam() { dxErrorProvider.ClearErrors(); if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波")) { return false; } if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差")) { return false; } if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差")) { return false; } if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差")) { return false; } if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差")) { return false; } if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider)) { return false; } if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider)) { return false; } return true; } public bool CheckPosParam() { dxErrorProvider.ClearErrors(); if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波")) { return false; } if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站")) { return false; } if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值")) { return false; } if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差")) { return false; } if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差")) { return false; } if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差")) { return false; } if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差")) { return false; } if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider)) { return false; } if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider)) { return false; } return true; } private void btnDtoLine_Click(object sender, EventArgs e) { if (!CheckParam()) { return; } try { var MsAnt = txtsatStation.GetLonLat(); var CDBAnt = txtcdbStation.GetLonLat(); var RefGeod = txtRefLocation.GetLonLat(); var DtoSx = Convert.ToDouble(this.txtDtoSx.Text); var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text); var YbMainDto = Convert.ToDouble(this.txtYbMain.Text); var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text); double[] msEph = ucEphXYZMain.EphXYZ(); double[] NsEph = ucEphXYZAdaj.EphXYZ(); DtoLineXdOption dtoLineXd = new DtoLineXdOption(); dtoLineXd.MsEph = msEph; dtoLineXd.MsAnt = MsAnt; dtoLineXd.CDBAnt = CDBAnt; dtoLineXd.RefGeod = RefGeod; dtoLineXd.xdDto = DtoCdb; dtoLineXd.RefDto = YbMainDto; dtoLineXd.PosLon = info.PosLon; dtoLineXd.PosLat = info.PosLat; DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption(); twoStartOption.MsEph = msEph; twoStartOption.NsEph = NsEph; twoStartOption.MsAnt = MsAnt; twoStartOption.NsAnt = MsAnt; twoStartOption.RefGeod = RefGeod; twoStartOption.TargetDto = DtoSx; twoStartOption.RefDto = YbMainDto - YbAdja1Dto; twoStartOption.PosLon = info.PosLon; twoStartOption.PosLat = info.PosLat; var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat; if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString(); var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat; if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString(); var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd); List polylines = new List(); foreach (var dtoLine in xdDtoLine) { var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]时差线", dtoLine.dtoLinePoints, true); if (mapline == null) { continue; } polylines.Add(mapline); } mapControl1.DrawDtoLine(polylines); var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption); mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine); } catch (Exception ex) { string msg = $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.Id},SigTime={info.SigTime}"; logger.LogError(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } } private async void btnEphCalc_Click(object sender, EventArgs e) { dxErrorProvider.ClearErrors(); if (this.txtSigTime.DateTime == DateTime.MinValue) { dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!"); return; } var sigTime = this.txtSigTime.DateTime; var repsXl = unitOfWork.Of() as XlRepository; try { var mainxlInfo = await repsXl.GetLatestAsync(cg.MainCode.Value, sigTime); if (mainxlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历"); return; } var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime }; var maineph = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("Xl/Calc"), XlCalcDto); ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red); var adjaxlInfo = await repsXl.GetLatestAsync(cg.Adja1Code.Value, sigTime); if (adjaxlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历"); return; } XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime }; var adjaeph = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("Xl/Calc"), XlCalcDto); ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red); } catch (Exception ex) { string msg = $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}"; logger.LogError(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } } private void btnPos_Click(object sender, EventArgs e) { if (!CheckPosParam()) { return; } txtPosRes.Text = " "; try { var MsAnt = txtsatStation.GetLonLat(); var CDBAnt = txtcdbStation.GetLonLat(); var RefGeod = txtRefLocation.GetLonLat(); var cxStation = txtCxLocation.GetLonLat(); var DtoSx = Convert.ToDouble(this.txtDtoSx.Text); var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text); var YbMainDto = Convert.ToDouble(this.txtYbMain.Text); var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text); var cxFx = Convert.ToDouble(this.txtcxFx.Text); double[] msEph = ucEphXYZMain.EphXYZ(); double[] nsEph = ucEphXYZAdaj.EphXYZ(); var sigTime = txtSigTime.DateTime; var StationRes = new StationRes() { SatTxLon = MsAnt[0], SatTxLat = MsAnt[1], CdbTxLon = CDBAnt[0], CdbTxLat = CDBAnt[1], CxLon = cxStation[0], CxLat = cxStation[1], RefLon = RefGeod[0], RefLat = RefGeod[1], }; var cgRes = new CgRes() { SigTime = sigTime, Dto1 = DtoSx, DtoCdb = DtoCdb, YbMainDto = YbMainDto, YbAdja1Dto = YbAdja1Dto, MainCode = cg.MainCode.Value, Adja1Code = cg.Adja1Code.Value, MainX = msEph[0], MainY = msEph[1], MainZ = msEph[2], Adja1X = nsEph[0], Adja1Y = nsEph[1], Adja1Z = nsEph[2], }; var rhcxRes = new CxRes() { SigTime = sigTime, Fx = cxFx, }; var res = PosApi.RH_Pos(cgRes, StationRes, rhcxRes, false); this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]"; } catch (Exception ex) { string msg = $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.Id},SigTime={info.SigTime}"; logger.LogError(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } } } }