コード例 #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
        protected static List <MVertex> ToVertexes(MarkGeometryCircle circle)
        {
            var vtx = new List <MVertex>(circle.VertexCount + 1);

            for (int i = 0; i <= circle.VertexCount; i++)
            {
                vtx.Add(new MVertex(
                            (circle.CentrePoint.X + (circle.Radius * Math.Cos(i * Math.PI * 2 / circle.VertexCount))), (circle.CentrePoint.Y + (circle.Radius * Math.Sin(i * Math.PI * 2 / circle.VertexCount)))
                            ));
            }
            return(vtx);
        }
コード例 #3
0
        private static (string Layer, IMarkGeometry Geometry) TryParseCircle(StreamReader readerIn)
        {
            string        layerName = null;
            IMarkGeometry geometry  = null;

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

                if (!found)
                {
                    break;
                }

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

                case "AcDbCircle":
                    MarkGeometryPoint 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");
                    }

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

                    geometry = new MarkGeometryCircle(centre, radius)
                    {
                        LayerName = layerName
                    };
                    return(layerName, geometry);

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

            return(layerName, geometry);
        }