Calculations fix

This commit is contained in:
NickAppLab
2022-08-30 19:47:52 +05:00
parent 51748407e8
commit cf0392ad6f
9 changed files with 115 additions and 98 deletions

View File

@@ -10,21 +10,40 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
{ {
public class Point : PrimitiveBase public class Point : PrimitiveBase
{ {
public Point(double d, double x, double y, MainViewModel mainViewModel) : base(PrimitiveType.Point, x, y, mainViewModel) public Point(double d, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Point, x, y, ownerVm)
{ {
PrimitiveWidth = d; PrimitiveWidth = d;
ShowedX = 0; PrimitiveHeight = d;
ShowedY = 0; PreviewMouseMove = new RelayCommand(o =>
{
if (!(o is Point point)) return;
if (point.Captured && !point.ElementLock)
{
var pointDelta = point.PrimitiveWidth / 2;
if (point.ShowedX % 10 <= pointDelta || point.ShowedX % 10 >= 10 - pointDelta)
point.ShowedX = Math.Round((ownerVm.PanelX - OwnerVm.YX1) / 10) * 10;
else
point.ShowedX = ownerVm.PanelX - pointDelta - OwnerVm.YX1;
if (point.ShowedY % 10 <= pointDelta || point.ShowedY % 10 >= 10 - pointDelta)
point.ShowedY = -(Math.Round((ownerVm.PanelY - OwnerVm.XY1) / 10) * 10);
else
point.ShowedY = -(ownerVm.PanelY - pointDelta - OwnerVm.XY1);
}
});
ShowedX = x;
ShowedY = y;
} }
public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem) public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem)
{ {
var width = unitSystem.ConvertLength(PrimitiveWidth); var diam = unitSystem.ConvertLength(PrimitiveWidth);
double area = Math.Round(width * width * Math.PI / 4, 2); double area = diam * diam * Math.PI / 4;
string materialName = MaterialName; string materialName = MaterialName;
ICenter center = new Center { X = unitSystem.ConvertLength(ShowedX), Y = unitSystem.ConvertLength(ShowedY) }; ICenter center = new Center { X = unitSystem.ConvertLength(ShowedX), Y = unitSystem.ConvertLength(ShowedY) };
IShape shape = new StructureHelperCommon.Models.Shapes.Point { Area = area }; IShape shape = new StructureHelperCommon.Models.Shapes.Point { Area = area };
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesingTensileStrength }; ; IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial }; INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial };
return ndmPrimitive; return ndmPrimitive;
} }

View File

