8
1

3 Commitit 34216a088a ... 76c330867e

Tekijä SHA1 Viesti Päivämäärä
  xulisong 76c330867e xls:提交合并 5 vuotta sitten
  xulisong a0e85914fe xls:提交合并 5 vuotta sitten
  xulisong d49d8b093f xls:门窗墙解析 5 vuotta sitten

+ 26 - 0
JBIM/JBIM/BimDocument.cs

@@ -50,7 +50,33 @@ namespace JBIM
             AddObject(originObject);
             return originObject;
         }
+        /// <summary>
+        /// 增加预定义对象
+        /// </summary>
+        /// <param name="originObject"></param>
+        /// <returns></returns>
+        public bool AddPredefinedObject(BimObject originObject)
+        {
+            if (originObject.Id == null)
+            {
+                return false;
+            }
 
+            if (m_IndexObjects.TryGetValue(originObject.Id, out BimObject oldObject))
+            {
+                //移除信息
+                if (oldObject != null)
+                {
+                    m_InnerObjects.Remove(oldObject);
+                }               
+                m_IndexObjects[originObject.Id] = originObject;
+            }
+            else
+            {
+                AddObject(originObject);
+            }
+            return true;
+        }
         private void AddObject(BimObject originObject)
         {
             this.m_InnerObjects.Add(originObject);

+ 93 - 0
JBIM/RevitToJBim/Common/CurveExtension.cs

@@ -0,0 +1,93 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:CurveExtension
+ * 作者:xulisong
+ * 创建时间: 2019/6/26 14:14:27
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.RevitUtils.Extends;
+
+namespace RevitToJBim.Common
+{
+    public static class CurveExtension
+    {
+        /// <summary>
+        /// 获取curve偏移后的Polygon信息
+        /// </summary>
+        /// <param name="curve"></param>
+        /// <param name="normal"></param>
+        /// <param name="offset"></param>
+        /// <returns></returns>
+        public static List<XYZ> GetCurvePolygon(this Curve curve, XYZ normal, double offset)
+        {
+            List<XYZ> xyzs = new List<XYZ>();
+            XYZ referenceDirection = normal;
+            if (curve.IsLine())
+            {
+                referenceDirection = normal.CrossProduct((curve as Line).Direction);
+            }
+
+            #region 构建围护线
+            //从curve1.StartPoint()开始的可以顺序连接的线结构
+            var curve1 = curve.CreateOffset(offset, referenceDirection);
+            var curve2 = curve.CreateOffset(-offset, referenceDirection);
+            var line1 = Line.CreateBound(curve1.EndPoint(), curve2.EndPoint());
+            var line2 = Line.CreateBound(curve2.StartPoint(), curve1.StartPoint());
+            //curve2调转方向
+            curve2 = curve2.CreateReversed();
+            List<Curve> curves = new List<Curve>();
+            curves.Add(curve1);
+            curves.Add(line1);
+            curves.Add(curve2);
+            curves.Add(line2);
+            foreach (Curve useCurve in curves)
+            {
+                var points = useCurve.Tessellate();
+                points.RemoveAt(points.Count - 1);
+                xyzs.AddRange(points);
+            }
+            #endregion
+            #region 逆时针顺序转化
+            /*
+                *  //将线结构整理成逆时针形式;
+                * 如果curve是弧线则使用开始,中间,结束三个点判断
+                * 如果curve是直线,则使用开始,结束,curve2的开始三个点判断;
+                *
+                * 也可以直接使用上面的的点集合取出三个点进行判断
+                */
+            List<XYZ> decisionXyzs = new List<XYZ>();
+            if (curve1.IsLine())
+            {
+                decisionXyzs.Add(curve1.StartPoint());
+                decisionXyzs.Add(curve1.EndPoint());
+                decisionXyzs.Add(curve2.StartPoint());
+            }
+            else if(curve1.IsArc())
+            {
+                //找半径大的弧
+                var useCurve = (curve1 as Arc).Radius > (curve2 as Arc).Radius ? curve1 : curve2;
+                decisionXyzs.Add(useCurve.StartPoint());
+                decisionXyzs.Add(useCurve.MiddlePoint());
+                decisionXyzs.Add(useCurve.EndPoint());
+
+            }
+            if (decisionXyzs.Any())
+            {
+                var useDirection = (decisionXyzs[1] - decisionXyzs[0]).CrossProduct(decisionXyzs[2] - decisionXyzs[0]);
+                var isAnticlockwise = useDirection.IsSameDirection(normal);
+                if (!isAnticlockwise)
+                {
+                    xyzs.Reverse();
+                }
+            }         
+            #endregion
+            return xyzs;
+        }
+    }
+}

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

@@ -17,6 +17,7 @@ using RevitToJBim.Extension;
 using RevitToJBim.MBI;
 using SAGA.DotNetUtils;
 using Parameter=JBIM.Component.Parameter;
+using SAGA.RevitUtils;
 
 namespace RevitToJBim.Common
 {
@@ -104,5 +105,112 @@ namespace RevitToJBim.Common
                 .FirstOrDefault(t => !t.Id.IsEqual(element.Id) && t.GetFamilyCode() == code);
             return parentInst;
         }
+
+        /// <summary>
+        /// 获取门窗到墙线上的投影线
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        public static List<XYZ> GetWindowDoorLocation(FamilyInstance fi)
+        {
+            //取几何实体顶点信息,将点到指定方向做投影
+            List<XYZ> xyzs = GetVertexPoints(fi);
+            XYZ handDirection = (fi.Host as Wall)?.Orientation;
+            if (handDirection != null)
+            {
+                handDirection = handDirection.CrossProduct(XYZ.BasisZ);
+            }
+            else if (handDirection == null)
+            {
+                handDirection = fi.HandOrientation;
+            }
+            var location = fi.GetLocationPoint();
+            if (location == null)
+            {
+                location = xyzs.FirstOrDefault();
+            }
+
+            double min = 0, max = 0;
+            XYZ minXYZ = XYZ.Zero, maxXYZ = XYZ.Zero;
+            for (int i = 0; i < xyzs.Count; i++)
+            {
+                var usePoint = xyzs[i];
+                var refDirection = usePoint - location;
+                var offset = refDirection.DotProduct(handDirection);
+                #region 初始化逻辑
+                if (i == 0)
+                {
+                    minXYZ = maxXYZ = usePoint;
+                    min = max = offset;
+                }
+                #endregion
+                #region 判定逻辑
+                else
+                {
+                    if (offset < min)
+                    {
+                        minXYZ = usePoint;
+                        min = offset;
+                        continue;
+                    }
+                    if (max < offset)
+                    {
+                        maxXYZ = usePoint;
+                        max = offset;
+                        continue;
+                    }
+                }
+                #endregion
+            }
+            return new List<XYZ>() { minXYZ, maxXYZ };
+        }
+
+        /// <summary>
+        /// 获取元素顶点集合
+        /// </summary>
+        /// <returns></returns>
+        public static List<XYZ> GetVertexPoints(Element element)
+        {
+            List<XYZ> xyzs = new List<XYZ>();
+            var solids = element.GetSolids();
+            foreach (var solid in solids)
+            {
+                foreach (Edge edge in solid.Edges)
+                {
+                    xyzs.AddRange(edge.Tessellate());
+                }
+            }
+            return xyzs.Distinct(new XyzEqualComparer()).ToList();
+        }
+
+        /// <summary>
+        /// 获取墙的轮廓线
+        /// </summary>
+        /// <param name="wall"></param>
+        /// <returns></returns>
+        public static List<List<XYZ>> GetWallPolygon(Wall wall)
+        {
+            /*
+             * 1找到墙的定位线,
+             * 2将定位线拆分成多段
+             * 3按照宽度,将多段定位线生成闭合区域
+             */
+            var curve = wall.GetLocationCurve();
+
+
+            List<List<XYZ>> polygons = new List<List<XYZ>>();
+            var refs = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior).OfType<Face>();
+            foreach (Face face in refs)
+            {
+                List<XYZ> polygon = new List<XYZ>();
+                //foreach (Curve curve in face.ed)
+                //{
+
+                //}
+            }
+
+            //偏移位位置信息
+            return polygons;
+        }
     }
 }

