Primitive View Logic for Main View modael was added
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using StructureHelper.Infrastructure;
|
||||
using StructureHelper.Infrastructure.UI.DataContexts;
|
||||
using StructureHelper.Services.Primitives;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
@@ -13,6 +14,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
@@ -48,7 +50,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
|
||||
public bool LongTerm { get; set; }
|
||||
|
||||
public ISourceToTargetViewModel<IForceCombinationList> CombinationViewModel { get; }
|
||||
//public ISourceToTargetViewModel<PrimitiveBase> PrimitivesViewModel { get; }
|
||||
public ISourceToTargetViewModel<PrimitiveBase> PrimitivesViewModel { get; }
|
||||
|
||||
public PrimitiveBase SelectedAllowedPrimitive { get; set; }
|
||||
public PrimitiveBase SelectedPrimitive { get; set; }
|
||||
@@ -60,7 +62,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
|
||||
var sourceItems = forcesCalculator.Primitives;
|
||||
var rejectedItems = allowedPrimitives.Where(x => sourceItems.Contains(x));
|
||||
var filteredItems = allowedPrimitives.Except(rejectedItems);
|
||||
return ConvertNdmPrimitivesToPrimitiveBase(filteredItems);
|
||||
return PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(filteredItems);
|
||||
}
|
||||
}
|
||||
public ObservableCollection<PrimitiveBase> Primitives
|
||||
@@ -68,7 +70,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
|
||||
get
|
||||
{
|
||||
var sourceItems = forcesCalculator.Primitives;
|
||||
return ConvertNdmPrimitivesToPrimitiveBase(sourceItems);
|
||||
return PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(sourceItems);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,37 +151,19 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
|
||||
CombinationViewModel = new SourceToTargetViewModel<IForceCombinationList>();
|
||||
CombinationViewModel.SetTargetItems(forcesCalculator.ForceCombinationLists);
|
||||
CombinationViewModel.SetSourceItems(allowedForceCombinations);
|
||||
CombinationViewModel.ItemDataDemplate = Application.Current.Resources["SimpleItemTemplate"] as DataTemplate;
|
||||
|
||||
//PrimitivesViewModel = new SourceToTargetViewModel<PrimitiveBase>();
|
||||
//var targetItems = forcesCalculator.NdmPrimitives;
|
||||
//var viewPrimitives = ConvertNdmPrimitivesToPrimitiveBase(targetItems);
|
||||
//PrimitivesViewModel.SetTargetItems(viewPrimitives);
|
||||
//var sourceViewPrimitives = ConvertNdmPrimitivesToPrimitiveBase(allowedPrimitives) ;
|
||||
//PrimitivesViewModel.SetSourceItems(sourceViewPrimitives);
|
||||
PrimitivesViewModel = new SourceToTargetViewModel<PrimitiveBase>();
|
||||
var targetItems = forcesCalculator.Primitives;
|
||||
var sourceViewPrimitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(allowedPrimitives);
|
||||
var viewPrimitives = sourceViewPrimitives.Where(x => targetItems.Contains(x.GetNdmPrimitive()));
|
||||
PrimitivesViewModel.SetTargetItems(viewPrimitives);
|
||||
PrimitivesViewModel.SetSourceItems(sourceViewPrimitives);
|
||||
PrimitivesViewModel.ItemDataDemplate = Application.Current.Resources["ColoredItemTemplate"] as DataTemplate;
|
||||
|
||||
InputRefresh();
|
||||
}
|
||||
|
||||
private ObservableCollection<PrimitiveBase> ConvertNdmPrimitivesToPrimitiveBase(IEnumerable<INdmPrimitive> primitives)
|
||||
{
|
||||
ObservableCollection<PrimitiveBase> viewItems = new ObservableCollection<PrimitiveBase>();
|
||||
foreach (var item in primitives)
|
||||
{
|
||||
if (item is IPointPrimitive)
|
||||
{
|
||||
var point = item as IPointPrimitive;
|
||||
viewItems.Add(new PointViewPrimitive(point));
|
||||
}
|
||||
else if (item is IRectanglePrimitive)
|
||||
{
|
||||
var rect = item as IRectanglePrimitive;
|
||||
viewItems.Add(new RectangleViewPrimitive(rect));
|
||||
}
|
||||
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown);
|
||||
}
|
||||
return viewItems;
|
||||
}
|
||||
|
||||
public void InputRefresh()
|
||||
{
|
||||
ULS = forcesCalculator.LimitStatesList.Contains(LimitStates.ULS);
|
||||
@@ -196,11 +180,11 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
|
||||
{
|
||||
forcesCalculator.ForceCombinationLists.Add(item);
|
||||
}
|
||||
//forcesCalculator.NdmPrimitives.Clear();
|
||||
//foreach (var item in PrimitivesViewModel.GetTargetItems())
|
||||
//{
|
||||
// forcesCalculator.NdmPrimitives.Add(item.GetNdmPrimitive());
|
||||
//}
|
||||
forcesCalculator.Primitives.Clear();
|
||||
foreach (var item in PrimitivesViewModel.GetTargetItems())
|
||||
{
|
||||
forcesCalculator.Primitives.Add(item.GetNdmPrimitive());
|
||||
}
|
||||
forcesCalculator.LimitStatesList.Clear();
|
||||
if (ULS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.ULS); }
|
||||
if (SLS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.SLS); }
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace StructureHelper.Windows.ViewModels
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace StructureHelper.Windows.ViewModels
|
||||
TItem SelectedTargetItem { get; set; }
|
||||
ObservableCollection<TItem> SourceItems { get; }
|
||||
ObservableCollection<TItem> TargetItems { get; }
|
||||
DataTemplate ItemDataDemplate { get; set; }
|
||||
RelayCommand AddAll { get; }
|
||||
RelayCommand ClearAll { get; }
|
||||
RelayCommand AddSelected { get; }
|
||||
|
||||
@@ -21,14 +21,14 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
public INdmCalculator SelectedItem { get; set; }
|
||||
public ObservableCollection<INdmCalculator> Items { get; private set; }
|
||||
|
||||
private RelayCommand addCalculatorCommand;
|
||||
private RelayCommand addCommand;
|
||||
public RelayCommand Add
|
||||
{
|
||||
get
|
||||
{
|
||||
return addCalculatorCommand ??
|
||||
return addCommand ??
|
||||
(
|
||||
addCalculatorCommand = new RelayCommand(o =>
|
||||
addCommand = new RelayCommand(o =>
|
||||
{
|
||||
AddCalculator();
|
||||
OnPropertyChanged(nameof(Items));
|
||||
@@ -41,14 +41,14 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
Items.Add(item);
|
||||
repository.CalculatorsList.Add(item);
|
||||
}
|
||||
private RelayCommand editCalculatorCommand;
|
||||
private RelayCommand editCommand;
|
||||
public RelayCommand Edit
|
||||
{
|
||||
get
|
||||
{
|
||||
return editCalculatorCommand ??
|
||||
return editCommand ??
|
||||
(
|
||||
editCalculatorCommand = new RelayCommand(o =>
|
||||
editCommand = new RelayCommand(o =>
|
||||
{
|
||||
var tmpSelected = SelectedItem;
|
||||
EditCalculator();
|
||||
@@ -70,23 +70,22 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
wnd.ShowDialog();
|
||||
}
|
||||
}
|
||||
private RelayCommand deleteCalculatorCommand;
|
||||
private RelayCommand deleteCommand;
|
||||
private RelayCommand runCommand;
|
||||
private RelayCommand copyCalculatorCommand;
|
||||
private RelayCommand copyCommand;
|
||||
|
||||
public RelayCommand Delete
|
||||
{
|
||||
get
|
||||
{
|
||||
return deleteCalculatorCommand ??
|
||||
return deleteCommand ??
|
||||
(
|
||||
deleteCalculatorCommand = new RelayCommand(o =>
|
||||
deleteCommand = new RelayCommand(o =>
|
||||
{
|
||||
DeleteCalculator();
|
||||
}, o => SelectedItem != null));
|
||||
}
|
||||
}
|
||||
|
||||
public RelayCommand Run
|
||||
{
|
||||
get
|
||||
@@ -111,14 +110,13 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
}, o => SelectedItem != null));
|
||||
}
|
||||
}
|
||||
|
||||
public RelayCommand Copy
|
||||
{
|
||||
get
|
||||
{
|
||||
return copyCalculatorCommand ??
|
||||
return copyCommand ??
|
||||
(
|
||||
copyCalculatorCommand = new RelayCommand(o =>
|
||||
copyCommand = new RelayCommand(o =>
|
||||
{
|
||||
var item = SelectedItem.Clone() as INdmCalculator;
|
||||
repository.CalculatorsList.Add(item);
|
||||
@@ -127,7 +125,6 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
}, o => SelectedItem != null));
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteCalculator()
|
||||
{
|
||||
var dialogResult = MessageBox.Show("Delete calculator?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using StructureHelper.Infrastructure;
|
||||
using StructureHelper.Infrastructure.UI.DataContexts;
|
||||
|
||||
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
{
|
||||
public interface IPrimitiveViewModelLogic : ICRUDViewModel<PrimitiveBase>
|
||||
{
|
||||
RelayCommand SetToFront { get; }
|
||||
RelayCommand SetToBack { get; }
|
||||
int PrimitivesCount { get; }
|
||||
void Refresh();
|
||||
}
|
||||
}
|
||||
227
Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs
Normal file
227
Windows/ViewModels/NdmCrossSections/PrimitiveViewModelLogic.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
using FieldVisualizer.ViewModels;
|
||||
using StructureHelper.Infrastructure.UI.DataContexts;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StructureHelper.Services.Primitives;
|
||||
using StructureHelper.Infrastructure;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperLogics.Models.Primitives;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using ViewModelBase = StructureHelper.Infrastructure.ViewModelBase;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Documents;
|
||||
using StructureHelper.Windows.PrimitiveProperiesWindow;
|
||||
|
||||
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
{
|
||||
public class PrimitiveViewModelLogic : ViewModelBase, IPrimitiveViewModelLogic
|
||||
{
|
||||
private readonly ICrossSectionRepository repository;
|
||||
private RelayCommand addCommand;
|
||||
private RelayCommand deleteCommand;
|
||||
private RelayCommand editCommand;
|
||||
private RelayCommand copyCommand;
|
||||
private RelayCommand setToFront;
|
||||
private RelayCommand setToBack;
|
||||
|
||||
public double CanvasWidth { get; set; }
|
||||
public double CanvasHeight { get; set; }
|
||||
|
||||
public PrimitiveBase SelectedItem { get; set; }
|
||||
|
||||
public ObservableCollection<PrimitiveBase> Items { get; private set; }
|
||||
|
||||
public RelayCommand Add
|
||||
{
|
||||
get
|
||||
{
|
||||
return addCommand ??
|
||||
(
|
||||
addCommand = new RelayCommand(o =>
|
||||
{
|
||||
if (!(o is PrimitiveType primitiveType)) return;
|
||||
AddPrimitive(primitiveType);
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private void AddPrimitive(PrimitiveType primitiveType)
|
||||
{
|
||||
PrimitiveBase viewPrimitive;
|
||||
INdmPrimitive ndmPrimitive;
|
||||
if (primitiveType == PrimitiveType.Rectangle)
|
||||
{
|
||||
var primitive = new RectanglePrimitive
|
||||
{
|
||||
Width = 0.4d,
|
||||
Height = 0.6d
|
||||
};
|
||||
ndmPrimitive = primitive;
|
||||
viewPrimitive = new RectangleViewPrimitive(primitive);
|
||||
|
||||
}
|
||||
else if (primitiveType == PrimitiveType.Point)
|
||||
{
|
||||
var primitive = new PointPrimitive
|
||||
{
|
||||
Area = 0.0005d
|
||||
};
|
||||
ndmPrimitive = primitive;
|
||||
viewPrimitive = new PointViewPrimitive(primitive);
|
||||
}
|
||||
|
||||
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); }
|
||||
viewPrimitive.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
|
||||
repository.Primitives.Add(ndmPrimitive);
|
||||
Items.Add(viewPrimitive);
|
||||
OnPropertyChanged(nameof(Items));
|
||||
OnPropertyChanged(nameof(PrimitivesCount));
|
||||
}
|
||||
|
||||
public RelayCommand Delete
|
||||
{
|
||||
get
|
||||
{
|
||||
return deleteCommand ??
|
||||
(
|
||||
deleteCommand = new RelayCommand(o=>
|
||||
DeleteSelectedPrimitive(),
|
||||
o => SelectedItem != null
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteSelectedPrimitive()
|
||||
{
|
||||
var dialogResult = MessageBox.Show("Delete primitive?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
var ndmPrimitive = SelectedItem.GetNdmPrimitive();
|
||||
repository.Primitives.Remove(ndmPrimitive);
|
||||
Items.Remove(SelectedItem);
|
||||
}
|
||||
OnPropertyChanged(nameof(Items));
|
||||
OnPropertyChanged(nameof(PrimitivesCount));
|
||||
}
|
||||
|
||||
public RelayCommand Edit
|
||||
{
|
||||
get
|
||||
{
|
||||
return editCommand ??
|
||||
(
|
||||
editCommand = new RelayCommand(
|
||||
o => EditSelectedItem(),
|
||||
o => SelectedItem != null
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private void EditSelectedItem()
|
||||
{
|
||||
var wnd = new PrimitivePropertiesView(SelectedItem, repository);
|
||||
wnd.ShowDialog();
|
||||
}
|
||||
|
||||
public RelayCommand Copy
|
||||
{
|
||||
get
|
||||
{
|
||||
return copyCommand ??
|
||||
(
|
||||
copyCommand = new RelayCommand(
|
||||
o => CopySelectedItem(),
|
||||
o => SelectedItem != null
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private void CopySelectedItem()
|
||||
{
|
||||
var oldPrimitive = SelectedItem.GetNdmPrimitive();
|
||||
var newPrimitive = oldPrimitive.Clone() as INdmPrimitive;
|
||||
repository.Primitives.Add(newPrimitive);
|
||||
PrimitiveBase primitiveBase;
|
||||
if (newPrimitive is IRectanglePrimitive) { primitiveBase = new RectangleViewPrimitive(newPrimitive as IRectanglePrimitive); }
|
||||
else if (newPrimitive is IPointPrimitive) { primitiveBase = new PointViewPrimitive(newPrimitive as IPointPrimitive); }
|
||||
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown);
|
||||
primitiveBase.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
|
||||
Items.Add(primitiveBase);
|
||||
OnPropertyChanged(nameof(Items));
|
||||
OnPropertyChanged(nameof(PrimitivesCount));
|
||||
}
|
||||
|
||||
public int PrimitivesCount => repository.Primitives.Count();
|
||||
|
||||
public RelayCommand SetToFront
|
||||
{
|
||||
get
|
||||
{
|
||||
return setToFront ??
|
||||
(setToFront = new RelayCommand(o=>
|
||||
{
|
||||
int maxZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Max();
|
||||
SelectedItem.ZIndex = maxZIndex + 1;
|
||||
},o => CheckMaxIndex()
|
||||
));
|
||||
}
|
||||
}
|
||||
private bool CheckMaxIndex()
|
||||
{
|
||||
if (SelectedItem is null) return false;
|
||||
int maxZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Max();
|
||||
if (SelectedItem.ZIndex <= maxZIndex) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
private bool CheckMinIndex()
|
||||
{
|
||||
if (SelectedItem is null) return false;
|
||||
int minZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Min();
|
||||
if (SelectedItem.ZIndex >= minZIndex) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public RelayCommand SetToBack
|
||||
{
|
||||
get
|
||||
{
|
||||
return setToBack ??
|
||||
(setToBack = new RelayCommand(o =>
|
||||
{
|
||||
int minZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Min();
|
||||
SelectedItem.ZIndex = minZIndex - 1;
|
||||
}, o => CheckMinIndex()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public void AddItems(IEnumerable<PrimitiveBase> items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
OnPropertyChanged(nameof(PrimitivesCount));
|
||||
}
|
||||
|
||||
public PrimitiveViewModelLogic(ICrossSectionRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
Items = new ObservableCollection<PrimitiveBase>();
|
||||
AddItems(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(this.repository.Primitives));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,6 +206,28 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsVisible
|
||||
{
|
||||
get => primitive.IsVisible;
|
||||
set
|
||||
{
|
||||
primitive.IsVisible = value;
|
||||
OnPropertyChanged(nameof(IsVisible));
|
||||
}
|
||||
}
|
||||
|
||||
public double Opacity
|
||||
{
|
||||
get => primitive.Opacity * 100d;
|
||||
set
|
||||
{
|
||||
if (value < 0d ) { value = 0d; }
|
||||
if (value > 100d) { value = 100d; }
|
||||
primitive.Opacity = value / 100d;
|
||||
OnPropertyChanged(nameof(Opacity));
|
||||
}
|
||||
}
|
||||
|
||||
public string this[string columnName]
|
||||
{
|
||||
get
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace StructureHelper.Windows.ViewModels
|
||||
{
|
||||
@@ -23,6 +24,7 @@ namespace StructureHelper.Windows.ViewModels
|
||||
public TItem SelectedTargetItem { get; set; }
|
||||
public ObservableCollection<TItem> SourceItems { get; }
|
||||
public ObservableCollection<TItem> TargetItems { get; }
|
||||
public DataTemplate ItemDataDemplate { get; set; }
|
||||
public RelayCommand AddAll
|
||||
{
|
||||
get
|
||||
@@ -82,6 +84,8 @@ namespace StructureHelper.Windows.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public SourceToTargetViewModel()
|
||||
{
|
||||
SourceItems = new ObservableCollection<TItem>();
|
||||
|
||||
Reference in New Issue
Block a user