public override bool Run(FeatureContext context)
        {
            LineStyle lineStyle = new LineStyle();

            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.BLUE);
            lineStyle.SetLineWidth(1.5f);
            LineStyle lineStyle2 = new LineStyle();

            lineStyle2.SetLineWidth(0.5f);
            lineStyle2.SetColor(ColorValue.GREEN);
            lineStyle2.SetLineWidth(2);
            TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z);

            context.ShowGeometry(arc);

            {
                GeomCurve curve = new GeomCurve();
                curve.Initialize(arc);

                double paramStart = curve.FirstParameter();
                double paramEnd   = curve.LastParameter();

                double step = (paramEnd - paramStart) * 0.1;

                for (double uu = paramStart; uu <= paramEnd; uu += step)
                {
                    Vector3 dir = curve.DN(uu, 1);
                    Vector3 pos = curve.Value(uu);

                    // 切线
                    {
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir);
                        SceneNode node = context.ShowGeometry(line);
                        node.SetLineStyle(lineStyle);
                    }
                    // 法线
                    {
                        Vector3   dirN = dir.CrossProduct(Vector3.UNIT_Z);
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN);
                        SceneNode node = context.ShowGeometry(line);
                        node.SetLineStyle(lineStyle2);
                    }
                }
            }

            return(true);
        }
Example #2
0
        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);
        }
Example #3
0
        private void curveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            renderView.SetStandardView(EnumStandardView.SV_Top);

            Platform.LineStyle lineStyle = new Platform.LineStyle();
            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.BLUE);
            Platform.LineStyle lineStyle2 = new Platform.LineStyle();
            lineStyle2.SetLineWidth(0.5f);
            lineStyle2.SetColor(ColorValue.GREEN);

            Platform.TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z);
            renderView.ShowGeometry(arc, 100);
 
            {
                GeomCurve curve = new GeomCurve();
                curve.Initialize(arc);

                float paramStart = curve.FirstParameter();
                float paramEnd = curve.LastParameter();

                float step = (paramEnd - paramStart) * 0.1f;

                for (float uu = paramStart; uu <= paramEnd; uu += step)
                {
                    Vector3 dir = curve.DN(uu, 1);
                    Vector3 pos = curve.Value(uu);

                    // 切线
                    {
                        Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir);
                        Platform.SceneNode node = renderView.ShowGeometry(line, 101);
                        node.SetLineStyle(lineStyle);
                    }
                    // 法线
                    {
                        Vector3 dirN = dir.CrossProduct(Vector3.UNIT_Z);
                        Platform.TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN);
                        Platform.SceneNode node = renderView.ShowGeometry(line, 101);
                        node.SetLineStyle(lineStyle2);
                    }

                }

            }

            TopoShapeProperty property = new TopoShapeProperty();
            property.SetShape(arc);

            float len = property.EdgeLength();

            TextNode text = new TextNode();
            text.SetText(String.Format("Arc Length: {0}", len));
            text.SetPosition(new Vector3(100, 100, 0));

            renderView.SceneManager.ClearNodes2d();
            renderView.SceneManager.AddNode2d(text);

            renderView.RequestDraw();
        }
Example #4
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
        }