using System.Runtime.Serialization;
|
using System.Text;
|
|
namespace Eventech.Model
|
{
|
//穿过点的线
|
[DataContract]
|
public class ThroughCurve : ICloneable
|
{
|
#region 构造函数
|
public ThroughCurve() { }
|
public ThroughCurve(string strPara)
|
{
|
if (string.IsNullOrEmpty(strPara))
|
{
|
isNull = true;
|
return;
|
}
|
|
string[] strParas = strPara.Split(',');
|
if (strParas.Count() < 4)
|
{
|
isNull = true;
|
return;
|
}
|
|
DispTension = float.Parse(strParas[0]);
|
IsClosed = bool.Parse(strParas[1]);
|
|
int iPtCount = Convert.ToInt32(strParas[2]);
|
if (iPtCount == 0)
|
{
|
isNull = true;
|
return;
|
}
|
|
PointInfo = new Eventech.Model.FeatPointList();
|
for (int i = 0; i < iPtCount; i++)
|
{//可能只有一个点
|
PointInfo.Add(new Eventech.Model.FeatPoint() { X = Convert.ToDouble(strParas[3 + i * 2]), Y = Convert.ToDouble(strParas[3 + 2 * i + 1]) });
|
}
|
}
|
public ThroughCurve(ThroughCurve rhs)
|
{
|
this.DispTension = rhs.DispTension;
|
this.IsClosed = rhs.IsClosed;
|
this.PointInfo = rhs.PointInfo.Clone();
|
}
|
#endregion
|
|
//显示的张力
|
[DataMember]
|
public float DispTension { get { return _dispTension; } set { _dispTension = value; } }
|
private float _dispTension = 0.5f;
|
|
//是否封闭
|
[DataMember]
|
public bool IsClosed { get { return _isClosed; } set { _isClosed = value; } }
|
public bool _isClosed = false;
|
|
//曲线点参数,存储时不能用拟合参数
|
//(注意可能一个点,两个点,或多个点,两个点就连成直线即可)
|
public Eventech.Model.FeatPointList _pointInfo = null;
|
public Eventech.Model.FeatPointList PointInfo { get { return _pointInfo; } set { _pointInfo = value; } }
|
|
protected bool isNull = false;
|
public bool IsNull
|
{
|
get { return isNull; }
|
}
|
|
public ThroughCurve Clone()
|
{
|
return new ThroughCurve(this);
|
}
|
object ICloneable.Clone()
|
{
|
return Clone();
|
}
|
|
public string ToDsString()
|
{
|
return ToDsString(this);
|
}
|
|
public static string ToDsString(ThroughCurve curve)
|
{
|
if (curve == null || curve.PointInfo == null)
|
return null;
|
|
StringBuilder sb = new StringBuilder();
|
sb.Append(curve.DispTension);
|
sb.Append(","); sb.Append(curve.IsClosed);
|
sb.Append(","); sb.Append(curve.PointInfo.Count);
|
|
foreach (var point in curve.PointInfo)
|
{//必须用,分割,//可能只有一个点
|
sb.AppendFormat(",{0},{1}", point.X, point.Y);
|
}
|
|
return sb.ToString();
|
}
|
|
|
|
public static ThroughParaCurve toM3H(Eventech.Model.UnitQ unit, ThroughParaCurve curvePara)
|
{
|
if (curvePara == null)
|
return null;
|
if (curvePara.PointInfo == null)
|
return curvePara;
|
|
ThroughParaCurve newCurve = curvePara.Clone();
|
newCurve.PointInfo = new Eventech.Model.FeatPointList();
|
for (int i = 0; i < curvePara.PointInfo.Count; i++)
|
{
|
Eventech.Model.FeatPoint pt = curvePara.PointInfo[i];
|
newCurve.PointInfo.Add(new Eventech.Model.FeatPoint(Eventech.Common.UnitQHelper.toM3H(unit, pt.X), pt.Y));
|
}
|
|
return newCurve;
|
}
|
|
public static List<ThroughParaCurve> toM3H(UnitQ unit, List<ThroughParaCurve> curvePara)
|
{
|
if (curvePara == null)
|
return null;
|
|
List<ThroughParaCurve> newCurvePara = new List<ThroughParaCurve>();
|
foreach (ThroughParaCurve curve in curvePara)
|
{
|
newCurvePara.Add(toM3H(unit, curve));
|
}
|
|
return newCurvePara;
|
}
|
|
//获得X值的坐标位置,可能有多个点(是线形插值,不是曲线上的点)
|
public List<double> GetInterPointY(double x)
|
{
|
if (this._pointInfo == null)
|
return null;
|
|
|
return this._pointInfo.GetInterPointY(x);
|
}
|
|
}
|
|
|
|
}
|