X2D1DTOParamEditor.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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.Configuration;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using DW5S.KxcApi;
  15. using DW5S.DTO;
  16. using DW5S.Entity;
  17. using DW5S.Repostory;
  18. using Serilog;
  19. using DW5S.Service;
  20. using DW5S.ViewModel;
  21. namespace DW5S.App.EditForms
  22. {
  23. public partial class X2D1DTOParamEditor : DevExpress.XtraEditors.XtraUserControl
  24. {
  25. private MapControl mapControl1;
  26. private PosResViewModel info;
  27. private CgRes cg;
  28. private List<SatInfo> listSat;
  29. public X2D1DTOParamEditor(PosResViewModel info, MapControl mapControl)
  30. {
  31. InitializeComponent();
  32. this.info = info;
  33. itemSigTime.Text = $"{itemSigTime.Text}";
  34. this.layoutControl1.UseDefault();
  35. txtSigTime.UseDefault();
  36. this.Text = $"{info.PosResType.GetEnumDisplayName()}时差参数";
  37. this.listSat = new List<SatInfo>();
  38. this.mapControl1 = mapControl;
  39. }
  40. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  41. {
  42. this.layoutControl1.BestFit();
  43. StationRes station = null;
  44. var unitOfWork = IocContainer.UnitOfWork;
  45. var repsSat = unitOfWork.Of<SatInfo>();
  46. listSat.AddRange(await repsSat.GetAllAsync());
  47. var repsPos = IocContainer.UnitOfWork.OfLong<PosRes>();
  48. var pos = await repsPos.GetByIdAsync(this.info.Id);
  49. var repsCg = unitOfWork.OfLong<CgRes>();
  50. cg = await repsCg.FirstOrDefaultAsync(m => m.Id == pos.CgResID);
  51. var repsStation = unitOfWork.OfLong<StationRes>();
  52. station = await repsStation.FirstOrDefaultAsync(m => m.Id == pos.StationResID);
  53. if (cg != null)
  54. {
  55. //if (info.PosResType == EnumPosResType.X2D1NoRef)
  56. //{
  57. // cg.Dto1 = 6348.6030;
  58. // cg.DtoCdb = 246616.0330;
  59. // cg.MainX = 11265194.9906;
  60. // cg.MainY = 40486056.6399;
  61. // cg.MainZ = -2055810.5412;
  62. // cg.Adja1X = 25525328.3455;
  63. // cg.Adja1Y = 33539987.1755;
  64. // cg.Adja1Z = -49504.0378;
  65. //}
  66. this.txtDtoSx.Text = $"{cg.Dto1}";
  67. this.txtDtoCdb.Text = cg.Dto2.HasValue? $"{cg.Dto2.Value}":"0";
  68. if (info.PosResType == EnumPosResType.X2D1)
  69. {
  70. this.txtYbMain.Text = cg.RefYbDto1.HasValue? $"{cg.RefYbDto1}" : "0";
  71. this.txtYbAdja.Text =cg.RefYbDto2.HasValue? $"{cg.RefYbDto2}" : "0";
  72. }
  73. this.txtSigTime.EditValue = info.SigTime;
  74. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (cg.MainX, cg.MainY, cg.MainZ), Color.Black);
  75. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (cg.Adja1X, cg.Adja1Y, cg.Adja1Z), Color.Black);
  76. }
  77. if (station != null)
  78. {
  79. //if (info.PosResType == EnumPosResType.X2D1NoRef)
  80. //{
  81. // station.SatTxLon = 45;
  82. // station.SatTxLat =20;
  83. // station.CdbTxLon = 45;
  84. // station.CdbTxLat = 20;
  85. //}
  86. this.txtsatStation.Text = $"{station.SatTxLon},{station.SatTxLat}";
  87. this.txtcdbStation.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
  88. this.txtRefLocation.Text = $"{station.RefLon},{station.RefLat}";
  89. }
  90. if (info.PosResType == EnumPosResType.X2D1NoRef)
  91. {
  92. txtYbMain.Properties.ReadOnly = true;
  93. txtYbAdja.Properties.ReadOnly = true;
  94. txtRefLocation.Properties.ReadOnly = true;
  95. this.txtRefLocation.Text = $"{0},{0}";
  96. }
  97. //double tarLon = 122.88, tarLat = 31.29;
  98. //double recLon = 118.5, recLat = 32.1;
  99. //double refLon = 121, refLat = 30;
  100. //double cdbLon = 122, cdbLat = 30;
  101. //var refEcef = PhysicsHelper.GeoToEcef((refLon, refLat, 0));
  102. //var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  103. //var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  104. //var cdbEcef = PhysicsHelper.GeoToEcef((cdbLon, cdbLat, 0));
  105. //var xl1 = (-41338971.25, 6141819.55, 5504123.22);
  106. //var dt1 = PhysicsHelper.Dto(tarEcef, xl1, recEcef);
  107. //var dt2 = PhysicsHelper.Dto(tarEcef, cdbEcef);
  108. //var dto1 = dt1 - dt2;
  109. //var dt3 = PhysicsHelper.Dto(refEcef, xl1, recEcef);
  110. //var dto2 = dt3 - 0;
  111. }
  112. public bool CheckParam()
  113. {
  114. dxErrorProvider.ClearErrors();
  115. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  116. {
  117. return false;
  118. }
  119. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  120. {
  121. return false;
  122. }
  123. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text) && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  124. {
  125. return false;
  126. }
  127. if (!txtDtoSx.CheckDouble(dxErrorProvider, "双星时差"))
  128. {
  129. return false;
  130. }
  131. if (!txtDtoCdb.CheckDouble(dxErrorProvider, "主星超短时差"))
  132. {
  133. return false;
  134. }
  135. if (!string.IsNullOrWhiteSpace(txtYbMain.Text) && !txtYbMain.CheckDouble(dxErrorProvider, "样本主星时差"))
  136. {
  137. return false;
  138. }
  139. if (!string.IsNullOrWhiteSpace(txtYbAdja.Text) && !txtYbAdja.CheckDouble(dxErrorProvider, "样本邻星时差"))
  140. {
  141. return false;
  142. }
  143. if (!ucEphXYZMain.CheckEphXYZ(dxErrorProvider))
  144. {
  145. return false;
  146. }
  147. if (!ucEphXYZAdaj.CheckEphXYZ(dxErrorProvider))
  148. {
  149. return false;
  150. }
  151. return true;
  152. }
  153. private void btnDtoLine_Click(object sender, EventArgs e)
  154. {
  155. if (!CheckParam()) { return; }
  156. bool isRef = false;
  157. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  158. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  159. && !string.IsNullOrWhiteSpace(txtYbAdja.Text))
  160. {
  161. isRef = true;
  162. }
  163. try
  164. {
  165. var MsAnt = txtsatStation.GetLonLat();
  166. var CDBAnt = txtcdbStation.GetLonLat();
  167. var RefGeod = isRef ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  168. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  169. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  170. var YbMainDto = isRef ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  171. var YbAdja1Dto = isRef ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  172. double[] msEph = ucEphXYZMain.EphXYZ();
  173. double[] NsEph = ucEphXYZAdaj.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. DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
  184. twoStartOption.MsEph = msEph;
  185. twoStartOption.NsEph = NsEph;
  186. twoStartOption.MsAnt = MsAnt;
  187. twoStartOption.NsAnt = MsAnt;
  188. twoStartOption.RefGeod = RefGeod;
  189. twoStartOption.TargetDto = DtoSx;
  190. twoStartOption.RefDto = YbMainDto - YbAdja1Dto;
  191. twoStartOption.PosLon = info.PosLon;
  192. twoStartOption.PosLat = info.PosLat;
  193. var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode)?.Sat;
  194. if (string.IsNullOrWhiteSpace(msat)) msat = cg.MainCode.ToString();
  195. var nsat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code)?.Sat;
  196. if (string.IsNullOrWhiteSpace(nsat)) nsat = cg.Adja1Code.ToString();
  197. if (isRef)
  198. {
  199. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNew(dtoLineXd);
  200. List<MapPolyline> polylines = new List<MapPolyline>();
  201. foreach (var dtoLine in xdDtoLine)
  202. {
  203. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]带参时差线", dtoLine.dtoLinePoints, true);
  204. if (mapline == null)
  205. {
  206. continue;
  207. }
  208. polylines.Add(mapline);
  209. }
  210. mapControl1.DrawDtoLine(polylines);
  211. var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
  212. mapControl1.DrawDtoLine($"[{msat},{nsat}]带参时差线", tsDtoLine);
  213. }
  214. else
  215. {
  216. var xdDtoLine = DrawDtoLineHelper.DtoLineXdNoRefNew(dtoLineXd);
  217. List<MapPolyline> polylines = new List<MapPolyline>();
  218. foreach (var dtoLine in xdDtoLine)
  219. {
  220. var mapline = mapControl1.GetLine($"[{msat},超短{CDBAnt[0]}°]无参时差线", dtoLine.dtoLinePoints, true);
  221. if (mapline == null)
  222. {
  223. continue;
  224. }
  225. polylines.Add(mapline);
  226. }
  227. mapControl1.DrawDtoLine(polylines);
  228. var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
  229. mapControl1.DrawDtoLine($"[{msat},{nsat}]无参时差线", tsDtoLine);
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. string msg = $"绘制{info.PosResType.GetEnumDisplayName()}时差线失败.PosID={info.Id},SigTime={info.SigTime}";
  235. IocContainer.Logger.Error(ex, msg);
  236. DxHelper.MsgBoxHelper.ShowError(msg);
  237. }
  238. }
  239. private async void btnEphCalc_Click(object sender, EventArgs e)
  240. {
  241. dxErrorProvider.ClearErrors();
  242. if (this.txtSigTime.DateTime == DateTime.MinValue)
  243. {
  244. dxErrorProvider.SetError(txtSigTime, "信号时间不能为空!");
  245. return;
  246. }
  247. var sigTime = this.txtSigTime.DateTime;
  248. try
  249. {
  250. var unitOfWork = IocContainer.UnitOfWork;
  251. var repsXl = unitOfWork.Of<XlInfo>() as XlRepository;
  252. var mainxlInfo = await repsXl.GetLatestAsync(cg.MainCode, sigTime);
  253. if (mainxlInfo == null)
  254. {
  255. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode}未找到对应的星历信息,请导入星历");
  256. return;
  257. }
  258. var XlCalcDto = new XlCalcDto() { tleStr = mainxlInfo.TwoLine, SigTime = sigTime };
  259. var maineph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  260. ucEphXYZMain.SetXYZ("主星", cg.MainCode, (maineph.data.X, maineph.data.Y, maineph.data.Z), Color.Red);
  261. var adjaxlInfo = await repsXl.GetLatestAsync(cg.Adja1Code, sigTime);
  262. if (adjaxlInfo == null)
  263. {
  264. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.Adja1Code}未找到对应的星历信息,请导入星历");
  265. return;
  266. }
  267. XlCalcDto = new XlCalcDto() { tleStr = adjaxlInfo.TwoLine, SigTime = sigTime };
  268. var adjaeph = await HttpHelper.PostRequestAsync<SatEphResDto>(SysConfig.GetUrl("Xl/Calc"), XlCalcDto);
  269. ucEphXYZAdaj.SetXYZ("邻星", cg.Adja1Code, (adjaeph.data.X, adjaeph.data.Y, adjaeph.data.Z), Color.Red);
  270. }
  271. catch (Exception ex)
  272. {
  273. string msg = $"手动推算{info.PosResType.GetEnumDisplayName()}星历失败,SigTime={sigTime}";
  274. IocContainer.Logger.Error(ex, msg);
  275. DxHelper.MsgBoxHelper.ShowError(msg);
  276. }
  277. }
  278. private void btnPos_Click(object sender, EventArgs e)
  279. {
  280. if (!CheckParam()) { return; }
  281. txtPosRes.Text = " ";
  282. bool isRef = false;
  283. if (!string.IsNullOrWhiteSpace(txtRefLocation.Text)
  284. && !string.IsNullOrWhiteSpace(txtYbMain.Text)
  285. && !string.IsNullOrWhiteSpace(txtYbAdja.Text))
  286. {
  287. isRef = true;
  288. }
  289. try
  290. {
  291. var MsAnt = txtsatStation.GetLonLat();
  292. var CDBAnt = txtcdbStation.GetLonLat();
  293. var RefGeod = isRef ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  294. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  295. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  296. var YbMainDto = isRef ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  297. var YbAdja1Dto = isRef ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  298. double[] msEph = ucEphXYZMain.EphXYZ();
  299. double[] nsEph = ucEphXYZAdaj.EphXYZ();
  300. var sigTime = txtSigTime.DateTime;
  301. var StationRes = new StationRes()
  302. {
  303. SatTxLon = MsAnt[0],
  304. SatTxLat = MsAnt[1],
  305. CdbTxLon = CDBAnt[0],
  306. CdbTxLat = CDBAnt[1],
  307. RefLon = RefGeod[0],
  308. RefLat = RefGeod[1],
  309. };
  310. if (!isRef)
  311. {
  312. var cgRes = new CgRes()
  313. {
  314. Dto1 = DtoSx,
  315. Snr1 = 20,
  316. Dto2 = DtoCdb,
  317. Snr2 = 20,
  318. MainX = msEph[0],
  319. MainY = msEph[1],
  320. MainZ = msEph[2],
  321. Adja1X = nsEph[0],
  322. Adja1Y = nsEph[1],
  323. Adja1Z = nsEph[2],
  324. };
  325. double[] res;
  326. //res = PosApi.X2D1_PosNoRef(cgRes, StationRes, dto.CalcConfidence);
  327. res = PosApi.X2D1_PosNoRef_ZL(cgRes, StationRes, false);
  328. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  329. }
  330. else
  331. {
  332. var cgRes = new CgRes()
  333. {
  334. Dto1 = DtoSx,
  335. Snr1 = 20,
  336. Dto2 = DtoCdb,
  337. Snr2 = 20,
  338. RefYbDto1 = YbMainDto,
  339. RefYbDto2 = YbAdja1Dto,
  340. MainX = msEph[0],
  341. MainY = msEph[1],
  342. MainZ = msEph[2],
  343. Adja1X = nsEph[0],
  344. Adja1Y = nsEph[1],
  345. Adja1Z = nsEph[2],
  346. };
  347. var res = PosApi.X2D1_Pos(cgRes, StationRes, false);
  348. this.txtPosRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f4},{res[1]:f4}] 镜像点:[{res[3]:f4},{res[4]:f4}]";
  349. }
  350. }
  351. catch (Exception ex)
  352. {
  353. string msg = $"{info.PosResType.GetEnumDisplayName()}手动定位失败.PosID={info.Id},SigTime={info.SigTime}";
  354. IocContainer.Logger.Error(ex, msg);
  355. DxHelper.MsgBoxHelper.ShowError(msg);
  356. }
  357. }
  358. }
  359. }