Рефакторинг, добавление моделей примитивов

This commit is contained in:
NickAppLab
2022-07-19 00:01:22 +05:00
parent 02f53bea5c
commit ac40c10bb7
45 changed files with 123 additions and 205 deletions

View File

@@ -2,7 +2,7 @@
{
public enum PrimitiveType
{
Ellipse,
Point,
Rectangle
}
}

View File

@@ -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};
}
}

View File

@@ -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();
}
}

View File

@@ -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};
}
}

View File

@@ -1,5 +1,4 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls;
namespace StructureHelper.Infrastructure.UI.DataTemplates
{

View File

@@ -1,5 +1,4 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls;
namespace StructureHelper.Infrastructure.UI.DataTemplates
{

View File

@@ -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}"/>

View File

@@ -1,5 +1,5 @@
using System.Windows;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Infrastructure.UI.DataContexts;
using System.Windows;
namespace StructureHelper.MaterialCatalogWindow
{

View File

@@ -89,7 +89,7 @@
<Compile Include="Models\Materials\ConcreteDefinition.cs" />
<Compile Include="Infrastructure\NamedList.cs" />
<Compile Include="Models\Materials\MaterialDefinitionBase.cs" />
<Compile Include="Infrastructure\UI\DataContexts\Ellipse.cs" />
<Compile Include="Infrastructure\UI\DataContexts\Point.cs" />
<Compile Include="Infrastructure\UI\DataContexts\PrimitiveBase.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Models\Materials\RebarDefinition.cs" />

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
/// <inheritdoc />
public class Center : ICenter

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
/// <summary>
/// Interface for point of center of some shape

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
public interface ICenterShape
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
public interface ICircle : IShape
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
public interface IPoint : IShape
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
public interface IRectangle : IShape
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
public interface IShape
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
public class Point : IPoint
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Data.Shapes
namespace StructureHelperLogics.Data.Shapes
{
/// <inheritdoc />
public class Rectangle : IRectangle

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Infrastructures.CommonEnums
namespace StructureHelperLogics.Infrastructures.CommonEnums
{
public enum CalcTerms
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Infrastructures.CommonEnums
namespace StructureHelperLogics.Infrastructures.CommonEnums
{
public enum LimitStates
{

View File

@@ -1,15 +1,10 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Models.NdmPrimitives
{
public interface IPrimitive
public interface IPrimitive : ICenterShape
{
ICenter Center { get;}
IShape Shape { get;}
INdmPrimitive GetNdmPrimitive();
}
}

View File

@@ -1,39 +1,19 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Entities;
using StructureHelperLogics.NdmCalculations.Materials;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Models.NdmPrimitives
{
public class PointPrimitive : IPrimitive
public class PointPrimitive : PrimitiveBase<IPoint>, IPoint
{
ICenter _center;
IShape _shape;
public ICenter Center => _center;
public IShape Shape => _shape;
public double Area
{
get
{
IPoint point = _shape as IPoint;
return point.Area;
}
set
{
IPoint point = _shape as IPoint;
point.Area = value;
}
get => _shape.Area;
set => _shape.Area = value;
}
public PointPrimitive(ICenter center, IShape shape)
{
_center = center;
_shape = shape;
}
public INdmPrimitive GetNdmPrimitive()
public PointPrimitive(ICenter center, IPoint shape) : base(center, shape) { }
public override INdmPrimitive GetNdmPrimitive()
{
double strength = 400;
string materialName = "s400";

View File

@@ -0,0 +1,22 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Entities;
namespace StructureHelperLogics.Models.NdmPrimitives
{
public abstract class PrimitiveBase<T> : IPrimitive where T : IShape
{
protected ICenter _center;
protected T _shape;
public ICenter Center => _center;
public IShape Shape => _shape;
public PrimitiveBase(ICenter center, T shape)
{
_center = center;
_shape = shape;
}
public abstract INdmPrimitive GetNdmPrimitive();
}
}

View File

@@ -0,0 +1,31 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Entities;
using StructureHelperLogics.NdmCalculations.Materials;
namespace StructureHelperLogics.Models.NdmPrimitives
{
public class RectanglePrimitive : PrimitiveBase<IRectangle>, IRectangle
{
public RectanglePrimitive(ICenter center, IRectangle shape) : base(center, shape) { }
public double Width => _shape.Width;
public double Height => _shape.Height;
public double Angle => _shape.Angle;
public override INdmPrimitive GetNdmPrimitive()
{
double strength = 400;
string materialName = "s400";
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial() { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = strength }; ;
INdmPrimitive ndmPrimitive = new NdmPrimitive() { Center = _center, Shape = _shape, PrimitiveMaterial = primitiveMaterial };
return ndmPrimitive;
}
private MaterialTypes GetMaterialTypes()
{
return MaterialTypes.Reinforcement;
}
}
}

View File

@@ -1,8 +1,5 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Materials;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Entities
{

View File

@@ -1,8 +1,5 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Materials;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Entities
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Materials
namespace StructureHelperLogics.NdmCalculations.Materials
{
public interface IPrimitiveMaterial
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Materials
namespace StructureHelperLogics.NdmCalculations.Materials
{
public enum MaterialTypes
{

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Materials
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
namespace StructureHelperLogics.NdmCalculations.Triangulations
{
interface IPointTriangulationLogic : ITriangulationLogic
{

View File

@@ -1,7 +1,4 @@
using StructureHelperLogics.Data.Shapes;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
namespace StructureHelperLogics.NdmCalculations.Triangulations
{
public interface IRectangleTriangulationLogic : ITriangulationLogic
{

View File

@@ -1,7 +1,4 @@
using StructureHelperLogics.Data.Shapes;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using LoaderCalculator.Data.Ndms;
using LoaderCalculator.Data.Materials;

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
namespace StructureHelperLogics.NdmCalculations.Triangulations
{
public interface ITriangulationLogicOptions
{

View File

@@ -1,7 +1,4 @@
using StructureHelperLogics.Infrastructures.CommonEnums;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -3,7 +3,6 @@ using LoaderCalculator.Data.Ndms;
using StructureHelperLogics.Data.Shapes;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -1,7 +1,4 @@
using StructureHelperLogics.Data.Shapes;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -2,7 +2,6 @@
using LoaderCalculator.Data.Ndms;
using System;
using System.Collections.Generic;
using System.Text;
using LoaderCalculator.Data.Ndms.Transformations;
namespace StructureHelperLogics.NdmCalculations.Triangulations

View File

@@ -1,8 +1,6 @@
using StructureHelperLogics.Data.Shapes;
using StructureHelperLogics.NdmCalculations.Entities;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using LoaderCalculator.Data.Materials;
using LoaderCalculator.Data.Materials.MaterialBuilders;
using LoaderCalculator.Data.Ndms;

View File

@@ -1,7 +1,4 @@
using StructureHelperLogics.Infrastructures.CommonEnums;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Triangulations
{

View File

@@ -1,5 +1,5 @@
using System.Windows;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Infrastructure.UI.DataContexts;
using System.Windows;
namespace StructureHelper.Windows.ColorPickerWindow
{

View File

@@ -19,7 +19,7 @@
<DataTemplate DataType="{x:Type dataContexts:Rectangle}">
<dataTemplates:RectangleTemplate/>
</DataTemplate>
<DataTemplate DataType="{x:Type dataContexts:Ellipse}">
<DataTemplate DataType="{x:Type dataContexts:Point}">
<dataTemplates:EllipseTemplate/>
</DataTemplate>
</Window.Resources>

View File

@@ -75,23 +75,23 @@ namespace StructureHelper.Windows.MainWindow
}
}
private double ellipseParameterX, ellipseParameterY, ellipseParameterSquare;
private double pointParameterX, pointParameterY, pointParameterSquare;
public double EllipseParameterX
{
get => ellipseParameterX;
set => OnPropertyChanged(value, ref ellipseParameterX);
get => pointParameterX;
set => OnPropertyChanged(value, ref pointParameterX);
}
public double EllipseParameterY
{
get => ellipseParameterY;
set => OnPropertyChanged(value, ref ellipseParameterY);
get => pointParameterY;
set => OnPropertyChanged(value, ref pointParameterY);
}
public double EllipseParameterSquare
{
get => ellipseParameterSquare;
set => OnPropertyChanged(value, ref ellipseParameterSquare);
get => pointParameterSquare;
set => OnPropertyChanged(value, ref pointParameterSquare);
}
private bool elementLock;
public bool ElementLock
@@ -237,10 +237,10 @@ namespace StructureHelper.Windows.MainWindow
rectangle.PrimitiveWidth = RectParameterWidth;
rectangle.PrimitiveHeight = RectParameterHeight;
break;
case Ellipse ellipse:
ellipse.Square = EllipseParameterSquare;
ellipse.ShowedX = EllipseParameterX;
ellipse.ShowedY = EllipseParameterY;
case Point point:
point.Square = EllipseParameterSquare;
point.ShowedX = EllipseParameterX;
point.ShowedY = EllipseParameterY;
break;
}
}
@@ -312,8 +312,8 @@ namespace StructureHelper.Windows.MainWindow
});
AddEllipse = new RelayCommand(o =>
{
var ellipse = new Ellipse(2000, YX1, XY1, this);
Primitives.Add(ellipse);
var point = new Point(2000, YX1, XY1, this);
Primitives.Add(point);
PrimitivesCount = Primitives.Count;
});