xulisong %!s(int64=5) %!d(string=hai) anos
pai
achega
a3ca2a8066

+ 24 - 0
JBIM/JBIM/Component/Grid.cs

@@ -0,0 +1,24 @@
+/* ==============================================================================
+ * 功能描述:Grid  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 15:01:34
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+using JBIM.Component;
+using JBIM.Definition;
+
+namespace JBIM.Component
+{
+    /// <summary>
+    /// Grid
+    /// </summary>
+    [TypeDefiniton(TypeDefinition.Grid)]
+    public class Grid: VisibleComponentObject
+    {
+    }
+}

+ 25 - 0
JBIM/JBIM/Component/Level.cs

@@ -0,0 +1,25 @@
+/* ==============================================================================
+ * 功能描述:Level  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 15:01:44
+ * ==============================================================================*/
+using JBIM.Definition;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+
+namespace JBIM.Component
+{
+    /// <summary>
+    /// Level
+    /// </summary>
+    [TypeDefiniton(TypeDefinition.Level)]
+    public class Level:VisibleComponentObject
+    {
+        //标高的高度
+        public double Value { get; set; }
+    }
+}

+ 25 - 0
JBIM/JBIM/Component/Unit.cs

@@ -0,0 +1,25 @@
+/* ==============================================================================
+ * 功能描述:Unit  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 15:02:34
+ * ==============================================================================*/
+using JBIM.Definition;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+
+namespace JBIM.Component
+{
+    /// <summary>
+    /// Unit
+    /// </summary>
+    [TypeDefiniton(TypeDefinition.Unit)]
+    public class Unit:ComponentObject
+    {
+        //单位的值
+        public string Value { get; set; }
+    }
+}

+ 3 - 0
JBIM/JBIM/JBIM.csproj

@@ -65,6 +65,8 @@
     <Compile Include="Component\Connector.cs" />
     <Compile Include="Component\Door.cs" />
     <Compile Include="Component\Duct.cs" />
+    <Compile Include="Component\Grid.cs" />
+    <Compile Include="Component\Level.cs" />
     <Compile Include="Component\MepSystem.cs" />
     <Compile Include="Component\MepSystemType.cs" />
     <Compile Include="Component\OtherJoinObject.cs" />
@@ -74,6 +76,7 @@
     <Compile Include="Component\EquipPart.cs" />
     <Compile Include="Component\Equipment.cs" />
     <Compile Include="Component\Space.cs" />
+    <Compile Include="Component\Unit.cs" />
     <Compile Include="Component\VirtualWall.cs" />
     <Compile Include="Component\VisibleComponentObject.cs" />
     <Compile Include="Component\Wall.cs" />

+ 57 - 0
JBIM/RevitToJBim/ComponentParse/ParseGrid.cs

