瀏覽代碼

mxg:修改底图文件格式

mengxiangge 5 年之前
父節點
當前提交
1de0b4d686
共有 40 個文件被更改,包括 1393 次插入135 次删除
  1. 5 4
      MBI/SAGA.MBI/Interaction/MBIModelInfoUpload.cs
  2. 73 0
      MBI/SAGA.MBI/RevitExport/Entity/BimConvert.cs
  3. 38 0
      MBI/SAGA.MBI/RevitExport/Entity/BimDocument.cs
  4. 68 0
      MBI/SAGA.MBI/RevitExport/Entity/BimId.cs
  5. 40 0
      MBI/SAGA.MBI/RevitExport/Entity/BimIdConverter.cs
  6. 32 0
      MBI/SAGA.MBI/RevitExport/Entity/CurveLoopExtension.cs
  7. 117 0
      MBI/SAGA.MBI/RevitExport/Entity/GeometryElementExtension.cs
  8. 48 0
      MBI/SAGA.MBI/RevitExport/Entity/GeometryLocation.cs
  9. 24 0
      MBI/SAGA.MBI/RevitExport/Entity/LocationType.cs
  10. 62 8
      MBI/SAGA.MBI/RevitExport/Entity/MBIElement.cs
  11. 9 8
      MBI/SAGA.MBI/RevitExport/Entity/MbiColumn.cs
  12. 19 0
      MBI/SAGA.MBI/RevitExport/Entity/MbiDoor.cs
  13. 4 2
      MBI/SAGA.MBI/RevitExport/Entity/MbiEquipment.cs
  14. 5 12
      MBI/SAGA.MBI/RevitExport/Entity/MbiSpace.cs
  15. 2 0
      MBI/SAGA.MBI/RevitExport/Entity/MbiVirtualWall.cs
  16. 6 0
      MBI/SAGA.MBI/RevitExport/Entity/MbiWall.cs
  17. 17 0
      MBI/SAGA.MBI/RevitExport/Entity/MbiWindow.cs
  18. 52 0
      MBI/SAGA.MBI/RevitExport/Entity/ParseCore.cs
  19. 28 0
      MBI/SAGA.MBI/RevitExport/Entity/Polygon.cs
  20. 187 0
      MBI/SAGA.MBI/RevitExport/Entity/RevitUtil.cs
  21. 35 0
      MBI/SAGA.MBI/RevitExport/Entity/StandardUtil.cs
  22. 83 0
      MBI/SAGA.MBI/RevitExport/Entity/TypeDefinition.cs
  23. 34 0
      MBI/SAGA.MBI/RevitExport/Entity/TypeDefinitonAttribute.cs
  24. 24 0
      MBI/SAGA.MBI/RevitExport/Entity/TypeDefinitonUtil.cs
  25. 69 0
      MBI/SAGA.MBI/RevitExport/Entity/WallExtension.cs
  26. 28 0
      MBI/SAGA.MBI/RevitExport/Entity/XYZ.cs
  27. 6 3
      MBI/SAGA.MBI/RevitExport/ExportData.cs
  28. 37 16
      MBI/SAGA.MBI/RevitExport/ExportDb.cs
  29. 3 1
      MBI/SAGA.MBI/RevitExport/MbiElementClassify.cs
  30. 3 1
      MBI/SAGA.MBI/RevitExport/MbiElementManager.cs
  31. 14 23
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseColumn.cs
  32. 60 0
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseDoor.cs
  33. 17 30
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseEquipment.cs
  34. 36 11
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseSpace.cs
  35. 10 4
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseVirtualWall.cs
  36. 13 8
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseWall.cs
  37. 57 0
      MBI/SAGA.MBI/RevitExport/ParseElement/ParseWindow.cs
  38. 21 0
      MBI/SAGA.MBI/SAGA.MBI.csproj
  39. 5 3
      MBI/SAGA.MBI/TestCommand.cs
  40. 2 1
      MBI/SAGA.MBI/WinView/Space/WinCreateSpaceWeb.xaml.cs

+ 5 - 4
MBI/SAGA.MBI/Interaction/MBIModelInfoUpload.cs

@@ -16,6 +16,7 @@ using SAGA.MBI.RequestData;
 using SAGA.MBI.RevitExport;
 using SAGA.MBI.WinView.TraceView;
 using SAGA.Models;
