123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- using DevExpress.Internal;
- using DevExpress.Utils.Drawing.Helpers;
- using DevExpress.Utils.Extensions;
- using DevExpress.XtraEditors;
- using DevExpress.XtraExport.Helpers;
- using DevExpress.XtraGrid.Views.Grid;
- using DevExpress.XtraMap;
- using DevExpress.XtraTreeList.Data;
- using DxHelper;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.Entity;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using XdCxRhDW.App.Api.时差粗值预测;
- using XdCxRhDW.App.Api.时差线;
- using XdCxRhDW.App.DTO;
- using XdCxRhDW.App.UserControl;
- using XzXdDw.App.Api;
- using XzXdDw.App.Api.星地GDOP误差椭圆;
- using XzXdDw.App.EditForms;
- using XzXdDw.App.EFContext;
- using XzXdDw.App.Model;
- namespace XzXdDw.App.UserControl
- {
- /// <summary>
- /// 星地定位
- /// </summary>
- public partial class CtrlPosSingle : DevExpress.XtraEditors.XtraUserControl
- {
- DtXDParam dtxdctrl = null;
- public CtrlPosSingle()
- {
- InitializeComponent();
- }
- private async void CtrlXdPos_Load(object sender, EventArgs e)
- {
- try
- {
- gridPos.Init().UseMultiSelect().UseFilter().UseRowNumber().UseExportXlsx()
- .AddMenu("删除", SvgHelper.CreateClose(), async () =>
- {
- try
- {
- if (XtraMessageBox.Show("确认删除?(Ctrl+A可全选删除)", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
- {
- return;
- }
- var ids = gridView1.GetSelectedRows();
- List<PosRes> deletePos = new List<PosRes>();
- using (RHDWContext db = new RHDWContext())
- {
- foreach (var id in ids)
- {
- var item = gridView1.GetRow(id) as PosRes;
- var delItem = await db.PosRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
- if (delItem != null)
- {
- db.PosRes.Remove(delItem);
- }
- deletePos.Add(item);
- }
- await db.SaveChangesAsync();
- }
- gridView1.DeleteSelectedRows();
- mapControl1.DelPosItem(deletePos);
- }
- catch (Exception ex)
- {
- Serilog.Log.Error("删除结果失败", ex);
- XtraMessageBox.Show("删除结果失败");
- }
- })
- .AddMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), LoadTestData)
- .AddMenu("绘制误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), DrawErrorEllipse1X)
- .AddMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), () => stoped = true);
- mapControl1.UseDefalutOptions()
- //.UseCluster()//定位点使用内置聚合
- .UseClearAll()
- .UseDistanceLine()
- .UseMarkDot()
- //.UseExportImg()
- //.UseExportXlsx()
- //.UseExportCsv()
- .UseDrawRect(rect =>
- {
- if (dtxdctrl != null)
- {
- dtxdctrl.rect = rect;
- }
- });
- //MapMenu为地图瓦片上右键菜单
- //AddPosMenu为定位点上右键菜单
- //RectMenu为框选的区域上右键菜单
- mapControl1.AddMapMenu("加载仿真数据", SvgHelper.LoadFromFile("Image\\LoadData.svg"), (lon, lat) => LoadTestData())
- .AddMapMenu("停止加载", SvgHelper.LoadFromFile("Image\\Stop.svg"), (lon, lat) => stoped = true)
- .AddMapMenu("GDOP分析", SvgHelper.LoadFromFile("Image\\GDOP.svg"), (lon, lat) =>
- {
- })
- .AddPosMenu<PosRes>("误差椭圆", SvgHelper.LoadFromFile("Image\\误差椭圆.svg"), item =>
- {
- });
- //查询已有的定位记录
- using (RHDWContext db = new RHDWContext())
- {
- List<PosRes> list = await db.PosRes.ToListAsync();
- this.gridPos.DataSource = list;
- mapControl1.SetPosDataSource(list);
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error("查询定位结果失败", ex);
- XtraMessageBox.Show("查询定位结果失败");
- }
- }
- bool stoped = false;
- private async void LoadTestData()
- {
- stoped = false;
- //在列表控件中全选+右键可以删除所有测试结果
- using (RHDWContext db = new RHDWContext())
- {
- var listTx = db.TxInfos.ToList();
- var lines = File.ReadAllLines("Simulation_Data2023.dat");
- Random r = new Random();
- foreach (var item in lines)
- {
- if (stoped) break;
- double[] main_eph =new double[6] { -1608409.905, 5994264.071, 3139843.443, -6633.016931, -374.023436, -2678.1580461 };
- double[] main_eph1 = new double[6] { -3479298.029, 5612482.078, 2187911.486, -5784.105325, -2163.505176, -3632.855383 };
- double[] main_eph2 = new double[6] { -5018677.726, 4714449.429, 1001437.615, -4399.327638, -3780.398104, -4206.338078 };
- //double[] Ref_Station_LLH = { 112.33, 16.3, 0 };
- double[] Ref_Station_LLH = { 115.5, 9.899, 64 }; //*****参考站的位置
- double[] Zone =new double[4] { -85, 85, -180, 180 };
- double target_dfo1 = 2.002242571242008e+02;
- double target_dfo2 = 4.311089914542198e+03;
- double fu1 = 3.1085e8;
- double[] target_llh = new double[6];
- PosApi.SingleStar_DFO_DW(main_eph, main_eph1, main_eph2, Zone, target_dfo1, target_dfo2, fu1, target_llh);
- PosRes posRes = new PosRes()
- {
- SigTime = DateTime.Now,
- CgResID = 1,
- TarName = "未知目标",
- TsName = "tar2",
- PosLon = target_llh[0],
- PosLat = target_llh[1],
- MirrLon = target_llh[3],
- MirrLat = target_llh[4],
- };
- db.PosRes.Add(posRes);//定位结果入库
- //更新定位结果UI列表和地图
- var currentTask = gridView1.GetFocusedRow() as TaskInfo;
- var ds = this.gridPos.DataSource as List<PosRes>;
- ds.Insert(0, posRes);
- this.Invoke(new Action(() =>
- {
- gridView1.RefreshData();
- mapControl1.AddPosItem(posRes);
- }));
- await Task.Delay(200);
- }
- }
- }
- private async void DrawErrorEllipse1X()
- {
- try
- {
- var ids = gridView1.GetSelectedRows();
- if (ids.Length <= 0)
- {
- XtraMessageBox.Show("请选择需要绘制误差椭圆线的定位数据信息!");
- return;
- }
- var item = gridView1.GetRow(ids[0]) as PosRes;
- List<TxInfo> listTx = new List<TxInfo>();
- List<Model.SatInfo> listSat = new List<Model.SatInfo>();
- CgRes cg;
- using (RHDWContext db = new RHDWContext())
- {
- listTx = db.TxInfos.ToList();
- listSat = db.SatInfos.ToList();
- cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
- }
- if (cg == null)
- {
- XtraMessageBox.Show($"未找到定位相关的计算[{item.CgResID}]信息");
- return;
- }
- var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
- var satNTx = listTx.Find(p => p.TxType == EnumTxType.AdjaSat);
- var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
- var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
- XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption Option = new XzXdDw.App.Api.低轨GDOP误差椭圆.ErrorEllipseDTO1XOption();
- Option.MsEph = new double[] { cg.MainX, cg.MainY, cg.MainZ, 0, 0, 0 };
- Option.NsEph1 = new double[] { cg.AdjaX, cg.AdjaY, cg.AdjaZ, 0, 0, 0 };
- Option.NsEph2 = new double[] { cdbTx.Lon, cdbTx.Lat, 0 };
- Option.SelectPoint = new double[3] { item.PosLon, item.PosLat, 0 };
- Option.DfoErr = 1;
- Option.EphPosErr = 1;
- Option.EphVelErr = 1;
- Option.fu = 3.1085e8;
- var points = XzXdDw.App.Api.低轨GDOP误差椭圆.ErrEllipseHelper.ErrorEllipseSingleX(Option);
- mapControl1.DrawDtoPonit($"单星[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat}]误差椭圆线", points);
- }
- catch (Exception ex)
- {
- Serilog.Log.Error("绘制误差椭圆线失败", ex);
- XtraMessageBox.Show($"绘制误差椭圆线失败,失败信息:{ex.Message}");
- }
- }
- public XdCxRhDW.App.DTO.MapLine SampleDots(XdCxRhDW.App.DTO.MapLine line)
- {
- var dots = line.Line;
- if (dots.Count < 30) return line;
- var tmp = dots.Count / 30;
- var newLine = new XdCxRhDW.App.DTO.MapLine();
- for (int i = 0; i < dots.Count; i += tmp)
- {
- newLine.Line.Add(dots[i]);
- }
- if (!newLine.Line.Contains(dots.Last()))
- newLine.Line.Add(dots.Last());
- return newLine;
- }
- }
- }
|