X1D1DTOParamEditor.cs 12 KB

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