/
anton.bessolitsyn
/
GraphTool
Обзор
Документация
Войти
/
anton.bessolitsyn
/
GraphTool
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
GraphToolWPF/Model/GraphModel.cs
105 строк
3 KB
Anton Bessolitsyn
in progress
22 окт 2025, 10:25
22 окт 2025, 10:25
8675066
Код
Авторство
О чём код?
using GraphToolWPF.Customs; using Multicad.DatabaseServices; using Multicad.Geometry; using System.Runtime.InteropServices; namespace GraphToolWPF.Model { internal class Vertex { public Guid Id { get; } public String Name { get; } = String.Empty; //public string Text { get; private set; } public List<Vertex> Neighbors { get; } = new List<Vertex>(); public VertexEntity Entity { get => _entity; } private readonly VertexEntity _entity; public Vertex(VertexEntity vertex) { _entity=vertex; Id = _entity.Guid; } public Vertex(string name) { Id = Guid.NewGuid(); Name = name; } public void AddNeighbor(Vertex neighbor) { if (neighbor == null || neighbor == this || Neighbors.Contains(neighbor)) return; Neighbors.Add(neighbor); neighbor.Neighbors.Add(this); } public void RemoveNeighbor(Vertex neighbor) { Neighbors.Remove(neighbor); neighbor?.Neighbors.Remove(this); } public Point3d GetOrigin() => _entity.Origin; } internal class Edge { public Guid Id { get; } /// <summary> /// P1 of EdgeEntity /// </summary> public Vertex Start { get; private set; } /// <summary> /// P2 of EdgeEntity /// </summary> public Vertex End { get; private set; } //public double Length { get; private set; } public double Length { get=> _entity.Length; } public EdgeEntity Entity { get => _entity; } private readonly EdgeEntity _entity; public Edge(Vertex start, Vertex end, EdgeEntity entity) { _entity = entity; Id = _entity.Guid; Start = start ?? throw new ArgumentNullException(nameof(start)); End = end ?? throw new ArgumentNullException(nameof(end)); } public void ApplyNewPositionOfStart() { _entity.P1 = Start.GetOrigin(); } public void ApplyNewPositionOfEnd() { _entity.P2 = End.GetOrigin(); } public void SetStart(Vertex start) { if (Start != null && start!=End && start != null) { End.RemoveNeighbor(Start); Start = start; End.AddNeighbor(Start); } } public void SetEnd(Vertex end) { if (End != null && end != Start && end != null) { Start.RemoveNeighbor(End); End = end; Start.AddNeighbor(End); } } } }