Răsfoiți Sursa

测试时频差线正确性

wyq 1 an în urmă
părinte
comite
b2175be907

+ 114 - 11
XdCxRhDW.App/UserControl/CtrlHome.cs

@@ -684,7 +684,9 @@ namespace XdCxRhDW.App.UserControl
                 case EnumPosResType.X2Dfo:
                     DrawX3toLine(item);
                     break;
-
+                case EnumPosResType.X3NoRef:
+                    DrawX3NoReftoLine(item);
+                    break;
                 default:
                     break;
             }
@@ -760,7 +762,7 @@ namespace XdCxRhDW.App.UserControl
                     twoStartOption.RefDto = cg.YbMainDto.Value - cg.YbAdja1Dto.Value;
                     twoStartOption.PosLon = item.PosLon;
                     twoStartOption.PosLat = item.PosLat;
-                    var tsDtoLine = DrawDtoLineHelper.DtoLineXDTwoStart(twoStartOption);
+                    var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
                     string nsat = string.Empty;
                     if (cg.Adja1Code.HasValue)
                     {
@@ -817,10 +819,18 @@ namespace XdCxRhDW.App.UserControl
                 twoStartOption.RefDto = cg.YbMainDto.Value - cg.YbAdja1Dto.Value;
                 twoStartOption.PosLon = item.PosLon;
                 twoStartOption.PosLat = item.PosLat;
-
-                var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
-                var tsDtoLine = DrawDtoLineHelper.DtoLineXDTwoStart(twoStartOption);
-                mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat}]时差线", tsDtoLine);
+                string msat = string.Empty;
+                string ad1sat = string.Empty;
+                if (cg.MainCode.HasValue)
+                {
+                    msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
+                }
+                if (cg.Adja1Code.HasValue)
+                {
+                    ad1sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
+                }
+                var tsDtoLine = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
+                mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad1sat}]时差线", tsDtoLine);
                 if (item.PosResType == EnumPosResType.X3)
                 {
                     twoStartOption.NsEph = new double[] { cg.Adja2X.Value, cg.Adja2Y.Value, cg.Adja2Z.Value, 0, 0, 0 };
@@ -828,8 +838,13 @@ namespace XdCxRhDW.App.UserControl
                     twoStartOption.RefDto = cg.YbMainDto.Value - cg.YbAdja2Dto.Value;
                     twoStartOption.PosLon = item.PosLon;
                     twoStartOption.PosLat = item.PosLat;
-                    var tsDtoLine1 = DrawDtoLineHelper.DtoLineXDTwoStart(twoStartOption);
-                    mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat}]时差线", tsDtoLine1);
+                    var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XStart(twoStartOption);
+                    string ad2sat = string.Empty;
+                    if (cg.Adja2Code.HasValue)
+                    {
+                        ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
+                    }
+                    mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad2sat}]时差线", tsDtoLine1);
                 }
             }
             catch (Exception ex)
@@ -838,6 +853,80 @@ namespace XdCxRhDW.App.UserControl
                 DxHelper.MsgBoxHelper.ShowWarning($"绘制{item.PosResType.GetEnumDisplayName()}时差线失败,失败信息:{ex.Message}");
             }
         }
