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/SigmaDrawerStyle/ProportionProperty.cs

356 lines
11 KiB
C#

1 month ago
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using GeoSigmaDrawLib;
namespace GeoSigma.SigmaDrawerStyle
{
/// <summary>
/// 长度单位转换类
/// </summary>
public class UnitConverter : StringConverter
{
public static readonly string[] Units = new string[] { " ", "公里","千米", "米", "km", "m", " (公里)", " (千米)", " (米)", " (km)", " (m)" };
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(Units);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(int))
{
if (value is string v)
{
return Array.IndexOf(Units, v);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is int v)
{
if (v < 0) // 新建比例尺时是 -1
{
v = 0;
}
if (v < Units.Length)
{
return Units[v];
}
}
return base.ConvertFrom(context, culture, value);
}
}
public interface IProportionPropertyChange
{
void ChangeScale(double scale);
void ChangeNumber(int number);
void ChangeShowMode(int mode);
void ChangeUnit(int unit);
void ChangeColor(int r, int g, int b);
void ChangeTextScale(double scale);
void ChangeAlign(int align);
void ChangeTextHeight(double height);
void ChangeTextWidth(double width);
void ChangeTextHeightAlone(int alone);
void ChangeCoordinate(double x, double y);
void ChangeScaleHeight(double height);
}
public class ProportionProperty
{
public enum SHOWMODE
{
,
,
,
}
public enum ALONE
{
,
,
}
public enum ALIGN
{
,
,
,
}
//private static List<string> UnitsValues = new List<string>
//{
// "公里", "千米", "米", " (公里)"," (千米)"," (米)"
//};
[Browsable(false)]
public IProportionPropertyChange PropertyParent { get { return iChange; } set { iChange = value; } }
/// <summary>
/// Initializes a new instance of the <see cref="ProportionProperty"/> class.
/// </summary>
/// <param name="iChange">iChange</param>
public ProportionProperty(IProportionPropertyChange iChange)
{
this.iChange = iChange;
scale = 100;
number = 5;
textScale = 1;
align = ALIGN.;
textHeightAlone = ALONE.;
color = Color.Black;
showMode = SHOWMODE.;
}
public void FillData(ref ProportionData data)
{
data.x = xCoord;
data.y = yCoord;
data.ScaleLength = scale;
data.ScaleHeight = scaleHeight;
data.ViewMode = (int)showMode;
UnitConverter converter = new UnitConverter();
data.Unit = (int)converter.ConvertTo(proportionUnit, typeof(int));
data.num = number;
data.ColorR = color.R;
data.ColorG = color.G;
data.ColorB = color.B;
data.TextScale = textScale;
data.TextAlign = (int)align;
data.TextHeight = textHeight;
data.TextWidth = textWidth;
}
private IProportionPropertyChange iChange;
private double xCoord;
private double yCoord;
private double scale; //比例格式为 "1:xxxxx"
private double scaleHeight;
private Color color;
private SHOWMODE showMode;
private string proportionUnit;
private int number; //个数
private double textScale; //文本比例
private ALIGN align;//水平对齐:[水平居中]、左对齐、右对齐。
private double textHeight; //文字高度
private double textWidth; //文字宽度
private ALONE textHeightAlone; //是否可以单独改变高度
public void SetData(GeoSigmaDrawLib.ProportionData data)
{
xCoord = data.x;
yCoord = data.y;
scale = (double)data.ScaleLength;
scaleHeight = (double)data.ScaleHeight;
showMode = (SHOWMODE)data.ViewMode;
UnitConverter converter = new UnitConverter();
proportionUnit = (string)converter.ConvertFrom(data.Unit);
number = data.num;
color = Color.FromArgb(data.ColorR, data.ColorG, data.ColorB);
textScale = data.TextScale;
align = (ALIGN)data.TextAlign;
textHeight = (int)data.TextHeight;
textWidth = (int)data.TextWidth;
}
public void SetXY(double x, double y)
{
this.xCoord = x;
this.yCoord = y;
}
[Category("\t坐标"), DisplayName("\t\t\t\t\t\tX"), Browsable(false)]
public double XCoord
{
get => xCoord;
set
{
xCoord = value;
iChange.ChangeCoordinate(xCoord, yCoord);
}
}
[Category("\t坐标"), DisplayName("\t\t\t\t\t\tY"), Browsable(false)]
public double YCoord
{
get => yCoord;
set
{
yCoord = value;
iChange.ChangeCoordinate(xCoord, yCoord);
}
}
[Category("\t基本属性"), DisplayName("\t\t\t\t\t\t刻度间隔")]
public double Scale
{
get => scale;
set
{
scale = value;
iChange.ChangeScale(scale);
//if (value.Length < 3)
//{
// MessageBox.Show("比例不合法,请重新输入。", "提示");
//}
//else
//{
// if (value[0] != '1' || value[1] != ':')
// {
// MessageBox.Show("比例不合法,请重新输入。", "提示");
// }
// else
// {
// string scaleStr = value.Substring(2);
// int scale = 0;
// if (!int.TryParse(scaleStr, out scale))
// {
// MessageBox.Show("比例不合法,请重新输入。", "提示");
// }
// else
// {
// scaleString = value;
// iChange.ChangeScale(scale);
// }
// }
//}
}
}
[Category("\t基本属性"), DisplayName("\t\t\t\t\t\t显示模式")]
public SHOWMODE ShowMode1
{
get => showMode;
set
{
showMode = value;
iChange.ChangeShowMode((int)showMode);
}
}
[Category("\t基本属性"), TypeConverter(typeof(UnitConverter)), DisplayName("\t\t\t\t\t\t单位")]
public string ProportionUnit
{
get => proportionUnit;
set
{
proportionUnit = value;
int type = Array.IndexOf(UnitConverter.Units, value);
if (type == -1)
{
type = 0;
}
iChange.ChangeUnit(type);
}
}
[Category("\t基本属性"), DisplayName("\t\t\t\t\t\t高度")]
public double ScaleHeight
{
get => scaleHeight;
set
{
scaleHeight = value;
iChange.ChangeScaleHeight(scaleHeight);
}
}
[Category("\t基本属性"), DisplayName("\t\t\t\t\t\t个数")]
public int Number
{ get => number;
set
{
number = value;
iChange.ChangeNumber(number);
}
}
[Category("\t基本属性"), DisplayName("\t\t\t\t\t\t颜色")]
[Editor(typeof(PropertyEditorColor), typeof(UITypeEditor))]
[TypeConverter(typeof(PropertyColorIndicatorConvert))]
public Color Color
{
get => color;
set
{
color = value;
iChange.ChangeColor(color.R, color.G, color.B);
}
}
[Category("\t文本属性"), DisplayName("\t\t\t\t\t\t文本比例")]
public double TextScale
{
get => textScale;
set
{
textScale = value;
iChange.ChangeTextScale(textScale);
}
}
[Category("\t文本属性"), DisplayName("\t\t\t\t\t\t水平对齐")]
public ALIGN Aligin
{
get => align;
set
{
align = value;
iChange.ChangeAlign((int)align);
}
}
[Category("\t文本属性"), DisplayName("\t\t\t\t\t\t文字高度")]
public double TextHeight
{
get => textHeight;
set
{
textHeight = value;
textWidth = textHeight * 0.4;
iChange.ChangeTextHeight(textHeight);
}
}
[Category("\t文本属性"), DisplayName("\t\t\t\t\t\t文字宽度"),Browsable(false)]
public double TextWidth
{
get => TextHeight * 0.4;
set
{
textWidth = value;
iChange.ChangeTextWidth(textWidth);
}
}
[Category("\t文本属性"), DisplayName("\t\t\t\t\t\t宽度可单独调整"), Browsable(false)]
public ALONE TextHeightAlone
{
get => textHeightAlone;
set
{
textHeightAlone = value;
if (value == ALONE.)
{
iChange.ChangeTextHeightAlone(1);
}
else
{
iChange.ChangeTextHeightAlone(0);
}
}
}
}
}