Beispiel #1
0
 public AsyncModelLoadData(string filename, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback, PrintDetails.ObjectDetails objectDetails)
 {
     this.filename       = filename;
     this.loadedCallback = loadedCallback;
     this.objectDetails  = objectDetails;
     this.onFailCallback = onFailCallback;
 }
Beispiel #2
0
        private void ShowFileLoadingExeption(Exception e, string filename, ModelLoadingManager.LoadFailedCallback onLoadFailed)
        {
            onLoadFailed?.Invoke(filename);

            if (e is FileNotFoundException)
            {
                messagebox.AddMessageToQueue("Sorry, but the file was not found.");
            }
            else
            {
                messagebox.AddMessageToQueue("There was an error loading the file. Please check to make sure the file is valid.");
            }
        }
Beispiel #3
0
        public bool LoadModelIntoPrinter(LibraryRecord record, ModelLoadingManager.LoadFailedCallback onFailCallback)
        {
            Form1.debugLogger.Add("LoadModelIntoPrinter()", "loading model into printer.", DebugLogger.LogType.Secondary);
            var num = LoadModelIntoPrinter(record.cachefilename, onFailCallback) ? 1 : 0;

            if (num == 0)
            {
                return(num != 0);
            }

            Form1.debugLogger.Add("LoadModelIntoPrinter()", "Model loaded into printer.", DebugLogger.LogType.Secondary);
            Form1.debugLogger.Add("LoadModelIntoPrinter()", "OpenGL GetError(): " + GL.GetError().ToString() + ".", DebugLogger.LogType.Secondary);
            return(num != 0);
        }
Beispiel #4
0
        public bool LoadModelIntoPrinter(string filename, ModelLoadingManager.LoadFailedCallback onFailCallback)
        {
            try
            {
                if (!OptimizingModel && !LoadingNewModel)
                {
                    return(LoadModelIntoPrinter(filename, new ModelLoadingManager.OnModelLoadedDel(OnModelLoadedCallback), onFailCallback, null));
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #5
0
        private bool ImportModel(string filename, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback, PrintDetails.ObjectDetails objectDetails)
        {
            IncFilesLoading();
            try
            {
                long num = 0;
                using (var streamReader = new StreamReader(filename))
                {
                    num = streamReader.BaseStream.Length;
                }

                if (num > 10485760L)
                {
                    informationbox.AddMessageToQueue("Fairly complex and may slow down this program");
                }

                M3D.Graphics.Ext3D.ModelRendering.Model model = printerview.GetModel(filename);
                if (model == null)
                {
                    var state = new ModelLoadingManager.AsyncModelLoadData(filename, loadedCallback, onFailCallback, objectDetails);
                    if (settings.CurrentAppearanceSettings.ShowRemoveModelWarning && printerview.ModelLoaded && (objectDetails == null || objectDetails.printerSettingsXMLFile == null || objectDetails.printerViewXMLFile == null))
                    {
                        DecFilesLoading();
                        messagebox.AddXMLMessageToQueue(new PopupMessageBox.MessageDataXML(new SpoolerMessage(), Resources.removeModelDialog, new PopupMessageBox.XMLButtonCallback(RemoveModelButtonCallback), state));
                        return(true);
                    }
                    if (printerview.ModelLoaded && !settings.CurrentAppearanceSettings.UseMultipleModels)
                    {
                        printerview.RemovePrintableModels();
                    }

                    StartLoadModelThread(state);
                }
                else
                {
                    modelLoadedQueue.Enqueue(new ModelLoadingManager.ModelLoadDetails(model, objectDetails));
                }
            }
            catch (Exception ex)
            {
                DecFilesLoading();
                ShowFileLoadingExeption(ex, filename, onFailCallback);
                return(false);
            }
            return(true);
        }
Beispiel #6
0
        private bool LoadZip(string zipFileName, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback)
        {
            IncFilesLoading();
            var        asyncZipLoadData = new ModelLoadingManager.AsyncZipLoadData(zipFileName, loadedCallback);
            FileStream file;

            try
            {
                file = File.OpenRead(zipFileName);
            }
            catch (IOException ex)
            {
                DecFilesLoading();
                ShowFileLoadingExeption(ex, zipFileName, onFailCallback);
                return(false);
            }
            try
            {
                asyncZipLoadData.zf        = new ZipFile(file);
                asyncZipLoadData.iconFile  = null;
                asyncZipLoadData.extractTo = Path.Combine(Paths.PublicDataFolder, "ExtractedZipFiles", Path.GetFileNameWithoutExtension(zipFileName));
                foreach (ZipEntry zipEntry in asyncZipLoadData.zf)
                {
                    if (zipEntry.IsFile)
                    {
                        var str = Path.Combine(asyncZipLoadData.extractTo, Path.GetFileName(zipEntry.Name));
                        if (ModelLoadingManager.GetModelLoader(zipEntry.Name) != null)
                        {
                            asyncZipLoadData.modelFiles.Add(str);
                        }
                        else if (zipEntry.Name.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                        {
                            asyncZipLoadData.xmlFiles.Add(str);
                        }
                        else if (zipEntry.Name.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || zipEntry.Name.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || zipEntry.Name.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase))
                        {
                            asyncZipLoadData.iconFile = str;
                        }
                    }
                }
                if (asyncZipLoadData.modelFiles.Count > 0)
                {
                    if (asyncZipLoadData.xmlFiles.Count > 0)
                    {
                        printerview.RemovePrintableModels();
                        xmlPrinterSettingsZipFileLoaded = true;
                    }
                    if (!Directory.Exists(asyncZipLoadData.extractTo))
                    {
                        Directory.CreateDirectory(asyncZipLoadData.extractTo);
                    }
                }
            }
            catch (Exception ex)
            {
                file.Close();
                DecFilesLoading();
                return(false);
            }
            if (asyncZipLoadData.modelFiles.Count > 0)
            {
                libraryview.RecentModels.CopyAndAssignIconForLibrary(zipFileName, asyncZipLoadData.iconFile);
                ThreadPool.QueueUserWorkItem(new WaitCallback(LoadZipWorkerThread), asyncZipLoadData);
                return(true);
            }
            file.Close();
            DecFilesLoading();
            return(false);
        }
Beispiel #7
0
        private bool LoadModelIntoPrinter(string filename, ModelLoadingManager.OnModelLoadedDel loadedCallback, ModelLoadingManager.LoadFailedCallback onFailCallback, PrintDetails.ObjectDetails objectDetails)
        {
            if (new SplitFileName(filename).ext.ToLowerInvariant() == "zip")
            {
                return(LoadZip(filename, loadedCallback, onFailCallback));
            }

            if (xmlPrinterSettingsZipFileLoaded)
            {
                printerview.ResetControlState();
                xmlPrinterSettingsZipFileLoaded = false;
            }
            return(ImportModel(filename, loadedCallback, onFailCallback, objectDetails));
        }