Esempio n. 1
0
        public IOReadResult ReadFile(Stream stream, IMeshBuilder builder, ReadOptions options, ParsingMessagesHandler messages)
        {
            // detect binary STL
            //BinaryReader binReader = new BinaryReader(stream);
            //byte[] header = binReader.ReadBytes(80);
            bool bIsBinary = Util.IsBinaryStream(stream, 500);

            // [RMS] Thingi10k includes some files w/ unicode string in ascii header...
            //   How can we detect this? can we check that each character is a character?
            //string sUTF8 = System.Text.Encoding.UTF8.GetString(header);
            //string sAscii = System.Text.Encoding.ASCII.GetString(header);
            //if (sUTF8.Contains("solid") == false && sAscii.Contains("solid") == false)
            //    bIsBinary = true;

            // if first 80 bytes contain non-text chars, probably a binary file
            //if (Util.IsTextString(header) == false)
            //    bIsBinary = true;
            //// if we don't see "solid" string in first 80 chars, probably binary
            //if (bIsBinary == false) {
            //    string sText = System.Text.Encoding.ASCII.GetString(header);
            //    if (sText.Contains("solid") == false)
            //        bIsBinary = true;
            //}

            stream.Seek(0, SeekOrigin.Begin);             // reset stream

            var reader = new STLReader();

            reader.warningEvent += messages;
            IOReadResult result = (bIsBinary) ?
                                  reader.Read(new BinaryReader(stream), options, builder) :
                                  reader.Read(new StreamReader(stream), options, builder);

            return(result);
        }
Esempio n. 2
0
        public IOReadResult ReadFile(Stream stream, IMeshBuilder builder, ReadOptions options, ParsingMessagesHandler messages)
        {
            // detect binary STL
            BinaryReader binReader = new BinaryReader(stream);

            byte[] header    = binReader.ReadBytes(80);
            bool   bIsBinary = false;

            // if first 80 bytes contain non-text chars, probably a binary file
            if (Util.IsTextString(header) == false)
            {
                bIsBinary = true;
            }
            // if we don't see "solid" string in first 80 chars, probably binary
            if (bIsBinary == false)
            {
                string sText = System.Text.Encoding.ASCII.GetString(header);
                if (sText.Contains("solid") == false)
                {
                    bIsBinary = true;
                }
            }

            stream.Seek(0, SeekOrigin.Begin); // reset stream

            STLReader reader = new STLReader();

            reader.warningEvent += messages;
            IOReadResult result = (bIsBinary) ?
                                  reader.Read(new BinaryReader(stream), options, builder) :
                                  reader.Read(new StreamReader(stream), options, builder);

            return(result);
        }
        public IOReadResult ReadFile(string sFilename, IMeshBuilder builder, ReadOptions options, ParsingMessagesHandler messages)
        {
            // detect binary STL
            FileStream stream = null;

            try {
                stream = File.Open(sFilename, FileMode.Open, FileAccess.Read);
            } catch (Exception e) {
                return(new IOReadResult(IOCode.FileAccessError, "Could not open file " + sFilename + " for reading : " + e.Message));
            }

            BinaryReader binReader = new BinaryReader(stream);

            byte[] header    = binReader.ReadBytes(80);
            bool   bIsBinary = false;

            // if first 80 bytes contain non-text chars, probably a binary file
            if (Util.IsTextString(header) == false)
            {
                bIsBinary = true;
            }
            // if we don't see "solid" string in first 80 chars, probably binary
            if (bIsBinary == false)
            {
                string sText = System.Text.Encoding.ASCII.GetString(header);
                if (sText.Contains("solid") == false)
                {
                    bIsBinary = true;
                }
            }

            stream.Seek(0, SeekOrigin.Begin); // reset stream

            STLReader reader = new STLReader();

            reader.warningEvent += messages;
            IOReadResult result = (bIsBinary) ?
                                  reader.Read(new BinaryReader(stream), options, builder) :
                                  reader.Read(new StreamReader(stream), options, builder);

            stream.Close();
            return(result);
        }