public override bool Run(FeatureContext context)
        {
            TopoShape oCircle1    = GlobalInstance.BrepTools.MakeCircle(Vector3.ZERO, 20, Vector3.UNIT_Z);
            TopoShape Pipe01_Surf = GlobalInstance.BrepTools.Extrude(oCircle1, 100, Vector3.UNIT_Z);

            context.ShowGeometry(Pipe01_Surf);

            TopoShape oCircle2    = GlobalInstance.BrepTools.MakeCircle(new Vector3(0.0f, 0.0f, 50.0f), 10, Vector3.UNIT_Y);
            TopoShape Pipe02_Surf = GlobalInstance.BrepTools.Extrude(oCircle2, 80, Vector3.UNIT_Y);
            {
                SceneNode node2 = context.ShowGeometry(Pipe02_Surf);
                FaceStyle fs    = new FaceStyle();
                fs.SetColor(new ColorValue(0.5f, 0.5f, 0.5f, 0.5f));
                fs.SetTransparent(true);
                node2.SetFaceStyle(fs);
            }

            // Compute the intersection curve
            TopoShape Inters1 = GlobalInstance.BrepTools.SurfaceSection(Pipe01_Surf, Pipe02_Surf);

            if (Inters1 != null)
            {
                SceneNode node = context.ShowGeometry(Inters1);
                LineStyle ls   = new LineStyle();
                ls.SetLineWidth(3);
                ls.SetColor(ColorValue.RED);
                node.SetLineStyle(ls);

                // Get the curve parameters
                GeomCurve curve = new GeomCurve();
                if (curve.Initialize(Inters1))
                {
                    LineStyle ls2 = new LineStyle();
                    ls2.SetColor(ColorValue.GREEN);

                    double start = curve.FirstParameter();
                    double end   = curve.LastParameter();
                    for (double ii = start; ii <= end; ii += 0.1)
                    {
                        List <Vector3> rt = curve.D1(ii);
                        LineNode       ln = new LineNode();
                        ln.SetLineStyle(ls2);
                        ln.Set(rt[0], rt[0] + rt[1]);
                        context.ShowSceneNode(ln);
                    }
                }
            }

            return(true);
        }
        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);
        }
Exemple #3
0
        public EdgeInfo(TopoShape edge, int idx, int faceIdx, double length)
        {
            Curve = new GeomCurve();
            Curve.Initialize(edge);
            Index     = idx;
            FaceIndex = faceIdx;
            var start = Curve.Value(Curve.FirstParameter());
            var end   = Curve.Value(Curve.LastParameter());

            Direction = end - start;
            Direction.Normalize();
            Length = length;

            var pts = GlobalInstance.TopoExplor.ExplorVertices(edge);

            for (int ii = 0; ii < pts.Size(); ++ii)
            {
                GeomPoint gp = new GeomPoint();
                gp.Initialize(pts.GetAt(ii));

                Vertices.Add(new VertexInfo(gp.GetPoint(), ii, idx, faceIdx));
            }
        }
        private void circleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectedShapeQuery query = new SelectedShapeQuery();

            renderView.QuerySelection(query);
            var shape = query.GetSubGeometry();

            if (shape == null)
            {
                return;
            }

            GeomCurve curve = new GeomCurve();

            if (!curve.Initialize(shape))
            {
                return;
            }

            if (curve.GetCurveType() != EnumCurveType.CurveType_Circle)
            {
                var     xx  = curve.FirstParameter() + curve.LastParameter();
                Vector3 pt1 = curve.Value(curve.FirstParameter());
                Vector3 pt2 = curve.Value(xx * 0.3);
                Vector3 pt3 = curve.Value(xx * 0.6);

                var arc = GlobalInstance.BrepTools.MakeArc3Pts(pt1, pt3, pt2);
                if (arc != null)
                {
                    GeomCircle circle = new GeomCircle();
                    circle.Initialize(arc);
                    var center = circle.GetCenter();
                    MessageBox.Show(String.Format("Center: {0}, {1}, {2}", center.X, center.Y, center.Z));
                }
            }
        }
