Ver código fonte

mxg:合并并处理冲突

mengxiangge 5 anos atrás
pai
commit
2bec1778f7

+ 4 - 8
JBIM/JBIM/Component/Column.cs

@@ -1,7 +1,7 @@
 /*-------------------------------------------------------------------------
- * 功能描述:柱子
+ * 功能描述:Column
  * 作者:xulisong
- * 创建时间: 2019/6/12 14:11:03
+ * 创建时间: 2019/6/24 9:26:43
  * 版本号:v1.0
  *  -------------------------------------------------------------------------*/
 
@@ -15,13 +15,9 @@ using JBIM.Definition;
 
 namespace JBIM.Component
 {
-    [TypeDefiniton(TypeDefinition.Space)]
+    [TypeDefiniton(TypeDefinition.Column)]
     public class Column : VisibleComponentObject
     {
-        public Column()
-        {
-            BoundarySegments = new List<List<BimId>>();
-        }
-        public List<List<BimId>> BoundarySegments { get; private set; }
+        //是否加上,建筑结构,是否是房间判断等枚举
     }
 }

+ 30 - 0
JBIM/JBIM/Component/OtherJoinObject.cs

@@ -0,0 +1,30 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:OtherJoinObject
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:25:47
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+using JBIM.Definition;
+
+namespace JBIM.Component
+{
+    [TypeDefiniton(TypeDefinition.Other)]
+    public class OtherJoinObject : VisibleComponentObject
+    {
+        public OtherJoinObject()
+        {
+            ConnectedIds = new List<BimId>();
+        }
+        /// <summary>
+        /// Connector连接的connectorIds
+        /// </summary>
+        public List<BimId> ConnectedIds { get; private set; }
+    }
+}

+ 2 - 0
JBIM/JBIM/JBIM.csproj

@@ -60,11 +60,13 @@
     <Compile Include="Common\TypeDefinitonAttribute.cs" />
     <Compile Include="Common\TypeDefinitonUtil.cs" />
     <Compile Include="Component\BoundarySegment.cs" />
+    <Compile Include="Component\Column.cs" />
     <Compile Include="Component\ComponentObject.cs" />
     <Compile Include="Component\Connector.cs" />
     <Compile Include="Component\Duct.cs" />
     <Compile Include="Component\MepSystem.cs" />
     <Compile Include="Component\MepSystemType.cs" />
+    <Compile Include="Component\OtherJoinObject.cs" />
     <Compile Include="Component\Parameter.cs" />
     <Compile Include="Component\ParameterDefinition.cs" />
     <Compile Include="Component\Pipe.cs" />

+ 26 - 0
JBIM/RevitToJBim/Common/CategoryGenerator.cs

@@ -0,0 +1,26 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ElementWrapperGenerator
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:03:15
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim.Common
+{
+    /// <summary>
+    /// 构件分类生成器
+    /// </summary>
+    public static class CategoryGenerator
+    {
+        public static string BuildingCategory(Enum e)
+        {
+            return $"{e.GetType()}.{e}";
+        }
+    }
+}

+ 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();
         }
     }
 }

+ 100 - 0
JBIM/RevitToJBim/Common/ElementWrapperFactory.cs