+        private async void DrawX3NoReftoLine(PosRes item)
+        {
+            try
+            {
+                StationRes station;
+                List<SatInfo> listSat = new List<SatInfo>();
+                CgRes cg;
+                using (RHDWContext db = new RHDWContext())
+                {
+
+                    listSat = db.SatInfos.ToList();
+                    cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
+                }
+                if (cg == null)
+                {
+                    DxHelper.MsgBoxHelper.ShowWarning($"未找到定位相关的计算[{item.CgResID}]信息");
+                    return;
+                }
+                if (station == null)
+                {
+                    DxHelper.MsgBoxHelper.ShowWarning($"站点信息为空!");
+                    return;
+                }
+
+                if (station.RefLon == 0 || station.RefLat == 0)
+                {
+                    DxHelper.MsgBoxHelper.ShowWarning($"参考站信息为空!");
+                    return;
+                }
+
+                DtoLineTwoStartOption twoStartOption = new DtoLineTwoStartOption();
+                twoStartOption.MsEph = new double[] { cg.MainX.Value, cg.MainY.Value, cg.MainZ.Value, 0, 0, 0 };
+                twoStartOption.NsEph = new double[] { cg.Adja1X.Value, cg.Adja1Y.Value, cg.Adja1Z.Value, 0, 0, 0 };
+                twoStartOption.MsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
+                twoStartOption.NsAnt = new double[] { station.SatTxLon, station.SatTxLat, 0 };
+                twoStartOption.RefGeod = new double[] { 0, 0, 0 };
+                twoStartOption.TargetDto = cg.Dto1.Value;
+                twoStartOption.RefDto = 0;
+                twoStartOption.PosLon = item.PosLon;
+                twoStartOption.PosLat = item.PosLat;
+                string msat = string.Empty;
+                string ad1sat = string.Empty;
+                if (cg.MainCode.HasValue)
+                {
+                    msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
+                }
+                if (cg.Adja1Code.HasValue)
+                {
+                    ad1sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
+                }
+                var tsDtoLine = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
+                mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad1sat}]时差线", tsDtoLine);
+
+                twoStartOption.NsEph = new double[] { cg.Adja2X.Value, cg.Adja2Y.Value, cg.Adja2Z.Value, 0, 0, 0 };
+                twoStartOption.TargetDto = cg.Dto2.Value;
+                twoStartOption.RefDto = 0;
+                twoStartOption.PosLon = item.PosLon;
+                twoStartOption.PosLat = item.PosLat;
+                var tsDtoLine1 = DrawDtoLineHelper.DtoLine2XNoRefStart(twoStartOption);
+                string ad2sat = string.Empty;
+                if (cg.Adja2Code.HasValue)
+                {
+                    ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
+                }
+                mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad2sat}]时差线", tsDtoLine1);
+
+            }
+            catch (Exception ex)
+            {
+                Serilog.Log.Error($"绘制{item.PosResType.GetEnumDisplayName()}时差线失败", ex);
+                DxHelper.MsgBoxHelper.ShowWarning($"绘制{item.PosResType.GetEnumDisplayName()}时差线失败,失败信息:{ex.Message}");
+            }
+        }
         private void DrawDfoLine(PosRes item)
         {
             switch (item.PosResType)
@@ -900,8 +989,17 @@ namespace XdCxRhDW.App.UserControl
                 twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja1Dfo.Value;
                 var tsDtoLine = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
 
-                var msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat;
-                mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja1X.Value)?.Sat}]频差线", tsDtoLine);
+                string msat = string.Empty;
+                string ad1sat = string.Empty;
+                if (cg.MainCode.HasValue)
+                {
+                    msat = listSat.FirstOrDefault(m => m.SatCode == cg.MainCode.Value)?.Sat; ;
+                }
+                if (cg.Adja1Code.HasValue)
+                {
+                    ad1sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja1Code.Value)?.Sat;
+                }
+                mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad1sat}]频差线", tsDtoLine);
 
                 if (item.PosResType == EnumPosResType.X3TwoDfo)
                 {
@@ -909,7 +1007,12 @@ namespace XdCxRhDW.App.UserControl
                     twoStartOption.TargetDfo = cg.Dfo2.Value;
                     twoStartOption.RefDfo = cg.YbMainDfo.Value - cg.YbAdja2Dfo.Value;
                     var tsDtoLine1 = DrawDfoLineHelper.DfoLineTwoStart(twoStartOption);
-                    mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat}]频差线", tsDtoLine1);
+                    string ad2sat = string.Empty;
+                    if (cg.Adja2Code.HasValue)
+                    {
+                        ad2sat = listSat.FirstOrDefault(m => m.SatCode == cg.Adja2Code.Value)?.Sat;
+                    }
+                    mapControl1.DrawDtoPonit($"{item.PosResType.GetEnumDisplayName()}[{msat},{ad2sat}]频差线", tsDtoLine1);
                 }
             }
             catch (Exception ex)

+ 109 - 4
XdCxRhDW.Core/Api/时差线/DrawDtoLineHelper.cs

