Beispiel #1
0
        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);
        }
Beispiel #2
0
        private static (string Layer, IMarkGeometry Geometry) TryParseArc(StreamReader readerIn)
        {
            string        layerName = null;
            IMarkGeometry geometry  = null;

            double radius = 0;
            var    centre = new MarkGeometryPoint()
            {
                LayerName = layerName
            };

            while (true)
            {
                var(found, line) = SkipUntil(readerIn, MatchLayerOrArc);

                if (!found)
                {
                    break;
                }

                switch (MatchLayerOrArc.Match(line).Value.Trim())
                {
                case "8":
                    layerName = readerIn.ReadLine();
                    break;

                case "AcDbCircle":
                    centre = TryParsePoint(readerIn);
                    if (centre == null)
                    {
                        throw new Exception("Failed to parse centre point of arc");
                    }

                    if (!SkipUntil(readerIn, MatchGroupCodeForRadius).Found)
                    {
                        throw new Exception("Failed to parse arc radius");
                    }

                    radius = double.Parse(readerIn.ReadLine());
                    break;

                case "AcDbArc":
                    if (!SkipUntil(readerIn, MatchGroupCodeForStartAngle).Found)
                    {
                        throw new Exception("Failed to parse arc start's angle");
                    }

                    double startAngle = double.Parse(readerIn.ReadLine());

                    if (!SkipUntil(readerIn, MatchGroupCodeForEndAngle).Found)
                    {
                        throw new Exception("Failed to parse arc end's angle");
                    }

                    double endAngle = double.Parse(readerIn.ReadLine());

                    geometry = new MarkGeometryArc(centre, radius, startAngle, endAngle)
                    {
                        LayerName = layerName
                    };
                    return(layerName, geometry);

                default:
                    throw new Exception($"Matched circle attribute is not supported: `{line}`");
                }
            }

            return(layerName, geometry);
        }