Exemplo n.º 1
0
        public override bool Run(FeatureContext context)
        {
            // build two surfaces
            TopoShape arc   = GlobalInstance.BrepTools.MakeArc(Vector3.ZERO, 100, 0, 135, Vector3.UNIT_Z);
            TopoShape cir   = GlobalInstance.BrepTools.MakeCircle(new Vector3(-200, 0, 0), 50, Vector3.UNIT_X);
            TopoShape surf1 = GlobalInstance.BrepTools.Extrude(arc, 100, Vector3.UNIT_Z);
            TopoShape surf2 = GlobalInstance.BrepTools.Extrude(cir, 400, Vector3.UNIT_X);

            SceneNode n1 = context.ShowGeometry(surf1);
            {
                FaceStyle fs1 = new FaceStyle();
                fs1.SetColor(new ColorValue(0, 0, 0.5f, 0.5f));
                fs1.SetTransparent(true);
                n1.SetFaceStyle(fs1);
            }
            SceneNode n2 = context.ShowGeometry(surf2);
            {
                FaceStyle fs2 = new FaceStyle();
                fs2.SetColor(new ColorValue(0, 0.5f, 0.5f, 0.5f));
                fs2.SetTransparent(true);
                n2.SetFaceStyle(fs2);
            }

            // compute section wire
            TopoShape wire = GlobalInstance.BrepTools.SurfaceSection(surf1, surf2);

            SceneNode sectionNode = context.ShowGeometry(wire);
            LineStyle lineStyle   = new LineStyle();

            lineStyle.SetLineWidth(4);
            lineStyle.SetColor(ColorValue.RED);
            sectionNode.SetLineStyle(lineStyle);

            return(true);
        }
Exemplo n.º 2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            mDefaultLineStyle = new LineStyle();
            mDefaultLineStyle.SetColor(255, 0, 0);
            mDefaultLineStyle.SetLineWidth(2);

            renderView.ExecuteCommand("PickClearMode", "Single");
        }
        public override bool Run(FeatureContext context)
        {
            LineStyle lineStyle = new LineStyle();

            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.RED);

            var points = new List <Vector3>();

            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(50, 0, 0));
            points.Add(new Vector3(100, 0, 0));

            points.Add(new Vector3(0, 50, 0));
            points.Add(new Vector3(50, 50, 5));
            points.Add(new Vector3(100, 50, -5));

            points.Add(new Vector3(0, 150, 5));
            points.Add(new Vector3(50, 150, -5));
            points.Add(new Vector3(100, 150, 0));

            TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3);

            context.ShowGeometry(face);

            GeomSurface surface = new GeomSurface();

            surface.Initialize(face);
            double ufirst = surface.FirstUParameter();
            double uLarst = surface.LastUParameter();
            double vfirst = surface.FirstVParameter();
            double vLast  = surface.LastVParameter();

            double ustep = (uLarst - ufirst) * 0.1;
            double vstep = (vLast - vfirst) * 0.1;

            for (double ii = ufirst; ii <= uLarst; ii += ustep)
            {
                for (double jj = vfirst; jj <= vLast; jj += vstep)
                {
                    var data = surface.D1(ii, jj);

                    Vector3 pos  = data[0];
                    Vector3 dirU = data[1];
                    Vector3 dirV = data[2];
                    Vector3 dir  = dirV.CrossProduct(dirU);
                    //dir.Normalize();
                    {
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir * 0.01f);
                        SceneNode node = context.ShowGeometry(line);

                        node.SetLineStyle(lineStyle);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public FindWireContext(FeatureContext context)
        {
            _Context = context;
            _LineStyle.SetLineWidth(2);
            _LineStyle.SetColor(255, 0, 0);

            _FaceStyle.SetColor(new ColorValue(0.5f, 0.5f, 0.5f, 0.5f));
            _FaceStyle.SetTransparent(true);
        }
Exemplo n.º 5
0
        public override void OnStartEvent()
        {
            LineStyle lineStyle = new LineStyle();
            lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine);
            lineStyle.SetColor(100, 0, 100);

            tempLineNode.SetLineStyle(lineStyle);

            this.ShowTempNode(tempLineNode);
            GetRenderer().RequestDraw(1);
        }
Exemplo n.º 6
0
        public override void OnStartEvent()
        {
            LineStyle lineStyle = new LineStyle();

            lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine);
            lineStyle.SetColor(100, 0, 100);

            tempLineNode.SetLineStyle(lineStyle);

            this.ShowTempNode(tempLineNode);
            GetRenderer().RequestDraw(1);
        }
