Add copy to clipboard command for material
This commit is contained in:
@@ -5,15 +5,19 @@ using StructureHelper.Services.Exports;
|
||||
using StructureHelper.Windows.ViewModels;
|
||||
using StructureHelperCommon.Models.Parameters;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia
|
||||
@@ -23,6 +27,7 @@ namespace StructureHelper.Windows.Graphs
|
||||
{
|
||||
public class GraphViewModel : ViewModelBase
|
||||
{
|
||||
private IFrameWorkElementServiseLogic frameWorkElementServiseLogic = new FrameWorkElementServiseLogic();
|
||||
public class ColumnInfo
|
||||
{
|
||||
public string Header { get; set; }
|
||||
@@ -37,6 +42,7 @@ namespace StructureHelper.Windows.Graphs
|
||||
private bool invertYValues;
|
||||
private RelayCommand saveImageCommand;
|
||||
private RelayCommand exportToCSVCommand;
|
||||
private RelayCommand copyToClipboardCommand;
|
||||
|
||||
public SelectItemVM<IValueParameter<double>> XItems { get; private set; }
|
||||
public SelectItemsVM<IValueParameter<double>> YItems { get; set; }
|
||||
@@ -81,67 +87,29 @@ namespace StructureHelper.Windows.Graphs
|
||||
|
||||
private void ExportSeries()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ICommand SaveAsImage
|
||||
{
|
||||
get => saveImageCommand ??= new RelayCommand(o => SaveImage());
|
||||
}
|
||||
public CartesianChart MainChart { get; set; }
|
||||
|
||||
public void ExportChartToImage(CartesianChart chart, string filePath)
|
||||
{
|
||||
// Measure and arrange the chart to ensure it's fully rendered
|
||||
chart.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
chart.Arrange(new System.Windows.Rect(0, 0, chart.ActualWidth, chart.ActualHeight));
|
||||
|
||||
// Create a RenderTargetBitmap
|
||||
var renderTarget = new RenderTargetBitmap(
|
||||
(int)chart.ActualWidth,
|
||||
(int)chart.ActualHeight,
|
||||
96, // DPI X
|
||||
96, // DPI Y
|
||||
PixelFormats.Pbgra32);
|
||||
|
||||
// Render the chart to the bitmap
|
||||
renderTarget.Render(chart);
|
||||
|
||||
// Save as a PNG
|
||||
var pngEncoder = new PngBitmapEncoder();
|
||||
pngEncoder.Frames.Add(BitmapFrame.Create(renderTarget));
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
var inputData = new ExportToFileInputData
|
||||
{
|
||||
pngEncoder.Save(stream);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveImage()
|
||||
{
|
||||
var inputData = new ExportToFileInputData();
|
||||
inputData.FileName = "New File";
|
||||
inputData.Filter = "png |*.png";
|
||||
inputData.Title = "Save in png File";
|
||||
|
||||
//var viewbox = new Viewbox();
|
||||
//viewbox.Child = MainChart;
|
||||
//viewbox.Measure(MainChart.RenderSize);
|
||||
//viewbox.Arrange(new Rect(new Point(0, 0), MainChart.RenderSize));
|
||||
//MainChart.Update(true, true); //force chart redraw
|
||||
//viewbox.UpdateLayout();
|
||||
|
||||
var logic = new ExportFrameWorkElementLogic(MainChart);
|
||||
Filter = "csv |*.csv",
|
||||
Title = "Save in *.csv File"
|
||||
};
|
||||
var logic = new ExportChartToCSVLogic(Series);
|
||||
var exportService = new ExportToFileService(inputData, logic);
|
||||
exportService.Export();
|
||||
}
|
||||
|
||||
|
||||
private void CopyImageToClipboard(BitmapImage bitmapImage)
|
||||
public ICommand SaveAsImage
|
||||
{
|
||||
Clipboard.SetImage(bitmapImage);
|
||||
get => saveImageCommand ??= new RelayCommand(o => frameWorkElementServiseLogic.SaveImageToFile(MainChart));
|
||||
}
|
||||
|
||||
public ICommand CopyToClipboardCommand
|
||||
{
|
||||
get => copyToClipboardCommand ??= new RelayCommand(o => frameWorkElementServiseLogic.CopyImageToClipboard(MainChart));
|
||||
}
|
||||
|
||||
|
||||
public CartesianChart MainChart { get; set; }
|
||||
|
||||
public GraphViewModel(IArrayParameter<double> arrayParameter) : this (new List<IArrayParameter<double>>() { arrayParameter})
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user