X3DfoPosParamEditor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  27. namespace XdCxRhDW.App.EditForms
  28. {
  29. public partial class X3DfoPosParamEditor : DevExpress.XtraEditors.XtraUserControl
  30. {
  31. private MapControl mapControl1;
  32. private PosRes info;
  33. private CgRes cg;
  34. private List<SatInfo> listSat;
  35. public X3DfoPosParamEditor(PosRes info, MapControl mapControl)
  36. {
  37. InitializeComponent();
  38. this.info = info;
  39. this.labelControl1.Text = $"";
  40. this.mapControl1 = mapControl;
  41. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  42. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  43. }
  44. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  45. {
  46. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  47. }
  48. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  49. {
  50. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  51. }
  52. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  53. {
  54. StationRes station;
  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. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  63. }
  64. if (cg != null)
  65. {
  66. this.txtDfoSx.Text = $"{cg.Dfo1.Value:f3}";
  67. this.txtDfoSx1.Text = $"{cg.Dfo2.Value:f3}";
  68. this.txtYbMain.Text = $"{cg.YbMainDfo.Value:f3}";
  69. this.txtYbAdja.Text = $"{cg.YbAdja1Dfo.Value:f3}";
  70. this.txtYbAdja1.Text = $"{cg.YbAdja2Dfo.Value:f3}";
  71. this.sigTime.EditValue = info.SigTime;
  72. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  73. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  74. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  75. this.txtMainVX.Text = $"{cg.MainVx.Value:f3}";
  76. this.txtMainVY.Text = $"{cg.MainVy.Value:f3}";
  77. this.txtMainVZ.Text = $"{cg.MainVz.Value:f3}";
  78. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  79. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  80. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  81. this.txtAdjaVX.Text = $"{cg.Adja1Vx.Value:f3}";
  82. this.txtAdjaVY.Text = $"{cg.Adja1Vy.Value:f3}";
  83. this.txtAdjaVZ.Text = $"{cg.Adja1Vz.Value:f3}";
  84. this.txtAdjaX1.Text = $"{cg.Adja2X.Value:f3}";
  85. this.txtAdjaY1.Text = $"{cg.Adja2Y.Value:f3}";
  86. this.txtAdjaZ1.Text = $"{cg.Adja2Z.Value:f3}";
  87. this.txtAdjaVX1.Text = $"{cg.Adja2Vx.Value:f3}";
  88. this.txtAdjaVY1.Text = $"{cg.Adja2Vy.Value:f3}";
  89. this.txtAdjaVZ1.Text = $"{cg.Adja2Vz.Value:f3}";
  90. this.txtTargetFreq.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
  91. this.txtTargetDFreq.EditValue = cg.TarFreqDown.HasValue ? cg.TarFreqDown.Value * 1e-6 : 950;
  92. this.txtRefFreq.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
  93. this.txtRefDFreq.EditValue = cg.RefFreqDown.HasValue ? cg.RefFreqDown.Value * 1e-6 : 950;
  94. }
  95. if (station != null)
  96. {
  97. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  98. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  99. }
  100. if (info.PosResType == EnumPosResType.X3NoRef)
  101. {
  102. txtYbMain.Properties.ReadOnly = true;
  103. txtYbAdja.Properties.ReadOnly = true;
  104. txtYbAdja1.Properties.ReadOnly = true;
  105. txtRefLocation.Properties.ReadOnly = true;
  106. this.txtRefLocation.Text = $"{0},{0}";
  107. }
  108. }
  109. public bool CheckParam()
  110. {
  111. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  112. {
  113. return false;
  114. }
  115. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  116. {
  117. return false;
  118. }
  119. return true;
  120. }
  121. private void btnOk_Click(object sender, EventArgs e)
  122. {
  123. if (!CheckParam()) { return; }
  124. try
  125. {
  126. var MsAnt = txtsatStation.GetLonLat();
  127. var RefGeod = txtRefLocation.GetLonLat();
  128. var sigTime = this.sigTime.DateTime;
  129. var DfoSx = Convert.ToDouble(this.txtDfoSx.Text);
  130. var DfoSx1 = Convert.ToDouble(this.txtDfoSx1.Text);
  131. var YbMainDfo = Convert.ToDouble(this.txtYbMain.Text);
  132. var YbAdja1Dfo = Convert.ToDouble(this.txtYbAdja.Text);
  133. var YbAdja2Dfo = Convert.ToDouble(this.txtYbAdja1.Text);
  134. var tFreq = Convert.ToDouble(this.txtTargetFreq.Text) * 1e6;
  135. var tdFreq = Convert.ToDouble(this.txtTargetDFreq.Text) * 1e6;
  136. var rFreq = Convert.ToDouble(this.txtRefFreq.Text) * 1e6;
  137. var rdFreq = Convert.ToDouble(this.txtRefDFreq.Text) * 1e6;
  138. var StationRes = new StationRes()
  139. {
  140. SatTxLon = MsAnt[0],
  141. SatTxLat = MsAnt[1],
  142. RefLon = RefGeod[0],
  143. RefLat = RefGeod[1],
  144. };
  145. var cgRes = new CgRes()
  146. {
  147. SigTime = sigTime,
  148. Dfo1 = DfoSx,
  149. Dfo2 = DfoSx1,
  150. YbMainDfo = YbMainDfo,
  151. YbAdja1Dfo = YbAdja1Dfo,
  152. YbAdja2Dfo = YbAdja2Dfo,
  153. TarFreqUp = tFreq,
  154. TarFreqDown = tdFreq,
  155. RefFreqUp = rFreq,
  156. RefFreqDown = rdFreq,
  157. MainX = Convert.ToDouble(this.txtMainX.Text),
  158. MainY = Convert.ToDouble(this.txtMainY.Text),
  159. MainZ = Convert.ToDouble(this.txtMainZ.Text),
  160. MainVx = Convert.ToDouble(this.txtMainVX.Text),
  161. MainVy = Convert.ToDouble(this.txtMainVY.Text),
  162. MainVz = Convert.ToDouble(this.txtMainVZ.Text),
  163. Adja1X = Convert.ToDouble(this.txtAdjaX.Text),
  164. Adja1Y = Convert.ToDouble(this.txtAdjaY.Text),
  165. Adja1Z = Convert.ToDouble(this.txtAdjaZ.Text),
  166. Adja1Vx = Convert.ToDouble(this.txtAdjaVX.Text),
  167. Adja1Vy = Convert.ToDouble(this.txtAdjaVY.Text),
  168. Adja1Vz = Convert.ToDouble(this.txtAdjaVZ.Text),
  169. Adja2X = Convert.ToDouble(this.txtAdjaX1.Text),
  170. Adja2Y = Convert.ToDouble(this.txtAdjaY1.Text),
  171. Adja2Z = Convert.ToDouble(this.txtAdjaZ1.Text),
  172. Adja2Vx = Convert.ToDouble(this.txtAdjaVX1.Text),
  173. Adja2Vy = Convert.ToDouble(this.txtAdjaVY1.Text),
  174. Adja2Vz = Convert.ToDouble(this.txtAdjaVZ1.Text),
  175. };
  176. var res = PosApi.X3_PosTwoDfo(cgRes, StationRes);
  177. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  178. }
  179. catch (Exception ex)
  180. {
  181. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}定位失败.PosID={info.ID},SigTime={info.SigTime}");
  182. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}定位失败");
  183. }
  184. }
  185. private async void btnXl_Click(object sender, EventArgs e)
  186. {
  187. try
  188. {
  189. var sigTime = this.sigTime.DateTime;
  190. var xlInfo = await XlCache.GetLatestAsync(cg.MainCode.Value, sigTime);
  191. if (xlInfo == null)
  192. {
  193. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  194. return;
  195. }
  196. var xlInfo1 = await XlCache.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  197. if (xlInfo1 == null)
  198. {
  199. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  200. return;
  201. }
  202. var xlInfo2 = await XlCache.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  203. if (xlInfo2 == null)
  204. {
  205. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  206. return;
  207. }
  208. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  209. this.txtMainX.Text = $"{mEph.X:f3}";
  210. this.txtMainY.Text = $"{mEph.Y:f3}";
  211. this.txtMainZ.Text = $"{mEph.Z:f3}";
  212. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime);
  213. this.txtAdjaX.Text = $"{nEph1.X:f3}";
  214. this.txtAdjaY.Text = $"{nEph1.Y:f3}";
  215. this.txtAdjaZ.Text = $"{nEph1.Z:f3}";
  216. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime);
  217. this.txtAdjaX1.Text = $"{nEph2.X:f3}";
  218. this.txtAdjaY1.Text = $"{nEph2.Y:f3}";
  219. this.txtAdjaZ1.Text = $"{nEph2.Z:f3}";
  220. }
  221. catch (Exception ex)
  222. {
  223. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  224. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  225. }
  226. }
  227. }
  228. }