Library material was added

This commit is contained in:
Evgeny Redikultsev
2022-11-06 18:55:01 +05:00
parent 1cf54603bc
commit 5d19958fd7
52 changed files with 1018 additions and 171 deletions

View File

@@ -1,5 +1,10 @@
using StructureHelper.Infrastructure;
using StructureHelper.Models.Materials;
using StructureHelper.Services.Primitives;
using StructureHelper.Windows.MainWindow;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Services.ColorServices;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -7,30 +12,136 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
namespace StructureHelper.Windows.ViewModels.Materials
{
public class HeadMaterialsViewModel : ViewModelBase
{
IHeadMaterialRepository materialRepository;
IEnumerable<IHeadMaterial> headMaterials;
IEnumerable<ILibMaterial> libMaterials;
IHeadMaterial selectedMaterial;
ILibMaterial selectedLibMaterial;
public ICommand AddHeadMaterial;
public ICommand CopyHeadMaterial;
public ICommand DeleteHeadMaterial;
public ICommand AddNewMaterialCommand { get; set; }
public ICommand CopyHeadMaterialCommand { get; set; }
public ICommand EditColorCommand { get; set; }
public ICommand DeleteMaterialCommand { get; set; }
public ICommand EditHeadMaterial;
public ObservableCollection<IHeadMaterial> HeadMaterials { get; private set; }
public IHeadMaterial SelectedMaterial { get; set; }
public HeadMaterialsViewModel(IEnumerable<IHeadMaterial> materials)
public IHeadMaterial SelectedMaterial
{
headMaterials = materials;
get => selectedMaterial;
set
{
OnPropertyChanged(value, ref selectedMaterial);
if (!(selectedMaterial is null))
{
selectedLibMaterial = selectedMaterial.HelperMaterial as ILibMaterial;
OnPropertyChanged(nameof(selectedLibMaterial));
}
}
}
public string SelectedName
{
get => selectedMaterial.Name;
set
{
selectedMaterial.Name = value;
OnPropertyChanged(nameof(selectedMaterial));
}
}
public ILibMaterial SelectedLibMaterial
{
get
{
if (selectedLibMaterial is null) { return null; }
else { return selectedLibMaterial; }
}
set
{
selectedMaterial.HelperMaterial = value;
}
}
public IEnumerable<ILibMaterial> LibMaterials
{
get
{
//if (SelectedMaterial is null)
//{
// return null;
//}
return libMaterials;//.Where(x => x.MaterialType == (SelectedMaterial.HelperMaterial as ILibMaterial).MaterialType);
}
}
public HeadMaterialsViewModel(IHeadMaterialRepository headMaterialRepository)
{
materialRepository = headMaterialRepository;
headMaterials = materialRepository.HeadMaterials;
HeadMaterials = new ObservableCollection<IHeadMaterial>();
foreach (var material in headMaterials)
{
HeadMaterials.Add(material);
}
libMaterials = materialRepository.LibMaterials;
AddNewMaterialCommand = new RelayCommand(o => AddNewMaterial(MaterialTypes.Reinforcement));
CopyHeadMaterialCommand = new RelayCommand(o => CopyMaterial(), o => !(SelectedMaterial is null));
EditColorCommand = new RelayCommand(o => EditColor(), o=> ! (SelectedMaterial is null));
DeleteMaterialCommand = new RelayCommand(o => DeleteMaterial(), o => !(SelectedMaterial is null));
}
private void CopyMaterial()
{
var material = SelectedMaterial.Clone() as IHeadMaterial;
HeadMaterials.Add(material);
materialRepository.HeadMaterials.Add(material);
SelectedMaterial = material;
}
private void DeleteMaterial()
{
var mainModel = materialRepository.Parent as MainModel;
var primitivesWithMaterial = mainModel.PrimitiveRepository.Primitives.Where(x => x.HeadMaterial == SelectedMaterial);
int primitivesCount = primitivesWithMaterial.Count();
if (primitivesCount > 0)
{
MessageBox.Show("Some primitives reference to this material", "Material can not be deleted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var dialogResult = MessageBox.Show("Delete material?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
materialRepository.HeadMaterials.Remove(SelectedMaterial);
HeadMaterials.Remove(SelectedMaterial);
}
}
private void EditColor()
{
Color color = SelectedMaterial.Color;
ColorProcessor.EditColor(ref color);
SelectedMaterial.Color = color;
OnPropertyChanged(nameof(selectedMaterial.Color));
OnPropertyChanged(nameof(selectedMaterial));
}
private void AddNewMaterial(MaterialTypes materialType)
{
IHeadMaterial material = new HeadMaterial() { Name = "New material" };
material.HelperMaterial = LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Concrete & x.Name.Contains("40"))).First();
HeadMaterials.Add(material);
//headMaterials.Append(material);
materialRepository.HeadMaterials.Add(material);
SelectedMaterial = material;
}
}
}

