X2D1PosParamEditor.cs 13 KB

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