Forráskód Böngészése

xls:完善解析关系

xulisong 5 éve
szülő
commit
6e491b3be0
65 módosított fájl, 102299 hozzáadás és 49 törlés
  1. 3 3
      JBIM/JBIM/BimDocument.cs
  2. 4 0
      JBIM/JBIM/BimId.cs
  3. 12 0
      JBIM/JBIM/Component/Duct.cs
  4. 12 0
      JBIM/JBIM/Component/Pipe.cs
  5. 2 0
      JBIM/JBIM/Definition/TypeDefinition.cs
  6. 7 0
      JBIM/JBIM/Definition/XYZ.cs
  7. 0 10
      JBIM/JBIM/Properties/AssemblyInfo.cs
  8. 13 0
      JBIM/JBIM/Relationship/OneToManyRel.cs
  9. 13 0
      JBIM/JBIM/Relationship/OneToOneRel.cs
  10. BIN
      JBIM/JBIM/bin/Debug/JBIM.dll
  11. BIN
      JBIM/JBIM/bin/Debug/JBIM.pdb
  12. 23 1
      JBIM/RevitExport/Export/ElementWrapper.cs
  13. 2 2
      JBIM/RevitExport/Parse/IParseElement.cs
  14. 9 6
      JBIM/RevitExport/Parse/ParseInstance.cs
  15. BIN
      JBIM/RevitExport/bin/Debug/RevitAPI.dll
  16. BIN
      JBIM/RevitExport/bin/Debug/RevitAPIUI.dll
  17. BIN
      JBIM/RevitExport/bin/Debug/RevitExport.dll
  18. BIN
      JBIM/RevitExport/bin/Debug/RevitExport.pdb
  19. BIN
      JBIM/RevitExport/bin/Debug/SAGA.RevitUtils.dll
  20. 1 1
      JBIM/RevitToJBim/Common/Converter.cs
  21. 2 2
      JBIM/RevitToJBim/ComponentParse/ParseBase.cs
  22. 101 0
      JBIM/RevitToJBim/ComponentParse/ParseConnector.cs
  23. 42 3
      JBIM/RevitToJBim/ComponentParse/ParseCore.cs
  24. 72 0
      JBIM/RevitToJBim/ComponentParse/ParseMepSystem.cs
  25. 36 3
      JBIM/RevitToJBim/ComponentParse/ParsePipe.cs
  26. 4 6
      JBIM/RevitToJBim/ComponentParse/ParseSpace.cs
  27. 19 0
      JBIM/RevitToJBim/ComponentParse/UsableParseAttribute.cs
  28. 73 5
      JBIM/RevitToJBim/JBimParseContext.cs
  29. 40 0
      JBIM/RevitToJBim/JsonConverter/BimIdConverter.cs
  30. 35 0
      JBIM/RevitToJBim/JsonConverter/BimJsonUtil.cs
  31. 11 0
      JBIM/RevitToJBim/RevitToJBim.csproj
  32. 2 7
      JBIM/RevitToJBim/RevitToJBimParser.cs
  33. BIN
      JBIM/RevitToJBim/bin/Debug/JBIM.dll
  34. BIN
      JBIM/RevitToJBim/bin/Debug/JBIM.pdb
  35. BIN
      JBIM/RevitToJBim/bin/Debug/Newtonsoft.Json.dll
  36. 10912 0
      JBIM/RevitToJBim/bin/Debug/Newtonsoft.Json.xml
  37. BIN
      JBIM/RevitToJBim/bin/Debug/RevitAPI.dll
  38. BIN
      JBIM/RevitToJBim/bin/Debug/RevitAPIUI.dll
  39. BIN
      JBIM/RevitToJBim/bin/Debug/RevitExport.dll
  40. BIN
      JBIM/RevitToJBim/bin/Debug/RevitExport.pdb
  41. BIN
      JBIM/RevitToJBim/bin/Debug/RevitToJBim.dll
  42. BIN
      JBIM/RevitToJBim/bin/Debug/RevitToJBim.pdb
  43. BIN
      JBIM/RevitToJBim/bin/Debug/SAGA.RevitUtils.dll
  44. 4 0
      JBIM/RevitToJBim/packages.config
  45. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/.signature.p7s
  46. 20 0
      JBIM/packages/Newtonsoft.Json.11.0.2/LICENSE.md
  47. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/Newtonsoft.Json.11.0.2.nupkg
  48. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net20/Newtonsoft.Json.dll
  49. 9967 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net20/Newtonsoft.Json.xml
  50. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net35/Newtonsoft.Json.dll
  51. 9096 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net35/Newtonsoft.Json.xml
  52. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net40/Newtonsoft.Json.dll
  53. 9296 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net40/Newtonsoft.Json.xml
  54. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net45/Newtonsoft.Json.dll
  55. 10912 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/net45/Newtonsoft.Json.xml
  56. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.0/Newtonsoft.Json.dll
  57. 10619 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.0/Newtonsoft.Json.xml
  58. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.3/Newtonsoft.Json.dll
  59. 10722 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.3/Newtonsoft.Json.xml
  60. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard2.0/Newtonsoft.Json.dll
  61. 10887 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard2.0/Newtonsoft.Json.xml
  62. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll
  63. 8707 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.xml
  64. BIN
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll
  65. 10619 0
      JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.xml