Exemplo n.º 7
0
        public CADBrower(System.Windows.Forms.TreeView _treeView, AnyCAD.Presentation.RenderWindow3d _renderView)
        {
            treeView   = _treeView;
            renderView = _renderView;
            faceStyle  = new FaceStyle();
            holeStyle  = new LineStyle();
            holeStyle.SetLineWidth(3);
            holeStyle.SetColor(0, 256, 0);

            System.Windows.Forms.TreeNode node = treeView.Nodes.Add("AnyCAD.net");
            nodeStack.Push(node);
        }
        public override bool Run(FeatureContext context)
        {
            TopoShape shape = GlobalInstance.BrepTools.MakeArc(Vector3.ZERO, 100, 10, 180, Vector3.UNIT_Z);
            SceneNode node  = context.ShowGeometry(shape);
            LineStyle ls    = new LineStyle();

            ls.SetLineWidth(2);
            ls.SetColor(0, 255, 0);
            ls.SetPatternStyle((int)EnumLinePattern.LP_DashedLine);
            node.SetLineStyle(ls);

            return(true);
        }
Exemplo n.º 9
0
        public DrawLineEditor(AddLineEvent callback)
        {
            SetId("AD::DrawLine");
            OnAddLineEvent = callback;

            LineStyle lineStyle = new LineStyle();

            lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DashedLine);
            lineStyle.SetColor(255, 0, 100);
            lineStyle.SetLineWidth(2);

            tempLineNode.SetLineStyle(lineStyle);
        }
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public override bool Run(FeatureContext context)
        {
            TopoShape cylinder = GlobalInstance.BrepTools.MakeCylinder(Vector3.ZERO, Vector3.UNIT_Z, 100, 200, 270);
            TopoShape section  = GlobalInstance.BrepTools.BodySection(cylinder, new Vector3(0, 0, 50), Vector3.UNIT_Z);

            context.ShowGeometry(cylinder);

            SceneNode node = context.ShowGeometry(section);
            LineStyle ls   = new LineStyle();

            ls.SetLineWidth(3.0f);
            ls.SetColor(255, 0, 0);
            node.SetLineStyle(ls);

            return(true);
        }
Exemplo n.º 13
0
        public override bool Run(FeatureContext context)
        {
            TopoShape arc  = GlobalInstance.BrepTools.MakeArc(new Vector3(-100, 0, 0), new Vector3(100, 0, 0), Vector3.ZERO, Vector3.UNIT_Z);
            TopoShape line = GlobalInstance.BrepTools.MakeLine(new Vector3(100, 0, 0), new Vector3(100, 200, 0));

            TopoShapeGroup group = new TopoShapeGroup();

            group.Add(arc);
            group.Add(line);

            TopoShape wire = GlobalInstance.BrepTools.MakeSpline(group);

            TopoShape splitter1 = GlobalInstance.BrepTools.MakePoint(new Vector3(0, -100, 0));
            TopoShape splitter2 = GlobalInstance.BrepTools.MakePoint(new Vector3(100, 100, 0));

            TopoShapeGroup spliterGroup = new TopoShapeGroup();

            spliterGroup.Add(splitter1);
            spliterGroup.Add(splitter2);
            TopoShape result = GlobalInstance.BrepTools.MakeSplit(wire, spliterGroup);

            TopoExplor     exp   = new TopoExplor();
            TopoShapeGroup itmes = exp.ExplorSubShapes(result);

            for (int ii = 0; ii < itmes.Size(); ++ii)
            {
                SceneNode node = context.ShowGeometry(itmes.GetAt(ii));
                LineStyle ls   = new LineStyle();
                ls.SetLineWidth(3.0f);
                ls.SetColor((ii + 1) * 50, ii * 20, ii * 10);
                node.SetLineStyle(ls);
            }


            return(true);
        }
