using System.Collections.Specialized; using System.IO; using System.Threading; namespace PdmSwPlugin.Common.Entity { /// /// 通过 SolidWorks Document Management API (DM API) 得到的文档属性集合 /// public class SldComponentInfo_DM { /// /// 唯一标识 /// 内部产生,从 1 开始递增 /// public int Id { get; set; } /// /// 层级,顶级装配体的层级为 0, 其它的依次为 1, 2, 3, N /// public int Level { get; set; } /// /// 父级的 Id,顶级装配体的父级 Id 为空 (0) /// public int ParentId { get; set; } /// /// 子节点的数量,不包含本节点 /// public int ChildrenCount { get; set; } /// /// 全路径 /// public string FullPath { get; set; } /// /// 路径 /// public string DirectoryName { get { try { return Path.GetDirectoryName(this.FullPath); } catch { return string.Empty; } } } /// /// 纯文件名,没有后缀的 /// public string FileNameWithoutExt { get { try { return Path.GetFileNameWithoutExtension(this.FullPath); } catch { return string.Empty; } } } /// /// 文件名,有后缀的 /// public string FileName { get { try { return Path.GetFileName(this.FullPath); } catch { return string.Empty; } } } /// /// Tag, 可以不用,或自定义 /// public string Tag { get; set; } /// /// 名称,也就是在特征树里显示的名称,与物料编码不一样 /// public string FeatureName { get; set; } /// /// 特征的唯一 ID /// public int FeatureId { get; set; } /// /// 压缩状态 /// public bool IsSuppressed { get; set; } /// /// 配置数量 /// public int ConfigurationCount { get; set; } /// /// 工程图名称 /// public string FileName2D { get; set; } /// /// 可见的吗? /// public bool Visible { get; set; } /// /// 所有的自定义属性 /// public NameValueCollection AllCustomProperties { get; set; } /// /// 私有构造函数,任何调用者都没法直接生成一个不带参数的本类的实例了 /// private SldComponentInfo_DM() { this.Id = -1; this.Visible = true; //this.IsSuppressed = false; } /// /// 每个项都将设置一个惟一的 ID, 就从 0 开始 /// private static int currentId = 0; /// /// 生成根节点,顶级装配体的信息 /// /// 顶级装配体的 ID = 1 public static SldComponentInfo_DM GenerateTheRoot() { currentId = 1; return new SldComponentInfo_DM() { Id = currentId, Level = 0, ParentId = 0 }; } /// /// 生成下一个节点,反正不是顶级装配体 /// /// 当前节点,只设置一个属性 - Id,确保 Id 是唯一的 public static SldComponentInfo_DM GenerateTheNext() { int nextId = Interlocked.Increment(ref currentId); return new SldComponentInfo_DM() { Id = currentId }; } } }