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.

504 lines
16 KiB
C#

1 month ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
1 month ago
#if WEB_SERVICE
1 month ago
#else
using System.Drawing.Design;
#endif
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using GeoSigmaDrawLib;
using SigmaDrawerStyle;
namespace GeoSigma.SigmaDrawerStyle
{
[XmlRoot("InName")]
[TypeConverter(typeof(PropertySorter))]
public class CurveInName : CurveView
{
1 month ago
// ==================== 分类常量 ====================
private const string TextProperty = "\t\t\t文字";
private const string LineProperty = "\t\t线属性";
private const string WaveProperty = "\t波浪线属性";
private const string OtherProperty = "其它";
1 month ago
public CurveInName()
{
1 month ago
TypeName = "线中心";
_curveWave.T = 30000;
_curveWave.A = 20000;
_curveWave.dnum = 10;
1 month ago
}
1 month ago
// ==================== 文字属性 ====================
1 month ago
private Font _TextFont;
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("字体"), PropertyOrder(1)]
1 month ago
[TypeConverterAttribute(typeof(FontPropertyConvert))]
public Font TextFont
{
get
{
_TextFont = Font.FromLogFont(NameFont);
return _TextFont;
}
set
{
_TextFont = value;
NameFont = LogFontConverter.convert(_TextFont);
}
}
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("高度"), PropertyOrder(2)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double TextHeight
{
1 month ago
get { return Text.Height; }
set { Text.Height = value; }
1 month ago
}
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("步长 | 数目"), PropertyOrder(3)]
1 month ago
[TypeConverter(typeof(Converter.CurveNameLineTypeConverter))]
public int InNameType
{
get
{
return Style.Value & ((int)LineType.PLINE_MARK_NAME_NUM | (int)LineType.PLINE_MARK_NAME_STEP);
}
set
{
Style.Value &= ~((int)LineType.PLINE_MARK_NAME_NUM | (int)LineType.PLINE_MARK_NAME_STEP);
Style.Value |= value;
}
}
1 month ago
1 month ago
[Browsable(true)]
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("数目"), PropertyOrder(4)]
[Range(1, 100)]
1 month ago
public int NameNum
{
1 month ago
get { return (int)(Text.NumOrStep + 0.0001); }
1 month ago
set
{
1 month ago
if (value <= 0) throw new ArgumentOutOfRangeException("数目必须大于 0。");
1 month ago
Text.NumOrStep = value;
}
}
[Browsable(true)]
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("步长"), PropertyOrder(5)]
1 month ago
[Range(0.01, double.MaxValue)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Step
{
1 month ago
get { return Text.NumOrStep; }
1 month ago
set
{
1 month ago
if (value <= 0) throw new ArgumentOutOfRangeException("步长必须大于 0。");
1 month ago
Text.NumOrStep = value;
}
}
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("偏移"), PropertyOrder(6)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Offset
{
1 month ago
get { return Text.Offset; }
set { Text.Offset = value; }
1 month ago
}
1 month ago
1 month ago
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("颜色"), PropertyOrder(7)]
#if WEB_SERVICE
1 month ago
#else
[Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))]
#endif
[TypeConverter(typeof(PropertyColorIndicatorConvert))]
public Color TextColor
{
1 month ago
get { return ColorTranslator.FromWin32(Text.ColorRef); }
set { Text.ColorRef = ColorTranslator.ToWin32(value); }
1 month ago
}
1 month ago
1 month ago
[XmlIgnore]
1 month ago
[Category(TextProperty), DisplayName("自动缩小字体"), PropertyOrder(8)]
1 month ago
[TypeConverter(typeof(Converter.YesNoConverter))]
public bool AutoDecrease
{
1 month ago
get { return (Style.Value & (int)Constants.PLINE_IN_NAME_AUTO_DECREASE) != 0; }
1 month ago
set
{
1 month ago
if (value) Style.Value |= (int)Constants.PLINE_IN_NAME_AUTO_DECREASE;
else Style.Value &= ~(int)Constants.PLINE_IN_NAME_AUTO_DECREASE;
1 month ago
}
}
1 month ago
// ==================== 线属性 ====================
1 month ago
[XmlIgnore]
1 month ago
[Category(LineProperty), DisplayName("宽度"), PropertyOrder(1)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Width
{
1 month ago
get { return Curve.Width; }
set { Curve.Width = value; }
1 month ago
}
[XmlIgnore]
1 month ago
[Category(LineProperty), DisplayName("颜色"), PropertyOrder(2)]
#if WEB_SERVICE
1 month ago
#else
[Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))]
#endif
public Color CurveColor
1 month ago
{
get { return ColorTranslator.FromWin32(Curve.ColorRef); }
set { Curve.ColorRef = ColorTranslator.ToWin32(value); }
}
//关键修改:样式支持平行和波浪线(使用已有的 CurveLineStyle 枚举)
[Category(LineProperty), DisplayName("样式"), PropertyOrder(3)]
[TypeConverter(typeof(Converter.CurveTypeConverter))]
public CurveLineType CurveStyle
1 month ago
{
get
{
1 month ago
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;
1 month ago
}
1 month ago
1 month ago
set
{
1 month ago
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(LineProperty), DisplayName("线端"), PropertyOrder(4)]
[TypeConverter(typeof(Converter.CurveCapConverter))]
public CurveCap CurveLineCap
1 month ago
{
1 month ago
get { return hasLineType(LineType.PLINE_SMOOTH_HEAD) ? CurveCap.Round : CurveCap.Square; }
1 month ago
set
{
1 month ago
if (value == CurveCap.Round) setLineType(LineType.PLINE_SMOOTH_HEAD);
else clearLineType(LineType.PLINE_SMOOTH_HEAD);
1 month ago
}
}
[XmlIgnore]
1 month ago
[Category(LineProperty), DisplayName("平滑"), PropertyOrder(5)]
[TypeConverter(typeof(Converter.CurveSmoothnessConverter))]
public CurveSmoothness CurveSmoothness
1 month ago
{
get
{
1 month ago
if (hasLineType(LineType.PLINE_BEZIER)) return CurveSmoothness.Bezier;
if (hasLineType(LineType.PLINE_SPLINE)) return CurveSmoothness.Spline;
return CurveSmoothness.None;
1 month ago
}
set
{
1 month ago
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);
1 month ago
}
}
[XmlIgnore]
1 month ago
[Category(LineProperty), DisplayName("光滑步长"), PropertyOrder(6)]
1 month ago
[TypeConverter(typeof(PropertyDoubleConverter))]
public double SmoothStep
1 month ago
{
get { return Curve.SmoothStep; }
set { Curve.SmoothStep = value; }
}
[XmlIgnore]
[Category(LineProperty), DisplayName("透明"), PropertyOrder(7)]
[TypeConverter(typeof(Converter.CurveAlphaModeConverter))]
public CurveAlphaMode CurveAlphaMode
1 month ago
{
get
{
1 month ago
if (hasLineType(LineType.PLINE_TRANSPARENT)) return CurveAlphaMode.Transparent;
if (hasLineType(LineType.PLINE_TRANSPARENT_VALUE)) return CurveAlphaMode.Alphand;
return CurveAlphaMode.None;
}
set
{
clearLineType(LineType.PLINE_TRANSPARENT);
clearLineType(LineType.PLINE_TRANSPARENT_VALUE);
if (value == CurveAlphaMode.Transparent) setLineType(LineType.PLINE_TRANSPARENT);
else if (value == CurveAlphaMode.Alphand) setLineType(LineType.PLINE_TRANSPARENT_VALUE);
1 month ago
}
1 month ago
}
[XmlIgnore]
[Category(LineProperty), DisplayName("充填"), PropertyOrder(8)]
[TypeConverter(typeof(Converter.YesNoConverter))]
public bool IsFill
{
get { return hasLineType(LineType.PLINE_SOLID); }
1 month ago
set
{
1 month ago
if (value) setLineType(LineType.PLINE_SOLID);
else clearLineType(LineType.PLINE_SOLID);
1 month ago
}
}
1 month ago
[XmlIgnore]
[Category(LineProperty), DisplayName("仅拐点处虚线"), PropertyOrder(9)]
[TypeConverter(typeof(Converter.YesNoConverter))]
public bool OnlyNodeVirture
{
get { return _curveVirture.OnlyNodeVirture; }
set { _curveVirture.OnlyNodeVirture = value; }
}
[XmlIgnore]
[Category(LineProperty), DisplayName("虚线 (有线长度 无线长度 ...)"), PropertyOrder(10)]
public string VirtureValues
{
get { return _curveVirture.VirtureValues; }
set { _curveVirture.VirtureValues = value; }
}
[XmlIgnore]
[Category(LineProperty), DisplayName("平行间距"), PropertyOrder(11)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double LineOffset
{
get { return Curve.Offset; }
set { Curve.Offset = value; }
}
// ==================== 波浪线属性(独立分类)====================
[XmlIgnore]
[Category(WaveProperty), DisplayName("周期"), PropertyOrder(1)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double WaveT
{
get { return _curveWave.T; }
set { _curveWave.T = value; }
}
[XmlIgnore]
[Category(WaveProperty), DisplayName("振幅"), PropertyOrder(2)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double WaveA
{
get { return _curveWave.A; }
set { _curveWave.A = value; }
}
[XmlIgnore]
[Category(WaveProperty), DisplayName("采样点数"), PropertyOrder(3)]
[TypeConverter(typeof(PropertyIntConverter))]
public int WaveNum
{
get { return _curveWave.dnum; }
set { _curveWave.dnum = value; }
}
// ==================== 内部对象 ====================
1 month ago
[Browsable(false)]
public InNameStyle Style { get; set; } = new InNameStyle();
1 month ago
1 month ago
private InNameText text;
[Browsable(false)]
public InNameText Text
{
get
{
if (text == null)
{
text = new InNameText();
text.Height = 60;
text.NumOrStep = 1;
text.ColorRef = 255;
}
return text;
}
1 month ago
set { text = value; }
1 month ago
}
1 month ago
1 month ago
[Browsable(false)]
public InNameCurve Curve { get; set; } = new InNameCurve();
1 month ago
private CurveVirtureType _curveVirture;
[Browsable(false)]
[XmlElement("VirtualLine")]
public CurveVirtureType CurveVirture
{
get { return _curveVirture; }
set { _curveVirture = value; }
}
private CurveWaveStyle _curveWave;
[Browsable(false)]
[XmlElement("Wave")]
public CurveWaveStyle CurveWave
{
get { return _curveWave; }
set { _curveWave = value; }
}
1 month ago
[Browsable(false)]
[XmlElement("Font")]
public LogFont NameFont { get; set; } = LogFont.Default;
1 month ago
[XmlIgnore]
[Category(OtherProperty), DisplayName("小数位数"), PropertyOrder(1)]
[TypeConverterAttribute(typeof(PropertyIntConverter))]
public int DecimalName
{
get { return Text.DecimalName; }
set { Text.DecimalName = value; }
}
1 month ago
public override PropertyDescriptorCollection ReOrderProperties(PropertyDescriptorCollection properties)
{
PropertyDescriptor itemHide = null;
if (InNameType == (int)LineType.PLINE_MARK_NAME_NUM)
itemHide = properties.Find("Step", true);
else
itemHide = properties.Find("NameNum", true);
var list = new PropertyDescriptor[properties.Count - 1];
int i = 0;
foreach (PropertyDescriptor pd in properties)
{
if (!pd.DisplayName.Equals(itemHide.DisplayName))
{
list[i] = pd;
i++;
}
}
return new PropertyDescriptorCollection(list, true);
}
1 month ago
private bool hasLineType(LineType lineType)
{
return (Style.Value & (int)lineType) != 0;
}
private void setLineType(LineType lineType)
{
Style.Value |= (int)lineType;
}
private void clearLineType(LineType lineType)
{
Style.Value &= ~(int)lineType;
}
1 month ago
}
1 month ago
1 month ago
public class InNameStyle
{
[XmlAttribute]
public int Value { get; set; } = (int)LineType.PLINE_SMOOTH_HEAD |
(int)LineType.PLINE_MARK_NAME_NUM |
Constants.PLINE_IN_NAME_AUTO_DECREASE;
}
public class InNameText
{
[XmlAttribute]
public double Height { get; set; }
1 month ago
1 month ago
[XmlAttribute("Color")]
public int ColorRef { get; set; }
1 month ago
1 month ago
[XmlAttribute]
public double NumOrStep { get; set; } = 1;
1 month ago
1 month ago
[XmlAttribute]
public double Offset { get; set; }
1 month ago
[XmlAttribute]
public int DecimalName { get; set; } = -1;
1 month ago
}
1 month ago
1 month ago
public class InNameCurve
{
[XmlAttribute]
public double Width { get; set; }
1 month ago
1 month ago
[XmlAttribute("Color")]
public int ColorRef { get; set; }
1 month ago
1 month ago
[XmlAttribute]
public double SmoothStep { get; set; }
1 month ago
[XmlAttribute]
public double Offset { get; set; } // 平行间距
1 month ago
}
1 month ago
}