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;
}
}

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.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperCommon.Models.Parameters
{
public interface ITextParameter
public interface IValueParameter<T>
{
bool IsValid { get; set; }
string Name { get; set; }
string ShortName { get; set; }
Color Color { get; set; }
string MeasurementUnit { get; set; }
double Value { get; set; }
T Value { get; set; }
string Description { get; set; }
}
}

View File

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

View File

@@ -7,12 +7,22 @@ namespace StructureHelperCommon.Services.ColorServices
{
public static class ColorProcessor
{
private static readonly Random random = new Random();
public static Color GetRandomColor()
{
var randomR = new Random(new Random((int)DateTime.Now.Ticks % 1000).Next(50)).Next(0, 255);
var randomG = new Random(new Random((int)DateTime.Now.Ticks % 200).Next(100, 200)).Next(0, 255);
var randomB = new Random(new Random((int)DateTime.Now.Ticks % 50).Next(500, 1000)).Next(0, 255);
return Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB);
int r = random.Next(0, 255);
int g = random.Next(0, 255);
int b = random.Next(0, 255);
// 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)
{

View File

@@ -9,13 +9,15 @@ namespace StructureHelperLogics.Models.Templates.CrossSections
{
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"};
combination.DesignForces.Clear();
combination.DesignForces.AddRange(ForceCombinationListFactory.GetDesignForces(DesignForceType.Suit_1));
combinations.Add(combination);
var factorCombination = new ForceCombinationByFactor();
combinations.Add(factorCombination);
return combinations;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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