示例#1
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private (string LayerName, MarkGeometryCircle Circle) ParseCircle(AdvancedLineStreamReader readerIn)
        {
            var(success, layerName) = ReadLayerName(readerIn, "AcDbCircle");

            if (success)
            {
                var result1 = readerIn.FindConsecutiveLines(
                    "100",
                    "AcDbCircle"
                    );

                if (!result1.Success)
                {
                    return(null, null);
                }
            }

            var centrePoint = ReadPointFast(readerIn);

            // read radius 40
            readerIn.ReadLine();
            double radius = double.Parse(readerIn.ReadLine());

            var circle = new MarkGeometryCircle(centrePoint, radius);

            return(layerName, circle);
        }
示例#2
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private (string LayerName, MarkGeometryPath Path) ParsePolyline(AdvancedLineStreamReader readerIn)
        {
            var(success, layerName) = ReadLayerName(readerIn, MatchPolylineEntity);

            if (success)
            {
                var result = readerIn.FindConsecutiveLines(
                    MatchSubClassMarker,
                    MatchPolylineEntity
                    );

                if (!result.Success)
                {
                    return(null, null);
                }
            }

            // read number of vertices 90
            var line             = readerIn.ReadLine();
            int numberOfVertices = int.Parse(readerIn.ReadLine());

            var points = new List <MarkGeometryPoint>(numberOfVertices);

            for (int i = 0; i < numberOfVertices; i++)
            {
                points.Add(ReadPointFast2D(readerIn));
            }

            return(layerName, new MarkGeometryPath(points.ToArray()));
        }
示例#3
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private MarkGeometryPoint ReadPointFast2D(AdvancedLineStreamReader readerIn)
        {
            // read doble params 10, 11, etc
            readerIn.FindLine(MatchDoubleParams);
            double X = double.Parse(readerIn.ReadLine());

            // read doble params 20, 21, etc
            readerIn.ReadLine();
            double Y = double.Parse(readerIn.ReadLine());

            return(new MarkGeometryPoint(X, Y));
        }
示例#4
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private double ReadDoubleAdvanced(AdvancedLineStreamReader readerIn, string paramCode)
        {
            readerIn.FindLine(paramCode);
            var line = readerIn.ReadLine();

            if (line.Contains("e"))
            {
                var components = line.Split('e');
                return(double.Parse(components[0]) * Math.Pow(10, double.Parse(components[1])));
            }

            return(double.Parse(readerIn.ReadLine()));
        }
