private static void WriteDxfFile()
        {
            DxfDocument dxf = new DxfDocument();

            //arc
            Arc arc = new Arc(new Vector3(10, 10, 0), 10, 45, 135);
            arc.Layer = new Layer("arc");
            arc.Layer.Color.Index = 1;
            dxf.AddEntity(arc);

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            XData xdata2 = new XData(new ApplicationRegistry("other application"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            //circle
            Vector3 extrusion = new Vector3(1, 1, 1);
            Vector3 centerWCS = new Vector3(1, 1, 1);
            Vector3 centerOCS = MathHelper.Transform(centerWCS,
                                                        extrusion,
                                                        CoordinateSystem.World,
                                                        CoordinateSystem.Object);

            Circle circle = new Circle(centerOCS, 5);
            circle.Layer = new Layer("circle with spaces");
            circle.Layer.Color=AciColor.Yellow;
            circle.LineType = LineType.Dashed;
            circle.Normal = extrusion;
            circle.XData.Add(xdata);
            circle.XData.Add(xdata2);

            dxf.AddEntity(circle);

            //points
            Point point1 = new Point(new Vector3(-3, -3, 0));
            point1.Layer = new Layer("point");
            point1.Color = new AciColor(30);
            Point point2 = new Point(new Vector3(1, 1, 1));
            point2.Layer = point1.Layer;
            point2.Layer.Color.Index = 9;
            point2.Normal = new Vector3(1, 1, 1);
            dxf.AddEntity(point1);
            dxf.AddEntity(point2);

            //3dface
            Face3d face3D = new Face3d(new Vector3(-5, -5, 5),
                                        new Vector3(5, -5, 5),
                                        new Vector3(5, 5, 5),
                                        new Vector3(-5, 5, 5));
            face3D.Layer = new Layer("3dface");
            face3D.Layer.Color.Index = 3;
            dxf.AddEntity(face3D);
            
            //polyline
            LwPolylineVertex polyVertex;
            List<LwPolylineVertex> polyVertexes = new List<LwPolylineVertex>();
            polyVertex = new LwPolylineVertex(new Vector2(-50, -50));
            polyVertex.StartWidth = 2;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(50, -50));
            polyVertex.StartWidth = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(50, 50));
            polyVertex.Bulge = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(-50, 50));
            polyVertexes.Add(polyVertex);
            LwPolyline polyline2d = new LwPolyline(polyVertexes, true);
            polyline2d.Layer = new Layer("polyline2d");
            polyline2d.Layer.Color.Index = 5;
            polyline2d.Normal = new Vector3(1, 1, 1);
            polyline2d.Elevation = 100.0f;
            dxf.AddEntity(polyline2d);

            //lightweight polyline
            LwPolylineVertex lwVertex;
            List<LwPolylineVertex> lwVertexes = new List<LwPolylineVertex>();
            lwVertex = new LwPolylineVertex(new Vector2(-25, -25));
            lwVertex.StartWidth = 2;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(25, -25));
            lwVertex.StartWidth = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(25, 25));
            lwVertex.Bulge = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(-25, 25));
            lwVertexes.Add(lwVertex);
            LwPolyline lwPolyline = new LwPolyline(lwVertexes, true);
            lwPolyline.Layer = new Layer("lwpolyline");
            lwPolyline.Layer.Color.Index = 5;
            lwPolyline.Normal = new Vector3(1, 1, 1);
            lwPolyline.Elevation = 100.0f;
            dxf.AddEntity(lwPolyline);

            // polyfaceMesh
            List<PolyfaceMeshVertex> meshVertexes = new List<PolyfaceMeshVertex>
                                                    {
                                                        new PolyfaceMeshVertex(0, 0, 0),
                                                        new PolyfaceMeshVertex(10, 0, 0),
                                                        new PolyfaceMeshVertex(10, 10, 0),
                                                        new PolyfaceMeshVertex(5, 15, 0),
                                                        new PolyfaceMeshVertex(0, 10, 0)
                                                    };
            List<PolyfaceMeshFace> faces = new List<PolyfaceMeshFace>
                                                {
                                                    new PolyfaceMeshFace(new short[] {1, 2, -3}),
                                                    new PolyfaceMeshFace(new short[] {-1, 3, -4}),
                                                    new PolyfaceMeshFace(new short[] {-1, 4, 5})
                                                };

            PolyfaceMesh mesh = new PolyfaceMesh(meshVertexes, faces);
            mesh.Layer = new Layer("polyfacemesh");
            mesh.Layer.Color.Index = 104;
            dxf.AddEntity(mesh);

            //line
            Line line = new Line(new Vector3(0, 0, 0), new Vector3(10, 10, 10));
            line.Layer = new Layer("line");
            line.Layer.Color.Index = 6;
            dxf.AddEntity(line);

            //3d polyline
            PolylineVertex vertex;
            List<PolylineVertex> vertexes = new List<PolylineVertex>();
            vertex = new PolylineVertex(new Vector3(-50, -50, 0));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(50, -50, 10));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(50, 50, 25));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(-50, 50, 50));
            vertexes.Add(vertex);
            Polyline polyline = new Polyline(vertexes, true);
            polyline.Layer = new Layer("polyline3d");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            //block definition
            Block block = new Block("TestBlock");
            block.Entities.Add(new Line(new Vector3(-5, -5, 5), new Vector3(5, 5, 5)));
            block.Entities.Add(new Line(new Vector3(5, -5, 5), new Vector3(-5, 5, 5)));
           
            //insert
            Insert insert = new Insert(block, new Vector3(5, 5, 5));
            insert.Layer = new Layer("insert");
            insert.Layer.Color.Index = 4;
            dxf.AddEntity(insert);

            //text
            TextStyle style=new TextStyle("True type font","Arial.ttf");
            Text text = new Text("Hello world!", Vector3.Zero, 10.0f,style);
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopRight;
            dxf.AddEntity(text);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("AutoCad2010.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save("AutoCad2007.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("AutoCad2004.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000;
            dxf.Save("AutoCad2000.dxf");
            dxf = DxfDocument.Load("AutoCad2000.dxf");
            dxf.Save("AutoCad2000 result.dxf");
        }
Example #2
0
        void ReadArc(netDxf.Entities.Arc arc, double x, double y)
        {
            // TODO :
            var point0 = CreateHiddenPoint(arc.Center.X + x, arc.Center.Y + y);

            var aPoint1 = CreateHiddenPoint(point0.X + arc.Radius * System.Math.Cos(System.Math.PI / 180 * arc.StartAngle), point0.Y + arc.Radius * System.Math.Sin(System.Math.PI / 180 * arc.StartAngle));
            var point1  = compareFreePoints(this.drawing.Figures, aPoint1);

            if (point1 == null)
            {
                point1 = aPoint1;
                this.drawing.Figures.Add(point1);
            }
            var aPoint2 = CreateHiddenPoint(point0.X + arc.Radius * System.Math.Cos(System.Math.PI / 180 * arc.EndAngle), point0.Y + arc.Radius * System.Math.Sin(System.Math.PI / 180 * arc.EndAngle));
            var point2  = compareFreePoints(this.drawing.Figures, aPoint2);

            if (point2 == null)
            {
                point2 = aPoint2;
                this.drawing.Figures.Add(point2);
            }
            var figure = Factory.CreateArc(drawing, new[] { point0, point1, point2 });

            Actions.Add(drawing, figure);
        }
Example #3
0
 private EntityObject ExportEllipse(GeoObject.Ellipse elli)
 {
     netDxf.Entities.EntityObject entity = null;
     if (elli.IsArc)
     {
         Plane dxfPlane;
         if (elli.CounterClockWise)
         {
             dxfPlane = Import.Plane(Vector3(elli.Center), Vector3(elli.Plane.Normal));
         }
         else
         {
             dxfPlane = Import.Plane(Vector3(elli.Center), Vector3(-elli.Plane.Normal));
         }
         if (elli.IsCircle)
         {
             GeoObject.Ellipse aligned = GeoObject.Ellipse.Construct();
             aligned.SetArcPlaneCenterStartEndPoint(dxfPlane, dxfPlane.Project(elli.Center), dxfPlane.Project(elli.StartPoint), dxfPlane.Project(elli.EndPoint), dxfPlane, true);
             entity        = new netDxf.Entities.Arc(Vector3(aligned.Center), aligned.Radius, aligned.StartParameter / Math.PI * 180, (aligned.StartParameter + aligned.SweepParameter) / Math.PI * 180);
             entity.Normal = Vector3(dxfPlane.Normal);
         }
         else
         {
             netDxf.Entities.Ellipse expelli = new netDxf.Entities.Ellipse(Vector3(elli.Center), 2 * elli.MajorRadius, 2 * elli.MinorRadius);
             entity        = expelli;
             entity.Normal = Vector3(elli.Plane.Normal);
             Plane       cdbplane = elli.Plane;
             GeoVector2D dir      = dxfPlane.Project(cdbplane.DirectionX);
             SweepAngle  rot      = new SweepAngle(GeoVector2D.XAxis, dir);
             expelli.Rotation = rot.Degree;
             SetEllipseParameters(expelli, elli.StartParameter, elli.StartParameter + elli.SweepParameter);
         }
     }
     else
     {
         if (elli.IsCircle)
         {
             entity        = new netDxf.Entities.Circle(Vector3(elli.Center), elli.Radius);
             entity.Normal = Vector3(elli.Plane.Normal);
         }
         else
         {
             netDxf.Entities.Ellipse expelli = new netDxf.Entities.Ellipse(Vector3(elli.Center), 2 * elli.MajorRadius, 2 * elli.MinorRadius);
             entity        = expelli;
             entity.Normal = Vector3(elli.Plane.Normal);
             Plane       dxfplane = Import.Plane(expelli.Center, expelli.Normal); // this plane is not correct, it has to be rotated
             Plane       cdbplane = elli.Plane;
             GeoVector2D dir      = dxfplane.Project(cdbplane.DirectionX);
             SweepAngle  rot      = new SweepAngle(GeoVector2D.XAxis, dir);
             expelli.Rotation = rot.Degree;
         }
     }
     return(entity);
 }
Example #4
0
        public Arc(netDxf.Entities.Arc inputArc)
        {
            InputArc = inputArc;


            var startPoint = new Point();

            startPoint.X = inputArc.Radius * Math.Cos(Math.PI * inputArc.StartAngle / 180) + inputArc.Center.X;
            startPoint.Y = inputArc.Radius * Math.Sin(Math.PI * inputArc.StartAngle / 180) + inputArc.Center.Y;

            if (angleSubtract(inputArc.EndAngle, inputArc.StartAngle) > 180)
            {
                Length = 2 * Math.PI * inputArc.Radius * angleSubtract(inputArc.EndAngle, inputArc.StartAngle) / 360;
            }
            else
            {
                Length = 2 * Math.PI * inputArc.Radius * angleSubtract(inputArc.EndAngle, inputArc.StartAngle) / 360;
            }


            MinXMinY = new Vector3(
                Math.Cos(Math.PI * inputArc.StartAngle / 180) * inputArc.Radius + inputArc.Center.X,
                Math.Sin(Math.PI * inputArc.StartAngle / 180) * inputArc.Radius + inputArc.Center.Y, 0);
            MaxXMaxY = MinXMinY;
            if (angleSubtract(inputArc.EndAngle, inputArc.StartAngle) > 180)
            {
                for (double i = 0; i < Math.Ceiling(Length); i += 0.5)
                {
                    var tempX = Math.Cos(Math.PI * (inputArc.StartAngle +
                                                    i * angleSubtract(inputArc.EndAngle, inputArc.StartAngle) / Length
                                                    ) / 180) * inputArc.Radius + inputArc.Center.X;
                    var tempY = Math.Sin(Math.PI * (inputArc.StartAngle +
                                                    i * angleSubtract(inputArc.EndAngle, inputArc.StartAngle) / Length
                                                    ) / 180) * inputArc.Radius + inputArc.Center.Y;
                    CheckIfNewPointExtendArea(new Vector3(tempX, tempY, 0));
                }
            }
            else
            {
                for (double i = 0; i < Math.Ceiling(Length); i += 0.5)
                {
                    var tempX = Math.Cos(Math.PI * (inputArc.StartAngle +
                                                    i * angleSubtract(inputArc.EndAngle, inputArc.StartAngle) / Length
                                                    ) / 180) * inputArc.Radius + inputArc.Center.X;
                    var tempY = Math.Sin(Math.PI * (inputArc.StartAngle +
                                                    i * angleSubtract(inputArc.EndAngle, inputArc.StartAngle) / Length
                                                    ) / 180) * inputArc.Radius + inputArc.Center.Y;
                    CheckIfNewPointExtendArea(new Vector3(tempX, tempY, 0));
                }
            }

            MinXMinY.Y -= 1;
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <c>RadialDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="rotation">Rotation in degrees of the dimension line.</param>
 /// <param name="offset">Distance between the reference point and the dimension text</param>
 /// <param name="style">The <see cref="DimensionStyle">style</see> to use with the dimension.</param>
 /// <remarks>The center point and the definition point define the distance to be measure.</remarks>
 public RadialDimension(Arc arc, double rotation, double offset, DimensionStyle style)
     : base(DimensionType.Radius)
 {
     double angle = rotation * MathHelper.DegToRad;
     Vector3 point = MathHelper.Transform(new Vector3(arc.Radius * Math.Sin(angle), arc.Radius * Math.Cos(angle), 0.0), arc.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);
     this.center = arc.Center;
     this.refPoint = arc.Center + point;
     this.offset = offset;
     if (style == null)
         throw new ArgumentNullException("style", "The Dimension style cannot be null.");
     this.style = style;
 }
Example #6
0
    void AddArc(netDxf.Entities.Arc a)
    {
        var   c   = new UnityEngine.Vector3((float)a.Center.X, (float)a.Center.Y, (float)a.Center.Z);
        var   e   = a.StartAngle;
        float sa  = (float)a.StartAngle * Mathf.Deg2Rad;
        float ea  = (float)a.EndAngle * Mathf.Deg2Rad;
        float r   = (float)a.Radius;
        var   rvs = new UnityEngine.Vector3(r * Mathf.Cos(sa), r * Mathf.Sin(sa), c.z) + c;
        var   rve = new UnityEngine.Vector3(r * Mathf.Cos(ea), r * Mathf.Sin(ea), c.z) + c;

        ArcEntity arc = new ArcEntity(DetailEditor.instance.currentSketch.GetSketch());

        arc.c.SetPosition(c);
        arc.p0.SetPosition(rvs);
        arc.p1.SetPosition(rve);
    }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <c>DiametricDimension</c> class.
        /// </summary>
        /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
        /// <param name="rotation">Rotation in degrees of the dimension line.</param>
        /// <param name="offset">Distance between the reference point and the dimension text</param>
        /// <param name="style">The <see cref="DimensionStyle">style</see> to use with the dimension.</param>
        /// <remarks>The center point and the definition point define the distance to be measure.</remarks>
        public DiametricDimension(Arc arc, double rotation, double offset, DimensionStyle style)
            : base(DimensionType.Diameter)
        {
            if (arc == null)
                throw new ArgumentNullException(nameof(arc));

            Vector3 ocsCenter = MathHelper.Transform(arc.Center, arc.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            this.center = new Vector2(ocsCenter.X, ocsCenter.Y);
            this.refPoint = Vector2.Polar(this.center, arc.Radius, rotation*MathHelper.DegToRad);
            this.offset = offset;

            if (style == null)
                throw new ArgumentNullException(nameof(style));
            this.Style = style;
            this.Normal = arc.Normal;
            this.Elevation = ocsCenter.Z;
        }
Example #8
0
        public Path GetCanvasArc(netDxf.Entities.Arc arc, Vector3 startVector, double canvasHeight)
        {
            var startPoint = new Point();

            startPoint.X = arc.Radius * Math.Cos(Math.PI * arc.StartAngle / 180) + arc.Center.X - startVector.X;
            startPoint.Y = -arc.Radius * Math.Sin(Math.PI * arc.StartAngle / 180) - arc.Center.Y + canvasHeight +
                           startVector.Y;

            var endPoint = new Point();

            endPoint.X = arc.Radius * Math.Cos(Math.PI * arc.EndAngle / 180) + arc.Center.X - startVector.X;
            endPoint.Y = -arc.Radius * Math.Sin(Math.PI * arc.EndAngle / 180) - arc.Center.Y + canvasHeight +
                         startVector.Y;

            var g = new StreamGeometry();
            StreamGeometryContext gc;

            using (gc = g.Open())
            {
                gc.BeginFigure(
                    startPoint,
                    false,
                    false);

                gc.ArcTo(
                    endPoint,
                    new Size(arc.Radius, arc.Radius),
                    180d,
                    angleSubtract(arc.EndAngle, arc.StartAngle) > 180,
                    SweepDirection.Counterclockwise,
                    true,
                    false);
            }

            var path = new Path
            {
                Stroke          = Brushes.Black,
                StrokeThickness = 1,
                Data            = g
            };


            return(path);
        }
Example #9
0
 /// <summary>
 /// Convert a Nucleus arc to a netDXF one
 /// </summary>
 /// <param name="arc"></param>
 /// <returns></returns>
 public static nDE.EntityObject Convert(Arc arc)
 {
     if (arc.Closed)
     {
         var result = new nDE.Circle(Convert(arc.Circle.Origin), arc.Circle.Radius * ConversionScaling);
         result.Normal = Convert(arc.Circle.L, 1);
         SetAttributes(result, arc.Attributes);
         return(result);
     }
     else
     {
         Plane plane  = new Plane(arc.Circle.Origin, arc.Circle.L);
         var   result = new nDE.Arc(Convert(arc.Circle.Origin), arc.Circle.Radius * ConversionScaling,
                                    plane.GlobalToLocal(arc.StartPoint).Angle.Degrees, plane.GlobalToLocal(arc.EndPoint).Angle.Degrees);
         result.Normal = Convert(plane.Z, 1);
         SetAttributes(result, arc.Attributes);
         return(result);
     }
 }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <c>Angular3PointDimension</c> class.
        /// </summary>
        /// <param name="arc">Angle <see cref="Arc">arc</see> to measure.</param>
        /// <param name="offset">Distance between the center of the arc and the dimension line.</param>
        /// <param name="style">The <see cref="DimensionStyle">style</see> to use with the dimension.</param>
        public Angular3PointDimension(Arc arc, double offset, DimensionStyle style)
            : base(DimensionType.Angular3Point)
        {
            if (arc == null)
                throw new ArgumentNullException(nameof(arc));

            Vector3 refPoint = MathHelper.Transform(arc.Center, arc.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            this.center = new Vector2(refPoint.X, refPoint.Y);
            this.start = Vector2.Polar(this.center, arc.Radius, arc.StartAngle*MathHelper.DegToRad);
            this.end = Vector2.Polar(this.center, arc.Radius, arc.EndAngle*MathHelper.DegToRad);

            if (MathHelper.IsZero(offset))
                throw new ArgumentOutOfRangeException(nameof(offset), "The offset value cannot be zero.");
            this.offset = offset;

            if (style == null)
                throw new ArgumentNullException(nameof(style));
            this.Style = style;
            this.Normal = arc.Normal;
            this.Elevation = refPoint.Z;
        }
        /// <summary>
        /// Initializes a new instance of the <c>Angular3PointDimension</c> class.
        /// </summary>
        /// <param name="arc">Angle <see cref="Arc">arc</see> to measure.</param>
        /// <param name="offset">Distance between the center of the arc and the dimension line.</param>
        /// <param name="style">The <see cref="DimensionStyle">style</see> to use with the dimension.</param>
        public Angular3PointDimension(Arc arc, double offset, DimensionStyle style)
            : base(DimensionType.Angular3Point)
        {
            this.center = arc.Center;

            Vector3 refPoint = MathHelper.Transform(arc.Center, arc.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);

            Vector2 centerRef = new Vector2(refPoint.X, refPoint.Y);
            double elev = refPoint.Z;

            Vector2 ref1 = Vector2.Polar(centerRef, arc.Radius, arc.StartAngle * MathHelper.DegToRad);
            this.start = MathHelper.Transform(new Vector3(ref1.X, ref1.Y, elev), arc.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);

            Vector2 ref2 = Vector2.Polar(centerRef, arc.Radius, arc.EndAngle * MathHelper.DegToRad);
            this.end = MathHelper.Transform(new Vector3(ref2.X, ref2.Y, elev), arc.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);

            if (MathHelper.IsZero(offset))
                throw new ArgumentOutOfRangeException("offset", "The offset value cannot be zero.");
            this.offset = offset;

            if (style == null)
                throw new ArgumentNullException("style", "The Dimension style cannot be null.");
            this.style = style;      
        }
 /// <summary>
 /// Initializes a new instance of the <c>Angular3PointDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="offset">Distance between the center of the arc and the dimension line.</param>
 public Angular3PointDimension(Arc arc, double offset)
     : this(arc, offset, DimensionStyle.Default)
 {
 }
Example #13
0
        private static void WriteDxfFile()
        {
            DxfDocument dxf = new DxfDocument();

            //arc
            Arc arc = new Arc(new Vector3d(10, 10, 0), 10, 45, 135);
            arc.Layer = new Layer("arc");
            arc.Layer.Color.Index = 1;
            dxf.AddEntity(arc);

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            XData xdata2 = new XData(new ApplicationRegistry("other application"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Long, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            //circle
            Vector3d extrusion = new Vector3d(1, 1, 1);
            Vector3d centerWCS = new Vector3d(1, 1, 1);
            Vector3d centerOCS = MathHelper.Transform(centerWCS,
                                                      extrusion,
                                                      MathHelper.CoordinateSystem.World,
                                                      MathHelper.CoordinateSystem.Object);

            Circle circle = new Circle(centerOCS, 5);
            circle.Layer = new Layer("circle with spaces");
            circle.Layer.Color=AciColor.Yellow;
            circle.LineType = LineType.Dashed;
            circle.Normal = extrusion;
            circle.XData=new Dictionary<ApplicationRegistry, XData>
                             {
                                 {xdata.ApplicationRegistry, xdata},
                                 {xdata2.ApplicationRegistry, xdata2}
                             };

            dxf.AddEntity(circle);

            //points
            Point point1 = new Point(new Vector3d(-3, -3, 0));
            point1.Layer = new Layer("point");
            point1.Color = new AciColor(30);
            Point point2 = new Point(new Vector3d(1, 1, 1));
            point2.Layer = point1.Layer;
            point2.Layer.Color.Index = 9;
            point2.Normal = new Vector3d(1, 1, 1);
            dxf.AddEntity(point1);
            dxf.AddEntity(point2);

            //3dface
            Face3d face3D = new Face3d(new Vector3d(-5, -5, 5),
                                       new Vector3d(5, -5, 5),
                                       new Vector3d(5, 5, 5),
                                       new Vector3d(-5, 5, 5));
            face3D.Layer = new Layer("3dface");
            face3D.Layer.Color.Index = 3;
            dxf.AddEntity(face3D);

            //polyline
            PolylineVertex polyVertex;
            List<PolylineVertex> polyVertexes = new List<PolylineVertex>();
            polyVertex = new PolylineVertex(new Vector2d(-50, -50));
            polyVertex.BeginThickness = 2;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(50, -50));
            polyVertex.BeginThickness = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(50, 50));
            polyVertex.Bulge = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(-50, 50));
            polyVertexes.Add(polyVertex);
            Polyline polyline2d = new Polyline(polyVertexes, true);
            polyline2d.Layer = new Layer("polyline2d");
            polyline2d.Layer.Color.Index = 5;
            polyline2d.Normal = new Vector3d(1, 1, 1);
            polyline2d.Elevation = 100.0;
            dxf.AddEntity(polyline2d);

            //lightweight polyline
            LightWeightPolylineVertex lwVertex;
            List<LightWeightPolylineVertex> lwVertexes = new List<LightWeightPolylineVertex>();
            lwVertex = new LightWeightPolylineVertex(new Vector2d(-25, -25));
            lwVertex.BeginThickness = 2;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(25, -25));
            lwVertex.BeginThickness = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(25, 25));
            lwVertex.Bulge = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(-25, 25));
            lwVertexes.Add(lwVertex);
            LightWeightPolyline lwPolyline = new LightWeightPolyline(lwVertexes, true);
            lwPolyline.Layer = new Layer("lwpolyline");
            lwPolyline.Layer.Color.Index = 5;
            lwPolyline.Normal = new Vector3d(1, 1, 1);
            lwPolyline.Elevation = 100.0;
            dxf.AddEntity(lwPolyline);

            //line
            Line line = new Line(new Vector3d(0, 0, 0), new Vector3d(10, 10, 10));
            line.Layer = new Layer("line");
            line.Layer.Color.Index = 6;
            dxf.AddEntity(line);

            //3d polyline
            Polyline3dVertex vertex;
            List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>();
            vertex = new Polyline3dVertex(new Vector3d(-50, -50, 0));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(50, -50, 10));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(50, 50, 25));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(-50, 50, 50));
            vertexes.Add(vertex);
            Polyline3d polyline = new Polyline3d(vertexes, true);
            polyline.Layer = new Layer("polyline3d");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            //block definition
            Block block = new Block("TestBlock");
            block.Entities.Add(new Line(new Vector3d(-5, -5, 5), new Vector3d(5, 5, 5)));
            block.Entities.Add(new Line(new Vector3d(5, -5, 5), new Vector3d(-5, 5, 5)));

            //insert
            Insert insert = new Insert(block, new Vector3d(5, 5, 5));
            insert.Layer = new Layer("insert");
            insert.Layer.Color.Index = 4;
            dxf.AddEntity(insert);

            //text
            TextStyle style=new TextStyle("True type font","Arial.ttf");
            Text text = new Text("Hello world!", Vector3d.Zero, 10.0f,style);
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopRight;
            dxf.AddEntity(text);

            dxf.Save("AutoCad2007.dxf", DxfVersion.AutoCad2007);
            dxf.Save("AutoCad2004.dxf", DxfVersion.AutoCad2004);
            dxf.Save("AutoCad2000.dxf", DxfVersion.AutoCad2000);
            dxf.Save("AutoCad12.dxf", DxfVersion.AutoCad12);
        }
 /// <summary>
 /// Initializes a new instance of the <c>DiametricDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="rotation">Rotation in degrees of the dimension line.</param>
 /// <param name="offset">Distance between the reference point and the dimension text</param>
 /// <remarks>The center point and the definition point define the distance to be measure.</remarks>
 public DiametricDimension(Arc arc, double rotation, double offset)
     : this(arc, rotation, offset, DimensionStyle.Default)
 {
 }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <c>RadialDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="rotation">Rotation in degrees of the dimension line.</param>
 /// <param name="offset">Distance between the reference point and the dimension text</param>
 /// <remarks>The center point and the definition point define the distance to be measure.</remarks>
 public RadialDimension(Arc arc, double rotation, double offset)
     : this(arc, rotation, offset, DimensionStyle.Default)
 {
 }
        private void WriteArc(Arc arc)
        {
            this.chunk.Write(100, SubclassMarker.Circle);

            this.chunk.Write(39, arc.Thickness);

            // this is just an example of the weird Autodesk dxf way of doing things, while an ellipse the center is given in world coordinates,
            // the center of an arc is given in object coordinates (different rules for the same concept).
            // It is a lot more intuitive to give the center in world coordinates and then define the orientation with the normal..
            Vector3 ocsCenter = MathHelper.Transform(arc.Center, arc.Normal, CoordinateSystem.World, CoordinateSystem.Object);

            this.chunk.Write(10, ocsCenter.X);
            this.chunk.Write(20, ocsCenter.Y);
            this.chunk.Write(30, ocsCenter.Z);

            this.chunk.Write(40, arc.Radius);

            this.chunk.Write(210, arc.Normal.X);
            this.chunk.Write(220, arc.Normal.Y);
            this.chunk.Write(230, arc.Normal.Z);

            this.chunk.Write(100, SubclassMarker.Arc);
            this.chunk.Write(50, arc.StartAngle);
            this.chunk.Write(51, arc.EndAngle);

            this.WriteXData(arc.XData);
        }
