|
@@ -7,14 +7,10 @@
|
|
|
|
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
-using System.Linq;
|
|
|
|
-using System.Text;
|
|
|
|
-using System.Threading.Tasks;
|
|
|
|
using JBIM;
|
|
using JBIM;
|
|
|
|
+using JBIM.Common;
|
|
using JBIM.Component;
|
|
using JBIM.Component;
|
|
using JBIM.Relationship;
|
|
using JBIM.Relationship;
|
|
-using Newtonsoft.Json;
|
|
|
|
-using Newtonsoft.Json.Linq;
|
|
|
|
using RevitExport;
|
|
using RevitExport;
|
|
using RevitToJBim.JsonConverter;
|
|
using RevitToJBim.JsonConverter;
|
|
|
|
|
|
@@ -29,7 +25,7 @@ namespace RevitToJBim
|
|
{
|
|
{
|
|
Parser = new RevitToJBimParser(this, parsers);
|
|
Parser = new RevitToJBimParser(this, parsers);
|
|
Document = new BimDocument();
|
|
Document = new BimDocument();
|
|
- RelationShips = new List<RelationshipBase>();
|
|
|
|
|
|
+ RelationShips = new List<ElementRelationShip>();
|
|
}
|
|
}
|
|
public RevitToJBimParser Parser { get; private set; }
|
|
public RevitToJBimParser Parser { get; private set; }
|
|
public BimDocument Document { get;private set; }
|
|
public BimDocument Document { get;private set; }
|
|
@@ -45,7 +41,24 @@ namespace RevitToJBim
|
|
}
|
|
}
|
|
m_RevitIdMap.TryGetValue(revitSourceId, out BimId result);
|
|
m_RevitIdMap.TryGetValue(revitSourceId, out BimId result);
|
|
return result;
|
|
return result;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ public List<BimId> GetBimIds(List<string> sourceIds)
|
|
|
|
+ {
|
|
|
|
+ List<BimId> relatedIds = null;
|
|
|
|
+ if (sourceIds != null)
|
|
|
|
+ {
|
|
|
|
+ relatedIds = new List<BimId>();
|
|
|
|
+ foreach (var sourceId in sourceIds)
|
|
|
|
+ {
|
|
|
|
+ var relatedid = GetBimId(sourceId);
|
|
|
|
+ if (relatedid != null)
|
|
|
|
+ {
|
|
|
|
+ relatedIds.Add(relatedid);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return relatedIds;
|
|
|
|
+ }
|
|
public BimId AddBimObject(BimObject obj)
|
|
public BimId AddBimObject(BimObject obj)
|
|
{
|
|
{
|
|
var id= this.Document.NewObject(obj)?.Id;
|
|
var id= this.Document.NewObject(obj)?.Id;
|
|
@@ -58,7 +71,7 @@ namespace RevitToJBim
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region 关系数据统一存储
|
|
#region 关系数据统一存储
|
|
- public List<RelationshipBase> RelationShips { get; private set; }
|
|
|
|
|
|
+ public List<ElementRelationShip> RelationShips { get; private set; }
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region 解析方法
|
|
#region 解析方法
|
|
@@ -78,16 +91,16 @@ namespace RevitToJBim
|
|
* 当前关系数据是一个临时数据,需要不全信息之后才能真实使用
|
|
* 当前关系数据是一个临时数据,需要不全信息之后才能真实使用
|
|
* 临时数据中,存储的是SourceId的对应关系
|
|
* 临时数据中,存储的是SourceId的对应关系
|
|
*/
|
|
*/
|
|
- var useShips = new List<RelationshipBase>();
|
|
|
|
foreach (var relationshipBase in RelationShips)
|
|
foreach (var relationshipBase in RelationShips)
|
|
{
|
|
{
|
|
- if (!relationshipBase.IsProperty)
|
|
|
|
|
|
+ if (relationshipBase.IsProperty)
|
|
{
|
|
{
|
|
- Document.NewObject(relationshipBase);
|
|
|
|
|
|
+ UpdateRelationShipInfo(relationshipBase);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- //var bimId = GetBimId(relationshipBase.re)
|
|
|
|
|
|
+ var bimRelation = ConvertRelationShipInfo(relationshipBase);
|
|
|
|
+ Document.NewObject(bimRelation);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
@@ -95,31 +108,68 @@ namespace RevitToJBim
|
|
return BimJsonUtil.Serializer(Document);
|
|
return BimJsonUtil.Serializer(Document);
|
|
}
|
|
}
|
|
|
|
|
|
- private RelationshipBase UpdateRelationShipInfo(RelationshipBase ship)
|
|
|
|
|
|
+
|
|
|
|
+ private RelationshipBase ConvertRelationShipInfo(ElementRelationShip ship)
|
|
{
|
|
{
|
|
- if (ship is OneToOneRel singleRel)
|
|
|
|
|
|
+ var relatingid = GetBimId(ship.RelatingObject);
|
|
|
|
+ RelationshipBase useShip = null;
|
|
|
|
+ if (relatingid == null)
|
|
{
|
|
{
|
|
- var relatingid = GetBimId(singleRel.RelatingObject);
|
|
|
|
- var relatedid = GetBimId(singleRel.RelatedObject);
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
- else if (ship is OneToManyRel manyRel)
|
|
|
|
|
|
+ if (ship is ElementOneToOneRel singleRel)
|
|
{
|
|
{
|
|
- var relatingid = GetBimId(manyRel.RelatingObject);
|
|
|
|
- List<BimId> relatedIds = new List<BimId>();
|
|
|
|
- if (manyRel.RelatedObjects != null)
|
|
|
|
|
|
+ var relatedid = GetBimId(singleRel.RelatedObject);
|
|
|
|
+ if (relatedid != null)
|
|
{
|
|
{
|
|
- foreach (var manyRelRelatedObject in manyRel.RelatedObjects)
|
|
|
|
- {
|
|
|
|
- var relatedid = GetBimId(manyRelRelatedObject);
|
|
|
|
- if (relatedid != null)
|
|
|
|
- {
|
|
|
|
- relatedIds.Add(relatedid);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ useShip = new OneToOneRel(relatingid, relatedid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else if (ship is ElementOneToManyRel manyRel)
|
|
|
|
+ {
|
|
|
|
+ var relatedIds = GetBimIds(manyRel.RelatedObjects);
|
|
|
|
+ if (relatedIds != null)
|
|
|
|
+ {
|
|
|
|
+ useShip = new OneToManyRel(relatingid, relatedIds);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ return useShip;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void UpdateRelationShipInfo(ElementRelationShip ship)
|
|
|
|
+ {
|
|
|
|
+ var relatingid = GetBimId(ship.RelatingObject);
|
|
|
|
+ RelationshipBase useShip = null;
|
|
|
|
+ if (relatingid == null)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var bimObject = Document.GetBimObject(relatingid);
|
|
|
|
+ if (bimObject == null)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (ship is ElementOneToOneRel singleRel)
|
|
|
|
+ {
|
|
|
|
+ var relatedid = GetBimId(singleRel.RelatedObject);
|
|
|
|
|
|
|
|
+ if (relatedid != null)
|
|
|
|
+ {
|
|
|
|
+ BimObjectUtil.AcceptRelation(bimObject, ship.PropertyName, relatingid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else if (ship is ElementOneToManyRel manyRel)
|
|
|
|
+ {
|
|
|
|
+ var relatedIds = GetBimIds(manyRel.RelatedObjects);
|
|
|
|
+ if (relatedIds != null)
|
|
|
|
+ {
|
|
|
|
+ BimObjectUtil.AcceptRelations(bimObject, ship.PropertyName, relatedIds);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return ship;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
}
|