CommonClass.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using System;
  2. using System.Collections.Generic;
  3. using Autodesk.Revit.DB;
  4. using SAGA.RevitUtils.Extends;
  5. namespace SAGA.RevitUtils
  6. {
  7. public static class GlobalStaticData
  8. {
  9. public static object FormData = null;
  10. public static void Dispose()
  11. {
  12. if (FormData != null)
  13. {
  14. FormData = null;
  15. }
  16. }
  17. }
  18. [Flags]
  19. public enum XyzOptions : uint
  20. {
  21. X = 1,
  22. Y = 2,
  23. Z = 4,
  24. }
  25. public class XyzComparerOption : IComparer<XYZ>
  26. {
  27. private XyzOptions _whereToCompare;
  28. public XyzComparerOption(XyzOptions whereToCompare)
  29. {
  30. this._whereToCompare = whereToCompare;
  31. }
  32. public int Compare(XYZ pt1, XYZ pt2)
  33. {
  34. return pt1.CompareTo(pt2, _whereToCompare);
  35. }
  36. }
  37. public class XyzComparerX : IComparer<XYZ>
  38. {
  39. public int Compare(XYZ pt1, XYZ pt2)
  40. {
  41. return pt1.CompareTo(pt2, XyzOptions.X);
  42. }
  43. }
  44. public class XyzComparerY : IComparer<XYZ>
  45. {
  46. public int Compare(XYZ pt1, XYZ pt2)
  47. {
  48. return pt1.CompareTo(pt2, XyzOptions.Y);
  49. }
  50. }
  51. public class XyzComparerZ : IComparer<XYZ>
  52. {
  53. public int Compare(XYZ pt1, XYZ pt2)
  54. {
  55. return pt1.CompareTo(pt2, XyzOptions.Z);
  56. }
  57. }
  58. public enum DirectionEnum : uint
  59. {
  60. BottomTop = 6,
  61. BottomTopLeftRight = 7,
  62. BottomTopRightLeft = 8,
  63. LeftBottomRightTop = 12,
  64. LeftRight = 0,
  65. LeftRightBottomTop = 1,
  66. LeftRightTopBottom = 2,
  67. LeftTopRightBottom = 13,
  68. RightBottomLeftTop = 14,
  69. RightLeft = 3,
  70. RightLeftBottomTop = 4,
  71. RightLeftTopBottom = 5,
  72. RightTopLeftBottom = 15,
  73. TopBottom = 9,
  74. TopBottomLeftRight = 10,
  75. TopBottomRightLeft = 11
  76. }
  77. public class CurveXyzComparer : IComparer<XYZ>
  78. {
  79. private bool _start;
  80. private Curve _curve;
  81. public CurveXyzComparer(Curve curve, bool blnStart = true)
  82. {
  83. _curve = curve;
  84. _start = blnStart;
  85. }
  86. #region IComparer<XYZ> 成员
  87. int IComparer<XYZ>.Compare(XYZ first, XYZ second)
  88. {
  89. return first.CompareTo(second, _curve, _start);
  90. }
  91. #endregion
  92. }
  93. public class XyzEqualComparer : IEqualityComparer<XYZ>
  94. {
  95. private double _tolerance = 0;
  96. public XyzEqualComparer(double tolerance = 0)
  97. {
  98. _tolerance = tolerance;
  99. }
  100. public bool Equals(XYZ x, XYZ y)
  101. {
  102. return x.IsEqual(y, _tolerance);
  103. }
  104. public int GetHashCode(XYZ obj)
  105. {
  106. return 0;
  107. }
  108. }
  109. public class CurveEqualComparer : IEqualityComparer<Curve>
  110. {
  111. private readonly double _tolerance = 0;
  112. public CurveEqualComparer(double tolerance = 0)
  113. {
  114. _tolerance = tolerance;
  115. }
  116. bool IEqualityComparer<Curve>.Equals(Curve x, Curve y)
  117. {
  118. return x.IsEqual(y, _tolerance);
  119. }
  120. int IEqualityComparer<Curve>.GetHashCode(Curve obj)
  121. {
  122. return 0;
  123. }
  124. }
  125. public class CurveEqualComparer2 : IEqualityComparer<Curve>
  126. {
  127. private double _tolerance = 0;
  128. public CurveEqualComparer2(double tolerance = 0)
  129. {
  130. _tolerance = tolerance;
  131. }
  132. bool IEqualityComparer<Curve>.Equals(Curve x, Curve y)
  133. {
  134. return x.IsEqual2(y, _tolerance);
  135. }
  136. int IEqualityComparer<Curve>.GetHashCode(Curve obj)
  137. {
  138. return 0;
  139. }
  140. }
  141. /// <summary>
  142. /// Curve平行,比较器
  143. /// </summary>
  144. public class CurveParallelEqualComparer : IEqualityComparer<Curve>
  145. {
  146. private double _tolerance = 0;
  147. public CurveParallelEqualComparer(double tolerance = 0)
  148. {
  149. _tolerance = tolerance;
  150. }
  151. bool IEqualityComparer<Curve>.Equals(Curve x, Curve y)
  152. {
  153. return x.IsParallel(y, _tolerance);
  154. }
  155. int IEqualityComparer<Curve>.GetHashCode(Curve obj)
  156. {
  157. return 0;
  158. }
  159. }
  160. public class ElementEqualComparer : IEqualityComparer<Element>
  161. {
  162. bool IEqualityComparer<Element>.Equals(Element el1, Element el2)
  163. {
  164. return el1.Id.IntegerValue == el2.Id.IntegerValue;
  165. }
  166. int IEqualityComparer<Element>.GetHashCode(Element element)
  167. {
  168. return 0;
  169. }
  170. }
  171. public class WallEqualComparer : IEqualityComparer<Wall>
  172. {
  173. bool IEqualityComparer<Wall>.Equals(Wall x, Wall y)
  174. {
  175. return x.IsEqual(y);
  176. }
  177. int IEqualityComparer<Wall>.GetHashCode(Wall obj)
  178. {
  179. return 0;
  180. }
  181. }
  182. /// <summary>
  183. /// 轴网的排序类
  184. /// </summary>
  185. public class ComparerGrid : IComparer<Grid>
  186. {
  187. #region IComparer<Grid> 成员
  188. public int Compare(Grid x, Grid y)
  189. {
  190. int result = 0;
  191. if (x.Curve.StartPoint().Y == x.Curve.EndPoint().Y)
  192. {
  193. if (x.Curve.StartPoint().Y > y.Curve.StartPoint().Y)
  194. {
  195. result = 1;
  196. }
  197. else if (x.Curve.StartPoint().Y < y.Curve.StartPoint().Y)
  198. {
  199. result = -1;
  200. }
  201. }
  202. else
  203. {
  204. if (x.Curve.StartPoint().X > y.Curve.StartPoint().X)
  205. {
  206. result = 1;
  207. }
  208. else if (x.Curve.StartPoint().X < y.Curve.StartPoint().X)
  209. {
  210. result = -1;
  211. }
  212. }
  213. return result;
  214. }
  215. #endregion
  216. }
  217. public class CompareReference : IEqualityComparer<Reference>
  218. {
  219. #region IEqualityComparer<Reference> 成员
  220. public bool Equals(Reference x, Reference y)
  221. {
  222. if (x.ElementId.IntegerValue.Equals(y.ElementId.IntegerValue))
  223. return true;
  224. else
  225. return false;
  226. }
  227. public int GetHashCode(Reference obj)
  228. {
  229. return obj.ElementId.GetHashCode();
  230. }
  231. #endregion
  232. }
  233. /// <summary>
  234. /// 柱定位点相等比较(默认比较x值)
  235. /// </summary>
  236. public class ColumnLocationCompare : IComparer<FamilyInstance>
  237. {
  238. private XyzOptions _xyzOption = XyzOptions.X;
  239. public ColumnLocationCompare()
  240. {
  241. }
  242. public ColumnLocationCompare(XyzOptions xyzOption)
  243. {
  244. this._xyzOption = xyzOption;
  245. }
  246. public int Compare(FamilyInstance instance1, FamilyInstance instance2)
  247. {
  248. LocationPoint point1 = instance1.Location as LocationPoint;
  249. LocationPoint point2 = instance2.Location as LocationPoint;
  250. return point1.Point.CompareTo(point2.Point, _xyzOption);
  251. }
  252. }
  253. /// <summary>
  254. /// 梁比较器,判断梁线Z值是否相同
  255. /// </summary>
  256. public class CompareBeamZ : IComparer<FamilyInstance>
  257. {
  258. public int Compare(FamilyInstance instance1, FamilyInstance instance2)
  259. {
  260. LocationCurve locationCurve1 = instance1.Location as LocationCurve;
  261. LocationCurve locationCurve2 = instance2.Location as LocationCurve;
  262. return locationCurve1.Curve.StartPoint().Z.CompareTo(locationCurve2.Curve.StartPoint().Z);
  263. }
  264. }
  265. public class CurveCompare : IComparer<Curve>
  266. {
  267. public int Compare(Curve x, Curve y)
  268. {
  269. if (x.Length > y.Length)
  270. return 1;
  271. else if (x.Length < y.Length)
  272. return -1;
  273. else
  274. return 0;
  275. }
  276. }
  277. public class CategoryCompare : IComparer<Category>
  278. {
  279. public int Compare(Category cat1, Category cat2)
  280. {
  281. return cat1.Name.CompareTo(cat2.Name);
  282. }
  283. }
  284. public class ElementCompare : IComparer<Element>
  285. {
  286. public int Compare(Element ele1, Element ele2)
  287. {
  288. return ele1.Name.CompareTo(ele2.Name);
  289. }
  290. }
  291. public interface IAllowSendCmd
  292. {
  293. event EventHandler SelectChanged;
  294. }
  295. }