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.

368 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace SigmaDrawerElement
{
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
public class DrawerCoordinateXY
{
[XmlText]
[Browsable(false)]
public string Text
{
get
{
return $"{X},{Y}";
}
set
{
var arr = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 2)
{
X = Convert.ToDouble(arr[0]);
Y = Convert.ToDouble(arr[1]);
}
}
}
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double X { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Y { get; set; }
public override string ToString()
{
return $"{X},{Y}";
}
}
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
public class DrawerCoordinateXYZ
{
[XmlText]
[Browsable(false)]
public string Text
{
get
{
return $"{X},{Y},{Z}";
}
set
{
var arr = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length >= 2)
{
X = Convert.ToDouble(arr[0]);
Y = Convert.ToDouble(arr[1]);
}
if (arr.Length >= 3)
{
Z = Convert.ToDouble(arr[1]);
}
}
}
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double X { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Y { get; set; }
[Browsable(false)]
[XmlIgnore]
public double Z { get; set; }
public override string ToString()
{
return $"{X},{Y}";
}
}
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
public class DrawerCoordinateLBTR
{
[XmlText]
[Browsable(false)]
public string Text
{
get
{
return $"{Left},{Bottom} {Right},{Top}";
}
set
{
var arr = value.Split(new string[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 4)
{
Left = Convert.ToDouble(arr[0]);
Bottom = Convert.ToDouble(arr[1]);
Right = Convert.ToDouble(arr[2]);
Top = Convert.ToDouble(arr[3]);
}
}
}
#region Helper
[XmlIgnore]
public DrawerRange RangeDelta { get; private set; }
[XmlIgnore]
public Size SizeDelta { get; private set; }
public DrawerCoordinateLBTR()
{
RangeDelta = new DrawerRange(this);
SizeDelta = new Size(this);
}
#endregion
public void Create(double left, double right, double top, double bottom)
{
this.Left = left;
this.Right = right;
this.Top = top;
this.Bottom = bottom;
SizeDelta = new Size(this);
RangeDelta = new DrawerRange(this);
}
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Left { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Bottom { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Right { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Top { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Width
{
get
{
return Right - Left;
}
set
{
this.Right = value - Left;
}
}
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
[XmlIgnore]
public double Height
{
get
{
return Top - Bottom;
}
set
{
this.Top = Bottom + value;
}
}
public class Size
{
private DrawerCoordinateLBTR _parent;
public Size()
{
}
public Size(DrawerCoordinateLBTR parent)
{
_parent = parent;
}
[DisplayName("\t宽度")]
public double Width
{
get => _parent.Width;
set => _parent.Width = value;
}
[DisplayName("高度")]
public double Height
{
get => _parent.Height;
set => _parent.Height = value;
}
public override string ToString()
{
return $"{Width},{Height}";
}
}
}
public class DrawerRange
{
private DrawerCoordinateLBTR _parent;
public DrawerRange(DrawerCoordinateLBTR parent)
{
_parent = parent;
}
[DisplayName("\t\t\t左")]
public double Left
{
get => _parent.Left;
set => _parent.Left = value;
}
[DisplayName("下")]
public double Bottom
{
get => _parent.Bottom;
set => _parent.Bottom = value;
}
[DisplayName("\t右")]
public double Right
{
get => _parent.Right;
set => _parent.Right = value;
}
[DisplayName("\t\t上")]
public double Top
{
get => _parent.Top;
set => _parent.Top = value;
}
public override string ToString()
{
return $"{Left},{Top} {Right},{Bottom}";
}
}
public class DrawerWithCenter : ElementBase
{
#region Coordinate
[Browsable(false)]
[XmlAttribute("Color")]
public int ColorRef;
[XmlIgnore]
[Category("基本信息"), DisplayName("颜色")]
public Color LineColor
{
get
{
return ColorTranslator.FromWin32(ColorRef);
}
set
{
ColorRef = ColorTranslator.ToWin32(value);
}
}
public class CoordinateClass
{
public class PointClass
{
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
public double X { get; set; }
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
public double Y { get; set; }
public override string ToString()
{
return $"{X},{Y}";
}
}
public class SizeClass
{
[DisplayName("横半径")]
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
public double Width { get; set; }
[DisplayName("纵半径")]
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.Double8Converter))]
public double Height { get; set; }
public override string ToString()
{
return $"{Width},{Height}";
}
}
[XmlText]
[Browsable(false)]
public string Text
{
get
{
return $"{Point.X},{Point.Y} {Point.X + Size.Width},{Point.Y + Size.Height}";
}
set
{
var arr = value.Split(new string[] { ",", " ", "\t" }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 4)
{
Point.X = Convert.ToDouble(arr[0]);
Point.Y = Convert.ToDouble(arr[1]);
var xMax = Convert.ToDouble(arr[2]);
var yMax = Convert.ToDouble(arr[3]);
Size.Width = xMax - Point.X;
Size.Height = yMax - Point.Y;
}
}
}
[XmlIgnore]
public PointClass Point { get; set; } = new PointClass();
[XmlIgnore]
public SizeClass Size { get; set; } = new SizeClass();
}
[Browsable(false)]
[XmlElement("Coordinate")]
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
public CoordinateClass Coordinate { get; set; } = new CoordinateClass();
[XmlIgnore]
[Category("基本信息"), DisplayName("\t\t\t\t圆心坐标")]
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
public CoordinateClass.PointClass Point
{
get => Coordinate.Point;
set => Coordinate.Point = value;
}
[XmlIgnore]
[Category("基本信息"), DisplayName("\t\t\t半径")]
[TypeConverter(typeof(GeoSigma.SigmaDrawerStyle.Converter.BaseExpandableConverter))]
public CoordinateClass.SizeClass Size
{
get => Coordinate.Size;
set => Coordinate.Size = value;
}
#endregion
}
}