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.

267 lines
8.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Xml.Serialization;
using GeoSigma.SigmaDrawerStyle;
using GeoSigma.SigmaDrawerStyle.Converter;
using SigmaDrawerStyle;
using System.Reflection;
using System.Globalization;
using System.Linq;
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 WellSectionSetting
{
private const string scaleCategory = "\t\t比例";
private const string properCategory = "\t属性";
[XmlIgnore]
[Category(scaleCategory)]
[DisplayName("海拔比例")]
[PropertyOrder(0)]
[TypeConverter(typeof(ScaleMappingConverter))]
public string levelScale
{
get => msections.Section.LevelScale.ToString();
set => msections.Section.LevelScale = Convert.ToInt32(value);
}
[XmlIgnore]
[Category(scaleCategory)]
[DisplayName("深度比例")]
[PropertyOrder(1)]
[TypeConverter(typeof(ScaleMappingConverter))]
public string depthScale
{
get => msections.Section.DepthScale.ToString();
set => msections.Section.DepthScale = Convert.ToInt32(value);
}
[XmlIgnore]
[Category(scaleCategory)]
[DisplayName("水平比例")]
[PropertyOrder(2)]
[TypeConverter(typeof(ScaleMappingConverter))]
public string horzScale
{
get => msections.Section.HorzScale.ToString();
set => msections.Section.HorzScale = Convert.ToInt32(value);
}
[XmlIgnore]
[Category(properCategory)]
[DisplayName("井柱模式")]
[PropertyOrder(3)]
[TypeConverter(typeof(SectionWellColumnStyleConverter))]
public string displayMode
{
get => msections.Section.DisplayMode;
set => msections.Section.DisplayMode = value;
}
[XmlElement("Sections")]
[Browsable(false)]
public Sections msections { get; set; }
}
public class ScaleMappingConverter : TypeConverter
{
private static readonly Dictionary<string, string> ValueMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "50", "1:50" },
{ "100", "1:100" },
{ "200", "1:200" },
{ "400", "1:400" },
{ "500", "1:500" },
{ "800", "1:800" },
{ "1000", "1:1000" },
{ "1500", "1:1500" },
{ "2000", "1:2000" },
{ "2500", "1:2500" },
{ "3000", "1:3000" },
{ "4000", "1:4000" },
{ "5000", "1:5000" },
{ "6000", "1:6000" },
{ "8000", "1:8000" },
{ "10000", "1:10000" },
{ "15000", "1:15000" },
{ "20000", "1:20000" },
{ "30000", "1:30000" },
{ "40000", "1:40000" },
{ "50000", "1:50000" },
};
private static readonly Dictionary<string, string> 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[] { "1:50", "1:100", "1:200", "1:400", "1:500", "1:800", "1:1000" , "1:1500" , "1:2000"
,"1:2500","1:3000" ,"1:4000","1:5000" ,"1:6000","1:8000","1:10000","1:15000","1:20000","1:30000" ,"1:40000" ,"1:50000"});
}
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 stringValue)
{
// 将内部值映射为显示值
if (ValueMap.TryGetValue(stringValue, out var displayValue))
{
return displayValue;
}
return stringValue; // 如果没有映射,返回原值
}
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 SectionWellColumnStyleConverter : GenericStringMapConverter<WellSectionSetting>
{
protected override Dictionary<string, string> ValueMap => new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["Normal"] = "测深模式",
["Vertical"] = "垂深模式",
["VerticalBevel"] = "轨迹模式",
};
protected override string[] GetOptions(WellSectionSetting wellsection)
{
return new[] { "测深模式","垂深模式", "轨迹模式" };
}
}
public class Sections
{
[XmlElement("Section")]
public Section Section { get; set; }
}
public class Section
{
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlAttribute("Index")]
public int Index { get; set; }
[XmlAttribute("WellCount")]
public int WellCount { get; set; }
[XmlAttribute("DisplayMode")]
public string DisplayMode { get; set; }
[XmlAttribute("SedimentaryFacies")]
public int SedimentaryFacies { get; set; }
[XmlAttribute("SandVerdict")]
public int SandVerdict { get; set; }
[XmlAttribute("IsActivate")]
public bool IsActivate { get; set; }
[XmlAttribute("IsDrawWellTitleDefault")]
public bool IsDrawWellTitleDefault { get; set; }
[XmlAttribute("WellsSameY")]
public bool WellsSameY { get; set; }
[XmlAttribute("DrawWellGridVertDepth")]
public bool DrawWellGridVertDepth { get; set; }
[XmlAttribute("BendLinkStyle")]
public string BendLinkStyle { get; set; }
[XmlAttribute("FlatLevelBase")]
public bool FlatLevelBase { get; set; }
[XmlAttribute("WellStyle")]
public string WellStyle { get; set; }
[XmlAttribute("Visible")]
public bool Visible { get; set; }
[XmlAttribute("BendBlendFacies")]
public bool BendBlendFacies { get; set; }
[XmlAttribute("Top")]
public double Top { get; set; }
[XmlAttribute("Bottom")]
public double Bottom { get; set; }
[XmlAttribute("Left")]
public double Left { get; set; }
[XmlAttribute("Right")]
public double Right { get; set; }
[XmlAttribute("LevelScale")]
public int LevelScale { get; set; }
[XmlAttribute("DepthScale")]
public int DepthScale { get; set; }
[XmlAttribute("HorzScale")]
public int HorzScale { get; set; }
[XmlElement("Wells")]
public Wells Wells { get; set; }
}
public class Wells
{
[XmlElement("Well")]
public List<Well> WellList { get; set; }
}
public class Well
{
[XmlAttribute("WellName")]
public string WellName { get; set; }
[XmlAttribute("BaseDepth")]
public double BaseDepth { get; set; }
[XmlAttribute("TopDepth")]
public double TopDepth { get; set; }
[XmlAttribute("Length")]
public double Length { get; set; }
[XmlAttribute("HorizDistance")]
public double HorizDistance { get; set; }
}
}