@@ -0,0 +1,57 @@
+/* ==============================================================================
+ * 功能描述:ParseGrid  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 15:16:06
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using JBIM;
+using JBIM.Definition;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using SAGA.RevitUtils.Extends;
+using JGrid=JBIM.Component.Grid;
+
+namespace RevitToJBim.ComponentParse
+{
+    /// <summary>
+    /// ParseGrid
+    /// </summary>
+    [UsableParseAttribute]
+    class ParseGrid : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>(){typeof(Grid).FullName};
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is Grid;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            var refElement = wrapper.RefElement as Grid;
+
+            if (refElement == null)
+            {
+                return null;
+            }
+            JGrid jObject = new JGrid();
+            //ElementType
+            ParseCore.AttachObject(jObject, wrapper);
+            //Name,SourceId
+            jObject.Name = refElement.Name;
+            //Location
+            var locations = refElement.GetCurve().Tessellate();
+            jObject.Location = GeometryLocation.CreateLineLocation(BimConvert.ConvertToXYZs(locations.ToList()));
+            //Id
+            context.AddBimObject(jObject);
+            return new List<BimId>() { jObject.Id };
+        }
+    }
+}

+ 55 - 0
JBIM/RevitToJBim/ComponentParse/ParseLevel.cs

@@ -0,0 +1,55 @@
+/* ==============================================================================
+ * 功能描述:ParseLevel  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 15:16:34
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using JBIM;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using SAGA.RevitUtils.Extends;
+using JLevel=JBIM.Component.Level;
+
+namespace RevitToJBim.ComponentParse
+{
+    /// <summary>
+    /// ParseLevel
+    /// </summary>
+    [UsableParseAttribute]
+    class ParseLevel : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(Level).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is Level;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            var level = wrapper.RefElement as Level;
+
+            if (level == null)
+            {
+                return null;
+            }
+            JLevel jObject=new JLevel();
+            //ElementType
+            ParseCore.AttachObject(jObject,wrapper);
+            //Name,SourceId
+            jObject.Name = level.Name;
+            //Value
+            jObject.Value = level.Elevation.FtToUse();
+            //Id
+            context.AddBimObject(jObject);
+            return new List<BimId>(){jObject.Id};
+        }
+    }
+}

+ 50 - 0
JBIM/RevitToJBim/ComponentParse/ParseUnit.cs

@@ -0,0 +1,50 @@
+/* ==============================================================================
+ * 功能描述:ParseUnit  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 15:15:33
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM;
+using RevitExport.Export;
+using Autodesk.Revit.DB;
+using RevitToJBim.Common;
+using JUnit=JBIM.Component.Unit;
+
+namespace RevitToJBim.ComponentParse
+{
+    /// <summary>
+    /// ParseUnit
+    /// </summary>
+    [UsableParseAttribute]
+    class ParseUnit : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { CategoryGenerator.BuildingCategory(Common.FamilyType.Other) };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefObject is FormatOptions;
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            var options= wrapper.RefObject as FormatOptions;
+            if (options == null)
+            {
+                return null;
+            }
+
+            JUnit jObject = new JUnit();
+            jObject.Name = "Length";
+            jObject.Tag = "长度单位";
+            jObject.Value = options.DisplayUnits.ToString();
+            context.AddBimObject(jObject);
+            return new List<BimId>(){jObject.Id};
+        }
+    }
+}

+ 17 - 8
JBIM/RevitToJBim/ExportDataBuilder.cs

@@ -16,6 +16,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using RevitToJBim.Extension;
 
 namespace RevitToJBim
 {
@@ -30,17 +31,25 @@ namespace RevitToJBim
             List<ElementWrapper> wrappers = new List<ElementWrapper>();
             //应对传入元素,不是document全集的情况
             //FilteredElementCollector collector = new FilteredElementCollector(doc, elements.Select(e => e.Id).ToList());
+
+            #region Unit
+
+            var formatOptions = doc.GetUnits().GetFormatOptions(UnitType.UT_Length);
+            ElementWrapper wrapper = new ElementWrapper(formatOptions, null);
+            wrappers.Add(wrapper);
+
+            #endregion
             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(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>().Where(t=>t.IsSpace()).ToList();
+            //附加逻辑判断
+            //  var originSpaces = collector.Clone().GetUseSpaces();
 
-            //wrappers.AddRange(sourceSpaces.Select(e => new ElementWrapper(e)));
+            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)));
+            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)
             {

+ 9 - 1
JBIM/RevitToJBim/Extension/ElementExtension.cs

@@ -107,7 +107,15 @@ namespace RevitToJBim.Extension
                 //空间比较特殊,周长为零就相当于删除
                 isspace = !ischeckzero || !(space.IsDeleteSpace());
                 //限制所用空间的阶段
-                //isspace = isspace && space.IsPhase1Space();
+                if (isspace)
+                {
+                    //增加过滤效率,如果上一步正确菜继续往下执行。
+                    isspace = isspace && space.IsPhase1Space();
+                }
+                if (isspace)
+                {
+                    isspace = isspace && space.IsViewLevel();
+                }
             }
 
             return isspace;

+ 89 - 0
JBIM/RevitToJBim/Extension/SpaceExtension.cs

@@ -0,0 +1,89 @@
+/* ==============================================================================
+ * 功能描述:SpaceExtension  
+ * 创 建 者:Garrett
+ * 创建日期:2019/6/26 17:40:25
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Extends;
+
+namespace RevitToJBim.Extension
+{
+    /// <summary>
+    /// SpaceExtension
+    /// </summary>
+    public static class SpaceExtension
+    {
+        public readonly static string UseablePhaseName = "阶段1";
+
+        /// <summary>
+        /// 获取系统使用的阶段Id
+        /// </summary>
+        /// <param name="doc"></param>
+        /// <returns></returns>
+        public static ElementId GetUsePhaseId(this Document doc)
+        {
+            var phase = GetUsePhase(doc);
+            if (phase == null)
+            {
+                return ElementId.InvalidElementId;
+            }
+            return phase.Id;
+        }
+        /// <summary>
+        /// 获取系统使用的阶段
+        /// </summary>
+        /// <param name="doc"></param>
+        /// <returns></returns>
+        public static Phase GetUsePhase(this Document doc)
+        {
+            var elements = doc.GetElements<Phase>(BuiltInCategory.OST_Phases);
+            foreach (var element in elements)
+            {
+                var tempName = element.Name.Replace(" ", "").Trim();
+                if (UseablePhaseName == tempName)
+                {
+                    return element;
+                }
+            }
+            return null;
+        }
+
+        public static ElementId GetCurrentPhaseId(this Space space)
+        {
+            return space.GetParameterElementId(BuiltInParameter.ROOM_PHASE_ID) ?? ElementId.InvalidElementId;
+        }
+        /// <summary>
+        /// 判断是否是阶段1的空间
+        /// </summary>
+        /// <param name="space"></param>
+        /// <returns></returns>
+        public static bool IsPhase1Space(this Space space)
+        {
+            var doc = space.Document;
+            var useId = GetUsePhaseId(doc);
+            return space.GetCurrentPhaseId() == useId;
+        }
+        /// <summary>
+        /// 空间标高是否是当前使用视图标高
+        /// </summary>
+        /// <param name="space"></param>
+        /// <returns></returns>
+        public static bool IsViewLevel(this Space space)
+        {
+            var doc = space.Document;
+            var useViewId = doc.GetUseView();
+            if (useViewId == null)
+            {
+                return false;
+            }
+            return space.Level?.Id == useViewId.GenLevel?.Id;
+        }
+    }
+}

+ 4 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -66,6 +66,10 @@
     <Compile Include="Common\ExceptionUtil.cs" />
     <Compile Include="Common\FamilyType.cs" />
     <Compile Include="Common\ParameterUtil.cs" />
+    <Compile Include="ComponentParse\ParseGrid.cs" />
+    <Compile Include="ComponentParse\ParseLevel.cs" />
+    <Compile Include="ComponentParse\ParseUnit.cs" />
+    <Compile Include="Extension\SpaceExtension.cs" />
     <Compile Include="Extension\CurveLoopExtension.cs" />
     <Compile Include="Extension\GeometryElementExtension.cs" />
     <Compile Include="Extension\WallExtension.cs" />