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 X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl { private MapControl mapControl1; private PosRes info; private CgRes cg; private List listSat; public X2D1DTOParamEditor(PosRes info, MapControl mapControl) { InitializeComponent(); this.info = info; itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})"; 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) { 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) { //if (info.PosResType == EnumPosResType.X2D1NoRef) //{ // cg.Dto1 = 6348.6030; // cg.DtoCdb = 246616.0330; // cg.MainX = 11265194.9906; // cg.MainY = 40486056.6399; // cg.MainZ = -2055810.5412; // cg.Adja1X = 25525328.3455; // cg.Adja1Y = 33539987.1755; // cg.Adja1Z = -49504.0378; //} this.txtDtoSx.Text = $"{cg.Dto1.Value}"; this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}"; if (info.PosResType == EnumPosResType.X2D1) { 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 (station != null) { //if (info.PosResType == EnumPosResType.X2D1NoRef) //{ // station.SatTxLon = 43.7; // station.SatTxLat = 12.9; // station.CdbTxLon = 43.7; // station.CdbTxLat = 12.9; //} 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) { txtYbMain.Properties.ReadOnly = true; txtYbAdja.Properties.ReadOnly = true; txtRefLocation.Properties.ReadOnly = true; this.txtRefLocation.Text = $"{0},{0}"; } //txtsatStation.Text = "43.7,12.9"; //txtcdbStation.Text = "43.7,12.9"; //txtDtoSx.Text = "6348.6030"; //txtDtoCdb.Text = "246616.0330"; //ucEphXYZMain.SetXYZ("a",1,(11265194.9906, 40486056.6399, -2055810.5412),Color.Red); //ucEphXYZAdaj.SetXYZ("b",1,(25525328.3455, 33539987.1755, -49504.0378),Color.Red); //double tarLon = 46, tarLat = 24; //double recLon = 45.9, recLat = 23.9; //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0)); //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0)); //var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value); //var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value); //var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef); //var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef); //var dto1 = (dt1 - dt2) * 1e6; //var dt3 = PhysicsHelper.Dto(tarEcef, recEcef); //var dto2 = (dt1 - dt3) * 1e6; } public bool CheckParam() { dxErrorProvider.ClearErrors(); if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波")) { return false; } if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差")) { return false; } if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差")) { return false; } if (info.PosResType == EnumPosResType.X2D1 && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差")) { return false; } if (info.PosResType == EnumPosResType.X2D1 && !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 = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 }; var DtoSx = Convert.ToDouble(this.txtDtoSx.Text); var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text); var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0; var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0; 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(); if (info.PosResType == EnumPosResType.X2D1) { //var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd); //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine); var xdDtoLine1 = DrawDtoLineHelper.DtoLineXdEx(dtoLineXd); mapControl1.DrawDtoLineTwo($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine1); var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption); mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine); } else { //var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRef(dtoLineXd); //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine); var xdDtoLine1 = DrawDtoLineHelper.DtoLineXdNoRefEx(dtoLineXd); mapControl1.DrawDtoLineTwo($"[{msat},超短{CDBAnt[0]}°]无参时差线", xdDtoLine1); //var xdDtoLine2 = DrawDtoLineHelper.DtoLineXdNoRefZl(dtoLineXd); //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]无参时差线zl", xdDtoLine2); var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption); mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine); //var tsDtoLine2 = DrawDtoLineHelper.DtoLine2XNoRefStartZl(twoStartOption); //mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线zl", tsDtoLine2); } } 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); ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.data.X, maineph.data.Y, maineph.data.Z), 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); ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red); } catch (Exception ex) { Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}"); DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}"); } } private void btnPos_Click(object sender, EventArgs e) { if (!CheckParam()) { return; } txtPosRes.Text = " "; try { var MsAnt = txtsatStation.GetLonLat(); var CDBAnt = txtcdbStation.GetLonLat(); var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 }; var DtoSx = Convert.ToDouble(this.txtDtoSx.Text); var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text); var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0; var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0; 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], RefLon = RefGeod[0], RefLat = RefGeod[1], }; if (info.PosResType == EnumPosResType.X2D1NoRef) { X2D1NoParPosDto dto = new X2D1NoParPosDto() { SigTime = sigTime, MainCode = cg.MainCode.Value, AdjaCode = cg.Adja1Code.Value, SxDto = DtoSx, XdDto = DtoCdb, MainX = msEph[0], MainY = msEph[1], MainZ = msEph[2], AdjaX = nsEph[0], AdjaY = nsEph[1], AdjaZ = nsEph[2], SatTxLon = MsAnt[0], SatTxLat = MsAnt[1], CdbTxLon = CDBAnt[0], CdbTxLat = CDBAnt[1], }; var cgRes = new CgRes() { SigTime = dto.SigTime, Dto1 = dto.SxDto, Dfo1 = dto.SxDfo, Snr1 = dto.SxSnr, DtoCdb = dto.XdDto, DfoCdb = dto.XdDfo, SnrCdb = dto.XdSnr, //StationResID = StationRes.ID, MainCode = dto.MainCode, Adja1Code = dto.AdjaCode, //TaskID = runTask.ID, MainX = dto.MainX, MainY = dto.MainY, MainZ = dto.MainZ, Adja1X = dto.AdjaX, Adja1Y = dto.AdjaY, Adja1Z = dto.AdjaZ, }; double[] res; if (ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"] != null && ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"].ToLower() != "false" && ConfigurationManager.AppSettings["UseNewPosX2D1NoRef"].ToLower() != "0") { res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes); } else { res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence); } this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]"; } else { X2D1PosDto dto = new X2D1PosDto() { SigTime = sigTime, MainCode = cg.MainCode.Value, AdjaCode = cg.Adja1Code.Value, SxDto = DtoSx, XdDto = DtoCdb, MainYbDto = YbMainDto, AdjaYbDto = YbAdja1Dto, MainX = msEph[0], MainY = msEph[1], MainZ = msEph[2], AdjaX = nsEph[0], AdjaY = nsEph[1], AdjaZ = nsEph[2], SatTxLon = MsAnt[0], SatTxLat = MsAnt[1], CdbTxLon = CDBAnt[0], CdbTxLat = CDBAnt[1], RefLon = RefGeod[0], RefLat = RefGeod[1], }; var cgRes = new CgRes() { SigTime = dto.SigTime, Dto1 = dto.SxDto, Dfo1 = dto.SxDfo, Snr1 = dto.SxSnr, DtoCdb = dto.XdDto, DfoCdb = dto.XdDfo, SnrCdb = dto.XdSnr, YbMainDto = dto.MainYbDto, YbAdja1Dto = dto.AdjaYbDto, //StationResID = StationRes.ID, MainCode = dto.MainCode, Adja1Code = dto.AdjaCode, // TaskID = runTask.ID, MainX = dto.MainX, MainY = dto.MainY, MainZ = dto.MainZ, Adja1X = dto.AdjaX, Adja1Y = dto.AdjaY, Adja1Z = dto.AdjaZ, }; var res = PosApi.X2D1_Pos(cgRes, StationRes); this.txtPosRes.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()}手动定位失败,{ex.Message}"); } } } }