123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using DevExpress.XtraMap;
- using DxHelper;
- using ExtensionsDev;
- using System;
- using System.CodeDom;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using DW5S.KxcApi;
- using DW5S.DTO;
- using DW5S.Entity;
- using DW5S.Repostory;
- using Serilog;
- using DW5S.Service;
- using DW5S.ViewModel;
- namespace DW5S.App.EditForms
- {
- public partial class X1D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
- {
- private MapControl mapControl1;
- private PosResViewModel info;
- private CgRes cg;
- private List<SatInfo> listSat;
- private CxRes cx;
- private StationRes station;
- public X1D1DTOParamEditor(PosResViewModel info, MapControl mapControl)
- {
- InitializeComponent();
- this.info = info;
- var unitOfWork = IocContainer.UnitOfWork;
- var repsSys = unitOfWork.Of<SysSetings>();
- var settings = repsSys.FirstOrDefaultAsync().Result;
- itemSigTime.Text = $"{itemSigTime.Text}({settings.TimeZoneUTC})";
- sigTime.UseDefault();
- this.layoutControl1.UseDefault();
- this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
- this.listSat = new List<SatInfo>();
- this.mapControl1 = mapControl;
- }
- private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
- {
- this.layoutControl1.BestFit();
- var unitOfWork = IocContainer.UnitOfWork;
- var repsSat = unitOfWork.Of<SatInfo>();
- listSat.AddRange(await repsSat.GetAllAsync());
- var repsPos = unitOfWork.OfLong<PosRes>();
- var pos = await repsPos.GetByIdAsync(info.Id);
- var repsCg = unitOfWork.OfLong<CgRes>();
- cg = await repsCg.FirstOrDefaultAsync(m => m.Id == pos.CgResID);
- var repsCx = unitOfWork.OfLong<CxRes>();
- cx = await repsCx.FirstOrDefaultAsync(m => m.Id == pos.CgResID);
- var repsStation = unitOfWork.OfLong<StationRes>();
- station = await repsStation.FirstOrDefaultAsync(m => m.Id == pos.StationResID);
- if (cg != null)
- {
- this.txtDtoCdb.Text = $"{cg.Dto1}";
- this.txtYbMain.Text = $"{cg.RefYbDto1.Value}";
- this.sigTime.EditValue = info.SigTime;
- ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
- }
- if (cx != null)
- {
- this.txtcxFx.Text = $"{cx.Fx}";
- }
- if (station != null)
- {
- this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
- this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
- this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
- this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
- }
- }
- public bool CheckDtoLineParam()
- {
- dxErrorProvider.ClearErrors();
- if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
- {
- return false;
- }
- if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
- {
- return false;
- }
- if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
- {
- return false;
- }
- if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
- {
- return false;
- }
- if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
- {
- return false;
- }
- if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
- {
- return false;
- }
- return true;
- }
- public bool CheckPosParam()
- {
- dxErrorProvider.ClearErrors();
- if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
- {
- return false;
- }
- if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
- {
- return false;
- }
- if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
- {
- return false;
- }
- if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
- {
- return false;
- }
- if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
- {
- return false;
- }
- if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
- {
- return false;
- }
- if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
- {
- return false;
- }
- if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
- {
- return false;
- }
- return true;
- }
- public bool CheckCxLineParam()
- {
- dxErrorProvider.ClearErrors();
- if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
- {
- return false;
- }
- if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
- {
- return false;
- }
- return true;
- }
- private void btnDtoLine_Click(object sender, EventArgs e)
- {
- if (!CheckDtoLineParam()) { return; }
- try
- {
- var MsAnt = txtsatStation.GetLonLat();
- var CDBAnt = txtcdbStation.GetLonLat();
- var RefGeod = txtRefLocation.GetLonLat();
- var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
- var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
- double[] msEph = ucEphXYZMain.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;
- var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode)?.Sat;
- if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.ToString();
- var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
- List<MapPolyline> polylines = new List<MapPolyline>();
- foreach (var dtoLine in xdDtoLine)
- {
- var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", dtoLine.dtoLinePoints, true);
- if (mapline == null)
- {
- continue;
- }
- polylines.Add(mapline);
- }
- mapControl1.DrawDtoLine(polylines);
- //var xdDtoLine1 = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
- //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine1);
- }
- catch (Exception ex)
- {
- IocContainer.Logger.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.sigTime.DateTime == DateTime.MinValue)
- {
- dxErrorProvider.SetError(this.sigTime, "信号时间不能为空!");
- return;
- }
- var sigTime = this.sigTime.DateTime;
- try
- {
- var mainCode = ucEphXYZMain.GetSatCode();
- var unitOfWork = IocContainer.UnitOfWork;
- var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
- var mainxlInfo = await repsXl.GetLatestAsync(mainCode, sigTime);
- if (mainxlInfo == null)
- {
- DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
- return;
- }
- var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
- var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
- ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
- }
- catch (Exception ex)
- {
- IocContainer.Logger.Error($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}", ex);
- DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
- }
- }
- private void btnPos_Click(object sender, EventArgs e)
- {
- if (!CheckPosParam()) { return; }
- try
- {
- var MsAnt = txtsatStation.GetLonLat();
- var CDBAnt = txtcdbStation.GetLonLat();
- var RefGeod = txtRefLocation.GetLonLat();
- var CXStation = txtCxLocation.GetLonLat();
- var sigTime = this.sigTime.DateTime;
- var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
- var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
- var Fx = Convert.ToDouble(this.txtcxFx.Text);
- double[] msEph = ucEphXYZMain.EphXYZ();
- var StationRes = new StationRes()
- {
- SatTxLon = MsAnt[0],
- SatTxLat = MsAnt[1],
- CdbTxLon = CDBAnt[0],
- CdbTxLat = CDBAnt[1],
- CxLon = CXStation[0],
- CxLat = CXStation[1],
- RefLon = RefGeod[0],
- RefLat = RefGeod[1],
- };
- var cgRes = new CgRes()
- {
- SigTime = sigTime,
- Dto1 = DtoCdb,
- Snr1 = 20,
- RefYbDto1 = YbMainDto,
- MainX = msEph[0],
- MainY = msEph[1],
- MainZ = msEph[2],
- };
- var cxRes = new CxRes()
- {
- SigTime = sigTime,
- Fx = Fx,
- };
- var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes, false);
- this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4} , {res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
- }
- catch (Exception ex)
- {
- IocContainer.Logger.Error($"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.Id},SigTime={info.SigTime}", ex);
- DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
- }
- }
- private void btnCxLine_Click(object sender, EventArgs e)
- {
- if (!CheckCxLineParam()) { return; }
- try
- {
- var deg = Convert.ToDouble(this.txtcxFx.Text);//向北顺时针方向为夹角
- var cxStation = txtCxLocation.GetLonLat();
- double cxLon = cxStation[0];
- double cxLat = cxStation[1];
- //计算测向站到定位点之间的距离
- var km = MapControlEx.CalcLineKm(cxLon, cxLat, info.PosLon, info.PosLat);
- var endpoint = MapControlEx.CalcSituation(cxLon, cxLat, deg, (km + 100) * 1000);
- List<(double, double)> points = new List<(double, double)>();
- points.Add((cxLon, cxLat));
- points.Add((endpoint.Item1, endpoint.Item2));
- mapControl1.DrawCXLine($"测向线角度:{deg}°\t\n", points, true);
- }
- catch (Exception ex)
- {
- IocContainer.Logger.Error($"绘制测向线失败.PosID={info.Id},SigTime={info.SigTime}", ex);
- DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败,{ex.Message}");
- }
- }
- }
- }
|