Пример #1
0
        private void Export()
        {
            var manager = new ExportManager {
                SetWaiting = status => Waiting = status
            };
            var dialog = new ExportDialog(manager);

            dialog.Show();
        }
Пример #2
0
        private void ExportResultsStripMenuItem_Click(object?sender, EventArgs e)
        {
            exportResultsStripMenuItem.Enabled = false;
            calculateStripMenuItem.Enabled     = false;

            if (saveFileDialog.ShowDialog() is not DialogResult.OK || DataToExport is null || LastCalculatedResults is null)
            {
                return;
            }

            string filePath = saveFileDialog.FileName;
            var    discreteOutputParameters = new Dictionary <string, IList <Parameter> >();

            discreteOutputParameters.Add("Производительность канала", new[] { new Parameter(null,
                                                                                            canalProductivityOutput.ParameterName, string.Empty,
                                                                                            canalProductivityOutput.MeasureUnit,
                                                                                            canalProductivityOutput.Value) });

            discreteOutputParameters.Add("Показатели качества", new List <ParameterOutput> {
                productTemperatureOutput,
                productViscosityOutput
            }
                                         .Select(po => new Parameter(null, po.ParameterName, string.Empty, po.MeasureUnit, po.Value)).ToArray());

            DataToExport.DiscreteOutputParameters = discreteOutputParameters;

            DataToExport.ContiniousResults = LastCalculatedResults.ResultsTable
                                             .Select(t => (new Parameter(null, "Координата по длине канала", string.Empty, "м", t.coordinate),
                                                           new Parameter(null, "Температура", string.Empty, "°C", t.tempreture),
                                                           new Parameter(null, "Вязкость", string.Empty, "Па⋅c", t.viscosity))).ToArray();

            var exportDialog = new ExportDialog();

            exportDialog.GetExportStatusAsync += async() =>
            {
                bool success;
                try
                {
                    success = await ExportToFileAsync !.Invoke(DataToExport, filePath);
                }
                catch { success = false; }

                if (success is true)
                {
                    return(ExportStatus.FinishedSuccessfully);
                }
                else
                {
                    return(ExportStatus.FinishedWithError);
                }
            };

            exportDialog.Show();

            exportResultsStripMenuItem.Enabled = true;
            calculateStripMenuItem.Enabled     = true;
        }
Пример #3
0
 ///<summary>Handle file->export command from menu</summary>
 public void OnExportActivated(object o, EventArgs args)
 {
     exportDialog.Show();
 }
Пример #4
0
        public void Execute(object parameter)
        {
            if (models.Images.NumImages == 0)
            {
                return;
            }

            // make sure only one image is visible
            if (models.Equations.NumVisible != 1)
            {
                App.ShowInfoDialog(models.App.Window, "Exactly one image equation should be visible when exporting.");
                return;
            }

            // get active final image
            var equationId       = models.Equations.GetFirstVisible();
            var firstImageId     = models.Equations.Get(equationId).ColorFormula.FirstImageId;
            var proposedFilename = firstImageId < models.Images.NumImages ?
                                   System.IO.Path.GetFileNameWithoutExtension(models.Images.GetFilename(firstImageId)) : "";

            // open save file dialog
            var sfd = new SaveFileDialog
            {
                Filter           = "PNG (*.png)|*.png|BMP (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|HDR (*.hdr)|*.hdr|Portable float map (*.pfm)|*.pfm|Khronos Texture (*.ktx)|*.ktx|Khronos Texture (*.ktx2)|*.ktx2|DirectDraw Surface (*.dds)|*.dds",
                InitialDirectory = Properties.Settings.Default.ExportPath,
                FileName         = proposedFilename
            };

            if (sfd.ShowDialog() != true)
            {
                return;
            }

            Properties.Settings.Default.ExportPath = System.IO.Path.GetDirectoryName(sfd.FileName);

            // obtain file format
            var format = ExportModel.FileFormat.Png;

            if (sfd.FileName.EndsWith(".bmp"))
            {
                format = ExportModel.FileFormat.Bmp;
            }
            else if (sfd.FileName.EndsWith(".hdr"))
            {
                format = ExportModel.FileFormat.Hdr;
            }
            else if (sfd.FileName.EndsWith(".pfm"))
            {
                format = ExportModel.FileFormat.Pfm;
            }
            else if (sfd.FileName.EndsWith(".jpg"))
            {
                format = ExportModel.FileFormat.Jpg;
            }
            else if (sfd.FileName.EndsWith(".ktx"))
            {
                format = ExportModel.FileFormat.Ktx;
            }
            else if (sfd.FileName.EndsWith(".ktx2"))
            {
                format = ExportModel.FileFormat.Ktx2;
            }
            else if (sfd.FileName.EndsWith(".dds"))
            {
                format = ExportModel.FileFormat.Dds;
            }

            var texFormat = new ImageLoader.ImageFormat(PixelFormat.Rgb, PixelType.UnsignedByte, true);

            switch (format)
            {
            case ExportModel.FileFormat.Png:
            case ExportModel.FileFormat.Bmp:
            case ExportModel.FileFormat.Jpg:
                if (models.Images.IsAlpha && format == ExportModel.FileFormat.Png)
                {
                    texFormat.ExternalFormat = PixelFormat.Rgba;
                }
                if (models.Images.IsGrayscale)
                {
                    texFormat.ExternalFormat = PixelFormat.Red;
                }
                break;

            case ExportModel.FileFormat.Hdr:
            case ExportModel.FileFormat.Pfm:
                texFormat = new ImageLoader.ImageFormat(PixelFormat.Rgb, PixelType.Float, false);
                if (models.Images.IsGrayscale)
                {
                    texFormat.ExternalFormat = PixelFormat.Red;
                }
                break;

            case ExportModel.FileFormat.Ktx:
            case ExportModel.FileFormat.Ktx2:
            case ExportModel.FileFormat.Dds:
                // load default format from settings
                if (Enum.TryParse <GliFormat>(Properties.Settings.Default.GliFormat, out var fmt))
                {
                    texFormat = new ImageLoader.ImageFormat(fmt);
                }
                else
                {
                    texFormat = new ImageLoader.ImageFormat(GliFormat.RGB8_SRGB_PACK8);
                }
                break;
            }

            models.Export.IsExporting = true;
            // open export dialog
            var dia = new ExportDialog(models, sfd.FileName, texFormat, format);

            dia.Owner   = models.App.Window;
            dia.Closed += (sender, args) =>
            {
                models.Export.IsExporting = false;

                // save gli format if present
                var fmt = models.Export.TexFormat.Format;
                if (fmt.HasGliFormat)
                {
                    Properties.Settings.Default.GliFormat = fmt.GliFormat.ToString();
                }

                if (!dia.ExportResult)
                {
                    return;
                }

                var info = models.Export;

                models.GlContext.Enable();
                try
                {
                    // obtain data from gpu
                    var texture = models.FinalImages.Get(equationId).Texture;
                    if (texture == null)
                    {
                        throw new Exception("texture is not computed");
                    }

                    if (info.FileType == ExportModel.FileFormat.Ktx || info.FileType == ExportModel.FileFormat.Ktx2 || info.FileType == ExportModel.FileFormat.Dds)
                    {
                        SaveMultipleLevel(info, texture);
                    }
                    else
                    {
                        SaveSingleLevel(info, texture);
                    }
                }
                catch (Exception e)
                {
                    App.ShowErrorDialog(models.App.Window, e.Message);
                }
                finally
                {
                    models.GlContext.Disable();
                }
            };

            dia.Show();
        }