+using SAGA.RevitUtils;
 
 namespace SAGA.MBI.Interaction
 {
@@ -28,7 +29,7 @@ namespace SAGA.MBI.Interaction
         /// 上传信息点导出信息
         /// </summary>
         /// <returns></returns>
-        public static bool  UploadMbiInfo(string floorId)
+        public static bool  UploadMbiInfo(string floorId,string sagaName)
         {
             bool flag = false;
             string key = $"{floorId}"+DateTime.Now.ToString("yyyyMMddHHmmss")+"bim.jsonz";//楼层对应信息文件key值
@@ -36,7 +37,7 @@ namespace SAGA.MBI.Interaction
             string jsonStr = string.Empty;
             if (db != null)
             {
-                jsonStr = db.ToJsonString();
+                jsonStr = db.ToJsonString(sagaName);
             }
             //测试使用
             //File.WriteAllText(@"c:\" + key, jsonStr);
@@ -92,8 +93,8 @@ namespace SAGA.MBI.Interaction
                     Document doc = context.RevitDoc;
                     MbiElementManager.ExecuteExport(doc);
                     var floorId = doc.PathName.GetFileName();
-
-                    var flag=MBIModelInfoUpload.UploadMbiInfo(floorId);
+                    var sagaName = doc.GetUseView()?.Name;
+                    var flag=MBIModelInfoUpload.UploadMbiInfo(floorId, sagaName);
                     results[floorId] = flag;
                 }
                 catch (Exception ex)

+ 73 - 0
MBI/SAGA.MBI/RevitExport/Entity/BimConvert.cs

@@ -0,0 +1,73 @@
+/* ==============================================================================
+ * 功能描述:BimConvert  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:02:11
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    public static class BimConvert
+    {
+        public static readonly int CoordinateDecimalDigits = 2;
+
+        public static double Round(double coordinateDecimal)
+        {
+            return Math.Round(coordinateDecimal, CoordinateDecimalDigits);
+        }
+        /// <summary>
+        /// 英尺转换成现在阶段使用单位
+        /// </summary>
+        /// <param name="footValue"></param>
+        /// <returns></returns>
+        public static double FtToUse(this double footValue)
+        {
+            return Round(footValue.FromApi());
+        }
+        /// <summary>
+        /// 将点转换成毫米单位形式
+        /// </summary>
+        /// <param name="xyz"></param>
+        /// <param name="ignoreZ">转换是否忽略Z</param>
+        /// <returns></returns>
+        public static XYZ ConvertToXYZ(Autodesk.Revit.DB.XYZ xyz, bool ignoreZ = false)
+        {
+            var result = new XYZ()
+            {
+                X = FtToUse(xyz.X),
+                Y = FtToUse(xyz.Y)
+            };
+            if (!ignoreZ)
+            {
+                result.Z = FtToUse(xyz.Z);
+            }
+
+            return result;
+        }
+        /// <summary>
+        /// 转换成向量
+        /// </summary>
+        /// <param name="xyz"></param>
+        /// <returns></returns>
+        public static XYZ ConvertToDirection(Autodesk.Revit.DB.XYZ xyz)
+        {
+            return new XYZ() { X = xyz.X, Y = xyz.Y, Z = xyz.Z, };
+        }
+        /// <summary>
+        /// 将点转换成毫米单位形式
+        /// </summary>
+        /// <param name="xyzs"></param>
+        /// <param name="ignoreZ">转换是否忽略Z</param>
+        /// <returns></returns>
+        public static List<XYZ> ConvertToXYZs(List<Autodesk.Revit.DB.XYZ> xyzs, bool ignoreZ = false)
+        {
+            return xyzs.Select(xyz => ConvertToXYZ(xyz, ignoreZ)).ToList();
+        }
+
+    }
+}

+ 38 - 0
MBI/SAGA.MBI/RevitExport/Entity/BimDocument.cs

@@ -0,0 +1,38 @@
+/* ==============================================================================
+ * 功能描述:BimDocument  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:48:59
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// BimDocument
+    /// </summary>
+    public class BimDocument
+    {
+        /// <summary>
+        /// 当前索引信息
+        /// </summary>
+        private long CurrentIndex { get; set; } = 10000;
+        internal BimId GenerateId()
+        {
+            return new BimId((++CurrentIndex).ToString());
+        }
+
+        public MbiElement NewObject(MbiElement originObject)
+        {
+            if (originObject.Id != null)
+            {
+                return originObject;
+            }
+            originObject.Id = GenerateId();
+            return originObject;
+        }
+    }
+}

+ 68 - 0
MBI/SAGA.MBI/RevitExport/Entity/BimId.cs

@@ -0,0 +1,68 @@
+/* ==============================================================================
+ * 功能描述:BimId  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:31:03
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// BimId
+    /// </summary>
+    public class BimId
+    {
+        public BimId(string id)
+        {
+            this.Id = id;
+        }
+        /// <summary>
+        /// Id值
+        /// </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)
+            {
+                return Id == inputId.Id;
+
+            }
+            return false;
+        }
+        public override int GetHashCode()
+        {
+            if (string.IsNullOrWhiteSpace(Id))
+            {
+                return 0;
+            }
+
+            return Id.GetHashCode();
+        }
+        public static bool operator ==(BimId a, BimId b)
+        {
+            if ((object)a == null)
+            {
+                return (object)b == null;
+            }
+            return a.Equals(b);
+        }
+        public static bool operator !=(BimId a, BimId b)
+        {
+            if ((object)a == null)
+            {
+                return ((object)b != null);
+            }
+            return !a.Equals(b);
+        }
+
+    }
+}

+ 40 - 0
MBI/SAGA.MBI/RevitExport/Entity/BimIdConverter.cs

@@ -0,0 +1,40 @@
+/* ==============================================================================
+ * 功能描述:BimIdConverter  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 19:59:47
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// BimIdConverter
+    /// </summary>
+    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());
+        }
+    }
+}

+ 32 - 0
MBI/SAGA.MBI/RevitExport/Entity/CurveLoopExtension.cs

@@ -0,0 +1,32 @@
+/* ==============================================================================
+ * 功能描述:CurveLoopExtension  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:08:11
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    public static class CurveLoopExtension
+    {
+        public static List<Autodesk.Revit.DB.XYZ> GetPolygon(this CurveLoop curveLoop)
+        {
+            List<Autodesk.Revit.DB.XYZ> polygon = new List<Autodesk.Revit.DB.XYZ>();
+
+
+            foreach (Curve curve in curveLoop)
+            {
+                var points = curve.Tessellate();
+                points.RemoveAt(points.Count - 1);
+                polygon.AddRange(points);
+            }
+
+            return polygon;
+        }
+    }
+}

+ 117 - 0
MBI/SAGA.MBI/RevitExport/Entity/GeometryElementExtension.cs

@@ -0,0 +1,117 @@
+/* ==============================================================================
+ * 功能描述:GeometryElementExtension  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:05:15
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// GeometryElementExtension
+    /// </summary>
+    public static class GeometryElementExtension
+    {
+        /// <summary>
+        /// 查找原始的几何对象
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="geoElement"></param>
+        /// <returns></returns>
+        public static List<T> GetGeometryOriginalObjects<T>(this GeometryElement geoElement) where T : GeometryObject
+        {
+            List<T> listRtn = new List<T>();
+            List<GeometryElement> useElements = new List<GeometryElement>() { geoElement };
+            for (int i = 0; i < useElements.Count; i++)
+            {
+                var useGeoElement = useElements[i];
+                foreach (var geoObject in useGeoElement)
+                {
+                    //系统族、相交切割后的外部族
+                    if (geoObject is T)
+                    {
+                        listRtn.Add(geoObject as T);
+                    }
+                    else if (geoObject is GeometryInstance)
+                    {
+                        var childElment = (geoObject as GeometryInstance).GetInstanceGeometry();
+                        if (childElment != null)
+                        {
+                            useElements.Add(childElment);
+                        }
+                    }
+                    else if (geoObject is GeometryElement)
+                    {
+                        useElements.Add(geoObject as GeometryElement);
+                    }
+                }
+            }
+            return listRtn;
+        }
+        public static List<T> GetGeometryObjects<T>(this GeometryElement geoElement) where T : GeometryObject
+        {
+            List<T> listRtn = geoElement.GetGeometryOriginalObjects<T>();
+            if (listRtn.Count == 0)
+            {
+                //计算为几何信息复制,可能引用相关有问题
+                var geoElementNew = geoElement.GetTransformed(Transform.Identity);
+                listRtn = geoElementNew.GetGeometryOriginalObjects<T>();
+            }
+            return listRtn;
+        }
+
+        /// <summary>
+        /// 获取指定元素的几何描述
+        /// </summary>
+        /// <param name="element"></param>
+        /// <param name="visibleObj"></param>
+        /// <param name="view"></param>
+        /// <returns></returns>
+        public static GeometryElement GetGeometryElement(this Element element, bool visibleObj = false, View view = null)
+        {
+            var options = new Options();
+            options.ComputeReferences = true;
+            options.IncludeNonVisibleObjects = visibleObj;
+            if (view == null)
+            {
+                options.DetailLevel = ViewDetailLevel.Fine;
+            }
+            else
+            {
+                options.View = view;
+            }
+
+            return element.get_Geometry(options);
+        }
+
+        /// <summary>
+        /// 获取几何Solid
+        /// </summary>
+        /// <param name="elem"></param>
+        /// <param name="view"></param>
+        /// <param name="visibleObj"></param>
+        /// <returns></returns>
+        public static List<Solid> GetSolids(this Element elem, View view = null, bool visibleObj = false)
+        {
+            var geoElement = elem.GetGeometryElement(visibleObj, view);
+            return geoElement.GetGeometryObjects<Solid>();
+        }
+        /// <summary>
+        /// 获取几何Solid
+        /// </summary>
+        /// <param name="elem"></param>
+        /// <param name="view"></param>
+        /// <param name="visibleObj"></param>
+        /// <returns></returns>
+        public static List<T> GetGeometryObjects<T>(this Element elem, View view = null, bool visibleObj = false) where T : GeometryObject
+        {
+            var geoElement = elem.GetGeometryElement(visibleObj, view);
+            return geoElement.GetGeometryObjects<T>();
+        }
+    }
+}

+ 48 - 0
MBI/SAGA.MBI/RevitExport/Entity/GeometryLocation.cs

@@ -0,0 +1,48 @@
+/* ==============================================================================
+ * 功能描述:GeometryLocation  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:38:30
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// GeometryLocation
+    /// </summary>
+    public class GeometryLocation
+    {
+        public GeometryLocation(LocationType type)
+        {
+            Type = type;
+            Points = new List<XYZ>();
+        }
+        public LocationType Type { get; set; }
+        public List<XYZ> Points { get; private set; }
+
+        public static GeometryLocation CreatePointLocation(XYZ xyz)
+        {
+            var result = new GeometryLocation(LocationType.Point);
+            result.Points.Add(xyz);
+            return result;
+        }
+
+        public static GeometryLocation CreateLineLocation(List<XYZ> xyzes)
+        {
+            var result = new GeometryLocation(LocationType.Line);
+            result.Points.AddRange(xyzes);
+            return result;
+        }
+
+        public static GeometryLocation CreateArcLocation(List<XYZ> xyzes)
+        {
+            var result = new GeometryLocation(LocationType.Arc);
+            result.Points.AddRange(xyzes);
+            return result;
+        }
+    }
+}

+ 24 - 0
MBI/SAGA.MBI/RevitExport/Entity/LocationType.cs

@@ -0,0 +1,24 @@
+/* ==============================================================================
+ * 功能描述:LocationType  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:38:54
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// 定位类型
+    /// </summary>
+    public enum LocationType
+    {
+        Point = 0,
+        Line,
+        Arc,
+        Common
+    }
+}

+ 62 - 8
MBI/SAGA.MBI/RevitExport/Entity/MBIElement.cs

@@ -7,6 +7,9 @@ using Autodesk.Revit.DB;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
 using SAGA.MBI.JsonConvert;
+using SAGA.MBI.RevitExport.Entity;
+using SAGA.RevitUtils.Utils;
+using Polygon = SAGA.MBI.RevitExport.Entity.Polygon;
 
 namespace SAGA.MBI.RevitExport
 {
@@ -14,15 +17,66 @@ namespace SAGA.MBI.RevitExport
     {
         public MbiElement()
         {
-            Points=new List<XYZ>();
+            ElementType = GetElementType();
+            OutLine=new List<Polygon>();
+            Parameters=new List<Parameter>();
         }
 
-        [JsonProperty("Id")]
-        public string Id { get; set; } = string.Empty;
-        //[JsonConverter(typeof(XYZListConverter))]
-        [JsonProperty("PointList")]
-        public virtual List<XYZ> Points { get; set; }
-        //[JsonConverter(typeof(XYZConvert))]
-        //public XYZ BasePoint { get; set; }
+
+        #region NewAdd1009
+
+        public BimId Id { get; internal set; }
+        public string ElementType { get; protected set; }
+
+        /// <summary>
+        /// 附加信息,预留
+        /// </summary>
+        public string Tag { get; set; }
+
+        /// <summary>
+        /// 数据来源Id
+        /// </summary>
+        public string SourceId { get; set; }
+        /// <summary>
+        /// 构件名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 构件关联类型Id
+        /// </summary>
+        public BimId TypeId { get; set; }
+        /// <summary>
+        /// 从模型中拾取的参数
+        /// </summary>
+        public List<Parameter> Parameters { get; set; }
+        /// <summary>
+        /// 定位信息
+        /// </summary>
+        public GeometryLocation Location { get; set; }
+        /// <summary>
+        /// 轮廓信息
+        /// </summary>
+        public List<Entity.Polygon> OutLine { get; private set; }
+        /// <summary>
+        /// 获取类型Type
+        /// </summary>
+        /// <returns></returns>
+        protected string GetElementType()
+        {
+            var attributes = this.GetType().GetCustomAttributes(typeof(TypeDefinitonAttribute), true);
+            string result = null;
+            if (attributes.Any())
+            {
+                result = (attributes[0] as TypeDefinitonAttribute)?.GetTypeDefiniton();
+            }
+
+            if (string.IsNullOrEmpty(result))
+            {
+                result = TypeDefinitonUtil.GetTypeDefiniton(TypeDefinition.BimObject);
+            }
+            return result;
+        }
+        #endregion
+
     }
 }

+ 9 - 8
MBI/SAGA.MBI/RevitExport/Entity/MbiColumn.cs

@@ -1,20 +1,21 @@
-using Autodesk.Revit.DB;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
+using XYZ = Autodesk.Revit.DB.XYZ;
 
 namespace SAGA.MBI.RevitExport
 {
+    [TypeDefiniton(TypeDefinition.Column)]
     public class MbiColumn : MbiElement
     {
-        public MbiColumn()
-        {
-            Path = new List<XYZ>();
-        }
-        [JsonProperty("Path")]
-        public List<XYZ> Path { get; set; }
+        //是否加上,建筑结构,是否是房间判断等枚举
+        /// <summary>
+        /// 是否是房间边界
+        /// </summary>
+        public bool RoomBoundary { get; set; } = true;
     }
 }

+ 19 - 0
MBI/SAGA.MBI/RevitExport/Entity/MbiDoor.cs

@@ -0,0 +1,19 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
+
+namespace SAGA.MBI.RevitExport
+{
+    [TypeDefiniton(TypeDefinition.Door)]
+    public class MbiDoor : MbiElement
+    {
+        public BimId Owner { get; set; }
+        public XYZ FaceDirection { get; set; }
+        public XYZ HandDirection { get; set; }
+        public double Thick { get; set; }
+    }
+}

+ 4 - 2
MBI/SAGA.MBI/RevitExport/Entity/MbiEquipment.cs

@@ -9,7 +9,9 @@ namespace SAGA.MBI.RevitExport
 {
     public class MbiEquipment:MbiElement
     {
-        [JsonProperty("Name")]
-        public string Name { get; set; }
+        /// <summary>
+        /// 族名称
+        /// </summary>
+        public string FamilyName { get; set; }
     }
 }

+ 5 - 12
MBI/SAGA.MBI/RevitExport/Entity/MbiSpace.cs

@@ -3,27 +3,20 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using Autodesk.Revit.DB;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
+using SAGA.MBI.RevitExport.Entity;
+using XYZ = Autodesk.Revit.DB.XYZ;
 
 namespace SAGA.MBI.RevitExport
 {
+    [TypeDefiniton(TypeDefinition.Space)]
     public class MbiSpace:MbiElement
     {
         public MbiSpace()
         {
-            this.PointPaths = new List<List<XYZ>>();
+            BoundarySegments = new List<List<BimId>>();
         }
-        [JsonProperty("Name")]
-        public string Name { get; set; }
-        [JsonIgnore]
-        public override List<XYZ> Points { get; set; }
-        [JsonProperty("Paths")]
-        public List<List<XYZ>> PointPaths { get; set; }
-        [JsonProperty("BimId")]
-        public string BimId { get; set; }
-        [JsonProperty("LocationPoint")]
-        public XYZ Location { get; set; }
+        public List<List<BimId>> BoundarySegments { get; private set; }
     }
 }

+ 2 - 0
MBI/SAGA.MBI/RevitExport/Entity/MbiVirtualWall.cs

@@ -3,9 +3,11 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
 
 namespace SAGA.MBI.RevitExport
 {
+    [TypeDefiniton(TypeDefinition.VirtualWall)]
     public class MbiVirtualWall:MbiElement
     {
     }

+ 6 - 0
MBI/SAGA.MBI/RevitExport/Entity/MbiWall.cs

@@ -3,10 +3,16 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
 
 namespace SAGA.MBI.RevitExport
 {
+    [TypeDefiniton(TypeDefinition.Wall)]
     public class MbiWall:MbiElement
     {
+        /// <summary>
+        /// 墙宽
+        /// </summary>
+        public double Width { get; set; }
     }
 }

+ 17 - 0
MBI/SAGA.MBI/RevitExport/Entity/MbiWindow.cs

@@ -0,0 +1,17 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
+
+namespace SAGA.MBI.RevitExport
+{
+    [TypeDefiniton(TypeDefinition.Window)]
+    public class MbiWindow : MbiElement
+    {
+        public BimId Owner { get; set; }
+        public double Thick { get; set; }
+    }
+}

+ 52 - 0
MBI/SAGA.MBI/RevitExport/Entity/ParseCore.cs

@@ -0,0 +1,52 @@
+/* ==============================================================================
+ * 功能描述:ParseCore  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:44:52
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// ParseCore
+    /// </summary>
+    public class ParseCore
+    {
+        public static void AttachObject(MbiElement bimObj, Element element)
+        {
+            bimObj.SourceId = element.Id.ToString();
+            bimObj.Name = element.Name;
+        }
+        /// <summary>
+        /// 解析定位信息
+        /// </summary>
+        /// <param name="location"></param>
+        /// <returns></returns>
+        public static GeometryLocation GetLocation(Location location)
+        {
+            if (location == null)
+                return null;
+            if (location is LocationPoint point)
+            {
+                var usePoint = point.Point;
+                return GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(usePoint));
+            }
+            else if (location is LocationCurve curve)
+            {
+                var useCurve = curve.Curve.GetPoints();
+                if (curve.Curve is Line)
+                    return GeometryLocation.CreateLineLocation(useCurve.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList());
+                else if (curve.Curve is Arc)
+                    return GeometryLocation.CreateArcLocation(useCurve.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList());
+            }
+
+            return null;
+        }
+    }
+}

+ 28 - 0
MBI/SAGA.MBI/RevitExport/Entity/Polygon.cs

@@ -0,0 +1,28 @@
+/* ==============================================================================
+ * 功能描述:Polygon  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:13:50
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// Polygon
+    /// </summary>
+    public class Polygon : List<XYZ>
+    {
+        public Polygon()
+        {
+
+        }
+        public Polygon(IEnumerable<XYZ> collection) : base(collection)
+        {
+
+        }
+    }
+}

+ 187 - 0
MBI/SAGA.MBI/RevitExport/Entity/RevitUtil.cs

@@ -0,0 +1,187 @@
+/* ==============================================================================
+ * 功能描述:RevitUtil  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:03:38
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.Extends.Graphic;
+using XYZ=Autodesk.Revit.DB.XYZ;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// RevitUtil
+    /// </summary>
+    public class RevitUtil
+    {
+        /// <summary>
+        /// 获取FamilyInstance顶面轮廓
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<Autodesk.Revit.DB.XYZ> GetTopPolygon(FamilyInstance fi)
+        {
+            List<Autodesk.Revit.DB.XYZ> path = new List<Autodesk.Revit.DB.XYZ>();
+            var faces = fi.GetOriginalFaces(Autodesk.Revit.DB.XYZ.BasisZ);
+            var topface = faces.FirstOrDefault();
+            //传递的path中没有重复点
+            if (topface != null)
+            {
+                var curves = topface.GetCurves();
+                for (int i = 0; i < curves.Count; i++)
+                {
+                    var current = curves[i];
+                    var points = current.GetPoints();
+                    points.RemoveAt(points.Count - 1);
+                    path.AddRange(points);
+                }
+            }
+
+            return path;
+        }
+        /// <summary>
+        /// 获取门窗到墙线上的投影线
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<Autodesk.Revit.DB.XYZ> GetWindowDoorLocation(FamilyInstance fi)
+        {
+            //取几何实体顶点信息,将点到指定方向做投影
+            List<Autodesk.Revit.DB.XYZ> xyzs = GetVertexPoints(fi);
+            Autodesk.Revit.DB.XYZ handDirection = (fi.Host as Wall)?.Orientation;
+            if (handDirection != null)
+            {
+                handDirection = handDirection.CrossProduct(Autodesk.Revit.DB.XYZ.BasisZ);
+            }
+            else if (handDirection == null)
+            {
+                handDirection = fi.HandOrientation;
+            }
+            var location = fi.GetLocationPoint();
+            if (location == null)
+            {
+                location = xyzs.FirstOrDefault();
+            }
+
+            double min = 0, max = 0;
+            Autodesk.Revit.DB.XYZ minXYZ = Autodesk.Revit.DB.XYZ.Zero, maxXYZ = Autodesk.Revit.DB.XYZ.Zero;
+            for (int i = 0; i < xyzs.Count; i++)
+            {
+                var usePoint = xyzs[i];
+                var refDirection = usePoint - location;
+                var offset = refDirection.DotProduct(handDirection);
+                var projectPoint = location.OffsetPoint(handDirection, offset);
+                #region 初始化逻辑
+                if (i == 0)
+                {
+                    minXYZ = maxXYZ = projectPoint;
+                    min = max = offset;
+                }
+                #endregion
+                #region 判定逻辑
+                else
+                {
+                    if (offset < min)
+                    {
+                        minXYZ = projectPoint;
+                        min = offset;
+                        continue;
+                    }
+                    if (max < offset)
+                    {
+                        maxXYZ = projectPoint;
+                        max = offset;
+                        continue;
+                    }
+                }
+                #endregion
+            }
+            return new List<Autodesk.Revit.DB.XYZ>() { minXYZ, maxXYZ };
+        }
+        /// <summary>
+        /// 获取FamilyInstance box底面轮廓
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<Autodesk.Revit.DB.XYZ> GetBottomPolygon(FamilyInstance fi)
+        {
+            List<Autodesk.Revit.DB.XYZ> path = new List<Autodesk.Revit.DB.XYZ>();
+            var box = fi.get_BoundingBox(null);
+            if (box == null) return path;
+            var boxMin = box.Min;
+            var boxMax = box.Max;
+            path.Add(boxMin);
+            path.Add(boxMin.NewX(boxMax.X));
+            path.Add(boxMin.NewX(boxMax.X).NewY(boxMax.Y));
+            path.Add(boxMin.NewY(boxMax.Y));
+            path.Add(boxMin);
+            return path;
+        }
+        /// <summary>
+        /// 获取元素顶点集合
+        /// </summary>
+        /// <returns></returns>
+        public static List<Autodesk.Revit.DB.XYZ> GetVertexPoints(Element element)
+        {
+            List<Autodesk.Revit.DB.XYZ> xyzs = new List<Autodesk.Revit.DB.XYZ>();
+            //string id = element.Id.ToString();
+            //var solids = Extension.GeometryElementExtension.GetSolids(element, element.Document.GetUseView());
+            //foreach (var solid in solids)
+            //{
+            //    foreach (Edge edge in solid.Edges)
+            //    {
+            //        xyzs.AddRange(edge.Tessellate());
+            //    }
+            //}
+            var curves = GeometryElementExtension.GetGeometryObjects<Curve>(element, element.Document.GetUseView(), true);
+            foreach (var curve in curves)
+            {
+                xyzs.AddRange(curve.Tessellate());
+            }
+            return xyzs.Distinct(new XyzEqualComparer()).ToList();
+        }
+
+        /// <summary>
+        /// 获取墙的轮廓线
+        /// </summary>
+        /// <param name="wall"></param>
+        /// <returns></returns>
+        public static List<List<Autodesk.Revit.DB.XYZ>> GetWallPolygon(Wall wall)
+        {
+            /* 方案1:
+             * 1找到墙的定位线,
+             * 2将定位线拆分成多段
+             * 3按照宽度,将多段定位线生成闭合区域
+             * 方案2:
+             * 直接去墙的顶面,过滤相关face形成轮廓
+             */
+            List<List<Autodesk.Revit.DB.XYZ>> polygons = new List<List<Autodesk.Revit.DB.XYZ>>();
+            #region 过滤墙的顶面         
+            List<PlanarFace> faces = wall.GetBottomFaces();
+            #endregion
+            foreach (PlanarFace face in faces)
+            {
+                foreach (CurveLoop curveLoop in face.GetEdgesAsCurveLoops())
+                {
+                    if (curveLoop == null)
+                    {
+                        continue;
+                    }
+                    var polygon = curveLoop.GetPolygon();
+                    if (polygon.Any())
+                    {
+                        polygons.Add(polygon);
+                    }
+                }
+            }
+            return polygons;
+        }
+    }
+}

