Edition of primitives is changed

This commit is contained in:
Evgeny Redikultsev
2022-10-30 18:58:51 +05:00
parent 87a42efc24
commit e1af4d5e07
48 changed files with 1198 additions and 146 deletions

View File

@@ -4,6 +4,7 @@ using LoaderCalculator.Data.Ndms;
using LoaderCalculator.Data.ResultData;
using LoaderCalculator.Data.SourceData;
using StructureHelper.Services;
using StructureHelper.Services.Primitives;
using StructureHelper.UnitSystem;
using StructureHelper.UnitSystem.Systems;
using StructureHelperLogics.Infrastructures.CommonEnums;
@@ -37,17 +38,13 @@ namespace StructureHelper.Windows.MainWindow
public IStrainMatrix Calculate(double mx, double my, double nz)
{
var unitSystem = unitSystemService.GetCurrentSystem();
return calculationService.GetPrimitiveStrainMatrix(primitiveRepository.GetRectangles()
.Select(x => x.GetNdmPrimitive(unitSystem))
.Concat(primitiveRepository.GetPoints().Select(x => x.GetNdmPrimitive(unitSystem))).ToArray(), mx, my, nz);
return calculationService.GetPrimitiveStrainMatrix(primitiveRepository.Primitives.Select(x => x.GetNdmPrimitive(unitSystem)).ToArray(), mx, my, nz);
}
public IEnumerable<INdm> GetNdms()
{
var unitSystem = unitSystemService.GetCurrentSystem();
var ndmPrimitives = primitiveRepository.GetRectangles()
.Select(x => x.GetNdmPrimitive(unitSystem))
.Concat(primitiveRepository.GetPoints().Select(x => x.GetNdmPrimitive(unitSystem))).ToArray();
var ndmPrimitives = primitiveRepository.Primitives.Select(x => x.GetNdmPrimitive(unitSystem)).ToArray();
//Настройки триангуляции, пока опции могут быть только такие
ITriangulationOptions options = new TriangulationOptions { LimiteState = LimitStates.Collapse, CalcTerm = CalcTerms.ShortTerm };

View File

@@ -10,10 +10,14 @@
xmlns:mouseEventTriggers="clr-namespace:StructureHelper.Infrastructure.UI.Triggers.MouseEventTriggers"
xmlns:local="clr-namespace:StructureHelper.Windows.MainWindow"
xmlns:enums="clr-namespace:StructureHelper.Infrastructure.Enums"
xmlns:converters ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Units"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:MainViewModel}"
Title="StructureHelper" Height="700" Width="1000">
<Window.Resources>
<converters:Length x:Key="LengthConverter"/>
<converters:Area x:Key="AreaConverter"/>
<DataTemplate DataType="{x:Type dataContexts:Rectangle}">
<dataTemplates:RectangleTemplate/>
</DataTemplate>
@@ -36,8 +40,12 @@
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Primitives">
<Button Content="Add Rectangle" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/>
<Button Content="Add Point" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
<MenuItem Header="Add">
<Button Content="Add Rectangle" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/>
<Button Content="Add Point" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
</MenuItem>
<Button Content="Edit primitive" Command="{Binding EditPrimitive}"/>
<Button Content="Delete primitive" Command="{Binding DeletePrimitive}"/>
</MenuItem>
<Button Content="Calculation properties" Command="{Binding Path=EditCalculationPropertyCommand}"/>
</MenuItem>
@@ -55,8 +63,35 @@
</Expander>
<Expander Header="Geometry" ExpandDirection="Down" MinWidth="20" >
<ListBox ItemsSource="{Binding Primitives}">
<ListBox ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Margin="3" Fill="{Binding Brush}" />
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
</Grid>
<!--<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1"/>
<ColumnDefinition MinWidth="50"/>
</Grid.ColumnDefinitions>
<Viewbox Grid.RowSpan="2">
</Viewbox>
<TextBlock Grid.Column="1" Text="{Binding Name}"/>
<Button Grid.Column="1" Grid.Row="1" Content="..."/>
</Grid>-->
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
</StackPanel>
@@ -111,8 +146,8 @@
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
<Setter Property="Canvas.Left" Value="{Binding X}"/>
<Setter Property="Canvas.Top" Value="{Binding Y}"/>
<Setter Property="Canvas.Left" Value="{Binding X, Converter={StaticResource LengthConverter}}"/>
<Setter Property="Canvas.Top" Value="{Binding Y, Converter={StaticResource LengthConverter}}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
@@ -121,14 +156,12 @@
</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="Система едениц" Command="{Binding OpenUnitsSystemSettings}"/>
<Label VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="{Binding UnitsSystemName}"/>
<!--<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="Добавить тестовые примитивы" Command="{Binding AddTestCase}"/>
<Button VerticalAlignment="Center" Margin="5" Content="Добавить прямоугольник" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/>
<Button VerticalAlignment="Center" Margin="5" Content="Добавить точку" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
<Button VerticalAlignment="Center" Margin="5" Content="Add test primitives" Command="{Binding AddTestCase}"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -1,5 +1,6 @@
using System.Windows;
using StructureHelper.Services;
using StructureHelper.Services.Primitives;
namespace StructureHelper.Windows.MainWindow
{

View File

@@ -22,6 +22,10 @@ using StructureHelper.Windows.CalculationWindows.CalculationPropertyWindow;
using StructureHelperLogics.Services;
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;
namespace StructureHelper.Windows.MainWindow
{
@@ -30,6 +34,8 @@ namespace StructureHelper.Windows.MainWindow
private readonly double scaleRate = 1.1;
private IPrimitiveRepository PrimitiveRepository { get; }
public PrimitiveBase SelectedPrimitive { get; set; }
private readonly UnitSystemService unitSystemService;
private MainModel Model { get; }
@@ -102,6 +108,10 @@ namespace StructureHelper.Windows.MainWindow
set => OnPropertyChanged(value, ref yY2);
}
public ICommand AddPrimitive { get; }
public ICommand Calculate { get; }
public ICommand DeletePrimitive { get; }
public ICommand EditCalculationPropertyCommand { get; }
public ICommand EditPrimitive { get; }
public ICommand AddTestCase { get; }
public ICommand LeftButtonDown { get; }
public ICommand LeftButtonUp { get; }
@@ -115,13 +125,12 @@ namespace StructureHelper.Windows.MainWindow
public ICommand SetInBackOfAll { get; }
public ICommand ScaleCanvasDown { get; }
public ICommand ScaleCanvasUp { get; }
public ICommand Calculate { get; }
public ICommand SetPopupCanBeClosedTrue { get; }
public ICommand SetPopupCanBeClosedFalse { get; }
public ICommand EditCalculationPropertyCommand { get; }
public string UnitsSystemName => unitSystemService.GetCurrentSystem().Name;
private double delta = 0.5;
private double delta = 0.0005;
public MainViewModel(MainModel model, IPrimitiveRepository primitiveRepository, UnitSystemService unitSystemService)
{
@@ -131,8 +140,8 @@ namespace StructureHelper.Windows.MainWindow
CanvasWidth = 1500;
CanvasHeight = 1000;
XX2 = CanvasWidth;
XY1 = CanvasHeight / 2;
YX1 = CanvasWidth / 2;
XY1 = CanvasHeight / 2d;
YX1 = CanvasWidth / 2d;
YY2 = CanvasHeight;
calculationProperty = new CalculationProperty();
@@ -149,15 +158,15 @@ namespace StructureHelper.Windows.MainWindow
{
if (o is Rectangle rect && rect.BorderCaptured && !rect.ElementLock)
{
if (rect.PrimitiveWidth % 10 < delta || rect.PrimitiveWidth % 10 >= delta)
rect.PrimitiveWidth = Math.Round(PanelX / 10) * 10 - rect.X + 10;
if (rect.PrimitiveWidth % 10d < delta || rect.PrimitiveWidth % 10d >= delta)
rect.PrimitiveWidth = Math.Round(PanelX / 10d) * 10d - rect.X + 10d;
else
rect.PrimitiveWidth = PanelX - rect.X + 10;
rect.PrimitiveWidth = PanelX - rect.X + 10d;
if (rect.PrimitiveHeight % 10 < delta || rect.PrimitiveHeight % 10 >= delta)
rect.PrimitiveHeight = Math.Round(PanelY / 10) * 10 - rect.Y + 10;
if (rect.PrimitiveHeight % 10d < delta || rect.PrimitiveHeight % 10d >= delta)
rect.PrimitiveHeight = Math.Round(PanelY / 10d) * 10d - rect.Y + 10d;
else
rect.PrimitiveHeight = PanelY - rect.Y + 10;
rect.PrimitiveHeight = PanelY - rect.Y + 10d;
}
});
ClearSelection = new RelayCommand(o =>
@@ -228,13 +237,30 @@ namespace StructureHelper.Windows.MainWindow
AddPrimitive = new RelayCommand(o =>
{
if (!(o is PrimitiveType primitiveType)) return;
var primitive = primitiveType == PrimitiveType.Point
? (PrimitiveBase)new Point(50, 0, 0, this)
: (PrimitiveBase)new Rectangle(60, 40, 0, 0, this);
PrimitiveBase primitive;
if (primitiveType == PrimitiveType.Rectangle)
{
primitive = new Rectangle(0.60, 0.40, 0, 0, this);
}
else if (primitiveType == PrimitiveType.Point)
{
primitive = new Point(0.50, 0, 0, this);
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); }
Primitives.Add(primitive);
PrimitiveRepository.Add(primitive);
});
DeletePrimitive = new RelayCommand(
o=>DeleteSelectedPrimitive(),
o => SelectedPrimitive != null
);
EditPrimitive = new RelayCommand(
o => EditSelectedPrimitive(),
o => SelectedPrimitive != null
);
AddTestCase = new RelayCommand(o =>
{
foreach (var primitive in GetTestCasePrimitives())
@@ -247,12 +273,6 @@ namespace StructureHelper.Windows.MainWindow
Calculate = new RelayCommand(o =>
{
//var matrix = model.Calculate(10e3, 0d, 0d);
//MessageBox.Show(
// $"{nameof(matrix.EpsZ)} = {matrix.EpsZ};\n" +
// $"{nameof(matrix.Kx)} = {matrix.Kx};\n" +
// $"{nameof(matrix.Ky)} = {matrix.Ky}",
// "StructureHelper");
CalculateResult();
});
@@ -271,6 +291,30 @@ namespace StructureHelper.Windows.MainWindow
});
}
private void DeleteSelectedPrimitive()
{
if (! (SelectedPrimitive is null))
{
var dialogResult = MessageBox.Show("Delete primitive?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
Primitives.Remove(SelectedPrimitive);
PrimitiveRepository.Delete(SelectedPrimitive);
}
}
else { MessageBox.Show("Selection is changed", "Please, select primitive", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); }
}
private void EditSelectedPrimitive()
{
if (!(SelectedPrimitive is null))
{
var wnd = new PrimitiveProperties(SelectedPrimitive);
wnd.ShowDialog();
}
else { MessageBox.Show("Selection is changed", "Please, select primitive", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); }
}
private void CalculateResult()
{
IEnumerable<INdm> ndms = Model.GetNdms();
@@ -282,17 +326,18 @@ namespace StructureHelper.Windows.MainWindow
private IEnumerable<PrimitiveBase> GetTestCasePrimitives()
{
var width = 400;
var height = 600;
var d1 = 12;
var d2 = 25;
var width = 0.4d;
var height = 0.6d;
var area1 = Math.PI * 0.012d * 0.012d / 4d;
var area2 = Math.PI * 0.025d * 0.025d / 4d;
var gap = 0.05d;
var rectMaterial = new ConcreteDefinition("C40", 0, 40, 0, 1.3, 1.5);
var pointMaterial = new RebarDefinition("S400", 2, 400, 400, 1.15, 1.15);
yield return new Rectangle(width, height, -width / 2, -height / 2, this) { Material = rectMaterial, MaterialName = rectMaterial.MaterialClass };
yield return new Point(d1, -width / 2 + 50, -height / 2 + 50, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Point(d1, width / 2 - 50, -height / 2 + 50, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Point(d2, -width / 2 + 50, height / 2 - 50, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Point(d2, width / 2 - 50, height / 2 - 50, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Rectangle(width, height, 0, 0, this) { Material = rectMaterial, MaterialName = rectMaterial.MaterialClass };
yield return new Point(area1, -width / 2 + gap, -height / 2 + gap, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Point(area1, width / 2 - gap, -height / 2 + gap, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Point(area2, -width / 2 + gap, height / 2 - gap, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
yield return new Point(area2, width / 2 - gap, height / 2 - gap, this) { Material = pointMaterial, MaterialName = pointMaterial.MaterialClass };
}
private void EditCalculationProperty()
{

View File

@@ -0,0 +1,116 @@
<Window x:Class="StructureHelper.Windows.PrimitiveProperiesWindow.PrimitiveProperties"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper.Windows.PrimitiveProperiesWindow"
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.PrimitiveProperties"
xmlns:converters ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Units"
d:DataContext="{d:DesignInstance vm:PrimitivePropertiesViewModel}"
mc:Ignorable="d"
Title="PrimitiveProperties" Height="450" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Window.Resources>
<converters:Length x:Key="LengthConverter"/>
<converters:Area x:Key="AreaConverter"/>
<DataTemplate x:Key="RectangleProperties">
<Expander Header="Rectangle" IsExpanded="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Width"/>
<TextBlock Grid.Row="1" Text="Height"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding Width, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="1" Text="{Binding Height, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
</Grid>
</Expander>
</DataTemplate>
<DataTemplate x:Key="PointProperties">
<Expander Header="Point" IsExpanded="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Area"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding Area, Converter={StaticResource AreaConverter}, ValidatesOnDataErrors=True}"/>
</Grid>
</Expander>
</DataTemplate>
<DataTemplate x:Key="TriangulationProperties">
<Expander Header="Triangulation" IsExpanded="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Minimum element division"/>
<TextBlock Grid.Row="1" Text="Maximum element size"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding MinElementDivision, ValidatesOnDataErrors=True}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="1" Text="{Binding MaxElementSize, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
</Grid>
</Expander>
</DataTemplate>
</Window.Resources>
<ScrollViewer>
<StackPanel x:Name="StpProperties">
<Expander Header="Common properties" IsExpanded="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Name"/>
<TextBlock Grid.Row="1" Text="Name of material"/>
<TextBlock Grid.Row="2" Text="Center X"/>
<TextBlock Grid.Row="3" Text="Center Y"/>
<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="...">
</Button>
</StackPanel>
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding CenterX, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
<TextBox Grid.Row="3" Grid.Column="1" Margin="1" Text="{Binding CenterY, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
</Grid>
</Expander>
<!--<Expander Header="Prestrain" IsExpanded="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<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}"/>
</Grid>
</Expander>-->
</StackPanel>
</ScrollViewer>
</Window>

View File

@@ -0,0 +1,64 @@
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Windows.ViewModels.PrimitiveProperties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;
using Point = StructureHelper.Infrastructure.UI.DataContexts.Point;
using Rectangle = StructureHelper.Infrastructure.UI.DataContexts.Rectangle;
namespace StructureHelper.Windows.PrimitiveProperiesWindow
{
/// <summary>
/// Логика взаимодействия для PrimitiveProperties.xaml
/// </summary>
public partial class PrimitiveProperties : Window
{
PrimitiveBase primitive;
private PrimitivePropertiesViewModel viewModel;
public PrimitiveProperties(PrimitiveBase primitive)
{
this.primitive = primitive;
viewModel = new PrimitivePropertiesViewModel(this.primitive);
this.DataContext = viewModel;
InitializeComponent();
if (primitive is Rectangle) { AddPrimitiveProperties(PrimitiveType.Rectangle); }
else if (primitive is Point) { AddPrimitiveProperties(PrimitiveType.Point); }
else { throw new Exception("Type of object is unknown"); }
}
private void AddPrimitiveProperties(PrimitiveType type)
{
List<string> names = new List<string>();
if (type == PrimitiveType.Rectangle)
{
names.Add("TriangulationProperties");
names.Add("RectangleProperties");
}
else if (type == PrimitiveType.Point)
{
names.Add("PointProperties");
}
else { throw new Exception("Type of object is unknown"); }
foreach (var name in names)
{
ContentControl contentControl = new ContentControl();
contentControl.SetResourceReference(ContentControl.ContentTemplateProperty, name);
Binding binding = new Binding();
binding.Source = viewModel;
contentControl.SetBinding(ContentControl.ContentProperty, binding);
StpProperties.Children.Add(contentControl);
}
}
}
}

View File

@@ -24,7 +24,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.CalculationProperies
set
{
calculationProperty.IterationProperty.Accuracy = value;
OnPropertyChanged("Accuracy");
OnPropertyChanged(nameof(IterationAccuracy));
}
}
public int MaxIterationCount
@@ -36,7 +36,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.CalculationProperies
set
{
calculationProperty.IterationProperty.MaxIterationCount = value;
OnPropertyChanged("MaxIterationCount");
OnPropertyChanged(nameof(MaxIterationCount));
}
}
public IForceCombination SelectedCombination { get; set; }

View File

@@ -0,0 +1,174 @@
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelperCommon.Models.Shapes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Point = StructureHelper.Infrastructure.UI.DataContexts.Point;
using Rectangle = StructureHelper.Infrastructure.UI.DataContexts.Rectangle;
namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
{
public class PrimitivePropertiesViewModel : ViewModelBase, IDataErrorInfo
{
private PrimitiveBase primitive;
public string Name
{
get => primitive.Name;
set
{
primitive.Name = value;
OnPropertyChanged(nameof(Name));
}
}
public string MaterialName
{
get => primitive.MaterialName;
set
{
primitive.Name = value;
OnPropertyChanged(nameof(MaterialName));
}
}
public double CenterX
{
get => primitive.CenterX;
set
{
primitive.CenterX = value;
OnPropertyChanged(nameof(CenterX));
OnPropertyChanged(nameof(primitive.ShowedX));
OnPropertyChanged(nameof(primitive.X));
}
}
public double CenterY
{
get => primitive.CenterY;
set
{
primitive.CenterY = value;
OnPropertyChanged(nameof(CenterY));
OnPropertyChanged(nameof(primitive.ShowedY));
OnPropertyChanged("Y");
}
}
public double Prestrain_Kx
{
get => primitive.Pre
}
public int MinElementDivision
{
get => primitive.MinElementDivision;
set
{
primitive.MinElementDivision = value;
OnPropertyChanged(nameof(MinElementDivision));
}
}
public double MaxElementSize
{
get => primitive.MaxElementSize;
set { primitive.MaxElementSize = value; }
}
public double Width
{
get
{
if (primitive is Rectangle)
{
var shape = primitive as Rectangle;
return shape.PrimitiveWidth;
}
return 0d;
}
set
{
if (primitive is Rectangle)
{
var shape = primitive as Rectangle;
shape.PrimitiveWidth = value;
}
}
}
public double Height
{
get
{
if (primitive is Rectangle)
{
var shape = primitive as Rectangle;
return shape.PrimitiveHeight;
}
return 0d;
}
set
{
if (primitive is Rectangle)
{
var shape = primitive as Rectangle;
shape.PrimitiveHeight = value;
}
}
}
public double Area
{
get
{
if (primitive is Point)
{
var shape = primitive as Point;
return shape.Area;
}
return 0d;
}
set
{
if (primitive is Point)
{
var shape = primitive as Point;
shape.Area = value;
}
}
}
public string this[string columnName]
{
get
{
string error = null;
if (columnName == nameof(Width)
||
columnName == nameof(Height))
{
if (this.Width <= 0 || this.Height <=0)
{
error = "Width and Height of rectangle must be greater than zero";
}
}
return error;
}
}
public string Error => throw new NotImplementedException();
public PrimitivePropertiesViewModel(PrimitiveBase primitive)
{
this.primitive = primitive;
}
}
}