using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
namespace Ips.Library.Entity
{
public class EphResult
{
///
/// 卫星编号
///
[DisplayName("卫星编号")]
public int SatNum { get; set; }
///
/// 星历时间
///
[DisplayName("星历时间")]
public DateTime Time { get; set; }
///
/// 星历类型
///
[DisplayName("星历类型")]
public EphType EphType { get; set; }
///
/// 位置X
///
[DisplayName("位置X")]
public double X { get; set; }
///
/// 位置Y
///
[DisplayName("位置Y")]
public double Y { get; set; }
///
/// 位置Z
///
[DisplayName("位置Z")]
public double Z { get; set; }
///
/// 速度X
///
[DisplayName("速度X")]
public double Vx { get; set; }
///
/// 速度Y
///
[DisplayName("速度Y")]
public double Vy { get; set; }
///
/// 速度Z
///
[DisplayName("速度Z")]
public double Vz { get; set; }
public EphResult() { }
public EphResult(int satNum, DateTime time, double x, double y, double z, double vx = 0, double vy = 0, double vz = 0)
{
this.SatNum = satNum;
this.Time = time;
this.X = x;
this.Y = y;
this.Z = z;
this.Vx = vx;
this.Vy = vy;
this.Vz = vz;
}
public EphResult(int satNum, EphType ephType, DateTime time, double x, double y, double z, double vx = 0, double vy = 0, double vz = 0)
{
this.SatNum = satNum;
this.EphType = ephType;
this.Time = time;
this.X = x;
this.Y = y;
this.Z = z;
this.Vx = vx;
this.Vy = vy;
this.Vz = vz;
}
public static EphResult FromString(string source)
{
EphResult result = new EphResult();
var items = source.TrimEnd().Split('\t');
int i = 0;
if (items.Length >= 1 && DateTime.TryParseExact(items[i++], "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentUICulture, DateTimeStyles.None, out DateTime timeRes))
{
result.Time = timeRes;
}
if (items.Length >= 3)
{
result.X = double.Parse(items[i++]);
result.Y = double.Parse(items[i++]);
result.Z = double.Parse(items[i++]);
}
if (items.Length >= 6)
{
result.Vx = double.Parse(items[i++]);
result.Vy = double.Parse(items[i++]);
result.Vz = double.Parse(items[i++]);
}
return result;
}
public static EphResult[] FromListString(string result, string itemsep = "")
{
if (string.IsNullOrWhiteSpace(result))
return Array.Empty();
if (string.IsNullOrWhiteSpace(itemsep))
{
itemsep = Environment.NewLine;
}
var items = result.Split(itemsep.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
EphResult[] results = new EphResult[items.Length];
for (int i = 0; i < items.Length; i++)
{
results[i] = EphResult.FromString(items[i]);
}
return results;
}
public double[] GetEphXyz()
{
return new double[] { this.X, this.Y, this.Z, this.Vx, this.Vy, this.Vz };
}
public override string ToString()
{
return $"{SatNum},{Time:yyyy-MM-dd HH:mm:ss},{X},{Y},{Z},{Vx},{Vy},{Vz}";
}
}
}