using DxHelper; using ExtensionsDev; using System; 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.Dto; using XdCxRhDW.Api; using XdCxRhDW.Dto; using XdCxRhDW.Entity; using XdCxRhDW.Repostory; namespace XdCxRhDW.App.EditForms { public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl { private List listSat; private PosRes info; private CgRes cg; private SysSetings settings = new SysSetings(); public X2D1PosParamEditor(PosRes info) { InitializeComponent(); this.Text = $"{info.PosResType.GetEnumDisplayName()}手动定位"; this.info = info; this.listSat = new List(); txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged; txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged; txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged; } private void TxtRefLocation_EditValueChanged(object sender, EventArgs e) { txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"); } private void TxtcdbStation_EditValueChanged(object sender, EventArgs e) { txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"); } private void TxtsatStation_EditValueChanged(object sender, EventArgs e) { txtsatStation.CheckLonLat(dxErrorProvider, "接收站"); } private async void X2D1DTOParamEditor_Load(object sender, EventArgs e) { StationRes station; using (RHDWContext db = new RHDWContext()) { listSat = await db.SatInfos.ToListAsync(); settings = await db.SysSetings.FirstOrDefaultAsync(); } 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:f3}"; this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}"; if (info.PosResType == EnumPosResType.X2D1) { this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}"; this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}"; } this.txtSigTime.EditValue = info.SigTime; this.txtMainX.Text = $"{cg.MainX.Value:f3}"; this.txtMainY.Text = $"{cg.MainY.Value:f3}"; this.txtMainZ.Text = $"{cg.MainZ.Value:f3}"; this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}"; this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}"; this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}"; } if (station != null) { this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}"; this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}"; this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}"; } if (info.PosResType == EnumPosResType.X2D1NoRef) { txtYbMain.Properties.ReadOnly = true; txtYbAdja.Properties.ReadOnly = true; txtRefLocation.Properties.ReadOnly = true; this.txtRefLocation.Text = $"{0},{0}"; } //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() { if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站")) { return false; } if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波")) { return false; } if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站")) { return false; } return true; } private void btnOk_Click(object sender, EventArgs e) { if (!CheckParam()) { return; } lblRes.Text = string.Empty; 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; var MainX = Convert.ToDouble(this.txtMainX.Text); var MainY = Convert.ToDouble(this.txtMainY.Text); var MainZ = Convert.ToDouble(this.txtMainZ.Text); var AdjaX = Convert.ToDouble(this.txtAdjaX.Text); var AdjaY = Convert.ToDouble(this.txtAdjaY.Text); var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text); double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 }; double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 }; 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], }; string url = string.Format("http://{0}:{1}/Api/Pos/", IpHelper.GetLocalIp(), settings.HttpPort); if (info.PosResType == EnumPosResType.X2D1NoRef) { url += "PosX2D1NoParAsync"; X2D1NoParPosDto dto = new X2D1NoParPosDto() { SigTime = sigTime, MainCode = cg.MainCode.Value, AdjaCode = cg.Adja1Code.Value, SxDto = DtoSx, XdDto = DtoCdb, MainX = MainX, MainY = MainY, MainZ = MainZ, AdjaX = AdjaX, AdjaY = AdjaY, AdjaZ = AdjaZ, 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, }; var res = PosApi.X2D1_PosNoRef(cgRes, StationRes); this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]"; //var result = await HttpHelper.PostRequestAsync(url, X2D1PosDto); //if (result.code == 200) //{ // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}"; //} } else { url += "PosX2D1Async"; X2D1PosDto dto = new X2D1PosDto() { SigTime = sigTime, MainCode = cg.MainCode.Value, AdjaCode = cg.Adja1Code.Value, SxDto = DtoSx, XdDto = DtoCdb, MainYbDto = YbMainDto, AdjaYbDto = YbAdja1Dto, MainX = MainX, MainY = MainY, MainZ = MainZ, AdjaX = AdjaX, AdjaY = AdjaY, AdjaZ = AdjaZ, 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.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]"; //var result = await HttpHelper.PostRequestAsync(url, X2D1PosDto); //if (result.code == 200) //{ // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}"; //} } } 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 btnMainXl_Click(object sender, EventArgs e) { var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, txtSigTime.DateTime); if (xlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历"); return; } var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime }; string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort); var ephMain = await HttpHelper.PostRequestAsync(url, XlCalcDto); this.txtMainX.Text = ephMain.data.X.ToString("f3"); this.txtMainY.Text = ephMain.data.Y.ToString("f3"); this.txtMainZ.Text = ephMain.data.Z.ToString("f3"); } private async void btnAdjaXl_Click(object sender, EventArgs e) { var xlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, txtSigTime.DateTime); if (xlInfo == null) { DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历"); return; } var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime }; string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort); var ephAdja = await HttpHelper.PostRequestAsync(url, XlCalcDto); this.txtAdjaX.Text = ephAdja.data.X.ToString("f3"); this.txtAdjaY.Text = ephAdja.data.Y.ToString("f3"); this.txtAdjaZ.Text = ephAdja.data.Z.ToString("f3"); } } }