Quellcode durchsuchen

xls:初版信息提交

xulisong vor 5 Jahren
Ursprung
Commit
7fb0915a7c

BIN
JBIM/Dlls/SAGA.RevitUtility.dll


+ 17 - 0
JBIM/JBIM/BimId.cs

@@ -53,5 +53,22 @@ namespace JBIM
 
             return Id.GetHashCode();
         }
+        public static bool operator ==(BimId a, BimId b)
+        {
+            if (a == null)
+            {
+                return b == null;
+            }
+            return a.Equals(b);
+        }
+        public static bool operator !=(BimId a, BimId b)
+        {
+            if (a == null)
+            {
+                return (b != null);
+            }
+            return !a.Equals(b);
+        }
+
     }
 }

+ 65 - 0
JBIM/JBIM/Common/BimObjectUtil.cs

@@ -0,0 +1,65 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:BimObjectUtil
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 15:13:11
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JBIM.Common
+{
+    public static class BimObjectUtil
+    {
+        public static void AcceptRelation<T>(BimObject bimObject, string property,T value)
+        {
+            var propertyInfo=ParseProperty(bimObject, property);
+            if (propertyInfo != null)
+            {
+                if (propertyInfo.PropertyType.IsInstanceOfType(value))
+                {
+                    propertyInfo.SetValue(bimObject, value);
+                }
+            }
+        }
+        /// <summary>
+        /// 增加单关联信息
+        /// </summary>
+        /// <param name="bimObject"></param>
+        /// <param name="property"></param>
+        /// <param name="value"></param>
+        public static void AcceptRelation(BimObject bimObject, string property, BimId value)
+        {
+            AcceptRelation<BimId>(bimObject, property, value);
+        }
+        /// <summary>
+        /// 增加一对多关联信息
+        /// </summary>
+        /// <param name="bimObject"></param>
+        /// <param name="property"></param>
+        /// <param name="value"></param>
+        public static void AcceptRelations(BimObject bimObject, string property,List<BimId> value)
+        {
+            AcceptRelation<List<BimId>>(bimObject, property, value);
+        }
+        private static PropertyInfo ParseProperty(BimObject bimObject,string pName)
+        {
+            var type = bimObject.GetType();
+            string propertyName = pName;
+            var key = type.FullName + "_" + propertyName;
+            var propertyInfo = PropertyCache.GetProperty(key);
+            if (propertyInfo == null)
+            {
+                //缓存解析出来的属性元数据,以便提高解析速度
+                var property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);
+                PropertyCache.SetProperty(key, property);
+            }
+            return propertyInfo;
+        }
+    }
+}

+ 1 - 0
JBIM/JBIM/Common/TypeDefinitonUtil.cs

@@ -19,5 +19,6 @@ namespace JBIM.Common
         {
             return typeDefinition.ToString();
         }
+
     }
 }

+ 1 - 0
JBIM/JBIM/JBIM.csproj

@@ -54,6 +54,7 @@
     <Compile Include="BimDocument.cs" />
     <Compile Include="BimId.cs" />
     <Compile Include="BimObject.cs" />
+    <Compile Include="Common\BimObjectUtil.cs" />
     <Compile Include="Common\EnumExtensions.cs" />
     <Compile Include="Common\PropertyCache.cs" />
     <Compile Include="Common\TypeDefinitonAttribute.cs" />

+ 4 - 7
JBIM/JBIM/Relationship/OneToManyRel.cs

@@ -19,22 +19,19 @@ namespace JBIM.Relationship
         {
 
         }
-        public OneToManyRel(string relatingObject)
+        public OneToManyRel(BimId relatingObject)
         {
             RelatingObject = relatingObject;
         }
-        public OneToManyRel(string relatingObject, List<string> relatedObjects)
+        public OneToManyRel(BimId relatingObject, List<BimId> relatedObjects)
         {
             RelatingObject = relatingObject;
             RelatedObjects = relatedObjects;
         }
         /// <summary>
-        /// 主体对象
-        /// </summary>
-        public string RelatingObject { get; set; }
-        /// <summary>
         /// 关联对象
         /// </summary>
-        public List<string> RelatedObjects { get; set; }
+        public List<BimId> RelatedObjects { get; set; }
+   
     }
 }

+ 3 - 7
JBIM/JBIM/Relationship/OneToOneRel.cs

@@ -19,22 +19,18 @@ namespace JBIM.Relationship
         {
 
         }
