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()
{