using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using GeoSigmaDrawLib;
//using System.Xml.Serialization;
namespace GeoSigma.SigmaDrawerStyle
{
public class CurveView : ICustomTypeDescriptor
{
//public int CurveType { get; set; }
//public int ColorRef { get; set; }
///
/// Initializes a new instance of the class.
///
public CurveView() : this(0)
{
}
///
/// Initializes a new instance of the class.
///
///
public CurveView(int type)
{
//CurveType=type;
//ColorRef= 0;
//XmlSerializer
}
///
/// 类型
///
[XmlIgnore]
[Browsable(false)]
public CurveStyleType StyleType
{
get
{
CurveStyleType styleType = 0;
switch (TypeName)
{
case "首箭头":
styleType = CurveStyleType.CurveArrowHead;
break;
case "尾箭头":
styleType = CurveStyleType.CurveArrowTail;
break;
case "常规":
styleType = CurveStyleType.CurveProperties;
break;
case "桩号":
styleType = CurveStyleType.CurveLocate;
break;
case "刻度":
styleType = CurveStyleType.CurveScale;
break;
case "名字":
styleType = CurveStyleType.CurveNameHead;
break;
case "两个符号":
styleType = CurveStyleType.CurveTwoMark;
break;
case "符号充填":
styleType = CurveStyleType.CurveRgn;
break;
case "内部写名字":
styleType = CurveStyleType.CurveInName;
break;
case "任意处写名字":
styleType = CurveStyleType.CurveInNameAny;
break;
case "渐变色":
styleType = CurveStyleType.CurveEffect;
break;
case "中心上名字":
styleType = CurveStyleType.CurveCenterName;
break;
default:
break;
}
return styleType;
}
}
string _TypeName;
[XmlIgnore]
[Browsable(false)]
public string TypeName { get => _TypeName; set => _TypeName = value; }
[XmlIgnore]
[Browsable(false)]
public GeoSigmaXY Geo { get; set; } = null;
///
/// 输出Xml数据
///
///
public virtual string SerialXml()
{
string strData = "";
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineChars = "\r\n";
settings.Encoding = Encoding.Default;
// 去除xml声明
settings.OmitXmlDeclaration = true;
System.IO.MemoryStream mem = new MemoryStream();
using (XmlWriter writer = XmlWriter.Create(mem, settings))
{
//去除默认命名空间xmlns:xsd和xmlns:xsi
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
XmlSerializer formatter = new XmlSerializer(this.GetType());
formatter.Serialize(writer, this, ns);
}
return Encoding.Default.GetString(mem.ToArray());
}
public virtual CurveView DeserialXml(string xml)
{
var xs = new XmlSerializer(this.GetType());
using (MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(xml)))
{
var obj = xs.Deserialize(stream) as CurveView;
return obj;
}
}
public CurveView Clone()
{
return DeserialXml(SerialXml());
}
#region ICustomTypeDescriptor 接口
///
AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
///
string ICustomTypeDescriptor.GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
///
string ICustomTypeDescriptor.GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
///
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
///
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
///
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
///
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
///
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
///
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
///
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, true);
return ReOrderProperties(properties);
}
///
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, attributes, true);
return ReOrderProperties(properties);
}
///
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
public virtual PropertyDescriptorCollection ReOrderProperties(PropertyDescriptorCollection properties)
{
return properties;
//var list = new PropertyDescriptor[properties.Count];
//string[] topProps = { "UUID", "Code", "Name" };
//int i = 0;
//foreach (string s in topProps)
//{
// PropertyDescriptor item = properties.Find(s, true);
// if (item!=null)
// {
// list[i]=item;
// i++;
// }
//}
//for (int j = 0; j