X3DTOParamEditor.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 X3DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  28. {
  29. private MapControl mapControl1;
  30. private PosRes info;
  31. private CgRes cg;
  32. private List<SatInfo> listSat;
  33. public X3DTOParamEditor(PosRes info, MapControl mapControl)
  34. {
  35. InitializeComponent();
  36. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  37. this.info = info;
  38. this.mapControl1 = mapControl;
  39. //this.StartPosition = FormStartPosition.CenterParent;
  40. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  41. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  42. }
  43. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  44. {
  45. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  46. }
  47. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  48. {
  49. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  50. }
  51. private async void X3DTOParamEditor_Load(object sender, EventArgs e)
  52. {
  53. StationRes station;
  54. using (RHDWContext db = new RHDWContext())
  55. {
  56. listSat = await db.SatInfos.ToListAsync();
  57. }
  58. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  59. {
  60. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  61. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  62. }
  63. if (cg != null)
  64. {
  65. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  66. this.txtDtoSx1.Text = $"{cg.Dto2.Value:f3}";
  67. if (info.PosResType == EnumPosResType.X3)
  68. {
  69. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  70. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  71. this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value:f3}";
  72. }
  73. this.sigTime.EditValue = info.SigTime;
  74. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  75. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  76. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  77. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  78. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  79. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  80. this.txtAdjaX1.Text = $"{cg.Adja2X.Value:f3}";
  81. this.txtAdjaY1.Text = $"{cg.Adja2Y.Value:f3}";
  82. this.txtAdjaZ1.Text = $"{cg.Adja2Z.Value:f3}";
  83. }
  84. if (station != null)
  85. {
  86. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  87. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  88. }
  89. if (info.PosResType == EnumPosResType.X3NoRef)
  90. {
  91. txtYbMain.Properties.ReadOnly = true;
  92. txtYbAdja.Properties.ReadOnly = true;
  93. txtYbAdja1.Properties.ReadOnly = true;
  94. txtRefLocation.Properties.ReadOnly = true;
  95. this.txtRefLocation.Text = $"{0},{0}";
  96. }
  97. }
  98. public bool CheckParam()
  99. {
  100. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  101. {
  102. return false;
  103. }
  104. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  105. {
  106. return false;
  107. }
  108. return true;
  109. }
  110. private void btnOk_Click(object sender, EventArgs e)
  111. {
  112. if (!CheckParam()) { return; }
  113. try
  114. {
  115. var MsAnt = txtsatStation.GetLonLat();
  116. var RefGeod = info.PosResType == EnumPosResType.X3 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  117. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  118. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  119. var YbMainDto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  120. var YbAdja1Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  121. var YbAdja2Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja1.Text) : 0;
  122. var MainX = Convert.ToDouble(this.txtMainX.Text);
  123. var MainY = Convert.ToDouble(this.txtMainY.Text);
  124. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  125. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  126. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  127. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  128. var AdjaX2 = Convert.ToDouble(this.txtAdjaX1.Text);
  129. var AdjaY2 = Convert.ToDouble(this.txtAdjaY1.Text);
  130. var AdjaZ2 = Convert.ToDouble(this.txtAdjaZ1.Text);
  131. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  132. double[] Ns1Eph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  133. double[] Ns2Eph = new double[] { AdjaX2, AdjaY2, AdjaZ2, 0, 0, 0 };
  134. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  135. twoStartOption.MsEph = msEph;
  136. twoStartOption.NsEph = Ns1Eph;
  137. twoStartOption.MsAnt = MsAnt;
  138. twoStartOption.NsAnt = MsAnt;
  139. twoStartOption.RefGeod = RefGeod;
  140. twoStartOption.TargetDto = DtoSx;
  141. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  142. twoStartOption.PosLon = info.PosLon;
  143. twoStartOption.PosLat = info.PosLat;
  144. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  145. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  146. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  147. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.Value.ToString();
  148. var ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  149. if (string.IsNullOrWhiteSpace(ad2sat)) ad2sat = cg.Adja2Code.Value.ToString();
  150. if (info.PosResType == EnumPosResType.X3)
  151. {
  152. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  153. mapControl1.DrawDtoPonit($"[{msat},[{nsat}]]带参时差线", tsDtoLine);
  154. twoStartOption.NsEph = Ns2Eph;
  155. twoStartOption.RefDto = YbMainDto - YbAdja2Dto;
  156. twoStartOption.TargetDto = DtoSx1;
  157. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  158. mapControl1.DrawDtoPonit($"[{msat},{ad2sat}]带参时差线", tsDtoLine1);
  159. }
  160. else
  161. {
  162. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  163. mapControl1.DrawDtoPonit($"[{msat},[{nsat}]]无参时差线", tsDtoLine);
  164. twoStartOption.NsEph = Ns2Eph;
  165. twoStartOption.TargetDto = DtoSx1;
  166. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  167. mapControl1.DrawDtoPonit($"[{msat},{ad2sat}]无参时差线", tsDtoLine1);
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  173. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败");
  174. }
  175. }
  176. }
  177. }