/
anton.bessolitsyn
/
GraphTool
Обзор
Документация
Войти
/
anton.bessolitsyn
/
GraphTool
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
GraphToolWPF/Customs/VertexEntity.cs
169 строк
5 KB
Anton Bessolitsyn
in progress
22 окт 2025, 10:25
22 окт 2025, 10:25
8675066
Код
Авторство
О чём код?
using GraphToolWPF.Model; using GraphToolWPF.Service; using Multicad; using Multicad.CustomObjectBase; using Multicad.DatabaseServices; using Multicad.Geometry; using Multicad.Runtime; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using static Multicad.Geometry.Mesh; namespace GraphToolWPF.Customs { [CustomEntity("E80CAB89-8970-447a-A5DF-AA3BA30D0002", "vertex-entity", "вершина графа")] internal class VertexEntity : BaseGraphEntity, IVertexEvent { public static new Guid TypeID { get { return GetTypeID(typeof(VertexEntity)); } } #region EVENTS public event EventHandler<EventArgs>? EditedOrigin; public event EventHandler<EventArgs>? Erased; public event EventHandler<EventArgs>? Edited; #endregion public VertexEntity(IGraphInteractor interactor) : base() { interactor.SubscribeOnVertexEvents(this); } public VertexEntity():base() { } protected override void DrawEntity(GeometryBuilder dc) { dc.DrawCircle(_pnt, 5 * DbEntity.Scale); } public override hresult PlaceObject(PlaceFlags lInsertType) { InputJig jig = new InputJig(); jig.SetInputOptions(InputJig.InputReturnMode.Other); jig.ForceInputNumbers = true; //Исключаем себя из привязки, что бы osnap точки не липли к самому себе //jig.ExcludeObject(ID); InputJig.PropertyInpector.SetSource(this); InputResult res = jig.GetPoint("Новая вершина:"); if (res.Result != InputResult.ResultCode.Normal) return hresult.e_Fail; _pnt = res.Point; InputJig.PropertyInpector.SetSource(null); DbEntity.AddToCurrentDocument(); return hresult.s_Ok; } public override hresult PlaceObject(PlaceFlags lInsertType, List<ExValue> AdditionalParameters) { if (lInsertType == PlaceFlags.Wout_Position && AdditionalParameters?.Count > 0) { _pnt = (Point3d)AdditionalParameters[0].Value; DbEntity.AddToCurrentDocument(); Erased?.Invoke(this, EventArgs.Empty); return hresult.s_Ok; } return hresult.e_Fail; } //[CommandMethod("gt_EdgeEntity", CommandFlags.NoCheck | CommandFlags.NoPrefix)] static public VertexEntity CreateEntity() { VertexEntity obj = new VertexEntity(); obj.DbEntity.Color = Multicad.Constants.Colors.ByLayer; obj.PlaceObject(); return obj; } //TO DO find vertex static public VertexEntity CreateEntity(Point3d origin) { VertexEntity obj = new VertexEntity(); obj.DbEntity.Color = Multicad.Constants.Colors.ByLayer; obj.PlaceObject(PlaceFlags.Wout_Position, new List<ExValue>() { new ("Origin", origin) }); return obj; } static public VertexEntity GetVertexEntity(Guid Id) { var obj = (VertexEntity)McObjectManager.GetObject(new McObjectId(Id)); return obj; } public override Point3d Origin { get { return _pnt; } set { if (!TryModify() || _pnt == value) return;//без этого не будет сохранятся Undo и перерисовыватся объект _pnt = value; EditedOrigin?.Invoke(this, EventArgs.Empty); } } private string _vertexType = "Circle"; [DisplayName("Тип вершины")] [Category("GraphTool")] public string VertexType { get { return _vertexType; } set { if (!TryModify()) return;//без этого не будет сохранятся Undo и перерисовыватся объект _vertexType = value; } } public override void OnErase() { Erased?.Invoke(this, EventArgs.Empty); base.OnErase(); } public override hresult OnEdit(Point3d pnt, EditFlags lInsertType) { Edited?.Invoke(this, EventArgs.Empty); return hresult.s_Ok; } //public override void OnPersistentReactor(McDbObject ent, bool Erased) //{ // base.OnPersistentReactor(ent, Erased); //} //public override void OnPersistentReactorEx(McDbObject ent, ReactorsType RectionType) //{ // base.OnPersistentReactorEx(ent, RectionType); //} public override bool GetGripPoints(GripPointsInfo info) { info.AppendGrip(new McSmartGrip<VertexEntity>(_pnt, (obj, grip, offset) => { obj.TryModify(); obj.Origin += offset; })); return true; } } }