using DevExpress.XtraMap; using DxHelper; using ExtensionsDev; using System; using System.CodeDom; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; 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.Dto; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.EditForms { public partial class X2D1EllipesEditor : DevExpress.XtraEditors.XtraUserControl { private MapControl mapControl1; private PosRes info; private CgRes cg; private List listSat; public X2D1EllipesEditor(PosRes info, MapControl mapControl) { InitializeComponent(); this.info = info; itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})"; this.layoutControl1.UseDefault(); txtSigTime.UseDefault(); this.listSat = new List(); this.mapControl1 = mapControl; } private async void X2D1DTOParamEditor_Load(object sender, EventArgs e) { this.layoutControl1.BestFit(); 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.txtSigTime.EditValue = info.SigTime; txtEphMain.SetParam("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz), Color.Black); txtEphAdja.SetParam("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz), Color.Black); } if (station != null) { this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}"; this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}"; this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}"; } if (info.PosResType == EnumPosResType.X2D1NoRef) { txtRefLocation.Properties.ReadOnly = true; this.txtRefLocation.Text = $"{0},{0}"; } } public bool CheckParam() { dxErrorProvider.ClearErrors(); if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波")) { return false; } if (!txtEphMain.CheckEph(dxErrorProvider)) { return false; } if (!txtEphAdja.CheckEph(dxErrorProvider)) { return false; } return true; } private async void btnDtoLine_Click(object sender, EventArgs e) { if (!CheckParam()) { return; } try { var MsAnt = txtsatStation.GetLonLat(); var CDBAnt = txtcdbStation.GetLonLat(); var pos = txtPosLocation.GetLonLat(); var RefGeod = txtRefLocation.GetLonLat(); double[] ephMain = txtEphMain.EphParam(); double[] ephAdja = txtEphAdja.EphParam(); var dto = new ErrEllipseX2D1Dto() { MainX = ephMain[0], MainY = ephMain[1], MainZ = ephMain[2], AdjaX = ephAdja[0], AdjaY = ephAdja[1], AdjaZ = ephAdja[2], CdbLon = CDBAnt[0], CdbLat = CDBAnt[1], RefLon = RefGeod[0], RefLat = RefGeod[1], PosLon = pos[0], PosLat = pos[1], DtoErrus = Convert.ToDouble(txtDtousErr1.Text), EphErr = Convert.ToDouble(txtSatLocErr1.Text), OutputErrPoint = true, }; if (info.PosResType == EnumPosResType.X2D1) { dto = dto.WithRef(RefGeod[0], RefGeod[1]); } var rsp = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("DetectCg/ErrorEllipse2X1D"), dto, 30); if (rsp.code != 200) { await LogHelper.Error($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{rsp.msg}"); DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}误差椭圆失败,{rsp.msg}"); } else { this.mapControl1.DrawErrEllipse(rsp.data.LongRadius, rsp.data.ShortRadius, rsp.data.GeoPoints.Select(t => (t.Lon, t.Lat))); this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}误差椭圆.长半轴={rsp.data.LongRadius:f1},短半轴={rsp.data.ShortRadius:f1},倾角={rsp.data.DipAngle:f2}"; } } catch (Exception ex) { Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}"); DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}"); } } 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; try { var mainxlInfo = await XlRepository.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); txtEphMain.SetParam("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z, maineph.data.VX, maineph.data.VY, maineph.data.VZ), Color.Red); var adjaxlInfo = await XlRepository.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); txtEphAdja.SetParam("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z, adjaeph.data.VX, adjaeph.data.VY, adjaeph.data.VZ), Color.Red); } catch (Exception ex) { Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}"); DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}"); } } } }