using GeoSigma.SigmaDrawerStyle; using GeoSigma.SigmaDrawerStyle.Converter; using SigmaDrawerElement; using SigmaDrawerStyle; using System.ComponentModel; using System.Drawing; using System.Drawing.Design; using System.Globalization; using System.Xml.Serialization; namespace GeoSigma.SigmaDrawerElement { #pragma warning disable SA1402 // File may only contain a single type #pragma warning disable SA1600 // Elements should be documented #pragma warning disable SA1649 // File name should match first type name /// /// 解释分层道属性 /// [XmlRoot("Pcg")] [TypeConverter(typeof(PropertySorter))] public class WellInterpretationLayerTrack { private const string InterpLayerTrackCategory = "\t\t\t解释分层道"; private const string InterpSymbolCategory = "\t\t解释符号"; private const string MarkCategory = "\t数据子对象"; // --- 解释分层道 --- [XmlIgnore] [Category(InterpLayerTrackCategory)] [DisplayName("标题")] [PropertyOrder(0)] public string Title { get => WellTrack.Title.Font.Text; set => WellTrack.Title.Font.Text = value; } [XmlIgnore] [Category(InterpLayerTrackCategory)] [DisplayName("宽度")] [PropertyOrder(1)] public double Width { get => WellTrack.Width; set => WellTrack.Width = value; } [XmlIgnore] [Category(InterpLayerTrackCategory)] [DisplayName("填充")] [TypeConverter(typeof(YesNoConverter))] [PropertyOrder(2)] public bool IsFill { get => WellTrack.BackFill != 0; set => WellTrack.BackFill = value ? 1 : 0; } [XmlIgnore] [Category(InterpLayerTrackCategory)] [DisplayName("背景颜色")] [PropertyOrder(3)] [Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))] public Color BackgroundColor { get => ColorTranslator2.FromHtml(WellTrack.BackColor); set => WellTrack.BackColor = ColorTranslator2.ToHtml(value); } [XmlIgnore] [Category(InterpLayerTrackCategory)] [DisplayName("道头字体")] [Editor(typeof(PropertyEditorWellFontEx), typeof(UITypeEditor))] [PropertyOrder(4)] public WellFontEx HeaderFont { get => WellTrack.Title.Font; set => WellTrack.Title.Font = value; } [XmlIgnore] [Category(MarkCategory)] [DisplayName("字体")] [PropertyOrder(7)] [Editor(typeof(PropertyEditorWellFontEx), typeof(UITypeEditor))] public WellFontEx ObjectFont { get => LayerStyleHelper.GetFontEx(WellTrack.LayerStyle); set => LayerStyleHelper.SetFontEx(WellTrack.LayerStyle, value); } [XmlIgnore] [Category(MarkCategory)] [DisplayName("显示类型")] [TypeConverter(typeof(TrackResultRenderTypeConverter))] [PropertyOrder(8)] public string renderType { get => extendedData.data.renderType; set => extendedData.data.renderType = value; } [XmlIgnore] [Category(MarkCategory)] [DisplayName("标注类型")] [TypeConverter(typeof(TrackResultMarkTypeConverter))] [PropertyOrder(9)] public string markType { get => extendedData.data.showMarkType; set => extendedData.data.showMarkType = value; } [Browsable(false)] [XmlAttribute("Version")] public int Version { get; set; } [Browsable(false)] [XmlElement("WellTrack")] public WellTrackWellTrack WellTrack { get; set; } [Browsable(false)] [XmlElement("ExtendedData")] public TrackResultExtendedData extendedData { get; set; } } public class TrackResultInExtendedData { [XmlAttribute("SandRenderType")] public string renderType { get; set; } [XmlAttribute("ShowMarkType")] public string showMarkType { get; set; } } public class TrackResultExtendedData { [XmlAttribute("type")] public string type { get; set; } [XmlElement("Data")] public TrackResultInExtendedData data { get; set; } } public class TrackResultRenderTypeConverter : TypeConverter { private static readonly Dictionary ValueMap = new Dictionary() // (StringComparer.OrdinalIgnoreCase) {//以后还会添加上,下 { "", "" }, { "Standard", "标准" }, { "Brief", "简明" }, }; private static readonly Dictionary ReverseMap = ValueMap.GroupBy(kvp => kvp.Value).ToDictionary(g => g.Key, g => g.First().Key); public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true; public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true; public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection(new[] { "", "标准", "简明" }); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)//进行逆向转换时要重新写这个函数 { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value is string iValue) { // 将内部值映射为显示值 if (ValueMap.TryGetValue(iValue, out var displayValue)) { return displayValue; } return iValue; // 如果没有映射,返回原值 } return base.ConvertTo(context, culture, value, destinationType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string stringValue) { // 将显示值映射回内部值 if (ReverseMap.TryGetValue(stringValue, out var internalValue)) { return internalValue; } return stringValue; // 如果没有映射,返回原值 } return base.ConvertFrom(context, culture, value); } } public class TrackResultMarkTypeConverter : TypeConverter { private static readonly Dictionary ValueMap = new Dictionary() // (StringComparer.OrdinalIgnoreCase) {//以后还会添加上,下 { "", "" }, { "Name", "层名" }, { "Thickness", "厚度" }, { "PureThickness", "纯厚度" }, { "ResultName", "解释结果名称" }, }; private static readonly Dictionary ReverseMap = ValueMap.GroupBy(kvp => kvp.Value).ToDictionary(g => g.Key, g => g.First().Key); public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true; public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true; public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection(new[] { "", "层名", "厚度", "纯厚度", "解释结果名称" }); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)//进行逆向转换时要重新写这个函数 { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value is string iValue) { // 将内部值映射为显示值 if (ValueMap.TryGetValue(iValue, out var displayValue)) { return displayValue; } return iValue; // 如果没有映射,返回原值 } return base.ConvertTo(context, culture, value, destinationType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string stringValue) { // 将显示值映射回内部值 if (ReverseMap.TryGetValue(stringValue, out var internalValue)) { return internalValue; } return stringValue; // 如果没有映射,返回原值 } return base.ConvertFrom(context, culture, value); } } #pragma warning restore SA1649 // File name should match first type name #pragma warning restore SA1600 // Elements should be documented #pragma warning restore SA1402 // File may only contain a single type }