@@ -19,7 +19,8 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured; private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured;
private Brush brush; private Brush brush;
private MaterialDefinitionBase material; private MaterialDefinitionBase material;
private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight, showedX, showedY, delta = 0.5; private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight, showedX, showedY;
protected double delta = 0.5;
private int showedZIndex = 1, zIndex; private int showedZIndex = 1, zIndex;
#endregion #endregion
@@ -182,102 +183,45 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
#region Команды #region Команды
public ICommand PrimitiveLeftButtonDown { get; } public ICommand PrimitiveLeftButtonDown { get; }
public ICommand PrimitiveLeftButtonUp { get; } public ICommand PrimitiveLeftButtonUp { get; }
public ICommand RectanglePreviewMouseMove { get; } public ICommand PreviewMouseMove { get; protected set; }
public ICommand PointPreviewMouseMove { get; }
public ICommand PrimitiveDoubleClick { get; } public ICommand PrimitiveDoubleClick { get; }
#endregion #endregion
protected PrimitiveBase(PrimitiveType type, double rectX, double rectY, MainViewModel mainViewModel) protected PrimitiveBase(PrimitiveType type, double x, double y, MainViewModel ownerVM)
{ {
this.type = type; this.type = type;
Yx1 = rectX; X = ownerVM.YX1 + x;
Xy1 = rectY; Y = ownerVM.XY1 + y;
var randomR = new Random().Next(150, 255); var randomR = new Random(new Random((int)DateTime.Now.Ticks % 1000).Next(50)).Next(0, 255);
var randomG = new Random().Next(0, 255); var randomG = new Random(new Random((int)DateTime.Now.Ticks % 200).Next(100, 200)).Next(0, 255);
var randomB = new Random().Next(30, 130); var randomB = new Random(new Random((int)DateTime.Now.Ticks % 50).Next(500, 1000)).Next(0, 255);
var color = Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB); var color = Color.FromRgb((byte)randomR, (byte)randomG, (byte)randomB);
Brush = new SolidColorBrush(color); Brush = new SolidColorBrush(color);
PrimitiveLeftButtonUp = new RelayCommand(o => Captured = false); PrimitiveLeftButtonUp = new RelayCommand(o => Captured = false);
PrimitiveLeftButtonDown = new RelayCommand(o => Captured = true); PrimitiveLeftButtonDown = new RelayCommand(o => Captured = true);
RectanglePreviewMouseMove = new RelayCommand(o =>
{
if (!(o is Rectangle rect)) return;
if (Captured && !rect.BorderCaptured && !ElementLock)
{
var deltaX = PrimitiveWidth / 2;
var deltaY = PrimitiveHeight / 2;
if (rect.ShowedX % 10 <= delta || rect.ShowedX % 10 >= 10 - delta)
rect.ShowedX = Math.Round((mainViewModel.PanelX - deltaX - Yx1) / 10) * 10;
else
rect.ShowedX = mainViewModel.PanelX - deltaX - Yx1;
if (rect.ShowedY % 10 <= delta || rect.ShowedY % 10 >= 10 - delta)
rect.ShowedY = -(Math.Round((mainViewModel.PanelY - deltaY - Xy1 + rect.PrimitiveHeight) / 10) * 10);
else
rect.ShowedY = -(mainViewModel.PanelY - deltaY - Xy1 + rect.PrimitiveHeight);
}
if (ParameterCaptured)
{
//RectParameterX = rect.ShowedX;
//RectParameterY = rect.ShowedY;
//RectParameterWidth = rect.PrimitiveWidth;
//RectParameterHeight = rect.PrimitiveHeight;
//ParameterOpacity = rect.ShowedOpacity;
//ElementLock = rect.ElementLock;
}
});
PointPreviewMouseMove = new RelayCommand(o =>
{
if (!(o is Point point)) return;
if (point.Captured && !point.ElementLock)
{
var pointDelta = point.PrimitiveWidth / 2;
if (point.ShowedX % 10 <= pointDelta || point.ShowedX % 10 >= 10 - pointDelta)
point.ShowedX = Math.Round((mainViewModel.PanelX - Yx1) / 10) * 10;
else
point.ShowedX = mainViewModel.PanelX - pointDelta - Yx1;
if (point.ShowedY % 10 <= pointDelta || point.ShowedY % 10 >= 10 - pointDelta)
point.ShowedY = -(Math.Round((mainViewModel.PanelY - Xy1) / 10) * 10);
else
point.ShowedY = -(mainViewModel.PanelY - pointDelta - Xy1);
}
if (ParameterCaptured)
{
//EllipseParameterX = point.ShowedX;
//EllipseParameterY = point.ShowedY;
//EllipseParameterSquare = point.Square;
//ParameterOpacity = point.ShowedOpacity;
//ElementLock = point.ElementLock;
}
});
PrimitiveDoubleClick = new RelayCommand(o => PrimitiveDoubleClick = new RelayCommand(o =>
{ {
PopupCanBeClosed = false; PopupCanBeClosed = false;
Captured = false; Captured = false;
ParamsPanelVisibilty = true; ParamsPanelVisibilty = true;
ParameterCaptured = true; ParameterCaptured = true;
//if (primitive is Rectangle rect)
// rect.BorderCaptured = false;
}); });
OwnerVm = ownerVM;
} }
protected readonly MainViewModel OwnerVm;
private void UpdateCoordinatesX(double showedX) private void UpdateCoordinatesX(double showedX)
{ {
if (Type == PrimitiveType.Rectangle) X = showedX + Yx1; if (Type == PrimitiveType.Rectangle) X = showedX + OwnerVm.YX1;
if (Type == PrimitiveType.Point) X = showedX + Yx1 - PrimitiveWidth / 2; if (Type == PrimitiveType.Point) X = showedX + OwnerVm.YX1 - PrimitiveWidth / 2;
} }
private void UpdateCoordinatesY(double showedY) private void UpdateCoordinatesY(double showedY)
{ {
if (Type == PrimitiveType.Rectangle) Y = -showedY + Xy1 - PrimitiveHeight; if (Type == PrimitiveType.Rectangle) Y = -showedY + OwnerVm.XY1 - PrimitiveHeight;
if (Type == PrimitiveType.Point) Y = -showedY + Xy1 - PrimitiveWidth / 2; if (Type == PrimitiveType.Point) Y = -showedY + OwnerVm.XY1 - PrimitiveWidth / 2;
} }
public abstract INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem); public abstract INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem);

