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.

204 lines
5.7 KiB
C#

// <copyright file="DrawerPoint.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
using GeoSigma.SigmaDrawerStyle;
using GeoSigmaDrawLib;
using SigmaDrawerStyle;
namespace SigmaDrawerElement
{
/// <summary>
/// 点类图元
/// </summary>
[TypeConverter(typeof(PropertySorter))]
public class DrawerPoint : ElementBase, INotifyPropertyChanged
{
/// <summary>
/// 属性类别排序
/// </summary>
private List<string> categorys = new List<string>() { "基础属性", "数据", "其他", "杂项" };
/// <summary>
/// Initializes a new instance of the <see cref="DrawerPoint"/> class.
/// </summary>
public DrawerPoint()
{
ElementType = DrawElementType.ELEMENT_POINT;
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawerPoint"/> class.
/// </summary>
/// <param name="name">名称</param>
/// <param name="x">坐标X</param>
/// <param name="y">坐标Y</param>
/// <param name="z">坐标Z</param>
/// <param name="angle">角度</param>
public DrawerPoint(string name, double x, double y, double z, double angle)
{
Name = name;
X = x;
Y = y;
Z = z;
Angle = angle;
}
// [Category("数据"), DisplayName("角度")]
[Browsable(false)]
[XmlElement("Base")]
public DrawerPointBase Base { get; set; } = new DrawerPointBase();
[XmlIgnore]
[Category("数据"), DisplayName("名字"), PropertyOrder(0)]
public override string Name
{
get
{
return Base.Name;
}
set
{
if (Base.Name != value)
{
Base.Name = value;
OnPropertyChanged(nameof(Name));
}
}
}
[XmlIgnore]
[Category("数据"), DisplayName("X"), PropertyOrder(1)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double X
{
get { return Base.X; }
set
{
if (Base.X != value)
{
Base.X = value;
OnPropertyChanged(nameof(X));
}
}
}
[XmlIgnore]
[Category("数据"), DisplayName("Y"), PropertyOrder(2)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Y
{
get { return Base.Y; }
set
{
if (Base.Y != value)
{
Base.Y = value;
OnPropertyChanged(nameof(Y));
}
}
}
[XmlIgnore]
[Browsable(false)]
[Category("数据"), DisplayName("Z"), PropertyOrder(3)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Z
{
get { return Base.Z; }
set
{
if (Base.Z != value)
{
Base.Z = value;
OnPropertyChanged(nameof(Z));
}
}
}
[XmlIgnore]
[Category("数据"), DisplayName("Z"), PropertyOrder(3)]
public string ZDisplay
{
get
{
if (Z == Constants.InvalidDouble)
{
return string.Empty;
}
else
{
return $"{Z}";
}
}
set
{
if (double.TryParse(value, out double z))
{
Z = z;
}
else
{
Z = Constants.InvalidDouble;
}
}
}
[XmlIgnore]
[Category("数据"), DisplayName("角度"), PropertyOrder(4)]
[TypeConverter(typeof(PropertyDoubleConverter))]
public double Angle
{
get
{
return Base.Angle;
}
set
{
Base.Angle = value;
}
}
public void Offset(double dx, double dy)
{
this.X = this.X + dx;
this.Y = this.Y + dy;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// Dfd格式字符串
/// </summary>
/// <returns>字符串</returns>
public override string ToDfdString()
{
return $"3dPoint {X},{Y},{Z} {Angle} {Name}";
}
public void CopyTo(DrawerPoint other)
{
if (other == null)
{
other = new DrawerPoint();
}
base.CopyTo(other);
other.Name = this.Name;
other.X = this.X;
other.Y = this.Y;
other.Z = this.Z;
other.Angle = this.Angle;
}
}
public class DrawerPointBase
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public double X { get; set; }
[XmlAttribute]
public double Y { get; set; }
[XmlAttribute]
public double Z { get; set; } = Constants.InvalidDouble;
[XmlAttribute]
public double Angle { get; set; }
}
}