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

@@ -10,10 +10,11 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
{
public class Point : PrimitiveBase
{
public Point(double d, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Point, x, y, ownerVm)
public double Area { get; set; }
public Point(double area, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Point, x, y, ownerVm)
{
PrimitiveWidth = d;
PrimitiveHeight = d;
Name = "New point";
Area = area;
PreviewMouseMove = new RelayCommand(o =>
{
if (!(o is Point point)) return;
@@ -32,17 +33,17 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
point.ShowedY = -(ownerVm.PanelY - pointDelta - OwnerVm.XY1);
}
});
ShowedX = x;
ShowedY = y;
CenterX = x;
CenterY = y;
}
public double Diameter { get => Math.Sqrt(Area / Math.PI) * 2; }
public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem)
{
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 };
ICenter center = new Center { X = CenterX, Y = CenterY };
IShape shape = new StructureHelperCommon.Models.Shapes.Point { Area = this.Area };
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial };
return ndmPrimitive;

View File

@@ -3,6 +3,9 @@ using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Infrastructure.Exceptions;
using StructureHelper.Infrastructure.Strings;
using StructureHelper.Infrastructure.UI.Converters.Units;
using StructureHelper.Models.Materials;
using StructureHelper.UnitSystem.Systems;
using StructureHelper.Windows.MainWindow;
@@ -16,9 +19,14 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
#region Поля
private readonly PrimitiveType type;
private string name;
private double centerX, centerY;
private int minElementDivision;
private double maxElementSize;
private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured;
private Brush brush;
private MaterialDefinitionBase material;
private double prestrain_kx, prestrain_ky, prestrain_epsz;
private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight, showedX, showedY;
protected double delta = 0.5;
private int showedZIndex = 1, zIndex;
@@ -39,6 +47,61 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
}
}
public string Name
{
get => name;
set
{
OnPropertyChanged(value, ref name);
}
}
public double CenterX
{
get => centerX;
set
{
if (this is Rectangle)
{
ShowedX = value - primitiveWidth / 2d;
}
else if (this is Point)
{
Point point = this as Point;
ShowedX = value - point.Diameter / 2;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
OnPropertyChanged(value, ref centerX);
}
}
public double CenterY
{
get => centerY;
set
{
if (this is Rectangle)
{
ShowedY = value - primitiveHeight / 2d;
}
else if (this is Point)
{
Point point = this as Point;
ShowedY = value - point.Diameter / 2;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
OnPropertyChanged(value, ref centerY);
}
}
public int MinElementDivision
{
get => minElementDivision;
set { OnPropertyChanged(value, ref minElementDivision); }
}
public double MaxElementSize
{
get => maxElementSize;
set { OnPropertyChanged(value, ref maxElementSize); }
}
public bool Captured
{
set => OnPropertyChanged(value, ref captured);
@@ -203,10 +266,11 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
PrimitiveDoubleClick = new RelayCommand(o =>
{
PopupCanBeClosed = false;
Captured = false;
ParamsPanelVisibilty = true;
ParameterCaptured = true;
//PopupCanBeClosed = false;
//Captured = false;
//ParamsPanelVisibilty = true;
//ParameterCaptured = true;
});
OwnerVm = ownerVM;
}
@@ -215,13 +279,29 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
private void UpdateCoordinatesX(double showedX)
{
if (Type == PrimitiveType.Rectangle) X = showedX + OwnerVm.YX1;
if (Type == PrimitiveType.Point) X = showedX + OwnerVm.YX1 - PrimitiveWidth / 2;
if (this is Rectangle)
{
X = showedX + OwnerVm.YX1 / UnitConstatnts.LengthConstant;
}
else if (this is Point)
{
Point point = this as Point;
X = showedX + OwnerVm.YX1 / UnitConstatnts.LengthConstant;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
}
private void UpdateCoordinatesY(double showedY)
{
if (Type == PrimitiveType.Rectangle) Y = -showedY + OwnerVm.XY1 - PrimitiveHeight;
if (Type == PrimitiveType.Point) Y = -showedY + OwnerVm.XY1 - PrimitiveWidth / 2;
if (this is Rectangle)
{
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.LengthConstant - PrimitiveHeight;
}
else if (this is Point)
{
Point point = this as Point;
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.LengthConstant - point.Diameter;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
}
public abstract INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem);
@@ -230,7 +310,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
MaterialTypes materialTypes;
if (Material is ConcreteDefinition) { materialTypes = MaterialTypes.Concrete; }
else if (Material is RebarDefinition) { materialTypes = MaterialTypes.Reinforcement; }
else { throw new Exception("MaterialType is unknown"); }
else { throw new StructureHelperException(ErrorStrings.MaterialTypeIsUnknown); }
return materialTypes;
}
}

View File

@@ -13,6 +13,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
public Rectangle(double primitiveWidth, double primitiveHeight, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Rectangle, x, y, ownerVm)
{
Type = PrimitiveType.Rectangle;
Name = "New rectangle";
PrimitiveWidth = primitiveWidth;
PrimitiveHeight = primitiveHeight;
PreviewMouseMove = new RelayCommand(o =>
@@ -34,22 +35,23 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
rect.ShowedY = -(OwnerVm.PanelY - deltaY - OwnerVm.XY1 + rect.PrimitiveHeight);
}
});
ShowedX = x;
ShowedY = y;
CenterX = x;
CenterY = y;
MinElementDivision = 10;
MaxElementSize = Math.Min(Math.Min(PrimitiveWidth, PrimitiveHeight) / MinElementDivision, 0.01);
}
public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem)
{
var width = unitSystem.ConvertLength(PrimitiveWidth);
var height = unitSystem.ConvertLength(PrimitiveHeight);
double centerX = unitSystem.ConvertLength(ShowedX) + width / 2;
double centerY = unitSystem.ConvertLength(ShowedY) + height / 2;
var width = PrimitiveWidth;
var height = PrimitiveHeight;
double centerX = CenterX;
double centerY = CenterY;
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.DesignCompressiveStrength };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = 0.01, NdmMinDivision = 20 };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = MaxElementSize, NdmMinDivision = MinElementDivision };
return ndmPrimitive;
}
}