/// <summary>
        /// Opens the specified stream, s. Note that as a Portable class library
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="solid">The solid.</param>
        /// <returns>TessellatedSolid.</returns>
        /// <exception cref="Exception">Cannot open file without extension (e.g. f00.stl).
        /// or
        /// This function has been recently removed.
        /// or
        /// Cannot determine format from extension (not .stl, .ply, .3ds, .lwo, .obj, .objx, or .off.</exception>
        /// <exception cref="System.Exception">Cannot open file without extension (e.g. f00.stl).
        /// or
        /// This function has been recently removed.
        /// or
        /// Cannot determine format from extension (not .stl, .ply, .3ds, .lwo, .obj, .objx, or .off.</exception>
        public static void Open(Stream s, string filename, out TessellatedSolid solid)
        {
            try
            {
                var extension = GetFileTypeFromExtension(Path.GetExtension(filename));
                switch (extension)
                {
                case FileType.STL_ASCII:
                case FileType.STL_Binary:
                    solid = STLFileData.OpenSolids(s, filename)[0];     // Standard Tessellation or StereoLithography
                    break;

                case FileType.ThreeMF:
                    solid = ThreeMFFileData.OpenSolids(s, filename)[0];
                    break;

                case FileType.Model3MF:
                    solid = ThreeMFFileData.OpenModelFile(s, filename)[0];
                    break;

                case FileType.AMF:
                    solid = AMFFileData.OpenSolids(s, filename)[0];
                    break;

                case FileType.OFF:
                    solid = OFFFileData.OpenSolid(s, filename);
                    // http://en.wikipedia.org/wiki/OFF_(file_format)
                    break;

                case FileType.PLY_ASCII:
                case FileType.PLY_Binary:
                    solid = PLYFileData.OpenSolid(s, filename);
                    break;

                case FileType.SHELL:
                    solid = ShellFileData.OpenSolids(s, filename)[0];
                    break;

                case FileType.STEP:
                    solid = STEPFileData.OpenSolids(s, filename)[0];
                    break;

                default:
                    var serializer = new JsonSerializer();
                    var sr         = new StreamReader(s);
                    using (var reader = new JsonTextReader(sr))
                        solid = serializer.Deserialize <TessellatedSolid>(reader);
                    break;
                }
            }
            catch (Exception exc)
            {
                throw new Exception("Cannot open file. Message: " + exc.Message);
            }
        }