+ 3 - 3
JBIM/JBIM/BimDocument.cs

@@ -42,11 +42,11 @@ namespace JBIM
 
         public BimObject NewObject(BimObject originObject)
         {
-            if (originObject.Id == null)
+            if (originObject.Id != null)
             {
-                originObject.Id = GenerateId();
+                return originObject;
             }
-
+            originObject.Id = GenerateId();
             AddObject(originObject);
             return originObject;
         }

+ 4 - 0
JBIM/JBIM/BimId.cs

@@ -31,6 +31,10 @@ namespace JBIM
         /// </summary>
         public string Id { get; private set; }
 
+        public override string ToString()
+        {
+            return Id?.ToString() ?? string.Empty;
+        }
         public override bool Equals(object obj)
         {
             if (obj is BimId inputId)

+ 12 - 0
JBIM/JBIM/Component/Duct.cs

@@ -20,6 +20,18 @@ namespace JBIM.Component
     [TypeDefiniton(TypeDefinition.Duct)]
     public class Duct:VisibleComponentObject
     {
+        public Duct()
+        {
+            ConnectedIds = new List<BimId>();
+        }
+        /// <summary>
+        /// connector关联的系统实例
+        /// </summary>
+        public BimId MepSystem { get; set; }
+        /// <summary>
+        /// Connector连接的connectorIds
+        /// </summary>
+        public List<BimId> ConnectedIds { get; private set; }
         /// <summary>
         /// 风管形状
         /// </summary>

+ 12 - 0
JBIM/JBIM/Component/Pipe.cs

@@ -17,6 +17,18 @@ namespace JBIM.Component
     [TypeDefiniton(TypeDefinition.Pipe)]
     public class Pipe:VisibleComponentObject
     {
+        public Pipe()
+        {
+            ConnectedIds = new List<BimId>();
+        }
+        /// <summary>
+        /// Connector连接的connectorIds
+        /// </summary>
+        public List<BimId> ConnectedIds { get; private set; }
+        /// <summary>
+        /// connector关联的系统实例
+        /// </summary>
+        public BimId MepSystem { get; set; }
         /// <summary>
         /// 管道直径
         /// </summary>

+ 2 - 0
JBIM/JBIM/Definition/TypeDefinition.cs

@@ -51,6 +51,8 @@ namespace JBIM
         Property_TypeId = Relationship - 3,
         [Description("ConnectedIds")]
         Property_ConnectedIds = Relationship - 4,
+        [Description("Host")]
+        Property_Host = Relationship - 5,
         #endregion
     }
 }

+ 7 - 0
JBIM/JBIM/Definition/XYZ.cs

@@ -27,6 +27,13 @@ namespace JBIM
 
     public class Polygon : List<XYZ>
     {
+        public Polygon()
+        {
 
+        }
+        public Polygon(IEnumerable<XYZ> collection):base(collection)
+        {
+
+        }
     }
 }

+ 0 - 10
JBIM/JBIM/Properties/AssemblyInfo.cs

