|
经常要做些选择集的过滤器,然而.Net的过滤器写起来真的很繁琐
所以。。。
ResultList类,原创是TonyT,:)
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Autodesk..DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- namespace TlsCad.Collections
- {
- ///
- /// TypedValue Collection
- ///
- public class ResultList : List, IFormattable
- {
- public ResultList(){ }
- public ResultList(IEnumerable values) : base(values)
- { }
- public ResultList(ResultBuffer rb) : base(rb.AsArray())
- { }
- #region Add
- public void Add(int typeCode, object obj)
- {
- base.Add(new TypedValue(typeCode, obj));
- }
- public void Add(LispDataType type, object obj)
- {
- base.Add(new TypedValue((int)type, obj));
- }
- public void Add(DxfCode type, object obj)
- {
- base.Add(new TypedValue((int)type, obj));
- }
- #endregion
- #region Convert
- public static implicit operator TypedValue[](ResultList rlst)
- {
- return rlst.ToArray();
- }
- public static implicit operator ResultBuffer(ResultList rlst)
- {
- return new ResultBuffer(rlst.ToArray());
- }
- public static implicit operator SelectionFilter(ResultList rlst)
- {
- return new SelectionFilter(rlst.ToArray());
- }
- #endregion
- #region IFormattable 成员
- public override string ToString()
- {
- var rb = new ResultBuffer(ToArray());
- return rb.ToString();
- }
- string IFormattable.ToString(string format, IFormatProvider formatProvider)
- {
- var rb = new ResultBuffer(ToArray());
- return rb.ToString(format, formatProvider);
- }
- #endregion
- }
- }
ResultTree类,原创飞狐 - using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using System.Collections;
- namespace TlsCad.Collections
- {
-
- public enum ResultTreeType
- {
- Node,
- List,
- DottedPair,
- RelationalOperator,
- LogicalOperator,
- }
-
- ///
- /// TypedValue Tree
- ///
- public class ResultTree : IEnumerable, IFormattable
- {
- ResultTreeType _treeType;
- ResultTree _owner;
- TypedValue _typedValue;
- List _lst = new List();
- static readonly List _relationalOperatorNames =
- new List { "not", "and", "or", "xor" };
- #region Properties
- public ResultTree this[int index]
- {
- get
- {
- if (_lst.Count == 0)
- {
- if(index == 0)
- {
- return this;
- }
- }
- else
- {
- if (index >= 0 && index ()
- {
- return (T)_typedValue.Value;
- }
- #endregion
- #region Constructor
- public ResultTree()
- {
- _treeType = ResultTreeType.Node;
- }
- public ResultTree(TypedValue value)
- :this()
- {
- _typedValue = value;
- }
- public ResultTree(int typeCode, object obj)
- : this(new TypedValue(typeCode, obj))
- { }
- public ResultTree(LispDataType type, object obj)
- : this(new TypedValue((int)type, obj))
- { }
- public ResultTree(DxfCode type, object obj)
- : this(new TypedValue((int)type, obj))
- { } public ResultTree(string operatorContext)
- {
- operatorContext = operatorContext.ToLower();
- _treeType =
- _relationalOperatorNames.Contains(operatorContext) ?
- ResultTreeType.RelationalOperator : ResultTreeType.LogicalOperator;
- _typedValue = new TypedValue(-4, operatorContext);
- }
- public ResultTree(ResultTreeType type)
- {
- _treeType = type;
- }
- private enum ResultNodeType
- {
- Node,
- ListBegin,
- ListEnd,
- DottedPairEnd,
- LogicalOperator,
- RelationalOperatorBegin,
- RelationalOperatorEnd,
- }
- private ResultNodeType GetNodeType(TypedValue tvalue, out ResultTree rt)
- {
- short typeCode = tvalue.TypeCode;
- object value = tvalue.Value;
- rt = null;
-
- if (typeCode == -4)
- {
- string s = ((string)value).ToLower();
- if(s[0] == '' && _relationalOperatorNames.Contains(s.Substring(0, s.Length - 1)))
- {
- return ResultNodeType.RelationalOperatorEnd;
- }
- else
- {
- rt = new ResultTree(s);
- return ResultNodeType.LogicalOperator;
- }
- }
- else if(typeCode == (short)LispDataType.ListBegin)
- {
- rt = new ResultTree(ResultTreeType.List);
- return ResultNodeType.ListBegin;
- }
- else if(typeCode == (short)LispDataType.ListEnd)
|
|