Пример #1
0
        // Do units matter?
        public static bool CreateSTLFile(string filename,
                                         List <Surface> surfaces,
                                         STLInfo.STLType type = STLInfo.STLType.Binary)
        {
            // Create file.
            string     filepath = DetermineFilename(filename);
            FileStream stream   = File.OpenWrite(filepath);

            bool success = false;

            // Write file if switch on stl type
            if (type == STLInfo.STLType.Binary)
            {
                if (WriteBinaryHeader(stream, filename))
                {
                    success = WriteBinarySTL(stream, surfaces);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            stream.Close();
            return(success);
        }
Пример #2
0
            private void GetTypeAndName()
            {
                // Read 80 bytes or until "solid"
                char[] header      = new char[STLInfo.STL_BIN_HEADER_LENGTH];
                string solid       = "solid ";
                int    lookIndex   = 0;
                char   lookingFor  = solid[lookIndex];
                char   lookingAt   = (char)fileStream.ReadByte();
                bool   FileIsASCII = false;

                while (lookingFor == lookingAt)
                {
                    // Set loop characteristics
                    lookIndex++;
                    if (lookIndex == solid.Length)
                    {
                        FileIsASCII = true;
                        break;
                    }
                    else
                    {
                        lookingAt         = (char)fileStream.ReadByte();
                        header[lookIndex] = lookingAt;
                        lookingFor        = solid[lookIndex];
                    }
                }

                if (FileIsASCII)
                {
                    // Use streamreader
                    // Read line to determine name
                    Name = reader.ReadLine();
                    Type = STLInfo.STLType.ASCII;
                }
                else
                {
                    // Read the rest of the header, call that the name
                    for (int i = lookIndex; i < header.Length; i++)
                    {
                        header[i] = (char)fileStream.ReadByte();
                    }
                    Name = header.ToString();
                    Type = STLInfo.STLType.Binary;
                }
            }