From 424b0a67591b9085c834d3b3a286c8ee1882bd14 Mon Sep 17 00:00:00 2001
From: DYH <1742647821@qq.com>
Date: Sat, 10 Sep 2022 21:58:28 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9E=AC=E6=80=81=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ExtensionMethod/JigExTransient.cs | 149 ++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 src/IFoxCAD.Cad/ExtensionMethod/JigExTransient.cs
diff --git a/src/IFoxCAD.Cad/ExtensionMethod/JigExTransient.cs b/src/IFoxCAD.Cad/ExtensionMethod/JigExTransient.cs
new file mode 100644
index 0000000..770739a
--- /dev/null
+++ b/src/IFoxCAD.Cad/ExtensionMethod/JigExTransient.cs
@@ -0,0 +1,149 @@
+#if !ac2008
+namespace IFoxCAD.Cad;
+
+///
+/// 瞬态容器
+///
+public class JigExTransient : IDisposable
+{
+ #region 私有字段
+ // 整数集,暂时不知道有什么意义
+ IntegerCollection _integerCollection;
+ // 维护集合
+ HashSet _entities;
+ #endregion
+
+ #region 公开属性
+ ///
+ /// 对象集合
+ ///
+ public Entity[] Entities => _entities.ToArray();
+ ///
+ /// 数量
+ ///
+ public int Count => _entities.Count;
+ #endregion
+
+ #region 构造函数
+ ///
+ /// 瞬态容器
+ ///
+ public JigExTransient()
+ {
+ _integerCollection = new();
+ _entities = new();
+ }
+ #endregion
+
+ #region 方法
+ ///
+ /// 判断瞬态容器里是否含有对象
+ ///
+ /// 对象
+ /// 含有返回true
+ public bool Contains(Entity ent)
+ {
+ return _entities.Contains(ent);
+ }
+
+ ///
+ /// 向瞬态容器中添加对象
+ ///
+ /// 图元
+ /// 绘图模式
+ public void Add(Entity ent, TransientDrawingMode tdm = TransientDrawingMode.Main)
+ {
+ if (_entities.Add(ent))
+ {
+ TransientManager
+ .CurrentTransientManager
+ .AddTransient(ent, tdm, 128, _integerCollection);
+ }
+ }
+
+
+ ///
+ /// 从瞬态容器中移除图元
+ ///
+ /// 已经加入瞬态容器的图元
+ public void Remove(Entity ent)
+ {
+ if (!Contains(ent))
+ return;
+ TransientManager
+ .CurrentTransientManager
+ .EraseTransient(ent, _integerCollection);
+ _entities.Remove(ent);
+ }
+
+ ///
+ /// 清空瞬态容器并移除图元显示
+ ///
+ public void Clear()
+ {
+ foreach (var ent in _entities)
+ {
+ TransientManager
+ .CurrentTransientManager
+ .EraseTransient(ent, _integerCollection);
+ }
+ _entities.Clear();
+ }
+
+
+ ///
+ /// 更新单个显示
+ ///
+ /// 已经加入瞬态容器的图元
+ public void Update(Entity ent)
+ {
+ if (!Contains(ent))
+ return;
+ TransientManager
+ .CurrentTransientManager
+ .UpdateTransient(ent, _integerCollection);
+ }
+
+ ///
+ /// 更新全部显示
+ ///
+ public void UpdateAll()
+ {
+ foreach (var ent in _entities)
+ Update(ent);
+ }
+ #endregion
+
+ #region IDisposable接口相关函数
+ public bool IsDisposed { get; private set; } = false;
+
+ ///
+ /// 手动释放
+ ///
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// 析构函数调用释放
+ ///
+ ~JigExTransient()
+ {
+ Dispose(false);
+ }
+
+ ///
+ /// 销毁瞬态容器
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ if (IsDisposed) return;
+ IsDisposed = true;
+
+ Clear();// 清空瞬态容器并移除对象在图纸上的显示
+ }
+ #endregion
+}
+#endif
\ No newline at end of file
--
Gitee