+ 35 - 0
MBI/SAGA.MBI/RevitExport/Entity/StandardUtil.cs

@@ -0,0 +1,35 @@
+/* ==============================================================================
+ * 功能描述:StandardUtil  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:14:35
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Extend;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// 标准整理工具
+    /// </summary>
+    public static class StandardUtil
+    {
+        public static void ArrangeLoop(Entity.Polygon polygon)
+        {
+            if (polygon.Count >= 2)
+            {
+                var firstPoint = polygon[0];
+                var lastPoint = polygon[polygon.Count - 1];
+                if (!firstPoint.X.IsEqual(lastPoint.X) || !firstPoint.Y.IsEqual(lastPoint.Y) ||
+                    !firstPoint.Z.IsEqual(lastPoint.Z))
+                {
+                    polygon.Add(firstPoint);
+                }
+
+            }
+        }
+    }
+}

+ 83 - 0
MBI/SAGA.MBI/RevitExport/Entity/TypeDefinition.cs

@@ -0,0 +1,83 @@
+/* ==============================================================================
+ * 功能描述:TypeDefinition  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:34:05
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /*
+      类型Id范围:[-10000,-19999)
+      {Id:"xxxxxx",ElementType:"Connector"}
+      //或者硬编码成枚举,或者使用配置文件存储
+     */
+    /// <summary>
+    /// 类型定义
+    /// </summary>
+    public enum TypeDefinition
+    {
+        [Description("BimObject")]
+        BimObject = -10000,
+        [Description("Connector")]
+        Connector,
+        [Description("Duct")]
+        Duct,
+        [Description("Pipe")]
+        Pipe,
+        [Description("Space")]
+        Space,
+        [Description("MepSystem")]
+        MepSystem,
+        [Description("MepSystemType")]
+        MepSystemType,
+        [Description("BoundarySegment")]
+        BoundarySegment,
+        [Description("Equipment")]
+        Equipment,
+        [Description("EquipPart")]
+        EquipPart,
+        [Description("Column")]
+        Column,
+
+        [Description("Wall")]
+        Wall,
+        [Description("VirtualWall")]
+        VirtualWall,
+        [Description("Window")]
+        Window,
+        [Description("Door")]
+        Door,
+        [Description("Other")]
+        Other,
+
+        [Description("Unit")]
+        Unit,
+        [Description("Grid")]
+        Grid,
+        [Description("Level")]
+        Level,
+
+        #region 关系类型相关
+        [Description("Relationship")]
+        Relationship = -25000,
+        [Description("MepSystem")]
+        Property_MepSystem,
+        [Description("Owner")]
+        Property_Owner,
+        [Description("TypeId")]
+        Property_TypeId,
+        [Description("ConnectedIds")]
+        Property_ConnectedIds,
+        [Description("Host")]
+        Property_Host,
+        [Description("Reference")]
+        Property_Reference,
+        #endregion
+    }
+}

