X1D1DTOParamEditor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.Data.Entity;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using XdCxRhDW.Api;
  15. using XdCxRhDW.Dto;
  16. using XdCxRhDW.Entity;
  17. using XdCxRhDW.Repostory;
  18. namespace XdCxRhDW.App.EditForms
  19. {
  20. public partial class X1D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. private MapControl mapControl1;
  23. private PosRes info;
  24. private CgRes cg;
  25. private List<SatInfo> listSat;
  26. private CxRes cx;
  27. private StationRes station;
  28. public X1D1DTOParamEditor(PosRes info, MapControl mapControl)
  29. {
  30. InitializeComponent();
  31. this.info = info;
  32. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  33. sigTime.UseDefault();
  34. this.layoutControl1.UseDefault();
  35. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  36. this.listSat = new List<SatInfo>();
  37. this.mapControl1 = mapControl;
  38. }
  39. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  40. {
  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.DtoLineXd(dtoLineXd);
  172. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine);
  173. }
  174. catch (Exception ex)
  175. {
  176. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  177. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  178. }
  179. }
  180. private async void btnEphCalc_Click(object sender, EventArgs e)
  181. {
  182. dxErrorProvider.ClearErrors();
  183. if (this.sigTime.DateTime == DateTime.MinValue)
  184. {
  185. dxErrorProvider.SetError(this.sigTime, "信号时间不能为空!");
  186. return;
  187. }
  188. var sigTime = this.sigTime.DateTime;
  189. try
  190. {
  191. var mainCode = ucEphXYZMain.GetSatCode();
  192. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  193. if (mainxlInfo == null)
  194. {
  195. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  196. return;
  197. }
  198. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  199. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  200. ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  201. }
  202. catch (Exception ex)
  203. {
  204. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  205. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  206. }
  207. }
  208. private void btnPos_Click(object sender, EventArgs e)
  209. {
  210. if (!CheckPosParam()) { return; }
  211. try
  212. {
  213. var MsAnt = txtsatStation.GetLonLat();
  214. var CDBAnt = txtcdbStation.GetLonLat();
  215. var RefGeod = txtRefLocation.GetLonLat();
  216. var CXStation = txtCxLocation.GetLonLat();
  217. var sigTime = this.sigTime.DateTime;
  218. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  219. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  220. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  221. double[] msEph = ucEphXYZMain.EphXYZ();
  222. var StationRes = new StationRes()
  223. {
  224. SatTxLon = MsAnt[0],
  225. SatTxLat = MsAnt[1],
  226. CdbTxLon = CDBAnt[0],
  227. CdbTxLat = CDBAnt[1],
  228. CxLon = CXStation[0],
  229. CxLat = CXStation[1],
  230. RefLon = RefGeod[0],
  231. RefLat = RefGeod[1],
  232. };
  233. var cgRes = new CgRes()
  234. {
  235. SigTime = sigTime,
  236. DtoCdb = DtoCdb,
  237. YbMainDto = YbMainDto,
  238. MainX = msEph[0],
  239. MainY = msEph[1],
  240. MainZ = msEph[2],
  241. };
  242. var cxRes = new CxRes()
  243. {
  244. SigTime = sigTime,
  245. Fx = Fx,
  246. };
  247. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  248. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4} , {res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  249. }
  250. catch (Exception ex)
  251. {
  252. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  253. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  254. }
  255. }
  256. private void btnCxLine_Click(object sender, EventArgs e)
  257. {
  258. if (!CheckCxLineParam()) { return; }
  259. try
  260. {
  261. var deg = Convert.ToDouble(this.txtcxFx.Text);//向北顺时针方向为夹角
  262. var cxStation = txtCxLocation.GetLonLat();
  263. double cxLon = cxStation[0];
  264. double cxLat= cxStation[1];
  265. //计算测向站到定位点之间的距离
  266. var km = MapControlEx.CalcLineKm(cxLon, cxLat, info.PosLon, info.PosLat);
  267. var endpoint = MapControlEx.CalcSituation(cxLon, cxLat, deg, (km + 100) * 1000);
  268. List<(double, double)> points = new List<(double, double)>();
  269. points.Add((cxLon, cxLat));
  270. points.Add((endpoint.Item1, endpoint.Item2));
  271. mapControl1.DrawCXLine($"测向线角度:{deg}°\t\n", points, true);
  272. }
  273. catch (Exception ex)
  274. {
  275. Serilog.Log.Error(ex, $"绘制测向线失败.PosID={info.ID},SigTime={info.SigTime}");
  276. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败,{ex.Message}");
  277. }
  278. }
  279. }
  280. }