public async void OpenFile(string fileName) { FileFormat format = FileFormat.Detect(fileName); if (format == null) { MessageBox.Show(this, "Unsupported file format", "Open file", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //create load option and allow user to modify the load options LoadOptions opt = format.CreateLoadOptions(); if (OptionDialog.ShowDialog(this, "Import Settings", opt) == DialogResult.Cancel) { return; } currentFileName = fileName; UpdateTitle(); long elapsed = 0; try { lblStatus.Text = string.Format("Loading {0}", fileName); fileListView1.Enabled = false; propertyGrid1.SelectedObject = null; Stopwatch st = Stopwatch.StartNew(); OnMovementChanged(btnOrbital, null); //open the scene using user modified load option in background thread. await Task.Run(() => scene.Open(fileName, opt)); elapsed = st.ElapsedMilliseconds; renderView1.SceneUpdated(fileName); sceneHierarchy.UpdateHierarchy(scene); } catch (Exception e) { MessageBox.Show(this, "Cannot open file " + fileName + "\n" + e.Message, "Open file", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (elapsed > 0) { lblStatus.Text = string.Format("Loaded in {0}ms, Ready.", elapsed); } else { lblStatus.Text = "Ready."; } fileListView1.Enabled = true; } }
/// <summary> /// Create a scene from the uploaded files. /// </summary> /// <returns></returns> /// <exception cref="NotSupportedException">Unsupported 3D file format</exception> public Scene LoadScene() { if (SourceFormat == null) { throw new NotSupportedException("Unsupported 3D file format"); } var loadOpt = sourceFormat.CreateLoadOptions(); loadOpt.FileSystem = CreateFileSystem(); var id = statsService.BeforeOpenSession(app, fileNames.Id); Scene scene = new Scene(); scene.Open(fileNames.GetFileName(SourceFile, mainFile), loadOpt); statsService.AfterLoadScene(id); return(scene); }
private void OnOpenInput(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.CheckFileExists = true; dialog.Filter = "All files (*.*)|*.*"; if (dialog.ShowDialog(this) == DialogResult.Cancel) { return; } FileFormat inputFormat = FileFormat.Detect(dialog.FileName); if (inputFormat == null) { MessageBox.Show(this, "Unsupported 3D file format", "Open file", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } tbInput.Text = dialog.FileName; //show load options for this format pgInput.SelectedObject = loadOptions = inputFormat.CreateLoadOptions(); }