using DevExpress.XtraMap; using DxHelper; using ExtensionsDev; using System; using System.CodeDom; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using XdCxRhDW.Api; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.EditForms { public partial class X3DTOParamEditor : DevExpress.XtraEditors.XtraUserControl { private MapControl mapControl1; private PosRes info; private CgRes cg; private List listSat; public X3DTOParamEditor(PosRes info, MapControl mapControl) { InitializeComponent(); this.layoutControl1.UseDefault(); sigTime.UseDefault(); this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数"; this.info = info; this.mapControl1 = mapControl; txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged; txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged; } private void TxtRefLocation_EditValueChanged(object sender, EventArgs e) { txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"); } private void TxtsatStation_EditValueChanged(object sender, EventArgs e) { txtsatStation.CheckLonLat(dxErrorProvider, "接收站"); } private async void X3DTOParamEditor_Load(object sender, EventArgs e) { StationRes station = null; using (RHDWContext db = new RHDWContext()) { listSat = await db.SatInfos.ToListAsync(); } using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime)) { cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync(); station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync(); } if (cg != null) { this.txtDtoSx.Text = $"{cg.Dto1.Value:f4}"; this.txtDtoSx1.Text = $"{cg.Dto2.Value:f4}"; if (info.PosResType == EnumPosResType.X3) { this.txtYbMain.Text = $"{cg.YbMainDto.Value:f4}"; this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f4}"; this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value:f4}"; } this.sigTime.EditValue = info.SigTime; var mainEph = (cg.MainX, cg.MainY, cg.MainZ); ucEphXYZMain.SetXYZ($"主星", cg.MainCode, mainEph, Color.Black); var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z); ucEphXYZAdja1.SetXYZ($"邻星1", cg.Adja1Code, adja1Eph, Color.Black); var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z); ucEphXYZAdja2.SetXYZ($"邻星2", cg.Adja2Code, adja2Eph, Color.Black); } if (station != null) { this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}"; this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}"; } if (info.PosResType == EnumPosResType.X3NoRef) { txtYbMain.Properties.ReadOnly = true; txtYbAdja.Properties.ReadOnly = true; txtYbAdja1.Properties.ReadOnly = true; txtRefLocation.Properties.ReadOnly = true; this.txtRefLocation.Text = $"{0},{0}"; } } public bool CheckParam() { if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } return true; } private void btnOk_Click(object sender, EventArgs e) { if (!CheckParam()) { return; } try { var MsAnt = txtsatStation.GetLonLat(); var RefGeod = info.PosResType == EnumPosResType.X3 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 }; var DtoSx = Convert.ToDouble(this.txtDtoSx.Text); var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text); var YbMainDto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbMain.Text) : 0; var YbAdja1Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja.Text) : 0; var YbAdja2Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja1.Text) : 0; double[] msEph = ucEphXYZMain.EphXYZ(); double[] Ns1Eph = ucEphXYZAdja1.EphXYZ(); double[] Ns2Eph = ucEphXYZAdja2.EphXYZ(); DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption(); twoStartOption.MsEph = msEph; twoStartOption.NsEph = Ns1Eph; 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 ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat; if (string.IsNullOrWhiteSpace(ad2sat)) ad2sat = cg.Adja2Code.Value.ToString(); if (info.PosResType == EnumPosResType.X3) { var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption); mapControl1.DrawDtoPonit($"[{msat},{nsat}]带参时差线", tsDtoLine); twoStartOption.NsEph = Ns2Eph; twoStartOption.RefDto = YbMainDto - YbAdja2Dto; twoStartOption.TargetDto = DtoSx1; var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XStart(twoStartOption); mapControl1.DrawDtoPonit($"[{msat},{ad2sat}]带参时差线", tsDtoLine1); } else { var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption); mapControl1.DrawDtoPonit($"[{msat},{nsat}]无参时差线", tsDtoLine); twoStartOption.NsEph = Ns2Eph; twoStartOption.TargetDto = DtoSx1; var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption); mapControl1.DrawDtoPonit($"[{msat},{ad2sat}]无参时差线", tsDtoLine1); } } catch (Exception ex) { Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}"); DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败"); } } private async void btnEphCalc_Click(object sender, EventArgs e) { if (this.sigTime.DateTime == DateTime.MinValue) { DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!"); return; } var sigTime = this.sigTime.DateTime; try { var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime); if (xlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历"); return; } var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime); if (xlInfo1 == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历"); return; } var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime); if (xlInfo2 == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历"); return; } var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime.ToUtc()); var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime.ToUtc()); var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime.ToUtc()); var mainEph = (mEph.X, mEph.Y, mEph.Z); ucEphXYZMain.SetXYZ($"主星", cg.MainCode, mainEph, Color.Red); var adja1Eph = (nEph1.X, nEph1.Y, nEph1.Z); ucEphXYZAdja1.SetXYZ($"邻星1", cg.Adja1Code, adja1Eph, Color.Red); var adja2Eph = (nEph2.X, nEph2.Y, nEph2.Z); ucEphXYZAdja2.SetXYZ($"邻星2", cg.Adja2Code, adja2Eph, Color.Red); } catch (Exception ex) { Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}"); DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败"); } } } }