Exemplo n.º 14
0
        private void customGridToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WorkingPlane wp = renderView.Renderer.GetWorkingPlane();
            GridNode gridNode = new GridNode();
            Vector3 modelSize = renderView.SceneManager.GetBBox().Size();
            Vector2 cellSize = gridNode.GetCellSize();
            int nCountX = (int)(modelSize.X / cellSize.X + 0.5f) + 1;
            int nCountY = (int)(modelSize.Y / cellSize.Y + 0.5f) + 1;
            if (nCountX < 2)
                nCountX = 2;
            if (nCountY < 2)
                nCountY = 2;

            gridNode.SetCellCount(nCountX, nCountY);

            LineStyle lineStyle = new LineStyle();
            lineStyle.SetColor(new ColorValue(1.0f, 1.0f, 1.0f));
            lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DotLine);
            {
                //Z
                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(0, 0, -1000), new Vector3(0, 0, 1000));
                lineNode.SetLineStyle(lineStyle);
                gridNode.AddNode(lineNode);
            }
            {
                //X
                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(-1000, 0, 0), new Vector3(1000, 0, 0));
                lineNode.SetLineStyle(lineStyle);
                gridNode.AddNode(lineNode);
            }
            {
                //Y
                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(0, -1000, 0), new Vector3(0, 1000, 0));
                lineNode.SetLineStyle(lineStyle);
                gridNode.AddNode(lineNode);
            }

            lineStyle = new LineStyle();
            lineStyle.SetColor(new ColorValue(0.9f, 0.9f, 0.9f));
            gridNode.SetLineStyle(lineStyle);
            for (int ii = -1; ii <= nCountX; ++ii)
            {
                if (ii == 0)
                    continue;

                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(ii * cellSize.X, cellSize.Y, 0), new Vector3(ii * cellSize.X, -nCountY * cellSize.Y, 0));

                gridNode.AddNode(lineNode);
            }
            for (int ii = -1; ii <= nCountY; ++ii)
            {
                if (ii == 0)
                    continue;

                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(-cellSize.X, -ii * cellSize.Y, 0), new Vector3(nCountX * cellSize.X, -ii * cellSize.Y, 0));
                gridNode.AddNode(lineNode);
            }
            gridNode.Update();
            wp.SetGridNode(gridNode);



            {
                AxesWidget xwh = new AxesWidget();
                xwh.EnableLeftHandCS();
                xwh.SetArrowText((int)EnumAxesDirection.Axes_Y, "w");
                xwh.SetArrowText((int)EnumAxesDirection.Axes_Z, "h");
                ScreenWidget coordWidget = new ScreenWidget();
                coordWidget.SetNode(xwh);
                coordWidget.SetWidgetPosition((int)EnumWidgetPosition.WP_BottomLeft);
                renderView.Renderer.AddWidgetNode(coordWidget);
            }
            {
                AxesWidget yz = new AxesWidget();
                yz.ShowArrow((int)EnumAxesDirection.Axes_X, false);
                ScreenWidget coordWidget = new ScreenWidget();
                coordWidget.SetNode(yz);
                coordWidget.SetWidgetPosition((int)EnumWidgetPosition.WP_BottomRight);
                renderView.Renderer.AddWidgetNode(coordWidget);
            }

            renderView.ShowCoordinateAxis(false);

            renderView.RequestDraw();
        }
