X1D1DTOParamEditor.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using DevExpress.XtraMap;
  2. using DxHelper;
  3. using ExtensionsDev;
  4. using System;
  5. using System.CodeDom;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using DW5S.KxcApi;
  14. using DW5S.DTO;
  15. using DW5S.Entity;
  16. using DW5S.Repostory;
  17. using Serilog;
  18. using DW5S.Service;
  19. using DW5S.ViewModel;
  20. namespace DW5S.App.EditForms
  21. {
  22. public partial class X1D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  23. {
  24. private MapControl mapControl1;
  25. private PosResViewModel info;
  26. private CgRes cg;
  27. private List<SatInfo> listSat;
  28. private CxRes cx;
  29. private StationRes station;
  30. public X1D1DTOParamEditor(PosResViewModel info, MapControl mapControl)
  31. {
  32. InitializeComponent();
  33. this.info = info;
  34. var unitOfWork = IocContainer.UnitOfWork;
  35. var repsSys = unitOfWork.Of<SysSetings>();
  36. var settings = repsSys.FirstOrDefaultAsync().Result;
  37. itemSigTime.Text = $"{itemSigTime.Text}({settings.TimeZoneUTC})";
  38. sigTime.UseDefault();
  39. this.layoutControl1.UseDefault();
  40. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  41. this.listSat = new List<SatInfo>();
  42. this.mapControl1 = mapControl;
  43. }
  44. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  45. {
  46. this.layoutControl1.BestFit();
  47. var unitOfWork = IocContainer.UnitOfWork;
  48. var repsSat = unitOfWork.Of<SatInfo>();
  49. listSat.AddRange(await repsSat.GetAllAsync());
  50. var repsPos = unitOfWork.OfLong<PosRes>();
  51. var pos = await repsPos.GetByIdAsync(info.Id);
  52. var repsCg = unitOfWork.OfLong<CgRes>();
  53. cg = await repsCg.FirstOrDefaultAsync(m => m.Id == pos.CgResID);
  54. var repsCx = unitOfWork.OfLong<CxRes>();
  55. cx = await repsCx.FirstOrDefaultAsync(m => m.Id == pos.CgResID);
  56. var repsStation = unitOfWork.OfLong<StationRes>();
  57. station = await repsStation.FirstOrDefaultAsync(m => m.Id == pos.StationResID);
  58. if (cg != null)
  59. {
  60. this.txtDtoCdb.Text = $"{cg.Dto1}";
  61. this.txtYbMain.Text = $"{cg.RefYbDto1.Value}";
  62. this.sigTime.EditValue = info.SigTime;
  63. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  64. }
  65. if (cx != null)
  66. {
  67. this.txtcxFx.Text = $"{cx.Fx}";
  68. }
  69. if (station != null)
  70. {
  71. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  72. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  73. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  74. this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
  75. }
  76. }
  77. public bool CheckDtoLineParam()
  78. {
  79. dxErrorProvider.ClearErrors();
  80. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  81. {
  82. return false;
  83. }
  84. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  85. {
  86. return false;
  87. }
  88. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  89. {
  90. return false;
  91. }
  92. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  93. {
  94. return false;
  95. }
  96. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  97. {
  98. return false;
  99. }
  100. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  101. {
  102. return false;
  103. }
  104. return true;
  105. }
  106. public bool CheckPosParam()
  107. {
  108. dxErrorProvider.ClearErrors();
  109. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  110. {
  111. return false;
  112. }
  113. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  114. {
  115. return false;
  116. }
  117. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  118. {
  119. return false;
  120. }
  121. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  122. {
  123. return false;
  124. }
  125. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  126. {
  127. return false;
  128. }
  129. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  130. {
  131. return false;
  132. }
  133. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  134. {
  135. return false;
  136. }
  137. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  138. {
  139. return false;
  140. }
  141. return true;
  142. }
  143. public bool CheckCxLineParam()
  144. {
  145. dxErrorProvider.ClearErrors();
  146. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  147. {
  148. return false;
  149. }
  150. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  151. {
  152. return false;
  153. }
  154. return true;
  155. }
  156. private void btnDtoLine_Click(object sender, EventArgs e)
  157. {
  158. if (!CheckDtoLineParam()) { return; }
  159. try
  160. {
  161. var MsAnt = txtsatStation.GetLonLat();
  162. var CDBAnt = txtcdbStation.GetLonLat();
  163. var RefGeod = txtRefLocation.GetLonLat();
  164. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  165. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  166. double[] msEph = ucEphXYZMain.EphXYZ();
  167. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  168. dtoLineXd.MsEph = msEph;
  169. dtoLineXd.MsAnt = MsAnt;
  170. dtoLineXd.CDBAnt = CDBAnt;
  171. dtoLineXd.RefGeod = RefGeod;
  172. dtoLineXd.xdDto = DtoCdb;
  173. dtoLineXd.RefDto = YbMainDto;
  174. dtoLineXd.PosLon = info.PosLon;
  175. dtoLineXd.PosLat = info.PosLat;
  176. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode)?.Sat;
  177. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.ToString();
  178. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
  179. List<MapPolyline> polylines = new List<MapPolyline>();
  180. foreach (var dtoLine in xdDtoLine)
  181. {
  182. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", dtoLine.dtoLinePoints, true);
  183. if (mapline == null)
  184. {
  185. continue;
  186. }
  187. polylines.Add(mapline);
  188. }
  189. mapControl1.DrawDtoLine(polylines);
  190. //var xdDtoLine1 = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  191. //mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine1);
  192. }
  193. catch (Exception ex)
  194. {
  195. IocContainer.Logger.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.Id},SigTime={info.SigTime}");
  196. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  197. }
  198. }
  199. private async void btnEphCalc_Click(object sender, EventArgs e)
  200. {
  201. dxErrorProvider.ClearErrors();
  202. if (this.sigTime.DateTime == DateTime.MinValue)
  203. {
  204. dxErrorProvider.SetError(this.sigTime, "信号时间不能为空!");
  205. return;
  206. }
  207. var sigTime = this.sigTime.DateTime;
  208. try
  209. {
  210. var mainCode = ucEphXYZMain.GetSatCode();
  211. var unitOfWork = IocContainer.UnitOfWork;
  212. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  213. var mainxlInfo = await repsXl.GetLatestAsync(mainCode, sigTime);
  214. if (mainxlInfo == null)
  215. {
  216. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  217. return;
  218. }
  219. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  220. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  221. ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  222. }
  223. catch (Exception ex)
  224. {
  225. IocContainer.Logger.Error($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}", ex);
  226. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  227. }
  228. }
  229. private void btnPos_Click(object sender, EventArgs e)
  230. {
  231. if (!CheckPosParam()) { return; }
  232. try
  233. {
  234. var MsAnt = txtsatStation.GetLonLat();
  235. var CDBAnt = txtcdbStation.GetLonLat();
  236. var RefGeod = txtRefLocation.GetLonLat();
  237. var CXStation = txtCxLocation.GetLonLat();
  238. var sigTime = this.sigTime.DateTime;
  239. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  240. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  241. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  242. double[] msEph = ucEphXYZMain.EphXYZ();
  243. var StationRes = new StationRes()
  244. {
  245. SatTxLon = MsAnt[0],
  246. SatTxLat = MsAnt[1],
  247. CdbTxLon = CDBAnt[0],
  248. CdbTxLat = CDBAnt[1],
  249. CxLon = CXStation[0],
  250. CxLat = CXStation[1],
  251. RefLon = RefGeod[0],
  252. RefLat = RefGeod[1],
  253. };
  254. var cgRes = new CgRes()
  255. {
  256. SigTime = sigTime,
  257. Dto1 = DtoCdb,
  258. Snr1 = 20,
  259. RefYbDto1 = YbMainDto,
  260. MainX = msEph[0],
  261. MainY = msEph[1],
  262. MainZ = msEph[2],
  263. };
  264. var cxRes = new CxRes()
  265. {
  266. SigTime = sigTime,
  267. Fx = Fx,
  268. };
  269. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes, false);
  270. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4} , {res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  271. }
  272. catch (Exception ex)
  273. {
  274. IocContainer.Logger.Error($"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.Id},SigTime={info.SigTime}", ex);
  275. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  276. }
  277. }
  278. private void btnCxLine_Click(object sender, EventArgs e)
  279. {
  280. if (!CheckCxLineParam()) { return; }
  281. try
  282. {
  283. var deg = Convert.ToDouble(this.txtcxFx.Text);//向北顺时针方向为夹角
  284. var cxStation = txtCxLocation.GetLonLat();
  285. double cxLon = cxStation[0];
  286. double cxLat = cxStation[1];
  287. //计算测向站到定位点之间的距离
  288. var km = MapControlEx.CalcLineKm(cxLon, cxLat, info.PosLon, info.PosLat);
  289. var endpoint = MapControlEx.CalcSituation(cxLon, cxLat, deg, (km + 100) * 1000);
  290. List<(double, double)> points = new List<(double, double)>();
  291. points.Add((cxLon, cxLat));
  292. points.Add((endpoint.Item1, endpoint.Item2));
  293. mapControl1.DrawCXLine($"测向线角度:{deg}°\t\n", points, true);
  294. }
  295. catch (Exception ex)
  296. {
  297. IocContainer.Logger.Error($"绘制测向线失败.PosID={info.Id},SigTime={info.SigTime}", ex);
  298. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败,{ex.Message}");
  299. }
  300. }
  301. }
  302. }