123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace JBIM
- {
-
-
-
- public class BimDocument
- {
- public BimDocument()
- {
- BimObjects = new ReadOnlyCollection<BimObject>(m_InnerObjects = new List<BimObject>());
- }
- private List<BimObject> m_InnerObjects;
- private Dictionary<BimId, BimObject> m_IndexObjects = new Dictionary<BimId, BimObject>();
-
-
-
- public ReadOnlyCollection<BimObject> BimObjects { get; private set; }
-
-
-
- private long CurrentIndex { get; set; } = 10000;
- internal BimId GenerateId()
- {
- return new BimId((++CurrentIndex).ToString());
- }
- public BimObject NewObject(BimObject originObject)
- {
- if (originObject.Id != null)
- {
- return originObject;
- }
- originObject.Id = GenerateId();
- AddObject(originObject);
- return originObject;
- }
-
-
-
-
-
- public bool AddPredefinedObject(BimObject originObject)
- {
- if (originObject.Id == null)
- {
- return false;
- }
- if (m_IndexObjects.TryGetValue(originObject.Id, out BimObject oldObject))
- {
-
- if (oldObject != null)
- {
- m_InnerObjects.Remove(oldObject);
- }
- m_IndexObjects[originObject.Id] = originObject;
- }
- else
- {
- AddObject(originObject);
- }
- return true;
- }
- private void AddObject(BimObject originObject)
- {
- this.m_InnerObjects.Add(originObject);
- m_IndexObjects[originObject.Id] = originObject;
- }
- public BimObject GetBimObject(BimId id)
- {
-
- if (m_IndexObjects.TryGetValue(id, out BimObject result))
- {
- return result;
- }
- return null;
- }
- }
- }
|