Exemple #5
0
        private void queryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectedShapeQuery context = new SelectedShapeQuery();

            renderView.QuerySelection(context);

            TopoShape subShape = context.GetSubGeometry();
            SceneNode topoNode = context.GetSubNode();


            if (subShape != null)
            {
                Console.WriteLine(subShape.GetShapeType());
            }

            Matrix4 shapeTransform = topoNode.GetTransform();
            //surface
            GeomSurface surface = new GeomSurface();

            if (surface.Initialize(subShape))
            {
                List <Vector3> ptVecList  = new List <Vector3>();
                List <Vector3> norVecList = new List <Vector3>();
                Console.Write("surface");
                //double firstU = surface.FirstUParameter();
                //double lastU = surface.LastUParameter();
                //double firstV = surface.FirstVParameter();
                //double lastV = surface.LastVParameter();
                double firstU  = surface.FirstUParameter();
                double lastU   = surface.LastUParameter();
                double firstV  = surface.FirstVParameter();
                double lastV   = surface.LastVParameter();
                double offSetU = lastU - firstU;
                double offSetV = lastV - firstV;

                double stepU   = 0.10;
                double stepV   = 10;
                int    stepNoU = (int)(offSetU / stepU);
                int    stepNoV = (int)(offSetV / stepV);
                for (int v_i = 3; v_i < stepNoV - 5; v_i++)
                {
                    for (int u_i = 0; u_i < stepNoU; u_i++)
                    {
                        double tempV = firstV + stepV * v_i;
                        double tempU = firstU + stepU * (v_i % 2 == 0 ? u_i : stepNoU - u_i);
                        //double tempV = firstV + stepV * (u_i % 2 == 0 ? v_i : stepNoV - v_i);
                        Vector3 ptVec_1     = surface.Value(tempU, tempV);
                        Vector3 ptVec       = shapeTransform.Transform(ptVec_1);
                        Vector3 normalVec_1 = surface.GetNormal(tempU, tempV);
                        //Vector3 normalVec =shapeTransform.Transform(normalVec_1);//matrix3  3*3
                        Vector3 normalVec = RotateDirVector(shapeTransform, normalVec_1);
                        ptVecList.Add(ptVec);
                        norVecList.Add(normalVec);
                        pathPqList.Add(QuaternionFromTo(new Vector3(-1, 0, 0), normalVec, ptVec));
                        ShowStatusMessage("path pts No: " + pathPqList.Count);

                        //LineNode tempLineNode = new LineNode();
                        //LineStyle lineStyle = new LineStyle();
                        //lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine);
                        //lineStyle.SetColor(100, 0, 100);
                        //tempLineNode.SetLineStyle(lineStyle);
                        //tempLineNode.Set(ptVec, ptVec + normalVec);
                        //tempLineNode.SetVisible(true);
                        //renderView.SceneManager.AddNode(tempLineNode);
                        //renderView.RequestDraw();
                    }
                }

                //for (int u_i = 0; u_i < stepNoU; u_i++)
                //{
                //    for (int v_i = 0; v_i < stepNoV-0; v_i++)
                //    {

                //        double tempU = firstU + stepU * u_i;
                //        double tempV = firstV + stepV * (u_i % 2 == 0 ? v_i : stepNoV - v_i);

                //        Vector3 ptVec =shapeTransform.Transform(surface.Value(tempU,tempV ));
                //        Vector3 normalVec = surface.GetNormal(tempU,tempV);
                //        ptVecList.Add(ptVec);
                //        norVecList.Add(normalVec);
                //        pathPqList.Add(QuaternionFromTo(new Vector3(-1, 0, 0), normalVec, ptVec));
                //    }
                //}
                int a = 0;
            }
            //curve
            GeomCurve curve = new GeomCurve();

            if (curve.Initialize(subShape))
            {
                Vector3 startPt = shapeTransform.Transform(curve.D0(curve.FirstParameter()));
                //Vector3 startPt_ = shapeTransform.Transform(startPt);
                Vector3 pt1   = curve.GetStartPoint();
                Vector3 endPt = shapeTransform.Transform(curve.D0(curve.LastParameter()));
                Vector3 pt2   = curve.GetEndPoint();
                switch ((EnumCurveType)curve.GetCurveType())
                {
                case EnumCurveType.CurveType_OtherCurve:
                    Console.Write("other");
                    break;

                case EnumCurveType.CurveType_BSplineCurve:
                    break;

                case EnumCurveType.CurveType_BezierCurve:
                    break;

                case EnumCurveType.CurveType_Parabola:
                    break;

                case EnumCurveType.CurveType_Hyperbola:
                    break;

                case EnumCurveType.CurveType_Ellipse:
                    break;

                case EnumCurveType.CurveType_Circle:
                    Console.Write("Circle");
                    break;

                case EnumCurveType.CurveType_Line:
                    Console.Write("Line");

                    //path
                    double[] startPt_ = new double[3] {
                        startPt.X, startPt.Y, startPt.Z
                    };
                    double[] endPt_ = new double[3] {
                        endPt.X, endPt.Y, endPt.Z
                    };
                    Path_U.Interpolation(startPt_, endPt_, 0.01, ref pathPtList);
                    //show pick result
                    LineNode  tempLineNode = new LineNode();
                    LineStyle lineStyle    = new LineStyle();
                    lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine);
                    lineStyle.SetColor(100, 0, 100);
                    tempLineNode.SetLineStyle(lineStyle);
                    tempLineNode.Set(new Vector3(startPt.X + 0.1, startPt.Y + 10, startPt.Z + 0.1), endPt);
                    tempLineNode.SetVisible(true);
                    renderView.SceneManager.AddNode(tempLineNode);
                    renderView.RequestDraw();
                    break;

                default:
                    break;
                }



                ElementId id = context.GetNodeId();
                MessageBox.Show(id.AsInt().ToString());
                //...
            }
        }