@@ -31,16 +31,6 @@ using System.Windows;
 //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
 
 
-[assembly: ThemeInfo(
-    ResourceDictionaryLocation.None, //主题特定资源词典所处位置
-                                     //(未在页面中找到资源时使用,
-                                     //或应用程序资源字典中找到时使用)
-    ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
-                                              //(未在页面中找到资源时使用,
-                                              //、应用程序或任何主题专用资源字典中找到时使用)
-)]
-
-
 // 程序集的版本信息由下列四个值组成: 
 //
 //      主版本

+ 13 - 0
JBIM/JBIM/Relationship/OneToManyRel.cs

@@ -15,6 +15,19 @@ namespace JBIM.Relationship
 {
     public class OneToManyRel:RelationshipBase
     {
+        public OneToManyRel()
+        {
+
+        }
+        public OneToManyRel(string relatingObject)
+        {
+            RelatingObject = relatingObject;
+        }
+        public OneToManyRel(string relatingObject, List<string> relatedObjects)
+        {
+            RelatingObject = relatingObject;
+            RelatedObjects = relatedObjects;
+        }
         /// <summary>
         /// 主体对象
         /// </summary>

+ 13 - 0
JBIM/JBIM/Relationship/OneToOneRel.cs

@@ -15,6 +15,19 @@ namespace JBIM.Relationship
 {
     public class OneToOneRel : RelationshipBase
     {
+        public OneToOneRel()
+        {
+
+        }
+        public OneToOneRel(string relatingObject)
+        {
+            RelatingObject = relatingObject;
+        }
+        public OneToOneRel(string relatingObject, string relatedObject)
+        {
+            RelatingObject = relatingObject;
+            RelatedObject = relatedObject;
+        }
         /// <summary>
         /// 主体对象
         /// </summary>

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


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


+ 23 - 1
JBIM/RevitExport/Export/ElementWrapper.cs

@@ -15,17 +15,39 @@ namespace RevitExport
         public ElementWrapper(Element element)
         {
             RefElement = element;
+            IsRevitElement = true;
             UseDefaultCategory();
+            SourceId = element.Id.ToString();
         }
+        public ElementWrapper(object instance,string sourceId)
+        {
+            RefObject = instance;
+            IsRevitElement = false;
+            UseDefaultCategory();
+            SourceId = sourceId;
+        }
+        public bool IsRevitElement { get; private set; }
         /// <summary>
         /// 使用默认的分类
         /// </summary>
         public void UseDefaultCategory()
         {
-            Category = RefElement.GetType().ToString();
+            Category = IsRevitElement ? RefElement.GetType().FullName : RefObject.GetType().FullName;
         }
         public Element RefElement { get; private set; }
 
         public string Category { get; set; }
+
+        public string SourceId { get; private set; }
+        #region 普通对象处理
+
+        public object RefObject{ get; private set; }
+
+        public T GetObject<T>()
+        {
+            return (T)RefObject;
+        }
+       
+        #endregion
     }
 }

+ 2 - 2
JBIM/RevitExport/Parse/IParseElement.cs

@@ -18,7 +18,7 @@ namespace RevitExport
     /// </summary>
     public interface IParseElement
     {
-        string FastIndex();
+        List<string> FastIndex();
         bool Match(ElementWrapper wrapper);
         List<string> Parse(ElementWrapper wrapper, ParseContext context);
         List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, ParseContext context);
@@ -28,7 +28,7 @@ namespace RevitExport
     /// </summary>
     public interface IParseElement<in C,  Result> where C: ParseContext
     {
-        string FastIndex();
+        List<string> FastIndex();
         bool Match(ElementWrapper wrapper);
         List<Result> Parse(ElementWrapper wrapper, C context);
         List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, C context);

+ 9 - 6
JBIM/RevitExport/Parse/ParseInstance.cs

@@ -34,11 +34,14 @@ namespace RevitExport
             FastFilter = new Dictionary<string, IParseElement<C, Result>>();
             foreach (var parseElement in Parsers)
             {
-                var key = parseElement.FastIndex();
-                if (!string.IsNullOrWhiteSpace(key))
+                var keys = parseElement.FastIndex();
+                foreach (var key in keys)
                 {
-                    FastFilter[key] = parseElement;
-                }
+                    if (!string.IsNullOrWhiteSpace(key))
+                    {
+                        FastFilter[key] = parseElement;
+                    }
+                }               
             }
         }
         protected virtual IParseElement<C, Result> GetMatchParser(ElementWrapper wrapper)
