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.

496 lines
13 KiB
C#

1 month ago
// <copyright file="CurveProperty.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
1 month ago
#if WEB_SERVICE
1 month ago
#else
using System.Drawing.Design;
#endif
using System.Xml.Serialization;
1 month ago
using GeoSigma.SigmaDrawerStyle.Converter;
1 month ago
using SigmaDrawerStyle;
namespace GeoSigma.SigmaDrawerStyle
{
/// <summary>
/// 曲线属性
/// </summary>
[XmlRoot("Property")]
[TypeConverter(typeof(PropertySorter))]
public class CurveProperty : CurveArrow
{
/// <summary>
/// Initializes a new instance of the <see cref="CurveProperty"/> class.
/// </summary>
public CurveProperty()
{
_VirtureType.OnlyNodeVirture = false;
TypeName = "常规";
_WaveStyle.T = 30000;
_WaveStyle.A = 20000;
_WaveStyle.dnum = 10;
}
1 month ago
private const string BaseProperty = "\t\t\t基础属性";
private const string WaveProperty = "\t波浪线属性";
private const string TransparentProperty = "\t\t透明属性";
1 month ago
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;
}
}
1 month ago
/// <summary>
/// 这个保留,保持兼容
/// </summary>
[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;
}
}
/// <summary>
/// 线型
/// </summary>
[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);
}
}
}
1 month ago
[XmlIgnore]
1 month ago
[Category(BaseProperty), /*CategoryOrder(0),*/ DisplayName("宽度"), PropertyOrder(1)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Width
{
get
{
return Base.Width;
}
set
{
_Base.Width = value;
}
}
[XmlIgnore]
1 month ago
[Category(BaseProperty), /*CategoryOrder(0),*/ DisplayName("颜色"), PropertyOrder(2)]
#if WEB_SERVICE
1 month ago
#else
1 month ago
[Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))]
1 month ago
#endif
1 month ago
//[TypeConverter(typeof(PropertyColorIndicatorConvert))]
1 month ago
public Color LineColor
{
get
{
return ColorTranslator.FromWin32(_Base.ColorRef);
}
set
{
_Base.ColorRef = ColorTranslator.ToWin32(value);
}
}
[XmlIgnore]
1 month ago
[Category(BaseProperty), DisplayName("线端"), PropertyOrder(3)]
[TypeConverter(typeof(Converter.CurveCapConverter))]
public CurveCap CurveLineCap
1 month ago
{
get
{
1 month ago
return hasLineType(LineType.PLINE_SMOOTH_HEAD) ? CurveCap.Round : CurveCap.Square;
1 month ago
}
1 month ago
1 month ago
set
{
1 month ago
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);
}
1 month ago
}
}
1 month ago
1 month ago
[XmlIgnore]
1 month ago
[Category(BaseProperty), DisplayName("充填"), PropertyOrder(6)]
1 month ago
[TypeConverter(typeof(Converter.YesNoConverter))]
1 month ago
public bool IsFill
1 month ago
{
get
{
1 month ago
return hasLineType(LineType.PLINE_SOLID);
1 month ago
}
1 month ago
1 month ago
set
{
if (value)
{
1 month ago
setLineType(LineType.PLINE_SOLID);
1 month ago
}
else
{
1 month ago
clearLineType(LineType.PLINE_SOLID);
1 month ago
}
}
}
1 month ago
1 month ago
[XmlIgnore]
1 month ago
[Category(BaseProperty), DisplayName("虚线(有线长度 无线长度 ...)"), PropertyOrder(9)]
1 month ago
public string VirtureValues
{
get
{
return _VirtureType.VirtureValues;
}
set
{
_VirtureType.VirtureValues = value;
}
}
[XmlIgnore]
1 month ago
[Category(BaseProperty), DisplayName("仅拐点处虚线"), PropertyOrder(10)]
1 month ago
[TypeConverter(typeof(Converter.YesNoConverter))]
public bool OnlyNodeVirture
{
get
{
return _VirtureType.OnlyNodeVirture;
}
set
{
_VirtureType.OnlyNodeVirture = value;
}
}
[XmlIgnore]
1 month ago
[Category(BaseProperty), DisplayName("平行间距"), PropertyOrder(7)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Offset
{
get
{
return _Base.Offset;
}
set
{
_Base.Offset = value;
}
}
[XmlIgnore]
1 month ago
[Category(BaseProperty), DisplayName("光滑步长"), PropertyOrder(8)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double SmoothStep
{
get
{
return _Base.SmoothStep;
}
set
{
_Base.SmoothStep = value;
}
}
private int alpha = 255;
/// <summary>
/// 透明属性
/// </summary>
1 month ago
[Category(TransparentProperty), DisplayName("透明度"), PropertyOrder(1), ReadOnly(false)]
1 month ago
public int Alpha
{
get
{
return alpha;
}
set
{
1 month ago
alpha = Math.Clamp(value, 0, 255);
1 month ago
}
}
[XmlIgnore]
1 month ago
[Category(WaveProperty), DisplayName("周期"), PropertyOrder(1), ReadOnly(false)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double WaveT
{
get
{
return _WaveStyle.T;
}
set
{
_WaveStyle.T = value;
}
}
[XmlIgnore]
1 month ago
[Category(WaveProperty), DisplayName("振幅"), PropertyOrder(2),ReadOnly(false)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double WaveA
{
get
{
return _WaveStyle.A;
}
set
{
_WaveStyle.A = value;
}
}
[XmlIgnore]
1 month ago
[Category(WaveProperty), DisplayName("采样点数"), PropertyOrder(3), ReadOnly(false)]
1 month ago
[TypeConverter(typeof(PropertyIntConverter))]
public int WaveNum
{
get
{
return _WaveStyle.dnum;
}
set
{
_WaveStyle.dnum = value;
}
}
/// <summary>
/// 属性类别排序
/// </summary>
1 month ago
private List<string> categorys = new List<string>() { 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;
}
1 month ago
}
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; //一个周期内采样点个数
};
}