コード例 #1
0
        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 (opt != null && opt.GetType() != typeof(LoadOptions))
            {
                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(btnStandardMovement, null);
                Console.WriteLine("Loading file {0}", fileName);
                //open the scene using user modified load option in background thread.
                await Task.Run(() => scene.Open(fileName, opt));

                elapsed = st.ElapsedMilliseconds;
                Console.WriteLine("Loaded in {0}ms", elapsed);

                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;
            }
        }