Example #17
0
 private static EntityObject ProcessArc(Arc arc, Matrix3 trans, Vector3 pos)
 {
     arc.Center = trans * arc.Center + pos;
     arc.Normal = trans * arc.Normal;
     return(arc);
 }
Example #18
0
 private static EntityObject ProcessArc(Arc arc, Matrix3 trans, Vector3 pos)
 {
     arc.Center = trans*arc.Center + pos;
     arc.Normal = trans*arc.Normal;
     return arc;
 }
        private void SetInternalInfo(ICollection <EntityObject> entities)
        {
            bool containsClosedPolyline = false;

            foreach (EntityObject entity in entities)
            {
                if ((this.pathTypeFlag & HatchBoundaryPathTypeFlags.Polyline) == HatchBoundaryPathTypeFlags.Polyline)
                {
                    if (this.edges.Count >= 1)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                }

                // it seems that AutoCad does not have problems on creating loops that theoretically does not make sense, like, for example an internal loop that is made of a single arc.
                // so if AutoCAD is ok with that I am too, the program that make use of this information will take care of this inconsistencies
                switch (entity.Type)
                {
                case EntityType.Arc:
                    if (containsClosedPolyline)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                    this.edges.Add(Arc.ConvertFrom(entity));
                    break;

                case EntityType.Circle:
                    if (containsClosedPolyline)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                    this.edges.Add(Arc.ConvertFrom(entity));
                    break;

                case EntityType.Ellipse:
                    if (containsClosedPolyline)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                    this.edges.Add(Ellipse.ConvertFrom(entity));
                    break;

                case EntityType.Line:
                    if (containsClosedPolyline)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                    this.edges.Add(Line.ConvertFrom(entity));
                    break;

                case EntityType.LightWeightPolyline:
                    if (containsClosedPolyline)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                    LwPolyline poly = (LwPolyline)entity;
                    if (poly.IsClosed)
                    {
                        this.edges.Add(Polyline.ConvertFrom(entity));     // A polyline HatchBoundaryPath must be closed
                        this.pathTypeFlag     |= HatchBoundaryPathTypeFlags.Polyline;
                        containsClosedPolyline = true;
                    }
                    else
                    {
                        this.SetInternalInfo(poly.Explode());     // open polylines will always be exploded, only one polyline can be present in a path
                    }
                    break;

                case EntityType.Spline:
                    if (containsClosedPolyline)
                    {
                        throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                    }
                    this.edges.Add(Spline.ConvertFrom(entity));
                    break;

                default:
                    throw new ArgumentException(string.Format("The entity type {0} cannot be part of a hatch boundary.", entity.Type));
                }
            }
        }