@@ -0,0 +1,100 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ElementWrapperFactory
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 8:44:46
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using RevitExport;
+using RevitExport.Export;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
+
+namespace RevitToJBim.Common
+{
+    /// <summary>
+    /// 解析对象创建工厂
+    /// </summary>
+    public class ElementWrapperFactory
+    {
+        /// <summary>
+        /// 根据element创建带分类对象的解析信息。便于快速过滤.
+        /// 注:生成wrapper时,为了保证统一性,最好统一调用该方法
+        /// </summary>
+        /// <param name="element"></param>
+        /// <returns></returns>
+        public static ElementWrapper CreateWrapper(Element element)
+        {
+            if (element is FamilyInstance fi)
+            {
+                CreateWrapper(fi);
+            }
+            return new ElementWrapper(element);
+        }
+        /// <summary>
+        /// 创建FamilyInstance的wrapper
+        /// </summary>
+        /// <param name="familyInstance"></param>
+        /// <returns></returns>
+        public static ElementWrapper CreateWrapper(FamilyInstance familyInstance)
+        {
+            var useFamilyType = FamilyType.Undefine;
+            var category = familyInstance.Category;          
+            if (category != null)
+            {
+                var enumValue = (BuiltInCategory)category.Id.IntegerValue;
+                #region category转换
+                switch (enumValue)
+                {
+                    case BuiltInCategory.OST_Doors:
+                        {
+                            useFamilyType = FamilyType.Door;
+                            break;
+                        }
+                    case BuiltInCategory.OST_Windows:
+                        {
+                            useFamilyType = FamilyType.Window;
+                            break;
+                        }
+                    case BuiltInCategory.OST_Columns:
+                        {
+                            useFamilyType = FamilyType.Column;
+                            break;
+                        }
+                } 
+                #endregion
+            }
+
+            if (useFamilyType == FamilyType.Undefine)
+            {
+                //判断部件和设备
+                var family = familyInstance.GetFamily();
+                ///todo
+            }
+            if (useFamilyType == FamilyType.Undefine)
+            {
+                var connectors = familyInstance.GetAllConnectors();
+                if (connectors.Any(c => c.Domain == Domain.DomainHvac || c.Domain == Domain.DomainPiping))
+                {
+                    useFamilyType = FamilyType.Other;
+                }
+            }
+
+            if (useFamilyType == FamilyType.Undefine)
+            {
+                return null;
+            }
+
+            ElementWrapper wrapper = new ElementWrapper(familyInstance);
+            wrapper.Category = CategoryGenerator.BuildingCategory(useFamilyType);
+            return wrapper;
+
+        }
+    }
+}

+ 30 - 0
JBIM/RevitToJBim/Common/FamilyType.cs

@@ -0,0 +1,30 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:FamilyType
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 8:50:06
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RevitToJBim.Common
+{
+    /// <summary>
+    /// family构件类型
+    /// </summary>
+    public enum FamilyType
+    {
+        Undefine,
+        Equipment,
+        EquipPart,
+        Window,
+        Door,
+        Column,
+        Other,
+
+    }
+}

+ 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 };
+        }
+    }
+}

+ 1 - 1
JBIM/RevitToJBim/ComponentParse/ParseConnector.cs

@@ -72,7 +72,7 @@ namespace RevitToJBim.ComponentParse
             //这里只维护关联,不进行递归
             var refConnectors = connector.GetReferenceConnectors();
             ElementOneToManyRel relMany = new ElementOneToManyRel(connectorId){RelatedObjects=new List<string>()};
-            relMany.SetElementType(TypeDefinition.Property_MepSystem);
+            relMany.SetElementType(TypeDefinition.Property_ConnectedIds);
             foreach (var refConnector in refConnectors)
             {
                 relMany.RelatedObjects.Add(RevitIdGenerator.GetConnectorId(refConnector));

+ 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;
+        }
     }
 }

+ 77 - 0
JBIM/RevitToJBim/ComponentParse/ParseFamilyJoinObject.cs

@@ -0,0 +1,77 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseFamilyJoinObject
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:29:00
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using JBIM;
+using JBIM.Component;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using JFamilyType=RevitToJBim.Common.FamilyType;
+using RevitToJBim.ParseData;
+using SAGA.RevitUtils.MEP;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseFamilyJoinObject : 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;
+            }
+            OtherJoinObject jObject = new OtherJoinObject();
+            ParseCore.AttachObject(jObject, wrapper);
+            context.AddBimObject(jObject);
+            #region Connector连接关系
+            var connectors = GetConnectors(familyInstance);
+            if (connectors.Any())
+            {
+                ElementOneToManyRel relMany = ParseCore.GetConnectorRels(familyInstance,connectors);
+                context.RelationShips.Add(relMany);
+            }
+            #endregion
+            return new List<BimId>() { jObject.Id };
+        }
+
+        public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance fi))
+            {
+                return null;
+            }
+
+            var wrappers = new List<ElementWrapper>() { };
+            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;
+        }
+    }
+}

+ 7 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -59,17 +59,24 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Common\CategoryGenerator.cs" />
     <Compile Include="Common\Converter.cs" />
+    <Compile Include="Common\ElementWrapperFactory.cs" />
     <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" />
+    <Compile Include="ComponentParse\ParseFamilyJoinObject.cs" />
     <Compile Include="ComponentParse\ParseMepSystem.cs" />
     <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;