X1D1PosParamEditor.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using DevExpress.Mvvm.ModuleInjection.Native;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.DXErrorProvider;
  4. using DevExpress.XtraLayout;
  5. using DevExpress.XtraMap;
  6. using DevExpress.XtraTreeList.Data;
  7. using DxHelper;
  8. using ExtensionsDev;
  9. using System;
  10. using System.CodeDom;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Data.Entity;
  15. using System.Data.Entity.Migrations;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows.Documents;
  21. using System.Windows.Forms;
  22. using XdCxRhDW.Core.Api;
  23. using XdCxRhDW.Repostory;
  24. using XdCxRhDW.Repostory.EFContext;
  25. using XdCxRhDW.Repostory.Model;
  26. namespace XdCxRhDW.App.EditForms
  27. {
  28. public partial class X1D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  29. {
  30. private MapControl mapControl1;
  31. private PosRes info;
  32. private CgRes cg;
  33. private List<SatInfo> listSat;
  34. public X1D1PosParamEditor(PosRes info, MapControl mapControl)
  35. {
  36. InitializeComponent();
  37. this.info = info;
  38. this.listSat = new List<SatInfo>();
  39. this.mapControl1 = mapControl;
  40. this.labelControl1.Text = $"";
  41. //this.StartPosition = FormStartPosition.CenterParent;
  42. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  43. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  44. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  45. txtCxLocation.EditValueChanged += TxtCxLocation_EditValueChanged;
  46. }
  47. private void TxtCxLocation_EditValueChanged(object sender, EventArgs e)
  48. {
  49. txtCxLocation.CheckLonLat(dxErrorProvider, "测向站");
  50. }
  51. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  52. {
  53. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  54. }
  55. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  56. {
  57. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  58. }
  59. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  60. {
  61. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  62. }
  63. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  64. {
  65. StationRes station;
  66. CxRes cx;
  67. using (RHDWContext db = new RHDWContext())
  68. {
  69. listSat = await db.SatInfos.ToListAsync();
  70. }
  71. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  72. {
  73. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  74. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  75. cx = await db.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  76. }
  77. if (cg != null)
  78. {
  79. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  80. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  81. this.sigTime.EditValue = info.SigTime;
  82. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  83. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  84. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  85. }
  86. if (cx != null)
  87. {
  88. this.txtcxFx.Text = $"{cx.Fx:f3}";
  89. }
  90. if (station != null)
  91. {
  92. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  93. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  94. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  95. this.txtCxLocation.Text = $"{station.CxLon:f3},{station.CxLat:f3}";
  96. }
  97. }
  98. public bool CheckParam()
  99. {
  100. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  101. {
  102. return false;
  103. }
  104. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  105. {
  106. return false;
  107. }
  108. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  109. {
  110. return false;
  111. }
  112. return true;
  113. }
  114. private void btnOk_Click(object sender, EventArgs e)
  115. {
  116. if (!CheckParam()) { return; }
  117. try
  118. {
  119. var MsAnt = txtsatStation.GetLonLat();
  120. var CDBAnt = txtcdbStation.GetLonLat();
  121. var RefGeod = txtRefLocation.GetLonLat();
  122. var CXStation = txtCxLocation.GetLonLat();
  123. var sigTime = this.sigTime.DateTime;
  124. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  125. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  126. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  127. var MainX = Convert.ToDouble(this.txtMainX.Text);
  128. var MainY = Convert.ToDouble(this.txtMainY.Text);
  129. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  130. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  131. var StationRes = new StationRes()
  132. {
  133. SatTxLon = MsAnt[0],
  134. SatTxLat = MsAnt[1],
  135. CdbTxLon = CDBAnt[0],
  136. CdbTxLat = CDBAnt[1],
  137. CxLon = CXStation[0],
  138. CxLat = CXStation[1],
  139. RefLon = RefGeod[0],
  140. RefLat = RefGeod[1],
  141. };
  142. var cgRes = new CgRes()
  143. {
  144. SigTime = sigTime,
  145. DtoCdb = DtoCdb,
  146. YbMainDto = YbMainDto,
  147. MainX = MainX,
  148. MainY = MainY,
  149. MainZ = MainZ,
  150. };
  151. var cxRes = new CxRes()
  152. {
  153. SigTime = sigTime,
  154. Fx = Fx,
  155. };
  156. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  157. this.labelControl1.Text = $"定位点:[{res[0]},{res[1]}] 镜像点:[{res[3]},{res[4]}]";
  158. }
  159. catch (Exception ex)
  160. {
  161. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  162. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  163. }
  164. }
  165. private async void btnCalcXl_Click(object sender, EventArgs e)
  166. {
  167. try
  168. {
  169. var sigTime = this.sigTime.DateTime;
  170. var xlInfo = await XlCache.GetLatestAsync(cg.MainCode.Value, sigTime);
  171. if (xlInfo == null)
  172. {
  173. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  174. return;
  175. }
  176. var p = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  177. this.txtMainX.Text = $"{p.X:f3}";
  178. this.txtMainY.Text = $"{p.Y:f3}";
  179. this.txtMainZ.Text = $"{p.Z:f3}";
  180. }
  181. catch (Exception ex)
  182. {
  183. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  184. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  185. }
  186. }
  187. }
  188. }