-        public OneToOneRel(string relatingObject)
+        public OneToOneRel(BimId relatingObject)
         {
             RelatingObject = relatingObject;
         }
-        public OneToOneRel(string relatingObject, string relatedObject)
+        public OneToOneRel(BimId relatingObject, BimId relatedObject)
         {
             RelatingObject = relatingObject;
             RelatedObject = relatedObject;
         }
         /// <summary>
-        /// 主体对象
-        /// </summary>
-        public string RelatingObject { get; set; }
-        /// <summary>
         /// 关联对象
         /// </summary>
-        public string RelatedObject { get; set; }
+        public BimId RelatedObject { get; set; }   
     }
 }

+ 11 - 40
JBIM/JBIM/Relationship/RelationshipBase.cs

@@ -11,6 +11,7 @@ using System.Linq;
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using JBIM.Common;
 
 namespace JBIM.Relationship
 {
@@ -26,58 +27,28 @@ namespace JBIM.Relationship
      *    通过关系名称进行反射,获取相应的值进行赋值,或者在List集合中加入相关项;
      *
      * 开放自定义关系:
+     *
+     * 数据定义,尽量不要掺加方法
      */
     /// <summary>
     /// 关系基类
     /// </summary>
+    [TypeDefiniton(TypeDefinition.Relationship)]
     public class RelationshipBase: BimObject
     {
         public RelationshipBase()
         {
-            IsProperty = true;
-            this.ElementType = TypeDefinition.Relationship.ToString();
-        }
-        /// <summary>
-        /// 标志关系是否由属性定义
-        /// </summary>
-        public bool IsProperty { get;protected set; }
-        public void SetPropertyName(string propertyName)
-        {
-            PropertyName = propertyName;
-        }
-        public void SetElementType(TypeDefinition type)
-        {
-            this.ElementType = type.ToString();
-            PropertyName = type.GetDescription();
+            //this.ElementType = TypeDefinition.Relationship.ToString();
         }
-        public string PropertyName { get; private set; }
-        public virtual void AcceptRelation(BimObject bimObject)
-        {
-            if (!IsProperty)
-            {
-                return;
-            }
 
-            AcceptRelationInner(bimObject);
-        }
-        protected virtual void AcceptRelationInner(BimObject bimObject)
+        public void SetElementType(TypeDefinition type)
         {
-
+            this.ElementType =TypeDefinitonUtil.GetTypeDefiniton(type);
         }
+        /// <summary>
+        /// 主体对象
+        /// </summary>
+        public BimId RelatingObject { get; set; }
 
-        protected PropertyInfo ParseProperty(BimObject bimObject)
-        {
-            var type = bimObject.GetType();
-            string propertyName = PropertyName;
-            var key = type.FullName + "_" + propertyName;
-            var propertyInfo = PropertyCache.GetProperty(key);
-            if (propertyInfo == null)
-            {
-                //缓存解析出来的属性元数据,以便提高解析速度
-                var property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);
-                PropertyCache.SetProperty(key,property);
-            }
-            return propertyInfo;
-        }
     }
 }

BIN
JBIM/JBIM/bin/Debug/JBIM.dll


BIN
JBIM/JBIM/bin/Debug/JBIM.pdb


BIN
JBIM/RevitExport/bin/Debug/SAGA.RevitUtility.dll


+ 6 - 4
JBIM/RevitToJBim/ComponentParse/ParseConnector.cs

@@ -16,6 +16,7 @@ using JBIM;
 using JBIM.Relationship;
 using RevitExport;
 using RevitToJBim.Common;
+using SAGA.RevitUtils.MEP;
 using JConnector = JBIM.Component.Connector;
 
 namespace RevitToJBim.ComponentParse
@@ -59,16 +60,17 @@ namespace RevitToJBim.ComponentParse
             var systemId = connector.MEPSystem?.Id?.ToString();
             if (!string.IsNullOrWhiteSpace(systemId))
             {
-                OneToOneRel rel = new OneToOneRel(connectorId, systemId);
-                rel.SetElementType(TypeDefinition.MepSystem);
+                ElementOneToOneRel rel = new ElementOneToOneRel(connectorId, systemId);
+                rel.SetElementType(TypeDefinition.Property_MepSystem);
                 context.RelationShips.Add(rel);
             }
            
             #endregion
             #region 关联Connector
             //这里只维护关联,不进行递归