View File

@@ -4,18 +4,39 @@ using StructureHelper.Windows.MainWindow;
using StructureHelperCommon.Models.Entities; using StructureHelperCommon.Models.Entities;
using StructureHelperCommon.Models.Materials; using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Models.Shapes;
using System;
namespace StructureHelper.Infrastructure.UI.DataContexts namespace StructureHelper.Infrastructure.UI.DataContexts
{ {
public class Rectangle : PrimitiveBase public class Rectangle : PrimitiveBase
{ {
public Rectangle(double primitiveWidth, double primitiveHeight, double rectX, double rectY, MainViewModel mainViewModel) : base(PrimitiveType.Rectangle, rectX, rectY, mainViewModel) public Rectangle(double primitiveWidth, double primitiveHeight, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Rectangle, x, y, ownerVm)
{ {
Type = PrimitiveType.Rectangle; Type = PrimitiveType.Rectangle;
PrimitiveWidth = primitiveWidth; PrimitiveWidth = primitiveWidth;
PrimitiveHeight = primitiveHeight; PrimitiveHeight = primitiveHeight;
ShowedX = 0; PreviewMouseMove = new RelayCommand(o =>
ShowedY = 0; {
if (!(o is Rectangle rect)) return;
if (Captured && !rect.BorderCaptured && !ElementLock)
{
var deltaX = PrimitiveWidth / 2;
var deltaY = PrimitiveHeight / 2;
if (rect.ShowedX % 10 <= delta || rect.ShowedX % 10 >= 10 - delta)
rect.ShowedX = Math.Round((OwnerVm.PanelX - deltaX - OwnerVm.YX1) / 10) * 10;
else
rect.ShowedX = OwnerVm.PanelX - deltaX - OwnerVm.YX1;
if (rect.ShowedY % 10 <= delta || rect.ShowedY % 10 >= 10 - delta)
rect.ShowedY = -(Math.Round((OwnerVm.PanelY - deltaY - OwnerVm.XY1 + rect.PrimitiveHeight) / 10) * 10);
else
rect.ShowedY = -(OwnerVm.PanelY - deltaY - OwnerVm.XY1 + rect.PrimitiveHeight);
}
});
ShowedX = x;
ShowedY = y;
} }
public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem) public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem)
@@ -27,8 +48,8 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
string materialName = MaterialName; string materialName = MaterialName;
ICenter center = new Center { X = centerX, Y = centerY }; ICenter center = new Center { X = centerX, Y = centerY };
IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle { Height = height, Width = width, Angle = 0 }; IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle { Height = height, Width = width, Angle = 0 };
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesingTensileStrength }; IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial }; INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = 1, NdmMinDivision = 20 };
return ndmPrimitive; return ndmPrimitive;
} }
} }

View File

@@ -19,7 +19,7 @@
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/> <i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
</i:EventTrigger> </i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove"> <i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding PointPreviewMouseMove}" CommandParameter="{Binding}"/> <i:InvokeCommandAction Command="{Binding PreviewMouseMove}" CommandParameter="{Binding}"/>
</i:EventTrigger> </i:EventTrigger>
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown"> <mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/> <i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>

View File

@@ -22,7 +22,7 @@
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/> <i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
</i:EventTrigger> </i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove"> <i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding RectanglePreviewMouseMove}" CommandParameter="{Binding}"/> <i:InvokeCommandAction Command="{Binding PreviewMouseMove}" CommandParameter="{Binding}"/>
</i:EventTrigger> </i:EventTrigger>
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown"> <mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/> <i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>

View File

@@ -32,7 +32,6 @@ namespace StructureHelperLogics.Services
NdmCollection = ndmCollection NdmCollection = ndmCollection
}; };
var calculator = new Calculator(); var calculator = new Calculator();
//Act
calculator.Run(loaderData, new CancellationToken()); calculator.Run(loaderData, new CancellationToken());
return calculator.Result.StrainMatrix; return calculator.Result.StrainMatrix;
} }

