using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Drawing; #if NET8_0 #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 { /// /// 属性类别排序 /// private List categorys = new List() { "基础属性", "文字", "线属性" }; /// /// Initializes a new instance of the class. /// public CurveInName() { TypeName = "内部写名字"; object obj = null; //SetPropertyDescription(ref obj,"", "步长"); } private Font _TextFont; [XmlIgnore] [Category("文字"), DisplayName("字体"), PropertyOrder(1)] [TypeConverterAttribute(typeof(FontPropertyConvert))] public Font TextFont { get { _TextFont = Font.FromLogFont(NameFont); return _TextFont; } set { _TextFont = value; NameFont = LogFontConverter.convert(_TextFont); } } [XmlIgnore] [Category("文字"), DisplayName("高度"), PropertyOrder(2)] [TypeConverter(typeof(PropertyDoubleConverter))] public double TextHeight { get { return Text.Height; } set { Text.Height = value; } } /// /// 数目或步长 /// [XmlIgnore] [Category("文字"), DisplayName("步长|数目"), PropertyOrder(3)] [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; } } [Browsable(true)] [XmlIgnore] [Category("文字"), DisplayName("数目"), PropertyOrder(4)] [Range(1,100)] public int NameNum { get { return (int)(Text.NumOrStep + 0.0001); } set { if (value <= 0) { throw new ArgumentOutOfRangeException("数目必须大于0。"); } Text.NumOrStep = value; } } [Browsable(true)] [XmlIgnore] [Category("文字"), DisplayName("步长"), PropertyOrder(5)] [Range(0.01, double.MaxValue)] [TypeConverter(typeof(PropertyDoubleConverter))] public double Step { get { return Text.NumOrStep; } set { if (value <= 0) { throw new ArgumentOutOfRangeException("步长必须大于0。"); } Text.NumOrStep = value; } } [XmlIgnore] [Category("文字"), DisplayName("偏移"), PropertyOrder(6)] [TypeConverter(typeof(PropertyDoubleConverter))] public double Offset { get { return Text.Offset; } set { Text.Offset = value; } } [XmlIgnore] [Category("文字"), DisplayName("颜色"), PropertyOrder(7)] #if NET8_0 #else [Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))] #endif [TypeConverter(typeof(PropertyColorIndicatorConvert))] public Color TextColor { get { return ColorTranslator.FromWin32(Text.ColorRef); } set { Text.ColorRef = ColorTranslator.ToWin32(value); } } [XmlIgnore] [Category("文字"), DisplayName("自动缩小字体"), PropertyOrder(8)] [TypeConverter(typeof(Converter.YesNoConverter))] public bool AutoDecrease { get { if ((Style.Value & (int)Constants.PLINE_IN_NAME_AUTO_DECREASE) != 0) return true; return false; } set { if (value == true) { Style.Value |= (int)Constants.PLINE_IN_NAME_AUTO_DECREASE; } else { Style.Value &= ~(int)Constants.PLINE_IN_NAME_AUTO_DECREASE; } } } [XmlIgnore] [Category("线属性"), DisplayName("宽度"), PropertyOrder(1)] [TypeConverter(typeof(PropertyDoubleConverter))] public double Width { get { return Curve.Width; } set { Curve.Width = value; } } [XmlIgnore] [Category("线属性"), DisplayName("颜色"), PropertyOrder(2)] #if NET8_0 #else [Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))] #endif [TypeConverter(typeof(PropertyColorIndicatorConvert))] public Color CurveColor { get { return ColorTranslator.FromWin32(Curve.ColorRef); } set { Curve.ColorRef = ColorTranslator.ToWin32(value); } } [XmlIgnore] [Category("线属性"), DisplayName("显示方式"), PropertyOrder(3)] [TypeConverter(typeof(Converter.LineTypeConverter))] public int CurveType { get { return Style.Value & (int)LineType.PLINE_TYPE_ALL; } set { Style.Value &= ~((int)LineType.PLINE_TYPE_ALL); Style.Value |= value; } } [XmlIgnore] [Category("线属性"), DisplayName("圆头显示"), PropertyOrder(4)] [TypeConverter(typeof(Converter.YesNoConverter))] public bool SmoothHead { get { return (Style.Value & (int)LineType.PLINE_SMOOTH_HEAD) != 0; } set { if (value) { Style.Value |= (int)LineType.PLINE_SMOOTH_HEAD; } else { Style.Value &= ~(int)LineType.PLINE_SMOOTH_HEAD; } } } [XmlIgnore] [Category("线属性"), DisplayName("光滑步长"), PropertyOrder(5)] [TypeConverter(typeof(PropertyDoubleConverter))] public double SmoothStep { get { return Curve.SmoothStep; } set { Curve.SmoothStep = value; } } [Browsable(false)] public InNameStyle Style { get; set; } = new InNameStyle(); 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; } set { text = value; } } [Browsable(false)] public InNameCurve Curve { get; set; } = new InNameCurve(); [Browsable(false)] [XmlElement("Font")] public LogFont NameFont { get; set; } = LogFont.Default; 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 properties; return new PropertyDescriptorCollection(list, true); } } 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; } [XmlAttribute("Color")] public int ColorRef { get; set; } [XmlAttribute] public double NumOrStep { get; set; } = 1; [XmlAttribute] public double Offset { get; set; } } public class InNameCurve { [XmlAttribute] public double Width { get; set; } [XmlAttribute("Color")] public int ColorRef { get; set; } [XmlAttribute] public double SmoothStep { get; set; } } }