Exemplo n.º 1
0
        private void PerformAction(bool export)
        {
            try {
                SetCancelEnabled(true);
                if (export)
                {
                    string extension = System.IO.Path.GetExtension(SaveFileName);
                    if (extension.Equals(".rm2", StringComparison.OrdinalIgnoreCase))
                    {
                        RM2Export.SaveToFile(SaveFileName, Document, this);
                    }
                    else if (extension.Equals(".rmesh", StringComparison.OrdinalIgnoreCase))
                    {
                        RMeshExport.SaveToFile(SaveFileName, Document, this);
                    }
                    else if (extension.Equals(".fbx", StringComparison.OrdinalIgnoreCase) ||
                             extension.Equals(".obj", StringComparison.OrdinalIgnoreCase) ||
                             extension.Equals(".dae", StringComparison.OrdinalIgnoreCase) ||
                             extension.Equals(".stl", StringComparison.OrdinalIgnoreCase) ||
                             extension.Equals(".ply", StringComparison.OrdinalIgnoreCase))
                    {
                        GenericExport.SaveToFile(SaveFileName, Document, this, extension.Substring(1));
                    }
                    else
                    {
                        throw new Exception($"Unknown file extension ({extension})");
                    }
                }
                else
                {
                    Lightmap.Lightmapper.Render(Document, this, out _, out _);
                }
            } catch (ThreadAbortException) {
                foreach (Thread thread in (Lightmap.Lightmapper.FaceRenderThreads ?? Enumerable.Empty <Thread>()))
                {
                    if (thread.IsAlive)
                    {
                        thread.Abort();
                    }
                }

                ProgressLog.Invoke((MethodInvoker)(() => ProgressLog.AppendText("\nCancelled by the user")));
                ProgressBar.Invoke((MethodInvoker)(() => ProgressBar.Value = 0));
            } catch (Exception e) {
                ProgressLog.Invoke((MethodInvoker)(() => {
                    ProgressLog.SelectionStart = ProgressLog.TextLength;
                    ProgressLog.SelectionLength = 0;
                    ProgressLog.SelectionColor = Color.Red;
                    ProgressLog.AppendText("\nError: " + e.Message + "\n" + e.StackTrace);
                    ProgressLog.SelectionColor = ProgressLog.ForeColor;
                }));
                ProgressBar.Invoke((MethodInvoker)(() => ProgressBar.Value = 0));
            } finally {
                SetCancelEnabled(false);
            }
        }