@@ -51,7 +54,7 @@ namespace RevitExport
             return currentParse;
         }
 
-        public virtual List<Result> ParseElement(ElementWrapper elementWrapper, C context)
+        public virtual List<Result> ParseElement(ElementWrapper elementWrapper)
         {
             var currentParser = GetMatchParser(elementWrapper);
             if (currentParser != null)
@@ -66,7 +69,7 @@ namespace RevitExport
             if (!Parsers.Any())
                 return;
             ElementWrapper element = e.ElementWrapper;
-            ParseElement(element, Context);      
+            ParseElement(element);      
         }
 
         /// <summary>

BIN
JBIM/RevitExport/bin/Debug/RevitAPI.dll


BIN
JBIM/RevitExport/bin/Debug/RevitAPIUI.dll


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


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


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


+ 1 - 1
JBIM/RevitToJBim/Common/Converter.cs

@@ -15,7 +15,7 @@ using SAGA.RevitUtils.Extends;
 
 namespace RevitToJBim.Common
 {
-    public static class BimConverter
+    public static class BimConvert
     {
         public static readonly int CoordinateDecimalDigits = 2;
 

+ 2 - 2
JBIM/RevitToJBim/ComponentParse/ParseBase.cs

@@ -23,7 +23,7 @@ namespace RevitToJBim.ComponentParse
         /// 快速索引
         /// </summary>
         /// <returns></returns>
-        public virtual string FastIndex()
+        public virtual List<string> FastIndex()
         {
             return null;//Guid.NewGuid().ToString("N");
         }
@@ -47,7 +47,7 @@ namespace RevitToJBim.ComponentParse
                 {
                     try
                     {
-                        context.Parse(elementWrapper);
+                        context.Parser.ParseElement(elementWrapper);
                     }
                     catch (Exception e)
                     {

+ 101 - 0
JBIM/RevitToJBim/ComponentParse/ParseConnector.cs

@@ -0,0 +1,101 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseConnector
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 11:26:05
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using JBIM;
+using JBIM.Relationship;
+using RevitExport;
+using RevitToJBim.Common;
+using JConnector = JBIM.Component.Connector;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseConnector : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(Connector).FullName, typeof(MechanicalSystemType).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.GetObject<Connector>() != null;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            var connector = wrapper.GetObject<Connector>();
+            if (connector == null)
+            {
+                return null;
+            }
+            JConnector jConnector = ParseCore.CreateConnector(connector);
+            jConnector.SourceId = wrapper.SourceId;
+            context.AddBimObject(jConnector);
+
+            #region 所属类别解析
+            //直接递归方式获取
+            var owner = connector.Owner;
+            if (owner != null)
+            {
+                ElementWrapper systemTypeWrapper = new ElementWrapper(owner);
+                jConnector.Owner = context.Parser.ParseElement(systemTypeWrapper)?.FirstOrDefault();
+            }
+            #endregion
+
+            #region 所属系统解析
+            //维护关联并递归
+            var connectorId = jConnector.SourceId;
+            var systemId = connector.MEPSystem?.Id?.ToString();
+            if (!string.IsNullOrWhiteSpace(systemId))
+            {
+                OneToOneRel rel = new OneToOneRel(connectorId, systemId);
+                rel.SetElementType(TypeDefinition.MepSystem);
+                context.RelationShips.Add(rel);
+            }
+           
+            #endregion
+            #region 关联Connector
+            //这里只维护关联,不进行递归
+            var refConnectors = new List<Connector>();
+            OneToManyRel relMany = new OneToManyRel(connectorId){RelatedObjects=new List<string>()};
+            foreach (var refConnector in refConnectors)
+            {
+                relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
+            }
+
+            if (relMany.RelatedObjects.Any())
+            {
+                context.RelationShips.Add(relMany);
+            }
+            #endregion
+            return new List<BimId>() { jConnector.Id };
+        }
+
+        public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefObject is Connector connector))
+            {
+                return null;
+            }
+
+            if (connector.MEPSystem == null)
+            {
+                return null;
+            }
+            //创建MepSystem
+            var mepSystemElementWrapper = new ElementWrapper(connector.MEPSystem);
+            return new List<ElementWrapper>() { mepSystemElementWrapper };
+        }
+    }
+}

