| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Shapes;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils.DB;
- namespace SAGA.Models {
- [TableName("DataNode")]
- [Serializable]
- public class DataNode {
- public int Id { get; set; }
- /// <summary>
- /// 设备revitID
- /// </summary>
- public string EId { get; set; }
- /// <summary>
- /// 楼层名称
- /// </summary>
- public string FloorName { get; set; }
- private string name;
- /// <summary>
- /// 本地名称
- /// </summary>
- public string EName
- {
- get => string.IsNullOrEmpty(this.name) ? this.EId : this.name;
- set => this.name = value;
- }
- /// <summary>
- /// 本地编码
- /// </summary>
- public string Sno { get; set; }
- /// <summary>
- /// 进线号(主电)
- /// </summary>
- public string InLineNo { get; set; }
- /// <summary>
- /// 进线号(备电)
- /// </summary>
- public string InLineNo1 { get; set; }
- /// <summary>
- /// 设备类型
- /// </summary>
- public string Type { get; set; }
- public DataNode Parent { get; set; }
- public List<DataNode> Childrens { get; set; } = new List<DataNode>();
- public Point Postition { get; set; }
- /// <summary>
- /// 用于显示属性窗体
- /// </summary>
- public JObject Infos { get; set; }
- private object data;
- public T GetData<T>() {
- if (data is T t) {
- return t;
- }
- return default(T);
- }
- public void SetData(object odata) {
- this.data = odata;
- }
- //public object Data { get; set; }
- public DataNode() {
- }
- public DataNode(string name) {
- this.name = name;
- this.Childrens = new List<DataNode>();
- }
- public DataNode(string name, DataNode parent) : this(name) {
- this.Parent = parent;
- }
- public Vertex GetVertex(double y) {
- this.Postition = new Point(this.Postition.X, y);
- return this.GetVertex();
- }
- public Vertex GetVertex(Point point) {
- this.Postition = point;
- return this.GetVertex();
- }
- public Vertex GetVertex() {
- var v = new Vertex(Postition) {
- ElementId = this.EId,
- RadiusX = 6,
- RadiusY = 6
- };
- this.Childrens.ForEach(t => {
- t.Postition = new Point(this.Postition.X + 270, this.Postition.Y);
- });
- return v;
- }
- public TextBlock GetText() {
- Border border = new Border() {
- Width = 140,
- Height = 100,
- BorderBrush = Brushes.Red,
- BorderThickness = new Thickness(1),
- Opacity = 0,
- CornerRadius = new CornerRadius(2),
- Background = Brushes.Azure
- };
- TextBlock label = new TextBlock {
- Text = RemoveNull(this.FloorName+":"+ this.Sno + ":" + this.EName),
- Width = 200,
- TextWrapping = TextWrapping.Wrap
- };
- string RemoveNull(string str)
- {
- return string.Join(":", str.Split(':').Where(t => !string.IsNullOrEmpty(t)));
- }
- // border.Child = label;
- Canvas.SetLeft(label, Postition.X - 70);
- Canvas.SetTop(label, Postition.Y - 12);
- return label;
- }
- public List<SgLine> GetLines() {
- List<SgLine> lines = new List<SgLine>();
- var n = Childrens.Count;
- for (int i = 1; i < n + 1; i++) {
- var angle = 180d / (n + 1) * i + 90 - 90 * (n % 2 - 1);
- SgLine line = new SgLine(Postition, angle);
- lines.Add(line);
- SgLine line1 = new SgLine(line.EndPoint, new Point(line.EndPoint.X + 40, line.EndPoint.Y));
- lines.Add(line1);
- Childrens[i - 1].Postition = line1.EndPoint;
- }
- return lines;
- }
- }
- public class Vertex : Shape, IVertex {
- protected override Geometry DefiningGeometry => new EllipseGeometry {
- Center = Position,
- RadiusX = RadiusX,
- RadiusY = RadiusY
- };
- public Point Position { get; set; }
- public string ElementId { get; set; }
- public Action<string> ShowAction { set; private get; }
- private static double radiusX = 1.6;
- private static double radiusY = 1.6;
- public static void SetRadius(double x, double y) {
- radiusX = x;
- radiusY = y;
- }
- public double RadiusX
- {
- get => radiusX;
- set => radiusX = value;
- }
- public double RadiusY
- {
- get => radiusY;
- set => radiusY = value;
- }
- public Vertex(Point center) {
- this.Fill = Brushes.Red;
- this.Position = center;
- this.MouseLeftButtonDown += Vertex_MouseLeftButtonDown;
- //this.MouseEnter += Vertex_MouseEnter;
- // this.MouseLeave += Vertex_MouseLeave;
- }
- private void Vertex_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) {
- if (Fill != Brushes.Transparent) {//空心不适用事件
- this.Fill = Brushes.Red;
- this.RadiusY = RadiusY / 2.0d;
- this.RadiusX /= 2.0d;
- }
- }
- private void Vertex_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {
- if (Fill != Brushes.Transparent) {//空心不适用事件
- this.Fill = Brushes.Blue;
- this.RadiusY = RadiusY * 2;
- this.RadiusX *= 2;
- }
- }
- private void Vertex_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
- ShowAction?.Invoke(this.ElementId);
- }
- public static Vertex GetHollow(Point center) {
- return new Vertex(center) {
- StrokeThickness = 2,
- Stroke = Brushes.Red,
- Fill = Brushes.Transparent
- };
- }
- }
- public interface IVertex {
- Point Position { get; }
- double RadiusX { get; set; }
- double RadiusY { get; set; }
- }
- public interface ILine {
- Point StartPoint { get; set; }
- Point EndPoint { get; set; }
- }
- public class SgLine : Shape, ILine {
- protected override Geometry DefiningGeometry => new LineGeometry(StartPoint, EndPoint);
- public Point StartPoint { get; set; }
- public Point EndPoint { get; set; }
- public double Length { get; set; } = 50;
- public double Angle { get; set; }
- /// <summary>
- /// 是否为新建的线
- /// </summary>
- public bool IsNew { get; set; }
- private SgLine() {
- StrokeThickness = 1;
- Stroke = Brushes.Red;
- }
- public SgLine(Vertex start, Vertex end) : this() {
- this.StartPoint = start.Position;
- this.EndPoint = end.Position;
- }
- public SgLine(Point start, Point end) : this() {
- this.StartPoint = start;
- this.EndPoint = end;
- System.Diagnostics.Debug.WriteLine($"start:{start.ToString()},end:{end}");
- }
- public SgLine(Point start, double angle) : this() {
- this.StartPoint = start;
- this.EndPoint = GetEndPoint(angle);
- }
- Point GetEndPoint(double angle) {
- if (angle == 90) {
- return new Point(StartPoint.X, StartPoint.Y + Length);
- }
- else if (angle == 270) {
- return new Point(StartPoint.X, StartPoint.Y - Length);
- }
- else {
- return new Point(StartPoint.X + Length, Math.Tan(angle / 180d * Math.PI) * Length + StartPoint.Y);
- }
- }
- }
- }
|