示例#5
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        public HashSet <string> ReadLayers()
        {
            var buffer = new HashSet <string>();

            using (var reader = new AdvancedLineStreamReader(_filePath))
            {
                while (!reader.EndOfStream)
                {
                    var result = reader.FindConsecutiveLines(
                        MatchSubClassMarker,
                        AcDbEntity
                        );

                    if (result.Success)
                    {
                        reader.FindLine(MatchLayerGroupCode);
                        buffer.Add(reader.ReadLine().Trim());
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(buffer);
        }
示例#6
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        public string ReadVersion()
        {
            using (var reader = new AdvancedLineStreamReader(_filePath))
            {
                var result = reader.FindConsecutiveLines(
                    MatchVersionGroupCode,
                    AcadVersionMarker
                    );

                if (result.Success)
                {
                    // skip sub group code
                    reader.ReadLine();
                    return(reader.ReadLine().Trim());
                }

                return(null);
            }
        }
示例#7
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private MarkGeometryPoint ReadPointFast(AdvancedLineStreamReader readerIn)
        {
            // read doble params 10, 11, etc
            readerIn.FindLine(MatchDoubleParams);
            double X = double.Parse(readerIn.ReadLine());

            // read doble params 20, 21, etc
            readerIn.ReadLine();
            double Y = double.Parse(readerIn.ReadLine());

            double Z = 0;

            if (MatchDoubleLastParams.IsMatch(readerIn.PeekLine()))
            {
                // read doble params 30, 31, etc
                readerIn.ReadLine();
                Z = double.Parse(readerIn.ReadLine());
            }

            return(new MarkGeometryPoint(X, Y, Z));
        }
示例#8
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private (bool Success, string) ReadLayerName(AdvancedLineStreamReader readerIn, Regex terminationRegexIn)
        {
            var result = readerIn.FindConsecutiveLines(
                "100",
                "AcDbEntity"
                );

            if (!result.Success)
            {
                return(false, "0");
            }

            var result2 = readerIn.FindLineUntil(
                new Regex(@"^\s*8$"),
                terminationRegexIn
                );

            return(result2.Success, result2.Success ? readerIn.ReadLine().Trim() : "0");
        }
示例#9
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private (string LayerName, MarkGeometryArc Arc) ParseArc(AdvancedLineStreamReader readerIn)
        {
            var(success, layerName) = ReadLayerName(readerIn, "AcDbCircle");

            if (success)
            {
                var result1 = readerIn.FindConsecutiveLines(
                    "100",
                    "AcDbCircle"
                    );

                if (!result1.Success)
                {
                    return(null, null);
                }
            }

            MarkGeometryPoint centrePoint = ReadPointFast(readerIn);

            // read radius 40
            readerIn.ReadLine();
            double radius = double.Parse(readerIn.ReadLine());

            var result2 = readerIn.FindConsecutiveLines(
                "100",
                "AcDbArc"
                );

            if (!result2.Success)
            {
                return(null, null);
            }

            // read angle 50
            readerIn.ReadLine();
            var startAngle = double.Parse(readerIn.ReadLine());

            // read angle 60
            readerIn.ReadLine();
            var endAngle = double.Parse(readerIn.ReadLine());

            var arc = new MarkGeometryArc(
                centrePoint,
                radius, // convert angle to radians
                GeometricArithmeticModule.ToRadians(startAngle),
                GeometricArithmeticModule.ToRadians(endAngle)
                );

            return(layerName, arc);
        }
示例#10
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
 private int ReadInteger(AdvancedLineStreamReader readerIn, string paramCode)
 {
     readerIn.FindLine(paramCode);
     return(int.Parse(readerIn.ReadLine()));
 }
示例#11
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
 private double ReadDouble(AdvancedLineStreamReader readerIn, string paramCode)
 {
     readerIn.FindLine(paramCode);
     return(double.Parse(readerIn.ReadLine()));
 }
示例#12
0
文件: DXFParser.cs 项目: AdilGM/2DCAD
        private (string LayerName, List <IMarkGeometry> Path) ParseLWPolyline(AdvancedLineStreamReader readerIn)
        {
            var(success, layerName) = ReadLayerName(readerIn, MatchLWPolylineEntity);

            if (success)
            {
                var result1 = readerIn.FindConsecutiveLines(
                    MatchSubClassMarker,
                    MatchLWPolylineEntity
                    );

                if (!result1.Success)
                {
                    return(null, null);
                }
            }

            readerIn.ReadLine(); // consume number of vertices 90
            int numberOfVertices = int.Parse(readerIn.ReadLine());
            int flag             = ReadInteger(readerIn, "70");

            var bulges = new List <double>(numberOfVertices);
            var points = new List <MarkGeometryPoint>(numberOfVertices - 1);

            for (int i = 0; i < numberOfVertices; i++)
            {
                points.Add(ReadPointFast2D(readerIn));
                bulges.Add((readerIn.PeekLine().Trim() == "42") ? ReadDouble(readerIn, "42") : 0d);
            }

            if (points.Count > 0 && flag == 1) // i.e. is closed
            {
                points.Add(points[0]);
            }

            var buffer = new List <IMarkGeometry>();
            var path   = new MarkGeometryPath();

            for (int i = 0; i < points.Count - 1; i++)
            {
                var p1    = points[i];
                var p2    = points[i + 1];
                var bulge = bulges[i];

                if (Math.Abs(bulge) <= double.Epsilon)
                {
                    path.Add(p1, true);
                    path.Add(p2, true);
                }
                else
                {
                    if (path.Points.Count > 0)
                    {
                        path.Update(); // force path to re-compute it's properties
                        buffer.Add(path);
                        path = new MarkGeometryPath();
                    }

                    buffer.Add(new MarkGeometryArc(p1, p2, bulge));
                }
            }

            if (path.Points.Count > 0)
            {
                path.Update(); // force path to re-compute it's properties
                buffer.Add(path);
            }

            return(layerName, buffer);
        }