X3PosParamEditor.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 X3PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  30. {
  31. private MapControl mapControl1;
  32. private PosRes info;
  33. private CgRes cg;
  34. private List<SatInfo> listSat;
  35. public X3PosParamEditor(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.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  67. this.txtDtoSx1.Text = $"{cg.Dto2.Value:f3}";
  68. if (info.PosResType == EnumPosResType.X3)
  69. {
  70. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  71. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  72. this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value:f3}";
  73. }
  74. this.sigTime.EditValue = info.SigTime;
  75. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  76. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  77. this.txtMainZ.Text = $"{cg.MainZ.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.txtAdjaX1.Text = $"{cg.Adja2X.Value:f3}";
  82. this.txtAdjaY1.Text = $"{cg.Adja2Y.Value:f3}";
  83. this.txtAdjaZ1.Text = $"{cg.Adja2Z.Value:f3}";
  84. }
  85. if (station != null)
  86. {
  87. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  88. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  89. }
  90. if (info.PosResType == EnumPosResType.X3NoRef)
  91. {
  92. txtYbMain.Properties.ReadOnly = true;
  93. txtYbAdja.Properties.ReadOnly = true;
  94. txtYbAdja1.Properties.ReadOnly = true;
  95. txtRefLocation.Properties.ReadOnly = true;
  96. this.txtRefLocation.Text = $"{0},{0}";
  97. }
  98. }
  99. public bool CheckParam()
  100. {
  101. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  102. {
  103. return false;
  104. }
  105. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  106. {
  107. return false;
  108. }
  109. return true;
  110. }
  111. private void btnOk_Click(object sender, EventArgs e)
  112. {
  113. if (!CheckParam()) { return; }
  114. try
  115. {
  116. var MsAnt = txtsatStation.GetLonLat();
  117. var RefGeod = info.PosResType == EnumPosResType.X3 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  118. var sigTime = this.sigTime.DateTime;
  119. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  120. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  121. var YbMainDto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  122. var YbAdja1Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  123. var YbAdja2Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja1.Text) : 0;
  124. var MainX = Convert.ToDouble(this.txtMainX.Text);
  125. var MainY = Convert.ToDouble(this.txtMainY.Text);
  126. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  127. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  128. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  129. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  130. var AdjaX2 = Convert.ToDouble(this.txtAdjaX1.Text);
  131. var AdjaY2 = Convert.ToDouble(this.txtAdjaY1.Text);
  132. var AdjaZ2 = Convert.ToDouble(this.txtAdjaZ1.Text);
  133. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  134. double[] Ns1Eph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  135. double[] Ns2Eph = new double[] { AdjaX2, AdjaY2, AdjaZ2, 0, 0, 0 };
  136. var StationRes = new StationRes()
  137. {
  138. SatTxLon = MsAnt[0],
  139. SatTxLat = MsAnt[1],
  140. RefLon = RefGeod[0],
  141. RefLat = RefGeod[1],
  142. };
  143. var cgRes = new CgRes()
  144. {
  145. SigTime = sigTime,
  146. Dto1 = DtoSx,
  147. Dto2 = DtoSx1,
  148. YbMainDto = YbMainDto,
  149. YbAdja1Dto = YbAdja1Dto,
  150. YbAdja2Dto = YbAdja2Dto,
  151. MainX = MainX,
  152. MainY = MainY,
  153. MainZ = MainZ,
  154. Adja1X = AdjaX,
  155. Adja1Y = AdjaY,
  156. Adja1Z = AdjaZ,
  157. Adja2X = AdjaX2,
  158. Adja2Y = AdjaY2,
  159. Adja2Z = AdjaZ2,
  160. };
  161. var res = info.PosResType == EnumPosResType.X3 ? PosApi.X3_Pos(cgRes, StationRes) : PosApi.X3_PosNoRef(cgRes, StationRes);
  162. this.labelControl1.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]},{res[1]}] 镜像点:[{res[3]},{res[4]}]";
  163. }
  164. catch (Exception ex)
  165. {
  166. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  167. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  168. }
  169. }
  170. private async void btnXl_Click(object sender, EventArgs e)
  171. {
  172. try
  173. {
  174. var sigTime = this.sigTime.DateTime;
  175. var xlInfo = await XlCache.GetLatestAsync(cg.MainCode.Value, sigTime);
  176. if (xlInfo == null)
  177. {
  178. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  179. return;
  180. }
  181. var xlInfo1 = await XlCache.GetLatestAsync(cg.Adja1Code.Value, sigTime);
  182. if (xlInfo1 == null)
  183. {
  184. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code.Value}未找到对应的星历信息,请导入星历");
  185. return;
  186. }
  187. var xlInfo2 = await XlCache.GetLatestAsync(cg.Adja2Code.Value, sigTime);
  188. if (xlInfo2 == null)
  189. {
  190. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja2Code.Value}未找到对应的星历信息,请导入星历");
  191. return;
  192. }
  193. var mEph = EphHelper.Calc(xlInfo.TwoLine, sigTime);
  194. this.txtMainX.Text = $"{mEph.X:f3}";
  195. this.txtMainY.Text = $"{mEph.Y:f3}";
  196. this.txtMainZ.Text = $"{mEph.Z:f3}";
  197. var nEph1 = EphHelper.Calc(xlInfo1.TwoLine, sigTime);
  198. this.txtAdjaX.Text = $"{nEph1.X:f3}";
  199. this.txtAdjaY.Text = $"{nEph1.Y:f3}";
  200. this.txtAdjaZ.Text = $"{nEph1.Z:f3}";
  201. var nEph2 = EphHelper.Calc(xlInfo2.TwoLine, sigTime);
  202. this.txtAdjaX1.Text = $"{nEph2.X:f3}";
  203. this.txtAdjaY1.Text = $"{nEph2.Y:f3}";
  204. this.txtAdjaZ1.Text = $"{nEph2.Z:f3}";
  205. }
  206. catch (Exception ex)
  207. {
  208. Serilog.Log.Error(ex, $"手动{info.PosResType.GetEnumDisplayName()}推算星历失败.PosID={info.ID},SigTime={info.SigTime}");
  209. DxHelper.MsgBoxHelper.ShowWarning($"手动{info.PosResType.GetEnumDisplayName()}推算星历失败");
  210. }
  211. }
  212. }
  213. }