+ 34 - 0
MBI/SAGA.MBI/RevitExport/Entity/TypeDefinitonAttribute.cs

@@ -0,0 +1,34 @@
+/* ==============================================================================
+ * 功能描述:TypeDefinitonAttribute  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:33:20
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// TypeDefinitonAttribute
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Class)]
+    class TypeDefinitonAttribute : Attribute
+    {
+        /*
+        * 由于可能扩展相关TypeDefiniton的生成方式,所以以方法形式返回需要值
+        */
+        private TypeDefinition m_TypeDefintion;
+        public TypeDefinitonAttribute(TypeDefinition typeDefinition)
+        {
+            m_TypeDefintion = typeDefinition;
+        }
+
+        public virtual string GetTypeDefiniton()
+        {
+            return TypeDefinitonUtil.GetTypeDefiniton(m_TypeDefintion);
+        }
+    }
+}

+ 24 - 0
MBI/SAGA.MBI/RevitExport/Entity/TypeDefinitonUtil.cs

@@ -0,0 +1,24 @@
+/* ==============================================================================
+ * 功能描述:TypeDefinitonUtil  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:34:43
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// TypeDefinitonUtil
+    /// </summary>
+    class TypeDefinitonUtil
+    {
+        public static string GetTypeDefiniton(TypeDefinition typeDefinition)
+        {
+            return typeDefinition.ToString();
+        }
+    }
+}

+ 69 - 0
MBI/SAGA.MBI/RevitExport/Entity/WallExtension.cs

@@ -0,0 +1,69 @@
+/* ==============================================================================
+ * 功能描述:WallExtension  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 16:04:36
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.DotNetUtils.Extend;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    public static class WallExtension
+    {
+        /// <summary>
+        /// 获取墙底面的轮廓,主要处理门窗分割墙问题
+        /// </summary>
+        /// <param name="wall"></param>
+        /// <returns></returns>
+        public static List<PlanarFace> GetBottomFaces(this Wall wall)
+        {
+            var solids = GeometryElementExtension.GetSolids(wall);
+            //var topZ = wall.GetTopStaticHeight();
+
+
+            double volume = double.MinValue;
+            List<PlanarFace> faces = new List<PlanarFace>();
+            foreach (var solid in solids)
+            {
+                var tempVolume = solid.Volume;
+                double topZ = double.MaxValue;
+                //取体积最大的Solid
+                if (tempVolume.IsThan(volume))
+                {
+                    volume = tempVolume;
+                    faces.Clear();
+                }
+                else
+                {
+                    continue;
+                }
+                foreach (Face face in solid.Faces)
+                {
+                    if (face is PlanarFace planarFace && planarFace.FaceNormal.IsEqual(-Autodesk.Revit.DB.XYZ.BasisZ))
+                    {
+                        var tempZ = planarFace.Origin.Z;
+                        //取底面FaceNormal为(0,0,-1),Z最小
+                        if (tempZ.IsLess(topZ))
+                        {
+                            faces.Clear();
+                            topZ = tempZ;
+                            faces.Add(planarFace);
+                        }
+                        else if (tempZ.IsEqual(topZ))
+                        {
+                            faces.Add(planarFace);
+                        }
+
+                    }
+                }
+            }
+            return faces;
+        }
+    }
+}

+ 28 - 0
MBI/SAGA.MBI/RevitExport/Entity/XYZ.cs

@@ -0,0 +1,28 @@
+/* ==============================================================================
+ * 功能描述:XYZ  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 15:39:29
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.RevitExport.Entity
+{
+    /// <summary>
+    /// XYZ
+    /// </summary>
+    public class XYZ
+    {
+        public double X { get; set; }
+        public double Y { get; set; }
+        public double Z { get; set; }
+
+        public override string ToString()
+        {
+            return $"{X},{Y},{Z}";
+        }
+    }
+}

+ 6 - 3
MBI/SAGA.MBI/RevitExport/ExportData.cs

@@ -72,10 +72,13 @@ namespace SAGA.MBI.RevitExport
                 {
                     data.Columns.Add(new RevitElementWrapper(familyInstance) { Category = MbiElementCategory.Column });
                 }
-                else
+                if (category == (int)BuiltInCategory.OST_Doors)
                 {
-                    data.Equipments.Add(new RevitElementWrapper(familyInstance) { Category = MbiElementCategory.Equipment });
-
+                    data.Columns.Add(new RevitElementWrapper(familyInstance) { Category = MbiElementCategory.Door });
+                }
+                if (category == (int)BuiltInCategory.OST_Windows)
+                {
+                    data.Columns.Add(new RevitElementWrapper(familyInstance) { Category = MbiElementCategory.Window });
                 }
             }
             #region 要不要继续这么写,还是改掉

+ 37 - 16
MBI/SAGA.MBI/RevitExport/ExportDb.cs

@@ -4,8 +4,11 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
 using Newtonsoft.Json.Linq;
 using SAGA.MBI.JsonConvert;
+using SAGA.MBI.RevitExport.Entity;
+using SAGA.RevitUtils;
 
 namespace SAGA.MBI.RevitExport
 {
@@ -15,12 +18,12 @@ namespace SAGA.MBI.RevitExport
     public class ExportDb
     {
         private readonly  Dictionary<string,List<MbiElement>> m_DataSource=new Dictionary<string, List<MbiElement>>();
-        /// <summary>
-        /// 清理数据
-        /// </summary>
-        public void ClaerData()
+     
+        protected BimDocument Document { get; private set; }
+
+        public ExportDb()
         {
-            m_DataSource.Clear();
+            Document = new BimDocument();
         }
         /// <summary>
         /// 增加导出关联数据
@@ -41,17 +44,18 @@ namespace SAGA.MBI.RevitExport
                 dataSource = new List<MbiElement>();
                 m_DataSource.Add(flag, dataSource);
             }
-
+            //Generate Object Id
+            var id = this.Document.NewObject(element)?.Id;
             dataSource.Add(element);
         }
         /// <summary>
         /// 生成json字符串
         /// </summary>
         /// <returns></returns>
-        public string ToJsonString()
+        public string ToJsonString(string sagaName)
         {
             string result = string.Empty;          
-            JObject jobject= ToJsonObject();
+            JObject jobject= ToJsonObject(sagaName);
             result = jobject.ToString();
             return result;
         }
@@ -59,37 +63,54 @@ namespace SAGA.MBI.RevitExport
         /// 转化成Json对象
         /// </summary>
         /// <returns></returns>
-        public JObject ToJsonObject()
+        public JObject ToJsonObject(string sagaName="")
         {
-            JsonSerializerSettings jsetting = new JsonSerializerSettings();
+            JsonSerializerSettings jsetting = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
+            jsetting.Converters.Add(new BimIdConverter());
             jsetting.Converters.Add(new XYZConvert());
+            jsetting.Converters.Add(new StringEnumConverter());
             var serializer = JsonSerializer.Create(jsetting);
             JObject jobject = new JObject();
             foreach (var collection in m_DataSource)
             {
                 jobject.Add(collection.Key, JArray.FromObject(collection.Value, serializer));
             }
-            return jobject;
+            JObject jelements=new JObject();
+            jelements.Add("Elements",jobject);
+            jelements.Add("PlanName", sagaName);
+            JArray jentityList=new JArray();
+            jentityList.Add(jelements);
+            var jresult=new JObject();
+            jresult.Add("entityList", jentityList);
+            return jresult;
         }
         public void AddWall(MbiWall mbiWall)
         {
-            AddObject("WallList", mbiWall);
+            AddObject("Walls", mbiWall);
         }
         public void AddVirtualWall(MbiVirtualWall mbiVirtaulWall)
         {
-            AddObject("VirtualWallList", mbiVirtaulWall);
+            AddObject("VirtualWalls", mbiVirtaulWall);
         }
         public void AddColumn(MbiColumn mbiColumn)
         {
-            AddObject("ColumnList", mbiColumn);
+            AddObject("Columns", mbiColumn);
         }
         public void AddSpace(MbiSpace mbiSpace)
         {
-            AddObject("SpaceList", mbiSpace);
+            AddObject("Spaces", mbiSpace);
         }
         public void AddEquipment(MbiEquipment mbiEquipment)
         {
-            AddObject("EquipmentList", mbiEquipment);
+            AddObject("Equipments", mbiEquipment);
+        }
+        public void AddDoor(MbiDoor mbiDoor)
+        {
+            AddObject("Doors", mbiDoor);
+        }
+        public void AddWindow(MbiWindow mbiWindow)
+        {
+            AddObject("Windows", mbiWindow);
         }
     }
 }

+ 3 - 1
MBI/SAGA.MBI/RevitExport/MbiElementClassify.cs

@@ -16,6 +16,8 @@ namespace SAGA.MBI.RevitExport
         Wall,
         Column,
         VirtualWall,
-        Equipment
+        Equipment,
+        Door,
+        Window
     }
 }

+ 3 - 1
MBI/SAGA.MBI/RevitExport/MbiElementManager.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB;
+using SAGA.RevitUtils;
 using SAGA.RevitUtils.Extends;
 
 namespace SAGA.MBI.RevitExport
@@ -99,7 +100,8 @@ namespace SAGA.MBI.RevitExport
             string result = string.Empty;
             ExportData data = ExportDataBuilder.CreateExportData(doc);
             ExportDb resultDb = ExportMbiEelemntDB(data);
-            return result= resultDb.ToJsonString();
+            string sagaName = doc.GetUseView()?.Name;
+            return result= resultDb.ToJsonString(sagaName);
         }
         public ExportDb ExportMbiEelemntDB(Document doc)
         {

+ 14 - 23
MBI/SAGA.MBI/RevitExport/ParseElement/ParseColumn.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
 using SAGA.RevitUtils.Extends;
 using SAGA.RevitUtils.Extends.Graphic;
 
@@ -20,38 +21,28 @@ namespace SAGA.MBI.RevitExport.ParseElement
 
         public void Parse(RevitElementWrapper wrapper, ExportDb db)
         {
-           
-
-           
             try
             {
                 FamilyInstance column = wrapper.RefElement as FamilyInstance;
                 if (column == null)
                     return;
                 MbiColumn mbiColumn = new MbiColumn();
-                mbiColumn.Id = column.Id.ToString();
-                XYZ location = column.GetLocationPoint();
-                mbiColumn.Points.Add(location.FromApi());
+                ParseCore.AttachObject(mbiColumn, column);
+                mbiColumn.Location = ParseCore.GetLocation(column.Location);
+                var polygonPath = RevitUtil.GetTopPolygon(column);
+                if (polygonPath != null && polygonPath.Any())
+                {
+                    Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath, true));
+                    StandardUtil.ArrangeLoop(outLine);
+                    mbiColumn.OutLine.Add(outLine);
+                }
 
-                //todo 取顶面的Face轮廓线
-                #region 获取轮廓线
-                List<XYZ> path = new List<XYZ>();
-                var faces = column.GetOriginalFaces(XYZ.BasisZ);
-                var topface = faces.FirstOrDefault();
-                //传递的path中没有重复点
-                if (topface != null)
+                var parameter = column.GetParameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING);
+                if (parameter != null)
                 {
-                    var curves = topface.GetCurves();
-                    for (int i = 0; i < curves.Count; i++)
-                    {
-                        var current = curves[i];
-                        var points = current.GetPoints();
-                        points.RemoveAt(points.Count - 1);
-                        path.AddRange(points);
-                    }
+                    mbiColumn.RoomBoundary = parameter.AsInteger() == 1;
                 }
-                mbiColumn.Path.AddRange(path.Select(p => p.FromApi()));
-                #endregion
+
                 //传入是为了,可以加可以不加
                 db.AddColumn(mbiColumn);
             }

+ 60 - 0
MBI/SAGA.MBI/RevitExport/ParseElement/ParseDoor.cs

@@ -0,0 +1,60 @@
+/* ==============================================================================
+ * 功能描述:ParseDoor  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 17:05:08
+ * ==============================================================================*/
+using Autodesk.Revit.DB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
+
+namespace SAGA.MBI.RevitExport.ParseElement
+{
+    [LoadParse]
+    public class ParseDoor : IParseRevitElement
+    {
+
+        public bool Match(RevitElementWrapper wrapper)
+        {
+            return wrapper.Category == MbiElementCategory.Door;
+        }
+
+        public void Parse(RevitElementWrapper wrapper, ExportDb db)
+        {
+            try
+            {
+                FamilyInstance fi = wrapper.RefElement as FamilyInstance;
+                if (fi == null)
+                    return;
+                MbiDoor jObject = new MbiDoor();
+                ParseCore.AttachObject(jObject, fi);
+                jObject.Location = ParseCore.GetLocation(fi.Location);
+                //if (fi.Host != null)
+                //{
+                //    jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();
+                //    jObject.Thick = (fi.Host as Autodesk.Revit.DB.Wall).Width.FtToUse();
+                //}
+                var polygonPath = RevitUtil.GetWindowDoorLocation(fi);
+                if (polygonPath != null && polygonPath.Any())
+                {
+                    Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath, true));
+                    jObject.OutLine.Add(outLine);
+                }
+                jObject.HandDirection = BimConvert.ConvertToDirection(fi.HandOrientation);
+                jObject.FaceDirection = BimConvert.ConvertToDirection(fi.FacingOrientation);
+
+                //传入是为了,可以加可以不加
+                db.AddDoor(jObject);
+            }
+            catch (Exception e)
+            {
+
+
+            }
+        }
+
+    }
+}

