RHDTOParamEditor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 RHDTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  21. {
  22. private MapControl mapControl1;
  23. private PosRes info;
  24. private CgRes cg;
  25. private List<SatInfo> listSat;
  26. public RHDTOParamEditor(PosRes info, MapControl mapControl)
  27. {
  28. InitializeComponent();
  29. this.info = info;
  30. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  31. this.layoutControl1.UseDefault();
  32. txtSigTime.UseDefault();
  33. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  34. this.listSat = new List<SatInfo>();
  35. this.mapControl1 = mapControl;
  36. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  37. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  38. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  39. }
  40. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  41. {
  42. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  43. }
  44. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  45. {
  46. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  47. }
  48. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  49. {
  50. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  51. }
  52. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  53. {
  54. StationRes station = null;
  55. CxRes cx = null;
  56. using (RHDWContext db = new RHDWContext())
  57. {
  58. listSat = await db.SatInfos.ToListAsync();
  59. }
  60. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  61. {
  62. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  63. cx = await db?.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  64. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  65. }
  66. if (cg != null)
  67. {
  68. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  69. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  70. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  71. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  72. this.txtSigTime.EditValue = info.SigTime;
  73. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  74. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  75. }
  76. if (cx != null)
  77. {
  78. this.txtcxFx.Text = $"{cx.Fx}";
  79. }
  80. if (station != null)
  81. {
  82. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  83. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  84. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  85. this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
  86. }
  87. }
  88. public bool CheckParam()
  89. {
  90. dxErrorProvider.ClearErrors();
  91. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  92. {
  93. return false;
  94. }
  95. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  96. {
  97. return false;
  98. }
  99. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  100. {
  101. return false;
  102. }
  103. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  104. {
  105. return false;
  106. }
  107. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  108. {
  109. return false;
  110. }
  111. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  112. {
  113. return false;
  114. }
  115. if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  116. {
  117. return false;
  118. }
  119. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  120. {
  121. return false;
  122. }
  123. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  124. {
  125. return false;
  126. }
  127. return true;
  128. }
  129. public bool CheckPosParam()
  130. {
  131. dxErrorProvider.ClearErrors();
  132. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  133. {
  134. return false;
  135. }
  136. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  137. {
  138. return false;
  139. }
  140. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  141. {
  142. return false;
  143. }
  144. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  145. {
  146. return false;
  147. }
  148. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  149. {
  150. return false;
  151. }
  152. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  153. {
  154. return false;
  155. }
  156. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  157. {
  158. return false;
  159. }
  160. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  161. {
  162. return false;
  163. }
  164. if (!txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  165. {
  166. return false;
  167. }
  168. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  169. {
  170. return false;
  171. }
  172. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  173. {
  174. return false;
  175. }
  176. return true;
  177. }
  178. private void btnDtoLine_Click(object sender, EventArgs e)
  179. {
  180. if (!CheckParam()) { return; }
  181. try
  182. {
  183. var MsAnt = txtsatStation.GetLonLat();
  184. var CDBAnt = txtcdbStation.GetLonLat();
  185. var RefGeod = txtRefLocation.GetLonLat();
  186. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  187. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  188. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  189. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  190. double[] msEph = ucEphXYZMain.EphXYZ();
  191. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  192. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  193. dtoLineXd.MsEph = msEph;
  194. dtoLineXd.MsAnt = MsAnt;
  195. dtoLineXd.CDBAnt = CDBAnt;
  196. dtoLineXd.RefGeod = RefGeod;
  197. dtoLineXd.xdDto = DtoCdb;
  198. dtoLineXd.RefDto = YbMainDto;
  199. dtoLineXd.PosLon = info.PosLon;
  200. dtoLineXd.PosLat = info.PosLat;
  201. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  202. twoStartOption.MsEph = msEph;
  203. twoStartOption.NsEph = NsEph;
  204. twoStartOption.MsAnt = MsAnt;
  205. twoStartOption.NsAnt = MsAnt;
  206. twoStartOption.RefGeod = RefGeod;
  207. twoStartOption.TargetDto = DtoSx;
  208. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  209. twoStartOption.PosLon = info.PosLon;
  210. twoStartOption.PosLat = info.PosLat;
  211. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  212. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  213. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  214. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  215. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  216. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  217. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  218. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  219. }
  220. catch (Exception ex)
  221. {
  222. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  223. DxHelper.MsgBoxHelper.ShowError($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  224. }
  225. }
  226. private async void btnEphCalc_Click(object sender, EventArgs e)
  227. {
  228. dxErrorProvider.ClearErrors();
  229. if (this.txtSigTime.DateTime == DateTime.MinValue)
  230. {
  231. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  232. return;
  233. }
  234. var sigTime = this.txtSigTime.DateTime;
  235. try
  236. {
  237. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  238. if (mainxlInfo == null)
  239. {
  240. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  241. return;
  242. }
  243. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  244. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  245. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  246. if (adjaxlInfo == null)
  247. {
  248. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  249. return;
  250. }
  251. var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc());
  252. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.X, adjaeph.Y, adjaeph.Z), Color.Red);
  253. }
  254. catch (Exception ex)
  255. {
  256. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  257. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  258. }
  259. }
  260. private void btnPos_Click(object sender, EventArgs e)
  261. {
  262. if (!CheckPosParam()) { return; }
  263. txtPosRes.Text = " ";
  264. try
  265. {
  266. var MsAnt = txtsatStation.GetLonLat();
  267. var CDBAnt = txtcdbStation.GetLonLat();
  268. var RefGeod = txtRefLocation.GetLonLat();
  269. var cxStation = txtCxLocation.GetLonLat();
  270. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  271. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  272. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  273. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  274. var cxFx = Convert.ToDouble(this.txtcxFx.Text);
  275. double[] msEph = ucEphXYZMain.EphXYZ();
  276. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  277. var sigTime = txtSigTime.DateTime;
  278. var StationRes = new StationRes()
  279. {
  280. SatTxLon = MsAnt[0],
  281. SatTxLat = MsAnt[1],
  282. CdbTxLon = CDBAnt[0],
  283. CdbTxLat = CDBAnt[1],
  284. CxLon = cxStation[0],
  285. CxLat = cxStation[1],
  286. RefLon = RefGeod[0],
  287. RefLat = RefGeod[1],
  288. };
  289. var cgRes = new CgRes()
  290. {
  291. SigTime = sigTime,
  292. Dto1 = DtoSx,
  293. DtoCdb = DtoCdb,
  294. YbMainDto = YbMainDto,
  295. YbAdja1Dto = YbAdja1Dto,
  296. MainCode = cg.MainCode.Value,
  297. Adja1Code = cg.Adja1Code.Value,
  298. MainX = msEph[0],
  299. MainY = msEph[1],
  300. MainZ = msEph[2],
  301. Adja1X = nsEph[0],
  302. Adja1Y = nsEph[1],
  303. Adja1Z = nsEph[2],
  304. };
  305. var rhcxRes = new CxRes()
  306. {
  307. SigTime = sigTime,
  308. Fx = cxFx,
  309. };
  310. var res = PosApi.RH_Pos(cgRes, StationRes, rhcxRes, false);
  311. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  312. }
  313. catch (Exception ex)
  314. {
  315. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  316. DxHelper.MsgBoxHelper.ShowError($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  317. }
  318. }
  319. }
  320. }