SourceToTargetViewModel was added

This commit is contained in:
Evgeny Redikultsev
2022-12-15 21:46:15 +05:00
parent f562cf2bce
commit d240968f29
21 changed files with 632 additions and 200 deletions

View File

@@ -1,5 +1,6 @@
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperCommon.Models.Forces;
@@ -22,6 +23,31 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
IEnumerable<IForceCombinationList> allowedForceCombinations;
ForceCalculator forcesCalculator;
public string Name
{
get { return forcesCalculator.Name; }
set { forcesCalculator.Name = value; }
}
public double IterationAccuracy
{
get { return forcesCalculator.IterationAccuracy; }
set { forcesCalculator.IterationAccuracy = value;}
}
public int MaxIterationCount
{
get { return forcesCalculator.MaxIterationCount; }
set { forcesCalculator.MaxIterationCount = value; }
}
public bool ULS { get; set; }
public bool SLS { get; set; }
public bool ShortTerm { get; set; }
public bool LongTerm { get; set; }
public ISourceToTargetViewModel<IForceCombinationList> CombinationViewModel { get; }
public PrimitiveBase SelectedAllowedPrimitive { get; set; }
public PrimitiveBase SelectedPrimitive { get; set; }
@@ -69,7 +95,6 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
forcesCalculator.NdmPrimitives.Clear();
forcesCalculator.NdmPrimitives.AddRange(allowedPrimitives);
}
public ICommand ClearAllPrimitivesCommand
{
get
@@ -84,7 +109,6 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
}, o => forcesCalculator.NdmPrimitives.Count > 0 ));
}
}
public ICommand AddSelectedPrimitiveCommand
{
get
@@ -99,7 +123,6 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
}, o => SelectedAllowedPrimitive != null));
}
}
public RelayCommand RemoveSelectedPrimitiveCommand
{
get
@@ -120,6 +143,12 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
allowedPrimitives = _allowedPrimitives;
allowedForceCombinations = _allowedForceCombinations;
forcesCalculator = _forcesCalculator;
CombinationViewModel = new SourceToTargetViewModel<IForceCombinationList>();
CombinationViewModel.SetTargetItems(forcesCalculator.ForceCombinationLists);
CombinationViewModel.SetSourceItems(allowedForceCombinations);
InputRefresh();
}
private ObservableCollection<PrimitiveBase> ConvertNdmPrimitivesToPrimitiveBase(IEnumerable<INdmPrimitive> primitives)
@@ -141,5 +170,29 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
}
return viewItems;
}
public void InputRefresh()
{
ULS = forcesCalculator.LimitStatesList.Contains(LimitStates.ULS);
SLS = forcesCalculator.LimitStatesList.Contains(LimitStates.SLS);
ShortTerm = forcesCalculator.CalcTermsList.Contains(CalcTerms.ShortTerm);
LongTerm = forcesCalculator.CalcTermsList.Contains(CalcTerms.LongTerm);
}
public void Refresh()
{
var combinations = CombinationViewModel.GetTargetItems();
forcesCalculator.ForceCombinationLists.Clear();
foreach (var item in combinations)
{
forcesCalculator.ForceCombinationLists.Add(item);
}
forcesCalculator.LimitStatesList.Clear();
if (ULS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.ULS); }
if (SLS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.SLS); }
forcesCalculator.CalcTermsList.Clear();
if (ShortTerm == true) { forcesCalculator.CalcTermsList.Add(CalcTerms.ShortTerm); }
if (LongTerm == true) { forcesCalculator.CalcTermsList.Add(CalcTerms.LongTerm); }
}
}
}

View File

@@ -0,0 +1,13 @@
using StructureHelperCommon.Models.Forces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
{
public interface ICombinationSourceToTargetViewModel : ISourceToTargetViewModel<IForceCombinationList>
{
}
}

View File

@@ -0,0 +1,20 @@
using StructureHelper.Infrastructure;
using StructureHelperLogics.NdmCalculations.Analyses;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels
{
public interface ICRUDViewModel<TItem>
{
TItem SelectedItem { get; set; }
ObservableCollection<TItem> Items { get; }
RelayCommand Add { get; }
RelayCommand Delete { get; }
RelayCommand Edit { get; }
}
}

