X3DfoPosParamEditor.cs 10 KB

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