X1D1DTOParamEditor.cs 12 KB

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