123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*-------------------------------------------------------------------------
- * 功能描述:JBimParseContext
- * 作者:xulisong
- * 创建时间: 2019/6/13 16:50:43
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using JBIM;
- using JBIM.Component;
- using JBIM.Relationship;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using RevitExport;
- using RevitToJBim.JsonConverter;
- namespace RevitToJBim
- {
- /// <summary>
- /// JBimParseContext解析上下文
- /// </summary>
- public class JBimParseContext: ParseContext
- {
- public JBimParseContext(List<IParseElement<JBimParseContext, BimId>> parsers)
- {
- Parser = new RevitToJBimParser(this, parsers);
- Document = new BimDocument();
- RelationShips = new List<RelationshipBase>();
- }
- public RevitToJBimParser Parser { get; private set; }
- public BimDocument Document { get;private set; }
-
- #region 数据缓存相关
- private Dictionary<string, BimId> m_RevitIdMap = new Dictionary<string, BimId>();
- public BimId GetBimId(string revitSourceId)
- {
- if (string.IsNullOrWhiteSpace(revitSourceId))
- {
- return null;
- }
- m_RevitIdMap.TryGetValue(revitSourceId, out BimId result);
- return result;
- }
- public BimId AddBimObject(BimObject obj)
- {
- var id= this.Document.NewObject(obj)?.Id;
- if (obj is ComponentObject cObject&&!string.IsNullOrWhiteSpace(cObject.SourceId))
- {
- m_RevitIdMap[cObject.SourceId] = id;
- }
- return id;
- }
- #endregion
- #region 关系数据统一存储
- public List<RelationshipBase> RelationShips { get; private set; }
- #endregion
- #region 解析方法
- public List<BimId> Parse(ElementWrapper wrapper)
- {
- return Parser.ParseElement(wrapper);
- }
- #endregion
- #region 序列化相关信息
- public string Serialize()
- {
- #region 关系数据处理
- /*
- * 当前关系数据是一个临时数据,需要不全信息之后才能真实使用
- * 临时数据中,存储的是SourceId的对应关系
- */
- var useShips = new List<RelationshipBase>();
- foreach (var relationshipBase in RelationShips)
- {
- if (!relationshipBase.IsProperty)
- {
- Document.NewObject(relationshipBase);
- }
- else
- {
- //var bimId = GetBimId(relationshipBase.re)
- }
- }
- #endregion
- return BimJsonUtil.Serializer(Document);
- }
- private RelationshipBase UpdateRelationShipInfo(RelationshipBase ship)
- {
- if (ship is OneToOneRel singleRel)
- {
- var relatingid = GetBimId(singleRel.RelatingObject);
- var relatedid = GetBimId(singleRel.RelatedObject);
- }
- else if (ship is OneToManyRel manyRel)
- {
- var relatingid = GetBimId(manyRel.RelatingObject);
- List<BimId> relatedIds = new List<BimId>();
- if (manyRel.RelatedObjects != null)
- {
- foreach (var manyRelRelatedObject in manyRel.RelatedObjects)
- {
- var relatedid = GetBimId(manyRelRelatedObject);
- if (relatedid != null)
- {
- relatedIds.Add(relatedid);
- }
- }
- }
-
- }
- return ship;
- }
- #endregion
- }
- }
|