diff --git a/StructureHelper/Documentation/FilesForImport/Forces/DCF.xlsx b/StructureHelper/Documentation/FilesForImport/Forces/DCF.xlsx new file mode 100644 index 0000000..e238b26 Binary files /dev/null and b/StructureHelper/Documentation/FilesForImport/Forces/DCF.xlsx differ diff --git a/StructureHelper/Infrastructure/Enums/ActionType.cs b/StructureHelper/Infrastructure/Enums/ActionType.cs index 3a81918..2b2909a 100644 --- a/StructureHelper/Infrastructure/Enums/ActionType.cs +++ b/StructureHelper/Infrastructure/Enums/ActionType.cs @@ -9,6 +9,7 @@ namespace StructureHelper.Infrastructure.Enums public enum ActionType { ForceCombination, - ForceCombinationByFactor + ForceCombinationByFactor, + ForceCombinationFromFile } } diff --git a/StructureHelper/Infrastructure/UI/Resources/ForceTemplates.xaml b/StructureHelper/Infrastructure/UI/Resources/ForceTemplates.xaml index 39c13cf..0e08bc1 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ForceTemplates.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ForceTemplates.xaml @@ -1,27 +1,40 @@  - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + diff --git a/StructureHelper/StructureHelper.csproj b/StructureHelper/StructureHelper.csproj index 1187d8f..3b413bc 100644 --- a/StructureHelper/StructureHelper.csproj +++ b/StructureHelper/StructureHelper.csproj @@ -90,6 +90,7 @@ + diff --git a/StructureHelper/StructureHelper.csproj.user b/StructureHelper/StructureHelper.csproj.user index 018a483..9e439e8 100644 --- a/StructureHelper/StructureHelper.csproj.user +++ b/StructureHelper/StructureHelper.csproj.user @@ -45,6 +45,12 @@ Code + + Code + + + Code + Code @@ -87,6 +93,9 @@ Code + + Code + Code @@ -152,6 +161,12 @@ Designer + + Designer + + + Designer + Designer @@ -194,6 +209,9 @@ Designer + + Designer + Designer diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultView.xaml b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultView.xaml index 15b7887..af65392 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultView.xaml +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultView.xaml @@ -33,6 +33,7 @@ + @@ -114,6 +115,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultViewModel.cs index 715ad19..5e839fa 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultViewModel.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/Cracks/CrackResultViewModel.cs @@ -12,10 +12,14 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews public class CrackResultViewModel : ViewModelBase { IShowCrackIsoFieldsLogic showCrackIsoFieldsLogic => new ShowCrackIsoFieldsLogic(); - private CrackResult crackResult; + private CrackResult resultModel; private RelayCommand? showIsoFieldCommand; private RelayCommand? showRebarsCommand; + public int ValidResultCount => resultModel.TupleResults.Count(x => x.IsValid == true); + public int InvalidResultCount => resultModel.TupleResults.Count(x => x.IsValid == false); + public int TotalResultCount => resultModel.TupleResults.Count; + public TupleCrackResult SelectedResult { get; set; } public List TupleResults => CrackResult.TupleResults; public ICommand ShowRebarsCommand @@ -41,11 +45,11 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews } } - public CrackResult CrackResult => crackResult; + public CrackResult CrackResult => resultModel; public CrackResultViewModel(CrackResult crackResult) { - this.crackResult = crackResult; + this.resultModel = crackResult; } } } diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs index 0bd9b3b..1c84a89 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs @@ -44,7 +44,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu private InteractionDiagramLogic interactionDiagramLogic; private static readonly ShowCrackResultLogic showCrackResultLogic = new(); //private static readonly ShowCrackWidthLogic showCrackWidthLogic = new(); - private IForcesResults forcesResults; + private IForcesResults resultModel; private IEnumerable ndmPrimitives; private IEnumerable selectedNdmPrimitives; private IEnumerable ndms; @@ -67,13 +67,13 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu private ICommand? graphValuepointsCommand; private ICommand showForceResultCommand; - public int ValidResultCount => forcesResults.ForcesResultList.Count(x => x.IsValid == true); - public int InvalidResultCount => forcesResults.ForcesResultList.Count(x => x.IsValid == false); - public int TotalResultCount => forcesResults.ForcesResultList.Count; + public int ValidResultCount => resultModel.ForcesResultList.Count(x => x.IsValid == true); + public int InvalidResultCount => resultModel.ForcesResultList.Count(x => x.IsValid == false); + public int TotalResultCount => resultModel.ForcesResultList.Count; public IForcesResults ForcesResults { - get => forcesResults; + get => resultModel; } public ICommand ShowInteractionDiagramCommand { @@ -150,7 +150,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu Filter = "csv |*.csv", Title = "Save in *.csv File" }; - var logic = new ExportForcesResultToCSVLogic(forcesResults); + var logic = new ExportForcesResultToCSVLogic(resultModel); var exportService = new ExportToFileService(inputData, logic); exportService.Export(); } @@ -429,7 +429,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu public ForcesResultsViewModel(ForceCalculator forceCalculator) { this.forceCalculator = forceCalculator; - forcesResults = forceCalculator.Result as IForcesResults; + resultModel = forceCalculator.Result as IForcesResults; ndmPrimitives = forceCalculator.InputData.Primitives; } diff --git a/StructureHelper/Windows/Forces/FactoredCombinationPropertyVM.cs b/StructureHelper/Windows/Forces/FactoredCombinationPropertyVM.cs index 75584de..28f04e2 100644 --- a/StructureHelper/Windows/Forces/FactoredCombinationPropertyVM.cs +++ b/StructureHelper/Windows/Forces/FactoredCombinationPropertyVM.cs @@ -7,7 +7,7 @@ using System.ComponentModel; namespace StructureHelper.Windows.Forces { - public class FactoredCombinationPropertyVM : ViewModelBase, IFactoredCombinationProperty + public class FactoredCombinationPropertyVM : ViewModelBase, IDataErrorInfo { private IFactoredCombinationProperty sourceProperty; @@ -63,18 +63,29 @@ namespace StructureHelper.Windows.Forces } } - internal void UpdateCombinationProperty(IFactoredCombinationProperty? newValue) - { - sourceProperty = newValue; - Refresh(); - } + public string Error => throw new NotImplementedException(); - private void Refresh() + public string this[string columnName] { - OnPropertyChanged(nameof(ULSFactor)); - OnPropertyChanged(nameof(LongTermFactor)); - OnPropertyChanged(nameof(CalcTerm)); - OnPropertyChanged(nameof(LimitState)); + get + { + string error = null; + if (columnName == nameof(ULSFactor)) + { + if (ULSFactor <= 0) + { + error = "Safety factor for ULS must be greater than zero"; + } + } + if (columnName == nameof(LongTermFactor)) + { + if (LongTermFactor < 0d || LongTermFactor > 1d) + { + error = "Long term factor must be between 0.0 and 1.0"; + } + } + return error; + } } } } diff --git a/StructureHelper/Windows/Forces/ForceCombinationByFactorVM.cs b/StructureHelper/Windows/Forces/ForceCombinationByFactorVM.cs index be21677..aba7a37 100644 --- a/StructureHelper/Windows/Forces/ForceCombinationByFactorVM.cs +++ b/StructureHelper/Windows/Forces/ForceCombinationByFactorVM.cs @@ -12,18 +12,21 @@ namespace StructureHelper.Windows.Forces { public class ForceCombinationByFactorVM : ForceActionVMBase, IDataErrorInfo { - IForceFactoredList forceAction; + IForceFactoredList model; ForceTupleVM forceTupleVM; + private FactoredCombinationPropertyVM combinationProperty; public ForceTupleVM ForceTupleVM => forceTupleVM; - public IFactoredCombinationProperty CombinationProperty + public FactoredCombinationPropertyVM CombinationProperty { - get + get => combinationProperty; set { - return forceAction.CombinationProperty; + combinationProperty = value; + OnPropertyChanged(nameof(CombinationProperty)); } } + public string Error => throw new NotImplementedException(); public string this[string columnName] @@ -31,29 +34,15 @@ namespace StructureHelper.Windows.Forces get { string error = null; - - //if (columnName == nameof(ULSFactor)) - //{ - // if (ULSFactor <= 0) - // { - // error = "Safety factor for ULS must be greater than zero"; - // } - //} - //if (columnName == nameof(LongTermFactor)) - //{ - // if (LongTermFactor < 0d || LongTermFactor > 1d) - // { - // error = "Long term factor must be between 0.0 and 1.0"; - // } - //} return error; } } - public ForceCombinationByFactorVM(IForceFactoredList forceAction) : base(forceAction) + public ForceCombinationByFactorVM(IForceFactoredList model) : base(model) { - this.forceAction = forceAction; - forceTupleVM = new ForceTupleVM(this.forceAction.ForceTuples[0]); + this.model = model; + forceTupleVM = new ForceTupleVM(this.model.ForceTuples[0]); + CombinationProperty = new FactoredCombinationPropertyVM(model.CombinationProperty); } } } diff --git a/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml b/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml index eb7d754..4632a5f 100644 --- a/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml +++ b/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml @@ -7,36 +7,46 @@ xmlns:uc="clr-namespace:StructureHelper.Windows.UserControls" d:DataContext="{d:DesignInstance local:ForceCombinationByFactorVM}" mc:Ignorable="d" - Title="Force Combination By Factor" Height="340" Width="350" MinHeight="290" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"> + Title="Force Combination By Factor" Height="220" Width="350" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"> - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml.cs b/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml.cs index bb14bfa..7eaf223 100644 --- a/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml.cs +++ b/StructureHelper/Windows/Forces/ForceCombinationByFactorView.xaml.cs @@ -20,14 +20,15 @@ namespace StructureHelper.Windows.Forces /// public partial class ForceCombinationByFactorView : Window { - ForceCombinationByFactorVM viewModel; + readonly ForceCombinationByFactorVM viewModel; public ForceCombinationByFactorView(IForceFactoredList forceCombination) { - viewModel = new ForceCombinationByFactorVM(forceCombination); + viewModel = new ForceCombinationByFactorVM(forceCombination) + { + ParentWindow = this + }; DataContext = viewModel; - viewModel.ParentWindow = this; InitializeComponent(); - FactoredCombination.CombinationProperty = viewModel.CombinationProperty; } } } diff --git a/StructureHelper/Windows/Forces/ForceCombinationFromFileVM.cs b/StructureHelper/Windows/Forces/ForceCombinationFromFileVM.cs new file mode 100644 index 0000000..ef5fc62 --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceCombinationFromFileVM.cs @@ -0,0 +1,44 @@ +using StructureHelper.Windows.ViewModels; +using StructureHelper.Windows.ViewModels.Forces; +using StructureHelperCommon.Models.Forces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelper.Windows.Forces +{ + public class ForceCombinationFromFileVM : ForceActionVMBase + { + private readonly IForceCombinationFromFile model; + private ListOfFilesVM files; + private FactoredCombinationPropertyVM combinationProperty; + + public FactoredCombinationPropertyVM CombinationProperty + { + get => combinationProperty; set + { + combinationProperty = value; + OnPropertyChanged(nameof(CombinationProperty)); + } + } + + public ListOfFilesVM Files + { + get => files; set + { + files = value; + OnPropertyChanged(); + } + } + + public ForceCombinationFromFileVM(IForceCombinationFromFile model) : base(model) + { + this.model = model; + files = new(this.model.ForceFiles); + CombinationProperty = new FactoredCombinationPropertyVM(model.CombinationProperty); + } + + } +} diff --git a/StructureHelper/Windows/Forces/ForceCombinationFromFileView.xaml b/StructureHelper/Windows/Forces/ForceCombinationFromFileView.xaml new file mode 100644 index 0000000..8d83ad4 --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceCombinationFromFileView.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/Forces/ForceCombinationFromFileView.xaml.cs b/StructureHelper/Windows/Forces/ForceCombinationFromFileView.xaml.cs new file mode 100644 index 0000000..90ca617 --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceCombinationFromFileView.xaml.cs @@ -0,0 +1,39 @@ +using StructureHelperCommon.Models.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.Shapes; + +namespace StructureHelper.Windows.Forces +{ + /// + /// Interaction logic for ForceCombinationFromFile.xaml + /// + public partial class ForceCombinationFromFileView : Window + { + ForceCombinationFromFileVM viewModel; + + public ForceCombinationFromFileView(ForceCombinationFromFileVM viewModel) + { + this.viewModel = viewModel; + this.viewModel.ParentWindow = this; + InitializeComponent(); + this.DataContext = this.viewModel; + } + + public ForceCombinationFromFileView(IForceCombinationFromFile model) : this (new ForceCombinationFromFileVM(model)) + { + + } + + } +} diff --git a/StructureHelper/Windows/Forces/ForceFilePropertyVM.cs b/StructureHelper/Windows/Forces/ForceFilePropertyVM.cs new file mode 100644 index 0000000..1c96a7c --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceFilePropertyVM.cs @@ -0,0 +1,65 @@ +using StructureHelper.Windows.ViewModels; +using StructureHelperCommon.Models.Forces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelper.Windows.Forces +{ + public class ForceFilePropertyVM : OkCancelViewModelBase + { + private IForceFileProperty model; + + public ForceFilePropertyVM(IForceFileProperty model) + { + this.model = model; + } + + public int SkipRowBeforeHeaderCount + { + get => model.SkipRowBeforeHeaderCount; + set + { + model.SkipRowBeforeHeaderCount = value; + OnPropertyChanged(nameof(SkipRowBeforeHeaderCount)); + } + } + public int SkipRowHeaderCount + { + get => model.SkipRowHeaderCount; + set + { + model.SkipRowHeaderCount = value; + OnPropertyChanged(nameof(SkipRowHeaderCount)); + } + } + public double GlobalFactor + { + get => model.GlobalFactor; + set + { + model.GlobalFactor = value; + OnPropertyChanged(nameof(GlobalFactor)); + } + } + public string FilePath + { + get => model.FilePath; + set + { + model.FilePath = value; + OnPropertyChanged(nameof(FilePath)); + } + } + + public IForceFileProperty Model + { + get + { + return model; + } + } + } +} diff --git a/StructureHelper/Windows/Forces/ForceFilePropertyView.xaml b/StructureHelper/Windows/Forces/ForceFilePropertyView.xaml new file mode 100644 index 0000000..63e2d67 --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceFilePropertyView.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/Forces/ForceFilePropertyView.xaml.cs b/StructureHelper/Windows/Forces/ForceFilePropertyView.xaml.cs new file mode 100644 index 0000000..3d94d88 --- /dev/null +++ b/StructureHelper/Windows/Forces/ForceFilePropertyView.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace StructureHelper.Windows.Forces +{ + /// + /// Interaction logic for ForceFilePropertyView.xaml + /// + public partial class ForceFilePropertyView : Window + { + public ForceFilePropertyView() + { + InitializeComponent(); + } + } +} diff --git a/StructureHelper/Windows/Forces/ListOfFilesVM.cs b/StructureHelper/Windows/Forces/ListOfFilesVM.cs new file mode 100644 index 0000000..ed1e815 --- /dev/null +++ b/StructureHelper/Windows/Forces/ListOfFilesVM.cs @@ -0,0 +1,59 @@ +using StructureHelper.Infrastructure; +using StructureHelper.Windows.ViewModels; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Services.FileServices; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms.Design; +using System.Windows.Input; + +namespace StructureHelper.Windows.Forces +{ + public class ListOfFilesVM : SelectItemVM + { + private ICommand openFileCommand; + public IShiftTraceLogger? TraceLogger; + + public ICommand FileOpen => openFileCommand ?? ( + openFileCommand = new RelayCommand(param => + { + OpenFileMethod(param); + } + )); + + private void OpenFileMethod(object param) + { + var result = GetFilePath(); + if (result.IsValid == false) + { + return; + } + ForceFileProperty fileProperty = new() + { + FilePath = result.FilePath, + }; + Collection.Add(fileProperty); + Refresh(); + } + + public ListOfFilesVM(List collection) : base(collection) + { + } + + private OpenFileResult GetFilePath() + { + var inputData = new OpenFileInputData() + { + FilterString = "MS Excel file (*.xlsx)|*.xlsx|All Files (*.*)|*.*", + TraceLogger = TraceLogger + }; + var fileDialog = new FileOpener(inputData); + var fileDialogResult = fileDialog.OpenFile(); + return fileDialogResult; + } + } +} diff --git a/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs b/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs index f69ddb9..591d342 100644 --- a/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs +++ b/StructureHelper/Windows/MainWindow/AxisCanvases/CrossSectionVisualPropertyVM.cs @@ -43,6 +43,8 @@ namespace StructureHelper.Windows.MainWindow public double Height => AxisCanvasVM.Height; public double HalfOfWidth => AxisCanvasVM.Width / 2d; public double HalfOfHeight => AxisCanvasVM.Height / 2d; + public int MainTextFontSize => 14; + public double TextScaleValue => 1 / scaleValue; public string CanvasViewportSize { @@ -63,6 +65,7 @@ namespace StructureHelper.Windows.MainWindow OnPropertyChanged(value, ref scaleValue); OnPropertyChanged(nameof(AxisLineThickness)); OnPropertyChanged(nameof(GridLineThickness)); + OnPropertyChanged(nameof(TextScaleValue)); } } diff --git a/StructureHelper/Windows/MainWindow/CrossSectionView.xaml b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml index ddc19de..4ba28bf 100644 --- a/StructureHelper/Windows/MainWindow/CrossSectionView.xaml +++ b/StructureHelper/Windows/MainWindow/CrossSectionView.xaml @@ -210,8 +210,9 @@ - + + + + + + + + + + + + + + + + + + diff --git a/StructureHelper/Windows/UserControls/ListOfFileControl.xaml.cs b/StructureHelper/Windows/UserControls/ListOfFileControl.xaml.cs new file mode 100644 index 0000000..9b0a413 --- /dev/null +++ b/StructureHelper/Windows/UserControls/ListOfFileControl.xaml.cs @@ -0,0 +1,28 @@ +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.UserControls +{ + /// + /// Interaction logic for ListOfFileControl.xaml + /// + public partial class ListOfFileControl : UserControl + { + public ListOfFileControl() + { + InitializeComponent(); + } + } +} diff --git a/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs b/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs index 92c0b3d..b7d5311 100644 --- a/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs +++ b/StructureHelper/Windows/ViewModels/Forces/ActionsViewModel.cs @@ -29,6 +29,10 @@ namespace StructureHelper.Windows.ViewModels.Forces { NewItem = new ForceFactoredList() { Name = "New Factored Combination" }; } + else if (paramType == ActionType.ForceCombinationFromFile) + { + NewItem = new ForceCombinationFromFile { Name = "New Combination from file" }; + } else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}"); //GlobalRepository.Actions.Create(NewItem); base.AddMethod(parameter); @@ -60,20 +64,22 @@ namespace StructureHelper.Windows.ViewModels.Forces { //var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction; var copyObject = SelectedItem.Clone() as IAction; - System.Windows.Window wnd; - if (SelectedItem is IForceCombinationList) + System.Windows.Window modelEditorWindow; + if (SelectedItem is IForceCombinationList combinationList) { - var item = (IForceCombinationList)SelectedItem; - wnd = new ForceCombinationView(item); + modelEditorWindow = new ForceCombinationView(combinationList); } - else if (SelectedItem is IForceFactoredList) + else if (SelectedItem is IForceFactoredList factoredList) { - var item = (IForceFactoredList)SelectedItem; - wnd = new ForceCombinationByFactorView(item); + modelEditorWindow = new ForceCombinationByFactorView(factoredList); + } + else if (SelectedItem is IForceCombinationFromFile fileCombination) + { + modelEditorWindow = new ForceCombinationFromFileView(fileCombination); } else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"actual object type: {nameof(SelectedItem)}"); - wnd.ShowDialog(); - if (wnd.DialogResult == true) + modelEditorWindow.ShowDialog(); + if (modelEditorWindow.DialogResult == true) { //GlobalRepository.Actions.Update(SelectedItem); } @@ -100,11 +106,15 @@ namespace StructureHelper.Windows.ViewModels.Forces var forceCombinations = forceCalculator.InputData as IHasForceActions; result = DeleteActionFromHost(result, calc, forceCombinations); } - else if (calc is CrackCalculator calculator) + else if (calc is CrackCalculator crackCalculator) { - var forceCombinations = calculator.InputData as IHasForceActions; + var forceCombinations = crackCalculator.InputData as IHasForceActions; result = DeleteActionFromHost(result, calc, forceCombinations); } + else if (calc is ILimitCurvesCalculator) + { + //nothing to do + } else { throw new StructureHelperException(ErrorStrings.ExpectedWas(typeof(ICalculator), calc)); diff --git a/StructureHelperCommon/Models/Forces/ForceCombinationFromFile.cs b/StructureHelperCommon/Models/Forces/ForceCombinationFromFile.cs index 0cdd239..2b72465 100644 --- a/StructureHelperCommon/Models/Forces/ForceCombinationFromFile.cs +++ b/StructureHelperCommon/Models/Forces/ForceCombinationFromFile.cs @@ -1,4 +1,6 @@ using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models.Forces.Logics; using StructureHelperCommon.Models.Shapes; using System; using System.Collections.Generic; @@ -8,9 +10,13 @@ using System.Threading.Tasks; namespace StructureHelperCommon.Models.Forces { - internal class ForceCombinationFromFile : IForceCombinationFromFile + public class ForceCombinationFromFile : IForceCombinationFromFile { - private IForceFactoredCombination factoredCombination; + IUpdateStrategy updateStrategy; + IUpdateStrategy propertyUpdateStrategy; + IGetTupleFromFileLogic getTupleFromFileLogic; + + private IForceFactoredList factoredCombination; public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public List ForceFiles { get; set; } = new(); @@ -21,12 +27,25 @@ namespace StructureHelperCommon.Models.Forces public object Clone() { - throw new NotImplementedException(); + ForceCombinationFromFile newItem = new(); + updateStrategy ??= new ForceCombinationFromFileUpdateStrategy(); + updateStrategy.Update(newItem, this); + return newItem; } public List GetCombinations() { + getTupleFromFileLogic ??= new GetTupleFromFileLogic() { TraceLogger = new ShiftTraceLogger()}; factoredCombination = new ForceFactoredList(); + factoredCombination.ForceTuples.Clear(); + propertyUpdateStrategy ??= new FactoredCombinationPropertyUpdateStrategy(); + propertyUpdateStrategy.Update(factoredCombination.CombinationProperty, CombinationProperty); + foreach (var file in ForceFiles) + { + getTupleFromFileLogic.ForceFileProperty = file; + var tuples = getTupleFromFileLogic.GetTuples(); + factoredCombination.ForceTuples.AddRange(tuples); + } return factoredCombination.GetCombinations(); } } diff --git a/StructureHelperCommon/Models/Forces/ForceFileProperty.cs b/StructureHelperCommon/Models/Forces/ForceFileProperty.cs index c244c11..e83c6be 100644 --- a/StructureHelperCommon/Models/Forces/ForceFileProperty.cs +++ b/StructureHelperCommon/Models/Forces/ForceFileProperty.cs @@ -10,15 +10,13 @@ namespace StructureHelperCommon.Models.Forces public class ForceFileProperty : IForceFileProperty { public Guid Id { get; private set; } - public LimitStates LimitState { get; set; } = LimitStates.ULS; - public CalcTerms CalcTerm { get; set; } = CalcTerms.ShortTerm; public string FilePath { get; set; } = string.Empty; public int SkipRowBeforeHeaderCount { get; set; } = 2; public int SkipRowHeaderCount { get; set; } = 1; public double GlobalFactor { get; set; } = 1d; - public IColumnProperty Mx { get; set; } = new ColumnProperty("N"); - public IColumnProperty My { get; set; } = new ColumnProperty("My"); - public IColumnProperty Nz { get; set; } = new ColumnProperty("Mz"); + public IColumnProperty Nz { get; set; } = new ColumnProperty("N") { ColumnIndex = 6}; + public IColumnProperty Mx { get; set; } = new ColumnProperty("My") { ColumnIndex = 8}; + public IColumnProperty My { get; set; } = new ColumnProperty("Mz") { ColumnIndex = 10}; public ForceFileProperty(Guid id) { diff --git a/StructureHelperCommon/Models/Forces/IFileProperty.cs b/StructureHelperCommon/Models/Forces/IFileProperty.cs new file mode 100644 index 0000000..b0cf5c4 --- /dev/null +++ b/StructureHelperCommon/Models/Forces/IFileProperty.cs @@ -0,0 +1,9 @@ +using StructureHelperCommon.Infrastructures.Interfaces; + +namespace StructureHelperCommon.Models.Forces +{ + public interface IFileProperty : ISaveable + { + string FilePath { get; set; } + } +} \ No newline at end of file diff --git a/StructureHelperCommon/Models/Forces/IForceCombinationFromFile.cs b/StructureHelperCommon/Models/Forces/IForceCombinationFromFile.cs index 9ad6baf..38b1125 100644 --- a/StructureHelperCommon/Models/Forces/IForceCombinationFromFile.cs +++ b/StructureHelperCommon/Models/Forces/IForceCombinationFromFile.cs @@ -9,7 +9,7 @@ namespace StructureHelperCommon.Models.Forces /// /// Supports list of files which provides import of combination of forces /// - internal interface IForceCombinationFromFile : IForceFactoredCombination + public interface IForceCombinationFromFile : IForceFactoredCombination { /// /// List of file properties for import combination diff --git a/StructureHelperCommon/Models/Forces/IForceFileProperty.cs b/StructureHelperCommon/Models/Forces/IForceFileProperty.cs index fe42830..9e1cec5 100644 --- a/StructureHelperCommon/Models/Forces/IForceFileProperty.cs +++ b/StructureHelperCommon/Models/Forces/IForceFileProperty.cs @@ -11,11 +11,8 @@ namespace StructureHelperCommon.Models.Forces /// /// Settings for extracting force combination from MSExcel file /// - public interface IForceFileProperty : ISaveable + public interface IForceFileProperty : IFileProperty { - LimitStates LimitState { get; set; } - CalcTerms CalcTerm { get; set; } - string FilePath { get; set; } int SkipRowBeforeHeaderCount { get; set; } int SkipRowHeaderCount { get; set; } double GlobalFactor { get; set; } diff --git a/StructureHelperCommon/Models/Forces/Logics/ActionUpdateStrategy.cs b/StructureHelperCommon/Models/Forces/Logics/ActionUpdateStrategy.cs index 855bd9c..19f5821 100644 --- a/StructureHelperCommon/Models/Forces/Logics/ActionUpdateStrategy.cs +++ b/StructureHelperCommon/Models/Forces/Logics/ActionUpdateStrategy.cs @@ -11,9 +11,10 @@ namespace StructureHelperCommon.Models.Forces { public class ActionUpdateStrategy : IUpdateStrategy { - readonly IUpdateStrategy forceUpdateStrategy = new ForceActionUpdateStrategy(); + private IUpdateStrategy forceUpdateStrategy; public void Update(IAction targetObject, IAction sourceObject) { + forceUpdateStrategy ??= new ForceActionUpdateStrategy(); CheckObject.IsNull(targetObject); CheckObject.IsNull(sourceObject); if (ReferenceEquals(targetObject, sourceObject)) { return; } diff --git a/StructureHelperCommon/Models/Forces/Logics/CheckForceActionsLogic.cs b/StructureHelperCommon/Models/Forces/Logics/CheckForceActionsLogic.cs new file mode 100644 index 0000000..0972afb --- /dev/null +++ b/StructureHelperCommon/Models/Forces/Logics/CheckForceActionsLogic.cs @@ -0,0 +1,45 @@ +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Forces.Logics +{ + public class CheckForceActionsLogic : ICheckEntityLogic> + { + private bool result; + private string checkResult; + public string CheckResult => checkResult; + + public IShiftTraceLogger? TraceLogger { get; set; } + public IEnumerable Entity { get; set; } + + public bool Check() + { + result = true; + foreach (var item in Entity) + { + try + { + item.GetCombinations(); + } + catch (Exception ex) + { + result = false; + string errorString = $"Error of getting of combination of forces from action {item.Name}: {ex.Message}"; + TraceMessage(errorString); + } + } + return result; + } + + private void TraceMessage(string errorString) + { + checkResult += errorString + "\n"; + TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); + } + } +} diff --git a/StructureHelperCommon/Models/Forces/Logics/ForceActionBaseUpdateStrategy.cs b/StructureHelperCommon/Models/Forces/Logics/ForceActionBaseUpdateStrategy.cs index 0403a78..1c5cf3f 100644 --- a/StructureHelperCommon/Models/Forces/Logics/ForceActionBaseUpdateStrategy.cs +++ b/StructureHelperCommon/Models/Forces/Logics/ForceActionBaseUpdateStrategy.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace StructureHelperCommon.Models.Forces.Logics +namespace StructureHelperCommon.Models.Forces { public class ForceActionBaseUpdateStrategy : IUpdateStrategy { diff --git a/StructureHelperCommon/Models/Forces/Logics/ForceActionUpdateStrategy.cs b/StructureHelperCommon/Models/Forces/Logics/ForceActionUpdateStrategy.cs index c674e80..d2bf4ae 100644 --- a/StructureHelperCommon/Models/Forces/Logics/ForceActionUpdateStrategy.cs +++ b/StructureHelperCommon/Models/Forces/Logics/ForceActionUpdateStrategy.cs @@ -10,6 +10,9 @@ using System.Threading.Tasks; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models.Forces.Logics; +//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia +//All rights reserved. + namespace StructureHelperCommon.Models.Forces { public class ForceActionUpdateStrategy : IUpdateStrategy @@ -18,24 +21,28 @@ namespace StructureHelperCommon.Models.Forces private readonly IUpdateStrategy forcePairUpdateStrategy; private readonly IUpdateStrategy factorUpdateStrategy; private readonly IUpdateStrategy forceListUpdateStrategy; + private readonly IUpdateStrategy fileCombinationUpdateStrategy; public ForceActionUpdateStrategy( IUpdateStrategy forceActionUpdateStrategy, IUpdateStrategy forcePairUpdateStrategy, IUpdateStrategy factorUpdateStrategy, - IUpdateStrategy forceListUpdateStrategy) + IUpdateStrategy forceListUpdateStrategy, + IUpdateStrategy fileCombinationUpdateStrategy) { this.forceActionUpdateStrategy = forceActionUpdateStrategy; this.forcePairUpdateStrategy = forcePairUpdateStrategy; this.factorUpdateStrategy = factorUpdateStrategy; this.forceListUpdateStrategy = forceListUpdateStrategy; + this.fileCombinationUpdateStrategy = fileCombinationUpdateStrategy; } public ForceActionUpdateStrategy() : this( new ForceActionBaseUpdateStrategy(), new ForcePairUpdateStrategy(), new ForceFactoredListUpdateStrategy(), - new ForceCombinationListUpdateStrategy() + new ForceCombinationListUpdateStrategy(), + new ForceCombinationFromFileUpdateStrategy() ) { @@ -64,6 +71,10 @@ namespace StructureHelperCommon.Models.Forces { forceListUpdateStrategy.Update(forceCombinationList, (IForceCombinationList)sourceObject); } + else if (targetObject is IForceCombinationFromFile fileCombination) + { + fileCombinationUpdateStrategy.Update(fileCombination, (IForceCombinationFromFile)sourceObject); + } else { ErrorCommonProcessor.ObjectTypeIsUnknown(typeof(IForceAction), targetObject.GetType()); diff --git a/StructureHelperCommon/Models/Forces/Logics/ForceCombinationFromFileUpdateStrategy.cs b/StructureHelperCommon/Models/Forces/Logics/ForceCombinationFromFileUpdateStrategy.cs index d96b8f8..71542d8 100644 --- a/StructureHelperCommon/Models/Forces/Logics/ForceCombinationFromFileUpdateStrategy.cs +++ b/StructureHelperCommon/Models/Forces/Logics/ForceCombinationFromFileUpdateStrategy.cs @@ -13,17 +13,15 @@ namespace StructureHelperCommon.Models.Forces private IUpdateStrategy baseUpdateStrategy; private IUpdateStrategy fileUpdateStrategy; - public ForceCombinationFromFileUpdateStrategy(IUpdateStrategy baseUpdateStrategy, IUpdateStrategy fileUpdateStrategy) + public ForceCombinationFromFileUpdateStrategy(IUpdateStrategy baseUpdateStrategy, + IUpdateStrategy fileUpdateStrategy) { this.baseUpdateStrategy = baseUpdateStrategy; this.fileUpdateStrategy = fileUpdateStrategy; } - public ForceCombinationFromFileUpdateStrategy() : this ( - new ForceActionUpdateStrategy(), - new ForceFilePropertyUpdateStrategy()) - { - + public ForceCombinationFromFileUpdateStrategy() + { } void IUpdateStrategy.Update(IForceCombinationFromFile targetObject, IForceCombinationFromFile sourceObject) @@ -31,12 +29,21 @@ namespace StructureHelperCommon.Models.Forces CheckObject.IsNull(targetObject); CheckObject.IsNull(sourceObject); if (ReferenceEquals(targetObject, sourceObject)) { return; } + InitializeLogics(); baseUpdateStrategy.Update(targetObject, sourceObject); targetObject.ForceFiles.Clear(); foreach (var file in sourceObject.ForceFiles) { - throw new NotImplementedException(); + ForceFileProperty newProperty = new(); + fileUpdateStrategy.Update(newProperty, file); + targetObject.ForceFiles.Add(newProperty); } } + + private void InitializeLogics() + { + baseUpdateStrategy ??= new ForceActionBaseUpdateStrategy(); + fileUpdateStrategy ??= new ForceFilePropertyUpdateStrategy(); + } } } diff --git a/StructureHelperCommon/Models/Forces/Logics/ForceFilePropertyUpdateStrategy.cs b/StructureHelperCommon/Models/Forces/Logics/ForceFilePropertyUpdateStrategy.cs index e65867d..f8cf5ba 100644 --- a/StructureHelperCommon/Models/Forces/Logics/ForceFilePropertyUpdateStrategy.cs +++ b/StructureHelperCommon/Models/Forces/Logics/ForceFilePropertyUpdateStrategy.cs @@ -27,8 +27,6 @@ namespace StructureHelperCommon.Models.Forces CheckObject.IsNull(targetObject); CheckObject.IsNull(sourceObject); if (ReferenceEquals(targetObject, sourceObject)) { return; } - targetObject.LimitState = sourceObject.LimitState; - targetObject.CalcTerm = sourceObject.CalcTerm; targetObject.FilePath = sourceObject.FilePath; targetObject.GlobalFactor = sourceObject.GlobalFactor; targetObject.SkipRowBeforeHeaderCount = sourceObject.SkipRowBeforeHeaderCount; diff --git a/StructureHelperCommon/Models/Forces/Logics/GetTupleFromFileLogic.cs b/StructureHelperCommon/Models/Forces/Logics/GetTupleFromFileLogic.cs new file mode 100644 index 0000000..e5d70c5 --- /dev/null +++ b/StructureHelperCommon/Models/Forces/Logics/GetTupleFromFileLogic.cs @@ -0,0 +1,79 @@ +using ExcelDataReader; +using StructureHelperCommon.Infrastructures.Exceptions; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperCommon.Models.Forces.Logics +{ + public class GetTupleFromFileLogic : IGetTupleFromFileLogic + { + public IForceFileProperty ForceFileProperty { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } + + public List GetTuples() + { + // Ensure ExcelDataReader's encoding provider is registered + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + + var result = ReadDataFromFile(); + return result; + } + + private List ReadDataFromFile() + { + List result = new(); + // Open the Excel file stream + using (var stream = File.Open(ForceFileProperty.FilePath, FileMode.Open, FileAccess.Read)) + { + // Create an Excel reader + using (var reader = ExcelReaderFactory.CreateReader(stream)) + { + // Skip the first two header rows if necessary (adjust based on structure) + int skipRows = ForceFileProperty.SkipRowBeforeHeaderCount + ForceFileProperty.SkipRowHeaderCount; + for (int i = 0; i < skipRows; i++) + { + reader.Read(); // Skip row + } + + // Loop through the rows + while (reader.Read()) + { + var nValue = reader.GetValue(ForceFileProperty.Nz.ColumnIndex)?.ToString(); + var mxValue = reader.GetValue(ForceFileProperty.Mx.ColumnIndex)?.ToString(); + var myValue = reader.GetValue(ForceFileProperty.My.ColumnIndex)?.ToString(); + TraceLogger?.AddMessage($"Values: Nz = {nValue}(N), Mx = {mxValue}(N*m), My = {myValue}(N*m) were gained", TraceLogStatuses.Debug); + if (nValue is not null && mxValue is not null && myValue is not null) + { + ForceTuple newTuple = GetForceTuple(nValue, mxValue, myValue); + result.Add(newTuple); + } + } + } + } + return result; + } + + private ForceTuple GetForceTuple(string? nValue, string? mxValue, string? myValue) + { + try + { + double nDouble = Convert.ToDouble(nValue); + double mxDouble = Convert.ToDouble(mxValue); + double myDouble = Convert.ToDouble(myValue); + TraceLogger?.AddMessage($"Values: Nz = {nDouble}(N), Mx = {mxDouble}(N*m), My = {myDouble}(N*m) were converted successfully", TraceLogStatuses.Debug); + ForceTuple newTuple = new() { Nz = nDouble, Mx = mxDouble, My = myDouble }; + return newTuple; + } + catch (Exception ex) + { + string errorString = ErrorStrings.DataIsInCorrect + $": incorrect data in file {ForceFileProperty.FilePath}, " + ex.Message; + TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); + throw new StructureHelperException(errorString); + } + } + } +} diff --git a/StructureHelperCommon/Models/Forces/Logics/IGetTupleFromFileLogic.cs b/StructureHelperCommon/Models/Forces/Logics/IGetTupleFromFileLogic.cs new file mode 100644 index 0000000..df923a8 --- /dev/null +++ b/StructureHelperCommon/Models/Forces/Logics/IGetTupleFromFileLogic.cs @@ -0,0 +1,12 @@ +using StructureHelperCommon.Infrastructures.Interfaces; +using System.Collections.Generic; + +namespace StructureHelperCommon.Models.Forces.Logics +{ + public interface IGetTupleFromFileLogic : ILogic + { + IForceFileProperty ForceFileProperty { get; set; } + + List GetTuples(); + } +} \ No newline at end of file diff --git a/StructureHelperCommon/StructureHelperCommon.csproj b/StructureHelperCommon/StructureHelperCommon.csproj index 64f85c9..5300505 100644 --- a/StructureHelperCommon/StructureHelperCommon.csproj +++ b/StructureHelperCommon/StructureHelperCommon.csproj @@ -10,6 +10,7 @@ + diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/CheckForceCalculatorInputData.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/CheckForceCalculatorInputData.cs index 80be38f..5e64b55 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/CheckForceCalculatorInputData.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/CheckForceCalculatorInputData.cs @@ -4,6 +4,7 @@ using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; +using StructureHelperCommon.Models.Forces.Logics; using StructureHelperLogics.NdmCalculations.Cracking; using System; using System.Collections.Generic; @@ -66,9 +67,24 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces result = false; } CheckAccuracy(); + CheckActions(); return result; } + private void CheckActions() + { + var checkLogic = new CheckForceActionsLogic() + { + Entity = InputData.ForceActions, + TraceLogger = TraceLogger + }; + if (checkLogic.Check() == false) + { + result = false; + } + TraceMessage(checkLogic.CheckResult); + } + private void CheckAccuracy() { checkAccuracyLogic.Entity = InputData.Accuracy; diff --git a/StructureHelperLogics/NdmCalculations/Cracking/CheckLogics/CheckCrackCalculatorInputDataLogic.cs b/StructureHelperLogics/NdmCalculations/Cracking/CheckLogics/CheckCrackCalculatorInputDataLogic.cs index bb3c702..78fb59c 100644 --- a/StructureHelperLogics/NdmCalculations/Cracking/CheckLogics/CheckCrackCalculatorInputDataLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Cracking/CheckLogics/CheckCrackCalculatorInputDataLogic.cs @@ -2,6 +2,7 @@ using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Calculators; +using StructureHelperCommon.Models.Forces.Logics; using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Materials; using StructureHelperLogics.NdmCalculations.Primitives; @@ -74,7 +75,23 @@ namespace StructureHelperLogics.NdmCalculations.Cracking string message = "Calculator does not contain any actions\n"; CheckResult += message; TraceLogger?.AddMessage(message, TraceLogStatuses.Error); + return; }; + var checkLogic = new CheckForceActionsLogic() + { + Entity = InputData.ForceActions, + TraceLogger = TraceLogger + }; + if (checkLogic.Check() == false) + { + result = false; + } + TraceMessage(checkLogic.CheckResult); + } + private void TraceMessage(string errorString) + { + CheckResult += errorString + "\n"; + TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); }