View File

@@ -0,0 +1,25 @@
using StructureHelper.Infrastructure;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels
{
public interface ISourceToTargetViewModel<TItem>
{
TItem SelectedSourceItem { get; set; }
TItem SelectedTargetItem { get; set; }
ObservableCollection<TItem> SourceItems { get; }
ObservableCollection<TItem> TargetItems { get; }
RelayCommand AddAll { get; }
RelayCommand ClearAll { get; }
RelayCommand AddSelected { get; }
RelayCommand RemoveSelected { get; }
void SetSourceItems(IEnumerable<TItem> allowedItems);
void SetTargetItems(IEnumerable<TItem> targetItems);
IEnumerable<TItem> GetTargetItems();
}
}

View File

@@ -0,0 +1,120 @@
using StructureHelper.Infrastructure;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews;
using StructureHelper.Windows.ViewModels.Calculations.Calculators;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public class CalculatorsViewModelLogic : ViewModelBase, ICalculatorsViewModelLogic
{
private readonly ICrossSectionRepository repository;
public INdmCalculator SelectedItem { get; set; }
public ObservableCollection<INdmCalculator> Items
{
get
{
var collection = new ObservableCollection<INdmCalculator>();
foreach (var item in repository.CalculatorsList)
{
collection.Add(item);
}
return collection;
}
}
private RelayCommand addCalculatorCommand;
public RelayCommand Add
{
get
{
return addCalculatorCommand ??
(
addCalculatorCommand = new RelayCommand(o =>
{
AddCalculator();
OnPropertyChanged(nameof(Items));
}));
}
}
private void AddCalculator()
{
var item = new ForceCalculator() { Name = "New force calculator" };
repository.CalculatorsList.Add(item);
}
private RelayCommand editCalculatorCommand;
public RelayCommand Edit
{
get
{
return editCalculatorCommand ??
(
editCalculatorCommand = new RelayCommand(o =>
{
EditCalculator();
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void EditCalculator()
{
if (SelectedItem is ForceCalculator)
{
var calculator = SelectedItem as ForceCalculator;
var vm = new ForceCalculatorViewModel(repository.Primitives, repository.ForceCombinationLists, calculator);
var wnd = new ForceCalculatorView(vm);
wnd.ShowDialog();
}
}
private RelayCommand deleteCalculatorCommand;
private RelayCommand runCommand;
public RelayCommand Delete
{
get
{
return deleteCalculatorCommand ??
(
deleteCalculatorCommand = new RelayCommand(o =>
{
DeleteCalculator();
}, o => SelectedItem != null));
}
}
public RelayCommand Run
{
get
{
return runCommand ??
(
runCommand = new RelayCommand(o =>
{
(SelectedItem as INdmCalculator).Run();
}, o => SelectedItem != null));
}
}
private void DeleteCalculator()
{
var dialogResult = MessageBox.Show("Delete calculator?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
repository.CalculatorsList.Remove(SelectedItem as INdmCalculator);
OnPropertyChanged(nameof(Items));
}
}
public CalculatorsViewModelLogic(ICrossSectionRepository repository)
{
this.repository = repository;
}
}
}

View File

@@ -0,0 +1,102 @@
using StructureHelper.Infrastructure;
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public class ForceCombinationViewModelLogic : ViewModelBase, IForceCombinationViewModelLogic
{
private readonly ICrossSectionRepository repository;
public IForceCombinationList SelectedItem { get; set; }
public ObservableCollection<IForceCombinationList> Items
{
get
{
var collection = new ObservableCollection<IForceCombinationList>();
foreach (var item in repository.ForceCombinationLists)
{
collection.Add(item);
}
return collection;
}
}
private RelayCommand addForceCombinationCommand;
public RelayCommand Add
{
get
{
return addForceCombinationCommand ??
(
addForceCombinationCommand = new RelayCommand(o =>
{
AddCombination();
OnPropertyChanged(nameof(Items));
}));
}
}
private void AddCombination()
{
var item = new ForceCombinationList() { Name = "New Force Combination" };
repository.ForceCombinationLists.Add(item);
}
private RelayCommand deleteForceCombinationCommand;
public RelayCommand Delete
{
get
{
return deleteForceCombinationCommand ??
(
deleteForceCombinationCommand = new RelayCommand(o =>
{
DeleteForceCombination();
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void DeleteForceCombination()
{
var dialogResult = MessageBox.Show("Delete action?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
repository.ForceCombinationLists.Remove(SelectedItem);
}
}
private RelayCommand editForceCombinationCommand;
public RelayCommand Edit
{
get
{
return editForceCombinationCommand ??
(
editForceCombinationCommand = new RelayCommand(o =>
{
EditForceCombination();
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void EditForceCombination()
{
var wnd = new ForceCombinationView(SelectedItem);
wnd.ShowDialog();
}
public ForceCombinationViewModelLogic(ICrossSectionRepository repository)
{
this.repository = repository;
}
}
}

View File

@@ -0,0 +1,13 @@
using StructureHelper.Infrastructure;
using StructureHelperLogics.NdmCalculations.Analyses;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public interface ICalculatorsViewModelLogic : ICRUDViewModel<INdmCalculator>
{
RelayCommand Run { get; }
}
}

View File

@@ -0,0 +1,14 @@
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public interface IForceCombinationViewModelLogic : ICRUDViewModel<IForceCombinationList>
{
}
}

View File

@@ -0,0 +1,117 @@
using StructureHelper.Infrastructure;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels
{
public class SourceToTargetViewModel<TItem> : ViewModelBase, ISourceToTargetViewModel<TItem>
{
private IEnumerable<TItem> allowedItems;
private IEnumerable<TItem> targetItems;
private RelayCommand addAll;
private RelayCommand addSelected;
private RelayCommand removeSelected;
private RelayCommand clearAll;
public TItem SelectedSourceItem { get; set; }
public TItem SelectedTargetItem { get; set; }
public ObservableCollection<TItem> SourceItems { get; }
public ObservableCollection<TItem> TargetItems { get; }
public RelayCommand AddAll
{
get
{
return addAll ??
(
addAll = new RelayCommand(o =>
{
foreach (var item in SourceItems)
{
TargetItems.Add(item);
}
SourceItems.Clear();
}, o=> SourceItems.Count() > 0));
}
}
public RelayCommand ClearAll
{
get
{
return clearAll ??
(
clearAll = new RelayCommand(o =>
{
foreach (var item in TargetItems)
{
SourceItems.Add(item);
}
TargetItems.Clear();
}, o => TargetItems.Count() > 0));
}
}
public RelayCommand AddSelected
{
get
{
return addSelected ??
(
addSelected = new RelayCommand(o =>
{
TargetItems.Add(SelectedSourceItem);
SourceItems.Remove(SelectedSourceItem);
}, o => SelectedSourceItem != null));
}
}
public RelayCommand RemoveSelected
{
get
{
return removeSelected ??
(
removeSelected = new RelayCommand(o =>
{
SourceItems.Add(SelectedTargetItem);
TargetItems.Remove(SelectedTargetItem);
}, o => SelectedTargetItem != null));
}
}
public SourceToTargetViewModel()
{
SourceItems = new ObservableCollection<TItem>();
TargetItems = new ObservableCollection<TItem>();
}
public void SetSourceItems(IEnumerable<TItem> allowedItems)
{
this.allowedItems = allowedItems;
var rejectedItems = allowedItems.Where(x => TargetItems.Contains(x));
var filteredItems = allowedItems.Except(rejectedItems);
SourceItems.Clear();
foreach (var item in filteredItems)
{
SourceItems.Add(item);
}
}
public void SetTargetItems(IEnumerable<TItem> targetItems)
{
this.targetItems = targetItems;
TargetItems.Clear();
foreach (var item in this.targetItems)
{
TargetItems.Add(item);
}
}
public IEnumerable<TItem> GetTargetItems()
{
return TargetItems;
}
}
}