Пример #1
0
        private void WriteNurbsCurve(NurbsCurve nurbsCurve)
        {
            if (this.activeSection != StringCode.EntitiesSection && !this.isBlockEntities)
            {
                throw new InvalidDxfSectionException(this.activeSection, this.file);
            }

            //we will draw the nurbsCurve as a polyline, it is not supported in AutoCad12 dxf files
            this.WriteCodePair(0, DxfObjectCode.Polyline);

            this.WriteEntityCommonCodes(nurbsCurve);

            //open polyline
            this.WriteCodePair(70, 0);

            //dummy point
            this.WriteCodePair(10, 0.0);
            this.WriteCodePair(20, 0.0);
            this.WriteCodePair(30, nurbsCurve.Elevation);

            this.WriteCodePair(39, nurbsCurve.Thickness);

            this.WriteCodePair(210, nurbsCurve.Normal.X);
            this.WriteCodePair(220, nurbsCurve.Normal.Y);
            this.WriteCodePair(230, nurbsCurve.Normal.Z);

            //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
            //but its needed to load the dxf file in AutoCAD
            this.WriteCodePair(66, "1");

            this.WriteXData(nurbsCurve.XData);

            List<Vector2d> points = nurbsCurve.PolygonalVertexes(nurbsCurve.CurvePoints);
            foreach (Vector2d v in points)
            {
                this.WriteCodePair(0, DxfObjectCode.Vertex);
                this.WriteCodePair(8, nurbsCurve.Layer);
                this.WriteCodePair(70, 0);
                this.WriteCodePair(10, v.X);
                this.WriteCodePair(20, v.Y);
            }
            this.WriteCodePair(0, StringCode.EndSequence);
        }
Пример #2
0
        private static void NurbsCurve()
        {
            DxfDocument dxf = new DxfDocument();

            NurbsCurve nurbs  = new NurbsCurve();
            nurbs.ControlPoints .Add(new NurbsVertex( 0, 0));
            nurbs.ControlPoints.Add(new NurbsVertex(10, 10));
            nurbs.ControlPoints.Add(new NurbsVertex(20, 0));
            nurbs.ControlPoints.Add(new NurbsVertex(30, 10));
            nurbs.ControlPoints.Add(new NurbsVertex(40, 0));
            nurbs.ControlPoints.Add(new NurbsVertex(50, 10));
            nurbs.ControlPoints.Add(new NurbsVertex(60, 0));
            nurbs.ControlPoints.Add(new NurbsVertex(70, 10));

            nurbs.Order = 3;

               dxf.AddEntity(nurbs);

               NurbsCurve nurbs2 = new NurbsCurve();
               nurbs2.ControlPoints.Add(new NurbsVertex(5, 0));
               nurbs2.ControlPoints.Add(new NurbsVertex(10, 0));
               nurbs2.ControlPoints.Add(new NurbsVertex(10, 5));
               nurbs2.ControlPoints.Add(new NurbsVertex(10, 10));
               nurbs2.ControlPoints.Add(new NurbsVertex(5, 10));
               nurbs2.ControlPoints.Add(new NurbsVertex(0, 10));
               nurbs2.ControlPoints.Add(new NurbsVertex(0, 5));
               nurbs2.ControlPoints.Add(new NurbsVertex(0, 0));
               nurbs2.ControlPoints.Add(new NurbsVertex(5, 0));

               nurbs2.Order = 3;

               nurbs2.SetUniformWeights((float)Math.Cos(MathHelper.HalfPI));
               dxf.AddEntity(nurbs2);

            dxf.Save("nurbs.dxf", DxfVersion.AutoCad12);
        }