Selaa lähdekoodia

xls:解析数据整合相关

xulisong 5 vuotta sitten
vanhempi
commit
a8f74e495e

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

@@ -33,9 +33,23 @@ namespace RevitToJBim.Common
         {
             return Round(footValue.FromApi());
         }
+        /// <summary>
+        /// 将点转换成毫米单位形式
+        /// </summary>
+        /// <param name="xyz"></param>
+        /// <returns></returns>
         public static XYZ ConvertToXYZ(Autodesk.Revit.DB.XYZ xyz)
         {
-            return new XYZ() {X = Round(xyz.X.FromApi()), Y = Round(xyz.Y.FromApi()), Z = Round(xyz.Z.FromApi()),};
+            return new XYZ() {X = FtToUse(xyz.X), Y = FtToUse(xyz.Y), Z = FtToUse(xyz.Z), };
+        }
+        /// <summary>
+        /// 将点转换成毫米单位形式
+        /// </summary>
+        /// <param name="xyzes"></param>
+        /// <returns></returns>
+        public static List<XYZ> ConvertToXYZs(List<Autodesk.Revit.DB.XYZ> xyzs)
+        {
+            return xyzs.Select(xyz=>ConvertToXYZ(xyz)).ToList();
         }
     }
 }

+ 2 - 1
JBIM/RevitToJBim/Common/ElementWrapperFactory.cs

@@ -24,7 +24,8 @@ namespace RevitToJBim.Common
     public class ElementWrapperFactory
     {
         /// <summary>
-        /// 根据element创建带分类对象的解析信息。便于快速过滤
+        /// 根据element创建带分类对象的解析信息。便于快速过滤.
+        /// 注:生成wrapper时,为了保证统一性,最好统一调用该方法
         /// </summary>
         /// <param name="element"></param>
         /// <returns></returns>

+ 47 - 0
JBIM/RevitToJBim/Common/RevitUtil.cs

@@ -0,0 +1,47 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:RevitUtil
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:55:09
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.Extends.Graphic;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim.Common
+{
+    public class RevitUtil
+    {
+        /// <summary>
+        /// 获取FamilyInstance顶面轮廓
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<XYZ> GetTopPolygon(FamilyInstance fi)
+        {
+            List<XYZ> path = new List<XYZ>();
+            var faces = fi.GetOriginalFaces(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;
+        }
+    }
+}

+ 53 - 0
JBIM/RevitToJBim/ComponentParse/ParseColumn.cs

@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseColumn
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:49:28
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using JBIM;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using System;
+using System.Collections.Generic;
+using JFamilyType = RevitToJBim.Common.FamilyType;
+using JColumn =JBIM.Component.Column;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.Extends.Graphic;
+using System.Linq;
+using JBIM.Definition;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseColumn : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { CategoryGenerator.BuildingCategory(JFamilyType.Other) };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Other);
+        }
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance familyInstance))
+            {
+                return null;
+            }
+            JColumn jObject = new JColumn();
+            ParseCore.AttachObject(jObject, wrapper);
+            jObject.Location = ParseCore.GetLocation(familyInstance.Location);
+            var polygonPath = RevitUtil.GetTopPolygon(familyInstance);
+            if (polygonPath != null && polygonPath.Any())
+            {
+                Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath));
+                jObject.OutLine.Add(outLine);
+            }
+            context.AddBimObject(jObject);          
+            return new List<BimId>() { jObject.Id };
+        }
+    }
+}

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

@@ -18,7 +18,9 @@ using JBIM.Definition;
 using RevitExport;
 using RevitExport.Export;
 using RevitToJBim.Common;
-using Connector = JBIM.Component.Connector;
+using RevitToJBim.ParseData;
+using SAGA.RevitUtils.Extends;
+using JConnector = JBIM.Component.Connector;
 
 namespace RevitToJBim.ComponentParse
 {
@@ -63,9 +65,9 @@ namespace RevitToJBim.ComponentParse
             bimObj.SourceId = wrapper.SourceId;
             bimObj.Name = wrapper.RefElement?.Name;
         }
-        public static Connector CreateConnector(Autodesk.Revit.DB.Connector connector)
+        public static JConnector CreateConnector(Autodesk.Revit.DB.Connector connector)
         {
-            var result= new Connector();
+            var result= new JConnector();
             result.SourceId = RevitIdGenerator.GetConnectorId(connector);
             switch (connector.Domain)
             {
@@ -95,5 +97,49 @@ namespace RevitToJBim.ComponentParse
             ElementWrapper wrapper = new ElementWrapper(connector, RevitIdGenerator.GetConnectorId(connector));
             return wrapper;
         }
+
+        /// <summary>
+        /// 获取元素关联的connector关联信息,若connector数量为0,则返回null
+        /// </summary>
+        /// <param name="element"></param>
+        /// <param name="connectors"></param>
+        /// <returns></returns>
+        public static ElementOneToManyRel GetConnectorRels(Element element,List<Autodesk.Revit.DB.Connector> connectors)
+        {
+            ElementOneToManyRel relMany = new ElementOneToManyRel(element.Id.ToString()) { RelatedObjects = new List<string>() };
+            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
+            foreach (var refConnector in connectors)
+            {
+                relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
+            }
+
+            if (relMany.RelatedObjects.Any())
+            {
+                return relMany;
+            }
+            return null;//创建关系无效
+        }
+        /// <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();
+                return GeometryLocation.CreateLineLocation(useCurve.Select(xyz=>BimConvert.ConvertToXYZ(xyz)).ToList());
+            }
+
+            return null;
+        }
     }
 }

+ 9 - 11
JBIM/RevitToJBim/ComponentParse/ParseFamilyJoinObject.cs