Example #20
0
        /// <summary>
        /// Explodes the current insert.
        /// </summary>
        /// <returns>A list of entities.</returns>
        public List <EntityObject> Explode()
        {
            List <EntityObject> entities       = new List <EntityObject>();
            Matrix3             transformation = this.GetTransformation();
            Vector3             translation    = this.Position - transformation * this.block.Origin;

            foreach (EntityObject entity in this.block.Entities)
            {
                Vector3 localScale     = MathHelper.Transform(this.Scale, entity.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                bool    isUniformScale = MathHelper.IsEqual(localScale.X, localScale.Y);

                // entities with reactors are associated with other entities they will handle the transformation
                if (entity.Reactors.Count > 0)
                {
                    continue;
                }

                if (!isUniformScale)
                {
                    switch (entity.Type)
                    {
                    case EntityType.Circle:
                    {
                        Circle  circle  = (Circle)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center    = circle.Center,
                            MajorAxis = 2 * circle.Radius,
                            MinorAxis = 2 * circle.Radius,
                            Thickness = circle.Thickness
                        };

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.Arc:
                    {
                        Arc     arc     = (Arc)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center     = arc.Center,
                            MajorAxis  = 2 * arc.Radius,
                            MinorAxis  = 2 * arc.Radius,
                            StartAngle = arc.StartAngle,
                            EndAngle   = arc.EndAngle,
                            Thickness  = arc.Thickness
                        };

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.LwPolyline:
                    {
                        List <EntityObject> newEntities = ((LwPolyline)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            if (newEntity.Type == EntityType.Arc)
                            {
                                Arc     arc     = (Arc)newEntity;
                                Ellipse ellipse = new Ellipse
                                {
                                    //EntityObject properties
                                    Layer         = (Layer)entity.Layer.Clone(),
                                    Linetype      = (Linetype)entity.Linetype.Clone(),
                                    Color         = (AciColor)entity.Color.Clone(),
                                    Lineweight    = entity.Lineweight,
                                    Transparency  = (Transparency)entity.Transparency.Clone(),
                                    LinetypeScale = entity.LinetypeScale,
                                    Normal        = entity.Normal,
                                    IsVisible     = entity.IsVisible,
                                    //Ellipse properties
                                    Center     = arc.Center,
                                    MajorAxis  = 2 * arc.Radius,
                                    MinorAxis  = 2 * arc.Radius,
                                    StartAngle = arc.StartAngle,
                                    EndAngle   = arc.EndAngle,
                                    Thickness  = arc.Thickness
                                };

                                ellipse.TransformBy(transformation, translation);
                                entities.Add(ellipse);
                            }
                            else
                            {
                                newEntity.TransformBy(transformation, translation);
                                entities.Add(newEntity);
                            }
                        }
                        break;
                    }

                    case EntityType.MLine:
                    {
                        List <EntityObject> newEntities = ((MLine)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            if (newEntity.Type == EntityType.Arc)
                            {
                                Arc     arc     = (Arc)newEntity;
                                Ellipse ellipse = new Ellipse
                                {
                                    //EntityObject properties
                                    Layer         = (Layer)entity.Layer.Clone(),
                                    Linetype      = (Linetype)entity.Linetype.Clone(),
                                    Color         = (AciColor)entity.Color.Clone(),
                                    Lineweight    = entity.Lineweight,
                                    Transparency  = (Transparency)entity.Transparency.Clone(),
                                    LinetypeScale = entity.LinetypeScale,
                                    Normal        = entity.Normal,
                                    IsVisible     = entity.IsVisible,
                                    //Ellipse properties
                                    Center     = arc.Center,
                                    MajorAxis  = 2 * arc.Radius,
                                    MinorAxis  = 2 * arc.Radius,
                                    StartAngle = arc.StartAngle,
                                    EndAngle   = arc.EndAngle,
                                    Thickness  = arc.Thickness
                                };

                                ellipse.TransformBy(transformation, translation);
                                entities.Add(ellipse);
                            }
                            else
                            {
                                newEntity.TransformBy(transformation, translation);
                                entities.Add(newEntity);
                            }
                        }
                        break;
                    }

                    default:
                    {
                        EntityObject newEntity = (EntityObject)entity.Clone();
                        newEntity.TransformBy(transformation, translation);
                        entities.Add(newEntity);
                        break;
                    }
                    }
                }
                else
                {
                    EntityObject newEntity = (EntityObject)entity.Clone();
                    newEntity.TransformBy(transformation, translation);
                    entities.Add(newEntity);
                }
            }

            foreach (Attribute attribute in this.attributes)
            {
                // the attributes will be exploded as a Text entity
                Text text = new Text
                {
                    //Attribute properties
                    Layer         = (Layer)attribute.Layer.Clone(),
                    Linetype      = (Linetype)attribute.Linetype.Clone(),
                    Color         = (AciColor)attribute.Color.Clone(),
                    Lineweight    = attribute.Lineweight,
                    Transparency  = (Transparency)attribute.Transparency.Clone(),
                    LinetypeScale = attribute.LinetypeScale,
                    Normal        = attribute.Normal,
                    IsVisible     = attribute.IsVisible,
                    Height        = attribute.Height,
                    WidthFactor   = attribute.WidthFactor,
                    ObliqueAngle  = attribute.ObliqueAngle,
                    Value         = attribute.Value.ToString(),
                    Style         = (TextStyle)attribute.Style.Clone(),
                    Position      = attribute.Position,
                    Rotation      = attribute.Rotation,
                    Alignment     = attribute.Alignment,
                    IsBackward    = attribute.IsBackward,
                    IsUpsideDown  = attribute.IsUpsideDown
                };
                entities.Add(text);
            }

            return(entities);
        }
 /// <summary>
 /// Initializes a new instance of the <c>Angular3PointDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="offset">Distance between the center of the arc and the dimension line.</param>
 public Angular3PointDimension(Arc arc, double offset)
     : this(arc, offset, DimensionStyle.Default)
 {
 }
        /// <summary>
        /// Gets the the block that contains the entities that make up the dimension picture.
        /// </summary>
        /// <param name="name">Name to be asigned to the generated block.</param>
        /// <returns>The block that represents the actual dimension.</returns>
        internal override Block BuildBlock(string name)
        {
            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 localPoint = MathHelper.Transform(this.center, this.normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 refCenter  = new Vector2(localPoint.X, localPoint.Y);

            localPoint = MathHelper.Transform(this.start, this.normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 refStart = new Vector2(localPoint.X, localPoint.Y);

            localPoint = MathHelper.Transform(this.end, this.normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 refEnd = new Vector2(localPoint.X, localPoint.Y);

            double elev = localPoint.Z;

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startRef = new Point(refStart)
            {
                Layer = defPoints
            };
            Point endRef = new Point(refEnd)
            {
                Layer = defPoints
            };
            Point centerPoint = new Point(refCenter)
            {
                Layer = defPoints
            };

            // dimension lines
            double startAngle = Vector2.Angle(refCenter, refStart);
            double endAngle   = Vector2.Angle(refCenter, refEnd);

            Vector2 startArc    = Vector2.Polar(refCenter, this.offset, startAngle);
            Line    startBorder = new Line(Vector2.Polar(refStart, this.style.DIMEXO, startAngle),
                                           Vector2.Polar(startArc, this.style.DIMEXE, startAngle));

            Vector2 endArc    = Vector2.Polar(refCenter, this.offset, endAngle);
            Line    endBorder = new Line(Vector2.Polar(refEnd, this.style.DIMEXO, endAngle),
                                         Vector2.Polar(endArc, this.style.DIMEXE, endAngle));

            Arc dimArc = new Arc(refCenter, this.offset, startAngle * MathHelper.RadToDeg, endAngle * MathHelper.RadToDeg);


            // dimension arrows
            Vector2 arrowRefBegin = Vector2.Polar(startArc, this.style.DIMASZ, startAngle + MathHelper.HalfPI);
            Solid   arrowBegin    = new Solid(startArc,
                                              Vector2.Polar(arrowRefBegin, -this.style.DIMASZ / 6, startAngle),
                                              Vector2.Polar(arrowRefBegin, this.style.DIMASZ / 6, startAngle),
                                              startArc);

            Vector2 arrowRefEnd = Vector2.Polar(endArc, -this.style.DIMASZ, endAngle + MathHelper.HalfPI);
            Solid   arrowEnd    = new Solid(endArc,
                                            Vector2.Polar(arrowRefEnd, this.style.DIMASZ / 6, endAngle),
                                            Vector2.Polar(arrowRefEnd, -this.style.DIMASZ / 6, endAngle),
                                            endArc);

            // dimension text
            double  aperture = this.Value;
            double  rotText  = Vector2.Angle(endArc, startArc);
            Vector2 midText  = Vector2.Polar(refCenter, this.offset + this.style.DIMGAP, startAngle + aperture * MathHelper.DegToRad * 0.5);

            this.definitionPoint = MathHelper.Transform(new Vector3(midText.X, midText.Y, elev), this.normal,
                                                        MathHelper.CoordinateSystem.Object,
                                                        MathHelper.CoordinateSystem.World);

            this.midTextPoint = new Vector3(midText.X, midText.Y, elev); // this value is in OCS

            MText text = new MText(this.FormatDimensionText(aperture),
                                   this.midTextPoint,
                                   this.style.DIMTXT, 0.0, this.style.TextStyle)
            {
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation        = rotText * MathHelper.RadToDeg
            };

            // drawing block
            Block dim = new Block(name);

            dim.Entities.Add(startRef);
            dim.Entities.Add(endRef);
            dim.Entities.Add(centerPoint);
            dim.Entities.Add(startBorder);
            dim.Entities.Add(endBorder);
            dim.Entities.Add(dimArc);
            dim.Entities.Add(arrowBegin);
            dim.Entities.Add(arrowEnd);
            dim.Entities.Add(text);
            this.block = dim;
            return(dim);
        }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <c>RadialDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="rotation">Rotation in degrees of the dimension line.</param>
 /// <remarks>The center point and the definition point define the distance to be measure.</remarks>
 public RadialDimension(Arc arc, double rotation)
     : this(arc, rotation, DimensionStyle.Default)
 {
 }
Example #24
0
        private static void Angular3PointDimension()
        {
            DxfDocument dxf = new DxfDocument();
            DimensionStyle myStyle = CreateDimStyle();

            Vector3 center = new Vector3(1, 2, 0);
            double radius = 2.42548;
            Arc arc = new Arc(center, radius, -30, 60);
            Angular3PointDimension dim1 = new Angular3PointDimension(arc, 5, myStyle);
            Angular3PointDimension dim2 = new Angular3PointDimension(arc, -5, myStyle);
            dxf.AddEntity(arc);
            dxf.AddEntity(dim1);
            dxf.AddEntity(dim2);
            dxf.Save("dimension drawing.dxf");

            dxf = DxfDocument.Load("dimension drawing.dxf");
        }
Example #25
0
        private void SetInternalInfo(IEnumerable <EntityObject> contour, bool clearEdges)
        {
            bool containsPolyline = false;

            if (clearEdges)
            {
                this.edges.Clear();
            }

            foreach (EntityObject entity in contour)
            {
                if (containsPolyline)
                {
                    throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                }

                // it seems that AutoCad does not have problems on creating loops that theoretically does not make sense,
                // like, for example, an internal loop that is made of a single arc.
                // so if AutoCAD is OK with that I am too, the program that make use of this information will take care of this inconsistencies
                switch (entity.Type)
                {
                case EntityType.Arc:
                    this.edges.Add(Arc.ConvertFrom(entity));
                    break;

                case EntityType.Circle:
                    this.edges.Add(Arc.ConvertFrom(entity));
                    break;

                case EntityType.Ellipse:
                    this.edges.Add(Ellipse.ConvertFrom(entity));
                    break;

                case EntityType.Line:
                    this.edges.Add(Line.ConvertFrom(entity));
                    break;

                case EntityType.LwPolyline:
                    Entities.LwPolyline lwpoly = (Entities.LwPolyline)entity;
                    if (lwpoly.IsClosed)
                    {
                        if (this.edges.Count != 0)
                        {
                            throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                        }
                        this.edges.Add(Polyline.ConvertFrom(entity));
                        this.pathType   |= HatchBoundaryPathTypeFlags.Polyline;
                        containsPolyline = true;
                    }
                    else
                    {
                        this.SetInternalInfo(lwpoly.Explode(), false);     // open polylines will always be exploded, only one polyline can be present in a path
                    }
                    break;

                case EntityType.Polyline:
                    Entities.Polyline poly = (Entities.Polyline)entity;
                    if (poly.IsClosed)
                    {
                        if (this.edges.Count != 0)
                        {
                            throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                        }
                        this.edges.Add(Polyline.ConvertFrom(entity));
                        this.pathType   |= HatchBoundaryPathTypeFlags.Polyline;
                        containsPolyline = true;
                    }
                    else
                    {
                        this.SetInternalInfo(poly.Explode(), false);     // open polylines will always be exploded, only one polyline can be present in a path
                    }
                    break;

                case EntityType.Spline:
                    this.edges.Add(Spline.ConvertFrom(entity));
                    break;

                default:
                    throw new ArgumentException(string.Format("The entity type {0} cannot be part of a hatch boundary. Only Arc, Circle, Ellipse, Line, LwPolyline, and Spline entities are allowed.", entity.Type));
                }
            }
        }
Example #26
0
 public static Arc3D ToArc3D(this netDxf.Entities.Arc dxf_arc)
 {
     return(new Arc3D(new CoordinateSystem3D(dxf_arc.Center, dxf_arc.Normal, CoordinateSystem3DAutoEnum.AAA), dxf_arc.Radius,
                      dxf_arc.StartAngle.ToRad(), dxf_arc.EndAngle.ToRad()));
 }
Example #27
0
        private Arc ReadArc()
        {
            Vector3 center = Vector3.Zero;
            double radius = 1.0;
            double startAngle = 0.0;
            double endAngle = 180.0;
            double thickness = 0.0;
            Vector3 normal = Vector3.UnitZ;
            List<XData> xData = new List<XData>();

            this.chunk.Next();

            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 10:
                        center.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 20:
                        center.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 30:
                        center.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 40:
                        radius = this.chunk.ReadDouble();
                        if (radius <= 0)
                            radius = 1.0;
                        this.chunk.Next();
                        break;
                    case 50:
                        startAngle = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 51:
                        endAngle = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 39:
                        thickness = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 210:
                        normal.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 220:
                        normal.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 230:
                        normal.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(this.GetApplicationRegistry(appId));
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new Exception("The extended data of an entity must start with the application registry code.");
                        this.chunk.Next();
                        break;
                }
            }

            // this is just an example of the stupid autodesk dxf way of doing things, while an ellipse the center is given in world coordinates,
            // the center of an arc is given in object coordinates (different rules for the same concept).
            // It is a lot more intuitive to give the center in world coordinates and then define the orientation with the normal..
            Vector3 wcsCenter = MathHelper.Transform(center, normal, CoordinateSystem.Object, CoordinateSystem.World);
            Arc entity = new Arc
            {
                Center = wcsCenter,
                Radius = radius,
                StartAngle = startAngle,
                EndAngle = endAngle,
                Thickness = thickness,
                Normal = normal
            };

            entity.XData.AddRange(xData);

            return entity;
        }
Example #28
0
        /// <summary>
        /// Convert a netDXF arc to a Nucleus one
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        public static Arc Convert(netDxf.Entities.Arc arc)
        {
            Circle circ = new Circle(arc.Radius * ConversionScaling, Convert(arc.Center), Convert(arc.Normal, 1));

            return(new Arc(circ, Angle.FromDegrees(arc.StartAngle), Angle.FromDegrees(arc.EndAngle), ExtractAttributes(arc)));
        }
Example #29
0
 void ReadArc(netDxf.Entities.Arc arc, double x, double y)
 {
     // TODO :
 }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the <c>RadialDimension</c> class.
 /// </summary>
 /// <param name="arc"><see cref="Arc">Arc</see> to measure.</param>
 /// <param name="rotation">Rotation in degrees of the dimension line.</param>
 /// <param name="style">The <see cref="DimensionStyle">style</see> to use with the dimension.</param>
 /// <remarks>The center point and the definition point define the distance to be measure.</remarks>
 public RadialDimension(Arc arc, double rotation, DimensionStyle style)
     : this(arc.Center, arc.Radius, rotation, style)
 {
     this.normal = arc.Normal;
 }
Example #31
0
        void WriteArc(ArcGeometry line)
        {
            IPointGeometry center = line.Circle.Center;
            double bcAngle = GetAngle(center, line.BC);
            double ecAngle = GetAngle(center, line.EC);

            Arc acLine = new Arc();
            acLine.Center = new Vector3d(center.X, center.Y, 0.0);
            acLine.Radius = line.Circle.Radius;

            // AutoCad arcs are *always* drawn counter-clockwise
            if (line.IsClockwise)
            {
                acLine.StartAngle = ecAngle;
                acLine.EndAngle = bcAngle;
            }
            else
            {
                acLine.StartAngle = bcAngle;
                acLine.EndAngle = ecAngle;
            }

            acLine.Layer = m_Layer;
            m_Dxf.AddEntity(acLine);
        }
Example #32
0
        private static void Angular3PointDimension()
        {
            DxfDocument dxf = new DxfDocument();
            DimensionStyle myStyle = CreateDimStyle();
            myStyle.DIMADEC = 4;
            myStyle.DIMAUNIT = AngleUnitType.DegreesMinutesSeconds;
            Vector3 center = new Vector3(1, 2, 0);
            double radius = 2.5;
            Arc arc = new Arc(center, radius, -32.8, 160.5);
            Angular3PointDimension dim1 = new Angular3PointDimension(arc, 5, myStyle);
            Angular3PointDimension dim2 = new Angular3PointDimension(arc, -5, myStyle);
            dxf.AddEntity(arc);
            dxf.AddEntity(dim1);
            dxf.AddEntity(dim2);
            dxf.Save("dimension drawing.dxf");

            dxf = DxfDocument.Load("dimension drawing.dxf");

            DxfDocument doc = new DxfDocument();
            foreach (var c in dxf.Circles)
            {
                doc.AddEntity((EntityObject)c.Clone());
            }
            foreach (var d in dxf.Dimensions)
            {
                doc.AddEntity((EntityObject)d.Clone());
            }
            doc.Save("dimension drawing saved.dxf");
        }
            public override object Clone()
            {
                Arc copy = new Arc
                {
                    Center = this.Center,
                    Radius = this.Radius,
                    StartAngle = this.StartAngle,
                    EndAngle = this.EndAngle,
                    IsCounterclockwise = this.IsCounterclockwise
                };

                return copy;
            }
Example #34
0
File: Arc.cs Project: Core2D/netdxf
        /// <summary>
        /// Creates a new Arc that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Arc that is a copy of this instance.</returns>
        public override object Clone()
        {
            Arc entity = new Arc
            {
                //EntityObject properties
                Layer = (Layer) this.Layer.Clone(),
                Linetype = (Linetype) this.Linetype.Clone(),
                Color = (AciColor) this.Color.Clone(),
                Lineweight = this.Lineweight,
                Transparency = (Transparency) this.Transparency.Clone(),
                LinetypeScale = this.LinetypeScale,
                Normal = this.Normal,
                IsVisible = this.IsVisible,
                //Arc properties
                Center = this.center,
                Radius = this.radius,
                StartAngle = this.startAngle,
                EndAngle = this.endAngle,
                Thickness = this.thickness
            };

            foreach (XData data in this.XData.Values)
                entity.XData.Add((XData) data.Clone());

            return entity;
        }
Example #35
0
        private void WriteArc(Arc arc)
        {
            if (this.activeSection != StringCode.EntitiesSection && !this.isBlockEntities)
            {
                throw new InvalidDxfSectionException(this.activeSection, this.file);
            }

            this.WriteCodePair(0, arc.CodeName);
            this.WriteCodePair(5, arc.Handle);
            this.WriteCodePair(100, SubclassMarker.Entity);
            this.WriteEntityCommonCodes(arc);
            this.WriteCodePair(100, SubclassMarker.Circle);

            this.WriteCodePair(39, arc.Thickness);

            this.WriteCodePair(10, arc.Center.X);
            this.WriteCodePair(20, arc.Center.Y);
            this.WriteCodePair(30, arc.Center.Z);

            this.WriteCodePair(40, arc.Radius);

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

            this.WriteCodePair(100, SubclassMarker.Arc);
            this.WriteCodePair(50, arc.StartAngle);
            this.WriteCodePair(51, arc.EndAngle);

            this.WriteXData(arc.XData);
        }
Example #36
0
        private static void HatchTest3()
        {
            DxfDocument dxf = new DxfDocument();

            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(-10, -10));
            poly.Vertexes.Add(new LwPolylineVertex(10, -10));
            poly.Vertexes.Add(new LwPolylineVertex(10, 10));
            poly.Vertexes.Add(new LwPolylineVertex(-10, 10));
            poly.Vertexes[2].Bulge = 1;
            poly.IsClosed = true;

            Ellipse ellipse = new Ellipse(Vector3.Zero, 16, 10);
            ellipse.Rotation = 0;
            ellipse.StartAngle = 0;
            ellipse.EndAngle = 180;

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(-8, 0));
            poly2.Vertexes.Add(new LwPolylineVertex(0, -4));
            poly2.Vertexes.Add(new LwPolylineVertex(8, 0));

            Arc arc = new Arc(Vector3.Zero,8,180,0);
            Line line =new Line(new Vector3(8,0,0), new Vector3(-8,0,0));

            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{
                                                                            new HatchBoundaryPath(new List<EntityObject>{poly}),
                                                                            new HatchBoundaryPath(new List<EntityObject>{poly2, ellipse})
                                                                          };

            Hatch hatch = new Hatch(HatchPattern.Line, boundary);
            hatch.Pattern.Angle = 45;
            dxf.AddEntity(poly);
            dxf.AddEntity(ellipse);
            //dxf.AddEntity(arc);
            //dxf.AddEntity(line);
            dxf.AddEntity(poly2);
            dxf.AddEntity(hatch);

            dxf.Save("hatchTest3.dxf");
        }
