private void DrawUnfoldGroup(BendingGroup bends)
        {
            renderViewDraw.ClearScene();

            #region 绘制底面
            TopoShape baseShape = GlobalInstance.BrepTools.FillFace(bends.Vertexes);

            SceneManager sceneMgr = renderViewDraw.SceneManager;
            SceneNode    root     = GlobalInstance.TopoShapeConvert.ToSceneNode(baseShape, 0.1f);
            sceneMgr.AddNode(root);
            #endregion

            #region  逆时针方向依次折弯
            Queue <Vector3> vertexQueue = new Queue <Vector3>(bends.Vertexes);
            for (int i = 0; i < vertexQueue.Count(); i++)
            {
                var sPt = vertexQueue.Dequeue();
                var ePt = vertexQueue.Peek();
                vertexQueue.Enqueue(sPt);
                var line      = GlobalInstance.BrepTools.MakeLine(sPt, ePt);
                var face      = baseShape;
                var groupEdge = from m in bends.Bendings
                                where m.Orientation == Math.Round(((ePt - sPt).Y >= 0 ? (ePt - sPt).AngleBetween(Vector3.UNIT_X) : (360 - (ePt - sPt).AngleBetween(Vector3.UNIT_X))), 3)
                                orderby m.Index
                                select m;
                foreach (var bending in groupEdge)
                {
                    if (face == null || line == null)
                    {
                        return;
                    }
                    if (face.GetShapeType() != EnumTopoShapeType.Topo_FACE || line.GetShapeType() != EnumTopoShapeType.Topo_EDGE)
                    {
                        break;
                    }
                    BendHelper helper = new BendHelper();
                    var        temp   = new Bending(bending);
                    temp.Length += temp.Radius * temp.Angle * Math.PI / 180;
                    temp.Angle   = 0;
                    helper       = BendUp(face, line, temp);
                    ElementId id   = new ElementId(bending.Index);
                    SceneNode node = GlobalInstance.TopoShapeConvert.ToSceneNode(helper.Sweep, 0.1f);
                    node.SetId(id);
                    sceneMgr.AddNode(node);
                    face = helper.EdFace;
                    line = helper.EdLine;
                }
            }
            #endregion

            renderViewDraw.FitAll();
            renderViewDraw.RequestDraw(EnumRenderHint.RH_LoadScene);
        }
        private void DrawBendingGroup(BendingGroup bends)
        {
            renderViewDraw.ClearScene();

            #region 绘制底面
            //var pt0 = new Vector3(0, 0, 0);
            //var pt1 = new Vector3(bends.Length, 0, 0);
            //var pt2 = new Vector3(bends.Length, bends.Width, 0);
            //var pt3 = new Vector3(0, bends.Width, 0);
            //TopoShape baseEdge1 = GlobalInstance.BrepTools.MakeLine(pt0, pt1);
            //TopoShape baseEdge2 = GlobalInstance.BrepTools.MakeLine(pt1, pt2);
            //TopoShape baseEdge3 = GlobalInstance.BrepTools.MakeLine(pt2, pt3);
            //TopoShape baseEdge4 = GlobalInstance.BrepTools.MakeLine(pt3, pt0);
            //TopoShape rect = GlobalInstance.BrepTools.MakeRectangle(bends.Length, bends.Width, 0, Coordinate3.UNIT_XYZ);
            //TopoShape baseShape = GlobalInstance.BrepTools.MakeFace(rect);
            TopoShape baseShape = GlobalInstance.BrepTools.FillFace(bends.Vertexes);

            SceneManager sceneMgr = renderViewDraw.SceneManager;
            SceneNode    root     = GlobalInstance.TopoShapeConvert.ToSceneNode(baseShape, 0.1f);
            sceneMgr.AddNode(root);
            #endregion

            #region  逆时针方向依次折弯
            //var oris = bends.Bendings.OrderBy(m => m.Orientation).Select(m => m.Orientation).Distinct();
            Queue <Vector3> vertexQueue = new Queue <Vector3>(bends.Vertexes);
            for (int i = 0; i < vertexQueue.Count(); i++)
            {
                var sPt = vertexQueue.Dequeue();
                var ePt = vertexQueue.Peek();
                vertexQueue.Enqueue(sPt);
                var line      = GlobalInstance.BrepTools.MakeLine(sPt, ePt);
                var face      = baseShape;
                var groupEdge = from m in bends.Bendings
                                where m.Orientation == Math.Round(((ePt - sPt).Y >= 0 ? (ePt - sPt).AngleBetween(Vector3.UNIT_X) : (360 - (ePt - sPt).AngleBetween(Vector3.UNIT_X))), 3)
                                orderby m.Index
                                select m;
                foreach (var bending in groupEdge)
                {
                    if (face == null || line == null)
                    {
                        return;
                    }
                    if (face.GetShapeType() != EnumTopoShapeType.Topo_FACE || line.GetShapeType() != EnumTopoShapeType.Topo_EDGE)
                    {
                        break;
                    }
                    BendHelper helper = new BendHelper();
                    if (bending.Direction.Equals(EnumDir.Edge_UP))
                    {
                        helper = BendUp(face, line, bending);
                    }
                    else
                    {
                        helper = BendDown(face, line, bending);
                    }
                    ElementId id   = new ElementId(bending.Index);
                    SceneNode node = GlobalInstance.TopoShapeConvert.ToSceneNode(helper.Sweep, 0.1f);
                    node.SetId(id);
                    sceneMgr.AddNode(node);
                    face = helper.EdFace;
                    line = helper.EdLine;
                }
            }
            #endregion
            #region  四个方向分别折弯
            //var groupEdge1 = from m in bends.Bendings
            //                 where m.Orientation == 0
            //                 orderby m.Index
            //                 select m ;
            //var groupEdge2 = from m in bends.Bendings
            //                 where m.Orientation == 1
            //                 orderby m.Index
            //                 select m;
            //var groupEdge3 = from m in bends.Bendings
            //                 where m.Orientation == 2
            //                 orderby m.Index
            //                 select m;
            //var groupEdge4 = from m in bends.Bendings
            //                 where m.Orientation == 3
            //                 orderby m.Index
            //                 select m;

            ////TopoShape line = baseEdge1;
            ////TopoShape face = baseShape;
            //foreach (var bending in groupEdge1)
            //{
            //    if (face == null || line == null)
            //    {
            //        return;
            //    }
            //    if (face.GetShapeType() != EnumTopoShapeType.Topo_FACE || line.GetShapeType() != EnumTopoShapeType.Topo_EDGE)
            //    {
            //        break;
            //    }
            //    BendHelper helper = new BendHelper();
            //    if (bending.Direction.Equals(EnumDir.Edge_UP))
            //    {
            //        helper = BendUp(face, line, bending);
            //    }
            //    else
            //    {
            //        helper = BendDown(face, line, bending);
            //    }
            //    ElementId id = new ElementId(bending.Index);
            //    SceneNode node = GlobalInstance.TopoShapeConvert.ToSceneNode(helper.Sweep, 0.1f);
            //    node.SetId(id);
            //    sceneMgr.AddNode(node);
            //    face = helper.EdFace;
            //    line = helper.EdLine;
            //}
            //face = baseShape;
            //line = baseEdge2;
            //foreach (var bending in groupEdge2)
            //{
            //    if (face == null)
            //    {
            //        break;
            //    }
            //    BendHelper helper = new BendHelper();
            //    if (bending.Direction.Equals(EnumDir.Edge_UP))
            //    {
            //        helper = BendUp(face, line, bending);
            //    }
            //    else
            //    {
            //        helper = BendDown(face, line, bending);
            //    }

            //    ElementId id = new ElementId(bending.Index);
            //    SceneNode node = GlobalInstance.TopoShapeConvert.ToSceneNode(helper.Sweep, 0.1f);
            //    node.SetId(id);
            //    sceneMgr.AddNode(node);
            //    face = helper.EdFace;
            //    line = helper.EdLine;
            //}
            //face = baseShape;
            //line = baseEdge3;
            //foreach (var bending in groupEdge3)
            //{
            //    if (face == null)
            //    {
            //        break;
            //    }
            //    BendHelper helper = new BendHelper();
            //    if (bending.Direction.Equals(EnumDir.Edge_UP))
            //    {
            //        helper = BendUp(face, line, bending);
            //    }
            //    else
            //    {
            //        helper = BendDown(face, line, bending);
            //    }

            //    ElementId id = new ElementId(bending.Index);
            //    SceneNode node = GlobalInstance.TopoShapeConvert.ToSceneNode(helper.Sweep, 0.1f);
            //    node.SetId(id);
            //    sceneMgr.AddNode(node);
            //    face = helper.EdFace;
            //    line = helper.EdLine;
            //}
            //face = baseShape;
            //line = baseEdge4;
            //foreach (var bending in groupEdge4)
            //{
            //    if (face == null)
            //    {
            //        break;
            //    }
            //    BendHelper helper = new BendHelper();
            //    if (bending.Direction.Equals(EnumDir.Edge_UP))
            //    {
            //        helper = BendUp(face, line, bending);
            //    }
            //    else
            //    {
            //        helper = BendDown(face, line, bending);
            //    }

            //    ElementId id = new ElementId(bending.Index);
            //    SceneNode node = GlobalInstance.TopoShapeConvert.ToSceneNode(helper.Sweep, 0.1f);
            //    node.SetId(id);
            //    sceneMgr.AddNode(node);
            //    face = helper.EdFace;
            //    line = helper.EdLine;
            //}
            #endregion

            renderViewDraw.FitAll();
            renderViewDraw.RequestDraw(EnumRenderHint.RH_LoadScene);
        }
        private BendHelper BendDown(TopoShape face, TopoShape line, Bending bending)
        {
            #region 计算平面法向量
            GeomSurface surface = new GeomSurface();
            surface.Initialize(face);
            //参数域UV范围
            double uFirst = surface.FirstUParameter();
            double uLast  = surface.LastUParameter();
            double vFirst = surface.FirstVParameter();
            double vLast  = surface.LastVParameter();
            //取中点
            double umid = uFirst + (uLast - uFirst) * 0.5f;
            double vmid = vFirst + (vLast - vFirst) * 0.5f;
            //计算法向量
            var     data = surface.D1(umid, vmid);
            Vector3 dirU = data[1];
            Vector3 dirV = data[2];
            Vector3 dirF = dirV.CrossProduct(dirU);
            dirF.Normalize();
            #endregion

            #region 计算边线参数
            GeomCurve curve = new GeomCurve();
            curve.Initialize(line);
            Vector3 dirL = curve.DN(curve.FirstParameter(), 1);
            Vector3 stPt = curve.Value(curve.FirstParameter()); //起点
            Vector3 edPt = curve.Value(curve.LastParameter());  //终点
            #endregion

            #region 绘制草图
            TopoShapeGroup lineGroup = new TopoShapeGroup();

            Vector3   center  = stPt + dirF * bending.Radius; //圆心
            Vector3   radius  = stPt - center;                //半径
            double    theta   = bending.Angle * (Math.PI / 180.0);
            Vector3   radius2 = radius * Math.Cos(theta) + dirL.CrossProduct(radius) * Math.Sin(theta);
            Vector3   edArc   = center + radius2;                                            //圆弧终点
            TopoShape arc     = GlobalInstance.BrepTools.MakeArc(stPt, edArc, center, dirL); //绘制圆弧
            if (arc != null)
            {
                lineGroup.Add(arc);
            }
            Vector3 edLine = dirL.CrossProduct(radius2) * (bending.Length / bending.Radius) + edArc;
            arc = GlobalInstance.BrepTools.MakeLine(edArc, edLine);
            lineGroup.Add(arc);
            //扫描生成折弯
            TopoShape wireSketch = GlobalInstance.BrepTools.MakeWire(lineGroup);
            TopoShape sweep;
            if (wireSketch != null)
            {
                sweep = GlobalInstance.BrepTools.Sweep(wireSketch, line, true);
            }
            else
            {
                sweep = GlobalInstance.BrepTools.Sweep(arc, line, true);
            }
            TopoShape oFace = GlobalInstance.BrepTools.Sweep(arc, line, true).GetSubShape(0, 1);
            TopoShape oEdge = GlobalInstance.BrepTools.MakeLine(edLine, edLine + edPt - stPt);
            #endregion
            BendHelper bend = new BendHelper()
            {
                Sweep  = sweep,
                EdFace = oFace,
                EdLine = oEdge
            };
            return(bend);
        }