PipeFilter.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using Autodesk.Revit.DB;
  3. using Autodesk.Revit.DB.Plumbing;
  4. using Autodesk.Revit.UI.Selection;
  5. using SAGA.RevitUtils.Extends;
  6. namespace SAGA.RevitUtils.MEP
  7. {
  8. public class PipeFilter : ISelectionFilter
  9. {
  10. private Predicate<Pipe> m_Predicate;
  11. private PipeSystemType m_Pst;
  12. private Func<Reference, XYZ, bool> m_ReferenceFunc;
  13. public PipeFilter(PipeSystemType pst = 0, Predicate<Pipe> conduit = null, Func<Reference, XYZ, bool> referenceFunc = null)
  14. {
  15. this.m_Pst = pst;
  16. this.m_Predicate = conduit;
  17. this.m_ReferenceFunc = referenceFunc;
  18. }
  19. public bool AllowElement(Element elem)
  20. {
  21. if (!(elem is Pipe))
  22. {
  23. return false;
  24. }
  25. bool flag = true;
  26. Pipe pipe = (Pipe) elem;
  27. if (this.m_Pst != PipeSystemType.UndefinedSystemType)
  28. {
  29. flag = pipe.GetPipeSystemType() == this.m_Pst;
  30. }
  31. bool flag2 = elem.GetCategory() == BuiltInCategory.OST_PipeCurves;
  32. if (this.m_Predicate != null)
  33. {
  34. flag = flag && this.m_Predicate(pipe);
  35. }
  36. return (flag && flag2);
  37. }
  38. public bool AllowReference(Reference reference, XYZ position)
  39. {
  40. if (this.m_ReferenceFunc != null)
  41. {
  42. return this.m_ReferenceFunc.Invoke(reference, position);
  43. }
  44. return true;
  45. }
  46. }
  47. }