Tools for graphs were added

This commit is contained in:
Evgeny Redikultsev
2023-05-06 21:10:02 +05:00
parent 3cb6e60fc9
commit 79c24f2cd5
31 changed files with 553 additions and 77 deletions

View File

@@ -18,6 +18,9 @@
<Compile Update="Windows\Forces\ForceCombinationByFactorView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\Graphs\GraphView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\MainWindow\AboutView.xaml.cs">
<SubType>Code</SubType>
</Compile>
@@ -47,6 +50,9 @@
<Page Update="Windows\Forces\ForceCombinationByFactorView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\Graphs\GraphView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\MainWindow\AboutView.xaml">
<SubType>Designer</SubType>
</Page>

View File

@@ -40,6 +40,7 @@
</DataGrid>
<StackPanel Grid.Column="1">
<Button Margin="3" Content="Graphic" ToolTip="Show graphic results" Command="{Binding ShowIsoFieldCommand}"/>
<Button Margin="3" Content="Diagrams" ToolTip="Show diagrams" Command="{Binding ShowGraphsCommand}"/>
<Button Margin="3" Content="Interpolate" ToolTip="Create analysis by substep" Command="{Binding InterpolateCommand}"/>
<Button Margin="3" Content="Export" ToolTip="Export results to *.csv" Command="{Binding ExportToCSVCommand}"/>
<Button Margin="3" Content="Set Prestrain" ToolTip="Set strains as auto prestrain" Command="{Binding SetPrestrainCommand}"/>

View File

@@ -0,0 +1,73 @@
<Window x:Class="StructureHelper.Windows.Graphs.GraphView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:StructureHelper.Windows.Graphs"
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Graphs"
d:DataContext="{d:DesignInstance vm:GraphViewModel}"
mc:Ignorable="d"
Title="Graph" Height="450" Width="800" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<StackPanel>
<GroupBox Header="X-axis values">
<StackPanel>
<ComboBox ItemsSource="{Binding XItems.Collection}" SelectedItem="{Binding XItems.SelectedItem}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Margin="3">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Color}"/>
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Margin="5" Content="Invert Values" IsChecked="{Binding InvertXValues}"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Y-axis values">
<StackPanel>
<ContentControl ContentTemplate="{StaticResource ResourceKey=SelectItems}" Content="{Binding YItems}"/>
<CheckBox Margin="5" Content="Invert Values" IsChecked="{Binding InvertYValues}"/>
</StackPanel>
</GroupBox>
<GroupBox Header="Line smoothness">
<StackPanel Orientation="Horizontal">
<Slider x:Name="slider" Width="195" Minimum="0" Maximum="1" Value="{Binding LineSmoothness}"/>
<TextBox Width="40" Text="{Binding LineSmoothness,Converter={StaticResource PlainDouble}, ValidatesOnDataErrors=True}"/>
</StackPanel>
</GroupBox>
</StackPanel>
<StackPanel Grid.Row="1">
<Button Margin="3" Content="Draw Lines" ToolTip="Draw Lines" Command="{Binding RedrawLinesCommand}"/>
</StackPanel>
</Grid>
<lvc:CartesianChart Grid.Column="1" Series="{Binding SeriesCollection}" LegendLocation="Bottom" >
<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>
</Window>

View File

@@ -0,0 +1,31 @@
using StructureHelper.Windows.ViewModels.Graphs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace StructureHelper.Windows.Graphs
{
/// <summary>
/// Логика взаимодействия для GraphView.xaml
/// </summary>
public partial class GraphView : Window
{
GraphViewModel vm;
public GraphView(GraphViewModel vm)
{
this.vm = vm;
InitializeComponent();
DataContext = vm;
}
}
}

View File

