|
@@ -11,7 +11,12 @@ 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
|
|
|
{
|
|
@@ -20,12 +25,15 @@ namespace RevitToJBim
|
|
|
/// </summary>
|
|
|
public class JBimParseContext: ParseContext
|
|
|
{
|
|
|
- public JBimParseContext()
|
|
|
+ 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>();
|
|
@@ -40,18 +48,78 @@ namespace RevitToJBim
|
|
|
}
|
|
|
public BimId AddBimObject(BimObject obj)
|
|
|
{
|
|
|
- return this.Document.NewObject(obj)?.Id;
|
|
|
+ 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 new List<BimId>();
|
|
|
+ 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
|
|
|
}
|