Calculations fix
This commit is contained in:
@@ -10,21 +10,40 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
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;
|
||||
ShowedX = 0;
|
||||
ShowedY = 0;
|
||||
PrimitiveHeight = d;
|
||||
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)
|
||||
{
|
||||
var width = unitSystem.ConvertLength(PrimitiveWidth);
|
||||
double area = Math.Round(width * width * Math.PI / 4, 2);
|
||||
var diam = unitSystem.ConvertLength(PrimitiveWidth);
|
||||
double area = diam * diam * Math.PI / 4;
|
||||
string materialName = MaterialName;
|
||||
ICenter center = new Center { X = unitSystem.ConvertLength(ShowedX), Y = unitSystem.ConvertLength(ShowedY) };
|
||||
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 };
|
||||
return ndmPrimitive;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured;
|
||||
private Brush brush;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
@@ -182,102 +183,45 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
#region Команды
|
||||
public ICommand PrimitiveLeftButtonDown { get; }
|
||||
public ICommand PrimitiveLeftButtonUp { get; }
|
||||
public ICommand RectanglePreviewMouseMove { get; }
|
||||
public ICommand PointPreviewMouseMove { get; }
|
||||
public ICommand PreviewMouseMove { get; protected set; }
|
||||
public ICommand PrimitiveDoubleClick { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
protected PrimitiveBase(PrimitiveType type, double rectX, double rectY, MainViewModel mainViewModel)
|
||||
protected PrimitiveBase(PrimitiveType type, double x, double y, MainViewModel ownerVM)
|
||||
{
|
||||
this.type = type;
|
||||
Yx1 = rectX;
|
||||
Xy1 = rectY;
|
||||
var randomR = new Random().Next(150, 255);
|
||||
var randomG = new Random().Next(0, 255);
|
||||
var randomB = new Random().Next(30, 130);
|
||||
X = ownerVM.YX1 + x;
|
||||
Y = ownerVM.XY1 + y;
|
||||
var randomR = new Random(new Random((int)DateTime.Now.Ticks % 1000).Next(50)).Next(0, 255);
|
||||
var randomG = new Random(new Random((int)DateTime.Now.Ticks % 200).Next(100, 200)).Next(0, 255);
|
||||
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);
|
||||
Brush = new SolidColorBrush(color);
|
||||
PrimitiveLeftButtonUp = new RelayCommand(o => Captured = false);
|
||||
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 =>
|
||||
{
|
||||
PopupCanBeClosed = false;
|
||||
Captured = false;
|
||||
ParamsPanelVisibilty = true;
|
||||
ParameterCaptured = true;
|
||||
|
||||
|
||||
|
||||
//if (primitive is Rectangle rect)
|
||||
// rect.BorderCaptured = false;
|
||||
});
|
||||
|
||||
OwnerVm = ownerVM;
|
||||
}
|
||||
|
||||
protected readonly MainViewModel OwnerVm;
|
||||
|
||||
private void UpdateCoordinatesX(double showedX)
|
||||
{
|
||||
if (Type == PrimitiveType.Rectangle) X = showedX + Yx1;
|
||||
if (Type == PrimitiveType.Point) X = showedX + Yx1 - PrimitiveWidth / 2;
|
||||
if (Type == PrimitiveType.Rectangle) X = showedX + OwnerVm.YX1;
|
||||
if (Type == PrimitiveType.Point) X = showedX + OwnerVm.YX1 - PrimitiveWidth / 2;
|
||||
}
|
||||
private void UpdateCoordinatesY(double showedY)
|
||||
{
|
||||
if (Type == PrimitiveType.Rectangle) Y = -showedY + Xy1 - PrimitiveHeight;
|
||||
if (Type == PrimitiveType.Point) Y = -showedY + Xy1 - PrimitiveWidth / 2;
|
||||
if (Type == PrimitiveType.Rectangle) Y = -showedY + OwnerVm.XY1 - PrimitiveHeight;
|
||||
if (Type == PrimitiveType.Point) Y = -showedY + OwnerVm.XY1 - PrimitiveWidth / 2;
|
||||
}
|
||||
|
||||
public abstract INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem);
|
||||
|
||||
@@ -4,18 +4,39 @@ using StructureHelper.Windows.MainWindow;
|
||||
using StructureHelperCommon.Models.Entities;
|
||||
using StructureHelperCommon.Models.Materials;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
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;
|
||||
PrimitiveWidth = primitiveWidth;
|
||||
PrimitiveHeight = primitiveHeight;
|
||||
ShowedX = 0;
|
||||
ShowedY = 0;
|
||||
PreviewMouseMove = 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((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)
|
||||
@@ -27,8 +48,8 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
string materialName = MaterialName;
|
||||
ICenter center = new Center { X = centerX, Y = centerY };
|
||||
IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle { Height = height, Width = width, Angle = 0 };
|
||||
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesingTensileStrength };
|
||||
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial };
|
||||
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
|
||||
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = 1, NdmMinDivision = 20 };
|
||||
return ndmPrimitive;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseMove">
|
||||
<i:InvokeCommandAction Command="{Binding PointPreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
<i:InvokeCommandAction Command="{Binding PreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonUp}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="PreviewMouseMove">
|
||||
<i:InvokeCommandAction Command="{Binding RectanglePreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
<i:InvokeCommandAction Command="{Binding PreviewMouseMove}" CommandParameter="{Binding}"/>
|
||||
</i:EventTrigger>
|
||||
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
|
||||
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace StructureHelperLogics.Services
|
||||
NdmCollection = ndmCollection
|
||||
};
|
||||
var calculator = new Calculator();
|
||||
//Act
|
||||
calculator.Run(loaderData, new CancellationToken());
|
||||
return calculator.Result.StrainMatrix;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace StructureHelper.Windows.MainWindow
|
||||
public IStrainMatrix Calculate(double mx, double my, double nz)
|
||||
{
|
||||
var unitSystem = unitSystemService.GetCurrentSystem();
|
||||
return calculationService.GetPrimitiveStrainMatrix(primitiveRepository.GetPoints()
|
||||
return calculationService.GetPrimitiveStrainMatrix(primitiveRepository.GetRectangles()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
<Label VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5" Content="{Binding UnitsSystemName}"/>
|
||||
</StackPanel>
|
||||
<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.Point}"/>
|
||||
</StackPanel>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using StructureHelper.Infrastructure;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
@@ -10,6 +12,7 @@ using StructureHelper.MaterialCatalogWindow;
|
||||
using StructureHelper.Services;
|
||||
using StructureHelper.Windows.ColorPickerWindow;
|
||||
using StructureHelper.UnitSystem;
|
||||
using StructureHelper.Models.Materials;
|
||||
|
||||
namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
@@ -89,6 +92,7 @@ namespace StructureHelper.Windows.MainWindow
|
||||
set => OnPropertyChanged(value, ref yY2);
|
||||
}
|
||||
public ICommand AddPrimitive { get; }
|
||||
public ICommand AddTestCase { get; }
|
||||
public ICommand LeftButtonDown { get; }
|
||||
public ICommand LeftButtonUp { get; }
|
||||
public ICommand PreviewMouseMove { get; }
|
||||
@@ -211,15 +215,29 @@ namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
if (!(o is PrimitiveType primitiveType)) return;
|
||||
var primitive = primitiveType == PrimitiveType.Point
|
||||
? (PrimitiveBase) new Point(50, YX1, XY1, this)
|
||||
: (PrimitiveBase) new Rectangle(60, 40, YX1, XY1, this);
|
||||
? (PrimitiveBase)new Point(50, 0, 0, this)
|
||||
: (PrimitiveBase)new Rectangle(60, 40, 0, 0, this);
|
||||
Primitives.Add(primitive);
|
||||
PrimitiveRepository.Add(primitive);
|
||||
});
|
||||
|
||||
AddTestCase = new RelayCommand(o =>
|
||||
{
|
||||
foreach (var primitive in GetTestCasePrimitives())
|
||||
{
|
||||
Primitives.Add(primitive);
|
||||
PrimitiveRepository.Add(primitive);
|
||||
}
|
||||
});
|
||||
|
||||
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 =>
|
||||
@@ -234,5 +252,20 @@ namespace StructureHelper.Windows.MainWindow
|
||||
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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user