+ 61 - 0
JBIM/RevitToJBim/ComponentParse/ParseDoor.cs

@@ -0,0 +1,61 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseDoor
+ * 作者:xulisong
+ * 创建时间: 2019/6/25 17:53:11
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using RevitExport.Export;
+using RevitToJBim.Common;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JFamilyType = RevitToJBim.Common.FamilyType;
+using JBIM;
+using Autodesk.Revit.DB;
+using JBIM.Component;
+using JBIM.Definition;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseDoor : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { CategoryGenerator.BuildingCategory(JFamilyType.Door) };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Door);
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance fi))
+            {
+                return null;
+            }
+            Door jObject = new Door();
+            ParseCore.AttachObject(jObject, wrapper);
+            context.AddBimObject(jObject);
+            jObject.Location = ParseCore.GetLocation(fi.Location);
+            if (fi.Host != null)
+            {
+                jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();
+            }
+            var polygonPath = RevitUtil.GetWindowDoorLocation(fi);
+            if (polygonPath != null && polygonPath.Any())
+            {
+                Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath));
+                jObject.OutLine.Add(outLine);
+            }
+            jObject.HandDirection = BimConvert.ConvertToXYZ(fi.HandOrientation);
+            jObject.FaceDirection = BimConvert.ConvertToXYZ(fi.FacingOrientation);
+            return new List<BimId>() { jObject.Id };
+        }
+
+    }
+}

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

