X1D1DTOParamEditor.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.Entity;
  16. using XdCxRhDW.Repostory;
  17. namespace XdCxRhDW.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. public X1D1DTOParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.info = info;
  29. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  30. sigTime.UseDefault();
  31. this.layoutControl1.UseDefault();
  32. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  33. this.listSat = new List<SatInfo>();
  34. this.mapControl1 = mapControl;
  35. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  36. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  37. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  38. }
  39. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  40. {
  41. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  42. }
  43. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  44. {
  45. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  46. }
  47. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  48. {
  49. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  50. }
  51. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  52. {
  53. StationRes station = null;
  54. CxRes cx = null;
  55. using (RHDWContext db = new RHDWContext())
  56. {
  57. listSat = await db.SatInfos.ToListAsync();
  58. }
  59. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  60. {
  61. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  62. cx = await db?.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  63. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  64. }
  65. if (cg != null)
  66. {
  67. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f4}";
  68. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f4}";
  69. this.sigTime.EditValue = info.SigTime;
  70. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  71. }
  72. if (cx != null)
  73. {
  74. this.txtcxFx.Text = $"{cx.Fx:f4}";
  75. }
  76. if (station != null)
  77. {
  78. this.txtsatStation.Text = $"{station.SatTxLon:f4},{station.SatTxLat:f4}";
  79. this.txtcdbStation.Text = $"{station.CdbTxLon:f4},{station.CdbTxLat:f4}";
  80. this.txtRefLocation.Text = $"{station.RefLon:f4},{station.RefLat:f4}";
  81. this.txtCxLocation.Text= $"{station.CxLon:f4},{station.CxLat:f4}";
  82. }
  83. }
  84. public bool CheckParam()
  85. {
  86. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  87. {
  88. return false;
  89. }
  90. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  91. {
  92. return false;
  93. }
  94. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  95. {
  96. return false;
  97. }
  98. return true;
  99. }
  100. private void btnOk_Click(object sender, EventArgs e)
  101. {
  102. if (!CheckParam()) { return; }
  103. try
  104. {
  105. var MsAnt = txtsatStation.GetLonLat();
  106. var CDBAnt = txtcdbStation.GetLonLat();
  107. var RefGeod = txtRefLocation.GetLonLat();
  108. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  109. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  110. double[] msEph = ucEphXYZMain.EphXYZ();
  111. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  112. dtoLineXd.MsEph = msEph;
  113. dtoLineXd.MsAnt = MsAnt;
  114. dtoLineXd.CDBAnt = CDBAnt;
  115. dtoLineXd.RefGeod = RefGeod;
  116. dtoLineXd.xdDto = DtoCdb;
  117. dtoLineXd.RefDto = YbMainDto;
  118. dtoLineXd.PosLon = info.PosLon;
  119. dtoLineXd.PosLat = info.PosLat;
  120. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  121. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  122. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  123. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine);
  124. }
  125. catch (Exception ex)
  126. {
  127. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  128. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  129. }
  130. }
  131. private async void btnEphCalc_Click(object sender, EventArgs e)
  132. {
  133. if (this.sigTime.DateTime == DateTime.MinValue)
  134. {
  135. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  136. return;
  137. }
  138. var sigTime = this.sigTime.DateTime;
  139. try
  140. {
  141. var mainCode = ucEphXYZMain.GetSatCode();
  142. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  143. if (mainxlInfo == null)
  144. {
  145. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  146. return;
  147. }
  148. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  149. ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  150. }
  151. catch (Exception ex)
  152. {
  153. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  154. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  155. }
  156. }
  157. private void btnPos_Click(object sender, EventArgs e)
  158. {
  159. if (!CheckParam()) { return; }
  160. try
  161. {
  162. var MsAnt = txtsatStation.GetLonLat();
  163. var CDBAnt = txtcdbStation.GetLonLat();
  164. var RefGeod = txtRefLocation.GetLonLat();
  165. var CXStation = txtCxLocation.GetLonLat();
  166. var sigTime = this.sigTime.DateTime;
  167. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  168. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  169. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  170. double[] msEph = ucEphXYZMain.EphXYZ();
  171. var StationRes = new StationRes()
  172. {
  173. SatTxLon = MsAnt[0],
  174. SatTxLat = MsAnt[1],
  175. CdbTxLon = CDBAnt[0],
  176. CdbTxLat = CDBAnt[1],
  177. CxLon = CXStation[0],
  178. CxLat = CXStation[1],
  179. RefLon = RefGeod[0],
  180. RefLat = RefGeod[1],
  181. };
  182. var cgRes = new CgRes()
  183. {
  184. SigTime = sigTime,
  185. DtoCdb = DtoCdb,
  186. YbMainDto = YbMainDto,
  187. MainX = msEph[0],
  188. MainY = msEph[1],
  189. MainZ = msEph[2],
  190. };
  191. var cxRes = new CxRes()
  192. {
  193. SigTime = sigTime,
  194. Fx = Fx,
  195. };
  196. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  197. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4} , {res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  198. }
  199. catch (Exception ex)
  200. {
  201. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  202. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败");
  203. }
  204. }
  205. }
  206. }