using System.ComponentModel; using System.Drawing; using System.Xml.Serialization; using GeoSigma.SigmaDrawerStyle; using GeoSigma.SigmaDrawerStyle.Converter; using GeoSigmaDrawLib; namespace SigmaDrawerElement { public class DrawerDonut : ElementBase { public DrawerDonut() { ElementType = DrawElementType.ELEMENT_CIRCLE; } [Browsable(false)] [XmlAttribute("Color")] public int ColorRef; [XmlIgnore] [Category("\t基本"), DisplayName("\t颜色")] public Color LineColor { get { return ColorTranslator.FromWin32(ColorRef); } set { ColorRef = ColorTranslator.ToWin32(value); } } private PropertyPoint center = new PropertyPoint(); [XmlIgnore] [Category("\t基本"), DisplayName("\t\t\t\t\t圆心坐标")] //[TypeConverterAttribute(typeof(PropertyPointConvert))] public PropertyPoint Center { get => BaseData.Center; set => BaseData.Center = value; } [XmlIgnore] [Category("\t基本"), DisplayName("\t\t\t\t半径")] [TypeConverter(typeof(DoubleTrimConverter))] public double R // 用外半径替代的,需要修改 { get { if (WidthStyle == 4) // 内侧 { return BaseData.ER; } else if (WidthStyle == 1) // 中心 { return (BaseData.BR + BaseData.ER) / 2.0; } else // 2 外侧 { return BaseData.BR; } } set { double dWidth = this.Width; if (WidthStyle == 4) // 内侧 { BaseData.ER = value; BaseData.BR = BaseData.ER - dWidth; } else if (widthStyle == 1) // 中心 { BaseData.ER = value + dWidth * 0.5; BaseData.BR = value - dWidth * 0.5; } else // 2 外侧 { BaseData.BR = value; BaseData.ER = value + dWidth; } } } [XmlIgnore] [Category("\t基本"), DisplayName("\t\t\t曲线宽度")] [TypeConverter(typeof(DoubleTrimConverter))] public double Width { get => BaseData.ER - BaseData.BR; set { if(widthStyle == 1) // 中心 { BaseData.ER += value / 2.0; BaseData.BR -= value / 2.0; } else if (widthStyle == 2) // 外侧 { BaseData.ER = BaseData.BR + value; } else // 内侧 if(widthStyle == 4) { BaseData.BR = BaseData.ER - value; } } } private int widthStyle = 4; [XmlIgnore] [Category("\t基本"), DisplayName("\t\t宽度定位")] [TypeConverter(typeof(SigmaDrawerElement.Converter.EllipseStyleConverter))] public int WidthStyle { get { return widthStyle; } set { widthStyle = value; } } [XmlElement("Base")] [Browsable(false)] public DonutBase BaseData { get; set; } = new DonutBase(); } public class DonutBase { [XmlAttribute] public double X { get { return Center.X; } set { Center = new PropertyPoint(value, Center.Y); } } [XmlAttribute] public double Y { get { return Center.Y; } set { Center = new PropertyPoint(Center.X, value); } } [XmlAttribute] public double Z { get; set; } /// /// Gets or sets 内半径. /// [XmlAttribute] public double BR { get; set; } /// /// Gets or sets 外半径. /// [XmlAttribute] public double ER { get; set; } [XmlIgnore] public PropertyPoint Center { get; set; } = new PropertyPoint(); } }