Exemplo n.º 15
0
        private void surfaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LineStyle lineStyle = new LineStyle();

            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.RED);

            Vector3List points = new Vector3List();

            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(50, 0, 0));
            points.Add(new Vector3(100, 0, 0));

            points.Add(new Vector3(0, 50, 0));
            points.Add(new Vector3(50, 50, 5));
            points.Add(new Vector3(100, 50, -5));

            points.Add(new Vector3(0, 150, 5));
            points.Add(new Vector3(50, 150, -5));
            points.Add(new Vector3(100, 150, 0));

            TopoShape face = GlobalInstance.BrepTools.MakeSurfaceFromPoints(points, 3, 3);

            renderView.ShowGeometry(face, ++shapeId);

            GeomeSurface surface = new GeomeSurface();

            surface.Initialize(face);
            float ufirst = surface.FirstUParameter();
            float uLarst = surface.LastUParameter();
            float vfirst = surface.FirstVParameter();
            float vLast  = surface.LastVParameter();

            float ustep = (uLarst - ufirst) * 0.1f;
            float vstep = (vLast - vfirst) * 0.1f;

            for (float ii = ufirst; ii <= uLarst; ii += ustep)
            {
                for (float jj = vfirst; jj <= vLast; jj += vstep)
                {
                    Vector3List data = surface.D1(ii, jj);

                    Vector3 pos  = data.Get(0);
                    Vector3 dirU = data.Get(1);
                    Vector3 dirV = data.Get(2);
                    Vector3 dir  = dirV.CrossProduct(dirU);
                    dir.Normalize();
                    {
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir * 10.0f);
                        SceneNode node = renderView.ShowGeometry(line, ++shapeId);

                        node.SetLineStyle(lineStyle);
                    }
                }
            }

            TopoShapeProperty property = new TopoShapeProperty();

            property.SetShape(face);

            float area = property.SurfaceArea();

            TextNode text = new TextNode();

            text.SetText(String.Format("Surface Area: {0}", area));
            text.SetPosition(new Vector3(100, 100, 0));
            renderView.SceneManager.ClearNodes2d();
            renderView.SceneManager.AddNode2d(text);

            renderView.RequestDraw();
        }
Exemplo n.º 16
0
        private void curveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            renderView.View3d.SetStandardView(3);

            LineStyle lineStyle = new LineStyle();

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

            lineStyle2.SetLineWidth(0.5f);
            lineStyle2.SetColor(ColorValue.GREEN);

            TopoShape arc = GlobalInstance.BrepTools.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z);

            renderView.ShowGeometry(arc, ++shapeId);

            {
                GeomeCurve curve = new GeomeCurve();
                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);

                    // 切线
                    {
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dir);
                        SceneNode node = renderView.ShowGeometry(line, ++shapeId);
                        node.SetLineStyle(lineStyle);
                    }
                    // 法线
                    {
                        Vector3   dirN = dir.CrossProduct(Vector3.UNIT_Z);
                        TopoShape line = GlobalInstance.BrepTools.MakeLine(pos, pos + dirN);
                        SceneNode node = renderView.ShowGeometry(line, ++shapeId);
                        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();
        }
Exemplo n.º 17
0
        public void UpdateWorkingGrid()
        {
            m_RenderView.SceneManager.ComputeBBox();

            WorkingPlane wp = m_RenderView.Renderer.GetWorkingPlane();

            GridNode gridNode  = new GridNode();
            Vector3  modelSize = m_RenderView.SceneManager.GetBBox().Size();
            Vector2  cellSize  = gridNode.GetCellSize();
            int      nCountX   = (int)(modelSize.X / cellSize.X + 0.5f) + 1;
            int      nCountY   = (int)(modelSize.Y / cellSize.Y + 0.5f) + 1;

            if (nCountX < 2)
            {
                nCountX = 2;
            }
            if (nCountY < 2)
            {
                nCountY = 2;
            }

            gridNode.SetCellCount(nCountX, nCountY);

            LineStyle lineStyle = new LineStyle();

            lineStyle.SetColor(new ColorValue(1.0f, 1.0f, 1.0f));
            lineStyle.SetPatternStyle((int)EnumLinePattern.LP_DotLine);
            {
                //Z
                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(0, 0, -1000), new Vector3(0, 0, 1000));
                lineNode.SetLineStyle(lineStyle);
                gridNode.AddNode(lineNode);
            }
            {
                //X
                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(-1000, 0, 0), new Vector3(1000, 0, 0));
                lineNode.SetLineStyle(lineStyle);
                gridNode.AddNode(lineNode);
            }
            {
                //Y
                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(0, -1000, 0), new Vector3(0, 1000, 0));
                lineNode.SetLineStyle(lineStyle);
                gridNode.AddNode(lineNode);
            }

            lineStyle = new LineStyle();
            lineStyle.SetColor(new ColorValue(0.9f, 0.9f, 0.9f));
            gridNode.SetLineStyle(lineStyle);
            for (int ii = -1; ii <= nCountX; ++ii)
            {
                if (ii == 0)
                {
                    continue;
                }

                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(ii * cellSize.X, cellSize.Y, 0), new Vector3(ii * cellSize.X, -nCountY * cellSize.Y, 0));

                gridNode.AddNode(lineNode);
            }
            for (int ii = -1; ii <= nCountY; ++ii)
            {
                if (ii == 0)
                {
                    continue;
                }

                LineNode lineNode = new LineNode();
                lineNode.Set(new Vector3(-cellSize.X, -ii * cellSize.Y, 0), new Vector3(nCountX * cellSize.X, -ii * cellSize.Y, 0));
                gridNode.AddNode(lineNode);
            }
            gridNode.Update();
            wp.SetGridNode(gridNode);
            m_RenderView.ShowWorkingGrid(true);
        }