@@ -13,7 +13,6 @@ using System.Threading.Tasks;
 using Autodesk.Revit.DB;
 using JBIM;
 using JBIM.Component;
-using JBIM.Definition;
 using RevitExport.Export;
 using RevitToJBim.Common;
 using JFamilyType=RevitToJBim.Common.FamilyType;
@@ -44,16 +43,10 @@ namespace RevitToJBim.ComponentParse
             ParseCore.AttachObject(jObject, wrapper);
             context.AddBimObject(jObject);
             #region Connector连接关系
-            var connectors = familyInstance.GetAllConnectors();
-            ElementOneToManyRel relMany = new ElementOneToManyRel(familyInstance.Id.ToString()) { RelatedObjects = new List<string>() };
-            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
-            foreach (var refConnector in connectors)
-            {
-                relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));
-            }
-
-            if (relMany.RelatedObjects.Any())
+            var connectors = GetConnectors(familyInstance);
+            if (connectors.Any())
             {
+                ElementOneToManyRel relMany = ParseCore.GetConnectorRels(familyInstance,connectors);
                 context.RelationShips.Add(relMany);
             }
             #endregion
@@ -68,12 +61,17 @@ namespace RevitToJBim.ComponentParse
             }
 
             var wrappers = new List<ElementWrapper>() { };
-            var connectors = fi.GetAllConnectors();
+            var connectors = GetConnectors(fi);
             foreach (var connector in connectors)
             {
                 wrappers.Add(ParseCore.GetConnectorWrapper(connector));
             }
             return wrappers;
         }
+
+        public List<Autodesk.Revit.DB.Connector> GetConnectors(Element familyInstance)
+        {   
+               return  familyInstance.GetAllConnectors();
+        }
     }
 }

+ 58 - 0
JBIM/RevitToJBim/ExportDataBuilder.cs

@@ -0,0 +1,58 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ExportDataBuilder
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:59:47
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using Autodesk.Revit.DB.Plumbing;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using SAGA.RevitUtils.Extends;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim
+{
+    public class ExportDataBuilder
+    {
+        /// <summary>
+        /// 创建数据源
+        /// </summary>
+        /// <returns></returns>
+        public static List<ElementWrapper> CreateExportData(Document doc)
+        {
+            List<ElementWrapper> wrappers = new List<ElementWrapper>();
+            //应对传入元素,不是document全集的情况
+            //FilteredElementCollector collector = new FilteredElementCollector(doc, elements.Select(e => e.Id).ToList());
+            FilteredElementCollector collector = new FilteredElementCollector(doc);
+            wrappers.AddRange(collector.Clone().FilterElements<Wall>().Select(e => new ElementWrapper(e)));
+            wrappers.AddRange(collector.Clone().FilterElements<CurveElement>(BuiltInCategory.OST_MEPSpaceSeparationLines).Select(e => new ElementWrapper(e)));
+            var sourceSpaces = collector.Clone().FilterElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>().ToList();
+            //附加逻辑判断
+            //  var originSpaces = collector.Clone().GetUseSpaces();
+
+            wrappers.AddRange(sourceSpaces.Select(e => new ElementWrapper(e)));
+
+            wrappers.AddRange(collector.Clone().FilterElements<Pipe>().Select(e => new ElementWrapper(e)));
+            wrappers.AddRange(collector.Clone().FilterElements<Duct>().Select(e => new ElementWrapper(e)));
+            var familyInstances = collector.Clone().FilterElements<FamilyInstance>();
+            foreach (FamilyInstance familyInstance in familyInstances)
+            {
+                var tempWrapper = ElementWrapperFactory.CreateWrapper(familyInstance);
+                if (tempWrapper != null)
+                {
+                    wrappers.Add(tempWrapper);
+                }
+            }
+            wrappers.AddRange(collector.Clone().FilterElements<Level>().Select(e => new ElementWrapper(e)));
+            wrappers.AddRange(collector.Clone().FilterElements<Grid>().Select(e => new ElementWrapper(e)));
+            return wrappers;
+        }
+    }
+}

+ 3 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -65,7 +65,9 @@
     <Compile Include="Common\ExceptionUtil.cs" />
     <Compile Include="Common\FamilyType.cs" />
     <Compile Include="Common\RevitIdGenerator.cs" />
+    <Compile Include="Common\RevitUtil.cs" />
     <Compile Include="ComponentParse\ParseBase.cs" />
+    <Compile Include="ComponentParse\ParseColumn.cs" />
     <Compile Include="ComponentParse\ParseConnector.cs" />
     <Compile Include="ComponentParse\ParseCore.cs" />
     <Compile Include="ComponentParse\ParseDuct.cs" />
@@ -74,6 +76,7 @@
     <Compile Include="ComponentParse\ParsePipe.cs" />
     <Compile Include="ComponentParse\ParseSpace.cs" />
     <Compile Include="ComponentParse\UsableParseAttribute.cs" />
+    <Compile Include="ExportDataBuilder.cs" />
     <Compile Include="JsonConverter\BimIdConverter.cs" />
     <Compile Include="JsonConverter\BimJsonUtil.cs" />
     <Compile Include="JsonConverter\XYZConverter.cs" />

+ 1 - 1
JBIM/RevitToJBim/TestExport.cs

@@ -34,7 +34,7 @@ namespace RevitToJBim
             var elements3 = Document.GetElements(typeof(Duct)).OfType<Duct>().ToList();
             elements.AddRange(elements2);
             elements.AddRange(elements3);
-            var wrappers = elements.Select(e => new ElementWrapper(e)).ToList();
+            var wrappers = ExportDataBuilder.CreateExportData(Document);// elements.Select(e => new ElementWrapper(e)).ToList();
             ExportInstance report = new ExportInstance(wrappers);
             JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
             var dd = false;