+ 17 - 30
MBI/SAGA.MBI/RevitExport/ParseElement/ParseEquipment.cs

@@ -7,6 +7,8 @@ using System.Threading.Tasks;
 using SAGA.RevitUtils.Extends;
 using SAGA.MBI.Tools;
 using System.Text.RegularExpressions;
+using SAGA.MBI.RevitExport.Entity;
+using XYZ = Autodesk.Revit.DB.XYZ;
 
 namespace SAGA.MBI.RevitExport.ParseElement
 {
@@ -32,45 +34,30 @@ namespace SAGA.MBI.RevitExport.ParseElement
                 {
                     return;
                 }
-                MbiEquipment mbiEquipment = new MbiEquipment();
-                mbiEquipment.Id = equipment.Id.ToString();
-                mbiEquipment.Name = name;
+                MbiEquipment jObject = new MbiEquipment();
+                ParseCore.AttachObject(jObject, equipment);
                 do
                 {
-                    //if (family.IsInPlace)
-                    //{
-                    //     var box=equipment.get_BoundingBox(null);
-                    //    if (box != null)
-                    //    {
-
-                    //        XYZ center = (box.Max + box.Min) / 2;
-                    //        mbiEquipment.Points.Add(center);
-                    //         break;
-                    //    }
-
-                       
-                    //}
-
-                    XYZ location = equipment.GetLocationPoint();
-                    if (location != null)
+                    //Location
+                    jObject.Location = GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(equipment.GetLocationPoint()));
+                    //OutLine
+                    var polygonPath = RevitUtil.GetBottomPolygon(equipment);
+                    if (polygonPath != null && polygonPath.Any())
                     {
-                        location = equipment.GetBoxCenter();
-                        mbiEquipment.Points.Add(location.FromApi());
-                        break;
+                        Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath));
+                        jObject.OutLine.Add(outLine);
                     }
