BimDocument.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:BimDocument
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/13 11:01:06
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace JBIM
  14. {
  15. /// <summary>
  16. /// Bim文件类信息
  17. /// </summary>
  18. public class BimDocument
  19. {
  20. public BimDocument()
  21. {
  22. BimObjects = new ReadOnlyCollection<BimObject>(m_InnerObjects = new List<BimObject>());
  23. }
  24. private List<BimObject> m_InnerObjects;
  25. private Dictionary<BimId, BimObject> m_IndexObjects = new Dictionary<BimId, BimObject>();
  26. /// <summary>
  27. /// 关联所有对象
  28. /// </summary>
  29. public ReadOnlyCollection<BimObject> BimObjects { get; private set; }
  30. /// <summary>
  31. /// 当前索引信息
  32. /// </summary>
  33. private long CurrentIndex { get; set; } = 10000;
  34. internal BimId GenerateId()
  35. {
  36. return new BimId((++CurrentIndex).ToString());
  37. }
  38. public BimObject NewObject(BimObject originObject)
  39. {
  40. if (originObject.Id != null)
  41. {
  42. return originObject;
  43. }
  44. originObject.Id = GenerateId();
  45. AddObject(originObject);
  46. return originObject;
  47. }
  48. private void AddObject(BimObject originObject)
  49. {
  50. this.m_InnerObjects.Add(originObject);
  51. m_IndexObjects[originObject.Id] = originObject;
  52. }
  53. public BimObject GetBimObject(BimId id)
  54. {
  55. //查询可优化,简单的二分查找
  56. if (m_IndexObjects.TryGetValue(id, out BimObject result))
  57. {
  58. return result;
  59. }
  60. return null;
  61. }
  62. }
  63. }