Пример #1
0
        public void Vertex_is_correctly_parsed_whatever_the_current_culture(string culture)
        {
            using (TestHelper.SetCurrentCulture(culture))
            {
                var text      = "  ( 1.2  ,  -3.4    ,  5.6789   )  ";
                var converter = new VertexConverter();
                var vertex    = (Vertex)converter.ConvertFrom(text);

                Assert.That(vertex, Is.EqualTo(new Vertex(1.2f, -3.4f, 5.6789f)));
            }
        }
Пример #2
0
        private List <Shape> LoadDXF(string Path, int SplinePrecision, int CirclePrecision)
        {
            List <Shape> retShape = new List <Shape>();

            //Opens the DXF file and load all the data into DXF shapes
            Document dxfFile = new Document(Path);

            dxfFile.Read();

            //Parse each line
            foreach (SimpleDXF.Line line in dxfFile.Lines)
            {
                Shape tempShape = new Shape();

                //Add start and end vertices
                tempShape.Vertices.Add(new Vector2d(line.P1.X, line.P1.Y));
                tempShape.Vertices.Add(new Vector2d(line.P2.X, line.P2.Y));

                retShape.Add(tempShape);
            }

            //Parse each polyline
            foreach (Polyline pl in dxfFile.Polylines)
            {
                Shape tempShape = new Shape();

                List <SimpleDXF.Vector2d> vertices = VertexConverter.GetPolyVertexes(pl, SplinePrecision);

                //Add all vertices of the shape
                foreach (SimpleDXF.Vector2d point in vertices)
                {
                    tempShape.Vertices.Add(new Vector2d(point.X, point.Y));
                }

                //If it's closed, add the first vertex at the end (so we are back where we started)
                if (pl.Closed)
                {
                    tempShape.Vertices.Add(new Vector2d(vertices[0].X, vertices[0].Y));
                }

                retShape.Add(tempShape);
            }

            //Parse each circle
            foreach (Circle circle in dxfFile.Circles)
            {
                Shape tempShape = new Shape();

                List <SimpleDXF.Vector2d> vertices = VertexConverter.GetCircleVertexes(circle, CirclePrecision);

                foreach (SimpleDXF.Vector2d point in vertices)
                {
                    tempShape.Vertices.Add(new Vector2d(point.X, point.Y));
                }

                //Repeat first vertex to close the circle
                tempShape.Vertices.Add(new Vector2d(vertices[0].X, vertices[0].Y));

                retShape.Add(tempShape);
            }

            //Parse each arc
            foreach (Arc arc in dxfFile.Arcs)
            {
                Shape tempShape = new Shape();

                List <SimpleDXF.Vector2d> vertices = VertexConverter.GetArcVertexes(arc, SplinePrecision);

                foreach (SimpleDXF.Vector2d point in vertices)
                {
                    tempShape.Vertices.Add(new Vector2d(point.X, point.Y));
                }

                retShape.Add(tempShape);
            }

            if (retShape.Count > 0)
            {
                return(retShape);
            }
            else
            {
                return(null);
            }
        }