Рефакторинг, добавление моделей примитивов
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public enum PrimitiveType
|
||||
{
|
||||
Ellipse,
|
||||
Point,
|
||||
Rectangle
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelper.Windows.MainWindow;
|
||||
using StructureHelperLogics.Data.Shapes;
|
||||
using StructureHelperLogics.NdmCalculations.Entities;
|
||||
@@ -9,7 +7,7 @@ using StructureHelperLogics.NdmCalculations.Materials;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
public class Ellipse : PrimitiveBase<Point>
|
||||
public class Point : PrimitiveBase
|
||||
{
|
||||
private double square;
|
||||
public double Square
|
||||
@@ -24,7 +22,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
}
|
||||
}
|
||||
|
||||
public Ellipse(double square, double ellipseX, double ellipseY, MainViewModel mainViewModel) : base(PrimitiveType.Ellipse, ellipseX, ellipseY, mainViewModel)
|
||||
public Point(double square, double x, double y, MainViewModel mainViewModel) : base(PrimitiveType.Point, x, y, mainViewModel)
|
||||
{
|
||||
Square = square;
|
||||
ShowedX = 0;
|
||||
@@ -39,13 +37,10 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
double area = 0;
|
||||
string materialName = "s400";
|
||||
ICenter center = new Center() { X = centerX, Y = centerY };
|
||||
IShape shape = new Point() { Area = area };
|
||||
IShape shape = new StructureHelperLogics.Data.Shapes.Point() { Area = area };
|
||||
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial() { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = strength }; ;
|
||||
INdmPrimitive ndmPrimitive = new NdmPrimitive() { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial };
|
||||
return ndmPrimitive;
|
||||
}
|
||||
|
||||
public override Point MapToShape()
|
||||
=> new Point {Area = Square};
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using StructureHelperLogics.NdmCalculations.Materials;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
public abstract class PrimitiveBase<T> : ViewModelBase where T : StructureHelperLogics.Data.Shapes.IShape
|
||||
public abstract class PrimitiveBase: ViewModelBase
|
||||
{
|
||||
#region Поля
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
public ICommand PrimitiveLeftButtonDown { get; }
|
||||
public ICommand PrimitiveLeftButtonUp { get; }
|
||||
public ICommand RectanglePreviewMouseMove { get; }
|
||||
public ICommand EllipsePreviewMouseMove { get; }
|
||||
public ICommand PointPreviewMouseMove { get; }
|
||||
public ICommand PrimitiveDoubleClick { get; }
|
||||
|
||||
#endregion
|
||||
@@ -208,30 +208,30 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
//ElementLock = rect.ElementLock;
|
||||
}
|
||||
});
|
||||
EllipsePreviewMouseMove = new RelayCommand(o =>
|
||||
PointPreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
if (!(o is Ellipse ellipse)) return;
|
||||
if (ellipse.Captured && !ellipse.ElementLock)
|
||||
if (!(o is Point point)) return;
|
||||
if (point.Captured && !point.ElementLock)
|
||||
{
|
||||
var ellipseDelta = ellipse.PrimitiveWidth / 2;
|
||||
var pointDelta = point.PrimitiveWidth / 2;
|
||||
|
||||
if (ellipse.ShowedX % 10 <= ellipseDelta || ellipse.ShowedX % 10 >= 10 - ellipseDelta)
|
||||
ellipse.ShowedX = Math.Round((mainViewModel.PanelX - Yx1) / 10) * 10;
|
||||
if (point.ShowedX % 10 <= pointDelta || point.ShowedX % 10 >= 10 - pointDelta)
|
||||
point.ShowedX = Math.Round((mainViewModel.PanelX - Yx1) / 10) * 10;
|
||||
else
|
||||
ellipse.ShowedX = mainViewModel.PanelX - ellipseDelta - Yx1;
|
||||
point.ShowedX = mainViewModel.PanelX - pointDelta - Yx1;
|
||||
|
||||
if (ellipse.ShowedY % 10 <= ellipseDelta || ellipse.ShowedY % 10 >= 10 - ellipseDelta)
|
||||
ellipse.ShowedY = -(Math.Round((mainViewModel.PanelY - Xy1) / 10) * 10);
|
||||
if (point.ShowedY % 10 <= pointDelta || point.ShowedY % 10 >= 10 - pointDelta)
|
||||
point.ShowedY = -(Math.Round((mainViewModel.PanelY - Xy1) / 10) * 10);
|
||||
else
|
||||
ellipse.ShowedY = -(mainViewModel.PanelY - ellipseDelta - Xy1);
|
||||
point.ShowedY = -(mainViewModel.PanelY - pointDelta - Xy1);
|
||||
}
|
||||
if (ParameterCaptured)
|
||||
{
|
||||
//EllipseParameterX = ellipse.ShowedX;
|
||||
//EllipseParameterY = ellipse.ShowedY;
|
||||
//EllipseParameterSquare = ellipse.Square;
|
||||
//ParameterOpacity = ellipse.ShowedOpacity;
|
||||
//ElementLock = ellipse.ElementLock;
|
||||
//EllipseParameterX = point.ShowedX;
|
||||
//EllipseParameterY = point.ShowedY;
|
||||
//EllipseParameterSquare = point.Square;
|
||||
//ParameterOpacity = point.ShowedOpacity;
|
||||
//ElementLock = point.ElementLock;
|
||||
}
|
||||
});
|
||||
PrimitiveDoubleClick = new RelayCommand(o =>
|
||||
@@ -249,12 +249,12 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
private void UpdateCoordinatesX(double showedX)
|
||||
{
|
||||
if (Type == PrimitiveType.Rectangle) X = showedX + Yx1;
|
||||
if (Type == PrimitiveType.Ellipse) X = showedX + Yx1 - PrimitiveWidth / 2;
|
||||
if (Type == PrimitiveType.Point) X = showedX + Yx1 - PrimitiveWidth / 2;
|
||||
}
|
||||
private void UpdateCoordinatesY(double showedY)
|
||||
{
|
||||
if (Type == PrimitiveType.Rectangle) Y = -showedY + Xy1 - PrimitiveHeight;
|
||||
if (Type == PrimitiveType.Ellipse) Y = -showedY + Xy1 - PrimitiveWidth / 2;
|
||||
if (Type == PrimitiveType.Point) Y = -showedY + Xy1 - PrimitiveWidth / 2;
|
||||
}
|
||||
|
||||
public abstract INdmPrimitive GetNdmPrimitive();
|
||||
@@ -266,7 +266,5 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
else { throw new Exception("MaterialType is unknown"); }
|
||||
return materialTypes;
|
||||
}
|
||||
|
||||
public abstract T MapToShape();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Infrastructure.Enums;
|
||||
using StructureHelper.Windows.MainWindow;
|
||||
using StructureHelperLogics.Data.Shapes;
|
||||
using StructureHelperLogics.NdmCalculations.Entities;
|
||||
using StructureHelperLogics.NdmCalculations.Materials;
|
||||
using RectangleShape = StructureHelperLogics.Data.Shapes.Rectangle;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
{
|
||||
public class Rectangle : PrimitiveBase<RectangleShape>
|
||||
public class Rectangle : PrimitiveBase
|
||||
{
|
||||
public Rectangle(double primitiveWidth, double primitiveHeight, double rectX, double rectY, MainViewModel mainViewModel) : base(PrimitiveType.Rectangle, rectX, rectY, mainViewModel)
|
||||
{
|
||||
@@ -34,8 +30,5 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
INdmPrimitive ndmPrimitive = new NdmPrimitive() { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial };
|
||||
return ndmPrimitive;
|
||||
}
|
||||
|
||||
public override RectangleShape MapToShape()
|
||||
=> new RectangleShape {Height = PrimitiveHeight, Width = PrimitiveWidth};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataTemplates
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace StructureHelper.Infrastructure.UI.DataTemplates
|
||||
{
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
</Border>
|
||||
</local:PrimitivePopup>
|
||||
<!--Ellipse-->
|
||||
<local:PrimitivePopup IsOpen="{Binding ParamsPanelVisibilty}" d:DataContext="{d:DesignInstance dataContexts:Ellipse}" Type="Ellipse">
|
||||
<local:PrimitivePopup IsOpen="{Binding ParamsPanelVisibilty}" d:DataContext="{d:DesignInstance dataContexts:Point}" Type="Ellipse">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseLeave">
|
||||
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SetPopupCanBeClosedTrue}" CommandParameter="{Binding}"/>
|
||||
|
||||
Reference in New Issue
Block a user