+ 42 - 3
JBIM/RevitToJBim/ComponentParse/ParseCore.cs

@@ -8,11 +8,15 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using Autodesk.Revit.DB;
 using JBIM;
 using JBIM.Component;
+using RevitExport;
 using RevitToJBim.Common;
+using Connector = JBIM.Component.Connector;
 
 namespace RevitToJBim.ComponentParse
 {
@@ -24,6 +28,41 @@ namespace RevitToJBim.ComponentParse
     /// </summary>
     public class ParseCore
     {
+        public class ParseElementManager
+        {
+            //获取可用的解析类
+            public static List<ParseBase> GetUseParses()
+            {
+                List<ParseBase> result = new List<ParseBase>();
+                Assembly assembly = Assembly.GetCallingAssembly();
+                Type[] types = assembly.GetTypes();
+                foreach (var type in types)
+                {
+                    if (typeof(ParseBase).IsAssignableFrom (type))
+                    {
+                        if (type.IsAbstract || type.IsGenericTypeDefinition)
+                            continue;
+                        var attribute = type.GetCustomAttribute<UsableParseAttribute>();
+                        if (attribute == null)
+                            continue;
+                        var construstor = type.GetConstructor(Type.EmptyTypes);
+                        if (construstor == null)
+                            continue;
+                        if (construstor.Invoke(null) is ParseBase parse)
+                            result.Add(parse);
+
+                    }
+                }
+
+                return result;
+
+            }
+        }
+        public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
+        {
+            bimObj.SourceId = wrapper.SourceId;
+            bimObj.Name = wrapper.RefElement?.Name;
+        }
         public static BimObject GetObject(object obj)
         {
             return null;
@@ -35,12 +74,12 @@ namespace RevitToJBim.ComponentParse
             result.SourceId = RevitIdGenerator.GetConnectorId(connector);
             switch (connector.Domain)
             {
-                case Autodesk.Revit.DB.Domain.DomainHvac:
+                case Domain.DomainHvac:
                 {
                     result.Domain = ConnectorDomain.DomainHvac.ToString();
                     break;
                 }
-                case Autodesk.Revit.DB.Domain.DomainPiping:
+                case Domain.DomainPiping:
                 {
                     result.Domain = ConnectorDomain.DomainPiping.ToString();
                     break;
@@ -48,7 +87,7 @@ namespace RevitToJBim.ComponentParse
             }
             result.IsConnected = connector.IsConnected;
             result.Description = connector.Description;
-            result.Origin = BimConverter.ConvertToXYZ(connector.Origin);
+            result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
             return result;
         }
         public static MepSystem CreateConnector(Autodesk.Revit.DB.MEPSystem mepSystem)

+ 72 - 0
JBIM/RevitToJBim/ComponentParse/ParseMepSystem.cs

@@ -0,0 +1,72 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseMepSystem
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 9:16:15
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using Autodesk.Revit.DB.Plumbing;
+using JBIM;
+using RevitExport;
+using JMepSystem = JBIM.Component.MepSystem;
+using JMepSystemType = JBIM.Component.MepSystemType;
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseMepSystem : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>(){typeof(PipingSystem).FullName, typeof(MechanicalSystem).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is MEPSystem;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            JMepSystem jBimObject = new JMepSystem();
+            ParseCore.AttachObject(jBimObject, wrapper);
+            var document = wrapper.RefElement.Document;
+            #region 直接自己获取解析信息,不通过架构获取
+            var mepSystemType = document.GetElement(wrapper.RefElement.GetTypeId()) as MEPSystemType;
+            if (mepSystemType != null)
+            {
+                ElementWrapper systemTypeWrapper = new ElementWrapper(mepSystemType);
+                jBimObject.TypeId = context.Parser.ParseElement(systemTypeWrapper)?.FirstOrDefault();
+            } 
+            #endregion
+
+            context.AddBimObject(jBimObject);
+            return new List<BimId>() { jBimObject.Id };
+        }
+    }
+    [UsableParse]
+    public class ParseMepSystemType : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(PipingSystemType).FullName, typeof(MechanicalSystemType).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is MEPSystemType;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            JMepSystemType jBimObject = new JMepSystemType();
+            ParseCore.AttachObject(jBimObject, wrapper);      
+            context.AddBimObject(jBimObject);
+            return new List<BimId>() { jBimObject.Id };
+        }
+    }
+}

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

