// // Copyright (c) PlaceholderCompany. All rights reserved. // using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; #if WEB_SERVICE #else using System.Drawing.Design; #endif using System.Xml.Serialization; using GeoSigma.SigmaDrawerStyle.Converter; using SigmaDrawerStyle; namespace GeoSigma.SigmaDrawerStyle { /// /// 曲线属性 /// [XmlRoot("Property")] [TypeConverter(typeof(PropertySorter))] public class CurveProperty : CurveArrow { /// /// Initializes a new instance of the class. /// public CurveProperty() { _VirtureType.OnlyNodeVirture = false; TypeName = "常规"; _WaveStyle.T = 30000; _WaveStyle.A = 20000; _WaveStyle.dnum = 10; } private const string BaseProperty = "\t\t\t基础属性"; private const string WaveProperty = "\t波浪线属性"; private const string TransparentProperty = "\t\t透明属性"; private ViewBase _Base; [XmlElement("Base")] [Browsable(false)] public ViewBase Base { get { return _Base; } set { _Base = value; } } private CurveVirtureType _VirtureType; [XmlElement("VirtualLine")] [Browsable(false)] public CurveVirtureType VirtureType { get { return _VirtureType; } set { _VirtureType = value; } } private CurveWaveStyle _WaveStyle; [XmlElement("Wave")] [Browsable(false)] public CurveWaveStyle WaveStyle { get { return _WaveStyle; } set { _WaveStyle = value; } } /// /// 这个保留,保持兼容 /// [XmlIgnore] [Browsable(false)] public int CurveType { get { return _Base.Style & (int)LineType.PLINE_TYPE_ALL; } set { _Base.Style &= ~((int)LineType.PLINE_TYPE_ALL); _Base.Style |= value; } } /// /// 线型 /// [XmlIgnore] [Category(BaseProperty), DisplayName("线型"), PropertyOrder(0)] [TypeConverter(typeof(CurveTypeConverter))] public CurveLineType CurveLineType { get { if (hasLineType(LineType.PLINE_ZERO)) { return CurveLineType.Default; } if (hasLineType(LineType.PLINE_NODRAW)) { return CurveLineType.NoDraw; } if (hasLineType(LineType.PLINE_CLOSE)) { return CurveLineType.Close; } if (hasLineType(LineType.PLINE_OFFSET)) { return CurveLineType.Offset; } if (hasLineType(LineType.PLINE_WAVE)) { return CurveLineType.Wave; } return CurveLineType.Default; } set { clearLineType(LineType.PLINE_ZERO); clearLineType(LineType.PLINE_NODRAW); clearLineType(LineType.PLINE_CLOSE); clearLineType(LineType.PLINE_OFFSET); clearLineType(LineType.PLINE_WAVE); if (value == CurveLineType.Default) { setLineType(LineType.PLINE_ZERO); } else if (value == CurveLineType.NoDraw) { setLineType(LineType.PLINE_NODRAW); } else if (value == CurveLineType.Close) { setLineType(LineType.PLINE_CLOSE); } else if (value == CurveLineType.Offset) { setLineType(LineType.PLINE_OFFSET); } else if (value == CurveLineType.Wave) { setLineType(LineType.PLINE_WAVE); } else { setLineType(LineType.PLINE_ZERO); } } } [XmlIgnore] [Category(BaseProperty), /*CategoryOrder(0),*/ DisplayName("宽度"), PropertyOrder(1)] [TypeConverter(typeof(PropertyDoubleConverter))] public double Width { get { return Base.Width; } set { _Base.Width = value; } } [XmlIgnore] [Category(BaseProperty), /*CategoryOrder(0),*/ DisplayName("颜色"), PropertyOrder(2)] #if WEB_SERVICE #else [Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))] #endif //[TypeConverter(typeof(PropertyColorIndicatorConvert))] public Color LineColor { get { return ColorTranslator.FromWin32(_Base.ColorRef); } set { _Base.ColorRef = ColorTranslator.ToWin32(value); } } [XmlIgnore] [Category(BaseProperty), DisplayName("线端"), PropertyOrder(3)] [TypeConverter(typeof(Converter.CurveCapConverter))] public CurveCap CurveLineCap { get { return hasLineType(LineType.PLINE_SMOOTH_HEAD) ? CurveCap.Round : CurveCap.Square; } set { if (value == CurveCap.Round) { setLineType(LineType.PLINE_SMOOTH_HEAD); } else { clearLineType(LineType.PLINE_SMOOTH_HEAD); } } } [XmlIgnore] [Category(BaseProperty), DisplayName("平滑"), PropertyOrder(4)] [TypeConverter(typeof(Converter.CurveSmoothnessConverter))] public CurveSmoothness CurveSmoothness { get { if (hasLineType(LineType.PLINE_BEZIER)) { return CurveSmoothness.Bezier; } if (hasLineType(LineType.PLINE_SPLINE)) { return CurveSmoothness.Spline; } return CurveSmoothness.None; } set { // 清理,因为我们这里使用枚举表示,选中其中一个之后,其它的都要清理掉 clearLineType(LineType.PLINE_BEZIER); clearLineType(LineType.PLINE_SPLINE); if (value == CurveSmoothness.Bezier) { setLineType(LineType.PLINE_BEZIER); } else if (value == CurveSmoothness.Spline) { setLineType(LineType.PLINE_SPLINE); } } } [XmlIgnore] [Category(BaseProperty), DisplayName("透明"), PropertyOrder(5)] [TypeConverter(typeof(Converter.CurveAlphaModeConverter))] public CurveAlphaMode CurveAlphaMode { get { if (hasLineType(LineType.PLINE_TRANSPARENT_VALUE)) { return CurveAlphaMode.Transparent; } if (hasLineType(LineType.PLINE_TRANSPARENT)) { return CurveAlphaMode.Alphand; } return CurveAlphaMode.None; } set { clearLineType(LineType.PLINE_TRANSPARENT); clearLineType(LineType.PLINE_TRANSPARENT_VALUE); if (value == CurveAlphaMode.Alphand) { setLineType(LineType.PLINE_TRANSPARENT); } else if (value == CurveAlphaMode.Transparent) { setLineType(LineType.PLINE_TRANSPARENT_VALUE); } } } [XmlIgnore] [Category(BaseProperty), DisplayName("充填"), PropertyOrder(6)] [TypeConverter(typeof(Converter.YesNoConverter))] public bool IsFill { get { return hasLineType(LineType.PLINE_SOLID); } set { if (value) { setLineType(LineType.PLINE_SOLID); } else { clearLineType(LineType.PLINE_SOLID); } } } [XmlIgnore] [Category(BaseProperty), DisplayName("虚线(有线长度 无线长度 ...)"), PropertyOrder(9)] public string VirtureValues { get { return _VirtureType.VirtureValues; } set { _VirtureType.VirtureValues = value; } } [XmlIgnore] [Category(BaseProperty), DisplayName("仅拐点处虚线"), PropertyOrder(10)] [TypeConverter(typeof(Converter.YesNoConverter))] public bool OnlyNodeVirture { get { return _VirtureType.OnlyNodeVirture; } set { _VirtureType.OnlyNodeVirture = value; } } [XmlIgnore] [Category(BaseProperty), DisplayName("平行间距"), PropertyOrder(7)] [TypeConverter(typeof(PropertyDoubleConverter))] public double Offset { get { return _Base.Offset; } set { _Base.Offset = value; } } [XmlIgnore] [Category(BaseProperty), DisplayName("光滑步长"), PropertyOrder(8)] [TypeConverter(typeof(PropertyDoubleConverter))] public double SmoothStep { get { return _Base.SmoothStep; } set { _Base.SmoothStep = value; } } private int alpha = 255; /// /// 透明属性 /// [Category(TransparentProperty), DisplayName("透明度"), PropertyOrder(1), ReadOnly(false)] public int Alpha { get { return alpha; } set { alpha = Math.Clamp(value, 0, 255); } } [XmlIgnore] [Category(WaveProperty), DisplayName("周期"), PropertyOrder(1), ReadOnly(false)] [TypeConverter(typeof(PropertyDoubleConverter))] public double WaveT { get { return _WaveStyle.T; } set { _WaveStyle.T = value; } } [XmlIgnore] [Category(WaveProperty), DisplayName("振幅"), PropertyOrder(2),ReadOnly(false)] [TypeConverter(typeof(PropertyDoubleConverter))] public double WaveA { get { return _WaveStyle.A; } set { _WaveStyle.A = value; } } [XmlIgnore] [Category(WaveProperty), DisplayName("采样点数"), PropertyOrder(3), ReadOnly(false)] [TypeConverter(typeof(PropertyIntConverter))] public int WaveNum { get { return _WaveStyle.dnum; } set { _WaveStyle.dnum = value; } } /// /// 属性类别排序 /// private List categorys = new List() { BaseProperty, WaveProperty, "透明属性" }; private bool hasLineType(LineType lineType) { return (_Base.Style & (int)lineType) != 0; } private void setLineType(LineType lineType) { _Base.Style |= (int)lineType; } private void clearLineType(LineType lineType) { _Base.Style &= ~(int)lineType; } } public struct ViewBase { [XmlAttribute("Width")] public double Width; [XmlAttribute("Color")] public int ColorRef; [XmlAttribute("Style")] public int Style; [XmlAttribute("SmoothStep")] public double SmoothStep; [XmlAttribute("Offset")] public double Offset; } public struct CurveVirtureType { [XmlAttribute("Number")] public int Num; [XmlAttribute("IsNode")] public bool OnlyNodeVirture; [XmlAttribute("Value")] public string VirtureValues; } public struct CurveWaveStyle { [XmlAttribute("T")] public double T; //采样周期 [XmlAttribute("A")] public double A; //振幅 [XmlAttribute("N")] public int dnum; //一个周期内采样点个数 }; }