+                    //FamilyName
+                    jObject.FamilyName = equipment.GetFamilyName();
+                    //Tag
+                    jObject.Tag = "";
 
-                    Curve curve = equipment.GetCurve();
-                    if (curve != null)
-                    {
-                        mbiEquipment.Points.Add(curve.StartPoint().FromApi());
-                        mbiEquipment.Points.Add(curve.EndPoint().FromApi());
-                         break;
-                    }
+                    //Id
 
                 } while (false);
                
 
-                db.AddEquipment(mbiEquipment);
+                db.AddEquipment(jObject);
             }
             catch (Exception e)
             {

+ 36 - 11
MBI/SAGA.MBI/RevitExport/ParseElement/ParseSpace.cs

@@ -3,7 +3,9 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using Autodesk.Revit.DB;
 using Autodesk.Revit.DB.Mechanical;
+using SAGA.MBI.RevitExport.Entity;
 using SAGA.MBI.Tools;
 using SAGA.RevitUtils.Extends;
 
@@ -29,23 +31,46 @@ namespace SAGA.MBI.RevitExport.ParseElement
                 {
                     return;
                 }
-                    #region 轮廓变更
                 var paths = space.GetBoundaryVertexes();
                 if (!paths.Any())
                     return;
-                
                 MbiSpace mbiSpace = new MbiSpace();
-                mbiSpace.Name = space.Name;
-                mbiSpace.Id = space.Id.ToString();
-
-                for (int i=0;i<paths.Count;i++)
+                ParseCore.AttachObject(mbiSpace, space);
+                var location = space.Location.GetPoint();
+                if (location != null)
                 {
-                    var currentPath = paths[i];
-                    mbiSpace.PointPaths.Add(currentPath.Select(xyz => xyz.FromApi()).ToList());
+                    mbiSpace.Location =
+                        GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(location));
                 }
