X3DTOParamEditor.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.XtraForm
  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.listSat = new List<SatInfo>();
  39. this.mapControl1 = mapControl;
  40. this.StartPosition = FormStartPosition.CenterParent;
  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 = db.SatInfos.ToList();
  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}";
  64. this.txtDtoSx1.Text = $"{cg.Dto2.Value}";
  65. if (info.PosResType == EnumPosResType.X3)
  66. {
  67. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  68. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value}";
  69. this.txtYbAdja1.Text = $"{cg.YbAdja2Dto.Value}";
  70. }
  71. this.sigTime.EditValue = info.SigTime;
  72. this.txtMainX.Text = $"{cg.MainX.Value}";
  73. this.txtMainY.Text = $"{cg.MainY.Value}";
  74. this.txtMainZ.Text = $"{cg.MainZ.Value}";
  75. this.txtAdjaX.Text = $"{cg.Adja1X.Value}";
  76. this.txtAdjaY.Text = $"{cg.Adja1Y.Value}";
  77. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value}";
  78. this.txtAdjaX1.Text = $"{cg.Adja2X.Value}";
  79. this.txtAdjaY1.Text = $"{cg.Adja2Y.Value}";
  80. this.txtAdjaZ1.Text = $"{cg.Adja2Z.Value}";
  81. }
  82. if (info.PosResType == EnumPosResType.X3NoRef)
  83. {
  84. txtYbMain.Properties.ReadOnly = true;
  85. txtYbAdja.Properties.ReadOnly = true;
  86. txtYbAdja1.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.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  93. }
  94. }
  95. public bool CheckParam()
  96. {
  97. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  98. {
  99. return false;
  100. }
  101. if (info.PosResType == EnumPosResType.X3 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  102. {
  103. return false;
  104. }
  105. return true;
  106. }
  107. private void btnOk_Click(object sender, EventArgs e)
  108. {
  109. if (!CheckParam()) { return; }
  110. try
  111. {
  112. var MsAnt = txtsatStation.GetLonLat();
  113. var RefGeod = info.PosResType == EnumPosResType.X3 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  114. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  115. var DtoSx1 = Convert.ToDouble(this.txtDtoSx1.Text);
  116. var YbMainDto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  117. var YbAdja1Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  118. var YbAdja2Dto = info.PosResType == EnumPosResType.X3 ? Convert.ToDouble(this.txtYbAdja1.Text) : 0;
  119. var MainX = Convert.ToDouble(this.txtMainX.Text);
  120. var MainY = Convert.ToDouble(this.txtMainY.Text);
  121. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  122. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  123. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  124. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  125. var AdjaX2 = Convert.ToDouble(this.txtAdjaX1.Text);
  126. var AdjaY2 = Convert.ToDouble(this.txtAdjaY1.Text);
  127. var AdjaZ2 = Convert.ToDouble(this.txtAdjaZ1.Text);
  128. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  129. double[] Ns1Eph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  130. double[] Ns2Eph = new double[] { AdjaX2, AdjaY2, AdjaZ2, 0, 0, 0 };
  131. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  132. twoStartOption.MsEph = msEph;
  133. twoStartOption.NsEph = Ns1Eph;
  134. twoStartOption.MsAnt = MsAnt;
  135. twoStartOption.NsAnt = MsAnt;
  136. twoStartOption.RefGeod = RefGeod;
  137. twoStartOption.TargetDto = DtoSx;
  138. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  139. twoStartOption.PosLon = info.PosLon;
  140. twoStartOption.PosLat = info.PosLat;
  141. string msat = string.Empty;
  142. if (cg.MainCode.HasValue)
  143. {
  144. msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  145. }
  146. string nsat = string.Empty;
  147. if (cg.Adja1Code.HasValue)
  148. {
  149. nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
  150. }
  151. string ad2sat = string.Empty;
  152. if (cg.Adja2Code.HasValue)
  153. {
  154. ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
  155. }
  156. if (info.PosResType == EnumPosResType.X3)
  157. {
  158. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  159. mapControl1.DrawDtoPonit($"双星[{msat},[{nsat}]]时差线", tsDtoLine);
  160. twoStartOption.NsEph = Ns2Eph;
  161. twoStartOption.RefDto = YbMainDto - YbAdja2Dto;
  162. twoStartOption.TargetDto = DtoSx1;
  163. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  164. mapControl1.DrawDtoPonit($"双星[{msat},{ad2sat}]时差线", tsDtoLine1);
  165. }
  166. else
  167. {
  168. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  169. mapControl1.DrawDtoPonit($"双星[{msat},[{nsat}]]时差线", tsDtoLine);
  170. twoStartOption.NsEph = Ns2Eph;
  171. twoStartOption.TargetDto = DtoSx1;
  172. var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  173. mapControl1.DrawDtoPonit($"双星[{msat},{ad2sat}]时差线", tsDtoLine1);
  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. }