X2D1DTOParamEditor.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.XtraUserControl
  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 = await db.SatInfos.ToListAsync();
  63. }
  64. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  65. {
  66. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  67. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  68. }
  69. if (cg != null)
  70. {
  71. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  72. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  73. if (info.PosResType == EnumPosResType.X2D1)
  74. {
  75. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  76. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  77. }
  78. this.sigTime.EditValue = info.SigTime;
  79. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  80. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  81. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  82. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  83. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  84. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  85. }
  86. if (station != null)
  87. {
  88. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  89. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  90. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  91. }
  92. if (info.PosResType == EnumPosResType.X2D1NoRef)
  93. {
  94. txtYbMain.Properties.ReadOnly = true;
  95. txtYbAdja.Properties.ReadOnly = true;
  96. txtRefLocation.Properties.ReadOnly = true;
  97. this.txtRefLocation.Text = $"{0},{0}";
  98. }
  99. }
  100. public bool CheckParam()
  101. {
  102. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  103. {
  104. return false;
  105. }
  106. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  107. {
  108. return false;
  109. }
  110. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  111. {
  112. return false;
  113. }
  114. return true;
  115. }
  116. private void btnOk_Click(object sender, EventArgs e)
  117. {
  118. if (!CheckParam()) { return; }
  119. try
  120. {
  121. var MsAnt = txtsatStation.GetLonLat();
  122. var CDBAnt = txtcdbStation.GetLonLat();
  123. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  124. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  125. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  126. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  127. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  128. var MainX = Convert.ToDouble(this.txtMainX.Text);
  129. var MainY = Convert.ToDouble(this.txtMainY.Text);
  130. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  131. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  132. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  133. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  134. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  135. double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  136. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  137. dtoLineXd.MsEph = msEph;
  138. dtoLineXd.MsAnt = MsAnt;
  139. dtoLineXd.CDBAnt = CDBAnt;
  140. dtoLineXd.RefGeod = RefGeod;
  141. dtoLineXd.xdDto = DtoCdb;
  142. dtoLineXd.RefDto = YbMainDto;
  143. dtoLineXd.PosLon = info.PosLon;
  144. dtoLineXd.PosLat = info.PosLat;
  145. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  146. twoStartOption.MsEph = msEph;
  147. twoStartOption.NsEph = NsEph;
  148. twoStartOption.MsAnt = MsAnt;
  149. twoStartOption.NsAnt = MsAnt;
  150. twoStartOption.RefGeod = RefGeod;
  151. twoStartOption.TargetDto = DtoSx;
  152. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  153. twoStartOption.PosLon = info.PosLon;
  154. twoStartOption.PosLat = info.PosLat;
  155. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  156. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  157. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  158. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  159. if (info.PosResType == EnumPosResType.X2D1)
  160. {
  161. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  162. mapControl1.DrawDtoPonit($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  163. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  164. mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine);
  165. }
  166. else
  167. {
  168. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRef(dtoLineXd);
  169. mapControl1.DrawDtoPonit($"[{msat},超短{CDBAnt[0]}°]时差线", xdDtoLine);
  170. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  171. mapControl1.DrawDtoPonit($"[{msat},{nsat}]时差线", tsDtoLine);
  172. }
  173. }
  174. catch (Exception ex)
  175. {
  176. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  177. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  178. }
  179. }
  180. }
  181. }