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.
160 lines
6.9 KiB
C#
160 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
using GeoSigma.SigmaDrawerStyle;
|
|
using GeoSigmaDrawLib;
|
|
|
|
namespace SigmaDrawerElement
|
|
{
|
|
public class DrawerElementHelp
|
|
{
|
|
public static DrawerElementProperty Deserialize(string data)
|
|
{
|
|
if (data.IndexOf("<HowToViewCurve>") > 0)
|
|
{
|
|
data = data.Replace("<HowToViewCurve />", "");
|
|
}
|
|
else if (data.IndexOf("<HowToViewPoint>") > 0)
|
|
{
|
|
data = data.Replace("<HowToViewPoint />", "");
|
|
}
|
|
|
|
DrawerElementProperty element = null;
|
|
using (StringReader reader = new StringReader(data))
|
|
{
|
|
try
|
|
{
|
|
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(DrawerElementProperty));
|
|
element = xmlSerializer.Deserialize(reader) as DrawerElementProperty;
|
|
// 原始属性处理
|
|
if (element.ElementType == DrawElementType.ELEMENT_CURVE && element.CurveStyle == null)
|
|
{
|
|
DrawerPline line = element.Element as DrawerPline;
|
|
if (element.ColorRef != 0
|
|
|| line.Width > 1E-10
|
|
|| !string.IsNullOrEmpty(line.DisplayType))
|
|
{
|
|
CurveProperty curveProperty = new CurveProperty();
|
|
curveProperty.TypeName = "原始";
|
|
ViewBase curViewBase = new ViewBase();
|
|
curViewBase.ColorRef = element.ColorRef;
|
|
curViewBase.Width = line.Width;
|
|
curViewBase.Style = (int)Constants.ParseLineType(line.DisplayType);
|
|
curViewBase.Style |= (int)LineType.PLINE_SMOOTH_HEAD;
|
|
curveProperty.Base = curViewBase;
|
|
element.CurveStyle = new DrawerCurveStyle();
|
|
element.CurveStyle.Properties.Add(curveProperty);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
return element;
|
|
}
|
|
public List<DrawerElementProperty> DeserializeList(string data)
|
|
{
|
|
if (data.IndexOf("<HowToViewCurve>") > 0)
|
|
{
|
|
data = data.Replace("<HowToViewCurve />", "");
|
|
}
|
|
else if (data.IndexOf("<HowToViewPoint>") > 0)
|
|
{
|
|
data = data.Replace("<HowToViewPoint />", "");
|
|
}
|
|
data = data.Replace("Element", "DrawerElementProperty");
|
|
GeoSigma.SigmaDrawerElement.DrawerData elements = null;
|
|
using (StringReader reader = new StringReader(data))
|
|
{
|
|
try
|
|
{
|
|
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(GeoSigma.SigmaDrawerElement.DrawerData));
|
|
elements = xmlSerializer.Deserialize(reader) as GeoSigma.SigmaDrawerElement.DrawerData;
|
|
// 原始属性处理
|
|
foreach (var element in elements)
|
|
{
|
|
if (element.ElementType == DrawElementType.ELEMENT_CURVE && element.CurveStyle == null)
|
|
{
|
|
DrawerPline line = element.Element as DrawerPline;
|
|
if (element.ColorRef != 0
|
|
|| line.Width > 1E-10
|
|
|| !string.IsNullOrEmpty(line.DisplayType))
|
|
{
|
|
CurveProperty curveProperty = new CurveProperty();
|
|
curveProperty.TypeName = "原始";
|
|
ViewBase curViewBase = new ViewBase();
|
|
curViewBase.ColorRef = element.ColorRef;
|
|
curViewBase.Width = line.Width;
|
|
curViewBase.Style = (int)Constants.ParseLineType(line.DisplayType);
|
|
curViewBase.Style |= (int)LineType.PLINE_SMOOTH_HEAD;
|
|
curveProperty.Base = curViewBase;
|
|
element.CurveStyle = new DrawerCurveStyle();
|
|
element.CurveStyle.Properties.Add(curveProperty);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
Console.WriteLine(ex.InnerException?.Message);
|
|
}
|
|
}
|
|
return elements;
|
|
}
|
|
|
|
public static string Serialize(DrawerElementProperty element)
|
|
{
|
|
//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);
|
|
|
|
// Create the XmlAttributeOverrides and XmlAttributes objects.
|
|
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
|
|
XmlAttributes attrs = new XmlAttributes();
|
|
|
|
// /* Use the XmlIgnore to instruct the XmlSerializer to ignore
|
|
// the GroupName instead. */
|
|
// attrs=new XmlAttributes();
|
|
// attrs.XmlIgnore=true;
|
|
// overrides.Add(typeof(SomeBase), "SomeProperty", attrs);
|
|
|
|
XmlSerializer formatter = new XmlSerializer(typeof(DrawerElementProperty));
|
|
formatter.Serialize(writer, element, ns);
|
|
}
|
|
string strData = Encoding.Default.GetString(mem.ToArray());
|
|
|
|
if (element.CurveStyle != null)
|
|
{
|
|
int nInsert = strData.LastIndexOf("</Element>");
|
|
strData.Insert(nInsert, "<HowToViewCurve />" + System.Environment.NewLine);
|
|
}
|
|
else if (element.PointStyle != null)
|
|
{
|
|
int nInsert = strData.LastIndexOf("</Element>");
|
|
strData.Insert(nInsert, "<HowToViewPoint />" + System.Environment.NewLine);
|
|
}
|
|
|
|
return strData;
|
|
}
|
|
}
|
|
}
|