diff --git a/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs b/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs index b5c0010..e259a79 100644 --- a/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs +++ b/FieldVisualizer/Entities/ColorMaps/Factories/ColorMapFactory.cs @@ -1,12 +1,18 @@ -using FieldVisualizer.InfraStructures.Enums; -using FieldVisualizer.InfraStructures.Exceptions; +using FieldVisualizer.InfraStructures.Exceptions; using FieldVisualizer.InfraStructures.Strings; -using System; using System.Collections.Generic; using System.Windows.Media; namespace FieldVisualizer.Entities.ColorMaps.Factories { + public enum ColorMapsTypes + { + LiraSpectrum = 0, //Lira + FullSpectrum = 1, //StaDiCon + RedToWhite = 2, + RedToBlue = 3, + BlueToWhite = 4, + } /// /// Factory for creating of different color maps /// @@ -18,13 +24,39 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories if (mapsTypes == ColorMapsTypes.RedToWhite) { return GetRedToWhite(); } if (mapsTypes == ColorMapsTypes.RedToBlue) { return GetRedToBlue(); } if (mapsTypes == ColorMapsTypes.BlueToWhite) { return GetBlueToWhite(); } + if (mapsTypes == ColorMapsTypes.LiraSpectrum) { return GetLiraSpectrum(); } else { throw new FieldVisulizerException(ErrorStrings.ColorMapTypeIsUnknown); } } + private static IColorMap GetLiraSpectrum() + { + ColorMap colorMap = new() + { + Name = "LiraSpectrumColorMap" + }; + List colors = new(); + byte Alpha = 0xff; + colors.AddRange(new Color[]{ + Color.FromArgb(Alpha, 0, 0, 128) ,//Dark Blue + Color.FromArgb(Alpha, 0, 0, 255) ,//Blue + Color.FromArgb(Alpha, 0, 128, 255) ,//Blue + Color.FromArgb(Alpha, 0, 200, 255) ,//Blue + Color.FromArgb(Alpha, 60, 255, 255) ,//Light Blue + Color.FromArgb(Alpha, 255, 255, 128) ,//Light Yellow + Color.FromArgb(Alpha, 255, 255, 0) ,//Yellow + Color.FromArgb(Alpha, 255, 215, 0) ,//Gold + Color.FromArgb(Alpha, 255, 128, 0) ,//Orange Red + Color.FromArgb(Alpha, 255, 0, 0) ,//Red + }); + colorMap.Colors = colors; + return colorMap; + } private static IColorMap GetFullSpectrum() { - ColorMap colorMap = new ColorMap(); - colorMap.Name = "FullSpectrumColorMap"; + ColorMap colorMap = new() + { + Name = "FullSpectrumColorMap" + }; List colors = new List(); byte Alpha = 0xff; colors.AddRange(new Color[]{ @@ -43,7 +75,6 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories colorMap.Colors = colors; return colorMap; } - private static IColorMap GetRedToWhite() { ColorMap colorMap = new ColorMap(); @@ -57,7 +88,6 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories colorMap.Colors = colors; return colorMap; } - private static IColorMap GetRedToBlue() { ColorMap colorMap = new ColorMap(); @@ -71,7 +101,6 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories colorMap.Colors = colors; return colorMap; } - private static IColorMap GetBlueToWhite() { ColorMap colorMap = new ColorMap(); diff --git a/FieldVisualizer/Entities/ColorMaps/IValueColorRange.cs b/FieldVisualizer/Entities/ColorMaps/IValueColorRange.cs index d4da2bc..395993c 100644 --- a/FieldVisualizer/Entities/ColorMaps/IValueColorRange.cs +++ b/FieldVisualizer/Entities/ColorMaps/IValueColorRange.cs @@ -1,19 +1,35 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; +using System.Windows.Media; namespace FieldVisualizer.Entities.ColorMaps { + /// + /// Colored range for building color legend + /// public interface IValueColorRange { + /// + /// Flag of activity + /// bool IsActive { get; set; } + /// + /// Minimum value of range + /// double BottomValue { get; set; } + /// + /// Average value of range + /// double AverageValue { get; set; } + /// + /// Maximum value of range + /// double TopValue {get;set;} + /// + /// Color correspondent to minimum value + /// Color BottomColor { get; set; } + /// + /// Color correspondent to maximum value + /// Color TopColor { get; set; } } } diff --git a/FieldVisualizer/Entities/ColorMaps/ValueColorRange.cs b/FieldVisualizer/Entities/ColorMaps/ValueColorRange.cs index 92eaff5..695cca3 100644 --- a/FieldVisualizer/Entities/ColorMaps/ValueColorRange.cs +++ b/FieldVisualizer/Entities/ColorMaps/ValueColorRange.cs @@ -1,19 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; +using System.Windows.Media; namespace FieldVisualizer.Entities.ColorMaps { + /// public class ValueColorRange : IValueColorRange { + /// public bool IsActive { get; set; } + /// public double BottomValue { get; set; } + /// public double AverageValue { get; set; } + /// public double TopValue { get; set; } + /// public Color BottomColor { get; set; } + /// public Color TopColor { get; set; } } } diff --git a/FieldVisualizer/FieldVisualizer.csproj b/FieldVisualizer/FieldVisualizer.csproj index 0a3b622..dc9183b 100644 --- a/FieldVisualizer/FieldVisualizer.csproj +++ b/FieldVisualizer/FieldVisualizer.csproj @@ -8,4 +8,12 @@ 7.0 + + + + + + + + diff --git a/FieldVisualizer/InfraStructures/Enums/ColorMapsTypes.cs b/FieldVisualizer/InfraStructures/Enums/ColorMapsTypes.cs deleted file mode 100644 index 5be9d8c..0000000 --- a/FieldVisualizer/InfraStructures/Enums/ColorMapsTypes.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FieldVisualizer.InfraStructures.Enums -{ - public enum ColorMapsTypes - { - FullSpectrum = 0, - RedToWhite = 1, - RedToBlue = 2, - BlueToWhite = 3 - } -} diff --git a/FieldVisualizer/Services/ColorServices/ColorOperations.cs b/FieldVisualizer/Services/ColorServices/ColorOperations.cs index dd4c7c7..9b3148d 100644 --- a/FieldVisualizer/Services/ColorServices/ColorOperations.cs +++ b/FieldVisualizer/Services/ColorServices/ColorOperations.cs @@ -1,5 +1,6 @@ using FieldVisualizer.Entities.ColorMaps; using FieldVisualizer.Entities.Values; +using StructureHelperCommon.Infrastructures.Exceptions; using System; using System.Collections.Generic; using System.Text; @@ -10,54 +11,123 @@ namespace FieldVisualizer.Services.ColorServices public static class ColorOperations { const byte Alpha = 0xff; - public static Color GetColorByValue(IValueRange range, IColorMap map, double val) - { - if (range.TopValue == range.BottomValue || map.Colors.Count == 0) { return map.Colors[0]; } - double minVal = range.BottomValue - 1e-15d*(Math.Abs(range.BottomValue)); - double maxVal = range.TopValue + 1e-15d * (Math.Abs(range.TopValue)); - if (val > maxVal || val < minVal) { return Colors.Gray; } - if (val == minVal) { return map.Colors[0]; } - if (val == maxVal) { return map.Colors[map.Colors.Count - 1]; } - - double valPerc = (val - minVal) / (maxVal - minVal);// value% - if (valPerc >= 1d) - { return map.Colors[map.Colors.Count - 1]; } - double colorPerc = 1d / (map.Colors.Count - 1d); // % of each block of color. the last is the "100% Color" - double blockOfColor = valPerc / colorPerc;// the integer part repersents how many block to skip - int blockIdx = (int)Math.Truncate(blockOfColor);// Idx of - double valPercResidual = valPerc - (blockIdx * colorPerc);//remove the part represented of block - double percOfColor = valPercResidual / colorPerc;// % of color of this block that will be filled - - Color cTarget = map.Colors[blockIdx]; - Color cNext = map.Colors[blockIdx + 1]; - - var deltaR = cNext.R - cTarget.R; - var deltaG = cNext.G - cTarget.G; - var deltaB = cNext.B - cTarget.B; - - var R = cTarget.R + (deltaR * percOfColor); - var G = cTarget.G + (deltaG * percOfColor); - var B = cTarget.B + (deltaB * percOfColor); - - Color c = map.Colors[0]; - c = Color.FromArgb(Alpha, (byte)R, (byte)G, (byte)B); - return c; - } + /// + /// + /// + /// + /// + /// + /// public static IEnumerable GetValueColorRanges(IValueRange fullRange, IEnumerable valueRanges, IColorMap colorMap) { var colorRanges = new List(); foreach (var valueRange in valueRanges) { - IValueColorRange valueColorRange = new ValueColorRange(); - valueColorRange.IsActive = true; - valueColorRange.BottomValue = valueRange.BottomValue; - valueColorRange.AverageValue = (valueRange.BottomValue + valueRange.TopValue) / 2; - valueColorRange.TopValue = valueRange.TopValue; + IValueColorRange valueColorRange = new ValueColorRange + { + IsActive = true, + BottomValue = valueRange.BottomValue, + AverageValue = (valueRange.BottomValue + valueRange.TopValue) / 2, + TopValue = valueRange.TopValue + }; valueColorRange.BottomColor = GetColorByValue(fullRange, colorMap, valueColorRange.BottomValue); valueColorRange.TopColor = GetColorByValue(fullRange, colorMap, valueColorRange.TopValue); colorRanges.Add(valueColorRange); } return colorRanges; } + /// + /// Returns color by value, range of value an color map + /// + /// Range of valoue + /// Color map + /// Value + /// + public static Color GetColorByValue(IValueRange range, IColorMap map, double val) + { + CheckColorMap(map); + if (range.TopValue == range.BottomValue || map.Colors.Count == 1) //if range width is zero or map contain just 1 color + { + return map.Colors[0]; + } + var valueRange = GetExtendedRange(range); + if (val >= valueRange.TopValue || val <= valueRange.BottomValue) + { + return GetColorValueIsOutOfRange(valueRange, map, val); + } + return GetColorValueIsInRange(valueRange, map, val); + } + + private static Color GetColorValueIsOutOfRange(IValueRange range, IColorMap map, double val) + { + if (val > range.TopValue || val < range.BottomValue) + { + return Colors.Gray; + } + if (val == range.BottomValue) + { + return map.Colors[0]; + } + if (val == range.TopValue) + { + return map.Colors[^1]; + } + throw new StructureHelperException(ErrorStrings.DataIsInCorrect); + } + + private static Color GetColorValueIsInRange(IValueRange range, IColorMap map, double val) + { + var deltaVal = val - range.BottomValue; + var rangeWidth = range.TopValue - range.BottomValue; + var valPerc = deltaVal / rangeWidth; // percent of value on the distance from minValue to maxValue + if (valPerc >= 1d) + { + return map.Colors[^1]; + } + double colorPerc = 1d / (map.Colors.Count - 1d); // % of each block of color. the last is the "100% Color" + double blockOfColor = valPerc / colorPerc;// the integer part repersents how many block to skip + int blockIdx = (int)Math.Truncate(blockOfColor);// Idx of + double valPercResidual = valPerc - (blockIdx * colorPerc);//remove the part represented of block + double percOfColor = valPercResidual / colorPerc;// % of color of this block that will be filled + + Color c = GetColorByColorMap(map, blockIdx, percOfColor); + return c; + } + + private static IValueRange GetExtendedRange(IValueRange range) + { + var minVal = range.BottomValue - 1e-15d * Math.Abs(range.BottomValue); + var maxVal = range.TopValue + 1e-15d * Math.Abs(range.TopValue); + return new ValueRange() + { + BottomValue = minVal, + TopValue = maxVal + }; + } + + private static Color GetColorByColorMap(IColorMap map, int blockIdx, double percOfColor) + { + Color cTarget = map.Colors[blockIdx]; + Color cNext = map.Colors[blockIdx + 1]; + + var deltaRed = cNext.R - cTarget.R; + var deltaGreen = cNext.G - cTarget.G; + var deltaBlue = cNext.B - cTarget.B; + + var Red = cTarget.R + (deltaRed * percOfColor); + var Green = cTarget.G + (deltaGreen * percOfColor); + var Blue = cTarget.B + (deltaBlue * percOfColor); + + Color c = Color.FromArgb(Alpha, (byte)Red, (byte)Green, (byte)Blue); + return c; + } + + private static void CheckColorMap(IColorMap map) + { + if (map.Colors.Count == 0) + { + throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": Color map is empty"); + } + } } } diff --git a/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs b/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs index 4f16ce6..540abf1 100644 --- a/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs +++ b/FieldVisualizer/ViewModels/FieldViewerViewModels/FieldViewerViewModel.cs @@ -1,27 +1,22 @@ -using FieldVisualizer.Entities.ColorMaps.Factories; -using FieldVisualizer.Entities.ColorMaps; -using FieldVisualizer.Entities.Values.Primitives; +using FieldVisualizer.Entities.ColorMaps; +using FieldVisualizer.Entities.ColorMaps.Factories; using FieldVisualizer.Entities.Values; +using FieldVisualizer.Entities.Values.Primitives; using FieldVisualizer.Infrastructure.Commands; -using FieldVisualizer.InfraStructures.Enums; using FieldVisualizer.InfraStructures.Exceptions; using FieldVisualizer.InfraStructures.Strings; using FieldVisualizer.Services.ColorServices; using FieldVisualizer.Services.PrimitiveServices; using FieldVisualizer.Services.ValueRanges; +using FieldVisualizer.Windows.UserControls; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; -using FieldVisualizer.Windows.UserControls; -using System.ComponentModel; -using System.Xml.Serialization; namespace FieldVisualizer.ViewModels.FieldViewerViewModels { @@ -177,7 +172,7 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels public FieldViewerViewModel() { - _ColorMapType = ColorMapsTypes.FullSpectrum; + _ColorMapType = ColorMapsTypes.LiraSpectrum; RebuildCommand = new RelayCommand(o => ProcessPrimitives(), o => PrimitiveValidation()); ZoomInCommand = new RelayCommand(o => Zoom(1.2), o => PrimitiveValidation()); ZoomOutCommand = new RelayCommand(o => Zoom(0.8), o => PrimitiveValidation()); diff --git a/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs b/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs index 1166be2..96e6753 100644 --- a/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs +++ b/FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs @@ -1,23 +1,7 @@ -using FieldVisualizer.Entities.ColorMaps; -using FieldVisualizer.Entities.ColorMaps.Factories; -using FieldVisualizer.Entities.Values; -using FieldVisualizer.Entities.Values.Primitives; -using FieldVisualizer.Infrastructure.Commands; -using FieldVisualizer.InfraStructures.Enums; -using FieldVisualizer.InfraStructures.Exceptions; -using FieldVisualizer.InfraStructures.Strings; -using FieldVisualizer.Services.ColorServices; -using FieldVisualizer.Services.PrimitiveServices; -using FieldVisualizer.Services.ValueRanges; +using FieldVisualizer.Entities.Values.Primitives; using FieldVisualizer.ViewModels.FieldViewerViewModels; -using System; -using System.Collections.Generic; -using System.Linq; using System.Windows; using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Shapes; namespace FieldVisualizer.Windows.UserControls { @@ -39,17 +23,6 @@ namespace FieldVisualizer.Windows.UserControls viewModel.Legend = LegendViewer; } - //public FieldViewer(FieldViewerViewModel vm) - //{ - // InitializeComponent(); - // viewModel = vm; - // this.DataContext = viewModel; - // PrimitiveSet = viewModel.PrimitiveSet; - // viewModel.WorkPlaneBox = WorkPlaneBox; - // viewModel.WorkPlaneCanvas = WorkPlaneCanvas; - // viewModel.Legend = LegendViewer; - //} - public IPrimitiveSet PrimitiveSet { get => viewModel.PrimitiveSet; set { viewModel.PrimitiveSet = value; } } internal void Refresh() diff --git a/StructureHelper.sln b/StructureHelper.sln index 10d38cf..7bf9930 100644 --- a/StructureHelper.sln +++ b/StructureHelper.sln @@ -14,6 +14,9 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StructureHelperLogics", "StructureHelperLogics\StructureHelperLogics.csproj", "{C9192AE7-EE6D-409C-A05C-3549D78CBB34}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FieldVisualizer", "FieldVisualizer\FieldVisualizer.csproj", "{6CAC5B83-81F3-47C2-92A1-0F94A58491C2}" + ProjectSection(ProjectDependencies) = postProject + {F1548BD2-7FE8-46C2-9BC4-9BA813A5C59A} = {F1548BD2-7FE8-46C2-9BC4-9BA813A5C59A} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/StructureHelper/App.xaml.cs b/StructureHelper/App.xaml.cs index 0f7f3b1..86d7f43 100644 --- a/StructureHelper/App.xaml.cs +++ b/StructureHelper/App.xaml.cs @@ -22,15 +22,15 @@ namespace StructureHelper builder.RegisterType().As().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); builder.RegisterType().AsSelf().SingleInstance(); - builder.RegisterType().AsSelf().SingleInstance(); - builder.RegisterType().AsSelf().SingleInstance(); + builder.RegisterType().AsSelf().SingleInstance(); + builder.RegisterType().AsSelf().SingleInstance(); - builder.RegisterType().AsSelf(); + builder.RegisterType().AsSelf(); Container = builder.Build(); Scope = Container.Resolve(); - var window = Scope.Resolve(); + var window = Scope.Resolve(); window.Show(); } diff --git a/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs b/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs index 39f4dbd..47bfe52 100644 --- a/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs +++ b/StructureHelper/Infrastructure/UI/DataContexts/PrimitiveBase.cs @@ -2,13 +2,15 @@ using StructureHelper.Services.Primitives; using StructureHelper.Windows.MainWindow; using StructureHelper.Windows.ViewModels.NdmCrossSections; +using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.NdmCalculations.Primitives; +using System; using System.Windows.Input; using System.Windows.Media; namespace StructureHelper.Infrastructure.UI.DataContexts { - public abstract class PrimitiveBase : ViewModelBase + public abstract class PrimitiveBase : ViewModelBase, IObserver { #region Поля private IPrimitiveRepository primitiveRepository; @@ -236,13 +238,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts this.primitive = primitive; } - public void RegisterDeltas(double dx, double dy) - { - DeltaX = dx; - DeltaY = dy; - } - - public MainViewModel OwnerVM { get; private set; } + public CrossSectionViewModel OwnerVM { get; private set; } public double DeltaX { get; private set; } public double DeltaY { get; private set; } @@ -253,14 +249,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts return primitive; } - //public virtual void RefreshNdmPrimitive() - //{ - //} - - public void RefreshColor() - { - OnPropertyChanged(nameof(Color)); - } public virtual void Refresh() { OnPropertyChanged(nameof(Name)); @@ -273,5 +261,22 @@ namespace StructureHelper.Infrastructure.UI.DataContexts OnPropertyChanged(nameof(PrimitiveWidth)); OnPropertyChanged(nameof(PrimitiveHeight)); } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnNext(IRectangleShape value) + { + DeltaX = value.Width / 2d; + DeltaY = value.Height / 2d; + Refresh(); + } } } diff --git a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml index 90a84a8..deaeb92 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml @@ -51,6 +51,20 @@ + diff --git a/StructureHelper/Infrastructure/UI/Resources/ItemEditPanels.xaml b/StructureHelper/Infrastructure/UI/Resources/ItemEditPanels.xaml index 0d0fd96..7c7acb2 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ItemEditPanels.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ItemEditPanels.xaml @@ -33,10 +33,10 @@ - + - + - - - + diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs index 5062bfe..cac1378 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; @@ -12,7 +13,6 @@ using StructureHelper.Windows.Forces; using StructureHelper.Windows.PrimitivePropertiesWindow; using StructureHelper.Windows.ViewModels.Calculations.Calculators; using StructureHelper.Windows.ViewModels.Errors; -using StructureHelper.Windows.ViewModels.PrimitiveProperties; using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Interfaces; @@ -22,7 +22,6 @@ using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Services.Forces; using StructureHelperLogics.NdmCalculations.Analyses; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; -using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve; using StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics; using StructureHelperLogics.NdmCalculations.Analyses.Geometry; using StructureHelperLogics.NdmCalculations.Primitives; @@ -54,17 +53,18 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu public static GeometryNames GeometryNames => ProgramSetting.GeometryNames; public ForcesTupleResult SelectedResult { get; set; } - private ICommand showIsoFieldCommand; - private ICommand exportToCSVCommand; - private ICommand interpolateCommand; - private ICommand setPrestrainCommand; - private ICommand showAnchorageCommand; - private ICommand showGeometryResultCommand; - private ICommand showGraphsCommand; - private ICommand showCrackResult; - private ICommand showCrackGraphsCommand; - private RelayCommand showCrackWidthResult; - private ICommand showInteractionDiagramCommand; + private ICommand? showIsoFieldCommand; + private ICommand? exportToCSVCommand; + private ICommand? interpolateCommand; + private ICommand? setPrestrainCommand; + private ICommand? showAnchorageCommand; + private ICommand? showGeometryResultCommand; + private ICommand? showGraphsCommand; + private ICommand? showCrackResult; + private ICommand? showCrackGraphsCommand; + private ICommand? showCrackWidthResult; + private ICommand? showInteractionDiagramCommand; + private ICommand? graphValuepointsCommand; public IForcesResults ForcesResults { @@ -157,7 +157,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu ShowInterpolationWindow(out interploateTuplesViewModel, out wndTuples); if (wndTuples.DialogResult != true) return; - var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.Result); + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.ForceInterpolationViewModel.Result); showProgressLogic = new(interpolationLogic) { WindowTitle = "Interpolate forces" @@ -176,8 +176,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu }; showProgressLogic.Show(); } - }, o => SelectedResult != null && SelectedResult.IsValid - ); + }, o => SelectedResult != null); } public ICommand ShowCrackGraphsCommand { @@ -188,7 +187,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu ShowInterpolationWindow(out interploateTuplesViewModel, out wndTuples); if (wndTuples.DialogResult != true) return; - var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.Result); + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.ForceInterpolationViewModel.Result); showProgressLogic = new(interpolationLogic) { WindowTitle = "Interpolate forces" @@ -261,13 +260,58 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu ShowInterpolationWindow(out interploateTuplesViewModel, out wndTuples); if (wndTuples.DialogResult != true) return; - var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.Result); + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.ForceInterpolationViewModel.Result); progressLogic = interpolationLogic; showProgressLogic = new(interpolationLogic); showProgressLogic.ShowResult = ShowInterpolationProgressDialog; showProgressLogic.Show(); } + public ICommand GraphValuePointsCommand + { + get + { + return graphValuepointsCommand ?? + (graphValuepointsCommand = new RelayCommand(o => + { + InterpolateValuePoints(); + }, o => SelectedResult != null)); + } + } + + private void InterpolateValuePoints() + { + if (SelectedResult is null) + { + throw new StructureHelperException(ErrorStrings.NullReference + ": Nothing is selected"); + } + var tuple = SelectedResult.DesignForceTuple ?? throw new StructureHelperException(ErrorStrings.NullReference + ": Design force combination"); + var inputData = new ValuePointsInterpolationInputData() + { + FinishDesignForce = tuple.Clone() as IDesignForceTuple, + LimitState = tuple.LimitState, + CalcTerm = tuple.CalcTerm, + }; + inputData.PrimitiveBases.AddRange(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(ndmPrimitives)); + var viewModel = new ValuePointsInterpolateViewModel(inputData); + var wnd = new ValuePointsInterpolateView(viewModel); + wnd.ShowDialog(); + if (wnd.DialogResult != true) { return; } + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, viewModel.ForceInterpolationViewModel.Result); + ShowValuePointDiagramLogic pointGraphLogic = new(ForcesResults.ForcesResultList, ndmPrimitives) + { + Calculator = interpolationLogic.InterpolateCalculator, + PrimitiveLogic = viewModel.PrimitiveLogic, + ValueDelegatesLogic = viewModel.ValueDelegatesLogic + }; + progressLogic = interpolationLogic; + showProgressLogic = new(interpolationLogic) + { + ShowResult = pointGraphLogic.ShowWindow + }; + showProgressLogic.Show(); + } + private void ShowInterpolationWindow(out InterpolateTuplesViewModel interploateTuplesViewModel, out InterpolateTuplesView wndTuples) { IDesignForceTuple finishDesignTuple = SelectedResult.DesignForceTuple.Clone() as IDesignForceTuple; diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/SurroundDataViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/SurroundDataViewModel.cs index 4234dda..db1f181 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/SurroundDataViewModel.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/UserControls/SurroundDataViewModel.cs @@ -157,6 +157,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu { var factor = GetFactor(SurroundData.ConvertLogicEntity.ZForceType); SurroundData.ConstZ = value / factor; + SurroundData.ConvertLogicEntity.ConstDirectionValue = SurroundData.ConstZ; OnPropertyChanged(nameof(ConstZ)); } } diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs index e4ea30a..cc5339f 100644 --- a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs @@ -1,16 +1,11 @@ using StructureHelper.Infrastructure; -using StructureHelper.Windows.AddMaterialWindow; using StructureHelper.Windows.ViewModels.Errors; -using StructureHelper.Windows.ViewModels.Materials; using StructureHelperCommon.Infrastructures.Exceptions; -using StructureHelperCommon.Models.Loggers; +using StructureHelperCommon.Models; using StructureHelperCommon.Models.Tables; using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.ConstrainedExecution; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; @@ -21,31 +16,35 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews { public class TraceDocumentVM : ViewModelBase { - IEnumerable loggerEntries; - IEnumerable selectedLoggerEntries; - FlowDocument document; + const double tabFactor = 500d; + private readonly IEnumerable loggerEntries; + private IEnumerable selectedLoggerEntries; + private FlowDocument document; private ICommand rebuildCommand; private ICommand printDocumentCommand; - private int maxPriority; + private int priorityLimit; private int tabGap; public FlowDocumentReader DocumentReader { get; set; } - public int MaxPriority + public int PriorityLimit { - get => maxPriority; set + get => priorityLimit; set { - var oldValue = maxPriority; + var oldValue = priorityLimit; try { - maxPriority = Math.Max(value, 0); - OnPropertyChanged(nameof(MaxPriority)); + priorityLimit = Math.Max(value, 0); + OnPropertyChanged(nameof(PriorityLimit)); } catch (Exception) { - maxPriority = oldValue; + priorityLimit = oldValue; } } } + + public int MaxPriority => loggerEntries.Max(x => x.Priority); + public int TabGap { get => tabGap; set @@ -65,8 +64,8 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews public TraceDocumentVM(IEnumerable loggerEntries) { this.loggerEntries = loggerEntries; - maxPriority = 350; - tabGap = 50; + priorityLimit = 350; + tabGap = 30; } public ICommand RebuildCommand => @@ -81,40 +80,82 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews SafetyProcessor.RunSafeProcess(DocumentReader.Print, "Error of printing document"); }); + + public void Prepare() + { + document = new(); + selectedLoggerEntries = loggerEntries.Where(x => x.Priority <= PriorityLimit); + var blocks = selectedLoggerEntries.Select(x => GetBlockByEntry(x)); + document.Blocks.AddRange(blocks); + } + public void ShowPrepared() + { + DocumentReader.Document = document; + } public void Show() { Prepare(); ShowPrepared(); } - public void Prepare() + private Block GetBlockByEntry(ITraceLoggerEntry traceEntry) { - document = new(); - selectedLoggerEntries = loggerEntries.Where(x => x.Priority <= MaxPriority); - foreach (var item in selectedLoggerEntries) + Block block; + if (traceEntry is StringLogEntry stringEntry) { - ProcessLoggerEntries(item); + block = GetBlockByStringEntry(stringEntry); } - } - - private void ProcessLoggerEntries(ITraceLoggerEntry item) - { - if (item is StringLoggerEntry stringEntry) + else if (traceEntry is TableLogEntry tableEntry) { - ProcessStringEntry(stringEntry); - } - else if (item is TableLoggerEntry tableEntry) - { - ProcessTableEntry(tableEntry); + block = GetBlockByTableEntry(tableEntry); } else { - throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(item)); + throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(traceEntry)); } + block.Margin = new Thickness(traceEntry.Priority / tabFactor * tabGap, 7, 0, 7); + return block; } - private void ProcessTableEntry(TableLoggerEntry tableEntry) + private Block GetBlockByStringEntry(StringLogEntry stringEntry) { + var paragraph = new Paragraph(new Run(stringEntry.Message)); + if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Fatal)) + { + paragraph.FontSize = 14; + paragraph.Background = Brushes.Red; + paragraph.Foreground = Brushes.Black; + paragraph.FontStyle = FontStyles.Italic; + } + else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Error)) + { + paragraph.FontSize = 14; + paragraph.Background = Brushes.Pink; + paragraph.Foreground = Brushes.Black; + } + else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Warning)) + { + paragraph.FontSize = 14; + paragraph.Background = Brushes.Yellow; + paragraph.Foreground = Brushes.Black; + } + else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLogStatuses.Debug)) + { + paragraph.FontSize = 12; + paragraph.Foreground = Brushes.Black; + } + else + { + paragraph.FontSize = 10; + paragraph.Foreground = Brushes.Gray; + } + + return paragraph; + } + + private Table GetBlockByTableEntry(TableLogEntry tableEntry) + { + const int columnWidth = 150; var rows = tableEntry.Table.GetAllRows(); int rowCount = rows.Count(); int columnCount = tableEntry.Table.RowSize; @@ -122,96 +163,53 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews for (int x = 0; x < columnCount; x++) { var tableColumn = new TableColumn(); - tableColumn.Width = new GridLength(150); + tableColumn.Width = new GridLength(columnWidth); table.Columns.Add(tableColumn); } foreach (var row in rows) { - var newRow = new TableRow(); - foreach (var cell in row.Elements) - { - TableCell tableCell; - if (cell is null) - { - tableCell = new TableCell(new Paragraph(new Run(string.Empty))); - } - else - { - if (cell.Value is StringLoggerEntry stringEntry) - { - tableCell = new TableCell(GetParagraphByStringEntry(stringEntry)); - tableCell.ColumnSpan = cell.ColumnSpan; - if (cell.Role == CellRole.Regular) - { - tableCell.TextAlignment = TextAlignment.Left; - tableCell.Background = Brushes.LightYellow; - } - else if (cell.Role == CellRole.Header) - { - tableCell.TextAlignment = TextAlignment.Center; - tableCell.Background = Brushes.AliceBlue; - } - } - else - { - throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(cell)); - } - } - newRow.Cells.Add(tableCell); - } + TableRow newRow = GetTableRow(row); table.RowGroups.Add(new TableRowGroup()); table.RowGroups[0].Rows.Add(newRow); } - document.Blocks.Add(table); + return table; } - private void ProcessStringEntry(StringLoggerEntry stringEntry) + private TableRow GetTableRow(IShTableRow row) { - var paragraph = GetParagraphByStringEntry(stringEntry); - document.Blocks.Add(paragraph); + var newRow = new TableRow(); + foreach (var cell in row.Elements) + { + TableCell tableCell; + if (cell is null) + { + tableCell = new TableCell(new Paragraph(new Run(string.Empty))); + } + else + { + var cellvalue = GetBlockByEntry(cell.Value); + tableCell = new TableCell(cellvalue); + AdjustTableCell(cell, tableCell); + } + newRow.Cells.Add(tableCell); + } + + return newRow; } - private Paragraph GetParagraphByStringEntry(StringLoggerEntry stringEntry) + private static void AdjustTableCell(IShTableCell? cell, TableCell tableCell) { - var paragraph = new Paragraph(new Run(stringEntry.Message)); - paragraph.Margin = new Thickness(stringEntry.Priority / tabGap); - if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Fatal)) + tableCell.ColumnSpan = cell.ColumnSpan; + if (cell.Role == CellRole.Regular) { - paragraph.FontSize = 14; - paragraph.Background = Brushes.Red; - paragraph.Foreground = Brushes.Black; - paragraph.FontStyle = FontStyles.Italic; + tableCell.TextAlignment = TextAlignment.Left; + tableCell.Background = Brushes.LightYellow; } - else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Error)) + else if (cell.Role == CellRole.Header) { - paragraph.FontSize = 14; - paragraph.Background = Brushes.Pink; - paragraph.Foreground = Brushes.Black; + tableCell.TextAlignment = TextAlignment.Center; + tableCell.Background = Brushes.AliceBlue; } - else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Warning)) - { - paragraph.FontSize = 14; - paragraph.Background = Brushes.Yellow; - paragraph.Foreground = Brushes.Black; - } - else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Debug)) - { - paragraph.FontSize = 12; - paragraph.Foreground = Brushes.Black; - } - else - { - paragraph.FontSize = 8; - paragraph.Foreground = Brushes.Gray; - - } - - return paragraph; - } - - public void ShowPrepared() - { - DocumentReader.Document = document; } } } diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml index c1c5a39..5d8f958 100644 --- a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentView.xaml @@ -10,7 +10,7 @@ - + @@ -18,7 +18,13 @@ - + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/Forces/ForceInterpolationControl.xaml.cs b/StructureHelper/Windows/Forces/ForceInterpolationControl.xaml.cs new file mode 100644 index 0000000..0a95c0c --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceInterpolationControl.xaml.cs @@ -0,0 +1,67 @@ +using StructureHelper.Windows.UserControls; +using StructureHelper.Windows.ViewModels.Materials; +using StructureHelperCommon.Services.Forces; +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.Navigation; +using System.Windows.Shapes; + +namespace StructureHelper.Windows.Forces +{ + /// + /// Логика взаимодействия для ForceInterpolationControl.xaml + /// + public partial class ForceInterpolationControl : UserControl + { + private ForceTupleInterpolationViewModel? properties; + + public ForceTupleInterpolationViewModel? Properties + { + get => properties; set + { + properties = value; + DataContext = Properties; + } + } + public ForceInterpolationControl() + { + InitializeComponent(); + } + + private void StartValueChanged(object sender, EventArgs e) + { + var obj = (MultiplyDouble)sender; + var tmpTuple = ForceTupleService.MultiplyTuples(Properties.StartDesignForce.ForceTuple, obj.DoubleFactor); + ForceTupleService.CopyProperties(tmpTuple, Properties.StartDesignForce.ForceTuple, 1d); + Properties.RefreshStartTuple(); + } + + private void FinishValueChanged(object sender, EventArgs e) + { + var obj = (MultiplyDouble)sender; + var tmpTuple = ForceTupleService.MultiplyTuples(Properties.FinishDesignForce.ForceTuple, obj.DoubleFactor); + ForceTupleService.CopyProperties(tmpTuple, Properties.FinishDesignForce.ForceTuple, 1d); + Properties.RefreshFinishTuple(); + } + + private void StepCountValueChanged(object sender, EventArgs e) + { + var obj = (MultiplyDouble)sender; + var factor = obj.DoubleFactor; + if (factor > 0d) + { + Properties.StepCount = Convert.ToInt32(Properties.StepCount * factor); + } + } + } +} diff --git a/StructureHelper/Windows/Forces/ForceTupleControl.xaml b/StructureHelper/Windows/Forces/ForceTupleControl.xaml deleted file mode 100644 index 6166d4d..0000000 --- a/StructureHelper/Windows/Forces/ForceTupleControl.xaml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/StructureHelper/Windows/Forces/ForceTupleInterpolationControl.xaml b/StructureHelper/Windows/Forces/ForceTupleInterpolationControl.xaml new file mode 100644 index 0000000..c106140 --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceTupleInterpolationControl.xaml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/Forces/ForceTupleControl.xaml.cs b/StructureHelper/Windows/Forces/ForceTupleInterpolationControl.xaml.cs similarity index 76% rename from StructureHelper/Windows/Forces/ForceTupleControl.xaml.cs rename to StructureHelper/Windows/Forces/ForceTupleInterpolationControl.xaml.cs index 446b197..ecc0032 100644 --- a/StructureHelper/Windows/Forces/ForceTupleControl.xaml.cs +++ b/StructureHelper/Windows/Forces/ForceTupleInterpolationControl.xaml.cs @@ -18,9 +18,10 @@ namespace StructureHelper.Windows.Forces /// /// Логика взаимодействия для ForceTupleControl.xaml /// - public partial class ForceTupleControl : UserControl + public partial class ForceTupleInterpolationControl : UserControl { - public ForceTupleControl() + public ForceTupleInterpolationViewModel? Properties { get; set; } + public ForceTupleInterpolationControl() { InitializeComponent(); } diff --git a/StructureHelper/Windows/Forces/ForceTupleInterpolationViewModel.cs b/StructureHelper/Windows/Forces/ForceTupleInterpolationViewModel.cs new file mode 100644 index 0000000..6259e1e --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceTupleInterpolationViewModel.cs @@ -0,0 +1,212 @@ +using StructureHelper.Infrastructure; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models.Forces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace StructureHelper.Windows.Forces +{ + public class ForceTupleInterpolationViewModel : ViewModelBase + { + private RelayCommand invertForcesCommand; + private RelayCommand copyToStartCommand; + private RelayCommand copyToFinishCommand; + private int stepCount; + private IDesignForceTuple startDesignForce; + private IDesignForceTuple finishDesignForce; + + public IDesignForceTuple StartDesignForce + { + get => startDesignForce; set + { + startDesignForce = value; + } + } + public IDesignForceTuple FinishDesignForce + { + get => finishDesignForce; set + { + finishDesignForce = value; + } + } + + public double StartFactor { get; set; } + public double FinishFactor { get; set; } + public double StepCountFactor { get; set; } + + public bool StepCountVisible { get; set; } + public double StartMx + { + get => StartDesignForce.ForceTuple.Mx; + set + { + StartDesignForce.ForceTuple.Mx = value; + OnPropertyChanged(nameof(StartMx)); + } + } + public double StartMy + { + get => StartDesignForce.ForceTuple.My; + set + { + StartDesignForce.ForceTuple.My = value; + OnPropertyChanged(nameof(StartMy)); + } + } + public double StartNz + { + get => StartDesignForce.ForceTuple.Nz; + set + { + StartDesignForce.ForceTuple.Nz = value; + OnPropertyChanged(nameof(StartNz)); + } + } + public double FinishMx + { + get => FinishDesignForce.ForceTuple.Mx; + set + { + FinishDesignForce.ForceTuple.Mx = value; + OnPropertyChanged(nameof(FinishMx)); + } + } + public double FinishMy + { + get => FinishDesignForce.ForceTuple.My; + set + { + FinishDesignForce.ForceTuple.My = value; + OnPropertyChanged(nameof(FinishMy)); + } + } + public double FinishNz + { + get => FinishDesignForce.ForceTuple.Nz; + set + { + FinishDesignForce.ForceTuple.Nz = value; + OnPropertyChanged(nameof(FinishNz)); + } + } + public int StepCount + { + get => stepCount; set + { + stepCount = value; + OnPropertyChanged(nameof(StepCount)); + } + } + + public ICommand InvertForcesCommand + { + get => invertForcesCommand ??= new RelayCommand(o => InvertForces()); + } + public ICommand CopyToStartCommand + { + get => copyToStartCommand ??= new RelayCommand(o => CopyFinishToStart()); + } + public ICommand CopyToFinishCommand + { + get => copyToFinishCommand ??= new RelayCommand(o => CopyStartToFinish()); + } + public InterpolateTuplesResult Result + { + get => new() + { + StartTuple = StartDesignForce, + FinishTuple = FinishDesignForce, + StepCount = StepCount + }; + } + + private void InvertForces() + { + var tmpForce = StartDesignForce.Clone() as IDesignForceTuple; + StartDesignForce = FinishDesignForce; + FinishDesignForce = tmpForce; + StepCountVisible = true; + RefreshStartTuple(); + RefreshFinishTuple(); + } + + private void CopyStartToFinish() + { + FinishDesignForce = StartDesignForce.Clone() as IDesignForceTuple; + RefreshFinishTuple(); + } + + private void CopyFinishToStart() + { + StartDesignForce = FinishDesignForce.Clone() as IDesignForceTuple; + RefreshStartTuple(); + } + + public void RefreshFinishTuple() + { + OnPropertyChanged(nameof(FinishDesignForce)); + OnPropertyChanged(nameof(FinishMx)); + OnPropertyChanged(nameof(FinishMy)); + OnPropertyChanged(nameof(FinishNz)); + } + + public void RefreshStartTuple() + { + OnPropertyChanged(nameof(StartDesignForce)); + OnPropertyChanged(nameof(StartMx)); + OnPropertyChanged(nameof(StartMy)); + OnPropertyChanged(nameof(StartNz)); + } + + public ForceTupleInterpolationViewModel(IDesignForceTuple finishDesignForce, IDesignForceTuple startDesignForce = null, int stepCount = 100) + { + if (startDesignForce != null) + { + CheckDesignForces(finishDesignForce, startDesignForce); + StartDesignForce = startDesignForce; + } + else + { + GetNewDesignForce(finishDesignForce); + } + FinishDesignForce = finishDesignForce; + StepCount = stepCount; + StepCountVisible = true; + } + public ForceTupleInterpolationViewModel() + { + + } + + private static void CheckDesignForces(IDesignForceTuple finishDesignForce, IDesignForceTuple startDesignForce) + { + if (startDesignForce.LimitState != finishDesignForce.LimitState) + { + throw new StructureHelperException(ErrorStrings.LimitStatesIsNotValid); + } + if (startDesignForce.CalcTerm != finishDesignForce.CalcTerm) + { + throw new StructureHelperException(ErrorStrings.LoadTermIsNotValid); + } + } + + private void GetNewDesignForce(IDesignForceTuple finishDesignForce) + { + StartDesignForce = new DesignForceTuple() + { + CalcTerm = finishDesignForce.CalcTerm, + LimitState = finishDesignForce.LimitState, + ForceTuple = new ForceTuple() + { + Mx = 0, + My = 0, + Nz = 0 + }, + }; + } + } +} diff --git a/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml b/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml index 5823dfc..911b889 100644 --- a/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml +++ b/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml @@ -8,7 +8,7 @@ xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls" d:DataContext="{d:DesignInstance local:InterpolateTuplesViewModel}" mc:Ignorable="d" - Title="Interpolate Combinations" Height="200" Width="460" MinHeight="180" MinWidth="460" WindowStartupLocation="CenterScreen"> + Title="Interpolate Combinations" Height="250" Width="460" MinHeight="250" MinWidth="460" WindowStartupLocation="CenterScreen">