-                #endregion
-                mbiSpace.BimId = space.Id.IntegerValue.ToString();
-                mbiSpace.Location = space.GetLocationPoint()?.FromApi();
+                
+                var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
+                if (segments != null)
+                {
+                    foreach (IList<BoundarySegment> segmentList in segments)
+                    {
+                        Polygon outLine = new Polygon();
+                        List<BimId> segmentBimids = new List<BimId>();
+                        foreach (BoundarySegment segment in segmentList)
+                        {
+                            var points = segment.GetCurve().GetPoints();
+                            var usePoints = points.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList();
+                            outLine.AddRange(usePoints.GetRange(0, usePoints.Count - 1));
+
+                        }
+
+                        if (outLine.Any())
+                        {
+                            StandardUtil.ArrangeLoop(outLine);
+                            mbiSpace.OutLine.Add(outLine);
+                        }
+
+                        if (segmentBimids.Any())
+                        {
+                            mbiSpace.BoundarySegments.Add(segmentBimids);
+                        }
+                    }
+                }
+
                 db.AddSpace(mbiSpace);
             }
             catch (Exception e)

+ 10 - 4
MBI/SAGA.MBI/RevitExport/ParseElement/ParseVirtualWall.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB;
+using SAGA.MBI.RevitExport.Entity;
 using SAGA.RevitUtils.Extends;
 
 namespace SAGA.MBI.RevitExport.ParseElement
@@ -25,10 +26,15 @@ namespace SAGA.MBI.RevitExport.ParseElement
                 if (modelCurve == null)
                     return;
                 MbiVirtualWall mbiVirtualWall = new MbiVirtualWall();
