All Test Was Repaired
This commit is contained in:
@@ -3,8 +3,11 @@ using StructureHelper.Models.Materials;
|
||||
using StructureHelper.Services.Primitives;
|
||||
using StructureHelper.Windows.MainWindow;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Models.Materials.Libraries;
|
||||
using StructureHelperCommon.Services.ColorServices;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,13 +23,14 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
{
|
||||
public class HeadMaterialsViewModel : ViewModelBase
|
||||
{
|
||||
IHeadMaterialRepository materialRepository;
|
||||
IEnumerable<IHeadMaterial> headMaterials;
|
||||
IEnumerable<ILibMaterial> libMaterials;
|
||||
IHasHeadMaterials parent;
|
||||
List<IHeadMaterial> headMaterials;
|
||||
IHeadMaterial selectedMaterial;
|
||||
ILibMaterial selectedLibMaterial;
|
||||
ILibMaterialEntity selectedLibMaterial;
|
||||
|
||||
public ICommand AddNewConcreteMaterialCommand { get;}
|
||||
public ICommand AddNewReinforcementMaterialCommand { get; }
|
||||
|
||||
public ICommand AddNewMaterialCommand { get; set; }
|
||||
public ICommand AddElasticMaterialCommand
|
||||
{
|
||||
get
|
||||
@@ -40,10 +44,10 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
|
||||
private void AddElasticMaterial()
|
||||
{
|
||||
IHeadMaterial material = new HeadMaterial() { Name = "New elastic material" };
|
||||
material.HelperMaterial = new ElasticMaterial() { Modulus = 2e11d, CompressiveStrength = 4e8d, TensileStrength = 4e8d };
|
||||
var material = HeadMaterialFactory.GetHeadMaterial(HeadmaterialType.Elastic200, ProgramSetting.CodeType);
|
||||
material.Name = "New Elastic Material";
|
||||
HeadMaterials.Add(material);
|
||||
materialRepository.HeadMaterials.Add(material);
|
||||
headMaterials.Add(material);
|
||||
SelectedMaterial = material;
|
||||
}
|
||||
|
||||
@@ -63,7 +67,8 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
OnPropertyChanged(value, ref selectedMaterial);
|
||||
if (!(selectedMaterial is null))
|
||||
{
|
||||
selectedLibMaterial = selectedMaterial.HelperMaterial as ILibMaterial;
|
||||
var libMaterial = selectedMaterial.HelperMaterial as ILibMaterial;
|
||||
selectedLibMaterial = libMaterial.MaterialEntity;
|
||||
OnPropertyChanged(nameof(selectedLibMaterial));
|
||||
}
|
||||
}
|
||||
@@ -79,7 +84,7 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
}
|
||||
}
|
||||
|
||||
public ILibMaterial SelectedLibMaterial
|
||||
public ILibMaterialEntity SelectedLibMaterial
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -88,33 +93,41 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
}
|
||||
set
|
||||
{
|
||||
selectedMaterial.HelperMaterial = value;
|
||||
var libMaterial = selectedMaterial.HelperMaterial as ILibMaterial;
|
||||
libMaterial.MaterialEntity = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ILibMaterial> LibMaterials
|
||||
public IEnumerable<ILibMaterialEntity> LibConcreteMaterials
|
||||
{
|
||||
get
|
||||
{
|
||||
//if (SelectedMaterial is null)
|
||||
//{
|
||||
// return null;
|
||||
//}
|
||||
return libMaterials;//.Where(x => x.MaterialType == (SelectedMaterial.HelperMaterial as ILibMaterial).MaterialType);
|
||||
return LibMaterialPepository.GetConcreteRepository(ProgramSetting.CodeType);
|
||||
}
|
||||
}
|
||||
|
||||
public HeadMaterialsViewModel(IHeadMaterialRepository headMaterialRepository)
|
||||
public IEnumerable<ILibMaterialEntity> LibReinforcementMaterials
|
||||
{
|
||||
materialRepository = headMaterialRepository;
|
||||
headMaterials = materialRepository.HeadMaterials;
|
||||
get
|
||||
{
|
||||
return LibMaterialPepository.GetReinforcementRepository(ProgramSetting.CodeType);
|
||||
}
|
||||
}
|
||||
|
||||
public HeadMaterialsViewModel(IHasHeadMaterials parent) : this(parent.HeadMaterials)
|
||||
{
|
||||
}
|
||||
|
||||
public HeadMaterialsViewModel(List<IHeadMaterial> _headMaterials)
|
||||
{
|
||||
headMaterials = _headMaterials;
|
||||
HeadMaterials = new ObservableCollection<IHeadMaterial>();
|
||||
foreach (var material in headMaterials)
|
||||
{
|
||||
HeadMaterials.Add(material);
|
||||
}
|
||||
libMaterials = materialRepository.LibMaterials;
|
||||
AddNewMaterialCommand = new RelayCommand(o => AddNewMaterial(MaterialTypes.Reinforcement));
|
||||
AddNewConcreteMaterialCommand = new RelayCommand(o => AddConcreteMaterial());
|
||||
AddNewReinforcementMaterialCommand = new RelayCommand(o => AddReinforcementMaterial());
|
||||
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));
|
||||
@@ -124,24 +137,30 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
{
|
||||
var material = SelectedMaterial.Clone() as IHeadMaterial;
|
||||
HeadMaterials.Add(material);
|
||||
materialRepository.HeadMaterials.Add(material);
|
||||
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)
|
||||
if (parent != null)
|
||||
{
|
||||
MessageBox.Show("Some primitives reference to this material", "Material can not be deleted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
if (parent is IHasPrimitives)
|
||||
{
|
||||
var primitives = (parent as IHasPrimitives).Primitives;
|
||||
var primitivesWithMaterial = 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);
|
||||
HeadMaterials.Remove(SelectedMaterial);
|
||||
}
|
||||
}
|
||||
@@ -155,13 +174,21 @@ namespace StructureHelper.Windows.ViewModels.Materials
|
||||
OnPropertyChanged(nameof(selectedMaterial));
|
||||
}
|
||||
|
||||
private void AddNewMaterial(MaterialTypes materialType)
|
||||
private void AddConcreteMaterial()
|
||||
{
|
||||
IHeadMaterial material = new HeadMaterial() { Name = "New material" };
|
||||
material.HelperMaterial = LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Concrete & x.Name.Contains("40"))).First();
|
||||
var material = HeadMaterialFactory.GetHeadMaterial(HeadmaterialType.Concrete40, ProgramSetting.CodeType);
|
||||
material.Name = "New Concrete";
|
||||
HeadMaterials.Add(material);
|
||||
//headMaterials.Append(material);
|
||||
materialRepository.HeadMaterials.Add(material);
|
||||
headMaterials.Add(material);
|
||||
SelectedMaterial = material;
|
||||
}
|
||||
|
||||
private void AddReinforcementMaterial()
|
||||
{
|
||||
var material = HeadMaterialFactory.GetHeadMaterial(HeadmaterialType.Reinforecement400, ProgramSetting.CodeType);
|
||||
material.Name = "New Reinforcement";
|
||||
HeadMaterials.Add(material);
|
||||
headMaterials.Add(material);
|
||||
SelectedMaterial = material;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user