@@ -328,7 +328,7 @@ namespace StructureHelper.Windows.MainWindow
});
}
private void afterMaterialEdit(CRUDViewModelBase<IHeadMaterial> sender, CRUDVMEventArgs e)
private void afterMaterialEdit(SelectedItemViewModel<IHeadMaterial> sender, CRUDVMEventArgs e)
{
foreach (var primitive in primitiveLogic.Items)
{

View File

@@ -17,7 +17,7 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel>
@@ -52,9 +52,7 @@
</Grid>
</StackPanel>
</ScrollViewer>
<StackPanel Grid.Row="1" Orientation="Horizontal" FlowDirection="RightToLeft">
<Button Content="Redraw Lines" Command="{Binding RedrawLinesCommand}"/>
</StackPanel>
<Button Grid.Row="1" Margin="3" Content="Draw Lines" ToolTip="Draw lines" Command="{Binding RedrawLinesCommand}"/>
</Grid>
<lvc:CartesianChart Grid.Column="1" Series="{Binding SeriesCollection}" LegendLocation="Bottom" >
<lvc:CartesianChart.AxisY>

View File

@@ -10,14 +10,20 @@ using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculato
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.GeometryCalculatorViews;
using StructureHelper.Windows.Errors;
using StructureHelper.Windows.Forces;
using StructureHelper.Windows.Graphs;
using StructureHelper.Windows.PrimitivePropertiesWindow;
using StructureHelper.Windows.ViewModels.Errors;
using StructureHelper.Windows.ViewModels.Forces;
using StructureHelper.Windows.ViewModels.Graphs;
using StructureHelper.Windows.ViewModels.PrimitiveProperties;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.Forces;
using StructureHelperCommon.Services.Units;
using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Analyses.Geometry;
@@ -43,6 +49,10 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
private IEnumerable<INdm> ndms;
private IReport isoFieldReport;
static string firstAxisName => ProgramSetting.CrossSectionAxisNames.FirstAxis;
static string secondAxisName => ProgramSetting.CrossSectionAxisNames.SecondAxis;
static string thirdAxisName => ProgramSetting.CrossSectionAxisNames.ThirdAxis;
public ForcesTupleResult SelectedResult { get; set; }
private RelayCommand showIsoFieldCommand;
private RelayCommand exportToCSVCommand;
@@ -94,6 +104,64 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
exportService.Export();
}
private ICommand showGraphsCommand;
public ICommand ShowGraphsCommand
{
get => showGraphsCommand ??= new RelayCommand(o => showGraphs());
}
private void showGraphs()
{
var unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN");
var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm");
var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m");
var labels = new string[]
{
$"M{firstAxisName}, {unitMoment.Name}",
$"M{secondAxisName}, {unitMoment.Name}",
$"N{thirdAxisName}, {unitForce.Name}",
$"K{firstAxisName}, {unitCurvature.Name}",
$"K{secondAxisName}, {unitCurvature.Name}",
$"Eps_{thirdAxisName}"
};
var resultList = forcesResults.ForcesResultList.Where(x => x.IsValid == true).ToList();
var array = new ArrayParameter<double>(resultList.Count(), labels.Count(), labels);
var data = array.Data;
for (int i = 0; i < resultList.Count(); i++)
{
var valueList = new List<double>
{
resultList[i].DesignForceTuple.ForceTuple.Mx * unitMoment.Multiplyer,
resultList[i].DesignForceTuple.ForceTuple.My * unitMoment.Multiplyer,
resultList[i].DesignForceTuple.ForceTuple.Nz * unitForce.Multiplyer,
resultList[i].LoaderResults.ForceStrainPair.StrainMatrix.Kx * unitCurvature.Multiplyer,
resultList[i].LoaderResults.ForceStrainPair.StrainMatrix.Ky * unitCurvature.Multiplyer,
resultList[i].LoaderResults.ForceStrainPair.StrainMatrix.EpsZ
};
for (int j = 0; j < valueList.Count(); j++)
{
data[i, j] = valueList[j];
}
}
var graphViewModel = new GraphViewModel(array);
var wnd = new GraphView(graphViewModel);
try
{
wnd.ShowDialog();
}
catch(Exception ex)
{
var vm = new ErrorProcessor()
{
ShortText = "Errors apearred during showing isofield, see detailed information",
DetailText = $"{ex}"
};
new ErrorMessage(vm).ShowDialog();
}
}
public RelayCommand InterpolateCommand
{
get

View File

@@ -18,7 +18,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCa
IGeometryResult result;
private ICommand exportToCSVCommand;
public List<ITextParameter> TextParameters
public List<IValueParameter<string>> TextParameters
{
get => result.TextParameters;
}

View File

@@ -14,7 +14,7 @@ using System.Windows.Forms;
namespace StructureHelper.Windows.ViewModels.Forces
{
public class ActionsViewModel : CRUDViewModelBase<IForceAction>
public class ActionsViewModel : SelectedItemViewModel<IForceAction>
{
ICrossSectionRepository repository;
@@ -41,7 +41,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
var dialogResult = MessageBox.Show("Delete action?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
DeleteAction();
if (DeleteAction() != true) return;
base.DeleteMethod(parameter);
}
}
@@ -71,8 +71,9 @@ namespace StructureHelper.Windows.ViewModels.Forces
this.repository = repository;
}
private void DeleteAction()
private bool DeleteAction()
{
bool result = true;
var calcRepository = repository.CalculatorsList;
foreach (var item in calcRepository)
{
@@ -83,11 +84,15 @@ namespace StructureHelper.Windows.ViewModels.Forces
if (containSelected)
{
var dialogResultCalc = MessageBox.Show($"Action is contained in calculator {item.Name}", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResultCalc == DialogResult.OK) { forceCalculator.ForceActions.Remove(SelectedItem); }
else return;
if (dialogResultCalc == DialogResult.Yes)
{
forceCalculator.ForceActions.Remove(SelectedItem);
}
else result = false;
}
}
}
return result;
}
}
}

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Forces
{
public class ForceTuplesViewModel : CRUDViewModelBase<IDesignForceTuple>
public class ForceTuplesViewModel : SelectedItemViewModel<IDesignForceTuple>
{
public override void AddMethod(object parameter)
{

View File

@@ -0,0 +1,178 @@
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Wpf;
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.Converters.Units;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.ColorServices;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
namespace StructureHelper.Windows.ViewModels.Graphs
{
public class GraphViewModel : ViewModelBase
{
public class ColumnInfo
{
public string Header { get; set; }
public string BindingPath { get; set; }
}
IArrayParameter<double> arrayParameter;
List<IValueParameter<double>> valueParameters;
Dictionary<IValueParameter<double>, double[]> valueList;
private RelayCommand redrawLinesCommand;
private bool invertXValues;
private bool invertYValues;
public SelectedItemViewModel<IValueParameter<double>> XItems { get; private set; }
public SelectItemsViewModel<IValueParameter<double>> YItems { get; set; }
public ObservableCollection<ColumnInfo> Columns { get; } = new ObservableCollection<ColumnInfo>();
public bool InvertXValues
{
get { return invertXValues; }
set
{
invertXValues = value;
OnPropertyChanged(nameof(InvertXValues));
}
}
public bool InvertYValues
{
get { return invertYValues; }
set
{
invertYValues = value;
OnPropertyChanged(nameof(InvertYValues));
}
}
private double lineSmoothness;
public double LineSmoothness
{
get { return lineSmoothness; }
set
{
value = Math.Max(value, 0d);
value = Math.Min(value, 1d);
value = Math.Round(value, 2);
lineSmoothness = value;
OnPropertyChanged(nameof(LineSmoothness));
}
}
public SeriesCollection SeriesCollection { get; set; }
public List<string> Labels { get; set; }
public Func<double, string> YFormatter { get; set; }
public ICommand RedrawLinesCommand
{
get => redrawLinesCommand ??= new RelayCommand(o => DrawLines());
}
public GraphViewModel(IArrayParameter<double> arrayParameter)
{
this.arrayParameter = arrayParameter;
valueParameters = GetParameters();
XItems = new SelectedItemViewModel<IValueParameter<double>>(valueParameters);
YItems = new SelectItemsViewModel<IValueParameter<double>>(valueParameters);
YItems.ShowButtons = true;
XItems.SelectedItem = XItems.Collection[0];
YItems.UnSelectAllCommand.Execute(null);
lineSmoothness = 0.3d;
}
private List<IValueParameter<double>> GetParameters()
{
valueList = new Dictionary<IValueParameter<double>, double[]>();
var items = new List<IValueParameter<double>>();
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],
Color = ColorProcessor.GetRandomColor(),
};
items.Add(item);
int rowCount = data.GetLength(0);
var values = new double[rowCount];
for (int j = 0; j < rowCount; j++)
{
values[j] = data[j, i];
}
valueList.Add(item, values);
}
return items;
}
private void DrawLines()
{
if (XItems.SelectedItem is null || YItems.SelectedCount == 0) return;
SetLines();
OnPropertyChanged(nameof(SeriesCollection));
OnPropertyChanged(nameof(Labels));
}
private void SetLines()
{
var xParameter = XItems.SelectedItem;
var yParameters = YItems.SelectedItems;
var xFactor = invertXValues ? -1d : 1d;
var yFactor = invertYValues ? -1d : 1d;
var labels = new List<double>();
SeriesCollection = new SeriesCollection();
foreach (var yParameter in yParameters)
{
var localLabels = new List<double>();
var lineSeries = new LineSeries()
{
Configuration = new CartesianMapper<IPoint2D>()
.X(point => point.X)
.Y(point => point.Y),
Title = yParameter.Name,
PointGeometry = null,
Stroke = new SolidColorBrush(yParameter.Color),
Fill = Brushes.Transparent,
LineSmoothness = lineSmoothness
};
_ = valueList.TryGetValue(xParameter, out double[] xValues);
_ = valueList.TryGetValue(yParameter, out double[] yValues);
var chartValues = new ChartValues<Point2D>();
for (int i = 0; i < yValues.Count(); i++)
{
double diagramValue = yValues[i] * yFactor;
var x = xValues[i] * xFactor;
var y = yValues[i] * yFactor;
var point = new Point2D() { X = x, Y = y};
chartValues.Add(point);
labels.Add(x);
localLabels.Add(x);
}
lineSeries.Values = chartValues;
//lineSeries.LabelPoint = point => localLabels[(int)point.X].ToString();
SeriesCollection.Add(lineSeries);
}
Labels = labels
.OrderBy(x => x)
.Distinct()
.Select(x => x.ToString())
.ToList();
}
}
}