View File

@@ -1,9 +1,15 @@
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Models.Materials;
using StructureHelper.Windows.ColorPickerWindow;
using StructureHelper.Windows.MainWindow.Materials;
using StructureHelperCommon.Models.NdmPrimitives;
using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.ColorServices;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
@@ -19,8 +25,13 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
public class PrimitivePropertiesViewModel : ViewModelBase, IDataErrorInfo
{
private PrimitiveBase primitive;
private IHeadMaterialRepository headMaterialRepository;
private List<IHeadMaterial> headMaterials;
public ICommand EditColorCommand;
public ICommand EditColorCommand { get; private set; }
public ICommand EditMaterialCommand { get; private set; }
public ObservableCollection<IHeadMaterial> HeadMaterials { get; private set; }
public string Name
{
@@ -40,6 +51,18 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
OnPropertyChanged(nameof(MaterialName));
}
}
public IHeadMaterial PrimitiveMaterial
{ get => primitive.HeadMaterial;
set
{
primitive.HeadMaterial = value;
OnPropertyChanged(nameof(PrimitiveMaterial));
if (primitive.SetMaterialColor == true)
{
OnPropertyChanged(nameof(Color));
}
}
}
public double CenterX
{
@@ -65,6 +88,22 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
}
}
public double PrestrainKx
{
get => primitive.PrestrainKx;
set => primitive.PrestrainKx = value;
}
public double PrestrainKy
{
get => primitive.PrestrainKy;
set => primitive.PrestrainKy = value;
}
public double PrestrainEpsZ
{
get => primitive.PrestrainEpsZ;
set => primitive.PrestrainEpsZ = value;
}
public int MinElementDivision
{
get => primitive.MinElementDivision;
@@ -99,6 +138,7 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
var shape = primitive as Rectangle;
shape.PrimitiveWidth = value;
}
CenterX = CenterX;
}
}
@@ -120,8 +160,9 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
var shape = primitive as Rectangle;
shape.PrimitiveHeight = value;
}
CenterY = CenterY; ;
}
}
}
public double Area
{
@@ -160,6 +201,7 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
set
{
primitive.SetMaterialColor = value;
OnPropertyChanged(nameof(Color));
OnPropertyChanged(nameof(SetMaterialColor));
}
}
@@ -185,17 +227,32 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
public string Error => throw new NotImplementedException();
public PrimitivePropertiesViewModel(PrimitiveBase primitive)
public PrimitivePropertiesViewModel(PrimitiveBase primitive, IHeadMaterialRepository materialRepository)
{
this.primitive = primitive;
headMaterialRepository = materialRepository;
headMaterials = materialRepository.HeadMaterials;
HeadMaterials = new ObservableCollection<IHeadMaterial>();
foreach (var material in headMaterials)
{
HeadMaterials.Add(material);
}
EditColorCommand = new RelayCommand(o => EditColor(), o => !SetMaterialColor);
EditMaterialCommand = new RelayCommand(o => EditMaterial());
}
private void EditMaterial()
{
var wnd = new HeadMaterialsView(headMaterialRepository);
wnd.ShowDialog();
}
public void EditColor()
{
var wnd = new ColorPickerView(primitive);
wnd.ShowDialog();
OnPropertyChanged(nameof(Color));
Color color = Color;
ColorProcessor.EditColor(ref color);
Color = color;
}
}
}