Add copy to clipboard command for material
This commit is contained in:
@@ -303,7 +303,6 @@
|
||||
</Canvas>
|
||||
</DataTemplate>
|
||||
|
||||
|
||||
<DataTemplate x:Key="ValuePointDiagram">
|
||||
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||
<Canvas.Children>
|
||||
@@ -363,10 +362,60 @@
|
||||
</Canvas>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="ExportToXLS">
|
||||
<DataTemplate x:Key="Image">
|
||||
<Canvas Style="{DynamicResource ButtonResultCanvas}">
|
||||
<Canvas.Children>
|
||||
<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}"/>
|
||||
<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"/>
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace StructureHelper.Services.Exports
|
||||
{
|
||||
internal class ExportToFileInputData : IExportToFileInputData
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string FileName { get; set; } = "New file";
|
||||
public string Filter { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
|
||||
@@ -145,11 +145,12 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
}
|
||||
private void ExportToCSV()
|
||||
{
|
||||
var inputData = new ExportToFileInputData();
|
||||
inputData.FileName = "New File";
|
||||
inputData.Filter = "csv |*.csv";
|
||||
inputData.Title = "Save in csv File";
|
||||
var logic = new ExportForceResultToCSVLogic(forcesResults);
|
||||
var inputData = new ExportToFileInputData
|
||||
{
|
||||
Filter = "csv |*.csv",
|
||||
Title = "Save in *.csv File"
|
||||
};
|
||||
var logic = new ExportForcesResultToCSVLogic(forcesResults);
|
||||
var exportService = new ExportToFileService(inputData, logic);
|
||||
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}"/>
|
||||
</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>
|
||||
<Button Style="{DynamicResource ToolButton}" Command="{Binding ExportToCSVCommand}">
|
||||
<Button.ToolTip>
|
||||
<uc:ButtonToolTipEh HeaderText="Export to *.csv"
|
||||
@@ -35,7 +55,7 @@
|
||||
</Button>
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
<Grid>
|
||||
<Grid x:Name="MainGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="250"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
@@ -97,14 +117,16 @@
|
||||
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=LineVisualProperties}" Content="{Binding VisualProps}"/>
|
||||
</Grid>
|
||||
<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">
|
||||
<lvc:CartesianChart.AxisY>
|
||||
<lvc:Axis Title="y-value"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisY>
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis Title="x-value"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
</lvc:CartesianChart>
|
||||
<Grid Grid.Column="2">
|
||||
<lvc:CartesianChart Name="MainChart" Series="{Binding SeriesCollection}" LegendLocation="Bottom" Zoom="Xy" Background="White">
|
||||
<lvc:CartesianChart.AxisY>
|
||||
<lvc:Axis Title="y-value"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisY>
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis Title="x-value"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace StructureHelper.Windows.Graphs
|
||||
this.vm = vm;
|
||||
InitializeComponent();
|
||||
DataContext = vm;
|
||||
|
||||
var cartesianChart = (CartesianChart)FindName("MainChart");
|
||||
vm.MainChart = cartesianChart;
|
||||
}
|
||||
|
||||
@@ -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})
|
||||
{
|
||||
|
||||
|
||||
@@ -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:local="clr-namespace:StructureHelper.Windows.Graphs"
|
||||
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||
xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls"
|
||||
d:DataContext="{d:DesignInstance local:MaterialDiagramViewModel}"
|
||||
mc:Ignorable="d"
|
||||
Title="Material Diagram" Height="550" Width="800" MinHeight="550" MinWidth="800" WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="250"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<DockPanel>
|
||||
<ToolBarTray DockPanel.Dock="Top">
|
||||
<ToolBar>
|
||||
<Button Style="{StaticResource ToolButton}"
|
||||
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.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="170"/>
|
||||
<RowDefinition Height="30"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel>
|
||||
<Expander Header="Materials" IsExpanded="True">
|
||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding MaterialsModel}"/>
|
||||
</Expander>
|
||||
<Expander Header="Limit States">
|
||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding LimitStatesModel}"/>
|
||||
</Expander>
|
||||
<Expander Header="Calculation terms">
|
||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding CalcTermsModel}"/>
|
||||
</Expander>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="22"/>
|
||||
<RowDefinition Height="22"/>
|
||||
<RowDefinition Height="22"/>
|
||||
<RowDefinition Height="22"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Minimum strain"/>
|
||||
<TextBox Grid.Column="1" Text="{Binding MinValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
||||
<TextBlock Grid.Row="1" Text="Maximum strain"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding MaxValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
||||
<TextBlock Grid.Row="2" Text="Step count"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding StepCount, ValidatesOnDataErrors=True}"/>
|
||||
<TextBlock Grid.Row="3" Text="Positive in tension"/>
|
||||
<CheckBox Grid.Column="1" Grid.Row="3" Margin="4" IsChecked="{Binding PositiveInTension}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=LineVisualProperties}" Content="{Binding VisualProps}"/>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<Button Margin="3" Content="Draw Lines" ToolTip="Draw lines" Command="{Binding RedrawLinesCommand}"/>
|
||||
<Button Margin="3" Content="Show Areas" ToolTip="Area under lines" Command="{Binding GetAreaCommand}"/>
|
||||
</StackPanel>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="250"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="170"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel>
|
||||
<Expander Header="Materials" IsExpanded="True">
|
||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding MaterialsModel}"/>
|
||||
</Expander>
|
||||
<Expander Header="Limit States">
|
||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding LimitStatesModel}"/>
|
||||
</Expander>
|
||||
<Expander Header="Calculation terms">
|
||||
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding CalcTermsModel}"/>
|
||||
</Expander>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="100"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="22"/>
|
||||
<RowDefinition Height="22"/>
|
||||
<RowDefinition Height="22"/>
|
||||
<RowDefinition Height="22"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Minimum strain"/>
|
||||
<TextBox Grid.Column="1" Text="{Binding MinValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
||||
<TextBlock Grid.Row="1" Text="Maximum strain"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding MaxValue, Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
|
||||
<TextBlock Grid.Row="2" Text="Step count"/>
|
||||
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding StepCount, ValidatesOnDataErrors=True}"/>
|
||||
<TextBlock Grid.Row="3" Text="Positive in tension"/>
|
||||
<CheckBox Grid.Column="1" Grid.Row="3" Margin="4" IsChecked="{Binding PositiveInTension}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<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>
|
||||
<lvc:CartesianChart Grid.Column="1" Series="{Binding SeriesCollection}" LegendLocation="Bottom" Zoom="Xy">
|
||||
<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>
|
||||
</DockPanel>
|
||||
</Window>
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace StructureHelper.Windows.MainWindow.Materials
|
||||
this.vm = vm;
|
||||
InitializeComponent();
|
||||
this.DataContext = this.vm;
|
||||
var cartesianChart = (CartesianChart)FindName("MainChart");
|
||||
vm.MainChart = cartesianChart;
|
||||
}
|
||||
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.Models.Materials;
|
||||
using StructureHelper.Windows.ViewModels;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Services.ColorServices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace StructureHelper.Windows.Graphs
|
||||
{
|
||||
@@ -27,16 +24,19 @@ namespace StructureHelper.Windows.Graphs
|
||||
public double Stress { get; set; }
|
||||
}
|
||||
|
||||
private IHeadMaterial material;
|
||||
//private IHeadMaterial material;
|
||||
private ICommand redrawLinesCommand;
|
||||
double minValue;
|
||||
double maxValue;
|
||||
int stepCount;
|
||||
bool positiveInTension;
|
||||
private double minValue = -0.005d;
|
||||
private double maxValue = 0.005d;
|
||||
private int stepCount = 50;
|
||||
bool positiveInTension = true;
|
||||
private ICommand getAreaCommand;
|
||||
private RelayCommand saveImageCommand;
|
||||
private RelayCommand copyToClipboardCommand;
|
||||
private IFrameWorkElementServiseLogic frameWorkElementServiseLogic = new FrameWorkElementServiseLogic();
|
||||
|
||||
public string MaterialName => material.Name;
|
||||
public GraphVisualProps VisualProps { get; }
|
||||
//public string MaterialName => material.Name;
|
||||
public GraphVisualProps VisualProps { get; } = new();
|
||||
public double MinValue
|
||||
{
|
||||
get => minValue;
|
||||
@@ -101,11 +101,29 @@ namespace StructureHelper.Windows.Graphs
|
||||
}, 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)
|
||||
{
|
||||
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 };
|
||||
//this.material = material;
|
||||
SetModels(headMaterials);
|
||||
SetSelectedMaterial(material);
|
||||
SetLines();
|
||||
}
|
||||
|
||||
private void SetSelectedMaterial(IHeadMaterial material)
|
||||
{
|
||||
foreach (var item in MaterialsModel.CollectionItems)
|
||||
{
|
||||
if (item.Item == material)
|
||||
@@ -114,14 +132,24 @@ namespace StructureHelper.Windows.Graphs
|
||||
}
|
||||
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()
|
||||
{
|
||||
var materials = MaterialsModel.SelectedItems;
|
||||
@@ -142,8 +170,12 @@ namespace StructureHelper.Windows.Graphs
|
||||
{
|
||||
double sumStress = 0d;
|
||||
var stressList = values
|
||||
.Where(x => x.LimitState == limitState & x.CalcTerm == calcTerm & x.Material == material).ToList();
|
||||
for (int i = 1; i < stressList.Count(); i++)
|
||||
.Where(x =>
|
||||
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;
|
||||
sumStress += midStress * UnitConstants.Stress * step;
|
||||
|
||||
@@ -20,11 +20,11 @@ namespace StructureHelper.Windows.Graphs
|
||||
{
|
||||
public class Series : ViewModelBase
|
||||
{
|
||||
private IArrayParameter<double> arrayParameter;
|
||||
private List<IValueParameter<double>> valueParameters;
|
||||
private Dictionary<IValueParameter<double>, double[]> valueList;
|
||||
private bool invertXValues;
|
||||
private bool invertYValues;
|
||||
private IArrayParameter<double> arrayParameter1;
|
||||
|
||||
public SelectItemVM<IValueParameter<double>> XItems { get; }
|
||||
public SelectItemsVM<IValueParameter<double>> YItems { get; }
|
||||
@@ -56,12 +56,14 @@ namespace StructureHelper.Windows.Graphs
|
||||
public IArrayParameter<double> ArrayParameter { get; set; }
|
||||
public Series(IArrayParameter<double> arrayParameter)
|
||||
{
|
||||
this.arrayParameter = arrayParameter;
|
||||
this.ArrayParameter = arrayParameter;
|
||||
valueParameters = GetParameters();
|
||||
XItems = new SelectItemVM<IValueParameter<double>>(valueParameters);
|
||||
YItems = new SelectItemsVM<IValueParameter<double>>(valueParameters);
|
||||
YItems.ShowButtons = true;
|
||||
XItems.SelectedItem = XItems.Collection[0];
|
||||
YItems = new SelectItemsVM<IValueParameter<double>>(valueParameters)
|
||||
{
|
||||
ShowButtons = true
|
||||
};
|
||||
YItems.UnSelectAllCommand.Execute(null);
|
||||
VisualProps = new();
|
||||
Color = ColorProcessor.GetRandomColor();
|
||||
@@ -71,13 +73,13 @@ namespace StructureHelper.Windows.Graphs
|
||||
{
|
||||
valueList = new Dictionary<IValueParameter<double>, double[]>();
|
||||
var items = new List<IValueParameter<double>>();
|
||||
var data = arrayParameter.Data;
|
||||
var data = ArrayParameter.Data;
|
||||
int columnCount = data.GetLength(1);
|
||||
for (int i = 0; i < columnCount; i++)
|
||||
{
|
||||
var item = new ValueParameter<double>()
|
||||
{
|
||||
Name = arrayParameter.ColumnLabels[i],
|
||||
Name = ArrayParameter.ColumnLabels[i],
|
||||
Color = ColorProcessor.GetRandomColor(),
|
||||
};
|
||||
items.Add(item);
|
||||
|
||||
@@ -32,10 +32,11 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCa
|
||||
}
|
||||
private void ExportToCSV()
|
||||
{
|
||||
var inputData = new ExportToFileInputData();
|
||||
inputData.FileName = "New File";
|
||||
inputData.Filter = "csv |*.csv";
|
||||
inputData.Title = "Save in csv File";
|
||||
var inputData = new ExportToFileInputData
|
||||
{
|
||||
Filter = "csv |*.csv",
|
||||
Title = "Save in csv File"
|
||||
};
|
||||
var logic = new ExportGeometryResultToCSVLogic(result);
|
||||
var exportService = new ExportToFileService(inputData, logic);
|
||||
exportService.Export();
|
||||
|
||||
@@ -3,38 +3,19 @@ using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
{
|
||||
public class ExportForceResultToCSVLogic : IExportResultLogic
|
||||
public class ExportForcesResultToCSVLogic : ExportToCSVLogicBase
|
||||
{
|
||||
const string separator = ";";
|
||||
StringBuilder output;
|
||||
IForcesResults results;
|
||||
public string FileName { get; set; }
|
||||
|
||||
public void Export()
|
||||
public ExportForcesResultToCSVLogic(IForcesResults results)
|
||||
{
|
||||
ExportHeadings();
|
||||
ExportBoby();
|
||||
try
|
||||
{
|
||||
File.AppendAllText(FileName, output.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Data could not be written to the CSV file.");
|
||||
return;
|
||||
}
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
public ExportForceResultToCSVLogic(IForcesResults forcesResults)
|
||||
{
|
||||
this.results = forcesResults;
|
||||
output = new StringBuilder();
|
||||
}
|
||||
|
||||
private void ExportHeadings()
|
||||
public override void ExportHeadings()
|
||||
{
|
||||
string[] headings =
|
||||
{
|
||||
{
|
||||
"Limit State",
|
||||
"Calc duration",
|
||||
"Mx",
|
||||
@@ -46,7 +27,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
};
|
||||
output.AppendLine(string.Join(separator, headings));
|
||||
}
|
||||
private void ExportBoby()
|
||||
public override void ExportBoby()
|
||||
{
|
||||
foreach (var item in results.ForcesResultList)
|
||||
{
|
||||
@@ -27,12 +27,23 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
|
||||
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);
|
||||
var frame = BitmapFrame.Create(bitmap);
|
||||
encoder.Frames.Add(frame);
|
||||
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