@@ -12,13 +12,21 @@ using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB.Plumbing;
 using JBIM;
+using JBIM.Relationship;
 using RevitExport;
+using RevitToJBim.Common;
+using SAGA.RevitUtils.Extends;
 using JPipe=JBIM.Component.Pipe;
 
 namespace RevitToJBim.ComponentParse
 {
+    [UsableParseAttribute]
     public class ParsePipe : ParseBase
     {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(Pipe).FullName };
+        }
         public override bool Match(ElementWrapper wrapper)
         {
             return wrapper.RefElement is Pipe;
@@ -35,13 +43,38 @@ namespace RevitToJBim.ComponentParse
             {
                 return null;
             }
-            JPipe jPipe = new JPipe();   
-            return null;
+            JPipe jPipe = new JPipe();
+            ParseCore.AttachObject(jPipe, wrapper);
+            jPipe.Diameter = BimConvert.Round(pipe.Diameter.FromApi());
+            jPipe.Location.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().StartPoint()));
+            jPipe.Location.Add(BimConvert.ConvertToXYZ(pipe.GetCurve().EndPoint()));
+            Polygon outLine = new Polygon(jPipe.Location);
+            jPipe.OutLine.Add(outLine);
+            context.AddBimObject(jPipe);
+            #region 关联数据处理相关
+            #region 系统关系
+            var pipeId = pipe.Id.ToString();
+            var systemId = pipe.MEPSystem.Id.ToString();
+            OneToOneRel rel = new OneToOneRel(pipeId, systemId);
+            rel.SetElementType(TypeDefinition.MepSystem);
+            context.RelationShips.Add(rel);
+            #endregion
+            #region Connector连接关系
+         
+            #endregion
+            #endregion
+            return new List<BimId>(){ jPipe.Id };
         }
 
         public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
         {
-            return base.ArrangeRefElements(wrapper, context);
+            if (!(wrapper.RefElement is Pipe pipe))
+            {
+                return null;
+            }
+            //创建MepSystem
+            var mepSystemElementWrapper = new ElementWrapper(pipe.MEPSystem);
+            return new List<ElementWrapper>() {mepSystemElementWrapper};
         }
     }
 }

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

@@ -11,25 +11,23 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB.Mechanical;
+using JBIM;
 using RevitExport;
 
 namespace RevitToJBim.ComponentParse
 {
     public class ParseSpace : ParseBase
     {
-        public override string FastIndex()
+        public override List<string> FastIndex()
         {
-            return typeof(Space).ToString();
+            return new List<string>() {typeof(Space).FullName};
         }
         public override bool Match(ElementWrapper wrapper)
         {
             return wrapper.RefElement is Space;
         }
-
-        public override void Parse(ElementWrapper wrapper, JBimParseContext context)
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
         {
-            var bimId=context.GetBimId(wrapper.RefElement.Id.ToString());
-
             throw new NotImplementedException();
         }
     }

+ 19 - 0
JBIM/RevitToJBim/ComponentParse/UsableParseAttribute.cs

@@ -0,0 +1,19 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:UsableParseAttribute
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 10:57:33
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim.ComponentParse
+{
+    public class UsableParseAttribute : Attribute
+    {
+    }
+}

+ 73 - 5
JBIM/RevitToJBim/JBimParseContext.cs

@@ -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
     }

+ 40 - 0
JBIM/RevitToJBim/JsonConverter/BimIdConverter.cs

