ParseBase.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 RevitToJBim.Common;
  15. namespace RevitToJBim.ComponentParse
  16. {
  17. public abstract class ParseBase : IParseElement<JBimParseContext,BimId>
  18. {
  19. #region 接口类相关
  20. /// <summary>
  21. /// 快速索引
  22. /// </summary>
  23. /// <returns></returns>
  24. public virtual List<string> FastIndex()
  25. {
  26. return null;//Guid.NewGuid().ToString("N");
  27. }
  28. public abstract bool Match(ElementWrapper wrapper);
  29. public virtual List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
  30. {
  31. return null;
  32. }
  33. public virtual List<BimId> Parse(ElementWrapper wrapper, JBimParseContext context)
  34. {
  35. BimId result = context.GetBimId(wrapper.SourceId);
  36. if (result != null)
  37. {
  38. return new List<BimId>() { result };
  39. }
  40. var innerResults = ParseInner(wrapper, context);
  41. var refElements = ArrangeRefElements(wrapper, context);
  42. if (refElements != null)
  43. {
  44. foreach (var elementWrapper in refElements)
  45. {
  46. try
  47. {
  48. context.Parser.ParseElement(elementWrapper);
  49. }
  50. catch (Exception e)
  51. {
  52. ExceptionUtil.ThrowIfDubug(e);
  53. }
  54. }
  55. }
  56. return innerResults;
  57. }
  58. #endregion
  59. protected abstract List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context);
  60. }
  61. }