Example #1
0
        public bool ReadDrawing(string fileName, Stream fileStream, out Drawing drawing, out ViewPort viewPort)
        {
            var file  = IgesFile.Load(fileStream);
            var layer = new Layer("igs");

            foreach (var entity in file.Entities)
            {
                var cadEntity = entity.ToEntity();
                if (cadEntity != null)
                {
                    layer = layer.Add(cadEntity);
                }
            }

            drawing = new Drawing(
                new DrawingSettings(fileName, UnitFormat.Architectural, 8),
                new ReadOnlyTree <string, Layer>().Insert(layer.Name, layer),
                layer.Name,
                file.Author);
            drawing.Tag = file;

            viewPort = null; // auto-set it later

            return(true);
        }
Example #2
0
        public void ReadWithDifferningNewlinesTest()
        {
            var file = new IgesFile();

            file.Entities.Add(new IgesLine(new IgesPoint(0.0, 0.0, 0.0), new IgesPoint(1.0, 1.0, 1.0)));

            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(ms))
                {
                    var text = reader.ReadToEnd();

                    // verify file reading with LF
                    text = text.Replace("\r", "");
                    var lengthLF = 0L;
                    using (var ms2 = new MemoryStream())
                    {
                        using (var writer = new StreamWriter(ms2, Encoding.ASCII, bufferSize: 1024, leaveOpen: true))
                        {
                            writer.Write(text);
                        }

                        ms2.Seek(0, SeekOrigin.Begin);
                        lengthLF = ms2.Length;
                        var fileLF = IgesFile.Load(ms2);
                        Assert.Single(fileLF.Entities);
                    }

                    // verify file reading with CRLF
                    text = text.Replace("\n", "\r\n");
                    var lengthCRLF = 0L;
                    using (var ms2 = new MemoryStream())
                    {
                        using (var writer = new StreamWriter(ms2, Encoding.ASCII, bufferSize: 1024, leaveOpen: true))
                        {
                            writer.Write(text);
                        }

                        ms2.Seek(0, SeekOrigin.Begin);
                        lengthCRLF = ms2.Length;
                        var fileLF = IgesFile.Load(ms2);
                        Assert.Single(fileLF.Entities);
                    }

                    // verify that the file lengths were non-zero and not equal
                    Assert.NotEqual(0L, lengthLF);
                    Assert.NotEqual(0L, lengthCRLF);
                    Assert.NotEqual(lengthLF, lengthCRLF);
                }
            }
        }
Example #3
0
 internal static IgesFile CreateFile(string content)
 {
     using (var stream = new MemoryStream())
         using (var writer = new StreamWriter(stream))
         {
             writer.Write(content.Trim('\r', '\n'));
             writer.Flush();
             stream.Seek(0, SeekOrigin.Begin);
             var file = IgesFile.Load(stream);
             return(file);
         }
 }
Example #4
0
        public Task <ReadDrawingResult> ReadDrawing(string fileName, Stream fileStream, Func <string, Task <byte[]> > contentResolver)
        {
            var file  = IgesFile.Load(fileStream);
            var layer = new Layer("igs");

            foreach (var entity in file.Entities)
            {
                var cadEntity = entity.ToEntity();
                if (cadEntity != null)
                {
                    layer = layer.Add(cadEntity);
                }
            }

            var drawing = new Drawing(
                new DrawingSettings(fileName, UnitFormat.Architectural, 8, 0),
                new ReadOnlyTree <string, Layer>().Insert(layer.Name, layer),
                layer.Name,
                file.Author);

            drawing.Tag = file;
            return(Task.FromResult(ReadDrawingResult.Succeeded(drawing, null)));
        }
Example #5
0
        public void RoundTripFileWithNonStandardDelimitersTest()
        {
            var file = new IgesFile()
            {
                FieldDelimiter  = ';', // inverted field and record delimiters
                RecordDelimiter = ',',
            };

            file.Entities.Add(new IgesLine(new IgesPoint(1.0, 2.0, 3.0), new IgesPoint(4.0, 5.0, 6.0)));

            // write then re-read the file
            using (var ms = new MemoryStream())
            {
                file.Save(ms);
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                var file2 = IgesFile.Load(ms);
                Assert.Equal(';', file.FieldDelimiter);
                Assert.Equal(',', file.RecordDelimiter);
                var line = (IgesLine)file.Entities.Single();
                Assert.Equal(new IgesPoint(1.0, 2.0, 3.0), line.P1);
                Assert.Equal(new IgesPoint(4.0, 5.0, 6.0), line.P2);
            }
        }