@@ -0,0 +1,40 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:BimIdConverter
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 11:16:54
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM;
+using Newtonsoft.Json;
+
+namespace RevitToJBim.JsonConverter
+{
+    public class BimIdConverter : Newtonsoft.Json.JsonConverter
+    {
+        public override bool CanConvert(Type objectType)
+        {
+            return objectType == typeof(BimId);
+        }
+
+        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+        {
+            if (value == null)
+            {
+                writer.WriteNull();
+                return;
+            }
+            writer.WriteValue(value.ToString());
+        }
+    }
+}

+ 35 - 0
JBIM/RevitToJBim/JsonConverter/BimJsonUtil.cs

@@ -0,0 +1,35 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:BimJsonUtil
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 11:23:16
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM;
+using Newtonsoft.Json;
+
+namespace RevitToJBim.JsonConverter
+{
+    public static class BimJsonUtil
+    {
+        public static string Serializer(BimDocument document)
+        {
+            JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
+            jsetting.Converters.Add(new BimIdConverter());
+            //var serializer = JsonSerializer.Create(jsetting);
+            //JObject jobject = new JObject();
+            //foreach (var collection in m_DataSource)
+            //{
+            //    jobject.Add(collection.Key, JArray.FromObject(collection.Value, serializer));
+            //}
+            //var settings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
+            string dataStr = JsonConvert.SerializeObject(document.BimObjects, jsetting);
+            return dataStr;
+        }
+    }
+}

+ 11 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -31,6 +31,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="RevitAPI">
       <HintPath>..\Dlls\RevitAPI.dll</HintPath>
     </Reference>
@@ -54,9 +57,14 @@
     <Compile Include="Common\ExceptionUtil.cs" />
     <Compile Include="Common\RevitIdGenerator.cs" />
     <Compile Include="ComponentParse\ParseBase.cs" />
+    <Compile Include="ComponentParse\ParseConnector.cs" />
     <Compile Include="ComponentParse\ParseCore.cs" />
+    <Compile Include="ComponentParse\ParseMepSystem.cs" />
     <Compile Include="ComponentParse\ParsePipe.cs" />
     <Compile Include="ComponentParse\ParseSpace.cs" />
+    <Compile Include="ComponentParse\UsableParseAttribute.cs" />
+    <Compile Include="JsonConverter\BimIdConverter.cs" />
+    <Compile Include="JsonConverter\BimJsonUtil.cs" />
     <Compile Include="RevitToJBimParser.cs" />
     <Compile Include="JBimParseContext.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
@@ -71,5 +79,8 @@
       <Name>RevitExport</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 2 - 7
JBIM/RevitToJBim/RevitToJBimParser.cs

@@ -21,14 +21,9 @@ namespace RevitToJBim
         {
            
         }
-        public override List<BimId> ParseElement(ElementWrapper elementWrapper, JBimParseContext context)
+        public override List<BimId> ParseElement(ElementWrapper elementWrapper)
         {
-            //BimId result = context.GetBimId(elementWrapper.RefElement.Id.ToString());
-            //if (result != null)
-            //{
-            //    return new List<BimId>() {result};
-            //}
-            return ParseElement(elementWrapper,context);
+            return ParseElement(elementWrapper);
         }
     }
 }

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


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


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


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 10912 - 0
JBIM/RevitToJBim/bin/Debug/Newtonsoft.Json.xml


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


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


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


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


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


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


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


+ 4 - 0
JBIM/RevitToJBim/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
+</packages>

BIN
JBIM/packages/Newtonsoft.Json.11.0.2/.signature.p7s


+ 20 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/LICENSE.md

@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2007 James Newton-King
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

BIN
JBIM/packages/Newtonsoft.Json.11.0.2/Newtonsoft.Json.11.0.2.nupkg


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net20/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 9967 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net20/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net35/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 9096 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net35/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net40/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 9296 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net40/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net45/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 10912 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/net45/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.0/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 10619 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.0/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.3/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 10722 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard1.3/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard2.0/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 10887 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/netstandard2.0/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 8707 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.xml


BIN
JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 10619 - 0
JBIM/packages/Newtonsoft.Json.11.0.2/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.xml