You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
245 lines
8.0 KiB
C#
245 lines
8.0 KiB
C#
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; }
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="CurveView"/> class.
|
|
/// </summary>
|
|
public CurveView() : this(0)
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="CurveView"/> class.
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
public CurveView(int type)
|
|
{
|
|
//CurveType=type;
|
|
//ColorRef= 0;
|
|
|
|
//XmlSerializer
|
|
}
|
|
/// <summary>
|
|
/// 类型
|
|
/// </summary>
|
|
[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;
|
|
/// <summary>
|
|
/// 输出Xml数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual string SerialXml()
|
|
{
|
|
string strData = "";
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
settings.Indent = true;
|
|
settings.IndentChars = " ";
|
|
settings.NewLineChars = "\r\n";
|
|
settings.Encoding = Encoding.Unicode;
|
|
// 去除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.Unicode.GetString(mem.ToArray());
|
|
}
|
|
|
|
public virtual CurveView DeserialXml(string xml)
|
|
{
|
|
var xs = new XmlSerializer(this.GetType());
|
|
using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(xml)))
|
|
{
|
|
var obj = xs.Deserialize(stream) as CurveView;
|
|
|
|
return obj;
|
|
}
|
|
}
|
|
|
|
public CurveView Clone()
|
|
{
|
|
return DeserialXml(SerialXml());
|
|
}
|
|
|
|
#region ICustomTypeDescriptor 接口
|
|
/// <inheritdoc/>
|
|
AttributeCollection ICustomTypeDescriptor.GetAttributes()
|
|
{
|
|
return TypeDescriptor.GetAttributes(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
string ICustomTypeDescriptor.GetClassName()
|
|
{
|
|
return TypeDescriptor.GetClassName(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
string ICustomTypeDescriptor.GetComponentName()
|
|
{
|
|
return TypeDescriptor.GetComponentName(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
TypeConverter ICustomTypeDescriptor.GetConverter()
|
|
{
|
|
return TypeDescriptor.GetConverter(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
|
|
{
|
|
return TypeDescriptor.GetDefaultEvent(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
|
|
{
|
|
return TypeDescriptor.GetDefaultProperty(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
|
|
{
|
|
return TypeDescriptor.GetEditor(this, editorBaseType, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
|
|
{
|
|
return TypeDescriptor.GetEvents(this, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
|
|
{
|
|
return TypeDescriptor.GetEvents(this, attributes, true);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
|
|
{
|
|
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, true);
|
|
return ReOrderProperties(properties);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
|
|
{
|
|
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, attributes, true);
|
|
return ReOrderProperties(properties);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
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<properties.Count; j++)
|
|
//{
|
|
// var item = properties[j];
|
|
// if (list.Contains(item))
|
|
// {
|
|
// continue;
|
|
// }
|
|
// list[i]=item;
|
|
// i++;
|
|
//}
|
|
//return new PropertyDescriptorCollection(list, true);
|
|
}
|
|
#endregion ICustomTypeDescriptor 接口
|
|
}
|
|
}
|