123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /*-------------------------------------------------------------------------
- * 功能描述:SelectionFilter
- * 作者:xulisong
- * 创建时间: 2019/5/23 14:14:35
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI.Selection;
- using FWindSoft.Revit.Extension;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit.Common
- {
- public class SelectionFilter : ISelectionFilter
- {
- private Predicate<Element> m_AllowElement;
- private Func<Reference,XYZ,bool> m_AllowReference;
- public SelectionFilter(Predicate<Element> allowElement, Func<Reference, XYZ, bool> allowReference)
- {
- m_AllowElement = allowElement;
- m_AllowReference = allowReference;
- }
- public bool AllowElement(Element elem)
- {
- if (m_AllowElement != null)
- {
- return m_AllowElement.Invoke(elem);
- }
- return true;
- }
- public bool AllowReference(Reference reference, XYZ position)
- {
- if (m_AllowReference != null)
- {
- return m_AllowReference.Invoke(reference,position);
- }
- return true;
- }
- }
- /// <summary>
- /// 类型选择过滤器
- /// </summary>
- public class TypeSelectionFilter : ISelectionFilter
- {
- private Type m_Type;
- public TypeSelectionFilter(Type type)
- {
- m_Type = type;
- }
- public bool AllowElement(Element elem)
- {
- return elem.GetType() == m_Type;
- }
- public bool AllowReference(Reference reference, XYZ position)
- {
- return true;
- }
- }
- /// <summary>
- /// 类别过滤器
- /// </summary>
- public class CategorySelectionFilter : ISelectionFilter
- {
- private BuiltInCategory m_BuiltInCategory;
- public CategorySelectionFilter(BuiltInCategory builtInCategory)
- {
- m_BuiltInCategory= builtInCategory;
- }
- public bool AllowElement(Element elem)
- {
- var bit = elem.GetCategory();
- return bit== m_BuiltInCategory;
- }
- public bool AllowReference(Reference reference, XYZ position)
- {
- return true;
- }
- }
- /// <summary>
- /// 多类别过滤器
- /// </summary>
- public class CategoriesSelectionFilter : ISelectionFilter
- {
- private readonly List<BuiltInCategory> m_Categories = new List<BuiltInCategory>();
- public CategoriesSelectionFilter(BuiltInCategory bic)
- {
- m_Categories.Add(bic);
- }
- public CategoriesSelectionFilter(List<BuiltInCategory> categories)
- {
- m_Categories.AddRange(categories??new List<BuiltInCategory>());
- }
- public bool AllowElement(Element elem)
- {
- if (!m_Categories.Any())
- {
- return false;
- }
- var useCategory = elem.GetCategory();
- return m_Categories.Any(p => p == useCategory);
- }
- public bool AllowReference(Reference reference, XYZ position)
- {
- return true;
- }
- }
- }
|