Exemple #6
0
        private void querySelectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SelectedShapeQuery context = new SelectedShapeQuery();
            renderView.QuerySelection(context);
            TopoShape subShape = context.GetSubGeometry();
            GeomCurve curve = new GeomCurve();
            if (curve.Initialize(subShape))
            {
               Vector3 startPt = curve.D0(curve.FirstParameter());
               Vector3 endPt = curve.D0(curve.LastParameter());
                //...
            }

            ElementId id = context.GetNodeId();
            MessageBox.Show(id.AsInt().ToString());
        }
Exemple #7
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();
        }
Exemple #8
0
        private void surfaceSectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TopoShape oCircle1 = GlobalInstance.BrepTools.MakeCircle(Vector3.ZERO, 20, Vector3.UNIT_Z);
            TopoShape Pipe01_Surf = GlobalInstance.BrepTools.Extrude(oCircle1, 100, Vector3.UNIT_Z);
            renderView.ShowGeometry(Pipe01_Surf, ++shapeId);

            TopoShape oCircle2 = GlobalInstance.BrepTools.MakeCircle(new Vector3(0.0f, 0.0f, 50.0f), 10, Vector3.UNIT_Y);
            TopoShape Pipe02_Surf = GlobalInstance.BrepTools.Extrude(oCircle2, 80, Vector3.UNIT_Y);
            renderView.ShowGeometry(Pipe02_Surf, ++shapeId);

            TopoShape Inters1 = GlobalInstance.BrepTools.SurfaceSection(Pipe01_Surf, Pipe02_Surf);
            if (Inters1 != null)
            {
                SceneNode node = renderView.ShowGeometry(Inters1, ++shapeId);
                LineStyle ls = new LineStyle();
                ls.SetLineWidth(3);
                ls.SetColor(ColorValue.RED);
                node.SetLineStyle(ls);

                GeomCurve curve = new GeomCurve();
                if (curve.Initialize(Inters1))
                {
                    LineStyle ls2 = new LineStyle();
                    ls2.SetColor(ColorValue.GREEN);

                    float start = curve.FirstParameter();
                    float end = curve.LastParameter();
                    for (float ii = start; ii <= end; ii += 0.1f)
                    {
                        List<Vector3> rt = curve.D1(ii);
                        LineNode ln = new LineNode();
                        ln.SetLineStyle(ls2);
                        ln.Set(rt[0], rt[0] + rt[1]);
                        renderView.ShowSceneNode(ln);
                    }
                }
            }
            renderView.RequestDraw();
        }
        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);
        }