Beispiel #2
0
        public static void Open(Stream s, string filename, out TessellatedSolid[] tessellatedSolids)
        {
            try
            {
                var extension = GetFileTypeFromExtension(Path.GetExtension(filename));
                switch (extension)
                {
                case FileType.STL_ASCII:
                case FileType.STL_Binary:
                    tessellatedSolids = STLFileData.OpenSolids(s, filename);     // Standard Tessellation or StereoLithography
                    break;

                case FileType.ThreeMF:
                    tessellatedSolids = ThreeMFFileData.OpenSolids(s, filename);
                    break;

                case FileType.Model3MF:
                    tessellatedSolids = ThreeMFFileData.OpenModelFile(s, filename);
                    break;

                case FileType.AMF:
                    tessellatedSolids = AMFFileData.OpenSolids(s, filename);
                    break;

                case FileType.SHELL:
                    tessellatedSolids = ShellFileData.OpenSolids(s, filename);
                    break;

                case FileType.OFF:
                case FileType.PLY_ASCII:
                case FileType.PLY_Binary:
                    throw new Exception("Attempting to open multiple solids with a " + extension.ToString() + " file.");

                default:
                    var serializer = new JsonSerializer();
                    var sr         = new StreamReader(s);
                    using (var reader = new JsonTextReader(sr))
                        // note this is a hack...<T> is overly specific
                        tessellatedSolids = serializer.Deserialize <TessellatedSolid[]>(reader);
                    break;
                }
            }
            catch (Exception exc)
            {
                throw new Exception("Cannot open file. Message: " + exc.Message);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Opens the specified stream, s. Note that as a Portable class library
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="filename">The filename.</param>
        /// <param name="solid">The solid.</param>
        /// <returns>TessellatedSolid.</returns>
        /// <exception cref="Exception">Cannot open file without extension (e.g. f00.stl).
        /// or
        /// This function has been recently removed.
        /// or
        /// Cannot determine format from extension (not .stl, .ply, .3ds, .lwo, .obj, .objx, or .off.</exception>
        /// <exception cref="System.Exception">Cannot open file without extension (e.g. f00.stl).
        /// or
        /// This function has been recently removed.
        /// or
        /// Cannot determine format from extension (not .stl, .ply, .3ds, .lwo, .obj, .objx, or .off.</exception>
        public static void Open(Stream s, string filename, out TessellatedSolid solid)
        {
            var extension = GetExtensionFromFileName(filename);

            switch (extension)
            {
            case "stl":
                solid = STLFileData.OpenSolids(s, filename)[0];     // Standard Tessellation or StereoLithography
                break;

            case "3mf":
#if net40
                throw new NotSupportedException("The loading or saving of .3mf files are not supported in the .NET4.0 version of TVGL.");
#else
                solid = ThreeMFFileData.OpenSolids(s, filename)[0];
                break;
#endif
            case "model":
                solid = ThreeMFFileData.OpenModelFile(s, filename)[0];
                break;

            case "amf":
                solid = AMFFileData.OpenSolids(s, filename)[0];
                break;

            case "off":
                solid = OFFFileData.OpenSolid(s, filename);
                // http://en.wikipedia.org/wiki/OFF_(file_format)
                break;

            case "ply":
                solid = PLYFileData.OpenSolid(s, filename);
                break;

            case "shell":
                solid = ShellFileData.OpenSolids(s, filename)[0];
                break;

            case "xml":
                solid = (TessellatedSolid)TVGLFileData.OpenSolids(s, filename)[0];
                break;

            default:
                throw new Exception(
                          "Cannot determine format from extension (not .stl, .ply, .3ds, .lwo, .obj, .objx, or .off.");
            }
        }
Beispiel #4
0
        public static void Open(Stream s, string filename, out TessellatedSolid[] tessellatedSolids)
        {
            var extension = GetExtensionFromFileName(filename);

            switch (extension)
            {
            case "stl":
                tessellatedSolids = STLFileData.OpenSolids(s, filename);     // Standard Tessellation or StereoLithography
                break;

            case "3mf":
#if net40
                throw new NotSupportedException("The loading or saving of .3mf files are not supported in the .NET4.0 version of TVGL.");
#else
                tessellatedSolids = ThreeMFFileData.OpenSolids(s, filename);
                break;
#endif
            case "model":
                tessellatedSolids = ThreeMFFileData.OpenModelFile(s, filename);
                break;

            case "amf":
                tessellatedSolids = AMFFileData.OpenSolids(s, filename);
                break;

            case "shell":
                tessellatedSolids = ShellFileData.OpenSolids(s, filename);
                break;

            case "xml":
                tessellatedSolids = TVGLFileData.OpenSolids(s, filename).Cast <TessellatedSolid>().ToArray();
                break;

            default:
                throw new Exception(
                          "Cannot determine format from extension (not .stl, .ply, .3ds, .lwo, .obj, .objx, or .off.");
            }
        }
Beispiel #5
0
        public static Solid Open(Stream s, string filename = "")
        {
            try
            {
                var extension = GetFileTypeFromExtension(Path.GetExtension(filename));
                switch (extension)
                {
                case FileType.STL_ASCII:
                case FileType.STL_Binary:
                    return(STLFileData.OpenSolids(s, filename)[0]);    // Standard Tessellation or StereoLithography

                case FileType.ThreeMF:
                    return(ThreeMFFileData.OpenSolids(s, filename)[0]);

                case FileType.Model3MF:
                    return(ThreeMFFileData.OpenModelFile(s, filename)[0]);

                case FileType.AMF:
                    return(AMFFileData.OpenSolids(s, filename)[0]);

                case FileType.OFF:
                    return(OFFFileData.OpenSolid(s, filename));

                case FileType.PLY_ASCII:
                case FileType.PLY_Binary:
                    return(PLYFileData.OpenSolid(s, filename));

                case FileType.SHELL:
                    return(ShellFileData.OpenSolids(s, filename)[0]);

                    break;

                default:
                    var serializer = new JsonSerializer();
                    var sr         = new StreamReader(s);
                    using (var reader = new JsonTextReader(sr))
                    {
                        JObject jObject    = JObject.Load(reader);
                        var     typeString = ((string)jObject["TVGLSolidType"]);
                        if (string.IsNullOrWhiteSpace(typeString))
                        {
                            return(null);
                        }
                        var type = Type.GetType(typeString);
                        if (type == null)
                        {
                            var assembly = Assembly.LoadFrom((string)jObject["InAssembly"]);
                            type = assembly.GetType(typeString);
                        }
                        if (type == null)
                        {
                            return(null);
                        }
                        return((Solid)JsonConvert.DeserializeObject(jObject.ToString(), type));
                    }
                }
            }
            catch (Exception exc)
            {
                throw new Exception("Cannot open file. Message: " + exc.Message);
            }
        }