X2D1DTOParamEditor.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private MapControl mapControl1;
  22. private PosRes info;
  23. private CgRes cg;
  24. private List<SatInfo> listSat;
  25. public X2D1DTOParamEditor(PosRes info, MapControl mapControl)
  26. {
  27. InitializeComponent();
  28. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  29. this.info = info;
  30. this.listSat = new List<SatInfo>();
  31. this.mapControl1 = mapControl;
  32. //this.StartPosition = FormStartPosition.CenterParent;
  33. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  34. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  35. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  36. }
  37. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  38. {
  39. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  40. }
  41. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  42. {
  43. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  44. }
  45. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  46. {
  47. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  48. }
  49. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  50. {
  51. StationRes station;
  52. using (RHDWContext db = new RHDWContext())
  53. {
  54. listSat = await db.SatInfos.ToListAsync();
  55. }
  56. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  57. {
  58. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  59. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  60. }
  61. if (cg != null)
  62. {
  63. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  64. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  65. if (info.PosResType == EnumPosResType.X2D1)
  66. {
  67. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  68. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  69. }
  70. this.sigTime.EditValue = info.SigTime;
  71. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  72. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  73. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  74. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  75. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  76. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  77. }
  78. if (station != null)
  79. {
  80. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  81. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  82. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  83. }
  84. if (info.PosResType == EnumPosResType.X2D1NoRef)
  85. {
  86. txtYbMain.Properties.ReadOnly = true;
  87. txtYbAdja.Properties.ReadOnly = true;
  88. txtRefLocation.Properties.ReadOnly = true;
  89. this.txtRefLocation.Text = $"{0},{0}";
  90. }
  91. //double tarLon = 46, tarLat = 24;
  92. //double recLon = 45.9, recLat = 23.9;
  93. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  94. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  95. //var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value);
  96. //var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value);
  97. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef);
  98. //var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef);
  99. //var dto1 = (dt1 - dt2) * 1e6;
  100. //var dt3 = PhysicsHelper.Dto(tarEcef, recEcef);
  101. //var dto2 = (dt1 - dt3) * 1e6;
  102. }
  103. public bool CheckParam()
  104. {
  105. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  106. {
  107. return false;
  108. }
  109. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  110. {
  111. return false;
  112. }
  113. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  114. {
  115. return false;
  116. }
  117. return true;
  118. }
  119. private void btnOk_Click(object sender, EventArgs e)
  120. {
  121. if (!CheckParam()) { return; }
  122. try
  123. {
  124. var MsAnt = txtsatStation.GetLonLat();
  125. var CDBAnt = txtcdbStation.GetLonLat();
  126. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  127. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  128. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  129. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  130. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  131. var MainX = Convert.ToDouble(this.txtMainX.Text);
  132. var MainY = Convert.ToDouble(this.txtMainY.Text);
  133. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  134. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  135. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  136. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  137. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  138. double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  139. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  140. dtoLineXd.MsEph = msEph;
  141. dtoLineXd.MsAnt = MsAnt;
  142. dtoLineXd.CDBAnt = CDBAnt;
  143. dtoLineXd.RefGeod = RefGeod;
  144. dtoLineXd.xdDto = DtoCdb;
  145. dtoLineXd.RefDto = YbMainDto;
  146. dtoLineXd.PosLon = info.PosLon;
  147. dtoLineXd.PosLat = info.PosLat;
  148. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  149. twoStartOption.MsEph = msEph;
  150. twoStartOption.NsEph = NsEph;
  151. twoStartOption.MsAnt = MsAnt;
  152. twoStartOption.NsAnt = MsAnt;
  153. twoStartOption.RefGeod = RefGeod;
  154. twoStartOption.TargetDto = DtoSx;
  155. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  156. twoStartOption.PosLon = info.PosLon;
  157. twoStartOption.PosLat = info.PosLat;
  158. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  159. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  160. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  161. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  162. if (info.PosResType == EnumPosResType.X2D1)
  163. {
  164. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  165. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  166. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  167. mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine);
  168. }
  169. else
  170. {
  171. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRef(dtoLineXd);
  172. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  173. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  174. mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine);
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  180. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  181. }
  182. }
  183. }
  184. }