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 X3PosParamEditor : DevExpress.XtraEditors.XtraUserControl { private PosRes info; private CgRes cg; public X3PosParamEditor(PosRes info, MapControl mapControl) { InitializeComponent(); this.info = info; itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})"; this.layoutControl1.UseDefault(); sigTime.UseDefault(); this.labelControl1.Text = $""; 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 (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:f4},{station.SatTxLat:f4}"; this.txtRefLocation.Text = $"{station.RefLon:f4},{station.RefLat:f4}"; } 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 sigTime = this.sigTime.DateTime; 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(); var StationRes = new StationRes() { SatTxLon = MsAnt[0], SatTxLat = MsAnt[1], RefLon = RefGeod[0], RefLat = RefGeod[1], }; var cgRes = new CgRes() { SigTime = sigTime, Dto1 = DtoSx, Dto2 = DtoSx1, YbMainDto = YbMainDto, YbAdja1Dto = YbAdja1Dto, YbAdja2Dto = YbAdja2Dto, MainX = msEph[0], MainY = msEph[1], MainZ = msEph[2], Adja1X = Ns1Eph[0], Adja1Y = Ns1Eph[1], Adja1Z = Ns1Eph[2], Adja2X = Ns2Eph[0], Adja2Y = Ns2Eph[1], Adja2Z = Ns2Eph[2], }; var res = info.PosResType == EnumPosResType.X3 ? PosApi.X3_Pos(cgRes, StationRes) : PosApi.X3_PosNoRef(cgRes, StationRes); this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]"; } 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 btnXl_Click(object sender, EventArgs e) { if (this.sigTime.DateTime == DateTime.MinValue) { DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!"); return; } try { var sigTime = this.sigTime.DateTime; 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()}推算星历失败"); } } } }