Example #1
0
        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);
        }
Example #2
0
        //打开stl文件
        private void openSTLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "STEP File(*.stl)|*.stl|All Files(*.*)|*.*";

            if (DialogResult.OK != dlg.ShowDialog())
            {
                return;
            }

            TopoShape shape = GlobalInstance.BrepTools.LoadFile(new AnyCAD.Platform.Path(dlg.FileName));

            renderView.RenderTimer.Enabled = false;
            if (shape != null)
            {
                //加载到stl文件时
                TopoShapeGroup group = new TopoShapeGroup();
                group.Add(shape);

                SceneManager sceneMgr = renderView.SceneManager;
                SceneNode    rootNode = GlobalInstance.TopoShapeConvert.ToSceneNode(shape, 0.1f);
                if (rootNode != null)
                {
                    sceneMgr.AddNode(rootNode);
                }
            }
            renderView.RenderTimer.Enabled = true;
            renderView.FitAll();
            renderView.RequestDraw(EnumRenderHint.RH_LoadScene);
        }
Example #3
0
        private TopoShape DrawRect(List <Vector3> vertex)
        {
            var face = GlobalInstance.BrepTools.FillFace(vertex);

            renderViewDraw.ClearScene();
            SceneManager sceneMgr = renderViewDraw.SceneManager;
            SceneNode    rootNode = GlobalInstance.TopoShapeConvert.ToSceneNode(face, 0.1f);

            if (rootNode != null)
            {
                sceneMgr.AddNode(rootNode);
            }
            renderViewDraw.FitAll();
            renderViewDraw.RequestDraw(EnumRenderHint.RH_LoadScene);
            return(face);
        }
Example #4
0
        private void sTLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "STL (*.stl)|*.stl|IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|All Files(*.*)|*.*";

            if (DialogResult.OK == dlg.ShowDialog())
            {
                TopoShape shape = GlobalInstance.BrepTools.LoadFile(dlg.FileName);
                renderView.RenderTimer.Enabled = false;
                if (shape != null)
                {
                    PhongMaterial material = new PhongMaterial();
                    material.SetAmbient(new ColorValue(0.24725f, 0.2245f, 0.0645f));
                    material.SetDiffuse(new ColorValue(0.84615f, 0.8143f, 0.2903f));
                    material.SetSpecular(new ColorValue(0.797357f, 0.723991f, 0.208006f));
                    material.SetShininess(83.2f);
                    FaceStyle faceStyle = new FaceStyle();
                    faceStyle.SetMaterial(material);
                    SceneManager   sceneMgr = renderView.SceneManager;
                    TopoShapeGroup subGroup = GlobalInstance.TopoExplor.ExplorSubShapes(shape);
                    int            nSize    = subGroup.Size();
                    for (int ii = 0; ii < nSize; ++ii)
                    {
                        SceneNode node = GlobalInstance.TopoShapeConvert.ToEntityNode(subGroup.GetTopoShape(ii), 10f);
                        node.SetId(++shapeId);
                        node.SetFaceStyle(faceStyle);

                        sceneMgr.AddNode(node);
                    }
                }
                renderView.RenderTimer.Enabled = true;
            }

            renderView.View3d.FitAll();
            renderView.RequestDraw(EnumRenderHint.RH_LoadScene);
        }
Example #5
0
        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);
        }
Example #6
0
        private void BtnDown_Click(object sender, EventArgs e)
        {
            //Get selected shape
            SelectedShapeQuery context = new SelectedShapeQuery();

            renderViewDraw.QuerySelection(context);
            var face = context.GetGeometry();
            var line = context.GetSubGeometry();

            if (face == null || line == null)
            {
                return;
            }
            if (face.GetShapeType() != EnumTopoShapeType.Topo_FACE || line.GetShapeType() != EnumTopoShapeType.Topo_EDGE)
            {
                return;
            }

            //记录输入参数
            Bending bending = new Bending()
            {
                Direction = EnumDir.Edge_DOWN,
                Angle     = Convert.ToDouble(txtAngle.Text),
                Radius    = Convert.ToDouble(txtRadius.Text),
                Length    = Convert.ToDouble(txtLength.Text)
            };
            GeomCurve curve = new GeomCurve();

            curve.Initialize(line);
            Vector3 dirL = curve.DN(curve.FirstParameter(), 1);

            if (dirL.Y >= 0)
            {
                bending.Orientation = Math.Round(dirL.AngleBetween(Vector3.UNIT_X), 3);
            }
            else
            {
                bending.Orientation = Math.Round(360 - dirL.AngleBetween(Vector3.UNIT_X), 3);
            }
            //if (dirL.X == 1)
            //{
            //    bending.Orientation = EnumEdge.Edge_1;
            //}
            //else if (dirL.Y == 1)
            //{
            //    bending.Orientation = EnumEdge.Edge_2;
            //}
            //else if (dirL.X == -1)
            //{
            //    bending.Orientation = EnumEdge.Edge_3;
            //}
            //else
            //{
            //    bending.Orientation = EnumEdge.Edge_4;
            //}

            TopoShape sweep = BendDown(face, line, bending).Sweep;

            bendings.Add(bending);

            #region 渲染
            ElementId    faceId   = new ElementId(bending.Index + shapeId);
            ElementId    edgeId   = new ElementId(bending.Index);
            SceneManager sceneMgr = renderViewDraw.SceneManager;
            SceneNode    rootNode = GlobalInstance.TopoShapeConvert.ToSceneNode(sweep, 0.1f);
            SceneNode    faceNode = GlobalInstance.TopoShapeConvert.ToSceneNode(face, 0.1f);
            SceneNode    edgeNode = GlobalInstance.TopoShapeConvert.ToSceneNode(line, 0.1f);
            faceNode.SetId(faceId);
            faceNode.SetVisible(false);
            edgeNode.SetId(edgeId);
            edgeNode.SetVisible(false);
            if (rootNode != null)
            {
                sceneMgr.AddNode(rootNode);
                sceneMgr.AddNode(faceNode);
                sceneMgr.AddNode(edgeNode);
            }
            renderViewDraw.FitAll();
            renderViewDraw.RequestDraw(EnumRenderHint.RH_LoadScene);

            #endregion
        }