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.
kev/Drawer/UCDraw/SigmaDrawerUtil/DrawerGlobalConfig.cs

212 lines
7.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace GeoSigma.SigmaDrawerUtil
{
/// <summary>
/// 全局设置
/// </summary>
public class DrawerGlobalConfig
{
private static DrawerGlobalConfig _globalConfig = null;
public static DrawerGlobalConfig Instance
{
get
{
if (_globalConfig == null)
{
_globalConfig = ReadFromFile();
}
return _globalConfig;
}
}
private static string configFile = Path.Combine(Application.StartupPath, "DrawGlobalConfig.xml");
/// <summary>
public RangSelectConfig RangSelectNode { get; set; } = new RangSelectConfig();
public FillConfig FillNode { get; set; } = new FillConfig();
public MeshColorEditConfig MeshColorEditNode { get; set; } = new MeshColorEditConfig();
public MeshConfig MeshNode { get; set; } = new MeshConfig();
/// 计算设置
/// </summary>
/// <summary>
/// Initializes a new instance of the <see cref="DrawerGlobalConfig"/> class.
/// </summary>
public DrawerGlobalConfig() { }
/// <summary>
/// Reads the specified XML file.
/// </summary>
/// <param name="xmlFile">The XML file.</param>
/// <returns>经读取生成的对象</returns>
private static DrawerGlobalConfig ReadFromFile()
{
//DialogResult result = DialogResult.Cancel;
string xmlFile = configFile;
if (!File.Exists(xmlFile))
{
return new DrawerGlobalConfig();
}
try
{
using (StreamReader reader = new StreamReader(xmlFile, Encoding.Default))
{
XmlSerializer serializer = new XmlSerializer(typeof(DrawerGlobalConfig));
DrawerGlobalConfig objRead = (DrawerGlobalConfig)serializer.Deserialize(reader);
return objRead;
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
/*
const string message =
"解析配置文件(DrawerGlobalConfig.xml)失败,点击确定创建缺省配置,点击取消保留错误配置文件!";
const string caption = "配置文件错误";
result = MessageBox.Show(message, caption,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Error);
*/
}
/*
if (result == DialogResult.OK)
{
return new DrawerGlobalConfig();
}
else
{
return null;
}
*/
return new DrawerGlobalConfig();
}
/// <summary>
/// Saves this instance.
/// </summary>
/// <returns>是否保存成功</returns>
public bool Save()
{
string xmlFile = configFile;
using (StreamWriter sw = new StreamWriter(xmlFile, false, Encoding.Default))
{
// 创建 XmlSerializer 实例
XmlSerializer serializer = new XmlSerializer(typeof(DrawerGlobalConfig));
// 将 MyClass 对象序列化到 XML
serializer.Serialize(sw, this);
}
return true;
}
}
/// <summary>
/// 相交面积因子
/// </summary>
public class RangSelectConfig
{
/// <summary>
/// Gets or sets 相交面积百分比.
/// </summary>
[System.ComponentModel.Category("相交面积"), System.ComponentModel.DisplayName("面积百分比")]
public int AreaFactor { get; set; } = 100;
}
/// <summary>
/// 区域填充相交填充相交延伸长度
/// </summary>
public class FillConfig
{
/// <summary>
/// Gets or sets 相交填充延伸长度.
/// </summary>
[System.ComponentModel.Category("相交填充"), System.ComponentModel.DisplayName("线段延伸长度")]
public int IntersectionExtendLength { get; set; } = 5000;
/*
/// <summary>
/// Gets or sets 自动填充延伸长度.
/// </summary>
[System.ComponentModel.Category("自动填充"), System.ComponentModel.DisplayName("线段延伸长度")]
public int AutoExtendLength { get; set; } = 50;
*/
}
/// <summary>
/// bool型数据属性转换
/// </summary>
public class CustomBooleanConverter : BooleanConverter
{
/// <inheritdoc/>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is bool)
{
return (bool)value ? "是" : "否";
}
return base.ConvertTo(context, culture, value, destinationType);
}
/// <summary>
/// Converts from.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="culture">The culture.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
string strValue = ((string)value).Trim().ToLower();
if (strValue == "是" || strValue == "true")
{
return true;
}
else if (strValue == "否" || strValue == "false")
{
return false;
}
}
return base.ConvertFrom(context, culture, value);
}
}
/// <summary>
/// 抗锯齿设置
/// </summary>
public class MeshConfig
{
/// <summary>
/// Gets or sets 是否抗锯齿.
/// </summary>
[System.ComponentModel.Category("抗锯齿设置"), System.ComponentModel.DisplayName("是否抗锯齿")]
[TypeConverter(typeof(CustomBooleanConverter))]
public bool AntiAliasingEnable { get; set; } = false;
}
public class MeshColorEditConfig
{
/// <summary>
/// Gets or sets 是否抗锯齿.
/// </summary>
[System.ComponentModel.Category("曲面颜色编辑设置"), System.ComponentModel.DisplayName("实时应用")]
[TypeConverter(typeof(CustomBooleanConverter))]
public bool AutoApplyEnable { get; set; } = false;
[System.ComponentModel.Category("曲面颜色编辑设置"), System.ComponentModel.DisplayName("循环获得颜色")]
[TypeConverter(typeof(CustomBooleanConverter))]
public bool LoopColorEnable { get; set; } = false;
}
}