X3PosParamEditor.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 X3PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private MapControl mapControl1;
  22. private PosRes info;
  23. private CgRes cg;
  24. private List<SatInfo> listSat;
  25. public X3PosParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.info = info;
  29. this.labelControl1.Text = $"";
  30. this.mapControl1 = mapControl;
  31. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  32. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  33. }
  34. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  35. {
  36. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  37. }
  38. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  39. {
  40. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  41. }
  42. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  43. {
  44. StationRes station;
  45. using (RHDWContext db = new RHDWContext())
  46. {
  47. listSat = await db.SatInfos.ToListAsync();
  48. }
  49. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  50. {
  51. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  52. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  53. }
  54. if (cg != null)
  55. {
  56. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  57. this.txtDtoSx1.Text = $"{cg.Dto2.Value:f3}";
  58. if (info.PosResType == EnumPosResType.X3)
  59. {
  60. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  61. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  62. this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value:f3}";
  63. }
  64. this.sigTime.EditValue = info.SigTime;
  65. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  66. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  67. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  68. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  69. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  70. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  71. this.txtAdjaX1.Text = $"{cg.Adja2X.Value:f3}";
  72. this.txtAdjaY1.Text = $"{cg.Adja2Y.Value:f3}";
  73. this.txtAdjaZ1.Text = $"{cg.Adja2Z.Value:f3}";
  74. }
  75. if (station != null)
  76. {
  77. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  78. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  79. }
  80. if (info.PosResType == EnumPosResType.X3NoRef)
  81. {
  82. txtYbMain.Properties.ReadOnly = true;
  83. txtYbAdja.Properties.ReadOnly = true;
  84. txtYbAdja1.Properties.ReadOnly = true;
  85. txtRefLocation.Properties.ReadOnly = true;
  86. this.txtRefLocation.Text = $"{0},{0}";
  87. }
  88. }
  89. public bool CheckParam()
  90. {
  91. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  92. {
  93. return false;
  94. }
  95. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  96. {
  97. return false;
  98. }
  99. return true;
  100. }
  101. private void btnOk_Click(object sender, EventArgs e)
  102. {
  103. if (!CheckParam()) { return; }
  104. try
  105. {
  106. var MsAnt = txtsatStation.GetLonLat();
  107. var RefGeod = info.PosResType == EnumPosResType.X3 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  108. var sigTime = this.sigTime.DateTime;
  109. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  110. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  111. var YbMainDto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  112. var YbAdja1Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  113. var YbAdja2Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja1.Text) : 0;
  114. var MainX = Convert.ToDouble(this.txtMainX.Text);
  115. var MainY = Convert.ToDouble(this.txtMainY.Text);
  116. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  117. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  118. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  119. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  120. var AdjaX2 = Convert.ToDouble(this.txtAdjaX1.Text);
  121. var AdjaY2 = Convert.ToDouble(this.txtAdjaY1.Text);
  122. var AdjaZ2 = Convert.ToDouble(this.txtAdjaZ1.Text);
  123. var StationRes = new StationRes()
  124. {
  125. SatTxLon = MsAnt[0],
  126. SatTxLat = MsAnt[1],
  127. RefLon = RefGeod[0],
  128. RefLat = RefGeod[1],
  129. };
  130. var cgRes = new CgRes()
  131. {
  132. SigTime = sigTime,
  133. Dto1 = DtoSx,
  134. Dto2 = DtoSx1,
  135. YbMainDto = YbMainDto,
  136. YbAdja1Dto = YbAdja1Dto,
  137. YbAdja2Dto = YbAdja2Dto,
  138. MainX = MainX,
  139. MainY = MainY,
  140. MainZ = MainZ,
  141. Adja1X = AdjaX,
  142. Adja1Y = AdjaY,
  143. Adja1Z = AdjaZ,
  144. Adja2X = AdjaX2,
  145. Adja2Y = AdjaY2,
  146. Adja2Z = AdjaZ2,
  147. };
  148. var res = info.PosResType == EnumPosResType.X3 ? PosApi.X3_Pos(cgRes, StationRes) : PosApi.X3_PosNoRef(cgRes, StationRes);
  149. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  150. }
  151. catch (Exception ex)
  152. {
  153. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  154. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  155. }
  156. }
  157. private async void btnXl_Click(object sender, EventArgs e)
  158. {
  159. try
  160. {
  161. var sigTime = this.sigTime.DateTime;
  162. var xlInfo = await XlRepository.GetLatestAsync(cg.MainCode.Value, sigTime);
  163. if (xlInfo == null)
  164. {
  165. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  166. return;
  167. }
  168. var xlInfo1 = await XlRepository.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  169. if (xlInfo1 == null)
  170. {
  171. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  172. return;
  173. }
  174. var xlInfo2 = await XlRepository.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  175. if (xlInfo2 == null)
  176. {
  177. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  178. return;
  179. }
  180. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  181. this.txtMainX.Text = $"{mEph.X:f3}";
  182. this.txtMainY.Text = $"{mEph.Y:f3}";
  183. this.txtMainZ.Text = $"{mEph.Z:f3}";
  184. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime);
  185. this.txtAdjaX.Text = $"{nEph1.X:f3}";
  186. this.txtAdjaY.Text = $"{nEph1.Y:f3}";
  187. this.txtAdjaZ.Text = $"{nEph1.Z:f3}";
  188. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime);
  189. this.txtAdjaX1.Text = $"{nEph2.X:f3}";
  190. this.txtAdjaY1.Text = $"{nEph2.Y:f3}";
  191. this.txtAdjaZ1.Text = $"{nEph2.Z:f3}";
  192. }
  193. catch (Exception ex)
  194. {
  195. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  196. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  197. }
  198. }
  199. }
  200. }