From 3b95fab0b2bc7e434ef62d58281418c6a1eedabb Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Sat, 27 Dec 2025 21:59:20 +0500 Subject: [PATCH] Add field 2d viewer --- .../Entities/ColorMaps/ColorMap.cs | 37 +++++ .../ColorMaps/Factories/ColorMapFactory.cs | 10 +- .../Entities/ColorMaps/IColorMap.cs | 1 + .../FieldViewerViewModel.cs | 6 +- .../Windows/UserControls/FieldViewer.xaml | 6 +- .../Windows/UserControls/FieldViewer.xaml.cs | 9 +- .../Windows/UserControls/VerticalLegend.xaml | 3 +- .../Windows/VerticalLegendTemplates.xaml | 4 - .../UI/DataContexts/SelectedPrimitiveSet.cs | 21 +++ .../UI/Resources/ButtonStyles.xaml | 28 ++++ .../CalculationReports/IsoField2DReport.cs | 34 +++++ StructureHelper/StructureHelper.csproj.user | 9 ++ .../ForceCalculatorViews/ColorMapViewModel.cs | 43 ++++++ .../ContourLegendViewModel.cs | 14 ++ .../ContoursRangeViewModel.cs | 61 ++++++++ .../ForcesResultsViewModel.cs | 19 ++- .../IsoField2DViewerView.xaml | 134 ++++++++++++++++++ .../IsoField2DViewerView.xaml.cs | 30 ++++ .../IsoField2DViewerViewModel.cs | 52 +++++++ .../ForceCalculatorViews/IsoFieldSummary.cs | 47 ++++++ .../ForceCalculatorViews/IsoFieldTitle.cs | 27 ++++ .../UserControls/IsoFieldContours.xaml | 21 +++ .../UserControls/IsoFieldContours.xaml.cs | 30 ++++ .../UserControls/IsoFieldVerticalLegend.xaml | 47 ++++++ .../IsoFieldVerticalLegend.xaml.cs | 39 +++++ .../SelectPrimitivesViewModel.cs | 10 +- .../Models/Forces/IStrainTuple.cs | 7 + .../Models/Forces/StrainTuple.cs | 6 +- 28 files changed, 726 insertions(+), 29 deletions(-) delete mode 100644 FieldVisualizer/Windows/VerticalLegendTemplates.xaml create mode 100644 StructureHelper/Infrastructure/UI/DataContexts/SelectedPrimitiveSet.cs create mode 100644 StructureHelper/Services/Reports/CalculationReports/IsoField2DReport.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ColorMapViewModel.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContourLegendViewModel.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContoursRangeViewModel.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerViewModel.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldSummary.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldTitle.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldContours.xaml create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldContours.xaml.cs create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldVerticalLegend.xaml create mode 100644 StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldVerticalLegend.xaml.cs create mode 100644 StructureHelperCommon/Models/Forces/IStrainTuple.cs diff --git a/FieldVisualizer/Entities/ColorMaps/ColorMap.cs b/FieldVisualizer/Entities/ColorMaps/ColorMap.cs index faf1a80..41722d9 100644 --- a/FieldVisualizer/Entities/ColorMaps/ColorMap.cs +++ b/FieldVisualizer/Entities/ColorMaps/ColorMap.cs @@ -2,12 +2,49 @@ using System.Collections.Generic; using System.Windows.Media; using System.Text; +using System.Windows; namespace FieldVisualizer.Entities.ColorMaps { public class ColorMap : IColorMap { + private LinearGradientBrush _gradientBrush; + public string Name { get; set; } public List Colors { get; set; } + + public LinearGradientBrush GradientBrush + { + get + { + if (_gradientBrush == null) + { + _gradientBrush = CreateGradientBrush(); + _gradientBrush.Freeze(); // very important for performance + } + + return _gradientBrush; + } + } + + protected virtual LinearGradientBrush CreateGradientBrush() + { + var brush = new LinearGradientBrush + { + StartPoint = new Point(0, 0), + EndPoint = new Point(1, 0) // horizontal + }; + + int count = Colors.Count; + for (int i = 0; i < count; i++) + { + brush.GradientStops.Add( + new GradientStop( + Colors[i], + (double)i / (count - 1))); + } + + return brush; + } } } diff --git a/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs b/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs index e259a79..0b7b11c 100644 --- a/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs +++ b/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs @@ -32,7 +32,7 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories { ColorMap colorMap = new() { - Name = "LiraSpectrumColorMap" + Name = "Lira Style Spectrum" }; List colors = new(); byte Alpha = 0xff; @@ -55,7 +55,7 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories { ColorMap colorMap = new() { - Name = "FullSpectrumColorMap" + Name = "Full Spectrum" }; List colors = new List(); byte Alpha = 0xff; @@ -78,7 +78,7 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories private static IColorMap GetRedToWhite() { ColorMap colorMap = new ColorMap(); - colorMap.Name = "FullSpectrumColorMap"; + colorMap.Name = "Red To White Spectrum"; List colors = new List(); byte Alpha = 0xff; colors.AddRange(new Color[]{ @@ -91,7 +91,7 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories private static IColorMap GetRedToBlue() { ColorMap colorMap = new ColorMap(); - colorMap.Name = "FullSpectrumColorMap"; + colorMap.Name = "Red To Blue Spectrum"; List colors = new List(); byte Alpha = 0xff; colors.AddRange(new Color[]{ @@ -104,7 +104,7 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories private static IColorMap GetBlueToWhite() { ColorMap colorMap = new ColorMap(); - colorMap.Name = "FullSpectrumColorMap"; + colorMap.Name = "Blue To White Spectrum"; List colors = new List(); byte Alpha = 0xff; colors.AddRange(new Color[]{ diff --git a/FieldVisualizer/Entities/ColorMaps/IColorMap.cs b/FieldVisualizer/Entities/ColorMaps/IColorMap.cs index 0d77ae3..3d19471 100644 --- a/FieldVisualizer/Entities/ColorMaps/IColorMap.cs +++ b/FieldVisualizer/Entities/ColorMaps/IColorMap.cs @@ -9,5 +9,6 @@ namespace FieldVisualizer.Entities.ColorMaps { string Name { get;} List Colors { get; } + LinearGradientBrush GradientBrush { get; } } } diff --git a/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs b/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs index c54a8de..fff0648 100644 --- a/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs +++ b/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs @@ -9,7 +9,6 @@ using FieldVisualizer.Services.ValueRanges; using FieldVisualizer.Windows.UserControls; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Windows.Controls; @@ -249,7 +248,10 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels } private bool PrimitiveValidation() { - if (PrimitiveSet == null || PrimitiveSet.ValuePrimitives.Count() == 0) { return false; } + if (PrimitiveSet == null || PrimitiveSet.ValuePrimitives.Count() == 0) + { + return false; + } else return true; } private void SetColor() diff --git a/FieldVisualizer/Windows/UserControls/FieldViewer.xaml b/FieldVisualizer/Windows/UserControls/FieldViewer.xaml index 960e698..dd88715 100644 --- a/FieldVisualizer/Windows/UserControls/FieldViewer.xaml +++ b/FieldVisualizer/Windows/UserControls/FieldViewer.xaml @@ -32,9 +32,8 @@ - - + @@ -46,7 +45,7 @@ - + @@ -102,7 +101,6 @@ - diff --git a/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs b/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs index 96e6753..720a4a3 100644 --- a/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs +++ b/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs @@ -23,7 +23,14 @@ namespace FieldVisualizer.Windows.UserControls viewModel.Legend = LegendViewer; } - public IPrimitiveSet PrimitiveSet { get => viewModel.PrimitiveSet; set { viewModel.PrimitiveSet = value; } } + public IPrimitiveSet PrimitiveSet + { + get => viewModel.PrimitiveSet; + set + { + viewModel.PrimitiveSet = value; + } + } internal void Refresh() { diff --git a/FieldVisualizer/Windows/UserControls/VerticalLegend.xaml b/FieldVisualizer/Windows/UserControls/VerticalLegend.xaml index 58c8315..1c8c18c 100644 --- a/FieldVisualizer/Windows/UserControls/VerticalLegend.xaml +++ b/FieldVisualizer/Windows/UserControls/VerticalLegend.xaml @@ -9,7 +9,7 @@ - + @@ -44,6 +44,5 @@ - diff --git a/FieldVisualizer/Windows/VerticalLegendTemplates.xaml b/FieldVisualizer/Windows/VerticalLegendTemplates.xaml deleted file mode 100644 index 825650e..0000000 --- a/FieldVisualizer/Windows/VerticalLegendTemplates.xaml +++ /dev/null @@ -1,4 +0,0 @@ - - - \ No newline at end of file diff --git a/StructureHelper/Infrastructure/UI/DataContexts/SelectedPrimitiveSet.cs b/StructureHelper/Infrastructure/UI/DataContexts/SelectedPrimitiveSet.cs new file mode 100644 index 0000000..add81fe --- /dev/null +++ b/StructureHelper/Infrastructure/UI/DataContexts/SelectedPrimitiveSet.cs @@ -0,0 +1,21 @@ +using LoaderCalculator.Data.Matrix; +using LoaderCalculator.Data.Ndms; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.States; +using StructureHelperLogics.NdmCalculations.Primitives; +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureHelper.Infrastructure.UI.DataContexts +{ + public class SelectedPrimitiveSet + { + public List? AllPrimitives { get; set; } + public List? SelectedPrimitives { get; set; } + public List Ndms { get; internal set; } + public IStateCalcTermPair? StateCalcTermPair { get; set; } + public IStrainMatrix StrainMatrix { get; set; } + } +} diff --git a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml index 4f332b9..7348dad 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml @@ -879,4 +879,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StructureHelper/Services/Reports/CalculationReports/IsoField2DReport.cs b/StructureHelper/Services/Reports/CalculationReports/IsoField2DReport.cs new file mode 100644 index 0000000..9196e30 --- /dev/null +++ b/StructureHelper/Services/Reports/CalculationReports/IsoField2DReport.cs @@ -0,0 +1,34 @@ +using StructureHelper.Infrastructure.UI.DataContexts; +using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews; + +namespace StructureHelper.Services.Reports.CalculationReports +{ + public class IsoField2DReport : IIsoFieldReport + { + private SelectedPrimitiveSet primitiveSet; + private IsoField2DViewerViewModel viewModel; + private IsoField2DViewerView view; + + public IsoField2DReport(SelectedPrimitiveSet primitiveSet) + { + this.primitiveSet = primitiveSet; + } + + public void Prepare() + { + viewModel = new(primitiveSet); + view = new(viewModel); + } + + public void Show() + { + Prepare(); + ShowPrepared(); + } + + public void ShowPrepared() + { + view.ShowDialog(); + } + } +} diff --git a/StructureHelper/StructureHelper.csproj.user b/StructureHelper/StructureHelper.csproj.user index b809350..c00d91d 100644 --- a/StructureHelper/StructureHelper.csproj.user +++ b/StructureHelper/StructureHelper.csproj.user @@ -72,6 +72,9 @@ Code + + Code + Code @@ -162,6 +165,12 @@ Code + + Code + + + Code + Code diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ColorMapViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ColorMapViewModel.cs new file mode 100644 index 0000000..1f815ae --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ColorMapViewModel.cs @@ -0,0 +1,43 @@ +using FieldVisualizer.Entities.ColorMaps; +using FieldVisualizer.Entities.ColorMaps.Factories; +using StructureHelper.Infrastructure; +using System; +using System.Collections.Generic; +using System.Drawing.Imaging; +using System.Text; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + public class ColorMapViewModel : ViewModelBase + { + private IsoField2DViewerViewModel isoField2DViewerViewModel; + private IColorMap selectedColorMap; + + public List ColorMaps { get; set; } + public IColorMap SelectedColorMap + { + get => selectedColorMap; + set + { + selectedColorMap = value; + Refresh(); + } + } + public ColorMapViewModel(IsoField2DViewerViewModel isoField2DViewerViewModel) + { + this.isoField2DViewerViewModel = isoField2DViewerViewModel; + ColorMaps = []; + ColorMaps.Add(ColorMapFactory.GetColorMap(ColorMapsTypes.LiraSpectrum)); + ColorMaps.Add(ColorMapFactory.GetColorMap(ColorMapsTypes.FullSpectrum)); + ColorMaps.Add(ColorMapFactory.GetColorMap(ColorMapsTypes.RedToWhite)); + ColorMaps.Add(ColorMapFactory.GetColorMap(ColorMapsTypes.RedToBlue)); + ColorMaps.Add(ColorMapFactory.GetColorMap(ColorMapsTypes.BlueToWhite)); + SelectedColorMap = ColorMaps[0]; + } + private void Refresh() + { + isoField2DViewerViewModel.Refresh(); + } + + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContourLegendViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContourLegendViewModel.cs new file mode 100644 index 0000000..d746c49 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContourLegendViewModel.cs @@ -0,0 +1,14 @@ +using FieldVisualizer.Entities.ColorMaps; +using StructureHelper.Infrastructure; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + public class ContourLegendViewModel : ViewModelBase + { + public ObservableCollection? ValueColorRanges { get; set; } = new(); + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContoursRangeViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContoursRangeViewModel.cs new file mode 100644 index 0000000..3534ea9 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ContoursRangeViewModel.cs @@ -0,0 +1,61 @@ +using FieldVisualizer.Entities.ColorMaps; +using FieldVisualizer.Entities.Values; +using FieldVisualizer.Services.ColorServices; +using FieldVisualizer.Services.ValueRanges; +using StructureHelper.Infrastructure; +using System; +using System.Collections.Generic; +using System.Drawing.Imaging; +using System.Text; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + public class ContoursRangeViewModel : ViewModelBase + { + const int RangeNumber = 16; + private double userMinValue; + private double userMaxValue; + + public IColorMap? ColorMap { get; set; } + public IValueRange? ValueRange { get; set; } = new ValueRange(); + public bool SetMinValue { get; set; } = false; + public double UserMinValue + { + get => userMinValue; + set + { + userMinValue = value; + Refresh(); + } + } + public bool SetMaxValue { get; set; } = false; + public double UserMaxValue + { + get => userMaxValue; + set + { + userMaxValue = value; + Refresh(); + } + } + + public ContourLegendViewModel ContourLegend { get; set; } = new(); + public ContoursRangeViewModel() + { + //Refresh(); + } + + public void Refresh() + { + var valueRanges = ValueRangeOperations.DivideValueRange(ValueRange, RangeNumber); + var valueColorRanges = ColorOperations.GetValueColorRanges(ValueRange, valueRanges, ColorMap); + ContourLegend.ValueColorRanges.Clear(); + foreach (var valueRange in valueColorRanges) + { + ContourLegend.ValueColorRanges.Add(valueRange); + } + OnPropertyChanged(nameof(UserMinValue)); + OnPropertyChanged(nameof(UserMaxValue)); + } + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs index 9a0a641..07d282a 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs @@ -1,6 +1,7 @@ using LoaderCalculator.Data.Matrix; using LoaderCalculator.Data.Ndms; using StructureHelper.Infrastructure; +using StructureHelper.Infrastructure.UI.DataContexts; using StructureHelper.Services.Exports; using StructureHelper.Services.Reports; using StructureHelper.Services.Reports.CalculationReports; @@ -461,10 +462,20 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu { try { - IStrainMatrix strainMatrix = SelectedResult.ForcesTupleResult.LoaderResults.ForceStrainPair.StrainMatrix; - var primitiveSets = ShowIsoFieldResult.GetPrimitiveSets(strainMatrix, ndms, ForceResultFuncFactory.GetResultFuncs()); - isoFieldReport = new IsoFieldReport(primitiveSets); - isoFieldReport.Show(); + SelectedPrimitiveSet selectedPrimitiveSet = new() + { + AllPrimitives = ndmPrimitives.ToList(), + SelectedPrimitives = selectedNdmPrimitives.ToList(), + StateCalcTermPair = SelectedResult.StateCalcTermPair, + Ndms = [.. ndms], + StrainMatrix = SelectedResult.ForcesTupleResult.LoaderResults.StrainMatrix + }; + IsoField2DReport report = new(selectedPrimitiveSet); + report.Show(); + //IStrainMatrix strainMatrix = SelectedResult.ForcesTupleResult.LoaderResults.ForceStrainPair.StrainMatrix; + //var primitiveSets = ShowIsoFieldResult.GetPrimitiveSets(strainMatrix, ndms, ForceResultFuncFactory.GetResultFuncs()); + //isoFieldReport = new IsoFieldReport(primitiveSets); + //isoFieldReport.Show(); } catch (Exception ex) { diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml new file mode 100644 index 0000000..c4258ca --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml.cs new file mode 100644 index 0000000..50f2ae0 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerView.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; +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.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + /// + /// Interaction logic for IsoField2DViewerView.xaml + /// + public partial class IsoField2DViewerView : Window + { + private IsoField2DViewerViewModel viewModel; + + public IsoField2DViewerView(IsoField2DViewerViewModel viewModel) + { + InitializeComponent(); + this.viewModel = viewModel; + this.DataContext = viewModel; + this.viewModel.Window = this; + } + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerViewModel.cs new file mode 100644 index 0000000..3540805 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoField2DViewerViewModel.cs @@ -0,0 +1,52 @@ +using FieldVisualizer.Entities.Values.Primitives; +using StructureHelper.Infrastructure; +using StructureHelper.Infrastructure.UI.DataContexts; +using StructureHelper.Services.ResultViewers; +using System.Collections.Generic; +using System.Linq; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + public class IsoField2DViewerViewModel : ViewModelBase + { + private SelectedPrimitiveSet ndmPrimitiveSet; + + public IsoField2DViewerView Window { get; internal set; } + public IsoFieldTitle Title { get; set; } + public IsoFieldSummary Summary { get; } + public List PrimitiveSets { get; set; } + public IPrimitiveSet SelectedPrimitiveSet { get; set; } + public ColorMapViewModel ColorMapViewModel { get; set; } + public ContoursRangeViewModel ContourRange { get; set; } = new(); + + public IsoField2DViewerViewModel(SelectedPrimitiveSet ndmPrimitiveSet) + { + this.ndmPrimitiveSet = ndmPrimitiveSet; + SetValues(ndmPrimitiveSet); + ColorMapViewModel = new ColorMapViewModel(this); + SelectedPrimitiveSet = PrimitiveSets[0]; + Refresh(); + } + + private void SetValues(SelectedPrimitiveSet ndmPrimitiveSet) + { + PrimitiveSets = ShowIsoFieldResult.GetPrimitiveSets(ndmPrimitiveSet.StrainMatrix, ndmPrimitiveSet.Ndms, ForceResultFuncFactory.GetResultFuncs()); + } + + public void Refresh() + { + if (SelectedPrimitiveSet is null) { return; } + Title = new(SelectedPrimitiveSet); + Title.Refresh(); + OnPropertyChanged(nameof(Title)); + if (ColorMapViewModel is null) { return; } + ContourRange.ColorMap = ColorMapViewModel.SelectedColorMap; + double minValue = SelectedPrimitiveSet.ValuePrimitives.Min(x => x.Value); + ContourRange.ValueRange.BottomValue = ContourRange.UserMinValue = minValue; + double maxValue = SelectedPrimitiveSet.ValuePrimitives.Max(x => x.Value); + ContourRange.ValueRange.TopValue = ContourRange.UserMinValue = maxValue; + ContourRange.Refresh(); + OnPropertyChanged(nameof(ContourRange)); + } + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldSummary.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldSummary.cs new file mode 100644 index 0000000..c56e7ee --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldSummary.cs @@ -0,0 +1,47 @@ +using FieldVisualizer.Entities.Values.Primitives; +using StructureHelper.Infrastructure; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + public class IsoFieldSummary : ViewModelBase + { + private IPrimitiveSet primitiveSet; + public double AreaTotal { get; private set; } + public double AreaNeg { get; private set; } + public double AreaZero { get; private set; } + public double AreaPos { get; private set; } + public double SumTotal { get; private set; } + public double SumNeg { get; private set; } + public double SumPos { get; private set; } + + public IsoFieldSummary(IPrimitiveSet primitiveSet) + { + this.primitiveSet = primitiveSet; + Refresh(); + } + + private void Refresh() + { + AreaTotal = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Sum(x => x.Area); + AreaNeg = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value < 0d).Sum(x => x.Area); + AreaZero = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value == 0d).Sum(x => x.Area); + AreaPos = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value > 0d).Sum(x => x.Area); + SumTotal = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Sum(x => x.Value); + SumNeg = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value < 0d).Sum(x => x.Value); + SumPos = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value > 0d).Sum(x => x.Value); + OnPropertyChanged(nameof(PrimitiveSet)); + OnPropertyChanged(nameof(AreaTotal)); + OnPropertyChanged(nameof(AreaNeg)); + OnPropertyChanged(nameof(AreaZero)); + OnPropertyChanged(nameof(AreaPos)); + OnPropertyChanged(nameof(SumTotal)); + OnPropertyChanged(nameof(SumNeg)); + OnPropertyChanged(nameof(SumPos)); + } + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldTitle.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldTitle.cs new file mode 100644 index 0000000..344ac68 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/IsoFieldTitle.cs @@ -0,0 +1,27 @@ +using FieldVisualizer.Entities.Values.Primitives; +using StructureHelper.Infrastructure; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews +{ + public class IsoFieldTitle : ViewModelBase + { + private IPrimitiveSet primitiveSet; + + public string Title { get; set; } + public string SubTitle { get; set; } + + + public IsoFieldTitle(IPrimitiveSet primitiveSet) + { + this.primitiveSet = primitiveSet; + Title = primitiveSet.Name; + SubTitle = primitiveSet.SubTitle; + } + + public void Refresh() + { + OnPropertyChanged(nameof(Title)); + OnPropertyChanged(nameof(SubTitle)); + } + } +} diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldContours.xaml b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldContours.xaml new file mode 100644 index 0000000..1ebeee8 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/IsoFieldContours.xaml @@ -0,0 +1,21 @@ + + + + + + + + +