X1D1DTOParamEditor.cs 12 KB

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