| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- using DevExpress.Mvvm.POCO;
- using DevExpress.Xpo;
- using DevExpress.XtraBars.Customization;
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.Controls;
- using DevExpress.XtraGauges.Win;
- using DevExpress.XtraMap;
- using Ips.Library.Basic;
- using Ips.Library.DxpLib;
- using Ips.Library.Entity;
- using Ips.LocAlgorithm;
- using Ips.Sps.Ants;
- using Ips.Sps.Emts;
- using Ips.Sps.Ephs;
- using Ips.Sps.Maps;
- using Ips.Sps.Refs;
- using Ips.Sps.Sats;
- using Ips.Sps.TskResults.Peses;
- using Ips.Sps.TskResults.Poses;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Ips.Sps.Tools.HandPoses
- {
- public partial class SimpleHandPosForm : DevExpress.XtraEditors.XtraForm
- {
- public SimpleHandPosForm()
- {
- InitializeComponent();
- mapControl.InitIpsOptions();
- mapControl.MapEditor.ActiveLayer = layerDefault;
- }
- public long PosId { get; set; }
- Session _session = Session.DefaultSession;
- Pos _pos;
- List<Pes> _pesList = new List<Pes>();
- private void HandPosForm_Load(object sender, EventArgs e)
- {
- BindPesList();
- }
- private void BindPesList()
- {
- if (PosId == 0) return;
- _pos = _session.GetObjectByKey<Pos>(PosId);
- var pesIds = _session.Query<PosRel>()
- .Where(m => m.PosId == PosId)
- .Select(m => m.PesId)
- .ToList();
- _pesList = _session.Query<Pes>()
- .Where(m => pesIds.Contains(m.Id))
- .OrderBy(m => m.Category).ThenByDescending(m => m.SigTime)
- .ToList();
- bsPesList.DataSource = _pesList;
- gvPesList.BestFitColumns();
- }
- private void btnClearAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- defaultItemStore.Items.Clear();
- }
- private void btnDrawDistinct_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- mapControl.Measurements.SetCreateMode(RulerType.Distance);
- }
- private void btnDrawPoint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
- {
- DrawPointForm form = new DrawPointForm();
- if (form.ShowDialog() == DialogResult.OK)
- {
- MapCustomElement mapItem = new MapCustomElement();
- mapItem.ImageIndex = 0;
- mapItem.Location = new GeoPoint(form.Lat, form.Lon);
- mapItem.Text = form.PointName;
- mapItem.TextAlignment = TextAlignment.BottomCenter;
- defaultItemStore.Items.Add(mapItem);
- }
- }
- private void mapControl_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right)
- {
- var hitInfo = mapControl.CalcHitInfo(e.Location);
- if (hitInfo.HitObjects.Length == 0)
- {
- popMap.ShowPopup(mapControl.PointToScreen(e.Location));
- }
- }
- }
- private void btnReload_Click(object sender, EventArgs e)
- {
- var res = MsgHelper.ShowConfirm("你确定要重新加载数据吗?");
- if (res)
- {
- BindPesList();
- }
- }
- private void sigTimeEdit_EditValueChanged(object sender, EventArgs e)
- {
- var arg = e as ChangingEventArgs;
- if (arg == null || arg.IsBoundUpdatingEditValue) return;
- var sigTime = (DateTime)arg.NewValue;
- var pes = gvPesList.GetFocusedRow() as Pes;
- RefreshEph(pes, sigTime);
- }
- private void RefreshEph(Pes pes, DateTime sigTime, bool? isMain = null)
- {
- if (pes != null)
- {
- if ((isMain == null || isMain == true) && pes.MainSatNum > 0)
- {
- EphResult ephRes = null;
- try
- {
- ephRes = EphManager.Default.GetEph(pes.MainSatNum, sigTime);
- }
- catch (Exception ex)
- {
- MsgHelper.ShowError("计算星历出错," + ex.Message);
- }
- pes.MainEphX = ephRes?.X ?? 0;
- pes.MainEphY = ephRes?.Y ?? 0;
- pes.MainEphZ = ephRes?.Z ?? 0;
- pes.MainEphVx = ephRes?.Vx ?? 0;
- pes.MainEphVy = ephRes?.Vy ?? 0;
- pes.MainEphVz = ephRes?.Vz ?? 0;
- }
- if ((isMain == null || isMain == false) && pes.AdjaSatNum > 0)
- {
- EphResult ephRes = null;
- try
- {
- ephRes = EphManager.Default.GetEph(pes.AdjaSatNum, sigTime);
- }
- catch (Exception ex)
- {
- MsgHelper.ShowError("计算星历出错," + ex.Message);
- }
- pes.AdjaEphX = ephRes?.X ?? 0;
- pes.AdjaEphY = ephRes?.Y ?? 0;
- pes.AdjaEphZ = ephRes?.Z ?? 0;
- }
- }
- }
- private void satEdit_EditValueChanging(object sender, ChangingEventArgs e)
- {
- var arg = e as ChangingEventArgs;
- if (arg == null || arg.IsBoundUpdatingEditValue) return;
- var satId = (int)arg.NewValue;
- var editor = sender as Control;
- if (editor == null) return;
- var pes = gvPesList.GetFocusedRow() as Pes;
- var sat = satEdit.GetDataSourceRowByKeyValue(satId) as Sat;
- if (editor.AccessibleName == "信号主星")
- {
- pes.MainSatNum = sat.SatNum;
- RefreshEph(pes, pes.SigTime, true);
- }
- else
- {
- pes.AdjaSatNum = sat.SatNum;
- RefreshEph(pes, pes.SigTime, false);
- }
- }
- private void antEdit_EditValueChanging(object sender, ChangingEventArgs e)
- {
- var arg = e as ChangingEventArgs;
- if (arg == null || arg.IsBoundUpdatingEditValue) return;
- var editor = sender as Control;
- if (editor == null) return;
- var antId = (int)arg.NewValue;
- var pes = gvPesList.GetFocusedRow() as Pes;
- var ant = antEdit.GetDataSourceRowByKeyValue(antId) as Ant;
- if (pes != null && ant != null)
- {
- if (editor.AccessibleName == "主星站点")
- {
- pes.MainAntLon = ant.Lon;
- pes.MainAntLat = ant.Lat;
- pes.MainAntAlt = ant.Alt;
- }
- else
- {
- pes.AdjaAntLon = ant.Lon;
- pes.AdjaAntLat = ant.Lat;
- pes.AdjaAntAlt = ant.Alt;
- }
- }
- }
- private void emtEdit_EditValueChanging(object sender, ChangingEventArgs e)
- {
- var arg = e as ChangingEventArgs;
- if (arg == null || arg.IsBoundUpdatingEditValue) return;
- var editor = sender as Control;
- if (editor == null) return;
- var emtId = (int)arg.NewValue;
- var pes = gvPesList.GetFocusedRow() as Pes;
- var emt = emtEdit.GetDataSourceRowByKeyValue(emtId) as Emt;
- if (pes != null && emt != null)
- {
- pes.SigLon = emt.Lon;
- pes.SigLat = emt.Lat;
- pes.SigAlt = emt.Alt;
- }
- }
- private void btnPos_Click(object sender, EventArgs e)
- {
- var pesList = bsPesList.DataSource as List<Pes>;
- var tarPesList = pesList.Where(m => m.Category != SignalCategory.RefSig).ToList();
- if (tarPesList.Count < 2)
- {
- MsgHelper.ShowError("参估数量不足,无法定位!");
- return;
- }
- List<Pes> refPesList = null;
- if (!txtNoRef.Checked)
- {
- refPesList = pesList.Where(m => m.Category == SignalCategory.RefSig).ToList();
- }
- btnPos.Enabled = false;
- var runTask = Task.Run(() => PosManager.Default.ExecLoc3x(tarPesList[0], tarPesList[1], refPesList))
- .ContinueWith(task =>
- {
- this.Invoke(() =>
- {
- try
- {
- var posRes = task.Result;
- btnPos.Enabled = true;
- var res = posRes.Result;
- if (res.Result1.IsValid() || res.Result2.IsValid())
- {
- if (res.Result1.IsValid())
- {
- AddPosToMap(res, res.Result1);
- lblPosText.Tag = res.Result1;
- lblPosText.Text = $"定位点:{res.Result1.Lon:F4},{res.Result1.Lat:F4}";
- }
- else
- {
- lblPosText.Tag = null;
- lblPosText.Text = "定位点:无";
- }
- if (res.Result2.IsValid())
- {
- AddPosToMap(res, res.Result2);
- lblMirText.Tag = res.Result2;
- lblMirText.Text = $"镜像点:{res.Result2.Lon:F4},{res.Result2.Lat:F4}";
- }
- else
- {
- lblMirText.Tag = null;
- lblMirText.Text = "镜像点:无";
- }
- }
- else
- {
- MsgHelper.ShowError("无有效定位点!");
- }
- }
- catch (Exception ex)
- {
- MsgHelper.ShowError("定位异常,错误消息:" + ex.Message);
- }
- });
- }, TaskContinuationOptions.ExecuteSynchronously);
- }
- private void AddPosToMap(PosResult res, GeoLLA lla)
- {
- MapDot mapDot = new MapDot();
- mapDot.Size = 10;
- mapDot.Fill = res.PosType == PosType.X3 ? Color.Gray : Color.Red;
- mapDot.Stroke = Color.White;
- mapDot.StrokeWidth = 3;
- mapDot.Location = new GeoPoint(lla.Lat, lla.Lon);
- mapDot.ToolTipPattern = $"定位类型:{EnumDisplayTextHelper.GetCachedDisplayText(res.PosType)}\r\n定位经度:{lla.Lon:F3}\r\n定位纬度:{lla.Lat:F3}";
- defaultItemStore.Items.Add(mapDot);
- }
- private void btnDrawDtoLine_Click(object sender, EventArgs e)
- {
- var pesList = bsPesList.DataSource as List<Pes>;
- var tarPesList = pesList.Where(m => m.Category != SignalCategory.RefSig).ToList();
- List<Pes> refPesList = null;
- if (!txtNoRef.Checked)
- {
- refPesList = pesList.Where(m => m.Category == SignalCategory.RefSig).ToList();
- }
- btnDrawDtoLine.Enabled = false;
- Task.Run(() =>
- {
- foreach (var pes in pesList)
- {
- if (pes.Category != SignalCategory.RefSig)
- {
- var refPes = RefManager.Default.GetRefPes(pes, refPesList, out _);
- DrawDtoLineByPes(pes, refPes, Color.Red);
- }
- else
- {
- DrawDtoLineByPes(pes, null, Color.Blue);
- }
- }
- }).ContinueWith(t =>
- {
- this.Invoke(() =>
- {
- btnDrawDtoLine.Enabled = true;
- });
- });
- }
- private void DrawDtoLineByPes(Pes pes, Pes refPes, Color color)
- {
- if (refPes != null)
- {
- LocUtil.DtoLineSxRef(pes.Dt, refPes.Dt,
- refPes.GetSigLLA(),
- pes.GetMainEphXYZ(),
- pes.GetAdjaEphXYZ(),
- pes.GetMainAntLLA(),
- pes.GetAdjaAntLLA()
- ).ContinueWith(t =>
- {
- this.Invoke(() =>
- {
- try
- {
- var exeRes = t.Result;
- AddDtoLine(exeRes.Result, color, pes, refPes != null);
- }
- catch (Exception ex)
- {
- MsgHelper.ShowError("绘制时差线异常,错误消息:" + ex.Message);
- }
- });
- });
- }
- else
- {
- LocUtil.DtoLineSx(pes.Dt, pes.GetMainAntLLA(), pes.GetAdjaAntLLA(), pes.GetMainEphXYZ(), pes.GetAdjaEphXYZ()).ContinueWith(t =>
- {
- this.Invoke(() =>
- {
- try
- {
- var exeRes = t.Result;
- AddDtoLine(exeRes.Result, color, pes, refPes != null);
- }
- catch (Exception ex)
- {
- MsgHelper.ShowError("绘制时差线异常,错误消息:" + ex.Message);
- }
- });
- });
- }
- }
- private void AddDtoLine(List<GeoLine> lines, Color color, Pes pes, bool hasRef)
- {
- if (lines.IsNullOrEmpty() || lines.All(m => m.Points.IsNullOrEmpty()))
- {
- MsgHelper.ShowMsg("时差线计算结果为空!");
- return;
- }
- defaultItemStore.Items.BeginUpdate();
- try
- {
- foreach (var line in lines)
- {
- if (line.Points.IsNullOrEmpty()) continue;
- CoordPointCollection geoPoints = new CoordPointCollection();
- line.Points.ForEach(m => geoPoints.Add(new GeoPoint(m.Lat, m.Lon)));
- var polyLine = new MapPolyline();
- polyLine.IsGeodesic = true;
- polyLine.Points = geoPoints;
- polyLine.StrokeWidth = 3;
- polyLine.Stroke = color;
- polyLine.ToolTipPattern = $"信号时间:{pes.SigTime:yyyy-MM-dd HH:mm:ss}\r\n卫星组合:{pes.MainSatNum}-{pes.AdjaSatNum}\r\n是否有参:{(hasRef ? "有参" : "无参")}";
- defaultItemStore.Items.Add(polyLine);
- //for (int i = 0; i < line.Points.Count; i++)
- //{
- // var point = line.Points[i];
- // MapDot dot = new MapDot();
- // dot.Location = new GeoPoint(point.Lat, point.Lon);
- // dot.Size = 6;
- // dot.ToolTipPattern = $"{i},信号时间:{pes.SigTime:yyyy-MM-dd HH:mm:ss}\r\n卫星组合:{pes.MainSatNum}-{pes.AdjaSatNum}\r\n是否有参:{(refPes != null ? "有参" : "无参")}";
- // misCustomer.Items.Add(dot);
- //}
- }
- }
- finally
- {
- defaultItemStore.Items.EndUpdate();
- }
- }
- private void mapControl_SelectionChanging(object sender, MapSelectionChangingEventArgs e)
- {
- }
- private void btnSaveDB_Click(object sender, EventArgs e)
- {
- if (!MsgHelper.ShowConfirm("确定要将修改和的参估和定位点保存到数据库吗?")) return;
- if (_pesList.IsNotNullOrEmpty())
- {
- _session.Save(_pesList);
- }
- if (lblPosText.Tag != null || lblMirText.Tag != null)
- {
- var posLoc = lblPosText.Tag as GeoLLA;
- var mirPos = lblMirText.Tag as GeoLLA;
- if (posLoc != null)
- {
- _pos.PosLon = posLoc.Lon;
- _pos.PosLat = posLoc.Lat;
- }
- if (mirPos != null)
- {
- _pos.MirrLon = mirPos.Lon;
- _pos.MirrLat = mirPos.Lat;
- }
- _session.Save(_pos);
- }
- MsgHelper.ShowMsg("已成功保存到数据库!");
- }
- }
- }
|