概述
在PML语法中,利用collect
语句或者COLLECTION
对象均可实现元素收集。在.NET中主要通过Filters
下面的类,来实现元素的收集。
普通过滤器
类型过滤器
类型过滤器主要类为TypeFilter
。
// 实例化
TypeFilter filt1 = new TypeFilter(DbElementTypeInstance.ATTACHMENT);
也可以通过Add / Remove等方法,进行增减等操作
属性过滤器
属性过滤器主要类为AttributeLikeFilter
。
AttributeLikeFilter filt2 = new AttributeLikeFilter(DbAttributeInstance.ATTY, "SUPP");
该过滤器可以支持模糊匹配,利用*
进行多字节匹配,?
单字节匹配。
过滤器运算
过滤器主要有与
和或
的运算符。
AndFilter filt = new AndFilter(filt1, filt2);
OrFilter filt = new OrFilter(filt1, filt2);
获取对象
利用DBElementCollection
对象,可以获取元素的集合。
DBElementCollection itemList = new DBElementCollection(CurrentElement.Element, filt);
混合过滤器
除了通过上述的方式,还可以通过按树结构,迭代元素的方式获取对象。采用这种方式的话,主要使用CompoundFilter
类。
类型过滤器和属性过滤器和普通过滤器操作方式一样。
// 可以通过Hide/Show/Skip等方式,操作混合过滤器
CompoundFilter compoundFilter = new CompoundFilter();
compoundFilter.AddShow(filt1);
// 迭代树,获取指定节点下的对象
ElementTreeNavigator elementTree = new ElementTreeNavigator(DbElement.GetElement("/*"), compoundFilter);
DbElement[] items = elementTree.MembersInScan(CurrentElement.Element)
按范围获取元素
该方式类似于PML中的limits
语法,这里需要用到一个专门的类spatial
,该类主要用于空间与元素的判定。
// 定义空间
Position p1 = Position.Create(0, 0, 0);
Position p2 = Position.Create(1000, 1000, 1000);
LimitsBox rbox = LimitsBox.Create(p1,p2);
// 获取空间内的元素
DbElement[] elements = Spatial.Instance.ElementsInBox(rbox ,true);
// 该方法有多个重载,返回指定空间内指定类型的元素如果参数3为true的话,要完全包含才输出。
public abstract DbElement[] ElementsInBox(LimitsBox rbox, DbElementType[] types, bool bFully);
// 返回指定元素的三维空间内指定类型的元素
public abstract DbElement[] ElementsInElementBox(DbElement ele,DbElementType[] types,bool bFully);
Spatial的其他用途
// 判断元素是否在指定的空间内,如果是的话返回true,否则返回false。
public abstract bool ElementInBox(DbElement ele,LimitsBox rbox);
Position p1 = Position.Create(0,0,0);
Position p2 = Position.Create("E1000 N1000 U1000");
LimitsBox rbox = LimitsBox.Create(p1,p2);
Spatial.Instance.ElementInBox(test,rbox)
// 判断元素1是不是包含元素2,如果参数3为true的话,要完全包含才能发挥true。
public abstract bool ElementInElementExact(DbElement ele1,DbElement ele2,bool bFully);