X1D1DTOParamEditor.cs 12 KB

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