Exemplo n.º 18
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());
                //...
            }
        }
Exemplo n.º 19
0
        private void sectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // build two surfaces
            TopoShape arc = GlobalInstance.BrepTools.MakeArc(Vector3.ZERO, 100, 0, 135, Vector3.UNIT_Z);
            TopoShape cir = GlobalInstance.BrepTools.MakeCircle(new Vector3(-200,0,0), 50, Vector3.UNIT_X);
            TopoShape surf1 = GlobalInstance.BrepTools.Extrude(arc, 100, Vector3.UNIT_Z);
            TopoShape surf2 = GlobalInstance.BrepTools.Extrude(cir, 400, Vector3.UNIT_X);

            renderView.ShowGeometry(surf1, ++shapeId);
            //renderView.ShowGeometry(surf2, ++shapeId);

            // compute section wire
            TopoShape wire = GlobalInstance.BrepTools.SurfaceSection(surf1, surf2);
            if (wire == null)
                return;


            SceneNode sectionNode = renderView.ShowGeometry(wire, ++shapeId);
            LineStyle lineStyle = new LineStyle();
            lineStyle.SetLineWidth(4);
            lineStyle.SetColor(ColorValue.RED);
            sectionNode.SetLineStyle(lineStyle);
       
            renderView.RequestDraw();
        }
Exemplo n.º 20
0
        private void planeAngleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // plane
            Vector3 planeDir = Vector3.UNIT_Z;
            TopoShape plane1 = GlobalInstance.BrepTools.MakePlaneFace(Vector3.ZERO, planeDir, -100, 100, -100, 100);

            {
                GeomSurface gs = new GeomSurface();
                gs.Initialize(plane1);
                List<Vector3> rst = gs.D1(gs.FirstUParameter(), gs.FirstVParameter());
                Vector3 dir2 = rst[1].CrossProduct(rst[2]);

                MessageBox.Show(dir2.ToString());
            }
    

            Vector3 normal = new Vector3(0,1,1);
            normal.Normalize();
            TopoShape plane2 = GlobalInstance.BrepTools.MakePlaneFace(Vector3.ZERO, normal, -100, 100, -100, 100);

            renderView.ShowGeometry(plane1, ++shapeId);
            renderView.ShowGeometry(plane2, ++shapeId);

            LineStyle style = new LineStyle();
            style.SetColor(ColorValue.GREEN);
            // witness
            Vector3 end1 =  new Vector3(0, 0, 100);
            LineNode line1 = new LineNode();
            line1.Set(Vector3.ZERO, end1);
            line1.SetLineStyle(style);
            renderView.ShowSceneNode(line1);

            Vector3 end2 = normal * 100;
            LineNode line2 = new LineNode();
            line2.Set(Vector3.ZERO, end2);
            line2.SetLineStyle(style);
            renderView.ShowSceneNode(line2);

            // angle
            float angle = normal.AngleBetween(planeDir);

            Vector3 dir = normal.CrossProduct(planeDir);
            dir.Normalize();
            TopoShape arc = GlobalInstance.BrepTools.MakeArc(end2, end1, Vector3.ZERO, dir);
            SceneNode arcNode = renderView.ShowGeometry(arc, ++shapeId);
            arcNode.SetLineStyle(style);

            // text
            TextNode text = new TextNode();
            text.SetText(angle.ToString());
            Vector3 pos = end2 + end1;
            pos = pos * 0.5f;
            text.SetPosition(pos);
            renderView.ShowSceneNode(text);

            renderView.RequestDraw();
        }
Exemplo n.º 21
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();
        }