X1D1DTOParamEditor.cs 12 KB

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