-                mbiVirtualWall.Id = modelCurve.Id.ToString();
-                Curve curve = modelCurve.GetCurve();
-                var inputPoints = curve.GetPoints().Select(xyz => xyz.FromApi());
-                mbiVirtualWall.Points.AddRange(inputPoints);
+                ParseCore.AttachObject(mbiVirtualWall, modelCurve);
+                //jObject.Location = ParseCore.GetLocation(se.Location);
+                var locations = new List<RevitExport.Entity.XYZ>();
+                var useCurve = (modelCurve.Location as LocationCurve).Curve;
+                locations.Add(BimConvert.ConvertToXYZ(useCurve.StartPoint()));
+                locations.Add(BimConvert.ConvertToXYZ(useCurve.EndPoint()));
+                mbiVirtualWall.Location = GeometryLocation.CreateLineLocation(locations);
+                Polygon outLine = new Polygon(locations);
+                mbiVirtualWall.OutLine.Add(outLine);
                 db.AddVirtualWall(mbiVirtualWall);
             }
             catch (Exception e)

+ 13 - 8
MBI/SAGA.MBI/RevitExport/ParseElement/ParseWall.cs

@@ -4,7 +4,10 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB;
+using SAGA.MBI.RevitExport.Entity;
 using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.Utils;
+using XYZ = Autodesk.Revit.DB.XYZ;
 
 namespace SAGA.MBI.RevitExport.ParseElement
 {
@@ -24,16 +27,18 @@ namespace SAGA.MBI.RevitExport.ParseElement
                 if (wall == null)
                     return;
                 MbiWall mbiWall = new MbiWall();
-                mbiWall.Id = wall.Id.ToString();
-                Curve wallCurve = wall.GetCurve();
-                List<XYZ> points = wallCurve.GetPoints();             
-                foreach (var point in points)
+                ParseCore.AttachObject(mbiWall, wall);
+                mbiWall.Location = ParseCore.GetLocation(wall.Location);
+                var polygons = RevitUtil.GetWallPolygon(wall);
+                //是否保持z为0的转换;
+                foreach (var polygon in polygons)
                 {
-                    mbiWall.Points.Add(point.FromApi());
-
+                    var outLine = new Entity.Polygon(BimConvert.ConvertToXYZs(polygon, true));
+                    StandardUtil.ArrangeLoop(outLine);
+                    mbiWall.OutLine.Add(outLine);
                 }
-                //mbiWall.Points.Add(wallCurve.StartPoint().FromApi());
-                //mbiWall.Points.Add(wallCurve.EndPoint().FromApi());
+
+                mbiWall.Width = wall.Width.FtToUse();
                 db.AddWall(mbiWall);
             }
             catch (Exception e)

+ 57 - 0
MBI/SAGA.MBI/RevitExport/ParseElement/ParseWindow.cs

@@ -0,0 +1,57 @@
+/* ==============================================================================
+ * 功能描述:ParseDoor  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 17:05:08
+ * ==============================================================================*/
+using Autodesk.Revit.DB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.MBI.RevitExport.Entity;
+
+namespace SAGA.MBI.RevitExport.ParseElement
+{
+    [LoadParse]
+    public class ParseWindow : IParseRevitElement
+    {
+
+        public bool Match(RevitElementWrapper wrapper)
+        {
+            return wrapper.Category == MbiElementCategory.Window;
+        }
+
+        public void Parse(RevitElementWrapper wrapper, ExportDb db)
+        {
+            try
+            {
+                FamilyInstance fi = wrapper.RefElement as FamilyInstance;
+                if (fi == null)
+                    return;
+                MbiWindow jObject = new MbiWindow();
+                ParseCore.AttachObject(jObject, fi);
+                jObject.Location = ParseCore.GetLocation(fi.Location);
+                //if (fi.Host != null)
+                //{
+                //    jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();
+                //    jObject.Thick = (fi.Host as Autodesk.Revit.DB.Wall).Width.FtToUse();
+                //}
+                var polygonPath = RevitUtil.GetWindowDoorLocation(fi);
+                if (polygonPath != null && polygonPath.Any())
+                {
+                    Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath, true));
+                    jObject.OutLine.Add(outLine);
+                }
+                //传入是为了,可以加可以不加
+                db.AddWindow(jObject);
+            }
+            catch (Exception e)
+            {
+
+
+            }
+        }
+
+    }
+}

+ 21 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -327,6 +327,27 @@
     <Compile Include="RequestData\QRCodeRequest.cs" />
     <Compile Include="RequestData\RequestResultUtil.cs" />
     <Compile Include="RequestData\WebRequestProxy.cs" />
+    <Compile Include="RevitExport\Entity\BimConvert.cs" />
+    <Compile Include="RevitExport\Entity\BimDocument.cs" />
+    <Compile Include="RevitExport\Entity\BimId.cs" />
+    <Compile Include="RevitExport\Entity\BimIdConverter.cs" />
+    <Compile Include="RevitExport\Entity\CurveLoopExtension.cs" />
+    <Compile Include="RevitExport\Entity\GeometryElementExtension.cs" />
+    <Compile Include="RevitExport\Entity\GeometryLocation.cs" />
+    <Compile Include="RevitExport\Entity\LocationType.cs" />
+    <Compile Include="RevitExport\Entity\MbiWindow.cs" />
+    <Compile Include="RevitExport\Entity\MbiDoor.cs" />
+    <Compile Include="RevitExport\Entity\ParseCore.cs" />
+    <Compile Include="RevitExport\Entity\Polygon.cs" />
+    <Compile Include="RevitExport\Entity\RevitUtil.cs" />
+    <Compile Include="RevitExport\Entity\StandardUtil.cs" />
+    <Compile Include="RevitExport\Entity\TypeDefinition.cs" />
+    <Compile Include="RevitExport\Entity\TypeDefinitonAttribute.cs" />
+    <Compile Include="RevitExport\Entity\TypeDefinitonUtil.cs" />
+    <Compile Include="RevitExport\Entity\WallExtension.cs" />
+    <Compile Include="RevitExport\Entity\XYZ.cs" />
+    <Compile Include="RevitExport\ParseElement\ParseWindow.cs" />
+    <Compile Include="RevitExport\ParseElement\ParseDoor.cs" />
     <Compile Include="RevitExport\SpaceSortUtils.cs" />
     <Compile Include="RevitModelHandle\ParameterDefinitionFactory.cs" />
     <Compile Include="RevitModelHandle\ParameterUtil.cs" />

+ 5 - 3
MBI/SAGA.MBI/TestCommand.cs

@@ -170,10 +170,12 @@ namespace SAGA.MBI
                             break;
                         }
                     case System.Windows.Forms.DialogResult.No:
-                        {
-                            MbiElementManager.ExecuteExport(ExternalDataWrapper.Current.Doc);
+                    {
+                        var doc = ExternalDataWrapper.Current.Doc;
+                            MbiElementManager.ExecuteExport(doc);
                             var floorId = ExternalDataWrapper.Current.Doc.PathName.GetFileName();
-                            MBIModelInfoUpload.UploadMbiInfo(floorId);
+                        string sagaName = doc.GetUseView()?.Name;
+                            MBIModelInfoUpload.UploadMbiInfo(floorId, sagaName);
                             break;
                         }
                 }

+ 2 - 1
MBI/SAGA.MBI/WinView/Space/WinCreateSpaceWeb.xaml.cs

@@ -343,7 +343,8 @@ namespace SAGA.MBI.WinView.Space
             Document linkDoc = CurrentContext.Document;
             MbiElementManager manager = new MbiElementManager();
             var exportDb = manager.ExportMbiEelemntDB(ExportDataBuilder.CreateExportData(linkDoc));
-            return exportDb.ToJsonObject();
+            var sagaName = linkDoc.GetUseView()?.Name;
+            return exportDb.ToJsonObject(sagaName);
         }
 
         private void Button_Click(object sender, RoutedEventArgs e)