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

View File

@@ -40,6 +40,7 @@
</DataGrid> </DataGrid>
<StackPanel Grid.Column="1"> <StackPanel Grid.Column="1">
<Button Margin="3" Content="Graphic" ToolTip="Show graphic results" Command="{Binding ShowIsoFieldCommand}"/> <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="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="Export" ToolTip="Export results to *.csv" Command="{Binding ExportToCSVCommand}"/>
<Button Margin="3" Content="Set Prestrain" ToolTip="Set strains as auto prestrain" Command="{Binding SetPrestrainCommand}"/> <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) foreach (var primitive in primitiveLogic.Items)
{ {

View File

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

View File

@@ -10,14 +10,20 @@ using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculato
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.GeometryCalculatorViews; using StructureHelper.Windows.CalculationWindows.CalculatorsViews.GeometryCalculatorViews;
using StructureHelper.Windows.Errors; using StructureHelper.Windows.Errors;
using StructureHelper.Windows.Forces; using StructureHelper.Windows.Forces;
using StructureHelper.Windows.Graphs;
using StructureHelper.Windows.PrimitivePropertiesWindow; using StructureHelper.Windows.PrimitivePropertiesWindow;
using StructureHelper.Windows.ViewModels.Errors; using StructureHelper.Windows.ViewModels.Errors;
using StructureHelper.Windows.ViewModels.Forces; using StructureHelper.Windows.ViewModels.Forces;
using StructureHelper.Windows.ViewModels.Graphs;
using StructureHelper.Windows.ViewModels.PrimitiveProperties; using StructureHelper.Windows.ViewModels.PrimitiveProperties;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Infrastructures.Strings; using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.Forces; using StructureHelperCommon.Services.Forces;
using StructureHelperCommon.Services.Units;
using StructureHelperLogics.NdmCalculations.Analyses; using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Analyses.Geometry; using StructureHelperLogics.NdmCalculations.Analyses.Geometry;
@@ -43,6 +49,10 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
private IEnumerable<INdm> ndms; private IEnumerable<INdm> ndms;
private IReport isoFieldReport; 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; } public ForcesTupleResult SelectedResult { get; set; }
private RelayCommand showIsoFieldCommand; private RelayCommand showIsoFieldCommand;
private RelayCommand exportToCSVCommand; private RelayCommand exportToCSVCommand;
@@ -94,6 +104,64 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
exportService.Export(); 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 public RelayCommand InterpolateCommand
{ {
get get

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Forces namespace StructureHelper.Windows.ViewModels.Forces
{ {
public class ForceTuplesViewModel : CRUDViewModelBase<IDesignForceTuple> public class ForceTuplesViewModel : SelectedItemViewModel<IDesignForceTuple>
{ {
public override void AddMethod(object parameter) 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() private void SetLines()
{ {
var materials = MaterialsModel.CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item); var materials = MaterialsModel.SelectedItems;
var limitStates = LimitStatesModel.CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item); var limitStates = LimitStatesModel.SelectedItems;
var calcTerms = CalcTermsModel.CollectionItems.Where(x => x.IsSelected == true).Select(x => x.Item); ; var calcTerms = CalcTermsModel.SelectedItems; ;
var labels = new List<string>(); var labels = new List<string>();
var factor = positiveInTension ? 1d : -1d; var factor = positiveInTension ? 1d : -1d;

View File

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

View File

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

View File

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

View File

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

View File

@@ -86,5 +86,11 @@ namespace StructureHelper.Windows.ViewModels
CollectionItems.Add(new CollectionItem() { IsSelected = true, Item = item }); 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 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 addCommand;
private ICommand deleteCommand; private ICommand deleteCommand;
@@ -115,7 +115,7 @@ namespace StructureHelper.Windows.ViewModels
} }
} }
public CRUDViewModelBase(List<TItem> collection) public SelectedItemViewModel(List<TItem> collection)
{ {
Collection = collection; Collection = collection;
Refresh(); Refresh();
@@ -126,7 +126,7 @@ namespace StructureHelper.Windows.ViewModels
OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(Items));
AfterItemsEdit?.Invoke(this, new CRUDVMEventArgs()); 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; public event CRUDHandler? AfterItemsEdit;
} }
} }

View File