View File

@@ -105,9 +105,9 @@ namespace StructureHelper.Windows.ViewModels.Materials
private void SetLines()
{
var materials = MaterialsModel.CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item);
var limitStates = LimitStatesModel.CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item);
var calcTerms = CalcTermsModel.CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item); ;
var materials = MaterialsModel.SelectedItems;
var limitStates = LimitStatesModel.SelectedItems;
var calcTerms = CalcTermsModel.SelectedItems; ;
var labels = new List<string>();
var factor = positiveInTension ? 1d : -1d;

View File

@@ -20,7 +20,7 @@ using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.Materials
{
public class MaterialsViewModel : CRUDViewModelBase<IHeadMaterial>
public class MaterialsViewModel : SelectedItemViewModel<IHeadMaterial>
{
ICrossSectionRepository repository;
private ICommand editMaterialsCommand;

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Materials
{
internal class PartialFactorsViewModel : CRUDViewModelBase<IMaterialPartialFactor>
internal class PartialFactorsViewModel : SelectedItemViewModel<IMaterialPartialFactor>
{
public override void AddMethod(object parameter)
{

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Materials
{
internal class SafetyFactorsViewModel : CRUDViewModelBase<IMaterialSafetyFactor>
internal class SafetyFactorsViewModel : SelectedItemViewModel<IMaterialSafetyFactor>
{
private RelayCommand showPartialCommand;

View File

@@ -15,7 +15,7 @@ using System.Windows.Forms;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public class AnalysisVewModelLogic : CRUDViewModelBase<INdmCalculator>
public class AnalysisVewModelLogic : SelectedItemViewModel<INdmCalculator>
{
private ICrossSectionRepository repository;
private RelayCommand runCommand;

View File

@@ -86,5 +86,11 @@ namespace StructureHelper.Windows.ViewModels
CollectionItems.Add(new CollectionItem() { IsSelected = true, Item = item });
}
}
public IEnumerable<TItem> SelectedItems
{
get => CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item);
}
public int SelectedCount => SelectedItems.Count();
}
}

View File

@@ -12,7 +12,7 @@ using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels
{
public abstract class CRUDViewModelBase<TItem> : ViewModelBase, ICRUDViewModel<TItem> where TItem : class
public class SelectedItemViewModel<TItem> : ViewModelBase, ICRUDViewModel<TItem> where TItem : class
{
private ICommand addCommand;
private ICommand deleteCommand;
@@ -115,7 +115,7 @@ namespace StructureHelper.Windows.ViewModels
}
}
public CRUDViewModelBase(List<TItem> collection)
public SelectedItemViewModel(List<TItem> collection)
{
Collection = collection;
Refresh();
@@ -126,7 +126,7 @@ namespace StructureHelper.Windows.ViewModels
OnPropertyChanged(nameof(Items));
AfterItemsEdit?.Invoke(this, new CRUDVMEventArgs());
}
public delegate void CRUDHandler(CRUDViewModelBase<TItem> sender, CRUDVMEventArgs e);
public delegate void CRUDHandler(SelectedItemViewModel<TItem> sender, CRUDVMEventArgs e);
public event CRUDHandler? AfterItemsEdit;
}
}