X2D1PosParamEditor.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.Security.Policy;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows.Documents;
  22. using System.Windows.Forms;
  23. using System.Windows.Input;
  24. using XdCxRhDw.Dto;
  25. using XdCxRhDW.App.App.Properties;
  26. using XdCxRhDW.Core;
  27. using XdCxRhDW.Core.Api;
  28. using XdCxRhDW.Repostory;
  29. using XdCxRhDW.Repostory.EFContext;
  30. using XdCxRhDW.Repostory.Model;
  31. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  32. namespace XdCxRhDW.App.EditForms
  33. {
  34. public partial class X2D1PosParamEditor : DevExpress.XtraEditors.XtraUserControl
  35. {
  36. private List<SatInfo> listSat;
  37. private PosRes info;
  38. private CgRes cg;
  39. private SysSetings settings = new SysSetings();
  40. public X2D1PosParamEditor(PosRes info)
  41. {
  42. InitializeComponent();
  43. this.Text = $"{info.PosResType.GetEnumDisplayName()}手动定位";
  44. this.info = info;
  45. this.listSat = new List<SatInfo>();
  46. txtsatStation.EditValueChanged += TxtsatStation_EditValueChanged;
  47. txtcdbStation.EditValueChanged += TxtcdbStation_EditValueChanged;
  48. txtRefLocation.EditValueChanged += TxtRefLocation_EditValueChanged;
  49. }
  50. private void TxtRefLocation_EditValueChanged(object sender, EventArgs e)
  51. {
  52. txtRefLocation.CheckLonLat(dxErrorProvider, "参考站");
  53. }
  54. private void TxtcdbStation_EditValueChanged(object sender, EventArgs e)
  55. {
  56. txtcdbStation.CheckLonLat(dxErrorProvider, "超短波");
  57. }
  58. private void TxtsatStation_EditValueChanged(object sender, EventArgs e)
  59. {
  60. txtsatStation.CheckLonLat(dxErrorProvider, "接收站");
  61. }
  62. private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
  63. {
  64. StationRes station;
  65. using (RHDWContext db = new RHDWContext())
  66. {
  67. listSat = await db.SatInfos.ToListAsync();
  68. settings = await db.SysSetings.FirstOrDefaultAsync();
  69. }
  70. using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
  71. {
  72. cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
  73. station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
  74. }
  75. if (cg != null)
  76. {
  77. this.txtDtoSx.Text = $"{cg.Dto1.Value:f3}";
  78. this.txtDtoCdb.Text = $"{cg.DtoCdb.Value:f3}";
  79. if (info.PosResType == EnumPosResType.X2D1)
  80. {
  81. this.txtYbMain.Text = $"{cg.YbMainDto.Value:f3}";
  82. this.txtYbAdja.Text = $"{cg.YbAdja1Dto.Value:f3}";
  83. }
  84. this.txtSigTime.EditValue = info.SigTime;
  85. this.txtMainX.Text = $"{cg.MainX.Value:f3}";
  86. this.txtMainY.Text = $"{cg.MainY.Value:f3}";
  87. this.txtMainZ.Text = $"{cg.MainZ.Value:f3}";
  88. this.txtAdjaX.Text = $"{cg.Adja1X.Value:f3}";
  89. this.txtAdjaY.Text = $"{cg.Adja1Y.Value:f3}";
  90. this.txtAdjaZ.Text = $"{cg.Adja1Z.Value:f3}";
  91. }
  92. if (station != null)
  93. {
  94. this.txtsatStation.Text = $"{station.SatTxLon:f3},{station.SatTxLat:f3}";
  95. this.txtcdbStation.Text = $"{station.CdbTxLon:f3},{station.CdbTxLat:f3}";
  96. this.txtRefLocation.Text = $"{station.RefLon:f3},{station.RefLat:f3}";
  97. }
  98. if (info.PosResType == EnumPosResType.X2D1NoRef)
  99. {
  100. txtYbMain.Properties.ReadOnly = true;
  101. txtYbAdja.Properties.ReadOnly = true;
  102. txtRefLocation.Properties.ReadOnly = true;
  103. this.txtRefLocation.Text = $"{0},{0}";
  104. }
  105. double tarLon = 46, tarLat = 24;
  106. double recLon = 45.9, recLat = 23.9;
  107. var tarEcef = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
  108. var recEcef = PhysicsHelper.GeoToEcef((recLon, recLat, 0));
  109. var xl1Ecef = (cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value);
  110. var xl2Ecef = (cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value);
  111. var dt1 = PhysicsHelper.Dto(tarEcef, xl1Ecef, recEcef);
  112. var dt2 = PhysicsHelper.Dto(tarEcef, xl2Ecef, recEcef);
  113. var dto1 = (dt1 - dt2) * 1e6;
  114. var dt3 = PhysicsHelper.Dto(tarEcef, recEcef);
  115. var dto2 = (dt1 - dt3) * 1e6;
  116. }
  117. public bool CheckParam()
  118. {
  119. if (!txtsatStation.CheckLonLat(dxErrorProvider, "接收站"))
  120. {
  121. return false;
  122. }
  123. if (!txtcdbStation.CheckLonLat(dxErrorProvider, "超短波"))
  124. {
  125. return false;
  126. }
  127. if (info.PosResType == EnumPosResType.X2D1 && !txtRefLocation.CheckLonLat(dxErrorProvider, "参考站"))
  128. {
  129. return false;
  130. }
  131. return true;
  132. }
  133. private async void btnOk_Click(object sender, EventArgs e)
  134. {
  135. if (!CheckParam()) { return; }
  136. lblRes.Text = string.Empty;
  137. try
  138. {
  139. var MsAnt = txtsatStation.GetLonLat();
  140. var CDBAnt = txtcdbStation.GetLonLat();
  141. var RefGeod = info.PosResType == EnumPosResType.X2D1 ? txtRefLocation.GetLonLat() : new double[3] { 0, 0, 0 };
  142. var DtoSx = Convert.ToDouble(this.txtDtoSx.Text);
  143. var DtoCdb = Convert.ToDouble(this.txtDtoCdb.Text);
  144. var YbMainDto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbMain.Text) : 0;
  145. var YbAdja1Dto = info.PosResType == EnumPosResType.X2D1 ? Convert.ToDouble(this.txtYbAdja.Text) : 0;
  146. var MainX = Convert.ToDouble(this.txtMainX.Text);
  147. var MainY = Convert.ToDouble(this.txtMainY.Text);
  148. var MainZ = Convert.ToDouble(this.txtMainZ.Text);
  149. var AdjaX = Convert.ToDouble(this.txtAdjaX.Text);
  150. var AdjaY = Convert.ToDouble(this.txtAdjaY.Text);
  151. var AdjaZ = Convert.ToDouble(this.txtAdjaZ.Text);
  152. double[] msEph = new double[] { MainX, MainY, MainZ, 0, 0, 0 };
  153. double[] NsEph = new double[] { AdjaX, AdjaY, AdjaZ, 0, 0, 0 };
  154. var sigTime = txtSigTime.DateTime;
  155. var StationRes = new StationRes()
  156. {
  157. SatTxLon = MsAnt[0],
  158. SatTxLat = MsAnt[1],
  159. CdbTxLon = CDBAnt[0],
  160. CdbTxLat = CDBAnt[1],
  161. RefLon = RefGeod[0],
  162. RefLat = RefGeod[1],
  163. };
  164. string url = string.Format("http://{0}:{1}/Api/Pos/", IpHelper.GetLocalIp(), settings.HttpPort);
  165. if (info.PosResType == EnumPosResType.X2D1NoRef)
  166. {
  167. url += "PosX2D1NoParAsync";
  168. X2D1NoParPosDto dto = new X2D1NoParPosDto()
  169. {
  170. SigTime = sigTime,
  171. MainCode = cg.MainCode.Value,
  172. AdjaCode = cg.Adja1Code.Value,
  173. SxDto = DtoSx,
  174. XdDto = DtoCdb,
  175. MainX = MainX,
  176. MainY = MainY,
  177. MainZ = MainZ,
  178. AdjaX = AdjaX,
  179. AdjaY = AdjaY,
  180. AdjaZ = AdjaZ,
  181. SatTxLon = MsAnt[0],
  182. SatTxLat = MsAnt[1],
  183. CdbTxLon = CDBAnt[0],
  184. CdbTxLat = CDBAnt[1],
  185. };
  186. var cgRes = new CgRes()
  187. {
  188. SigTime = dto.SigTime,
  189. Dto1 = dto.SxDto,
  190. Dfo1 = dto.SxDfo,
  191. Snr1 = dto.SxSnr,
  192. DtoCdb = dto.XdDto,
  193. DfoCdb = dto.XdDfo,
  194. SnrCdb = dto.XdSnr,
  195. //StationResID = StationRes.ID,
  196. MainCode = dto.MainCode,
  197. Adja1Code = dto.AdjaCode,
  198. //TaskID = runTask.ID,
  199. MainX = dto.MainX,
  200. MainY = dto.MainY,
  201. MainZ = dto.MainZ,
  202. Adja1X = dto.AdjaX,
  203. Adja1Y = dto.AdjaY,
  204. Adja1Z = dto.AdjaZ,
  205. };
  206. var res = PosApi.X2D1_PosNoRef(cgRes, StationRes);
  207. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  208. //var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  209. //if (result.code == 200)
  210. //{
  211. // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  212. //}
  213. }
  214. else
  215. {
  216. url += "PosX2D1Async";
  217. X2D1PosDto dto = new X2D1PosDto()
  218. {
  219. SigTime = sigTime,
  220. MainCode = cg.MainCode.Value,
  221. AdjaCode = cg.Adja1Code.Value,
  222. SxDto = DtoSx,
  223. XdDto = DtoCdb,
  224. MainYbDto = YbMainDto,
  225. AdjaYbDto = YbAdja1Dto,
  226. MainX = MainX,
  227. MainY = MainY,
  228. MainZ = MainZ,
  229. AdjaX = AdjaX,
  230. AdjaY = AdjaY,
  231. AdjaZ = AdjaZ,
  232. SatTxLon = MsAnt[0],
  233. SatTxLat = MsAnt[1],
  234. CdbTxLon = CDBAnt[0],
  235. CdbTxLat = CDBAnt[1],
  236. RefLon = RefGeod[0],
  237. RefLat = RefGeod[1],
  238. };
  239. var cgRes = new CgRes()
  240. {
  241. SigTime = dto.SigTime,
  242. Dto1 = dto.SxDto,
  243. Dfo1 = dto.SxDfo,
  244. Snr1 = dto.SxSnr,
  245. DtoCdb = dto.XdDto,
  246. DfoCdb = dto.XdDfo,
  247. SnrCdb = dto.XdSnr,
  248. YbMainDto = dto.MainYbDto,
  249. YbAdja1Dto = dto.AdjaYbDto,
  250. //StationResID = StationRes.ID,
  251. MainCode = dto.MainCode,
  252. Adja1Code = dto.AdjaCode,
  253. // TaskID = runTask.ID,
  254. MainX = dto.MainX,
  255. MainY = dto.MainY,
  256. MainZ = dto.MainZ,
  257. Adja1X = dto.AdjaX,
  258. Adja1Y = dto.AdjaY,
  259. Adja1Z = dto.AdjaZ,
  260. };
  261. var res = PosApi.X2D1_Pos(cgRes, StationRes);
  262. this.lblRes.Text = $"{info.PosResType.GetEnumDisplayName()}定位点:[{res[0]:f3},{res[1]:f3}] 镜像点:[{res[3]:f3},{res[4]:f3}]";
  263. //var result = await HttpHelper.PostRequestAsync<PosResDto>(url, X2D1PosDto);
  264. //if (result.code == 200)
  265. //{
  266. // lblRes.Text = $"定位结果{result.data.PosLon},{result.data.PosLat}";
  267. //}
  268. }
  269. }
  270. catch (Exception ex)
  271. {
  272. Serilog.Log.Error(ex, $"定位{info.PosResType.GetEnumDisplayName()}失败.PosID={info.ID},SigTime={info.SigTime}");
  273. DxHelper.MsgBoxHelper.ShowWarning($"定位{info.PosResType.GetEnumDisplayName()}失败");
  274. }
  275. }
  276. private async void btnMainXl_Click(object sender, EventArgs e)
  277. {
  278. var xlInfo = await XlCache.GetLatestAsync(cg.MainCode.Value, txtSigTime.DateTime);
  279. if (xlInfo == null)
  280. {
  281. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  282. return;
  283. }
  284. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime };
  285. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  286. var ephMain = await HttpHelper.PostRequestAsync<SatEphDto>(url, XlCalcDto);
  287. this.txtMainX.Text = ephMain.data.X.ToString("f3");
  288. this.txtMainY.Text = ephMain.data.Y.ToString("f3");
  289. this.txtMainZ.Text = ephMain.data.Z.ToString("f3");
  290. }
  291. private async void btnAdjaXl_Click(object sender, EventArgs e)
  292. {
  293. var xlInfo = await XlCache.GetLatestAsync(cg.Adja1Code.Value, txtSigTime.DateTime);
  294. if (xlInfo == null)
  295. {
  296. DxHelper.MsgBoxHelper.ShowWarning($"卫星:{cg.MainCode.Value}未找到对应的星历信息,请导入星历");
  297. return;
  298. }
  299. var XlCalcDto = new XlCalcDto() { tleStr = xlInfo.TwoLine, dt = txtSigTime.DateTime };
  300. string url = string.Format("http://{0}:{1}/Api/Xl/Calc", IpHelper.GetLocalIp(), settings.HttpPort);
  301. var ephAdja = await HttpHelper.PostRequestAsync<SatEphDto>(url, XlCalcDto);
  302. this.txtAdjaX.Text = ephAdja.data.X.ToString("f3");
  303. this.txtAdjaY.Text = ephAdja.data.Y.ToString("f3");
  304. this.txtAdjaZ.Text = ephAdja.data.Z.ToString("f3");
  305. }
  306. }
  307. }