View File

@@ -22,9 +22,9 @@ namespace StructureHelper.Windows.MainWindow
public IStrainMatrix Calculate(double mx, double my, double nz) public IStrainMatrix Calculate(double mx, double my, double nz)
{ {
var unitSystem = unitSystemService.GetCurrentSystem(); var unitSystem = unitSystemService.GetCurrentSystem();
return calculationService.GetPrimitiveStrainMatrix(primitiveRepository.GetPoints() return calculationService.GetPrimitiveStrainMatrix(primitiveRepository.GetRectangles()
.Select(x => x.GetNdmPrimitive(unitSystem)) .Select(x => x.GetNdmPrimitive(unitSystem))
.Concat(primitiveRepository.GetRectangles().Select(x => x.GetNdmPrimitive(unitSystem))).ToArray(), mx, my, nz); .Concat(primitiveRepository.GetPoints().Select(x => x.GetNdmPrimitive(unitSystem))).ToArray(), mx, my, nz);
} }
} }
} }

View File

@@ -94,6 +94,7 @@
<Label VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="{Binding UnitsSystemName}"/> <Label VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="{Binding UnitsSystemName}"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<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.Rectangle}"/>
<Button VerticalAlignment="Center" Margin="5" Content="Добавить точку" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/> <Button VerticalAlignment="Center" Margin="5" Content="Добавить точку" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
</StackPanel> </StackPanel>

View File

@@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.Enums;
@@ -10,6 +12,7 @@ using StructureHelper.MaterialCatalogWindow;
using StructureHelper.Services; using StructureHelper.Services;
using StructureHelper.Windows.ColorPickerWindow; using StructureHelper.Windows.ColorPickerWindow;
using StructureHelper.UnitSystem; using StructureHelper.UnitSystem;
using StructureHelper.Models.Materials;
namespace StructureHelper.Windows.MainWindow namespace StructureHelper.Windows.MainWindow
{ {
@@ -89,6 +92,7 @@ namespace StructureHelper.Windows.MainWindow
set => OnPropertyChanged(value, ref yY2); set => OnPropertyChanged(value, ref yY2);
} }
public ICommand AddPrimitive { get; } public ICommand AddPrimitive { get; }
public ICommand AddTestCase { get; }
public ICommand LeftButtonDown { get; } public ICommand LeftButtonDown { get; }
public ICommand LeftButtonUp { get; } public ICommand LeftButtonUp { get; }
public ICommand PreviewMouseMove { get; } public ICommand PreviewMouseMove { get; }
@@ -211,15 +215,29 @@ namespace StructureHelper.Windows.MainWindow
{ {
if (!(o is PrimitiveType primitiveType)) return; if (!(o is PrimitiveType primitiveType)) return;
var primitive = primitiveType == PrimitiveType.Point var primitive = primitiveType == PrimitiveType.Point
? (PrimitiveBase) new Point(50, YX1, XY1, this) ? (PrimitiveBase)new Point(50, 0, 0, this)
: (PrimitiveBase) new Rectangle(60, 40, YX1, XY1, this); : (PrimitiveBase)new Rectangle(60, 40, 0, 0, this);
Primitives.Add(primitive); Primitives.Add(primitive);
PrimitiveRepository.Add(primitive); PrimitiveRepository.Add(primitive);
}); });
AddTestCase = new RelayCommand(o =>
{
foreach (var primitive in GetTestCasePrimitives())
{
Primitives.Add(primitive);
PrimitiveRepository.Add(primitive);
}
});
Calculate = new RelayCommand(o => Calculate = new RelayCommand(o =>
{ {
model.Calculate(-50e3, 0d, 0d); 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");
}); });
SetPopupCanBeClosedTrue = new RelayCommand(o => SetPopupCanBeClosedTrue = new RelayCommand(o =>
@@ -234,5 +252,20 @@ namespace StructureHelper.Windows.MainWindow
primitive.PopupCanBeClosed = false; primitive.PopupCanBeClosed = false;
}); });
} }
private IEnumerable<PrimitiveBase> GetTestCasePrimitives()
{
var width = 400;
var height = 600;
var d1 = 12;
var d2 = 25;
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 };
}
} }
} }