using DevExpress.XtraMap;
using ExtensionsDev;
using System;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using XdCxRhDW.Repostory;
using XdCxRhDW.Entity;
using XdCxRhDW.Api;
using System.Drawing;
namespace XdCxRhDW.App.UserControl
{
public partial class X1D1GDOPParam : DevExpress.XtraEditors.XtraUserControl
{
public MapControl mapControl1;
public GDOP星地一星一地接口 Model => new GDOP星地一星一地接口()
{
EphMain = ucEphXYZMain.EphParam(),
CapTime = txtCapTime.DateTime,
StationLon = Convert.ToDouble(txtStationLocation1.Text.Replace(",", ",").Split(',')[0].Trim()),
StationLat = Convert.ToDouble(txtStationLocation1.Text.Replace(",", ",").Split(',')[1].Trim()),
CXLon = Convert.ToDouble(txtCXStation.Text.Replace(",", ",").Split(',')[0].Trim()),
CXLat = Convert.ToDouble(txtCXStation.Text.Replace(",", ",").Split(',')[1].Trim()),
RefLon = Convert.ToDouble(txtRefLocation1.Text.Replace(",", ",").Split(',')[0].Trim()),
RefLat = Convert.ToDouble(txtRefLocation1.Text.Replace(",", ",").Split(',')[1].Trim()),
DtousErr = Convert.ToDouble(txtDtousErr1.Text),
SatLocErr = Convert.ToDouble(txtSatLocErr1.Text),
CXErr = Convert.ToDouble(txtCxErr.Text),
};
private EnumPosResType PosResType;
public X1D1GDOPParam(PosRes item)
{
InitializeComponent();
this.layoutControl1.UseDefault();
txtCapTime.UseDefault();
txtStationLocation1.UseDoubleClickToSelectAll();
txtRefLocation1.UseDoubleClickToSelectAll();
txtCXStation.UseDoubleClickToSelectAll();
this.txtCapTime.DateTime = item.SigTime;
this.txtDtousErr1.EditValue = 1;
this.txtSatLocErr1.EditValue = 10000;
this.txtCxErr.EditValue = 0.001;
PosResType = item.PosResType;
using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
{
var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
if (station != null)
{
this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
this.txtCXStation.Text = $"{station.CxLon},{station.CxLat}";
}
if (cg != null)
{
var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
}
}
}
private (bool, string) ParamValidate()
{
var mainparam = ucEphXYZMain.ValidateParam();
if (!mainparam.Item1)
{
return (false, mainparam.Item2);
}
var txtstat = txtStationLocation1.CheckLonLat("超短波");
if (!txtstat.Item1)
{
return txtstat;
}
var cxsta = txtCXStation.CheckLonLat("测向站");
if (!cxsta.Item1)
{
return cxsta;
}
var refsta = txtRefLocation1.CheckLonLat("参考站");
if (!refsta.Item1)
{
return refsta;
}
return (true, "");
}
private void btnOK_Click(object sender, EventArgs e)
{
var pv = ParamValidate();
if (!pv.Item1)
{
DxHelper.MsgBoxHelper.ShowWarning($"{pv.Item2}");
return;
}
try
{
mapControl1.ClearMap();
var cdb = new double[] { Model.StationLon, Model.StationLat, 0 };
var cx = new double[] { Model.StationLon, Model.StationLat, 0 };
var refstation = new double[] { Model.RefLon, Model.RefLat, 0 };
var data = GdopHelper.Gdop1Sat1DByXyz(Model.EphMain, cdb, cx,
Model.DtousErr, Model.CXErr, Model.SatLocErr, refstation);
if (data == null)
{
return;
}
foreach (var errLins in data)//画GDOP
{
var mapDots = errLins.MapDots.Select(p => p).Select(p => (p.Lon, p.Lat));
mapControl1.DrawGdopLineTwo(errLins.ErrDistanceKm, mapDots, 1);
}
}
catch (Exception ex)
{
DxHelper.MsgBoxHelper.ShowError($"绘制{PosResType.GetEnumDisplayName()}GDOP失败,{ex.Message}");
}
}
private void btnClose_Click(object sender, EventArgs e)
{
DxHelper.PopupHelper.HidePopup(this);
}
private async void btnEphCalc_Click(object sender, EventArgs e)
{
if (txtCapTime.DateTime == DateTime.MinValue)
{
DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
return;
}
var sigTime = txtCapTime.DateTime;
try
{
var mainCode = ucEphXYZMain.GetSatCode();
var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
if (mainxlInfo == null)
{
DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
return;
}
var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime);
ucEphXYZMain.SetParam("主星", mainCode, (maineph.X, maineph.Y, maineph.Z, maineph.VX, maineph.VY, maineph.VZ), Color.Red);
}
catch (Exception ex)
{
Serilog.Log.Error(ex, $"手动推算{PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
DxHelper.MsgBoxHelper.ShowError($"手动推算{PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
}
}
}
public class GDOP星地一星一地接口
{
///
/// 主星星历 x y z vx vy vz
///
public double[] EphMain { get; set; }
///
/// 采集时刻
///
public DateTime CapTime { get; set; }
///
/// 超短接收站-经度
///
public double StationLon { get; set; }
///
/// 超短接收站-纬度
///
public double StationLat { get; set; }
///
/// 参考站位置经度
///
public double RefLon { get; set; }
///
/// 参考站位置纬度
///
public double RefLat { get; set; }
///
/// 测向站位置经度
///
public double CXLon { get; set; }
///
///测向站位置纬度
///
public double CXLat { get; set; }
///
/// 时差误差(单位us)
///
public double DtousErr { get; set; } = 1;
///
/// 星历位置误差(单位米)
///
public double SatLocErr { get; set; } = 10000;
///
/// 测向误差(单位°)
///
public double CXErr { get; set; } = 0.01;
}
}