X2D1DTOParamEditor.cs 8.2 KB

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