SimpleHandPosForm.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. using DevExpress.Mvvm.POCO;
  2. using DevExpress.Xpo;
  3. using DevExpress.XtraBars.Customization;
  4. using DevExpress.XtraEditors;
  5. using DevExpress.XtraEditors.Controls;
  6. using DevExpress.XtraGauges.Win;
  7. using DevExpress.XtraMap;
  8. using Ips.Library.Basic;
  9. using Ips.Library.DxpLib;
  10. using Ips.Library.Entity;
  11. using Ips.LocAlgorithm;
  12. using Ips.Sps.Ants;
  13. using Ips.Sps.Emts;
  14. using Ips.Sps.Ephs;
  15. using Ips.Sps.Maps;
  16. using Ips.Sps.Refs;
  17. using Ips.Sps.Sats;
  18. using Ips.Sps.TskResults.Peses;
  19. using Ips.Sps.TskResults.Poses;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.ComponentModel;
  23. using System.Data;
  24. using System.Drawing;
  25. using System.Linq;
  26. using System.Text;
  27. using System.Threading.Tasks;
  28. using System.Windows.Forms;
  29. namespace Ips.Sps.Tools.HandPoses
  30. {
  31. public partial class SimpleHandPosForm : DevExpress.XtraEditors.XtraForm
  32. {
  33. public SimpleHandPosForm()
  34. {
  35. InitializeComponent();
  36. mapControl.InitIpsOptions();
  37. mapControl.MapEditor.ActiveLayer = layerDefault;
  38. }
  39. public long PosId { get; set; }
  40. Session _session = Session.DefaultSession;
  41. Pos _pos;
  42. List<Pes> _pesList = new List<Pes>();
  43. private void HandPosForm_Load(object sender, EventArgs e)
  44. {
  45. BindPesList();
  46. }
  47. private void BindPesList()
  48. {
  49. if (PosId == 0) return;
  50. _pos = _session.GetObjectByKey<Pos>(PosId);
  51. var pesIds = _session.Query<PosRel>()
  52. .Where(m => m.PosId == PosId)
  53. .Select(m => m.PesId)
  54. .ToList();
  55. _pesList = _session.Query<Pes>()
  56. .Where(m => pesIds.Contains(m.Id))
  57. .OrderBy(m => m.Category).ThenByDescending(m => m.SigTime)
  58. .ToList();
  59. bsPesList.DataSource = _pesList;
  60. gvPesList.BestFitColumns();
  61. }
  62. private void btnClearAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  63. {
  64. defaultItemStore.Items.Clear();
  65. }
  66. private void btnDrawDistinct_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  67. {
  68. mapControl.Measurements.SetCreateMode(RulerType.Distance);
  69. }
  70. private void btnDrawPoint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  71. {
  72. DrawPointForm form = new DrawPointForm();
  73. if (form.ShowDialog() == DialogResult.OK)
  74. {
  75. MapCustomElement mapItem = new MapCustomElement();
  76. mapItem.ImageIndex = 0;
  77. mapItem.Location = new GeoPoint(form.Lat, form.Lon);
  78. mapItem.Text = form.PointName;
  79. mapItem.TextAlignment = TextAlignment.BottomCenter;
  80. defaultItemStore.Items.Add(mapItem);
  81. }
  82. }
  83. private void mapControl_MouseDown(object sender, MouseEventArgs e)
  84. {
  85. if (e.Button == MouseButtons.Right)
  86. {
  87. var hitInfo = mapControl.CalcHitInfo(e.Location);
  88. if (hitInfo.HitObjects.Length == 0)
  89. {
  90. popMap.ShowPopup(mapControl.PointToScreen(e.Location));
  91. }
  92. }
  93. }
  94. private void btnReload_Click(object sender, EventArgs e)
  95. {
  96. var res = MsgHelper.ShowConfirm("你确定要重新加载数据吗?");
  97. if (res)
  98. {
  99. BindPesList();
  100. }
  101. }
  102. private void sigTimeEdit_EditValueChanged(object sender, EventArgs e)
  103. {
  104. var arg = e as ChangingEventArgs;
  105. if (arg == null || arg.IsBoundUpdatingEditValue) return;
  106. var sigTime = (DateTime)arg.NewValue;
  107. var pes = gvPesList.GetFocusedRow() as Pes;
  108. RefreshEph(pes, sigTime);
  109. }
  110. private void RefreshEph(Pes pes, DateTime sigTime, bool? isMain = null)
  111. {
  112. if (pes != null)
  113. {
  114. if ((isMain == null || isMain == true) && pes.MainSatNum > 0)
  115. {
  116. EphResult ephRes = null;
  117. try
  118. {
  119. ephRes = EphManager.Default.GetEph(pes.MainSatNum, sigTime);
  120. }
  121. catch (Exception ex)
  122. {
  123. MsgHelper.ShowError("计算星历出错," + ex.Message);
  124. }
  125. pes.MainEphX = ephRes?.X ?? 0;
  126. pes.MainEphY = ephRes?.Y ?? 0;
  127. pes.MainEphZ = ephRes?.Z ?? 0;
  128. pes.MainEphVx = ephRes?.Vx ?? 0;
  129. pes.MainEphVy = ephRes?.Vy ?? 0;
  130. pes.MainEphVz = ephRes?.Vz ?? 0;
  131. }
  132. if ((isMain == null || isMain == false) && pes.AdjaSatNum > 0)
  133. {
  134. EphResult ephRes = null;
  135. try
  136. {
  137. ephRes = EphManager.Default.GetEph(pes.AdjaSatNum, sigTime);
  138. }
  139. catch (Exception ex)
  140. {
  141. MsgHelper.ShowError("计算星历出错," + ex.Message);
  142. }
  143. pes.AdjaEphX = ephRes?.X ?? 0;
  144. pes.AdjaEphY = ephRes?.Y ?? 0;
  145. pes.AdjaEphZ = ephRes?.Z ?? 0;
  146. }
  147. }
  148. }
  149. private void satEdit_EditValueChanging(object sender, ChangingEventArgs e)
  150. {
  151. var arg = e as ChangingEventArgs;
  152. if (arg == null || arg.IsBoundUpdatingEditValue) return;
  153. var satId = (int)arg.NewValue;
  154. var editor = sender as Control;
  155. if (editor == null) return;
  156. var pes = gvPesList.GetFocusedRow() as Pes;
  157. var sat = satEdit.GetDataSourceRowByKeyValue(satId) as Sat;
  158. if (editor.AccessibleName == "信号主星")
  159. {
  160. pes.MainSatNum = sat.SatNum;
  161. RefreshEph(pes, pes.SigTime, true);
  162. }
  163. else
  164. {
  165. pes.AdjaSatNum = sat.SatNum;
  166. RefreshEph(pes, pes.SigTime, false);
  167. }
  168. }
  169. private void antEdit_EditValueChanging(object sender, ChangingEventArgs e)
  170. {
  171. var arg = e as ChangingEventArgs;
  172. if (arg == null || arg.IsBoundUpdatingEditValue) return;
  173. var editor = sender as Control;
  174. if (editor == null) return;
  175. var antId = (int)arg.NewValue;
  176. var pes = gvPesList.GetFocusedRow() as Pes;
  177. var ant = antEdit.GetDataSourceRowByKeyValue(antId) as Ant;
  178. if (pes != null && ant != null)
  179. {
  180. if (editor.AccessibleName == "主星站点")
  181. {
  182. pes.MainAntLon = ant.Lon;
  183. pes.MainAntLat = ant.Lat;
  184. pes.MainAntAlt = ant.Alt;
  185. }
  186. else
  187. {
  188. pes.AdjaAntLon = ant.Lon;
  189. pes.AdjaAntLat = ant.Lat;
  190. pes.AdjaAntAlt = ant.Alt;
  191. }
  192. }
  193. }
  194. private void emtEdit_EditValueChanging(object sender, ChangingEventArgs e)
  195. {
  196. var arg = e as ChangingEventArgs;
  197. if (arg == null || arg.IsBoundUpdatingEditValue) return;
  198. var editor = sender as Control;
  199. if (editor == null) return;
  200. var emtId = (int)arg.NewValue;
  201. var pes = gvPesList.GetFocusedRow() as Pes;
  202. var emt = emtEdit.GetDataSourceRowByKeyValue(emtId) as Emt;
  203. if (pes != null && emt != null)
  204. {
  205. pes.SigLon = emt.Lon;
  206. pes.SigLat = emt.Lat;
  207. pes.SigAlt = emt.Alt;
  208. }
  209. }
  210. private void btnPos_Click(object sender, EventArgs e)
  211. {
  212. var pesList = bsPesList.DataSource as List<Pes>;
  213. var tarPesList = pesList.Where(m => m.Category != SignalCategory.RefSig).ToList();
  214. if (tarPesList.Count < 2)
  215. {
  216. MsgHelper.ShowError("参估数量不足,无法定位!");
  217. return;
  218. }
  219. List<Pes> refPesList = null;
  220. if (!txtNoRef.Checked)
  221. {
  222. refPesList = pesList.Where(m => m.Category == SignalCategory.RefSig).ToList();
  223. }
  224. btnPos.Enabled = false;
  225. var runTask = Task.Run(() => PosManager.Default.ExecLoc3x(tarPesList[0], tarPesList[1], refPesList))
  226. .ContinueWith(task =>
  227. {
  228. this.Invoke(() =>
  229. {
  230. try
  231. {
  232. var posRes = task.Result;
  233. btnPos.Enabled = true;
  234. var res = posRes.Result;
  235. if (res.Result1.IsValid() || res.Result2.IsValid())
  236. {
  237. if (res.Result1.IsValid())
  238. {
  239. AddPosToMap(res, res.Result1);
  240. lblPosText.Tag = res.Result1;
  241. lblPosText.Text = $"定位点:{res.Result1.Lon:F4},{res.Result1.Lat:F4}";
  242. }
  243. else
  244. {
  245. lblPosText.Tag = null;
  246. lblPosText.Text = "定位点:无";
  247. }
  248. if (res.Result2.IsValid())
  249. {
  250. AddPosToMap(res, res.Result2);
  251. lblMirText.Tag = res.Result2;
  252. lblMirText.Text = $"镜像点:{res.Result2.Lon:F4},{res.Result2.Lat:F4}";
  253. }
  254. else
  255. {
  256. lblMirText.Tag = null;
  257. lblMirText.Text = "镜像点:无";
  258. }
  259. }
  260. else
  261. {
  262. MsgHelper.ShowError("无有效定位点!");
  263. }
  264. }
  265. catch (Exception ex)
  266. {
  267. MsgHelper.ShowError("定位异常,错误消息:" + ex.Message);
  268. }
  269. });
  270. }, TaskContinuationOptions.ExecuteSynchronously);
  271. }
  272. private void AddPosToMap(PosResult res, GeoLLA lla)
  273. {
  274. MapDot mapDot = new MapDot();
  275. mapDot.Size = 10;
  276. mapDot.Fill = res.PosType == PosType.X3 ? Color.Gray : Color.Red;
  277. mapDot.Stroke = Color.White;
  278. mapDot.StrokeWidth = 3;
  279. mapDot.Location = new GeoPoint(lla.Lat, lla.Lon);
  280. mapDot.ToolTipPattern = $"定位类型:{EnumDisplayTextHelper.GetCachedDisplayText(res.PosType)}\r\n定位经度:{lla.Lon:F3}\r\n定位纬度:{lla.Lat:F3}";
  281. defaultItemStore.Items.Add(mapDot);
  282. }
  283. private void btnDrawDtoLine_Click(object sender, EventArgs e)
  284. {
  285. var pesList = bsPesList.DataSource as List<Pes>;
  286. var tarPesList = pesList.Where(m => m.Category != SignalCategory.RefSig).ToList();
  287. List<Pes> refPesList = null;
  288. if (!txtNoRef.Checked)
  289. {
  290. refPesList = pesList.Where(m => m.Category == SignalCategory.RefSig).ToList();
  291. }
  292. btnDrawDtoLine.Enabled = false;
  293. Task.Run(() =>
  294. {
  295. foreach (var pes in pesList)
  296. {
  297. if (pes.Category != SignalCategory.RefSig)
  298. {
  299. var refPes = RefManager.Default.GetRefPes(pes, refPesList, out _);
  300. DrawDtoLineByPes(pes, refPes, Color.Red);
  301. }
  302. else
  303. {
  304. DrawDtoLineByPes(pes, null, Color.Blue);
  305. }
  306. }
  307. }).ContinueWith(t =>
  308. {
  309. this.Invoke(() =>
  310. {
  311. btnDrawDtoLine.Enabled = true;
  312. });
  313. });
  314. }
  315. private void DrawDtoLineByPes(Pes pes, Pes refPes, Color color)
  316. {
  317. if (refPes != null)
  318. {
  319. LocUtil.DtoLineSxRef(pes.Dt, refPes.Dt,
  320. refPes.GetSigLLA(),
  321. pes.GetMainEphXYZ(),
  322. pes.GetAdjaEphXYZ(),
  323. pes.GetMainAntLLA(),
  324. pes.GetAdjaAntLLA()
  325. ).ContinueWith(t =>
  326. {
  327. this.Invoke(() =>
  328. {
  329. try
  330. {
  331. var exeRes = t.Result;
  332. AddDtoLine(exeRes.Result, color, pes, refPes != null);
  333. }
  334. catch (Exception ex)
  335. {
  336. MsgHelper.ShowError("绘制时差线异常,错误消息:" + ex.Message);
  337. }
  338. });
  339. });
  340. }
  341. else
  342. {
  343. LocUtil.DtoLineSx(pes.Dt, pes.GetMainAntLLA(), pes.GetAdjaAntLLA(), pes.GetMainEphXYZ(), pes.GetAdjaEphXYZ()).ContinueWith(t =>
  344. {
  345. this.Invoke(() =>
  346. {
  347. try
  348. {
  349. var exeRes = t.Result;
  350. AddDtoLine(exeRes.Result, color, pes, refPes != null);
  351. }
  352. catch (Exception ex)
  353. {
  354. MsgHelper.ShowError("绘制时差线异常,错误消息:" + ex.Message);
  355. }
  356. });
  357. });
  358. }
  359. }
  360. private void AddDtoLine(List<GeoLine> lines, Color color, Pes pes, bool hasRef)
  361. {
  362. if (lines.IsNullOrEmpty() || lines.All(m => m.Points.IsNullOrEmpty()))
  363. {
  364. MsgHelper.ShowMsg("时差线计算结果为空!");
  365. return;
  366. }
  367. defaultItemStore.Items.BeginUpdate();
  368. try
  369. {
  370. foreach (var line in lines)
  371. {
  372. if (line.Points.IsNullOrEmpty()) continue;
  373. CoordPointCollection geoPoints = new CoordPointCollection();
  374. line.Points.ForEach(m => geoPoints.Add(new GeoPoint(m.Lat, m.Lon)));
  375. var polyLine = new MapPolyline();
  376. polyLine.IsGeodesic = true;
  377. polyLine.Points = geoPoints;
  378. polyLine.StrokeWidth = 3;
  379. polyLine.Stroke = color;
  380. polyLine.ToolTipPattern = $"信号时间:{pes.SigTime:yyyy-MM-dd HH:mm:ss}\r\n卫星组合:{pes.MainSatNum}-{pes.AdjaSatNum}\r\n是否有参:{(hasRef ? "有参" : "无参")}";
  381. defaultItemStore.Items.Add(polyLine);
  382. //for (int i = 0; i < line.Points.Count; i++)
  383. //{
  384. // var point = line.Points[i];
  385. // MapDot dot = new MapDot();
  386. // dot.Location = new GeoPoint(point.Lat, point.Lon);
  387. // dot.Size = 6;
  388. // dot.ToolTipPattern = $"{i},信号时间:{pes.SigTime:yyyy-MM-dd HH:mm:ss}\r\n卫星组合:{pes.MainSatNum}-{pes.AdjaSatNum}\r\n是否有参:{(refPes != null ? "有参" : "无参")}";
  389. // misCustomer.Items.Add(dot);
  390. //}
  391. }
  392. }
  393. finally
  394. {
  395. defaultItemStore.Items.EndUpdate();
  396. }
  397. }
  398. private void mapControl_SelectionChanging(object sender, MapSelectionChangingEventArgs e)
  399. {
  400. }
  401. private void btnSaveDB_Click(object sender, EventArgs e)
  402. {
  403. if (!MsgHelper.ShowConfirm("确定要将修改和的参估和定位点保存到数据库吗?")) return;
  404. if (_pesList.IsNotNullOrEmpty())
  405. {
  406. _session.Save(_pesList);
  407. }
  408. if (lblPosText.Tag != null || lblMirText.Tag != null)
  409. {
  410. var posLoc = lblPosText.Tag as GeoLLA;
  411. var mirPos = lblMirText.Tag as GeoLLA;
  412. if (posLoc != null)
  413. {
  414. _pos.PosLon = posLoc.Lon;
  415. _pos.PosLat = posLoc.Lat;
  416. }
  417. if (mirPos != null)
  418. {
  419. _pos.MirrLon = mirPos.Lon;
  420. _pos.MirrLat = mirPos.Lat;
  421. }
  422. _session.Save(_pos);
  423. }
  424. MsgHelper.ShowMsg("已成功保存到数据库!");
  425. }
  426. }
  427. }