X1D1DTOParamEditor.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 X1D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  20. {
  21. private MapControl mapControl1;
  22. private PosRes info;
  23. private CgRes cg;
  24. private List<SatInfo> listSat;
  25. private CxRes cx;
  26. private StationRes station;
  27. public X1D1DTOParamEditor(PosRes info, MapControl mapControl)
  28. {
  29. InitializeComponent();
  30. this.info = info;
  31. itemSigTime.Text = $"{itemSigTime.Text}({SysConfig.Config.TimeZoneUTC})";
  32. sigTime.UseDefault();
  33. this.layoutControl1.UseDefault();
  34. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  35. this.listSat = new List<SatInfo>();
  36. this.mapControl1 = mapControl;
  37. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  38. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  39. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  40. }
  41. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  42. {
  43. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  44. }
  45. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  46. {
  47. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  48. }
  49. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  50. {
  51. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  52. }
  53. private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
  54. {
  55. using (RHDWContext db = new RHDWContext())
  56. {
  57. listSat = await db.SatInfos.ToListAsync();
  58. }
  59. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  60. {
  61. cg = await db?.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  62. cx = await db?.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
  63. station = await db?.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  64. }
  65. if (cg != null)
  66. {
  67. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value}";
  68. this.txtYbMain.Text = $"{cg.YbMainDto.Value}";
  69. this.sigTime.EditValue = info.SigTime;
  70. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  71. }
  72. if (cx != null)
  73. {
  74. this.txtcxFx.Text = $"{cx.Fx}";
  75. }
  76. if (station != null)
  77. {
  78. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  79. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  80. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  81. this.txtCxLocation.Text = $"{station.CxLon},{station.CxLat}";
  82. }
  83. }
  84. public bool CheckDtoLineParam()
  85. {
  86. dxErrorProvider.ClearErrors();
  87. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  88. {
  89. return false;
  90. }
  91. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  92. {
  93. return false;
  94. }
  95. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  96. {
  97. return false;
  98. }
  99. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  100. {
  101. return false;
  102. }
  103. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  104. {
  105. return false;
  106. }
  107. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  108. {
  109. return false;
  110. }
  111. return true;
  112. }
  113. public bool CheckPosParam()
  114. {
  115. dxErrorProvider.ClearErrors();
  116. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  117. {
  118. return false;
  119. }
  120. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  121. {
  122. return false;
  123. }
  124. if (!txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  125. {
  126. return false;
  127. }
  128. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  129. {
  130. return false;
  131. }
  132. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  133. {
  134. return false;
  135. }
  136. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  137. {
  138. return false;
  139. }
  140. if (!txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  141. {
  142. return false;
  143. }
  144. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  145. {
  146. return false;
  147. }
  148. return true;
  149. }
  150. public bool CheckCxLineParam()
  151. {
  152. dxErrorProvider.ClearErrors();
  153. if (!txtCxLocation.CheckLonLat(dxErrorProvider, "测向站"))
  154. {
  155. return false;
  156. }
  157. if (!txtcxFx.CheckDouble(dxErrorProvider, "测向方向值"))
  158. {
  159. return false;
  160. }
  161. return true;
  162. }
  163. private void btnDtoLine_Click(object sender, EventArgs e)
  164. {
  165. if (!CheckDtoLineParam()) { return; }
  166. try
  167. {
  168. var MsAnt = txtsatStation.GetLonLat();
  169. var CDBAnt = txtcdbStation.GetLonLat();
  170. var RefGeod = txtRefLocation.GetLonLat();
  171. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  172. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  173. double[] msEph = ucEphXYZMain.EphXYZ();
  174. DtoLineXdOption dtoLineXd = new DtoLineXdOption();
  175. dtoLineXd.MsEph = msEph;
  176. dtoLineXd.MsAnt = MsAnt;
  177. dtoLineXd.CDBAnt = CDBAnt;
  178. dtoLineXd.RefGeod = RefGeod;
  179. dtoLineXd.xdDto = DtoCdb;
  180. dtoLineXd.RefDto = YbMainDto;
  181. dtoLineXd.PosLon = info.PosLon;
  182. dtoLineXd.PosLat = info.PosLat;
  183. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
  184. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.Value.ToString();
  185. var xdDtoLine = DrawDtoLineHelper.DtoLineXd(dtoLineXd);
  186. mapControl1.DrawDtoLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", xdDtoLine);
  187. }
  188. catch (Exception ex)
  189. {
  190. Serilog.Log.Error(ex, $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.ID},SigTime={info.SigTime}");
  191. DxHelper.MsgBoxHelper.ShowWarning($"绘制{info.PosResType.GetEnumDisplayName()}时差线失败,{ex.Message}");
  192. }
  193. }
  194. private async void btnEphCalc_Click(object sender, EventArgs e)
  195. {
  196. dxErrorProvider.ClearErrors();
  197. if (this.sigTime.DateTime == DateTime.MinValue)
  198. {
  199. DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");
  200. return;
  201. }
  202. var sigTime = this.sigTime.DateTime;
  203. try
  204. {
  205. var mainCode = ucEphXYZMain.GetSatCode();
  206. var mainxlInfo = await XlRepository.GetLatestAsync(mainCode, sigTime);
  207. if (mainxlInfo == null)
  208. {
  209. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{mainCode}未找到对应的星历信息,请导入星历");
  210. return;
  211. }
  212. var maineph = EphHelper.Calc(mainxlInfo.TwoLine, sigTime.ToUtc());
  213. ucEphXYZMain.SetXYZ("主星", mainCode, (maineph.X, maineph.Y, maineph.Z), Color.Red);
  214. }
  215. catch (Exception ex)
  216. {
  217. Serilog.Log.Error(ex, $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}");
  218. DxHelper.MsgBoxHelper.ShowError($"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,{ex.Message}");
  219. }
  220. }
  221. private void btnPos_Click(object sender, EventArgs e)
  222. {
  223. if (!CheckPosParam()) { return; }
  224. try
  225. {
  226. var MsAnt = txtsatStation.GetLonLat();
  227. var CDBAnt = txtcdbStation.GetLonLat();
  228. var RefGeod = txtRefLocation.GetLonLat();
  229. var CXStation = txtCxLocation.GetLonLat();
  230. var sigTime = this.sigTime.DateTime;
  231. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  232. var YbMainDto = Convert.ToDouble(this.txtYbMain.Text);
  233. var Fx = Convert.ToDouble(this.txtcxFx.Text);
  234. double[] msEph = ucEphXYZMain.EphXYZ();
  235. var StationRes = new StationRes()
  236. {
  237. SatTxLon = MsAnt[0],
  238. SatTxLat = MsAnt[1],
  239. CdbTxLon = CDBAnt[0],
  240. CdbTxLat = CDBAnt[1],
  241. CxLon = CXStation[0],
  242. CxLat = CXStation[1],
  243. RefLon = RefGeod[0],
  244. RefLat = RefGeod[1],
  245. };
  246. var cgRes = new CgRes()
  247. {
  248. SigTime = sigTime,
  249. DtoCdb = DtoCdb,
  250. YbMainDto = YbMainDto,
  251. MainX = msEph[0],
  252. MainY = msEph[1],
  253. MainZ = msEph[2],
  254. };
  255. var cxRes = new CxRes()
  256. {
  257. SigTime = sigTime,
  258. Fx = Fx,
  259. };
  260. var res = PosApi.X1D1_Pos(cgRes, StationRes, cxRes);
  261. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4} , {res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  262. }
  263. catch (Exception ex)
  264. {
  265. Serilog.Log.Error(ex, $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.ID},SigTime={info.SigTime}");
  266. DxHelper.MsgBoxHelper.ShowWarning($"{info.PosResType.GetEnumDisplayName()}手动定位失败,{ex.Message}");
  267. }
  268. }
  269. private void btnCxLine_Click(object sender, EventArgs e)
  270. {
  271. if (!CheckCxLineParam()) { return; }
  272. try
  273. {
  274. var deg = Convert.ToDouble(this.txtcxFx.Text);//向北顺时针方向为夹角
  275. var cxStation = txtCxLocation.GetLonLat();
  276. double cxLon = cxStation[0];
  277. double cxLat= cxStation[1];
  278. //计算测向站到定位点之间的距离
  279. var km = MapControlEx.CalcLineKm(cxLon, cxLat, info.PosLon, info.PosLat);
  280. var endpoint = MapControlEx.CalcSituation(cxLon, cxLat, deg, (km + 100) * 1000);
  281. List<(double, double)> points = new List<(double, double)>();
  282. points.Add((cxLon, cxLat));
  283. points.Add((endpoint.Item1, endpoint.Item2));
  284. mapControl1.DrawCXLine($"测向线角度:{deg}°\t\n", points, true);
  285. }
  286. catch (Exception ex)
  287. {
  288. Serilog.Log.Error(ex, $"绘制测向线失败.PosID={info.ID},SigTime={info.SigTime}");
  289. DxHelper.MsgBoxHelper.ShowWarning($"绘制测向线失败,{ex.Message}");
  290. }
  291. }
  292. }
  293. }