Example #37
0
        private Arc ReadArc(ref CodeValuePair code)
        {
            var arc = new Arc();
            Vector3d center = Vector3d.Zero;
            Vector3d normal = Vector3d.UnitZ;
            Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();
            code = this.ReadCodePair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        arc.Handle = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 8: //layer code
                        arc.Layer = this.GetLayer(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 62: //aci color code
                        arc.Color = new AciColor(short.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 6: //type line code
                        arc.LineType = this.GetLineType(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 10:
                        center.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 20:
                        center.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 30:
                        center.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 40:
                        arc.Radius = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 50:
                        arc.StartAngle = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 51:
                        arc.EndAngle = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 39:
                        arc.Thickness = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 210:
                        normal.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 220:
                        normal.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 230:
                        normal.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 1001:
                        XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
                        xData.Add(xDataItem.ApplicationRegistry, xDataItem);
                        break;
                    default:
                        if (code.Code >= 1000 && code.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value,
                                                                         this.file, "The extended data of an entity must start with the application registry code " + this.fileLine);
                        code = this.ReadCodePair();
                        break;
                }
            }

            arc.XData = xData;
            arc.Center = center;
            arc.Normal = normal;
            return arc;
        }
Example #38
0
        private static void ToPolyline()
        {
            DxfDocument dxf = new DxfDocument();

            Vector3 center = new Vector3(1, 8, -7);
            Vector3 normal = new Vector3(1, 1, 1);

            Circle circle = new Circle(center, 7.5);
            circle.Normal = normal;

            Arc arc = new Arc(center, 5, -45, 45);
            arc.Normal = normal;

            Ellipse ellipse = new Ellipse(center, 15, 7.5);
            ellipse.Rotation = 35;
            ellipse.Normal = normal;

            Ellipse ellipseArc = new Ellipse(center, 10, 5);
            ellipseArc.StartAngle = 315;
            ellipseArc.EndAngle = 45;
            ellipseArc.Rotation = 35;
            ellipseArc.Normal = normal;

            dxf.AddEntity(circle);
            dxf.AddEntity(circle.ToPolyline(10));

            dxf.AddEntity(arc);
            dxf.AddEntity(arc.ToPolyline(10));

            dxf.AddEntity(ellipse);
            dxf.AddEntity(ellipse.ToPolyline(10));

            dxf.AddEntity(ellipseArc);
            dxf.AddEntity(ellipseArc.ToPolyline(10));

            dxf.Save("to polyline.dxf");

            dxf = DxfDocument.Load("to polyline.dxf");

            dxf.Save("to polyline2.dxf");
        }
Example #39
0
		/*Draw Arc*/
		public static void DrawArc(netDxf.Entities.Arc arc, Canvas mainCanvas)
		{
			
			

			System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
			path.Stroke = System.Windows.Media.Brushes.Black;
			path.StrokeThickness = 1;

			System.Windows.Point endPoint = new System.Windows.Point(
				(arc.Center.X + Math.Cos(arc.StartAngle * Math.PI / 180) * arc.Radius),
				mainCanvas.Height - (arc.Center.Y + Math.Sin(arc.StartAngle * Math.PI / 180) * arc.Radius));

			System.Windows.Point startPoint = new System.Windows.Point(
				(arc.Center.X + Math.Cos(arc.EndAngle * Math.PI / 180) * arc.Radius),
				mainCanvas.Height - (arc.Center.Y + Math.Sin(arc.EndAngle * Math.PI / 180) * arc.Radius));
			

			Debug.WriteLine("debut:"+startPoint.Y+" fin:"+endPoint.Y);

			
			getMaxPt((arc.Center.X + Math.Cos(arc.StartAngle * Math.PI / 180) * arc.Radius),
			         (arc.Center.Y + Math.Sin(arc.StartAngle * Math.PI / 180) * arc.Radius));
			
			getMaxPt((arc.Center.X + Math.Cos(arc.EndAngle * Math.PI / 180) * arc.Radius),
			         (arc.Center.Y + Math.Sin(arc.EndAngle * Math.PI / 180) * arc.Radius));

			
			
			ArcSegment arcSegment = new ArcSegment();
			double sweep = 0.0;
			if (arc.EndAngle < arc.StartAngle)
				sweep = (360 + arc.EndAngle) - arc.StartAngle;
			else sweep = Math.Abs(arc.EndAngle - arc.StartAngle);

			arcSegment.IsLargeArc = sweep >= 180;
			arcSegment.Point = endPoint;
			arcSegment.Size = new System.Windows.Size(arc.Radius, arc.Radius);
			arcSegment.SweepDirection = arc.Normal.Z >= 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;

			PathGeometry geometry = new PathGeometry();
			PathFigure pathFigure = new PathFigure();
			pathFigure.StartPoint = startPoint;
			pathFigure.Segments.Add(arcSegment);
			geometry.Figures.Add(pathFigure);

			path.Data = geometry;
			TypeConverter.Entity2Shape(arc, path);

			
			if(arc.StartAngle <=90 && arc.EndAngle >=90)
			{
				//Debug.WriteLine("ARC Blue "+arc.Center.ToString()+" R:"+arc.Radius+" start:"+arc.StartAngle+" end:"+arc.EndAngle);
				getMaxPt((arc.Center.X),
				         (arc.Center.Y + arc.Radius));
			}
			
			
			if(arc.StartAngle <=180 && arc.EndAngle >=180)
			{
				//Debug.WriteLine("ARC Red "+arc.Center.ToString()+" R:"+arc.Radius+" start:"+arc.StartAngle+" end:"+arc.EndAngle);
				getMaxPt((arc.Center.X - arc.Radius),
				         (arc.Center.Y));
			}
			
			
			if(arc.StartAngle <=270 && arc.EndAngle >=270)
			{
				//Debug.WriteLine("ARC Green "+arc.Center.ToString()+" R:"+arc.Radius+" start:"+arc.StartAngle+" end:"+arc.EndAngle);
				getMaxPt((arc.Center.X),
				         (arc.Center.Y - arc.Radius));
			}
			
			
			if(arc.StartAngle <=380 && arc.EndAngle >=0 && arc.StartAngle>arc.EndAngle)
			{
				//Debug.WriteLine("ARC Green "+arc.Center.ToString()+" R:"+arc.Radius+" start:"+arc.StartAngle+" end:"+arc.EndAngle);
				getMaxPt((arc.Center.X + arc.Radius),
				         (arc.Center.Y));
			}
			

			mainCanvas.Children.Add(path);

		}
Example #40
0
 public void DrawArc( string strLayer, Vec2 vCentre, double dRadius, double dStartAngle, double dEndAngle )
 {
     Arc a = new Arc( new Vector3d( vCentre.x, vCentre.y, 0 ), dRadius, dStartAngle, dEndAngle );
     a.Layer = m_layers[ strLayer ];
     m_dxf.AddEntity( a );
 }
Example #41
0
        private static void DocumentUnits()
        {
            DxfDocument dxf = new DxfDocument();

            // setting the LUnit variable to engineering or architectural will also set the InsUnits variable to Inches,
            // this need to be this way since AutoCad will show those units in feet and inches and will always consider the drawing base units as inches.
            // You can change again the InsUnits it at your own risk.
            // its main purpose is at the user interface level
            //dxf.DrawingVariables.LUnits = LinearUnitType.Engineering;

            // this is the recommended document unit type
            dxf.DrawingVariables.LUnits = LinearUnitType.Decimal;

            // this is the real important unit,
            // it is used when inserting blocks or images into the drawing as this and the block units will give the scale of the resulting Insert
            dxf.DrawingVariables.InsUnits = DrawingUnits.Millimeters;

            // the angle unit type is purely cosmetic as it has no influence on how the angles are stored in the dxf 
            // its purpose is only at the user interface level
            dxf.DrawingVariables.AUnits = AngleUnitType.Radians;

            // even though we have set the drawing angles in radians the dxf always stores angle data in degrees,
            // this arc goes from 45 to 270 degrees and not radians or whatever the AUnits header variable says.
            Arc arc = new Arc(Vector2.Zero, 5, 45, 270);
            // Remember, at the moment, once the entity has been added to the document is not safe to modify it, changes in some of their properties might generate problems
            dxf.AddEntity(arc);

            // the units of this line will correspond to the ones set in InsUnits
            Line lineM = new Line(new Vector2(-5, -5), new Vector2(5, 5));
            dxf.AddEntity(lineM);

            // All entities added to a block are expressed in the coordinates defined by the block
            // You can set a default unit so all new blocks will use them, the default value is Unitless
            // You might want to use the same units as the drawing, this is just a convenient way to make sure all blocks share the same units 
            BlockRecord.DefaultUnits = dxf.DrawingVariables.InsUnits;

            // In this case the line will be 10 cm long
            Line lineCm = new Line(new Vector2(-5, 0), new Vector2(5, 0));
            Block blockCm = new Block("CmBlock");
            // You can override the default units changing the block.Record.Units value
            blockCm.Record.Units = DrawingUnits.Centimeters;
            blockCm.Entities.Add(lineCm);
            Insert insCm = new Insert(blockCm);

            // In this case the line will be 10 dm long
            Line lineDm = new Line(new Vector2(0, 5), new Vector2(0, -5));
            Block blockDm = new Block("DmBlock");
            blockDm.Record.Units = DrawingUnits.Decimeters;
            // AllowExploding and ScaleUniformy properties will only be recognized by dxf version AutoCad2007 and upwards
            blockDm.Record.AllowExploding = false;
            blockDm.Record.ScaleUniformly = true;
            blockDm.Entities.Add(lineDm);
            blockDm.Entities.Add(insCm);
            Insert insDm = new Insert(blockDm);

            dxf.AddEntity(insDm);

            // the image units are stored in the raster variables units, it is recommended to use the same units as the document to avoid confusions
            dxf.RasterVariables.Units = ImageUnits.Millimeters;
            // Sometimes AutoCad does not like image file relative paths, in any case reloading the references will fix the problem
            ImageDefinition imgDefinition = new ImageDefinition("image.jpg");
            // the resolution units is only used to calculate the image resolution that will return pixels per inch or per centimeter (the use of NoUnits is not recommended).
            imgDefinition.ResolutionUnits = ImageResolutionUnits.Inches;
            // this image will be 10x10 mm in size
            Image img = new Image(imgDefinition, Vector3.Zero, 10, 10);
            dxf.AddEntity(img);

            dxf.Save("Document Units.dxf");

            DxfDocument dxfLoad = DxfDocument.Load("Document Units.dxf");

        }
Example #42
0
        private static void Ellipse()
        {
            DxfDocument dxf = new DxfDocument();

            Line line = new Line(new Vector3d(0, 0, 0), new Vector3d((2 * Math.Cos(Math.PI / 4)), (2 * Math.Cos(Math.PI / 4)), 0));
            dxf.AddEntity(line);

            Line line2 = new Line(new Vector3d(0, 0, 0), new Vector3d(0, -2, 0));
            dxf.AddEntity(line2);

            Arc arc=new Arc(Vector3d.Zero,2,45,270);
            dxf.AddEntity(arc);

            // ellipses are saved as polylines
            Ellipse ellipse = new Ellipse(new Vector3d(2,2,0), 5,3);
            ellipse.Rotation = 30;
            ellipse.Normal=new Vector3d(1,1,1);
            ellipse.Thickness = 2;
            dxf.AddEntity(ellipse);

            dxf.Save("ellipse.dxf", DxfVersion.AutoCad2000);
            dxf = new DxfDocument();
            dxf.Load("ellipse.dxf");
        }
Example #43
0
        /// <summary>
        /// 门把手绘制
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        public static void Draw(DxfDocument dxf, Location location)
        {
            float factor = 0.05f;
             float distance = 30;
            //底部小圆的圆心
             Vector3f sCircle = new Vector3f(location.X + 10 * factor, location.Y, location.Z);
            //上部同心圆圆心
             Vector3f bCircle = new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance*factor, location.Z);

             double alpha = Math.Asin(3 / distance);
             double beta = Math.Acos(0.8);

             Vector3f v1 = new Vector3f(
                 location.X + 10 * factor - float.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                 location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                 location.Z);

             Vector3f v2 = new Vector3f(
                  location.X + 10 * factor + float.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                  location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                  location.Z);

             Vector3f v4 = new Vector3f(
                 location.X + 10 * factor -float.Parse((8*factor* Math.Cos(alpha)).ToString()),
                 location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()),
                 location.Z
                 );

             Vector3f v5 = new Vector3f(
             location.X + 10 * factor  + float.Parse((8*factor*Math.Cos(alpha)).ToString()),
             location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()),
             location.Z
             );
             Layer layer = new Layer("line");
             Line line14 = new Line(v1, v4);
             line14.Layer = layer;
             line14.Layer.Color.Index = 6;
             dxf.AddEntity(line14);

             Line line25 = new Line(v2, v5);
             line25.Layer = new Layer("line");
             line25.Layer = layer;
             dxf.AddEntity(line25);

             //arc
             Arc arc = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor, location.Z),
                 5 * factor, Convert.ToInt32(180 + alpha * 180 / Math.PI), Convert.ToInt32(360 - alpha * 180 / Math.PI));
             arc.Layer = layer;
             dxf.AddEntity(arc);

             //arcup
             Arc arcup = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z),
                 8 * factor, Convert.ToInt32(-alpha * 180 / Math.PI), Convert.ToInt32(180 + alpha * 180 / Math.PI));
             arcup.Layer = layer;
             dxf.AddEntity(arcup);

             //arcround
             Arc arcround = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z),
                 10 * factor,
                 Convert.ToInt32(-(alpha +beta) * 180 / Math.PI),
                 Convert.ToInt32(180 + (alpha +beta) * 180 / Math.PI));
             arcround.Layer = layer;
             dxf.AddEntity(arcround);

             //circle
             Vector3f extrusion = new Vector3f(0, 0, 1);
             Vector3f centerWCS = new Vector3f(location.X+10*factor, location.Y+5*factor+distance*factor, location.Z);
             Vector3d centerOCS = MathHelper.Transform((Vector3d)centerWCS,
                                                       (Vector3d)extrusion,
                                                       MathHelper.CoordinateSystem.World,
                                                       MathHelper.CoordinateSystem.Object);

             Circle circle = new Circle((Vector3f)centerOCS, 7*factor);
             circle.Layer = layer;
             circle.LineType = LineType.Continuous;
             circle.Normal = extrusion;
             dxf.AddEntity(circle);

             //上部同心圆圆心
             Vector3f t1 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.7f,
                 location.Z);
             Vector3f t2 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.5f,
                 location.Z);
             Vector3f t3 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.3f,
                 location.Z);
             Vector3f t4 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.1f,
                 location.Z);

             //text
             TextStyle style = new TextStyle("True type font", "Arial.ttf");
             Text text1 = new Text("A", t1, 0.2f, style);
             text1.Layer = layer;
             text1.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text1);

             //text
             Text text2 = new Text("A", t2, 0.2f, style);
             text2.Layer = layer;
             text2.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text2);

             //text
             Text text3 = new Text("O", t3, 0.2f, style);
             text3.Layer = layer;
             text3.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text3);

             //text
             Text text4 = new Text("N", t4, 0.2f, style);
             text4.Layer = layer;
             text4.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text4);
        }
Example #44
0
        private static void Angular3PointDimensionDrawing()
        {
            DxfDocument dxf = new DxfDocument();

            Vector3 center = new Vector3(1, 2, 0);
            double radius = 2.42548;
            Arc arc = new Arc(center, radius, -30, 60);
            //arc.Normal = new Vector3(1, 1, 1);
            DimensionStyle myStyle = new DimensionStyle("MyStyle");

            Angular3PointDimension dim = new Angular3PointDimension(arc, 5, myStyle);
            dxf.AddEntity(arc);
            dxf.AddEntity(dim);
            dxf.Save("angular 3 point dimension.dxf");

            dxf = DxfDocument.Load("angular 3 point dimension.dxf");
        }