@@ -0,0 +1,57 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseVirtualWall
+ * 作者:xulisong
+ * 创建时间: 2019/6/25 17:54:31
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using JBIM;
+using JBIM.Component;
+using JBIM.Definition;
+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.ComponentParse
+{
+    [UsableParse]
+    public class ParseVirtualWall : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(SpatialElement).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is SpatialElement;
+        }
+
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is SpatialElement se))
+            {
+                return null;
+            }
+            VirtualWall jObject = new VirtualWall();
+            ParseCore.AttachObject(jObject, wrapper);
+            context.AddBimObject(jObject);
+            //jObject.Location = ParseCore.GetLocation(se.Location);
+            var locations = new List<JBIM.Definition.XYZ>();
+            var useCurve = (se.Location as LocationCurve).Curve;
+            locations.Add(BimConvert.ConvertToXYZ(useCurve.StartPoint()));
+            locations.Add(BimConvert.ConvertToXYZ(useCurve.EndPoint()));
+            jObject.Location = GeometryLocation.CreateLineLocation(locations);
+            Polygon outLine = new Polygon(locations);
+            jObject.OutLine.Add(outLine);
+            return new List<BimId>() { jObject.Id };
+        }
+
+    }
+}

+ 51 - 0
JBIM/RevitToJBim/ComponentParse/ParseWall.cs

@@ -0,0 +1,51 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseWall
+ * 作者:xulisong
+ * 创建时间: 2019/6/25 17:53:27
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using JBIM;
+using RevitExport.Export;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JWall = JBIM.Component.Wall;
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseWall : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { typeof(Wall).FullName };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.RefElement is Wall;
+        }
+
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is Wall wall))
+            {
+                return null;
+            }
+            JWall jObject = new JWall();
+            ParseCore.AttachObject(jObject, wrapper);
+            context.AddBimObject(jObject);
+            jObject.Location = ParseCore.GetLocation(wall.Location);
+            //if (fi.Host != null)
+            //{
+            //    jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();
+            //}
+
+            return new List<BimId>() { jObject.Id };
+        }
+
+    }
+}

+ 59 - 0
JBIM/RevitToJBim/ComponentParse/ParseWindow.cs

@@ -0,0 +1,59 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseWindow
+ * 作者:xulisong
+ * 创建时间: 2019/6/25 17:52:58
+ * 版本号: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 JBIM.Definition;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using JFamilyType = RevitToJBim.Common.FamilyType;
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseWindow : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { CategoryGenerator.BuildingCategory(JFamilyType.Door) };
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Door);
+        }
+
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance fi))
+            {
+                return null;
+            }
+            Window jObject = new Window();
+            ParseCore.AttachObject(jObject, wrapper);
+            context.AddBimObject(jObject);
+            jObject.Location = ParseCore.GetLocation(fi.Location);
+            if (fi.Host != null)
+            {
+                jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();
+            }
+            var polygonPath = RevitUtil.GetWindowDoorLocation(fi);
+            if (polygonPath != null && polygonPath.Any())
+            {
+                Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath));
+                jObject.OutLine.Add(outLine);
+            }
+            return new List<BimId>() { jObject.Id };
+        }
+
+    }
+}

+ 5 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -61,6 +61,7 @@
   <ItemGroup>
     <Compile Include="Common\CategoryGenerator.cs" />
     <Compile Include="Common\Converter.cs" />
+    <Compile Include="Common\CurveExtension.cs" />
     <Compile Include="Common\ElementWrapperFactory.cs" />
     <Compile Include="Common\ExceptionUtil.cs" />
     <Compile Include="Common\FamilyType.cs" />
@@ -75,11 +76,15 @@
     <Compile Include="ComponentParse\ParseConnector.cs" />
     <Compile Include="ComponentParse\ParseCore.cs" />
     <Compile Include="ComponentParse\ParseFacility.cs" />
+    <Compile Include="ComponentParse\ParseDoor.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\ParseVirtualWall.cs" />
+    <Compile Include="ComponentParse\ParseWall.cs" />
+    <Compile Include="ComponentParse\ParseWindow.cs" />
     <Compile Include="ComponentParse\UsableParseAttribute.cs" />
     <Compile Include="ExportDataBuilder.cs" />
     <Compile Include="Extension\ElementExtension.cs" />