diff --git a/StructureHelper/StructureHelper.csproj.user b/StructureHelper/StructureHelper.csproj.user index 024985a..9146fef 100644 --- a/StructureHelper/StructureHelper.csproj.user +++ b/StructureHelper/StructureHelper.csproj.user @@ -15,7 +15,7 @@ Code - + Code @@ -59,7 +59,7 @@ Designer - + Designer diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs new file mode 100644 index 0000000..d5fdd90 --- /dev/null +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs @@ -0,0 +1,155 @@ +using LoaderCalculator; +using StructureHelper.Windows.Graphs; +using StructureHelper.Windows.ViewModels.Errors; +using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Infrastructures.Settings; +using StructureHelperCommon.Models.Parameters; +using StructureHelperCommon.Services.Units; +using StructureHelperLogics.NdmCalculations.Analyses.ByForces; +using StructureHelperLogics.NdmCalculations.Cracking; +using StructureHelperLogics.NdmCalculations.Primitives; +using StructureHelperLogics.Services.NdmPrimitives; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews +{ + internal class CrackDiagramLogic : ILongProcessLogic + { + static readonly CrackForceCalculator calculator = new(); + private List ValidTupleList { get; set; } + ArrayParameter arrayParameter; + private IEnumerable TupleList { get; set; } + private IEnumerable NdmPrimitives { get; set; } + + private static GeometryNames GeometryNames => ProgramSetting.GeometryNames; + + public Action SetProgress { get; set; } + public bool Result { get; set; } + + public int StepCount => ValidTupleList.Count(); + + public CrackDiagramLogic(IEnumerable tupleList, IEnumerable ndmPrimitives) + { + TupleList = tupleList; + NdmPrimitives = ndmPrimitives; + ValidTupleList = TupleList.Where(x => x.IsValid == true).ToList(); + } + + public void WorkerDoWork(object sender, DoWorkEventArgs e) + { + ShowCracks(); + Result = true; + } + + public void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) + { + //nothing to do + } + + public void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) + { + //nothing to do + } + + public void ShowCracks() + { + var unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN"); + var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm"); + var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m"); + + string[] labels = GetCrackLabels(unitForce, unitMoment, unitCurvature); + arrayParameter = new ArrayParameter(ValidTupleList.Count(), labels.Count(), labels); + CalculateWithCrack(ValidTupleList, NdmPrimitives, unitForce, unitMoment, unitCurvature); + } + + public void ShowWindow() + { + SafetyProcessor.RunSafeProcess(() => + { + var wnd = new GraphView(arrayParameter); + wnd.ShowDialog(); + }, + "Errors appeared during showing a graph, see detailed information"); + } + + private void CalculateWithCrack(List validTupleList, IEnumerable ndmPrimitives, IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) + { + var data = arrayParameter.Data; + for (int i = 0; i < validTupleList.Count(); i++) + { + var valueList = new List + { + validTupleList[i].DesignForceTuple.ForceTuple.Mx * unitMoment.Multiplyer, + validTupleList[i].DesignForceTuple.ForceTuple.My * unitMoment.Multiplyer, + validTupleList[i].DesignForceTuple.ForceTuple.Nz * unitForce.Multiplyer + }; + calculator.EndTuple = validTupleList[i].DesignForceTuple.ForceTuple; + var limitState = validTupleList[i].DesignForceTuple.LimitState; + var calcTerm = validTupleList[i].DesignForceTuple.CalcTerm; + var ndms = NdmPrimitivesService.GetNdms(ndmPrimitives, limitState, calcTerm); + calculator.NdmCollection = ndms; + calculator.Run(); + var result = (CrackForceResult)calculator.Result; + if (result.IsValid == false) + { + MessageBox.Show( + "Result is not valid", + "Crack results", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + return; + } + valueList.Add(result.CrackedStrainTuple.Mx); + valueList.Add(result.CrackedStrainTuple.My); + valueList.Add(result.CrackedStrainTuple.Nz); + + valueList.Add(result.ReducedStrainTuple.Mx); + valueList.Add(result.ReducedStrainTuple.My); + valueList.Add(result.ReducedStrainTuple.Nz); + + valueList.Add(result.SofteningFactors.Mx); + valueList.Add(result.SofteningFactors.My); + valueList.Add(result.SofteningFactors.Nz); + + valueList.Add(result.PsiS); + + for (int j = 0; j < valueList.Count; j++) + { + data[i, j] = valueList[j]; + } + + SetProgress?.Invoke(i); + } + } + + private static string[] GetCrackLabels(IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) + { + const string crc = "Crc"; + const string crcFactor = "CrcSofteningFactor"; + return new string[] + { + $"{GeometryNames.MomFstName}, {unitMoment.Name}", + $"{GeometryNames.MomSndName}, {unitMoment.Name}", + $"{GeometryNames.LongForceName}, {unitForce.Name}", + $"{GeometryNames.CurvFstName}, {unitCurvature.Name}", + $"{GeometryNames.CurvSndName}, {unitCurvature.Name}", + $"{GeometryNames.StrainTrdName}", + $"{crc}{GeometryNames.CurvFstName}, {unitCurvature.Name}", + $"{crc}{GeometryNames.CurvSndName}, {unitCurvature.Name}", + $"{crc}{GeometryNames.StrainTrdName}", + $"{crcFactor}Ix", + $"{crcFactor}Iy", + $"{crcFactor}Az", + $"PsiFactor" + }; + } + + } +} diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressView.xaml b/StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressView.xaml similarity index 58% rename from StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressView.xaml rename to StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressView.xaml index 1963305..6b512b7 100644 --- a/StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressView.xaml +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressView.xaml @@ -1,12 +1,12 @@ - + d:DataContext="{d:DesignInstance local:ShowProgressViewModel}" + Title="{Binding WindowTitle}" Height="150" Width="400" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None"> @@ -16,14 +16,16 @@ + - - - - - - + + + + + + + diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressView.xaml.cs b/StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressView.xaml.cs similarity index 79% rename from StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressView.xaml.cs rename to StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressView.xaml.cs index d59bb9d..e49abec 100644 --- a/StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressView.xaml.cs +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressView.xaml.cs @@ -18,10 +18,10 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews /// /// Логика взаимодействия для InterpolationProgressView.xaml /// - public partial class InterpolationProgressView : Window + public partial class ShowProgressView : Window { - InterpolationProgressViewModel viewModel; - public InterpolationProgressView(InterpolationProgressViewModel viewModel) + ShowProgressViewModel viewModel; + public ShowProgressView(ShowProgressViewModel viewModel) { InitializeComponent(); this.viewModel = viewModel; diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressViewModel.cs b/StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressViewModel.cs similarity index 90% rename from StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressViewModel.cs rename to StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressViewModel.cs index 7628212..0ef1a21 100644 --- a/StructureHelper/Windows/CalculationWindows/ProgressViews/InterpolationProgressViewModel.cs +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/ShowProgressViewModel.cs @@ -7,12 +7,14 @@ using System.Threading.Tasks; namespace StructureHelper.Windows.CalculationWindows.ProgressViews { - public class InterpolationProgressViewModel : ViewModelBase + public class ShowProgressViewModel : ViewModelBase { private double progressValue; private double maxValue; private double minValue; + public string WindowTitle { get; set; } + public double MinValue { get => minValue; set diff --git a/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml b/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml index 5c675b7..fdfdbd7 100644 --- a/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml +++ b/StructureHelper/Windows/Forces/InterpolateTuplesView.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:StructureHelper.Windows.Forces" xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Forces" xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls" - d:DataContext="{d:DesignInstance vm:InterpolateTuplesViewModel}" + d:DataContext="{d:DesignInstance local:InterpolateTuplesViewModel}" mc:Ignorable="d" Title="Interpolate Combinations" Height="200" Width="400" MinHeight="180" MinWidth="400" WindowStartupLocation="CenterScreen"> diff --git a/StructureHelper/Windows/ViewModels/Forces/InterpolateTuplesViewModel.cs b/StructureHelper/Windows/Forces/InterpolateTuplesViewModel.cs similarity index 93% rename from StructureHelper/Windows/ViewModels/Forces/InterpolateTuplesViewModel.cs rename to StructureHelper/Windows/Forces/InterpolateTuplesViewModel.cs index 86805fe..2df7d0a 100644 --- a/StructureHelper/Windows/ViewModels/Forces/InterpolateTuplesViewModel.cs +++ b/StructureHelper/Windows/Forces/InterpolateTuplesViewModel.cs @@ -1,14 +1,10 @@ using StructureHelper.Infrastructure; +using StructureHelper.Windows.ViewModels; 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.ViewModels.Forces +namespace StructureHelper.Windows.Forces { public class InterpolateTuplesViewModel : OkCancelViewModelBase { @@ -91,6 +87,16 @@ namespace StructureHelper.Windows.ViewModels.Forces 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; diff --git a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/InterpolateLogic.cs b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/InterpolateLogic.cs deleted file mode 100644 index c7f17a4..0000000 --- a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/InterpolateLogic.cs +++ /dev/null @@ -1,112 +0,0 @@ -using LoaderCalculator; -using LoaderCalculator.Data.ResultData; -using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews; -using StructureHelper.Windows.CalculationWindows.ProgressViews; -using StructureHelper.Windows.Forces; -using StructureHelper.Windows.ViewModels.Forces; -using StructureHelperCommon.Models.Calculators; -using StructureHelperCommon.Models.Forces; -using StructureHelperLogics.NdmCalculations.Analyses.ByForces; -using StructureHelperLogics.Services.NdmCalculations; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Forms; - -namespace StructureHelper.Windows.ViewModels.Calculations.Calculators -{ - internal class InterpolateLogic - { - private InterpolationProgressViewModel progressViewModel; - private InterpolationProgressView wndProgress; - private IForceCalculator forceCalculator; - private IDesignForceTuple finishDesignTuple; - private IDesignForceTuple startDesignTuple; - private int stepCount; - private IResult result; - private IForceCalculator interpolateCalculator; - - public void Show(IDesignForceTuple finishTuple, IForceCalculator forceCalculator) - { - this.forceCalculator = forceCalculator; - var viewModel = new InterpolateTuplesViewModel(finishTuple, null); - var wndTuples = new InterpolateTuplesView(viewModel); - wndTuples.ShowDialog(); - if (wndTuples.DialogResult != true) return; - - startDesignTuple = viewModel.StartDesignForce; - finishDesignTuple = viewModel.FinishDesignForce; - stepCount = viewModel.StepCount; - progressViewModel = new() - { - MinValue = 0, - MaxValue = stepCount, - ProgressValue = 0 - }; - - wndProgress =new InterpolationProgressView(progressViewModel); - wndProgress.Loaded += RunCalc; - wndProgress.ShowDialog(); - } - - private void RunCalc(object sender, RoutedEventArgs e) - { - BackgroundWorker worker = new(); - worker.DoWork += WorkerDoWork; - worker.ProgressChanged += WorkerProgressChanged; - worker.RunWorkerCompleted += WorkerRunWorkCompleted; - worker.RunWorkerAsync(); - } - - private void ShowProgressResult(IResult result) - { - if (result is ForcesResults) - { - var forceResult = result as ForcesResults; - progressViewModel.ProgressValue = forceResult.ForcesResultList.Count(); - } - } - - private void WorkerDoWork(object sender, DoWorkEventArgs e) - { - interpolateCalculator = InterpolateService.InterpolateForceCalculator(forceCalculator, finishDesignTuple, startDesignTuple, stepCount); - interpolateCalculator.ActionToOutputResults = ShowProgressResult; - interpolateCalculator.Run(); - result = interpolateCalculator.Result; - } - - private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) - { - - } - - private void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) - { - try - { - wndProgress.Close(); - - if (result is null || result.IsValid == false) - { - System.Windows.Forms.MessageBox.Show(result.Description, "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - else - { - var vm = new ForcesResultsViewModel(interpolateCalculator); - var wnd = new ForceResultsView(vm); - wnd.ShowDialog(); - } - } - catch (Exception ex) - { - - throw; - } - } - } -} diff --git a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowDiagramLogic.cs b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowDiagramLogic.cs index f049b85..c3d8bd2 100644 --- a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowDiagramLogic.cs +++ b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowDiagramLogic.cs @@ -7,6 +7,7 @@ using StructureHelper.Windows.ViewModels.Errors; using StructureHelper.Windows.ViewModels.Graphs; using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models.Parameters; using StructureHelperCommon.Services.Units; @@ -16,6 +17,7 @@ using StructureHelperLogics.NdmCalculations.Primitives; using StructureHelperLogics.Services.NdmPrimitives; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,87 +25,63 @@ using System.Windows.Forms; namespace StructureHelper.Windows.ViewModels.Calculations.Calculators { - internal class ShowDiagramLogic + internal class ShowDiagramLogic : ILongProcessLogic { - static readonly CrackForceCalculator calculator = new(); ArrayParameter arrayParameter; + private IEnumerable TupleList; + private IEnumerable NdmPrimitives; + private List ValidTupleList; + private static GeometryNames GeometryNames => ProgramSetting.GeometryNames; - public void Show(List results) + public int StepCount => ValidTupleList.Count(); + + public Action SetProgress { get ; set; } + public bool Result { get; set; } + + public void WorkerDoWork(object sender, DoWorkEventArgs e) { - var resultList = results.Where(x => x.IsValid == true).ToList(); + Show(); + Result = true; + } + + public void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) + { + //nothing to do + } + + public void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) + { + //nothing to do + } + public void ShowWindow() + { + SafetyProcessor.RunSafeProcess(() => + { + var wnd = new GraphView(arrayParameter); + wnd.ShowDialog(); + }, + "Errors appeared during showing a graph, see detailed information"); + } + private void Show() + { + ValidTupleList = TupleList.Where(x => x.IsValid == true).ToList(); var unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN"); var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm"); var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m"); string[] labels = GetLabels(unitForce, unitMoment, unitCurvature); - arrayParameter = new ArrayParameter(resultList.Count(), labels.Count(), labels); - CalculateWithoutCrack(resultList, unitForce, unitMoment, unitCurvature); - SafetyProcessor.RunSafeProcess(ShowWindow, "Errors appeared during showing a graph, see detail information"); - } - public void ShowCracks(List results, IEnumerable ndmPrimitives) - { - var resultList = results.Where(x => x.IsValid == true).ToList(); - var unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN"); - var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm"); - var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m"); - - string[] labels = GetCrackLabels(unitForce, unitMoment, unitCurvature); - arrayParameter = new ArrayParameter(resultList.Count(), labels.Count(), labels); - CalculateWithCrack(resultList, ndmPrimitives, unitForce, unitMoment, unitCurvature); - SafetyProcessor.RunSafeProcess(ShowWindow, "Errors appeared during showing a graph, see detailed information"); + arrayParameter = new ArrayParameter(ValidTupleList.Count(), labels.Count(), labels); + CalculateWithoutCrack(ValidTupleList, unitForce, unitMoment, unitCurvature); } - private void CalculateWithCrack(List resultList, IEnumerable ndmPrimitives, IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) + public ShowDiagramLogic(IEnumerable tupleList, IEnumerable ndmPrimitives) { - var data = arrayParameter.Data; - for (int i = 0; i < resultList.Count(); i++) - { - var valueList = new List - { - resultList[i].DesignForceTuple.ForceTuple.Mx * unitMoment.Multiplyer, - resultList[i].DesignForceTuple.ForceTuple.My * unitMoment.Multiplyer, - resultList[i].DesignForceTuple.ForceTuple.Nz * unitForce.Multiplyer - }; - calculator.EndTuple = resultList[i].DesignForceTuple.ForceTuple; - var limitState = resultList[i].DesignForceTuple.LimitState; - var calcTerm = resultList[i].DesignForceTuple.CalcTerm; - var ndms = NdmPrimitivesService.GetNdms(ndmPrimitives, limitState, calcTerm); - calculator.NdmCollection = ndms; - calculator.Run(); - var result = (CrackForceResult)calculator.Result; - if (result.IsValid == false) - { - MessageBox.Show( - "Result is not valid", - "Crack results", - MessageBoxButtons.OK, - MessageBoxIcon.Information); - return; - } - valueList.Add(result.CrackedStrainTuple.Mx); - valueList.Add(result.CrackedStrainTuple.My); - valueList.Add(result.CrackedStrainTuple.Nz); - - valueList.Add(result.ReducedStrainTuple.Mx); - valueList.Add(result.ReducedStrainTuple.My); - valueList.Add(result.ReducedStrainTuple.Nz); - - valueList.Add(result.SofteningFactors.Mx); - valueList.Add(result.SofteningFactors.My); - valueList.Add(result.SofteningFactors.Nz); - - valueList.Add(result.PsiS); - - for (int j = 0; j < valueList.Count; j++) - { - data[i, j] = valueList[j]; - } - } + TupleList = tupleList; + NdmPrimitives = ndmPrimitives; + ValidTupleList = TupleList.Where(x => x.IsValid == true).ToList(); } - - private void CalculateWithoutCrack(List resultList, IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) { var data = arrayParameter.Data; @@ -114,14 +92,10 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators { data[i, j] = valueList[j]; } + SetProgress?.Invoke(i); } } - private void ShowWindow() - { - var wnd = new GraphView(arrayParameter); - wnd.ShowDialog(); - } private static List ProcessResultWithouCrack(List resultList, IUnit unitForce, IUnit unitMoment, IUnit unitCurvature, int i) { @@ -147,26 +121,6 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators $"{GeometryNames.StrainTrdName}" }; } - private static string[] GetCrackLabels(IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) - { - const string crc = "Crc"; - const string crcFactor = "CrcSofteningFactor"; - return new string[] - { - $"{GeometryNames.MomFstName}, {unitMoment.Name}", - $"{GeometryNames.MomSndName}, {unitMoment.Name}", - $"{GeometryNames.LongForceName}, {unitForce.Name}", - $"{GeometryNames.CurvFstName}, {unitCurvature.Name}", - $"{GeometryNames.CurvSndName}, {unitCurvature.Name}", - $"{GeometryNames.StrainTrdName}", - $"{crc}{GeometryNames.CurvFstName}, {unitCurvature.Name}", - $"{crc}{GeometryNames.CurvSndName}, {unitCurvature.Name}", - $"{crc}{GeometryNames.StrainTrdName}", - $"{crcFactor}Ix", - $"{crcFactor}Iy", - $"{crcFactor}Az", - $"PsiFactor" - }; - } + } } diff --git a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowProgressLogic.cs b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowProgressLogic.cs new file mode 100644 index 0000000..7dc3ed8 --- /dev/null +++ b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForceResultLogic/ShowProgressLogic.cs @@ -0,0 +1,89 @@ +using StructureHelper.Windows.CalculationWindows.ProgressViews; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Forces; +using StructureHelperLogics.NdmCalculations.Analyses.ByForces; +using System; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Forms; + +namespace StructureHelper.Windows.ViewModels.Calculations.Calculators +{ + internal class ShowProgressLogic + { + private ShowProgressViewModel progressViewModel; + private ShowProgressView wndProgress; + private bool result; + private string resultDescription; + private ILongProcessLogic processLogic; + + public string WindowTitle { get; set; } + + public void Show() + { + progressViewModel = new() + { + MinValue = 0, + MaxValue = processLogic.StepCount, + ProgressValue = 0, + WindowTitle = WindowTitle + }; + + wndProgress =new ShowProgressView(progressViewModel); + wndProgress.Loaded += RunCalc; + wndProgress.ShowDialog(); + } + + public Action ShowResult { get; set; } + + public ShowProgressLogic(ILongProcessLogic processLogic) + { + this.processLogic = processLogic; + processLogic.SetProgress = ShowProgressResult; + } + + public void ShowProgressResult(int progressValue) + { + progressViewModel.ProgressValue = progressValue; + } + + private void RunCalc(object sender, RoutedEventArgs e) + { + BackgroundWorker worker = new(); + worker.DoWork += processLogic.WorkerDoWork; + worker.ProgressChanged += WorkerProgressChanged; + worker.RunWorkerCompleted += WorkerRunWorkCompleted; + worker.RunWorkerAsync(); + } + + private void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) + { + processLogic.WorkerProgressChanged(sender, e); + } + + private void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) + { + try + { + processLogic.WorkerRunWorkCompleted(sender, e); + wndProgress.Close(); + result = processLogic.Result; + if (result == true) + { + ShowResult?.Invoke(); + } + else + { + System.Windows.Forms.MessageBox.Show(resultDescription, "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + catch (Exception ex) + { + + throw; + } + } + } +} diff --git a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForcesResultsViewModel.cs b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForcesResultsViewModel.cs index 5d1d545..217d71e 100644 --- a/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForcesResultsViewModel.cs +++ b/StructureHelper/Windows/ViewModels/Calculations/Calculators/ForcesResultsViewModel.cs @@ -6,19 +6,23 @@ using StructureHelper.Services.Reports; using StructureHelper.Services.Reports.CalculationReports; using StructureHelper.Services.ResultViewers; using StructureHelper.Windows.CalculationWindows.CalculatorsViews; +using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews; using StructureHelper.Windows.CalculationWindows.CalculatorsViews.GeometryCalculatorViews; using StructureHelper.Windows.Errors; +using StructureHelper.Windows.Forces; using StructureHelper.Windows.PrimitivePropertiesWindow; using StructureHelper.Windows.ViewModels.Calculations.Calculators.ForceResultLogic; using StructureHelper.Windows.ViewModels.Errors; using StructureHelper.Windows.ViewModels.PrimitiveProperties; using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Services.Forces; using StructureHelperLogics.NdmCalculations.Analyses; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; +using StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics; using StructureHelperLogics.NdmCalculations.Analyses.Geometry; using StructureHelperLogics.NdmCalculations.Primitives; using StructureHelperLogics.NdmCalculations.Triangulations; @@ -32,11 +36,12 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators { public class ForcesResultsViewModel : ViewModelBase { - private static readonly ShowDiagramLogic showDiagramLogic = new(); - private static readonly InterpolateLogic interpolateLogic = new(); + private ShowDiagramLogic showDiagramLogic; + private ForceCalculator forceCalculator; + private ILongProcessLogic progressLogic; + private ShowProgressLogic showProgressLogic; private static readonly ShowCrackResultLogic showCrackResultLogic = new(); private static readonly ShowCrackWidthLogic showCrackWidthLogic = new(); - private IForceCalculator forceCalculator; private IForcesResults forcesResults; private IEnumerable ndmPrimitives; private IEnumerable selectedNdmPrimitives; @@ -101,7 +106,30 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators { get => showGraphsCommand ??= new RelayCommand(o => { - showDiagramLogic.Show(forcesResults.ForcesResultList); + InterpolateTuplesViewModel interploateTuplesViewModel; + InterpolateTuplesView wndTuples; + ShowInterpolationWindow(out interploateTuplesViewModel, out wndTuples); + if (wndTuples.DialogResult != true) return; + + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.Result); + showProgressLogic = new(interpolationLogic) + { + WindowTitle = "Interpolate forces" + }; + showProgressLogic.Show(); + + var result = interpolationLogic.InterpolateCalculator.Result; + if (result is IForcesResults) + { + var tupleResult = result as IForcesResults; + var diagramLogic = new ShowDiagramLogic(tupleResult.ForcesResultList, ndmPrimitives); + showProgressLogic = new(diagramLogic) + { + ShowResult = diagramLogic.ShowWindow, + WindowTitle = "Calculate crack diagram" + }; + showProgressLogic.Show(); + } } ); } @@ -109,7 +137,30 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators { get => showCrackGraphsCommand ??= new RelayCommand(o => { - showDiagramLogic.ShowCracks(forcesResults.ForcesResultList, ndmPrimitives); + InterpolateTuplesViewModel interploateTuplesViewModel; + InterpolateTuplesView wndTuples; + ShowInterpolationWindow(out interploateTuplesViewModel, out wndTuples); + if (wndTuples.DialogResult != true) return; + + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.Result); + showProgressLogic = new(interpolationLogic) + { + WindowTitle = "Interpolate forces" + }; + showProgressLogic.Show(); + + var result = interpolationLogic.InterpolateCalculator.Result; + if (result is IForcesResults) + { + var tupleResult = result as IForcesResults; + var diagramLogic = new CrackDiagramLogic(tupleResult.ForcesResultList, ndmPrimitives); + showProgressLogic = new(diagramLogic) + { + ShowResult = diagramLogic.ShowWindow, + WindowTitle = "Calculate crack diagram" + }; + showProgressLogic.Show(); + } } ); } @@ -152,11 +203,45 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators return interpolateCommand ?? (interpolateCommand = new RelayCommand(o => { - IDesignForceTuple finishDesignTuple = SelectedResult.DesignForceTuple.Clone() as IDesignForceTuple; - interpolateLogic.Show(finishDesignTuple, forceCalculator); + InterpolateCurrentTuple(); }, o => SelectedResult != null)); } } + + private void InterpolateCurrentTuple() + { + InterpolateTuplesViewModel interploateTuplesViewModel; + InterpolateTuplesView wndTuples; + ShowInterpolationWindow(out interploateTuplesViewModel, out wndTuples); + if (wndTuples.DialogResult != true) return; + + var interpolationLogic = new InterpolationProgressLogic(forceCalculator, interploateTuplesViewModel.Result); + progressLogic = interpolationLogic; + showProgressLogic = new(interpolationLogic); + showProgressLogic.ShowResult = ShowInterpolationProgressDialog; + showProgressLogic.Show(); + } + + private void ShowInterpolationWindow(out InterpolateTuplesViewModel interploateTuplesViewModel, out InterpolateTuplesView wndTuples) + { + IDesignForceTuple finishDesignTuple = SelectedResult.DesignForceTuple.Clone() as IDesignForceTuple; + interploateTuplesViewModel = new InterpolateTuplesViewModel(finishDesignTuple, null); + wndTuples = new InterpolateTuplesView(interploateTuplesViewModel); + wndTuples.ShowDialog(); + } + + private void ShowInterpolationProgressDialog() + { + if (progressLogic is InterpolationProgressLogic) + { + var interpolationLogic = progressLogic as InterpolationProgressLogic; + var calculator = interpolationLogic.InterpolateCalculator; + var vm = new ForcesResultsViewModel(calculator); + var wnd = new ForceResultsView(vm); + wnd.ShowDialog(); + } + } + public ICommand SetPrestrainCommand { get @@ -243,11 +328,11 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators } } } - public ForcesResultsViewModel(IForceCalculator forceCalculator) + public ForcesResultsViewModel(ForceCalculator forceCalculator) { this.forceCalculator = forceCalculator; - this.forcesResults = this.forceCalculator.Result as IForcesResults; - ndmPrimitives = this.forceCalculator.Primitives; + forcesResults = forceCalculator.Result as IForcesResults; + ndmPrimitives = forceCalculator.Primitives; } private void ShowIsoField() { diff --git a/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs b/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs index 572bf7d..ac138b5 100644 --- a/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs +++ b/StructureHelper/Windows/ViewModels/NdmCrossSections/AnalysisVewModelLogic.cs @@ -83,7 +83,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections } else { - var calculator = SelectedItem as IForceCalculator; + var calculator = SelectedItem as ForceCalculator; var vm = new ForcesResultsViewModel(calculator); var wnd = new ForceResultsView(vm); wnd.ShowDialog(); diff --git a/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs b/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs new file mode 100644 index 0000000..72ecb43 --- /dev/null +++ b/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs @@ -0,0 +1,22 @@ +using StructureHelperCommon.Models.Calculators; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StructureHelperCommon.Infrastructures.Interfaces +{ + public interface ILongProcessLogic + { + int StepCount { get; } + Action SetProgress { get; set; } + bool Result { get; set; } + + void WorkerDoWork(object sender, DoWorkEventArgs e); + void WorkerProgressChanged(object sender, ProgressChangedEventArgs e); + void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e); + } +} diff --git a/StructureHelperCommon/Models/Forces/InterpolateTuplesResult.cs b/StructureHelperCommon/Models/Forces/InterpolateTuplesResult.cs new file mode 100644 index 0000000..d576653 --- /dev/null +++ b/StructureHelperCommon/Models/Forces/InterpolateTuplesResult.cs @@ -0,0 +1,9 @@ +namespace StructureHelperCommon.Models.Forces +{ + public class InterpolateTuplesResult + { + public IDesignForceTuple StartTuple { get; set; } + public IDesignForceTuple FinishTuple { get; set; } + public int StepCount { get; set; } + } +} diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs new file mode 100644 index 0000000..6ea9342 --- /dev/null +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/Logics/InterpolationProgressLogic.cs @@ -0,0 +1,59 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Forces; +using StructureHelperLogics.Services.NdmCalculations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics +{ + public class InterpolationProgressLogic : ILongProcessLogic + { + private ForceCalculator forceCalculator; + private InterpolateTuplesResult interpolateTuplesResult; + + public Action SetProgress { get; set; } + + public ForceCalculator InterpolateCalculator { get; private set; } + public bool Result { get; set; } + + public int StepCount => interpolateTuplesResult.StepCount + 1; + + public void WorkerDoWork(object sender, DoWorkEventArgs e) + { + InterpolateCalculator = InterpolateService.InterpolateForceCalculator(forceCalculator, interpolateTuplesResult); + InterpolateCalculator.ActionToOutputResults = ShowProgressResult; + InterpolateCalculator.Run(); + } + + public void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) + { + //nothing to do + } + + public void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) + { + //nothing to do + } + + public InterpolationProgressLogic(ForceCalculator forceCalculator, InterpolateTuplesResult interpolateTuplesResult) + { + this.forceCalculator = forceCalculator; + this.interpolateTuplesResult = interpolateTuplesResult; + } + + private void ShowProgressResult(IResult result) + { + if (result is ForcesResults) + { + var forceResult = result as ForcesResults; + SetProgress?.Invoke(forceResult.ForcesResultList.Count()); + Result = forceResult.IsValid; + } + } + } +} diff --git a/StructureHelperLogics/Services/NdmCalculations/InterpolateService.cs b/StructureHelperLogics/Services/NdmCalculations/InterpolateService.cs index a8ff145..921dbc4 100644 --- a/StructureHelperLogics/Services/NdmCalculations/InterpolateService.cs +++ b/StructureHelperLogics/Services/NdmCalculations/InterpolateService.cs @@ -8,18 +8,18 @@ namespace StructureHelperLogics.Services.NdmCalculations public static class InterpolateService { static readonly CompressedMemberUpdateStrategy compressedMemberUpdateStrategy = new(); - public static IForceCalculator InterpolateForceCalculator(IForceCalculator source, IDesignForceTuple finishDesignForce,IDesignForceTuple startDesignForce, int stepCount) + public static ForceCalculator InterpolateForceCalculator(IForceCalculator source, InterpolateTuplesResult interpolateTuplesResult) { - IForceCalculator calculator = new ForceCalculator(); + ForceCalculator calculator = new ForceCalculator(); calculator.LimitStatesList.Clear(); - calculator.LimitStatesList.Add(finishDesignForce.LimitState); + calculator.LimitStatesList.Add(interpolateTuplesResult.StartTuple.LimitState); calculator.CalcTermsList.Clear(); - calculator.CalcTermsList.Add(finishDesignForce.CalcTerm); + calculator.CalcTermsList.Add(interpolateTuplesResult.FinishTuple.CalcTerm); compressedMemberUpdateStrategy.Update(calculator.CompressedMember, source.CompressedMember); calculator.Accuracy = source.Accuracy; calculator.Primitives.AddRange(source.Primitives); calculator.ForceActions.Clear(); - var forceTuples = ForceTupleService.InterpolateDesignTuple(finishDesignForce, startDesignForce, stepCount); + var forceTuples = ForceTupleService.InterpolateDesignTuple(interpolateTuplesResult.FinishTuple, interpolateTuplesResult.StartTuple, interpolateTuplesResult.StepCount); foreach (var forceTuple in forceTuples) { var combination = new ForceCombinationList()