Ejemplo n.º 1
0
        /// <summary>
        /// Reads the TEXT data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Text object with layer, value (text) and position data</returns>
        private Text ReadText(ref CodePair code)
        {
            Text returnval = new Text(Vector2d.Zero, "", "0");

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 1:
                    returnval.Value = code.Value;
                    break;

                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 10:
                    returnval.Position.X = double.Parse(code.Value);
                    break;

                case 20:
                    returnval.Position.Y = double.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the VERTEX data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Vertex object with layer, position and bulge data</returns>
        private Vertex ReadVertex(ref CodePair code)
        {
            Vertex returnval = new Vertex(0, 0, 0, "0");

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 10:
                    returnval.Position.X = double.Parse(code.Value);
                    break;

                case 20:
                    returnval.Position.Y = double.Parse(code.Value);
                    break;

                case 42:
                    returnval.Bulge = double.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the CIRCLE data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Circle object with layer, center point and radius data</returns>
        private Circle ReadCircle(ref CodePair code)
        {
            Circle returnval = new Circle(Vector2d.Zero, 0, "0");

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 10:
                    returnval.Center.X = double.Parse(code.Value);
                    break;

                case 20:
                    returnval.Center.Y = double.Parse(code.Value);
                    break;

                case 40:
                    returnval.Radius = double.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads the LINE data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Line object with layer and two point data</returns>
        private Line ReadLine(ref CodePair code)
        {
            Line returnval = new Line(Vector2d.Zero, Vector2d.Zero, "0");

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 10:
                    returnval.P1.X = double.Parse(code.Value);
                    break;

                case 20:
                    returnval.P1.Y = double.Parse(code.Value);
                    break;

                case 11:
                    returnval.P2.X = double.Parse(code.Value);
                    break;

                case 21:
                    returnval.P2.Y = double.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads the SECTION name from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A string containing the section name</returns>
        private string ReadSection(ref CodePair code)
        {
            string returnval = "";

            code = this.ReadPair();
            while (code.Code != 0)
            {
                if (code.Code == 2)
                {
                    returnval = code.Value;
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reads the LWPOLYLINE data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Polyline object with layer, closed flag and vertex list data</returns>
        private Polyline ReadLwPolyline(ref CodePair code)
        {
            Polyline returnval = new Polyline(new List <Vertex>(), "0", false);
            Vertex   vtx       = new Vertex(Vector2d.Zero);
            int      flags     = 0;

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 70:
                    flags = int.Parse(code.Value);
                    break;

                case 10:
                    vtx            = new Vertex(Vector2d.Zero);
                    vtx.Position.X = double.Parse(code.Value);
                    break;

                case 20:
                    vtx.Position.Y = double.Parse(code.Value);
                    returnval.Vertexes.Add(vtx);
                    break;

                case 42:
                    vtx.Bulge = double.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            if ((flags & 1) == 1)
            {
                returnval.Closed = true;
            }

            return(returnval);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Reads the POLYLINE data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Polyline object with layer, closed flag and vertex list data</returns>
        private Polyline ReadPolyline(ref CodePair code)
        {
            Polyline returnval = new Polyline(new List <Vertex>(), "0", false);
            int      flags     = 0;

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 70:
                    flags = int.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            while (code.Value != "SEQEND")
            {
                if (code.Value == "VERTEX")
                {
                    Vertex vtx = ReadVertex(ref code);
                    returnval.Vertexes.Add(vtx);
                }
                else
                {
                    code = this.ReadPair();
                }
            }

            if ((flags & 1) == 1)
            {
                returnval.Closed = true;
            }

            return(returnval);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the LAYER data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>A Layer object with name and AciColor index</returns>
        private Layer ReadLayer(ref CodePair code)
        {
            Layer returnval = new Layer("0", 0);

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 2:
                    returnval.Name = code.Value;
                    break;

                case 62:
                    returnval.ColorIndex = int.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Reads the ARC data from the DXF file
        /// </summary>
        /// <param name="code">A reference to the current CodePair read</param>
        /// <returns>An Arc object with layer, center point, radius, start angle and end angle data</returns>
        private Arc ReadArc(ref CodePair code)
        {
            Arc returnval = new Arc(Vector2d.Zero, 0, 0, 0, "0");

            code = this.ReadPair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                case 8:
                    returnval.Layer = code.Value;
                    break;

                case 10:
                    returnval.Center.X = double.Parse(code.Value);
                    break;

                case 20:
                    returnval.Center.Y = double.Parse(code.Value);
                    break;

                case 40:
                    returnval.Radius = double.Parse(code.Value);
                    break;

                case 50:
                    returnval.StartAngle = double.Parse(code.Value);
                    break;

                case 51:
                    returnval.EndAngle = double.Parse(code.Value);
                    break;
                }
                code = this.ReadPair();
            }

            return(returnval);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Read and parse the DXF file
        /// </summary>
        public void Read()
        {
            bool entitysection = false;

            CodePair code = this.ReadPair();

            while ((code.Value != "EOF") && (!dxfReader.EndOfStream))
            {
                if (code.Code == 0)
                {
                    //Have we reached the entities section yet?
                    if (!entitysection)
                    {
                        //No, so keep going until we find the ENTIIES section (and since we are here, let's try to read the layers)
                        switch (code.Value)
                        {
                        case "SECTION":
                            string sec = ReadSection(ref code);
                            if (sec == "ENTITIES")
                            {
                                entitysection = true;
                            }
                            break;

                        case "LAYER":
                            Layer layer = ReadLayer(ref code);
                            Layers.Add(layer);
                            break;

                        default:
                            code = this.ReadPair();
                            break;
                        }
                    }
                    else
                    {
                        //Yes, so let's read the entities
                        switch (code.Value)
                        {
                        case "LINE":
                            Line line = ReadLine(ref code);
                            Lines.Add(line);
                            break;

                        case "CIRCLE":
                            Circle circle = ReadCircle(ref code);
                            Circles.Add(circle);
                            break;

                        case "ARC":
                            Arc arc = ReadArc(ref code);
                            Arcs.Add(arc);
                            break;

                        case "POINT":
                            Point point = ReadPoint(ref code);
                            Points.Add(point);
                            break;

                        case "TEXT":
                            Text text = ReadText(ref code);
                            Texts.Add(text);
                            break;

                        case "POLYLINE":
                            Polyline polyline = ReadPolyline(ref code);
                            Polylines.Add(polyline);
                            break;

                        case "LWPOLYLINE":
                            Polyline lwpolyline = ReadLwPolyline(ref code);
                            Polylines.Add(lwpolyline);
                            break;

                        default:
                            code = this.ReadPair();
                            break;
                        }
                    }
                }
                else
                {
                    code = this.ReadPair();
                }
            }
        }