-            var refConnectors = new List<Connector>();
-            OneToManyRel relMany = new OneToManyRel(connectorId){RelatedObjects=new List<string>()};
+            var refConnectors = connector.GetReferenceConnectors();
+            ElementOneToManyRel relMany = new ElementOneToManyRel(connectorId){RelatedObjects=new List<string>()};
+            relMany.SetElementType(TypeDefinition.Property_MepSystem);
             foreach (var refConnector in refConnectors)
             {
                 relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));

+ 1 - 14
JBIM/RevitToJBim/ComponentParse/ParseCore.cs

@@ -90,20 +90,7 @@ namespace RevitToJBim.ComponentParse
             result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
             return result;
         }
-        public static MepSystem CreateConnector(Autodesk.Revit.DB.MEPSystem mepSystem)
-        {
-            var result= new MepSystem();
-            result.Name = mepSystem.Name;
-            result.SourceId = mepSystem.Id.ToString();
-            return result;
-        }
-        public static MepSystemType CreateConnector(Autodesk.Revit.DB.MEPSystemType mepSystemType)
-        {
-            var result = new MepSystemType();
-            result.Name = mepSystemType.Name;
-            result.SourceId = mepSystemType.Id.ToString();
-            return result;
 
-        }
+       
     }
 }

+ 15 - 3
JBIM/RevitToJBim/ComponentParse/ParsePipe.cs

@@ -16,6 +16,7 @@ using JBIM.Relationship;
 using RevitExport;
 using RevitToJBim.Common;
 using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
 using JPipe=JBIM.Component.Pipe;
 
 namespace RevitToJBim.ComponentParse
@@ -55,12 +56,23 @@ namespace RevitToJBim.ComponentParse
             #region 系统关系
             var pipeId = pipe.Id.ToString();
             var systemId = pipe.MEPSystem.Id.ToString();
-            OneToOneRel rel = new OneToOneRel(pipeId, systemId);
-            rel.SetElementType(TypeDefinition.MepSystem);
+            ElementOneToOneRel rel = new ElementOneToOneRel(pipeId, systemId);
+            rel.SetElementType(TypeDefinition.Property_MepSystem);
             context.RelationShips.Add(rel);
             #endregion
             #region Connector连接关系
-         
+            var connectors = pipe.GetConnectors();
+            ElementOneToManyRel relMany = new ElementOneToManyRel(pipeId) { RelatedObjects = new List<string>() };
+            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
+            foreach (var refConnector in connectors)
+            {
+                relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
+            }
+
+            if (relMany.RelatedObjects.Any())
+            {
+                context.RelationShips.Add(relMany);
+            }
             #endregion
             #endregion
             return new List<BimId>(){ jPipe.Id };

+ 79 - 29
JBIM/RevitToJBim/JBimParseContext.cs

@@ -7,14 +7,10 @@
 
 using System;
 using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using JBIM;
+using JBIM.Common;
 using JBIM.Component;
 using JBIM.Relationship;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
 using RevitExport;
 using RevitToJBim.JsonConverter;
 
@@ -29,7 +25,7 @@ namespace RevitToJBim
         {
             Parser = new RevitToJBimParser(this, parsers);
             Document = new BimDocument();
-            RelationShips = new List<RelationshipBase>();
+            RelationShips = new List<ElementRelationShip>();
         }
         public RevitToJBimParser Parser { get; private set; }
         public BimDocument Document { get;private set; }
@@ -45,7 +41,24 @@ namespace RevitToJBim
             }
             m_RevitIdMap.TryGetValue(revitSourceId, out BimId 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)
         {
             var id= this.Document.NewObject(obj)?.Id;
@@ -58,7 +71,7 @@ namespace RevitToJBim
         #endregion
 
         #region 关系数据统一存储
-        public List<RelationshipBase> RelationShips { get; private set; }
+        public List<ElementRelationShip> RelationShips { get; private set; }
         #endregion
 
         #region 解析方法
@@ -78,16 +91,16 @@ namespace RevitToJBim
              * 当前关系数据是一个临时数据,需要不全信息之后才能真实使用
              * 临时数据中,存储的是SourceId的对应关系
              */
-            var useShips = new List<RelationshipBase>();
             foreach (var relationshipBase in RelationShips)
             {
-                if (!relationshipBase.IsProperty)
+                if (relationshipBase.IsProperty)
                 {
-                    Document.NewObject(relationshipBase);
+                    UpdateRelationShipInfo(relationshipBase);
                 }
                 else
                 {
-                    //var bimId = GetBimId(relationshipBase.re)
+                    var bimRelation = ConvertRelationShipInfo(relationshipBase);
+                    Document.NewObject(bimRelation);
                 }
             }
             #endregion
@@ -95,31 +108,68 @@ namespace RevitToJBim
             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
     }

