ParseBase.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ParseBase
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/13 16:55:35
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using JBIM;
  13. using RevitExport;
  14. using RevitExport.Export;
  15. using RevitExport.Parse;
  16. using RevitToJBim.Common;
  17. namespace RevitToJBim.ComponentParse
  18. {
  19. public abstract class ParseBase : IParseElement<JBimParseContext,BimId>
  20. {
  21. #region 接口类相关
  22. /// <summary>
  23. /// 快速索引
  24. /// </summary>
  25. /// <returns></returns>
  26. public virtual List<string> FastIndex()
  27. {
  28. return new List<string>();//Guid.NewGuid().ToString("N");
  29. }
  30. public abstract bool Match(ElementWrapper wrapper);
  31. public virtual List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  32. {
  33. return null;
  34. }
  35. public virtual List<BimId> Parse(ElementWrapper wrapper, JBimParseContext context)
  36. {
  37. BimId result = context.GetBimId(wrapper.SourceId);
  38. if (result != null)
  39. {
  40. return new List<BimId>() { result };
  41. }
  42. var innerResults = ParseInner(wrapper, context);
  43. var refElements = ArrangeRefElements(wrapper, context);
  44. if (refElements != null)
  45. {
  46. foreach (var elementWrapper in refElements)
  47. {
  48. try
  49. {
  50. context.Parser.ParseElement(elementWrapper);
  51. }
  52. catch (Exception e)
  53. {
  54. ExceptionUtil.ThrowIfDubug(e);
  55. }
  56. }
  57. }
  58. return innerResults;
  59. }
  60. #endregion
  61. protected abstract List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context);
  62. }
  63. }