RHDTOParamEditor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. txtCxLocation.EditValueChanged += TxtCxLocation_EditValueChanged;
  40. }
  41. private void TxtCxLocation_EditValueChanged(object sender, EventArgs e)
  42. {
  43. txtCxLocation.CheckLonLat(dxErrorProvider, "测向站");
  44. }
  45. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  46. {
  47. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  48. }
  49. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  50. {
  51. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  52. }
  53. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  54. {
  55. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  56. }
  57. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  58. {
  59. StationRes station = null;
  60. CxRes cx = null;
  61. using (RHDWContext db = new RHDWContext())
  62. {
  63. listSat = await db.SatInfos.ToListAsync();
  64. }
  65. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  66. {
  67. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  68. cx = await db?.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  69. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  70. }
  71. if (cg != null)
  72. {
  73. this.txtDtoSx.Text = $"{cg.Dto1.Value}";
  74. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  75. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  76. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  77. this.txtSigTime.EditValue = info.SigTime;
  78. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  79. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  80. }
  81. if (cx != null)
  82. {
  83. this.txtcxFx.Text = $"{cx.Fx}";
  84. }
  85. if (station != null)
  86. {
  87. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  88. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  89. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  90. this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
  91. }
  92. }
  93. public bool CheckParam()
  94. {
  95. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  96. {
  97. return false;
  98. }
  99. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  100. {
  101. return false;
  102. }
  103. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  104. {
  105. return false;
  106. }
  107. return true;
  108. }
  109. private void btnDtoLine_Click(object sender, EventArgs e)
  110. {
  111. if (!CheckParam()) { return; }
  112. try
  113. {
  114. var MsAnt = txtsatStation.GetLonLat();
  115. var CDBAnt = txtcdbStation.GetLonLat();
  116. var RefGeod = txtRefLocation.GetLonLat();
  117. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  118. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  119. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  120. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  121. double[] msEph = ucEphXYZMain.EphXYZ();
  122. double[] NsEph = ucEphXYZAdaj.EphXYZ();
  123. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  124. dtoLineXd.MsEph = msEph;
  125. dtoLineXd.MsAnt = MsAnt;
  126. dtoLineXd.CDBAnt = CDBAnt;
  127. dtoLineXd.RefGeod = RefGeod;
  128. dtoLineXd.xdDto = DtoCdb;
  129. dtoLineXd.RefDto = YbMainDto;
  130. dtoLineXd.PosLon = info.PosLon;
  131. dtoLineXd.PosLat = info.PosLat;
  132. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  133. twoStartOption.MsEph = msEph;
  134. twoStartOption.NsEph = NsEph;
  135. twoStartOption.MsAnt = MsAnt;
  136. twoStartOption.NsAnt = MsAnt;
  137. twoStartOption.RefGeod = RefGeod;
  138. twoStartOption.TargetDto = DtoSx;
  139. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  140. twoStartOption.PosLon = info.PosLon;
  141. twoStartOption.PosLat = info.PosLat;
  142. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  143. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  144. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  145. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  146. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  147. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  148. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  149. mapControl1.DrawDtoLine($"[{msat},{nsat}]时差线", tsDtoLine);
  150. }
  151. catch (Exception ex)
  152. {
  153. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  154. DxHelper.MsgBoxHelper.ShowError($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  155. }
  156. }
  157. private async void btnEphCalc_Click(object sender, EventArgs e)
  158. {
  159. if (this.txtSigTime.DateTime == DateTime.MinValue)
  160. {
  161. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  162. return;
  163. }
  164. var sigTime = this.txtSigTime.DateTime;
  165. try
  166. {
  167. var mainxlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  168. if (mainxlInfo == null)
  169. {
  170. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  171. return;
  172. }
  173. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  174. ucEphXYZMain.SetXYZ("主星", cg.MainCode.Value, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  175. var adjaxlInfo = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  176. if (adjaxlInfo == null)
  177. {
  178. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  179. return;
  180. }
  181. var adjaeph = EphHelper.Calc(adjaxlInfo.TwoLine, sigTime.ToUtc());
  182. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code.Value, (adjaeph.X, adjaeph.Y, adjaeph.Z), Color.Red);
  183. }
  184. catch (Exception ex)
  185. {
  186. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  187. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  188. }
  189. }
  190. private void btnPos_Click(object sender, EventArgs e)
  191. {
  192. if (!CheckParam()) { return; }
  193. txtPosRes.Text = " ";
  194. try
  195. {
  196. var MsAnt = txtsatStation.GetLonLat();
  197. var CDBAnt = txtcdbStation.GetLonLat();
  198. var RefGeod = txtRefLocation.GetLonLat();
  199. var cxStation = txtCxLocation.GetLonLat();
  200. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  201. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  202. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  203. var YbAdja1Dto = Convert.ToDouble(this.txtYbAdja.Text);
  204. var cxFx = Convert.ToDouble(this.txtcxFx.Text);
  205. double[] msEph = ucEphXYZMain.EphXYZ();
  206. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  207. var sigTime = txtSigTime.DateTime;
  208. var StationRes = new StationRes()
  209. {
  210. SatTxLon = MsAnt[0],
  211. SatTxLat = MsAnt[1],
  212. CdbTxLon = CDBAnt[0],
  213. CdbTxLat = CDBAnt[1],
  214. CxLon = cxStation[0],
  215. CxLat = cxStation[1],
  216. RefLon = RefGeod[0],
  217. RefLat = RefGeod[1],
  218. };
  219. var cgRes = new CgRes()
  220. {
  221. SigTime = sigTime,
  222. Dto1 = DtoSx,
  223. DtoCdb = DtoCdb,
  224. YbMainDto = YbMainDto,
  225. YbAdja1Dto = YbAdja1Dto,
  226. MainCode = cg.MainCode.Value,
  227. Adja1Code = cg.Adja1Code.Value,
  228. MainX = msEph[0],
  229. MainY = msEph[1],
  230. MainZ = msEph[2],
  231. Adja1X = nsEph[0],
  232. Adja1Y = nsEph[1],
  233. Adja1Z = nsEph[2],
  234. };
  235. var rhcxRes = new CxRes()
  236. {
  237. SigTime = sigTime,
  238. Fx = cxFx,
  239. };
  240. var res = PosApi.RH_Pos(cgRes, StationRes, rhcxRes, false);
  241. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  242. }
  243. catch (Exception ex)
  244. {
  245. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  246. DxHelper.MsgBoxHelper.ShowError($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  247. }
  248. }
  249. }
  250. }