@@ -5,19 +5,38 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Runtime.InteropServices;
+using System.Text;
+using XdCxRhDW.App.Api;
 
 namespace XdCxRhDW.Core.Api
 {
     public class DrawDtoLineHelper
     {
+
         private const string XdtsDll = @"Api\时差线\Positioning.dll";
 
-        [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOA", CallingConvention = CallingConvention.Cdecl)]//星地时差线
+        [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOA", CallingConvention = CallingConvention.Cdecl)]//高轨双星有参时差线
         public extern static void CurveByTwoTDOA(double[] main_sat_pos, double[] neigh_sat_pos, double[] rec1_pos, double[] rec2_pos, double[] ref_pos, double[] Zone,
       double target_dto, double ref_dto, out IntPtr LOP_Value, ref int LOP_Len);
 
-        private const string exeName = "XingDiSCX.exe";
+        /*
+	双星时差线-无参
+	LOP_Value 返回值 结构参考DTO_Plot
+	LOP_Len*3为LOP_Value的长度
+	*/
+        [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOAWithNoRef", CallingConvention = CallingConvention.Cdecl)]//高轨双星无参时差线
+        public extern static void CurveByTwoTDOAWithNoRef(double[] main_sat_pos, double[] neigh_sat_pos, double[] rec1_pos, double[] rec2_pos,
+            double[] Zone, double target_dto, out IntPtr LOP_Value, ref int LOP_Len);
+
+
+        [DllImport(XdtsDll, CallingConvention = CallingConvention.Cdecl)]
+        public static extern void Destory(IntPtr val);
+
+        private const string exeName = "XingDiSCX.exe";//星地时差线
         private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
+
+
+        private const string locexeName = "locow.exe";
         /// <summary>
         /// 星地时差线
         /// </summary>
@@ -92,11 +111,11 @@ namespace XdCxRhDW.Core.Api
         }
 
         /// <summary>
-        /// 星地双星时差线
+        /// 高轨双星时差线
         /// </summary>
         /// <param name="opt"></param>
         /// <returns></returns>
-        public static IEnumerable<(double lon, double lat)> DtoLineXDTwoStart(DtoLineTwoStartOption opt)
+        public static IEnumerable<(double lon, double lat)> DtoLine2XStart(DtoLineTwoStartOption opt)
         {
 
             List<DtoLinePoint> list = new List<DtoLinePoint>();
@@ -122,10 +141,96 @@ namespace XdCxRhDW.Core.Api
 
                 list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
             }
+            Destory(LOP_ValuePtr);
             var Lines = list.Select(p => (p.Lon, p.Lat));
             return Lines;
         }
 
+        public static IEnumerable<(double lon, double lat)> DtoLine2XNoRefStart(DtoLineTwoStartOption opt)
+        {
+
+            List<DtoLinePoint> list = new List<DtoLinePoint>();
+            IntPtr LOP_ValuePtr;
+            int LOP_Len = 0;
+            CurveByTwoTDOAWithNoRef(
+                opt.MsEph,
+                 opt.NsEph,
+                 opt.MsAnt,
+                 opt.NsAnt,
+                 zone,
+                opt.TargetDto * 1e-6, out LOP_ValuePtr, ref LOP_Len);
+
+            double[] LOP_Value = new double[LOP_Len * 3];
+            if (LOP_Len > 0)
+            {
+                Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
+
+                list = OutputHelper.WriteDtoLine(LOP_Value, LOP_Len);
+            }
+            Destory(LOP_ValuePtr);
+            var Lines = list.Select(p => (p.Lon, p.Lat));
+            return Lines;
+        }
+
+        /// <summary>
+        /// 高轨双星频差线
+        /// </summary>
+        /// <param name="opt"></param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
+        public static IEnumerable<(double lon, double lat)> DtoLineTwoStart(DtoLineTwoStartOption opt)
+        {
+            List<DfoLinePoint> list = new List<DfoLinePoint>();
+
+            string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\频差线");
+            if (string.IsNullOrWhiteSpace(exePath))
+                throw new Exception($"请先调用SetExePath指定{locexeName}进程所在路径,支持相对路径");
+            if (!Directory.Exists(exePath))
+                throw new Exception($"路径[{exePath}]不存在");
+            var exeFile = Path.Combine(exePath, locexeName);
+            if (!File.Exists(exeFile))
+                throw new Exception($"文件[{exeFile}]不存在");
+            List<string> arguments = new List<string>();
+            arguments.Add("dtoline");
+            arguments.Add($"{opt.TargetDto}");
+            arguments.Add($"--rec1 {opt.MsAnt[0]} {opt.MsAnt[1]} 0");
+            arguments.Add($"--rec2 {opt.NsAnt[0]} {opt.NsAnt[1]} 0");
+            arguments.Add($"--eph1 {opt.MsEph[0]} {opt.MsEph[1]} {opt.MsEph[2]}");
+            arguments.Add($"--eph2 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]}");
+            arguments.Add($"--refdt {opt.RefDto}");
+            arguments.Add($"--reflla {opt.RefGeod[0]} {opt.RefGeod[1]} 0");
+            Process p = new Process();
+            p.StartInfo.WorkingDirectory = exePath;
+            p.StartInfo.FileName = exeFile;
+            p.StartInfo.Arguments = string.Join(" ", arguments);
+            p.StartInfo.CreateNoWindow = true;
+            p.StartInfo.RedirectStandardError = true;
+            p.StartInfo.RedirectStandardOutput = true;
+            p.StartInfo.UseShellExecute = false;
+            StringBuilder sb = new StringBuilder();
+            p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
+
+            p.Start();
+            p.BeginOutputReadLine();
+            p.WaitForExit();
+            if (string.IsNullOrWhiteSpace(sb.ToString()))
+            {
+                throw new Exception("计算时差线出现未知错误!");
+            }
+            var array = sb.ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+
+            foreach (var item in array)
+            {
+                var strs = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+                DfoLinePoint point = new DfoLinePoint();
+                point.Lon = Convert.ToDouble(strs[0]);
+                point.Lat = Convert.ToDouble(strs[1]);
+                list.Add(point);
+            }
+            var Lines = list.Select(s => (s.Lon, s.Lat));
+            return Lines;
+        }
+
         private static IEnumerable<(double lon, double lat)> ParseResult(IntPtr LOP_ValuePtr, int LOP_Len)
         {
             List<DtoLinePoint> list = new List<DtoLinePoint>();

+ 25 - 27
XdCxRhDW.Core/Api/频差线/DrawDfoLineHelper.cs

@@ -5,12 +5,13 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Runtime.InteropServices;
+using System.Text;
 
 namespace XdCxRhDW.App.Api
 {
     public class DrawDfoLineHelper
     {
-      
+
         private const string exeName = "locow.exe";
         private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
         /// <summary>
@@ -34,18 +35,16 @@ namespace XdCxRhDW.App.Api
             List<string> arguments = new List<string>();
             arguments.Add("dfoline");
             arguments.Add($"{opt.TargetDfo}");
-            arguments.Add($"{opt.Freq * 1e6}");
-            arguments.Add($"{opt.Turn1 * 1e6}");
-            arguments.Add($"{opt.Turn2 * 1e6}");
+            arguments.Add($"{opt.Freq * 1e-6}");
+            arguments.Add($"{opt.Turn1 * 1e-6}");
+            arguments.Add($"{opt.Turn2 * 1e-6}");
             arguments.Add($"--rec1 {opt.MsAnt[0]} {opt.MsAnt[1]} 0");
-            arguments.Add($"--rec1 {opt.NsAnt[0]} {opt.NsAnt[1]} 0");
-
+            arguments.Add($"--rec2 {opt.NsAnt[0]} {opt.NsAnt[1]} 0");
             arguments.Add($"--eph1 {opt.MsEph[0]} {opt.MsEph[1]} {opt.MsEph[2]} {opt.MsEph[3]} {opt.MsEph[4]} {opt.MsEph[5]}");
-            arguments.Add($"--eph1 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]} {opt.NsEph[3]} {opt.NsEph[4]} {opt.NsEph[5]}");
+            arguments.Add($"--eph2 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]} {opt.NsEph[3]} {opt.NsEph[4]} {opt.NsEph[5]}");
             arguments.Add($"--refdf {opt.RefDfo}");
-            arguments.Add($"--reffreq {opt.RefFreq * 1e6}");
-
-            arguments.Add($"--reflla {opt.RefGeod[0]} {opt.RefGeod[0]} 0");
+            arguments.Add($"--reffreq {opt.RefFreq * 1e-6}");
+            arguments.Add($"--reflla {opt.RefGeod[0]} {opt.RefGeod[1]} 0");
             Process p = new Process();
             p.StartInfo.WorkingDirectory = exePath;
             p.StartInfo.FileName = exeFile;
@@ -54,34 +53,33 @@ namespace XdCxRhDW.App.Api
             p.StartInfo.RedirectStandardError = true;
             p.StartInfo.RedirectStandardOutput = true;
             p.StartInfo.UseShellExecute = false;
+            StringBuilder sb = new StringBuilder();
+            p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
+
             p.Start();
-            var succeed = p.WaitForExit(10000);
-            if (!succeed)
-            {
-                throw new Exception($"进程[{exeName}]超时未完成!");
-            }
-            string result = p.StandardOutput.ReadToEnd();
-            if (string.IsNullOrWhiteSpace(result))
+            p.BeginOutputReadLine();
+            p.WaitForExit();
+            if (string.IsNullOrWhiteSpace(sb.ToString()))
             {
                 throw new Exception("计算频差线出现未知错误!");
             }
-            var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
-            if (array[0] == "1")
+            var array = sb.ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+
+            foreach (var item in array)
             {
-                throw new Exception(array[1]);
+                var strs = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+                DfoLinePoint point = new DfoLinePoint();
+                point.Lon = Convert.ToDouble(strs[0]);
+                point.Lat = Convert.ToDouble(strs[1]);
+                list.Add(point);
             }
-            //if (File.Exists(file))
-            //{
-            //    var dtostr = File.ReadAllText(file);
-            //    list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DfoLinePoint>>(dtostr);
-            //}
             var Lines = list.Select(s => (s.Lon, s.Lat));
             return Lines;
         }
 
-        
 
-       
+
+
 
     }
 }