Library material was added
This commit is contained in:
@@ -8,8 +8,11 @@ using StructureHelper.Services;
|
||||
using StructureHelper.Services.Primitives;
|
||||
using StructureHelper.UnitSystem;
|
||||
using StructureHelper.UnitSystem.Systems;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperLogics.Infrastructures.CommonEnums;
|
||||
using StructureHelperLogics.Models.Calculations.CalculationProperties;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using StructureHelperLogics.Models.Materials.Factories;
|
||||
using StructureHelperLogics.NdmCalculations.Triangulations;
|
||||
using StructureHelperLogics.Services;
|
||||
using System.Collections;
|
||||
@@ -21,11 +24,17 @@ namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
public class MainModel
|
||||
{
|
||||
//const CodeTypes code = CodeTypes.EuroCode_2_1990;
|
||||
const CodeTypes code = CodeTypes.SP63_13330_2018;
|
||||
|
||||
private IPrimitiveRepository primitiveRepository;
|
||||
public IHeadMaterialRepository HeadMaterialRepository { get; }
|
||||
public List<IHeadMaterial> HeadMaterials { get; }
|
||||
private CalculationService calculationService;
|
||||
private UnitSystemService unitSystemService;
|
||||
|
||||
public IPrimitiveRepository PrimitiveRepository => primitiveRepository;
|
||||
|
||||
public ICalculationProperty CalculationProperty { get; private set; }
|
||||
|
||||
public MainModel(IPrimitiveRepository primitiveRepository, CalculationService calculationService, UnitSystemService unitSystemService)
|
||||
@@ -36,6 +45,8 @@ namespace StructureHelper.Windows.MainWindow
|
||||
|
||||
CalculationProperty = new CalculationProperty();
|
||||
HeadMaterials = new List<IHeadMaterial>();
|
||||
HeadMaterialRepository = new HeadMaterialRepository(this);
|
||||
HeadMaterialRepository.LibMaterials = LibMaterialFactory.GetLibMaterials(code);
|
||||
}
|
||||
|
||||
public IStrainMatrix Calculate(double mx, double my, double nz)
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="20"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="25"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@@ -49,6 +48,9 @@
|
||||
</MenuItem>
|
||||
<Button Content="Materials" Command="{Binding EditHeadMaterialsCommand}"/>
|
||||
<Button Content="Calculation properties" Command="{Binding Path=EditCalculationPropertyCommand}"/>
|
||||
<MenuItem Header="Templates">
|
||||
<Button Content="Concrete beam 400x600" Command="{Binding AddTestCase}"/>
|
||||
</MenuItem>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Analisys">
|
||||
<Button Content="Solve problem" Command="{Binding Path=Calculate}"/>
|
||||
@@ -96,7 +98,7 @@
|
||||
</Rectangle>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
|
||||
</Grid>
|
||||
|
||||
|
||||
<!--<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="25"/>
|
||||
@@ -177,13 +179,10 @@
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Grid>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<!--<Button VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="Справочник" Command="{Binding OpenMaterialCatalog}"/>
|
||||
<Button VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="Units" Command="{Binding OpenUnitsSystemSettings}"/>
|
||||
<Label VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="{Binding UnitsSystemName}"/>-->
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0.333,0.333,39.667" Grid.RowSpan="2" Width="519">
|
||||
<Button VerticalAlignment="Center" Margin="5" Content="Add test primitives" Command="{Binding AddTestCase}"/>
|
||||
</StackPanel>
|
||||
<StatusBar Grid.Row="2">
|
||||
<StatusBarItem>
|
||||
<TextBlock Text="Structure Helper"/>
|
||||
</StatusBarItem>
|
||||
</StatusBar>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -24,16 +24,20 @@ using StructureHelper.Windows.CalculationWindows.CalculationResultWindow;
|
||||
using StructureHelper.Windows.ViewModels.Calculations.CalculationResult;
|
||||
using StructureHelper.Services.Primitives;
|
||||
using StructureHelper.Windows.PrimitiveProperiesWindow;
|
||||
using StructureHelper.Infrastructure.Exceptions;
|
||||
using StructureHelper.Infrastructure.Strings;
|
||||
using StructureHelper.Windows.MainWindow.Materials;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperLogics.Models.Materials.Factories;
|
||||
|
||||
namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
private List<IHeadMaterial> headMaterials;
|
||||
private readonly double scaleRate = 1.1;
|
||||
|
||||
|
||||
private IPrimitiveRepository PrimitiveRepository { get; }
|
||||
public PrimitiveBase SelectedPrimitive { get; set; }
|
||||
|
||||
@@ -87,7 +91,19 @@ namespace StructureHelper.Windows.MainWindow
|
||||
get => canvasHeight;
|
||||
set => OnPropertyChanged(value, ref canvasHeight);
|
||||
}
|
||||
public List<IHeadMaterial> HeadMaterials { get => Model.HeadMaterials; }
|
||||
|
||||
public ObservableCollection<IHeadMaterial> HeadMaterials
|
||||
{
|
||||
get
|
||||
{
|
||||
var collection = new ObservableCollection<IHeadMaterial>();
|
||||
foreach (var obj in headMaterials)
|
||||
{
|
||||
collection.Add(obj);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
||||
public double XX2
|
||||
{
|
||||
@@ -139,6 +155,7 @@ namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
PrimitiveRepository = primitiveRepository;
|
||||
Model = model;
|
||||
headMaterials = Model.HeadMaterialRepository.HeadMaterials;
|
||||
this.unitSystemService = unitSystemService;
|
||||
CanvasWidth = 1500;
|
||||
CanvasHeight = 1000;
|
||||
@@ -148,7 +165,6 @@ namespace StructureHelper.Windows.MainWindow
|
||||
YY2 = CanvasHeight;
|
||||
calculationProperty = new CalculationProperty();
|
||||
|
||||
|
||||
LeftButtonUp = new RelayCommand(o =>
|
||||
{
|
||||
if (o is Rectangle rect) rect.BorderCaptured = false;
|
||||
@@ -297,8 +313,10 @@ namespace StructureHelper.Windows.MainWindow
|
||||
|
||||
private void EditHeadMaterials()
|
||||
{
|
||||
var wnd = new HeadMaterialsView(HeadMaterials);
|
||||
var wnd = new HeadMaterialsView(Model.HeadMaterialRepository);
|
||||
wnd.ShowDialog();
|
||||
headMaterials = Model.HeadMaterialRepository.HeadMaterials;
|
||||
OnPropertyChanged(nameof(headMaterials));
|
||||
}
|
||||
|
||||
private void DeleteSelectedPrimitive()
|
||||
@@ -319,19 +337,46 @@ namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
if (!(SelectedPrimitive is null))
|
||||
{
|
||||
var wnd = new PrimitiveProperties(SelectedPrimitive);
|
||||
var wnd = new PrimitiveProperties(SelectedPrimitive, Model.HeadMaterialRepository);
|
||||
wnd.ShowDialog();
|
||||
OnPropertyChanged(nameof(headMaterials));
|
||||
}
|
||||
else { MessageBox.Show("Selection is changed", "Please, select primitive", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); }
|
||||
}
|
||||
|
||||
private void CalculateResult()
|
||||
{
|
||||
IEnumerable<INdm> ndms = Model.GetNdms();
|
||||
CalculationService calculationService = new CalculationService();
|
||||
var loaderResults = calculationService.GetCalculationResults(calculationProperty, ndms);
|
||||
var wnd = new CalculationResultView(new CalculationResultViewModel(loaderResults, ndms));
|
||||
wnd.ShowDialog();
|
||||
bool check = CheckAnalisysOptions();
|
||||
if (check == false)
|
||||
{
|
||||
MessageBox.Show(ErrorStrings.DataIsInCorrect, "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
IEnumerable<INdm> ndms = Model.GetNdms();
|
||||
CalculationService calculationService = new CalculationService();
|
||||
var loaderResults = calculationService.GetCalculationResults(calculationProperty, ndms);
|
||||
var wnd = new CalculationResultView(new CalculationResultViewModel(loaderResults, ndms));
|
||||
wnd.ShowDialog();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"{ErrorStrings.UnknownError}: {ex}", "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckAnalisysOptions()
|
||||
{
|
||||
foreach (var item in PrimitiveRepository.Primitives)
|
||||
{
|
||||
if (item.HeadMaterial == null)
|
||||
{
|
||||
MessageBox.Show($"Primitive {item.Name} does not has material", "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerable<PrimitiveBase> GetTestCasePrimitives()
|
||||
@@ -345,10 +390,13 @@ namespace StructureHelper.Windows.MainWindow
|
||||
var rectMaterial = new ConcreteDefinition("C40", 0, 40, 0, 1.3, 1.5);
|
||||
var pointMaterial = new RebarDefinition("S400", 2, 400, 400, 1.15, 1.15);
|
||||
|
||||
IHeadMaterial concrete = new HeadMaterial() { Name = "Concrete C40", Material = rectMaterial };
|
||||
HeadMaterials.Add(concrete);
|
||||
IHeadMaterial reinforcement = new HeadMaterial() { Name = "Reinforcement S400", Material = pointMaterial };
|
||||
HeadMaterials.Add(reinforcement);
|
||||
IHeadMaterial concrete = new HeadMaterial() { Name = "Concrete 40"};
|
||||
concrete.HelperMaterial = Model.HeadMaterialRepository.LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Concrete & x.Name.Contains("40"))).First();
|
||||
IHeadMaterial reinforcement = new HeadMaterial() { Name = "Reinforcement 400"};
|
||||
reinforcement.HelperMaterial = Model.HeadMaterialRepository.LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Reinforcement & x.Name.Contains("400"))).First();
|
||||
headMaterials.Add(concrete);
|
||||
headMaterials.Add(reinforcement);
|
||||
OnPropertyChanged(nameof(headMaterials));
|
||||
|
||||
yield return new Rectangle(width, height, 0, 0, this) { Material = rectMaterial, MaterialName = rectMaterial.MaterialClass, HeadMaterial = concrete };
|
||||
yield return new Point(area1, -width / 2 + gap, -height / 2 + gap, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass, HeadMaterial = reinforcement };
|
||||
|
||||
@@ -13,29 +13,46 @@
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="120"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ListBox ItemsSource="{Binding HeadMaterials}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Column="0" Margin="3">
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush Color="{Binding Color}"/>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition Height="30"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Column="0" Margin="3">
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush Color="{Binding Color}"/>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<TextBox Grid.Row="1" Text="{Binding SelectedMaterial.Name}"/>
|
||||
<ComboBox Grid.Row="2" ItemsSource="{Binding LibMaterials}" SelectedItem="{Binding SelectedLibMaterial}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Column="1">
|
||||
<Button Content="New Concrete" Command="{Binding AddHeadMaterial}"/>
|
||||
<Button Content="New Reinforcement" Command="{Binding AddHeadMaterial}"/>
|
||||
<Button Content="Edit" Command="{Binding EditHeadMaterial}"/>
|
||||
<Button Content="Edit" Command="{Binding DeleteHeadMaterial}"/>
|
||||
<Button Content="New Material" Command="{Binding AddNewMaterialCommand}"/>
|
||||
<Button Content="Edit color" Command="{Binding EditColorCommand}"/>
|
||||
<Button Content="Copy" Command="{Binding CopyHeadMaterialCommand}"/>
|
||||
<Button Content="Delete" Command="{Binding DeleteMaterialCommand}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelper.Windows.ViewModels.Materials;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -23,9 +24,9 @@ namespace StructureHelper.Windows.MainWindow.Materials
|
||||
{
|
||||
private HeadMaterialsViewModel viewmodel;
|
||||
|
||||
public HeadMaterialsView(IEnumerable<IHeadMaterial> materials)
|
||||
public HeadMaterialsView(IHeadMaterialRepository headMaterialRepository)
|
||||
{
|
||||
viewmodel = new HeadMaterialsViewModel(materials);
|
||||
viewmodel = new HeadMaterialsViewModel(headMaterialRepository);
|
||||
this.DataContext = viewmodel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -87,9 +87,26 @@
|
||||
<TextBlock Grid.Row="3" Text="Center Y"/>
|
||||
<TextBlock Grid.Row="4" Text="Material color"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding Name}"/>
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<ComboBox HorizontalAlignment="Left"/>
|
||||
<Button Width="50" Content="...">
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<ComboBox Width="120" ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding PrimitiveMaterial}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Column="0" Margin="3">
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush Color="{Binding Color}"/>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<Button Width="50" Content="..." Command="{Binding EditMaterialCommand}">
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding CenterX, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
|
||||
@@ -102,11 +119,10 @@
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<Button Width="50" Content="..." Command="{Binding EditColorCommand}"/>
|
||||
<Button Width="50" Content="..." Click="Button_Click"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Expander>
|
||||
<!--<Expander Header="Prestrain" IsExpanded="True">
|
||||
<Expander Header="Prestrain" IsExpanded="True">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="22"/>
|
||||
@@ -120,11 +136,11 @@
|
||||
<TextBlock Grid.Row="0" Text="k_x"/>
|
||||
<TextBlock Grid.Row="1" Text="k_y"/>
|
||||
<TextBlock Grid.Row="2" Text="epsilon_z"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding Prestrain_kx, ValidatesOnDataErrors=True}"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Margin="1" Text="{Binding Prestrain_kx, ValidatesOnDataErrors=True}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding Prestrain_kx, ValidatesOnDataErrors=True}"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding PrestrainKx, ValidatesOnDataErrors=True}"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Margin="1" Text="{Binding PrestrainKy, ValidatesOnDataErrors=True}"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding PrestrainEpsZ, ValidatesOnDataErrors=True}"/>
|
||||
</Grid>
|
||||
</Expander>-->
|
||||
</Expander>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Window>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Infrastructure.UI.DataContexts;
|
||||
using StructureHelper.Windows.ViewModels.PrimitiveProperties;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -27,10 +28,10 @@ namespace StructureHelper.Windows.PrimitiveProperiesWindow
|
||||
{
|
||||
PrimitiveBase primitive;
|
||||
private PrimitivePropertiesViewModel viewModel;
|
||||
public PrimitiveProperties(PrimitiveBase primitive)
|
||||
public PrimitiveProperties(PrimitiveBase primitive, IHeadMaterialRepository materialRepository)
|
||||
{
|
||||
this.primitive = primitive;
|
||||
viewModel = new PrimitivePropertiesViewModel(this.primitive);
|
||||
viewModel = new PrimitivePropertiesViewModel(this.primitive, materialRepository);
|
||||
this.DataContext = viewModel;
|
||||
InitializeComponent();
|
||||
if (primitive is Rectangle) { AddPrimitiveProperties(PrimitiveType.Rectangle); }
|
||||
@@ -60,10 +61,5 @@ namespace StructureHelper.Windows.PrimitiveProperiesWindow
|
||||
StpProperties.Children.Add(contentControl);
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
viewModel.EditColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user