+ 36 - 0
JBIM/RevitToJBim/ParseData/ElementOneToManyRel.cs

@@ -0,0 +1,36 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:OneToManyRel
+ * 作者:xulisong
+ * 创建时间: 2019/6/17 10:49:50
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim
+{
+    public class ElementOneToManyRel : ElementRelationShip
+    {
+        public ElementOneToManyRel()
+        {
+
+        }
+        public ElementOneToManyRel(string relatingObject)
+        {
+            RelatingObject = relatingObject;
+        }
+        public ElementOneToManyRel(string relatingObject, List<string> relatedObjects)
+        {
+            RelatingObject = relatingObject;
+            RelatedObjects = relatedObjects;
+        }
+        /// <summary>
+        /// 关联对象
+        /// </summary>
+        public List<string> RelatedObjects { get; set; }
+    }
+}

+ 36 - 0
JBIM/RevitToJBim/ParseData/ElementOneToOneRel.cs

@@ -0,0 +1,36 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:OneToOneRel
+ * 作者:xulisong
+ * 创建时间: 2019/6/17 10:49:09
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim
+{
+    public class ElementOneToOneRel : ElementRelationShip
+    {
+        public ElementOneToOneRel()
+        {
+
+        }
+        public ElementOneToOneRel(string relatingObject)
+        {
+            RelatingObject = relatingObject;
+        }
+        public ElementOneToOneRel(string relatingObject, string relatedObject)
+        {
+            RelatingObject = relatingObject;
+            RelatedObject = relatedObject;
+        }
+        /// <summary>
+        /// 关联对象
+        /// </summary>
+        public string RelatedObject { get; set; }
+    }
+}

+ 41 - 0
JBIM/RevitToJBim/ParseData/ElementRelationShip.cs

@@ -0,0 +1,41 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ElementRelationShip
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 14:57:08
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM;
+
+namespace RevitToJBim
+{
+    public class ElementRelationShip
+    {
+        public ElementRelationShip()
+        {
+            IsProperty = true;
+        }
+        /// <summary>
+        /// 主体对象
+        /// </summary>
+        public string RelatingObject { get; set; }
+        /// <summary>
+        /// 标志关系是否由属性定义
+        /// </summary>
+        public bool IsProperty { get;  set; }
+        public void SetPropertyName(string propertyName)
+        {
+            PropertyName = propertyName;
+        }
+        public void SetElementType(TypeDefinition type)
+        {
+            PropertyName = type.GetDescription();
+        }
+        public string PropertyName { get; private set; }
+    }
+}

+ 6 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -40,6 +40,9 @@
     <Reference Include="RevitAPIUI">
       <HintPath>..\Dlls\RevitAPIUI.dll</HintPath>
     </Reference>
+    <Reference Include="SAGA.RevitUtility">
+      <HintPath>..\Dlls\SAGA.RevitUtility.dll</HintPath>
+    </Reference>
     <Reference Include="SAGA.RevitUtils">
       <HintPath>..\Dlls\SAGA.RevitUtils.dll</HintPath>
     </Reference>
@@ -65,6 +68,9 @@
     <Compile Include="ComponentParse\UsableParseAttribute.cs" />
     <Compile Include="JsonConverter\BimIdConverter.cs" />
     <Compile Include="JsonConverter\BimJsonUtil.cs" />
+    <Compile Include="ParseData\ElementRelationShip.cs" />
+    <Compile Include="ParseData\ElementOneToManyRel.cs" />
+    <Compile Include="ParseData\ElementOneToOneRel.cs" />
     <Compile Include="RevitToJBimParser.cs" />
     <Compile Include="JBimParseContext.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

BIN
JBIM/RevitToJBim/bin/Debug/JBIM.dll


BIN
JBIM/RevitToJBim/bin/Debug/JBIM.pdb


BIN
JBIM/RevitToJBim/bin/Debug/RevitToJBim.dll


BIN
JBIM/RevitToJBim/bin/Debug/RevitToJBim.pdb


BIN
JBIM/RevitToJBim/bin/Debug/SAGA.RevitUtility.dll