@@ -0,0 +1,37 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Parameters
{
public class ArrayParameter<T> : IArrayParameter<T>
{
private string[] columnLabels;
public string[] ColumnLabels
{
get { return columnLabels; }
set
{
var labelCount = value.Count();
var columnCount = Data.GetLength(1);
if (labelCount != columnCount)
{
throw new StructureHelperException(ErrorStrings.IncorrectValue + $" of label count: expected {columnCount}, but was {labelCount}");
}
columnLabels = value;
}
}
public T[,] Data { get; private set; }
public ArrayParameter(int rowCount, int columnCount, string[] columnLabels = null)
{
Data = new T[rowCount, columnCount];
if (columnLabels is not null) { ColumnLabels = columnLabels; }
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Parameters
{
public interface IArrayParameter<T>
{
T[,] Data { get; }
string[] ColumnLabels { get; set; }
}
}

View File

@@ -3,16 +3,18 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperCommon.Models.Parameters namespace StructureHelperCommon.Models.Parameters
{ {
public interface ITextParameter public interface IValueParameter<T>
{ {
bool IsValid { get; set; } bool IsValid { get; set; }
string Name { get; set; } string Name { get; set; }
string ShortName { get; set; } string ShortName { get; set; }
Color Color { get; set; }
string MeasurementUnit { get; set; } string MeasurementUnit { get; set; }
double Value { get; set; } T Value { get; set; }
string Description { get; set; } string Description { get; set; }
} }
} }

View File

@@ -3,16 +3,18 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperCommon.Models.Parameters namespace StructureHelperCommon.Models.Parameters
{ {
public class TextParameter : ITextParameter public class ValueParameter<T> : IValueParameter<T>
{ {
public bool IsValid { get; set; } public bool IsValid { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string ShortName { get; set; } public string ShortName { get; set; }
public Color Color { get; set; }
public string MeasurementUnit { get; set; } public string MeasurementUnit { get; set; }
public double Value { get; set; } public T Value { get; set; }
public string Description { get; set; } public string Description { get; set; }
} }
} }

View File

@@ -7,12 +7,22 @@ namespace StructureHelperCommon.Services.ColorServices
{ {
public static class ColorProcessor public static class ColorProcessor
{ {
private static readonly Random random = new Random();
public static Color GetRandomColor() public static Color GetRandomColor()
{ {
var randomR = new Random(new Random((int)DateTime.Now.Ticks % 1000).Next(50)).Next(0, 255); int r = random.Next(0, 255);
var randomG = new Random(new Random((int)DateTime.Now.Ticks % 200).Next(100, 200)).Next(0, 255); int g = random.Next(0, 255);
var randomB = new Random(new Random((int)DateTime.Now.Ticks % 50).Next(500, 1000)).Next(0, 255); int b = random.Next(0, 255);
return Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB);
// check, that colors are different
while (Math.Abs(r - g) < 30 || Math.Abs(g - b) < 30 || Math.Abs(b - r) < 30)
{
r = random.Next(0, 255);
g = random.Next(0, 255);
b = random.Next(0, 255);
}
return Color.FromRgb((byte)r, (byte)g, (byte)b);
} }
public static void EditColor(ref Color wpfColor) public static void EditColor(ref Color wpfColor)
{ {

View File

@@ -9,13 +9,15 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
{ {
internal class ForceLogic : IForceLogic internal class ForceLogic : IForceLogic
{ {
public IEnumerable<IForceCombinationList> GetCombinationList() public IEnumerable<IForceAction> GetCombinationList()
{ {
var combinations = new List<IForceCombinationList>(); var combinations = new List<IForceAction>();
var combination = new ForceCombinationList() { Name = "New Force Action"}; var combination = new ForceCombinationList() { Name = "New Force Action"};
combination.DesignForces.Clear(); combination.DesignForces.Clear();
combination.DesignForces.AddRange(ForceCombinationListFactory.GetDesignForces(DesignForceType.Suit_1)); combination.DesignForces.AddRange(ForceCombinationListFactory.GetDesignForces(DesignForceType.Suit_1));
combinations.Add(combination); combinations.Add(combination);
var factorCombination = new ForceCombinationByFactor();
combinations.Add(factorCombination);
return combinations; return combinations;
} }
} }

View File

@@ -9,6 +9,6 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
{ {
internal interface IForceLogic internal interface IForceLogic
{ {
IEnumerable<IForceCombinationList> GetCombinationList(); IEnumerable<IForceAction> GetCombinationList();
} }
} }

View File

@@ -19,7 +19,7 @@ namespace StructureHelperLogics.Models.Templates.CrossSections.RCs
IRCGeometryLogic geometryLogic; IRCGeometryLogic geometryLogic;
ICalculatorLogic calculatorLogic; ICalculatorLogic calculatorLogic;
IEnumerable<INdmPrimitive> primitives; IEnumerable<INdmPrimitive> primitives;
IEnumerable<IForceCombinationList> combinations; IEnumerable<IForceAction> combinations;
IEnumerable<INdmCalculator> calculators; IEnumerable<INdmCalculator> calculators;
public SectionTemplate(IRCGeometryLogic geometryLogic) public SectionTemplate(IRCGeometryLogic geometryLogic)

View File

@@ -83,6 +83,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
{ {
bucklingCalculator.Run(); bucklingCalculator.Run();
var bucklingResult = bucklingCalculator.Result as IConcreteBucklingResult; var bucklingResult = bucklingCalculator.Result as IConcreteBucklingResult;
if (bucklingResult.IsValid != true) if (bucklingResult.IsValid != true)
{ {
result.IsValid = false; result.IsValid = false;
@@ -107,6 +108,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
Result = ndmResult; Result = ndmResult;
} }
private void GetCombinations() private void GetCombinations()
{ {
ForceCombinationLists = new List<IForceCombinationList>(); ForceCombinationLists = new List<IForceCombinationList>();

View File

@@ -10,7 +10,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.Geometry
public class GeometryResult : IGeometryResult public class GeometryResult : IGeometryResult
{ {
public bool IsValid { get; set; } public bool IsValid { get; set; }
public List<ITextParameter> TextParameters { get; set; } public List<IValueParameter<string>> TextParameters { get; set; }
public string Description { get; set; } public string Description { get; set; }
} }
} }

View File

@@ -9,6 +9,6 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.Geometry
{ {
public interface IGeometryResult : INdmResult public interface IGeometryResult : INdmResult
{ {
List<ITextParameter> TextParameters { get; set; } List<IValueParameter<string>> TextParameters { get; set; }
} }
} }

View File

@@ -23,9 +23,9 @@ namespace StructureHelperLogics.Services.NdmPrimitives
static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection(); static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
private IEnumerable<INdm> ndms; private IEnumerable<INdm> ndms;
private IStrainMatrix strainMatrix; private IStrainMatrix strainMatrix;
public List<ITextParameter> GetTextParameters() public List<IValueParameter<string>> GetTextParameters()
{ {
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
parameters.AddRange(GetGravityCenter(prefixInitial, ndms)); parameters.AddRange(GetGravityCenter(prefixInitial, ndms));
parameters.AddRange(GetSimpleArea(ndms)); parameters.AddRange(GetSimpleArea(ndms));
parameters.AddRange(GetArea(prefixInitial, ndms)); parameters.AddRange(GetArea(prefixInitial, ndms));
@@ -38,15 +38,15 @@ namespace StructureHelperLogics.Services.NdmPrimitives
return parameters; return parameters;
} }
private IEnumerable<ITextParameter> GetSimpleArea(IEnumerable<INdm> ndms) private IEnumerable<IValueParameter<string>> GetSimpleArea(IEnumerable<INdm> ndms)
{ {
const string name = "Summary Area"; const string name = "Summary Area";
const string shortName = "A"; const string shortName = "A";
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2"); var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2");
var unitName = $"{unitArea.Name}"; var unitName = $"{unitArea.Name}";
var unitMultiPlayer = unitArea.Multiplyer; var unitMultiPlayer = unitArea.Multiplyer;
var firstParameter = new TextParameter() var firstParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{name}", Name = $"{name}",
@@ -56,28 +56,28 @@ namespace StructureHelperLogics.Services.NdmPrimitives
}; };
try try
{ {
firstParameter.Value = ndms.Sum(x => x.Area) * unitMultiPlayer; firstParameter.Value = (ndms.Sum(x => x.Area) * unitMultiPlayer).ToString();
} }
catch (Exception ex) catch (Exception ex)
{ {
firstParameter.IsValid = false; firstParameter.IsValid = false;
firstParameter.Value = double.NaN; firstParameter.Value = (double.NaN).ToString();
firstParameter.Description += $": {ex}"; firstParameter.Description += $": {ex}";
} }
parameters.Add(firstParameter); parameters.Add(firstParameter);
return parameters; return parameters;
} }
private IEnumerable<ITextParameter> GetMomentOfInertia(string prefix, IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null) private IEnumerable<IValueParameter<string>> GetMomentOfInertia(string prefix, IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null)
{ {
const string name = "Bending stiffness"; const string name = "Bending stiffness";
const string shortName = "EI"; const string shortName = "EI";
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2"); var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2");
var unitStress = CommonOperation.GetUnit(UnitTypes.Stress, "MPa"); var unitStress = CommonOperation.GetUnit(UnitTypes.Stress, "MPa");
var unitName = $"{unitStress.Name} * {unitArea.Name} * {unitArea.Name}"; var unitName = $"{unitStress.Name} * {unitArea.Name} * {unitArea.Name}";
var unitMultiPlayer = unitArea.Multiplyer * unitArea.Multiplyer * unitStress.Multiplyer; var unitMultiPlayer = unitArea.Multiplyer * unitArea.Multiplyer * unitStress.Multiplyer;
var firstParameter = new TextParameter() var firstParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefix} {name} {firstAxisName.ToUpper()}", Name = $"{prefix} {name} {firstAxisName.ToUpper()}",
@@ -85,7 +85,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
MeasurementUnit = unitName, MeasurementUnit = unitName,
Description = $"{prefix} {name} of cross-section arbitrary {firstAxisName}-axis multiplied by {prefix} modulus" Description = $"{prefix} {name} of cross-section arbitrary {firstAxisName}-axis multiplied by {prefix} modulus"
}; };
var secondParameter = new TextParameter() var secondParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefix} {name} {secondAxisName}", Name = $"{prefix} {name} {secondAxisName}",
@@ -96,28 +96,28 @@ namespace StructureHelperLogics.Services.NdmPrimitives
try try
{ {
var gravityCenter = GeometryOperations.GetReducedMomentsOfInertia(locNdms, locStrainMatrix); var gravityCenter = GeometryOperations.GetReducedMomentsOfInertia(locNdms, locStrainMatrix);
firstParameter.Value = gravityCenter.MomentX * unitMultiPlayer; firstParameter.Value = (gravityCenter.MomentX * unitMultiPlayer).ToString();
secondParameter.Value = gravityCenter.MomentY * unitMultiPlayer; secondParameter.Value = (gravityCenter.MomentY * unitMultiPlayer).ToString();
} }
catch (Exception ex) catch (Exception ex)
{ {
firstParameter.IsValid = false; firstParameter.IsValid = false;
firstParameter.Value = double.NaN; firstParameter.Value = (double.NaN).ToString();
firstParameter.Description += $": {ex}"; firstParameter.Description += $": {ex}";
secondParameter.IsValid = false; secondParameter.IsValid = false;
secondParameter.Value = double.NaN; secondParameter.Value = (double.NaN).ToString();
secondParameter.Description += $": {ex}"; secondParameter.Description += $": {ex}";
} }
parameters.Add(firstParameter); parameters.Add(firstParameter);
parameters.Add(secondParameter); parameters.Add(secondParameter);
return parameters; return parameters;
} }
private IEnumerable<ITextParameter> GetMomentOfInertiaRatio(IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null) private IEnumerable<IValueParameter<string>> GetMomentOfInertiaRatio(IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null)
{ {
const string name = "Bending stiffness"; const string name = "Bending stiffness";
const string shortName = "EI"; const string shortName = "EI";
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
var firstParameter = new TextParameter() var firstParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefixActual}/{prefixInitial} {name} {firstAxisName.ToUpper()} ratio", Name = $"{prefixActual}/{prefixInitial} {name} {firstAxisName.ToUpper()} ratio",
@@ -125,7 +125,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
MeasurementUnit = "-", MeasurementUnit = "-",
Description = $"{prefixActual}/{prefixInitial} {name} of cross-section arbitrary {firstAxisName}-axis ratio" Description = $"{prefixActual}/{prefixInitial} {name} of cross-section arbitrary {firstAxisName}-axis ratio"
}; };
var secondParameter = new TextParameter() var secondParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefixActual}/{prefixInitial} {name} {secondAxisName} ratio", Name = $"{prefixActual}/{prefixInitial} {name} {secondAxisName} ratio",
@@ -137,32 +137,32 @@ namespace StructureHelperLogics.Services.NdmPrimitives
{ {
var initialMoments = GeometryOperations.GetReducedMomentsOfInertia(locNdms); var initialMoments = GeometryOperations.GetReducedMomentsOfInertia(locNdms);
var actualMoments = GeometryOperations.GetReducedMomentsOfInertia(locNdms, locStrainMatrix); var actualMoments = GeometryOperations.GetReducedMomentsOfInertia(locNdms, locStrainMatrix);
firstParameter.Value = actualMoments.MomentX / initialMoments.MomentX; firstParameter.Value = (actualMoments.MomentX / initialMoments.MomentX).ToString();
secondParameter.Value = actualMoments.MomentY / initialMoments.MomentY; secondParameter.Value = (actualMoments.MomentY / initialMoments.MomentY).ToString();
} }
catch (Exception ex) catch (Exception ex)
{ {
firstParameter.IsValid = false; firstParameter.IsValid = false;
firstParameter.Value = double.NaN; firstParameter.Value = (double.NaN).ToString();
firstParameter.Description += $": {ex}"; firstParameter.Description += $": {ex}";
secondParameter.IsValid = false; secondParameter.IsValid = false;
secondParameter.Value = double.NaN; secondParameter.Value = (double.NaN).ToString();
secondParameter.Description += $": {ex}"; secondParameter.Description += $": {ex}";
} }
parameters.Add(firstParameter); parameters.Add(firstParameter);
parameters.Add(secondParameter); parameters.Add(secondParameter);
return parameters; return parameters;
} }
private IEnumerable<ITextParameter> GetArea(string prefix, IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null) private IEnumerable<IValueParameter<string>> GetArea(string prefix, IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null)
{ {
const string name = "Longitudinal stiffness"; const string name = "Longitudinal stiffness";
const string shortName = "EA"; const string shortName = "EA";
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2"); var unitArea = CommonOperation.GetUnit(UnitTypes.Area, "mm2");
var unitStress = CommonOperation.GetUnit(UnitTypes.Stress, "MPa"); var unitStress = CommonOperation.GetUnit(UnitTypes.Stress, "MPa");
var unitName = $"{unitStress.Name} * {unitArea.Name}" ; var unitName = $"{unitStress.Name} * {unitArea.Name}" ;
var unitMultiPlayer = unitArea.Multiplyer * unitStress.Multiplyer; var unitMultiPlayer = unitArea.Multiplyer * unitStress.Multiplyer;
var firstParameter = new TextParameter() var firstParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefix} {name}", Name = $"{prefix} {name}",
@@ -172,23 +172,23 @@ namespace StructureHelperLogics.Services.NdmPrimitives
}; };
try try
{ {
firstParameter.Value = GeometryOperations.GetReducedArea(locNdms, locStrainMatrix) * unitMultiPlayer; firstParameter.Value = (GeometryOperations.GetReducedArea(locNdms, locStrainMatrix) * unitMultiPlayer).ToString();
} }
catch (Exception ex) catch (Exception ex)
{ {
firstParameter.IsValid = false; firstParameter.IsValid = false;
firstParameter.Value = double.NaN; firstParameter.Value = (double.NaN).ToString();
firstParameter.Description += $": {ex}"; firstParameter.Description += $": {ex}";
} }
parameters.Add(firstParameter); parameters.Add(firstParameter);
return parameters; return parameters;
} }
private IEnumerable<ITextParameter> GetAreaRatio(IEnumerable<INdm> locNdms, IStrainMatrix locStrainMatrix) private IEnumerable<IValueParameter<string>> GetAreaRatio(IEnumerable<INdm> locNdms, IStrainMatrix locStrainMatrix)
{ {
const string name = "Longitudinal stiffness"; const string name = "Longitudinal stiffness";
const string shortName = "EA"; const string shortName = "EA";
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
var firstParameter = new TextParameter() var firstParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefixActual}/{prefixInitial} {name} ratio", Name = $"{prefixActual}/{prefixInitial} {name} ratio",
@@ -200,12 +200,12 @@ namespace StructureHelperLogics.Services.NdmPrimitives
{ {
var actual = GeometryOperations.GetReducedArea(locNdms, locStrainMatrix); var actual = GeometryOperations.GetReducedArea(locNdms, locStrainMatrix);
var initial = GeometryOperations.GetReducedArea(locNdms); var initial = GeometryOperations.GetReducedArea(locNdms);
firstParameter.Value = actual / initial; firstParameter.Value = (actual / initial).ToString();
} }
catch (Exception ex) catch (Exception ex)
{ {
firstParameter.IsValid = false; firstParameter.IsValid = false;
firstParameter.Value = double.NaN; firstParameter.Value = (double.NaN).ToString();
firstParameter.Description += $": {ex}"; firstParameter.Description += $": {ex}";
} }
parameters.Add(firstParameter); parameters.Add(firstParameter);
@@ -216,14 +216,14 @@ namespace StructureHelperLogics.Services.NdmPrimitives
this.ndms = ndms; this.ndms = ndms;
this.strainMatrix = strainMatrix; this.strainMatrix = strainMatrix;
} }
private IEnumerable<ITextParameter> GetGravityCenter(string prefix, IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null) private IEnumerable<IValueParameter<string>> GetGravityCenter(string prefix, IEnumerable<INdm> locNdms, IStrainMatrix? locStrainMatrix = null)
{ {
var parameters = new List<ITextParameter>(); var parameters = new List<IValueParameter<string>>();
var unitType = UnitTypes.Length; var unitType = UnitTypes.Length;
var unit = CommonOperation.GetUnit(unitType, "mm"); var unit = CommonOperation.GetUnit(unitType, "mm");
var unitName = unit.Name; var unitName = unit.Name;
var unitMultiPlayer = unit.Multiplyer; var unitMultiPlayer = unit.Multiplyer;
var firstParameter = new TextParameter() var firstParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefix} Center{firstAxisName.ToUpper()}", Name = $"{prefix} Center{firstAxisName.ToUpper()}",
@@ -231,7 +231,7 @@ namespace StructureHelperLogics.Services.NdmPrimitives
MeasurementUnit = unitName, MeasurementUnit = unitName,
Description = $"{prefix} Displacement of center of gravity of cross-section along {firstAxisName}-axis" Description = $"{prefix} Displacement of center of gravity of cross-section along {firstAxisName}-axis"
}; };
var secondParameter = new TextParameter() var secondParameter = new ValueParameter<string>()
{ {
IsValid = true, IsValid = true,
Name = $"{prefix} Center{secondAxisName.ToUpper()}", Name = $"{prefix} Center{secondAxisName.ToUpper()}",
@@ -242,16 +242,16 @@ namespace StructureHelperLogics.Services.NdmPrimitives
try try
{ {
var gravityCenter = GeometryOperations.GetGravityCenter(locNdms, locStrainMatrix); var gravityCenter = GeometryOperations.GetGravityCenter(locNdms, locStrainMatrix);
firstParameter.Value = gravityCenter.CenterX * unitMultiPlayer; firstParameter.Value = (gravityCenter.CenterX * unitMultiPlayer).ToString();
secondParameter.Value = gravityCenter.CenterY * unitMultiPlayer; secondParameter.Value = (gravityCenter.CenterY * unitMultiPlayer).ToString();
} }
catch (Exception ex) catch (Exception ex)
{ {
firstParameter.IsValid = false; firstParameter.IsValid = false;
firstParameter.Value = double.NaN; firstParameter.Value = (double.NaN).ToString();
firstParameter.Description += $": {ex}"; firstParameter.Description += $": {ex}";
secondParameter.IsValid = false; secondParameter.IsValid = false;
secondParameter.Value = double.NaN; secondParameter.Value = (double.NaN).ToString();
secondParameter.Description += $": {ex}"; secondParameter.Description += $": {ex}";
} }
parameters.Add(firstParameter); parameters.Add(firstParameter);

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using StructureHelper.Windows.ViewModels.Graphs;
using StructureHelperCommon.Models.Parameters;
namespace StructureHelperTests.ViewModelTests
{
internal class GraphViewModelTest
{
[TestCase(2, 3)]
[TestCase(2, 4)]
[TestCase(3, 3)]
public void RunShouldPass(int rowCount, int columnCount)
{
//Arrange
string[] labels = new string[columnCount];
for (int i = 0; i < columnCount; i++)
{
labels[i] = $"Column{i}";
}
var array = new ArrayParameter<double>(rowCount, columnCount, labels);
for (int i = 0; i < columnCount; i++)
{
for (int j = 0; j < rowCount; j++)
{
array.Data[j, i] = i + 2 * j;
}
}
//Act
var vm = new GraphViewModel(array);
//Assert
Assert.IsNotNull(vm);
Assert.AreEqual(columnCount, vm.XItems.Collection.Count());
Assert.AreEqual(columnCount, vm.YItems.CollectionItems.Count());
}
}
}