Add copy to clipboard command for material
This commit is contained in:
@@ -303,7 +303,6 @@
|
|||||||
</Canvas>
|
</Canvas>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
|
|
||||||
<DataTemplate x:Key="ValuePointDiagram">
|
<DataTemplate x:Key="ValuePointDiagram">
|
||||||
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||||
<Canvas.Children>
|
<Canvas.Children>
|
||||||
@@ -363,10 +362,60 @@
|
|||||||
</Canvas>
|
</Canvas>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate x:Key="ExportToXLS">
|
<DataTemplate x:Key="Image">
|
||||||
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||||
<Canvas.Children>
|
<Canvas.Children>
|
||||||
<ContentControl ContentTemplate="{DynamicResource ButtonResultRectangle}"/>
|
<ContentControl ContentTemplate="{DynamicResource ButtonResultRectangle}"/>
|
||||||
|
<Path Data="M 4 16 l 8 -3 l 3 3 l 6 -3 l 7 3 v 12 h -24 z" Fill="DarkGray" Stroke="Black" StrokeThickness="1"/>
|
||||||
|
<Ellipse Canvas.Top="16" Canvas.Left="18" Height="6" Width="6" Fill="White"/>
|
||||||
|
</Canvas.Children>
|
||||||
|
</Canvas>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate x:Key="GetArea">
|
||||||
|
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||||
|
<Canvas.Children>
|
||||||
|
<TextBlock Text="A" FontSize="22" FontWeight="Bold" Margin="2,-4,0,2"/>
|
||||||
|
<TextBlock Text="?" FontSize="18" FontWeight="Bold" Margin="20,8,0,2"/>
|
||||||
|
</Canvas.Children>
|
||||||
|
</Canvas>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate x:Key="PngImage">
|
||||||
|
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||||
|
<Canvas.Children>
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource Image}"/>
|
||||||
|
<TextBlock Text="PNG" FontSize="8" FontWeight="Bold" Margin="4,2,0,2"/>
|
||||||
|
</Canvas.Children>
|
||||||
|
</Canvas>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate x:Key="Document">
|
||||||
|
<Canvas>
|
||||||
|
<Canvas.Children>
|
||||||
|
<Rectangle Height="16" Width="12" Fill="White" Stroke="DarkGray"/>
|
||||||
|
<Line X1="2" Y1="4" X2="10" Y2="4" Stroke="Black"/>
|
||||||
|
<Line X1="2" Y1="7" X2="10" Y2="7" Stroke="Black"/>
|
||||||
|
<Line X1="2" Y1="10" X2="10" Y2="10" Stroke="Black"/>
|
||||||
|
<Line X1="2" Y1="13" X2="10" Y2="13" Stroke="Black"/>
|
||||||
|
</Canvas.Children>
|
||||||
|
</Canvas>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate x:Key="CopyToClipboard">
|
||||||
|
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||||
|
<Canvas.Children>
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource ButtonResultRectangle}"/>
|
||||||
|
<ContentControl Canvas.Top="10" Canvas.Left="14" ContentTemplate="{DynamicResource Document}"/>
|
||||||
|
<ContentControl Canvas.Top="6" Canvas.Left="8" ContentTemplate="{DynamicResource Document}"/>
|
||||||
|
</Canvas.Children>
|
||||||
|
</Canvas>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate x:Key="ExportToXLS">
|
||||||
|
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||||
|
<Canvas.Children>
|
||||||
|
<!--<ContentControl ContentTemplate="{DynamicResource ButtonResultRectangle}"/>-->
|
||||||
<ContentControl ContentTemplate="{DynamicResource Table}"/>
|
<ContentControl ContentTemplate="{DynamicResource Table}"/>
|
||||||
<TextBlock Text="CSV" FontSize="8" FontWeight="Bold" Margin="4,2,0,2"/>
|
<TextBlock Text="CSV" FontSize="8" FontWeight="Bold" Margin="4,2,0,2"/>
|
||||||
<TextBlock Text="XLS" FontSize="12" FontWeight="Bold" FontStyle="Italic" Margin="6,14,0,2"/>
|
<TextBlock Text="XLS" FontSize="12" FontWeight="Bold" FontStyle="Italic" Margin="6,14,0,2"/>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace StructureHelper.Services.Exports
|
|||||||
{
|
{
|
||||||
internal class ExportToFileInputData : IExportToFileInputData
|
internal class ExportToFileInputData : IExportToFileInputData
|
||||||
{
|
{
|
||||||
public string FileName { get; set; }
|
public string FileName { get; set; } = "New file";
|
||||||
public string Filter { get; set; }
|
public string Filter { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,11 +145,12 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
|||||||
}
|
}
|
||||||
private void ExportToCSV()
|
private void ExportToCSV()
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData();
|
var inputData = new ExportToFileInputData
|
||||||
inputData.FileName = "New File";
|
{
|
||||||
inputData.Filter = "csv |*.csv";
|
Filter = "csv |*.csv",
|
||||||
inputData.Title = "Save in csv File";
|
Title = "Save in *.csv File"
|
||||||
var logic = new ExportForceResultToCSVLogic(forcesResults);
|
};
|
||||||
|
var logic = new ExportForcesResultToCSVLogic(forcesResults);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
}
|
}
|
||||||
|
|||||||
61
StructureHelper/Windows/Graphs/ExportChartToCSVLogic.cs
Normal file
61
StructureHelper/Windows/Graphs/ExportChartToCSVLogic.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using StructureHelperCommon.Models.Parameters;
|
||||||
|
using StructureHelperCommon.Services.ColorServices;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelper.Windows.Graphs
|
||||||
|
{
|
||||||
|
public class ExportChartToCSVLogic : ExportToCSVLogicBase
|
||||||
|
{
|
||||||
|
private List<Series> series;
|
||||||
|
|
||||||
|
public ExportChartToCSVLogic(IEnumerable<Series> series)
|
||||||
|
{
|
||||||
|
this.series = series.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExportBoby()
|
||||||
|
{
|
||||||
|
foreach (var ser in series)
|
||||||
|
{
|
||||||
|
output.AppendLine(string.Join(separator, ser.Name));
|
||||||
|
var arrayParameter = ser.ArrayParameter;
|
||||||
|
output.AppendLine(string.Join(separator, arrayParameter.ColumnLabels));
|
||||||
|
var data = arrayParameter.Data;
|
||||||
|
int columnCount = data.GetLength(1);
|
||||||
|
int rowCount = data.GetLength(0);
|
||||||
|
for (int j = 0; j < rowCount; j++)
|
||||||
|
{
|
||||||
|
string[] values = new string[columnCount];
|
||||||
|
for (int i = 0; i < columnCount; i++)
|
||||||
|
{
|
||||||
|
values[i] = data[j, i].ToString();
|
||||||
|
}
|
||||||
|
output.AppendLine(string.Join(separator, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ExportHeadings()
|
||||||
|
{
|
||||||
|
//int headerCount = series.Sum(x => x.YItems.CollectionItems.Count);
|
||||||
|
//string[] headings = new string[headerCount];
|
||||||
|
//int counter = 0;
|
||||||
|
//foreach (var ser in series)
|
||||||
|
//{
|
||||||
|
// foreach (var serCollection in ser.YItems.CollectionItems)
|
||||||
|
// {
|
||||||
|
// headings[counter] = serCollection.Item.Name;
|
||||||
|
// counter++;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//output.AppendLine(string.Join(separator, headings));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using StructureHelper.Services.Exports;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace StructureHelper.Windows.Graphs
|
||||||
|
{
|
||||||
|
public class FrameWorkElementServiseLogic : IFrameWorkElementServiseLogic
|
||||||
|
{
|
||||||
|
public void SaveImageToFile(FrameworkElement element)
|
||||||
|
{
|
||||||
|
var inputData = new ExportToFileInputData
|
||||||
|
{
|
||||||
|
Filter = "png |*.png",
|
||||||
|
Title = "Save in *.png File"
|
||||||
|
};
|
||||||
|
var logic = new ExportFrameWorkElementLogic(element);
|
||||||
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
|
exportService.Export();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CopyImageToClipboard(FrameworkElement element)
|
||||||
|
{
|
||||||
|
if (element == null) return;
|
||||||
|
|
||||||
|
// Measure and arrange the element to ensure it's fully rendered
|
||||||
|
element.Measure(new Size(element.ActualWidth, element.ActualHeight));
|
||||||
|
element.Arrange(new Rect(new Size(element.ActualWidth, element.ActualHeight)));
|
||||||
|
|
||||||
|
// Render the element to a RenderTargetBitmap
|
||||||
|
var renderTarget = new RenderTargetBitmap(
|
||||||
|
(int)element.ActualWidth,
|
||||||
|
(int)element.ActualHeight,
|
||||||
|
96, // DPI X
|
||||||
|
96, // DPI Y
|
||||||
|
PixelFormats.Pbgra32);
|
||||||
|
|
||||||
|
renderTarget.Render(element);
|
||||||
|
|
||||||
|
Clipboard.SetImage(renderTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,26 @@
|
|||||||
<ContentControl ContentTemplate="{StaticResource Renew}"/>
|
<ContentControl ContentTemplate="{StaticResource Renew}"/>
|
||||||
</Viewbox>
|
</Viewbox>
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button Style="{DynamicResource ToolButton}" Command="{Binding CopyToClipboardCommand}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<uc:ButtonToolTipEh HeaderText="Copy to clipboard"
|
||||||
|
IconContent="{StaticResource CopyToClipboard}"
|
||||||
|
DescriptionText="Copy chart to clipboard as image"/>
|
||||||
|
</Button.ToolTip>
|
||||||
|
<Viewbox>
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource CopyToClipboard}"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
|
<Button Style="{DynamicResource ToolButton}" Command="{Binding SaveAsImage}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<uc:ButtonToolTipEh HeaderText="Export to *.png"
|
||||||
|
IconContent="{StaticResource PngImage}"
|
||||||
|
DescriptionText="Export chart to *.png file"/>
|
||||||
|
</Button.ToolTip>
|
||||||
|
<Viewbox>
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource PngImage}"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
<Button Style="{DynamicResource ToolButton}" Command="{Binding ExportToCSVCommand}">
|
<Button Style="{DynamicResource ToolButton}" Command="{Binding ExportToCSVCommand}">
|
||||||
<Button.ToolTip>
|
<Button.ToolTip>
|
||||||
<uc:ButtonToolTipEh HeaderText="Export to *.csv"
|
<uc:ButtonToolTipEh HeaderText="Export to *.csv"
|
||||||
@@ -35,7 +55,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</ToolBarTray>
|
</ToolBarTray>
|
||||||
<Grid>
|
<Grid x:Name="MainGrid">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition MinWidth="250"/>
|
<ColumnDefinition MinWidth="250"/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
@@ -97,14 +117,16 @@
|
|||||||
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=LineVisualProperties}" Content="{Binding VisualProps}"/>
|
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=LineVisualProperties}" Content="{Binding VisualProps}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<GridSplitter Grid.Column="1" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" ShowsPreview="False"/>
|
<GridSplitter Grid.Column="1" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" ShowsPreview="False"/>
|
||||||
<lvc:CartesianChart Name="MainChart" Grid.Column="2" Series="{Binding SeriesCollection}" LegendLocation="Bottom" Zoom="Xy">
|
<Grid Grid.Column="2">
|
||||||
<lvc:CartesianChart.AxisY>
|
<lvc:CartesianChart Name="MainChart" Series="{Binding SeriesCollection}" LegendLocation="Bottom" Zoom="Xy" Background="White">
|
||||||
<lvc:Axis Title="y-value"></lvc:Axis>
|
<lvc:CartesianChart.AxisY>
|
||||||
</lvc:CartesianChart.AxisY>
|
<lvc:Axis Title="y-value"></lvc:Axis>
|
||||||
<lvc:CartesianChart.AxisX>
|
</lvc:CartesianChart.AxisY>
|
||||||
<lvc:Axis Title="x-value"></lvc:Axis>
|
<lvc:CartesianChart.AxisX>
|
||||||
</lvc:CartesianChart.AxisX>
|
<lvc:Axis Title="x-value"></lvc:Axis>
|
||||||
</lvc:CartesianChart>
|
</lvc:CartesianChart.AxisX>
|
||||||
|
</lvc:CartesianChart>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
this.vm = vm;
|
this.vm = vm;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = vm;
|
DataContext = vm;
|
||||||
|
|
||||||
var cartesianChart = (CartesianChart)FindName("MainChart");
|
var cartesianChart = (CartesianChart)FindName("MainChart");
|
||||||
vm.MainChart = cartesianChart;
|
vm.MainChart = cartesianChart;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,19 @@ using StructureHelper.Services.Exports;
|
|||||||
using StructureHelper.Windows.ViewModels;
|
using StructureHelper.Windows.ViewModels;
|
||||||
using StructureHelperCommon.Models.Parameters;
|
using StructureHelperCommon.Models.Parameters;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
|
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Media.Media3D;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
|
||||||
//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia
|
//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia
|
||||||
@@ -23,6 +27,7 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
{
|
{
|
||||||
public class GraphViewModel : ViewModelBase
|
public class GraphViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
private IFrameWorkElementServiseLogic frameWorkElementServiseLogic = new FrameWorkElementServiseLogic();
|
||||||
public class ColumnInfo
|
public class ColumnInfo
|
||||||
{
|
{
|
||||||
public string Header { get; set; }
|
public string Header { get; set; }
|
||||||
@@ -37,6 +42,7 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
private bool invertYValues;
|
private bool invertYValues;
|
||||||
private RelayCommand saveImageCommand;
|
private RelayCommand saveImageCommand;
|
||||||
private RelayCommand exportToCSVCommand;
|
private RelayCommand exportToCSVCommand;
|
||||||
|
private RelayCommand copyToClipboardCommand;
|
||||||
|
|
||||||
public SelectItemVM<IValueParameter<double>> XItems { get; private set; }
|
public SelectItemVM<IValueParameter<double>> XItems { get; private set; }
|
||||||
public SelectItemsVM<IValueParameter<double>> YItems { get; set; }
|
public SelectItemsVM<IValueParameter<double>> YItems { get; set; }
|
||||||
@@ -81,67 +87,29 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
|
|
||||||
private void ExportSeries()
|
private void ExportSeries()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var inputData = new ExportToFileInputData
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
pngEncoder.Save(stream);
|
Filter = "csv |*.csv",
|
||||||
}
|
Title = "Save in *.csv File"
|
||||||
}
|
};
|
||||||
|
var logic = new ExportChartToCSVLogic(Series);
|
||||||
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);
|
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand SaveAsImage
|
||||||
private void CopyImageToClipboard(BitmapImage bitmapImage)
|
|
||||||
{
|
{
|
||||||
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})
|
public GraphViewModel(IArrayParameter<double> arrayParameter) : this (new List<IArrayParameter<double>>() { arrayParameter})
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace StructureHelper.Windows.Graphs
|
||||||
|
{
|
||||||
|
public interface IFrameWorkElementServiseLogic
|
||||||
|
{
|
||||||
|
void CopyImageToClipboard(FrameworkElement element);
|
||||||
|
void SaveImageToFile(FrameworkElement element);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,66 +5,114 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:StructureHelper.Windows.Graphs"
|
xmlns:local="clr-namespace:StructureHelper.Windows.Graphs"
|
||||||
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||||
|
xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls"
|
||||||
d:DataContext="{d:DesignInstance local:MaterialDiagramViewModel}"
|
d:DataContext="{d:DesignInstance local:MaterialDiagramViewModel}"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Material Diagram" Height="550" Width="800" MinHeight="550" MinWidth="800" WindowStartupLocation="CenterScreen">
|
Title="Material Diagram" Height="550" Width="800" MinHeight="550" MinWidth="800" WindowStartupLocation="CenterScreen">
|
||||||
<Grid>
|
<DockPanel>
|
||||||
<Grid.ColumnDefinitions>
|
<ToolBarTray DockPanel.Dock="Top">
|
||||||
<ColumnDefinition Width="250"/>
|
<ToolBar>
|
||||||
<ColumnDefinition/>
|
<Button Style="{StaticResource ToolButton}"
|
||||||
</Grid.ColumnDefinitions>
|
Command="{Binding RedrawLinesCommand}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<uc:ButtonToolTipEh HeaderText="Redraw lines"
|
||||||
|
IconContent="{StaticResource Renew}"
|
||||||
|
DescriptionText="Redraw all lines of chart which have been selected"/>
|
||||||
|
</Button.ToolTip>
|
||||||
|
<Viewbox>
|
||||||
|
<ContentControl ContentTemplate="{StaticResource Renew}"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
|
<Button Style="{DynamicResource ToolButton}" Command="{Binding CopyToClipboardCommand}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<uc:ButtonToolTipEh HeaderText="Copy to clipboard"
|
||||||
|
IconContent="{StaticResource CopyToClipboard}"
|
||||||
|
DescriptionText="Copy chart to clipboard as image"/>
|
||||||
|
</Button.ToolTip>
|
||||||
|
<Viewbox>
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource CopyToClipboard}"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
|
<Button Style="{DynamicResource ToolButton}" Command="{Binding SaveAsImage}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<uc:ButtonToolTipEh HeaderText="Export to *.png"
|
||||||
|
IconContent="{StaticResource PngImage}"
|
||||||
|
DescriptionText="Export chart to *.png file"/>
|
||||||
|
</Button.ToolTip>
|
||||||
|
<Viewbox>
|
||||||
|
<ContentControl ContentTemplate="{DynamicResource PngImage}"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
|
</ToolBar>
|
||||||
|
<ToolBar>
|
||||||
|
<Button Style="{StaticResource ToolButton}"
|
||||||
|
Command="{Binding GetAreaCommand}">
|
||||||
|
<Button.ToolTip>
|
||||||
|
<uc:ButtonToolTipEh HeaderText="Show diagram's areas"
|
||||||
|
IconContent="{StaticResource GetArea}"
|
||||||
|
DescriptionText="Show areas of regions under diagrams (represent energy of deformation of material)"/>
|
||||||
|
</Button.ToolTip>
|
||||||
|
<Viewbox>
|
||||||
|
<ContentControl ContentTemplate="{StaticResource GetArea}"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Button>
|
||||||
|
</ToolBar>
|
||||||
|
</ToolBarTray>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<RowDefinition/>
|
<ColumnDefinition Width="250"/>
|
||||||
<RowDefinition Height="170"/>
|
<ColumnDefinition/>
|
||||||
<RowDefinition Height="30"/>
|
</Grid.ColumnDefinitions>
|
||||||
</Grid.RowDefinitions>
|
<Grid>
|
||||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
<Grid.RowDefinitions>
|
||||||
<StackPanel>
|
<RowDefinition/>
|
||||||
<Expander Header="Materials" IsExpanded="True">
|
<RowDefinition Height="170"/>
|
||||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding MaterialsModel}"/>
|
</Grid.RowDefinitions>
|
||||||
</Expander>
|
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||||
<Expander Header="Limit States">
|
<StackPanel>
|
||||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding LimitStatesModel}"/>
|
<Expander Header="Materials" IsExpanded="True">
|
||||||
</Expander>
|
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding MaterialsModel}"/>
|
||||||
<Expander Header="Calculation terms">
|
</Expander>
|
||||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding CalcTermsModel}"/>
|
<Expander Header="Limit States">
|
||||||
</Expander>
|
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding LimitStatesModel}"/>
|
||||||
<Grid>
|
</Expander>
|
||||||
<Grid.ColumnDefinitions>
|
<Expander Header="Calculation terms">
|
||||||
<ColumnDefinition/>
|
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding CalcTermsModel}"/>
|
||||||
<ColumnDefinition Width="100"/>
|
</Expander>
|
||||||
</Grid.ColumnDefinitions>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<RowDefinition Height="22"/>
|
<ColumnDefinition/>
|
||||||
<RowDefinition Height="22"/>
|
<ColumnDefinition Width="100"/>
|
||||||
<RowDefinition Height="22"/>
|
</Grid.ColumnDefinitions>
|
||||||
<RowDefinition Height="22"/>
|
<Grid.RowDefinitions>
|
||||||
</Grid.RowDefinitions>
|
<RowDefinition Height="22"/>
|
||||||
<TextBlock Text="Minimum strain"/>
|
<RowDefinition Height="22"/>
|
||||||
<TextBox Grid.Column="1" Text="{Binding MinValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
<RowDefinition Height="22"/>
|
||||||
<TextBlock Grid.Row="1" Text="Maximum strain"/>
|
<RowDefinition Height="22"/>
|
||||||
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding MaxValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
</Grid.RowDefinitions>
|
||||||
<TextBlock Grid.Row="2" Text="Step count"/>
|
<TextBlock Text="Minimum strain"/>
|
||||||
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding StepCount, ValidatesOnDataErrors=True}"/>
|
<TextBox Grid.Column="1" Text="{Binding MinValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
||||||
<TextBlock Grid.Row="3" Text="Positive in tension"/>
|
<TextBlock Grid.Row="1" Text="Maximum strain"/>
|
||||||
<CheckBox Grid.Column="1" Grid.Row="3" Margin="4" IsChecked="{Binding PositiveInTension}"/>
|
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding MaxValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
||||||
</Grid>
|
<TextBlock Grid.Row="2" Text="Step count"/>
|
||||||
</StackPanel>
|
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding StepCount, ValidatesOnDataErrors=True}"/>
|
||||||
</ScrollViewer>
|
<TextBlock Grid.Row="3" Text="Positive in tension"/>
|
||||||
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=LineVisualProperties}" Content="{Binding VisualProps}"/>
|
<CheckBox Grid.Column="1" Grid.Row="3" Margin="4" IsChecked="{Binding PositiveInTension}"/>
|
||||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
</Grid>
|
||||||
<Button Margin="3" Content="Draw Lines" ToolTip="Draw lines" Command="{Binding RedrawLinesCommand}"/>
|
</StackPanel>
|
||||||
<Button Margin="3" Content="Show Areas" ToolTip="Area under lines" Command="{Binding GetAreaCommand}"/>
|
</ScrollViewer>
|
||||||
</StackPanel>
|
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=LineVisualProperties}" Content="{Binding VisualProps}"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Grid.Column="1">
|
||||||
|
<lvc:CartesianChart Name="MainChart" Series="{Binding SeriesCollection}" LegendLocation="Bottom" Zoom="Xy" Background="White">
|
||||||
|
<lvc:CartesianChart.AxisY>
|
||||||
|
<lvc:Axis Title="Stress"></lvc:Axis>
|
||||||
|
</lvc:CartesianChart.AxisY>
|
||||||
|
<lvc:CartesianChart.AxisX>
|
||||||
|
<lvc:Axis Title="Strain" Labels="{Binding Labels}"></lvc:Axis>
|
||||||
|
</lvc:CartesianChart.AxisX>
|
||||||
|
</lvc:CartesianChart>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<lvc:CartesianChart Grid.Column="1" Series="{Binding SeriesCollection}" LegendLocation="Bottom" Zoom="Xy">
|
</DockPanel>
|
||||||
<lvc:CartesianChart.AxisY>
|
|
||||||
<lvc:Axis Title="Stress"></lvc:Axis>
|
|
||||||
</lvc:CartesianChart.AxisY>
|
|
||||||
<lvc:CartesianChart.AxisX>
|
|
||||||
<lvc:Axis Title="Strain" Labels="{Binding Labels}"></lvc:Axis>
|
|
||||||
</lvc:CartesianChart.AxisX>
|
|
||||||
</lvc:CartesianChart>
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ namespace StructureHelper.Windows.MainWindow.Materials
|
|||||||
this.vm = vm;
|
this.vm = vm;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.DataContext = this.vm;
|
this.DataContext = this.vm;
|
||||||
|
var cartesianChart = (CartesianChart)FindName("MainChart");
|
||||||
|
vm.MainChart = cartesianChart;
|
||||||
}
|
}
|
||||||
public MaterialDiagramView(IEnumerable<IHeadMaterial> headMaterials, IHeadMaterial material) : this(new MaterialDiagramViewModel(headMaterials, material))
|
public MaterialDiagramView(IEnumerable<IHeadMaterial> headMaterials, IHeadMaterial material) : this(new MaterialDiagramViewModel(headMaterials, material))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,15 +4,12 @@ using StructureHelper.Infrastructure;
|
|||||||
using StructureHelper.Infrastructure.UI.Converters.Units;
|
using StructureHelper.Infrastructure.UI.Converters.Units;
|
||||||
using StructureHelper.Models.Materials;
|
using StructureHelper.Models.Materials;
|
||||||
using StructureHelper.Windows.ViewModels;
|
using StructureHelper.Windows.ViewModels;
|
||||||
using StructureHelperCommon.Infrastructures.Enums;
|
|
||||||
using StructureHelperCommon.Infrastructures.Settings;
|
using StructureHelperCommon.Infrastructures.Settings;
|
||||||
using StructureHelperCommon.Services.ColorServices;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace StructureHelper.Windows.Graphs
|
namespace StructureHelper.Windows.Graphs
|
||||||
{
|
{
|
||||||
@@ -27,16 +24,19 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
public double Stress { get; set; }
|
public double Stress { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private IHeadMaterial material;
|
//private IHeadMaterial material;
|
||||||
private ICommand redrawLinesCommand;
|
private ICommand redrawLinesCommand;
|
||||||
double minValue;
|
private double minValue = -0.005d;
|
||||||
double maxValue;
|
private double maxValue = 0.005d;
|
||||||
int stepCount;
|
private int stepCount = 50;
|
||||||
bool positiveInTension;
|
bool positiveInTension = true;
|
||||||
private ICommand getAreaCommand;
|
private ICommand getAreaCommand;
|
||||||
|
private RelayCommand saveImageCommand;
|
||||||
|
private RelayCommand copyToClipboardCommand;
|
||||||
|
private IFrameWorkElementServiseLogic frameWorkElementServiseLogic = new FrameWorkElementServiseLogic();
|
||||||
|
|
||||||
public string MaterialName => material.Name;
|
//public string MaterialName => material.Name;
|
||||||
public GraphVisualProps VisualProps { get; }
|
public GraphVisualProps VisualProps { get; } = new();
|
||||||
public double MinValue
|
public double MinValue
|
||||||
{
|
{
|
||||||
get => minValue;
|
get => minValue;
|
||||||
@@ -101,11 +101,29 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
}, b => IsDrawPossible());
|
}, b => IsDrawPossible());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand SaveAsImage
|
||||||
|
{
|
||||||
|
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 MaterialDiagramViewModel(IEnumerable<IHeadMaterial> headMaterials, IHeadMaterial material)
|
public MaterialDiagramViewModel(IEnumerable<IHeadMaterial> headMaterials, IHeadMaterial material)
|
||||||
{
|
{
|
||||||
MaterialsModel = new SelectItemsVM<IHeadMaterial>(headMaterials) { ShowButtons = true };
|
//this.material = material;
|
||||||
LimitStatesModel = new SelectItemsVM<LimitStateEntity>(ProgramSetting.LimitStatesList.LimitStates) { ShowButtons = false };
|
SetModels(headMaterials);
|
||||||
CalcTermsModel = new SelectItemsVM<CalcTermEntity>(ProgramSetting.CalcTermList.CalcTerms) { ShowButtons = false };
|
SetSelectedMaterial(material);
|
||||||
|
SetLines();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetSelectedMaterial(IHeadMaterial material)
|
||||||
|
{
|
||||||
foreach (var item in MaterialsModel.CollectionItems)
|
foreach (var item in MaterialsModel.CollectionItems)
|
||||||
{
|
{
|
||||||
if (item.Item == material)
|
if (item.Item == material)
|
||||||
@@ -114,14 +132,24 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
}
|
}
|
||||||
else item.IsSelected = false;
|
else item.IsSelected = false;
|
||||||
}
|
}
|
||||||
this.material = material;
|
|
||||||
minValue = -0.005d;
|
|
||||||
maxValue = 0.005d;
|
|
||||||
stepCount = 50;
|
|
||||||
positiveInTension = true;
|
|
||||||
VisualProps = new();
|
|
||||||
SetLines();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetModels(IEnumerable<IHeadMaterial> headMaterials)
|
||||||
|
{
|
||||||
|
MaterialsModel = new SelectItemsVM<IHeadMaterial>(headMaterials)
|
||||||
|
{
|
||||||
|
ShowButtons = true
|
||||||
|
};
|
||||||
|
LimitStatesModel = new SelectItemsVM<LimitStateEntity>(ProgramSetting.LimitStatesList.LimitStates)
|
||||||
|
{
|
||||||
|
ShowButtons = false
|
||||||
|
};
|
||||||
|
CalcTermsModel = new SelectItemsVM<CalcTermEntity>(ProgramSetting.CalcTermList.CalcTerms)
|
||||||
|
{
|
||||||
|
ShowButtons = false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private string GetAreas()
|
private string GetAreas()
|
||||||
{
|
{
|
||||||
var materials = MaterialsModel.SelectedItems;
|
var materials = MaterialsModel.SelectedItems;
|
||||||
@@ -142,8 +170,12 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
{
|
{
|
||||||
double sumStress = 0d;
|
double sumStress = 0d;
|
||||||
var stressList = values
|
var stressList = values
|
||||||
.Where(x => x.LimitState == limitState & x.CalcTerm == calcTerm & x.Material == material).ToList();
|
.Where(x =>
|
||||||
for (int i = 1; i < stressList.Count(); i++)
|
x.LimitState == limitState
|
||||||
|
& x.CalcTerm == calcTerm
|
||||||
|
& x.Material == material)
|
||||||
|
.ToList();
|
||||||
|
for (int i = 1; i < stressList.Count; i++)
|
||||||
{
|
{
|
||||||
double midStress = (stressList[i - 1].Stress + stressList[i].Stress) / 2;
|
double midStress = (stressList[i - 1].Stress + stressList[i].Stress) / 2;
|
||||||
sumStress += midStress * UnitConstants.Stress * step;
|
sumStress += midStress * UnitConstants.Stress * step;
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
{
|
{
|
||||||
public class Series : ViewModelBase
|
public class Series : ViewModelBase
|
||||||
{
|
{
|
||||||
private IArrayParameter<double> arrayParameter;
|
|
||||||
private List<IValueParameter<double>> valueParameters;
|
private List<IValueParameter<double>> valueParameters;
|
||||||
private Dictionary<IValueParameter<double>, double[]> valueList;
|
private Dictionary<IValueParameter<double>, double[]> valueList;
|
||||||
private bool invertXValues;
|
private bool invertXValues;
|
||||||
private bool invertYValues;
|
private bool invertYValues;
|
||||||
|
private IArrayParameter<double> arrayParameter1;
|
||||||
|
|
||||||
public SelectItemVM<IValueParameter<double>> XItems { get; }
|
public SelectItemVM<IValueParameter<double>> XItems { get; }
|
||||||
public SelectItemsVM<IValueParameter<double>> YItems { get; }
|
public SelectItemsVM<IValueParameter<double>> YItems { get; }
|
||||||
@@ -56,12 +56,14 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
public IArrayParameter<double> ArrayParameter { get; set; }
|
public IArrayParameter<double> ArrayParameter { get; set; }
|
||||||
public Series(IArrayParameter<double> arrayParameter)
|
public Series(IArrayParameter<double> arrayParameter)
|
||||||
{
|
{
|
||||||
this.arrayParameter = arrayParameter;
|
this.ArrayParameter = arrayParameter;
|
||||||
valueParameters = GetParameters();
|
valueParameters = GetParameters();
|
||||||
XItems = new SelectItemVM<IValueParameter<double>>(valueParameters);
|
XItems = new SelectItemVM<IValueParameter<double>>(valueParameters);
|
||||||
YItems = new SelectItemsVM<IValueParameter<double>>(valueParameters);
|
|
||||||
YItems.ShowButtons = true;
|
|
||||||
XItems.SelectedItem = XItems.Collection[0];
|
XItems.SelectedItem = XItems.Collection[0];
|
||||||
|
YItems = new SelectItemsVM<IValueParameter<double>>(valueParameters)
|
||||||
|
{
|
||||||
|
ShowButtons = true
|
||||||
|
};
|
||||||
YItems.UnSelectAllCommand.Execute(null);
|
YItems.UnSelectAllCommand.Execute(null);
|
||||||
VisualProps = new();
|
VisualProps = new();
|
||||||
Color = ColorProcessor.GetRandomColor();
|
Color = ColorProcessor.GetRandomColor();
|
||||||
@@ -71,13 +73,13 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
{
|
{
|
||||||
valueList = new Dictionary<IValueParameter<double>, double[]>();
|
valueList = new Dictionary<IValueParameter<double>, double[]>();
|
||||||
var items = new List<IValueParameter<double>>();
|
var items = new List<IValueParameter<double>>();
|
||||||
var data = arrayParameter.Data;
|
var data = ArrayParameter.Data;
|
||||||
int columnCount = data.GetLength(1);
|
int columnCount = data.GetLength(1);
|
||||||
for (int i = 0; i < columnCount; i++)
|
for (int i = 0; i < columnCount; i++)
|
||||||
{
|
{
|
||||||
var item = new ValueParameter<double>()
|
var item = new ValueParameter<double>()
|
||||||
{
|
{
|
||||||
Name = arrayParameter.ColumnLabels[i],
|
Name = ArrayParameter.ColumnLabels[i],
|
||||||
Color = ColorProcessor.GetRandomColor(),
|
Color = ColorProcessor.GetRandomColor(),
|
||||||
};
|
};
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCa
|
|||||||
}
|
}
|
||||||
private void ExportToCSV()
|
private void ExportToCSV()
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData();
|
var inputData = new ExportToFileInputData
|
||||||
inputData.FileName = "New File";
|
{
|
||||||
inputData.Filter = "csv |*.csv";
|
Filter = "csv |*.csv",
|
||||||
inputData.Title = "Save in csv File";
|
Title = "Save in csv File"
|
||||||
|
};
|
||||||
var logic = new ExportGeometryResultToCSVLogic(result);
|
var logic = new ExportGeometryResultToCSVLogic(result);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
|
|||||||
@@ -3,38 +3,19 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||||
{
|
{
|
||||||
public class ExportForceResultToCSVLogic : IExportResultLogic
|
public class ExportForcesResultToCSVLogic : ExportToCSVLogicBase
|
||||||
{
|
{
|
||||||
const string separator = ";";
|
|
||||||
StringBuilder output;
|
|
||||||
IForcesResults results;
|
IForcesResults results;
|
||||||
public string FileName { get; set; }
|
|
||||||
|
|
||||||
public void Export()
|
public ExportForcesResultToCSVLogic(IForcesResults results)
|
||||||
{
|
{
|
||||||
ExportHeadings();
|
this.results = results;
|
||||||
ExportBoby();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.AppendAllText(FileName, output.ToString());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Data could not be written to the CSV file.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExportForceResultToCSVLogic(IForcesResults forcesResults)
|
public override void ExportHeadings()
|
||||||
{
|
|
||||||
this.results = forcesResults;
|
|
||||||
output = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExportHeadings()
|
|
||||||
{
|
{
|
||||||
string[] headings =
|
string[] headings =
|
||||||
{
|
{
|
||||||
"Limit State",
|
"Limit State",
|
||||||
"Calc duration",
|
"Calc duration",
|
||||||
"Mx",
|
"Mx",
|
||||||
@@ -46,7 +27,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
|
|||||||
};
|
};
|
||||||
output.AppendLine(string.Join(separator, headings));
|
output.AppendLine(string.Join(separator, headings));
|
||||||
}
|
}
|
||||||
private void ExportBoby()
|
public override void ExportBoby()
|
||||||
{
|
{
|
||||||
foreach (var item in results.ForcesResultList)
|
foreach (var item in results.ForcesResultList)
|
||||||
{
|
{
|
||||||
@@ -27,12 +27,23 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
|
|||||||
|
|
||||||
private static void EncodeVisual(FrameworkElement visual, string fileName, BitmapEncoder encoder)
|
private static void EncodeVisual(FrameworkElement visual, string fileName, BitmapEncoder encoder)
|
||||||
{
|
{
|
||||||
var bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Pbgra32);
|
// Measure and arrange the element to ensure it's fully rendered
|
||||||
|
visual.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||||
|
Rect previousBounds = VisualTreeHelper.GetDescendantBounds(visual);
|
||||||
|
visual.Arrange(new Rect(0, 0, visual.ActualWidth, visual.ActualHeight));
|
||||||
|
|
||||||
|
var bitmap = new RenderTargetBitmap(
|
||||||
|
(int)visual.ActualWidth,
|
||||||
|
(int)visual.ActualHeight,
|
||||||
|
96,
|
||||||
|
96,
|
||||||
|
PixelFormats.Pbgra32);
|
||||||
|
|
||||||
bitmap.Render(visual);
|
bitmap.Render(visual);
|
||||||
var frame = BitmapFrame.Create(bitmap);
|
var frame = BitmapFrame.Create(bitmap);
|
||||||
encoder.Frames.Add(frame);
|
encoder.Frames.Add(frame);
|
||||||
using (var stream = File.Create(fileName)) encoder.Save(stream);
|
using (var stream = File.Create(fileName)) encoder.Save(stream);
|
||||||
|
visual.Arrange(previousBounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||||
|
{
|
||||||
|
public abstract class ExportToCSVLogicBase : IExportResultLogic
|
||||||
|
{
|
||||||
|
public string separator => ";";
|
||||||
|
public StringBuilder output { get; } = new();
|
||||||
|
public string FileName { get; set; }
|
||||||
|
|
||||||
|
public void Export()
|
||||||
|
{
|
||||||
|
ExportHeadings();
|
||||||
|
ExportBoby();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.AppendAllText(FileName, output.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Data could not be written to the CSV file.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void ExportBoby();
|
||||||
|
public abstract void ExportHeadings();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user