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; namespace SigmaDrawerElement { [XmlRoot("Layer")] [XmlType("Layer")] public class DrawerLayer { [XmlAttribute] public string Name { get; set; } = ""; [XmlAttribute] public int Visibility { get; set; } = 1; [XmlElement("HowToViewCurve")] public DrawerCurveStyle CurveStyle { set; get; } [XmlElement("HowToViewPoint")] public DrawerPointStyle PointStyle { set; get; } [XmlIgnore] [XmlElement("Visibility")] public LayerElementVisibility ElementVisibility { get; set; } = new LayerElementVisibility(); [XmlIgnore] [XmlElement("Color")] public LayerElementColor ElementColor { get; set; } = new LayerElementColor(); //Type[] Types = { typeof(DrawerPoint), typeof(DrawerPointTwoName), typeof(DrawerPointCrossName) }; [XmlElement("Point", typeof(DrawerPoint))] [XmlElement("TwoPoint", typeof(DrawerPointTwoName))] [XmlElement("CrossPoint", typeof(DrawerPointCrossName))] [XmlElement("Pline", typeof(DrawerPline))] [XmlElement("Surface", typeof(DrawerSurface))] [XmlElement("Text", typeof(DrawerText))] [XmlElement("Ellipse", typeof(DrawerEllipse))] [XmlElement("Arc", typeof(DrawerArc))] [XmlElement("Proportion", typeof(DrawerProportion))] [XmlElement("Frame", typeof(DrawerFrame))] [XmlElement("FGrid", typeof(DrawerFrameGrid))] [XmlElement("Xyz", typeof(DrawerXyz))] public List Elements { get; set; } = new List(); public string ToXml() { 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(); StringBuilder sb = new StringBuilder(); using (StringWriter stringWriter = new StringWriter(sb)) { using (XmlWriter writer = XmlWriter.Create(stringWriter, 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(); XmlSerializer formatter = new XmlSerializer(this.GetType()); formatter.Serialize(writer, this, ns); } } // string strData = Encoding.Default.GetString(mem.ToArray()); string strData = sb.ToString(); if (this.CurveStyle != null) { int nInsert = strData.LastIndexOf(""); strData.Insert(nInsert, "" + System.Environment.NewLine); } else if (this.PointStyle != null) { int nInsert = strData.LastIndexOf(""); strData.Insert(nInsert, "" + System.Environment.NewLine); } // strData.Replace("") return strData; } } public class LayerElementVisibility { [XmlAttribute("Value")] public int Visibility { get; set; } = 1; } public class LayerElementColor { [XmlAttribute("Value")] public int ElementColor { get; set; } = 0; } }