Add polygon to DTO convert strategy

This commit is contained in:
Evgeny Redikultsev
2025-10-19 17:37:17 +05:00
parent 5bf01bcb09
commit ed66da123c
64 changed files with 759 additions and 266 deletions

View File

@@ -70,7 +70,7 @@ namespace DataAccess.DTOs
private EllipseNdmPrimitiveDTO GetNewPrimitive(IEllipseNdmPrimitive source)
{
EllipseNdmPrimitiveDTO newItem = new() { Id = source.Id };
EllipseNdmPrimitiveDTO newItem = new(source.Id);
updateStrategy.Update(newItem, source);
newItem.NdmElement = ndmElementConvertStrategy.Convert(source.NdmElement);
newItem.RectangleShape = rectangleShapeConvertStrategy.Convert(source.Shape as IRectangleShape);

View File

@@ -55,8 +55,11 @@ namespace DataAccess.DTOs
headMaterialConvertStrategy.ReferenceDictionary = ReferenceDictionary;
headMaterialConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<HeadMaterialDTO, IHeadMaterial>(this, headMaterialConvertStrategy);
var headMaterial = convertLogic.Convert(source.HeadMaterial);
newItem.HeadMaterial = headMaterial;
if (source.HeadMaterial != null)
{
var headMaterial = convertLogic.Convert(source.HeadMaterial);
newItem.HeadMaterial = headMaterial;
}
forceUpdateStrategy.Update(newItem.UsersPrestrain, source.UsersPrestrain);
(newItem.UsersPrestrain as ForceTupleDTO).Id = source.UsersPrestrain.Id;
forceUpdateStrategy.Update(newItem.AutoPrestrain, source.AutoPrestrain);

View File

@@ -11,6 +11,7 @@ namespace DataAccess.DTOs.Converters
private readonly IConvertStrategy<PointNdmPrimitiveDTO, IPointNdmPrimitive> pointConvertStrategy;
private readonly IConvertStrategy<EllipseNdmPrimitiveDTO, IEllipseNdmPrimitive> ellipseConvertStrategy;
private readonly IConvertStrategy<RectangleNdmPrimitiveDTO, IRectangleNdmPrimitive> rectangleConvertStrategy;
private IConvertStrategy<ShapeNdmPrimitiveDTO, IShapeNdmPrimitive> shapeConvertStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
@@ -55,10 +56,21 @@ namespace DataAccess.DTOs.Converters
{
return ProcessRectangle(rectangle);
}
if (source is IShapeNdmPrimitive shape)
{
return ProcessShape(shape);
}
TraceLogger.AddMessage("Object type is unknown", TraceLogStatuses.Error);
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source));
}
private ShapeNdmPrimitiveDTO ProcessShape(IShapeNdmPrimitive shape)
{
shapeConvertStrategy = new DictionaryConvertStrategy<ShapeNdmPrimitiveDTO,IShapeNdmPrimitive>(this, new ShapeNdmPrimitiveToDTOConvertStrategy(this));
ShapeNdmPrimitiveDTO shapeNdmPrimitiveDTO = shapeConvertStrategy.Convert(shape);
return shapeNdmPrimitiveDTO;
}
private RebarNdmPrimitiveDTO ProcessRebar(IRebarNdmPrimitive rebar)
{
rebarConvertStrategy.ReferenceDictionary = ReferenceDictionary;

View File

@@ -0,0 +1,50 @@
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.NdmCalculations.Primitives;
namespace DataAccess.DTOs
{
public class ShapeNdmPrimitiveToDTOConvertStrategy : ConvertStrategy<ShapeNdmPrimitiveDTO, IShapeNdmPrimitive>
{
private IUpdateStrategy<IShapeNdmPrimitive> updateStrategy;
private IConvertStrategy<IShape, IShape> shapeConvertStrategy;
private IConvertStrategy<NdmElementDTO, INdmElement> ndmElementConvertStrategy;
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
private IConvertStrategy<VisualPropertyDTO, IVisualProperty> visualPropsConvertStrategy;
private IConvertStrategy<DivisionSizeDTO, IDivisionSize> divisionConvertStrategy;
public ShapeNdmPrimitiveToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override ShapeNdmPrimitiveDTO GetNewItem(IShapeNdmPrimitive source)
{
ChildClass = this;
NewItem = new(source.Id);
InitializeStrategies();
updateStrategy.Update(NewItem, source);
updateChildProperties(source);
return NewItem;
}
private void updateChildProperties(IShapeNdmPrimitive source)
{
NewItem.SetShape(shapeConvertStrategy.Convert(source.Shape));
NewItem.NdmElement = ndmElementConvertStrategy.Convert(source.NdmElement);
NewItem.Center = pointConvertStrategy.Convert(source.Center);
NewItem.VisualProperty = visualPropsConvertStrategy.Convert(source.VisualProperty);
NewItem.DivisionSize = divisionConvertStrategy.Convert(source.DivisionSize);
}
private void InitializeStrategies()
{
updateStrategy = new ShapeNdmPrimitiveUpdateStrategy() { UpdateChildren = false };
shapeConvertStrategy = new DictionaryConvertStrategy<IShape, IShape>(this, new ShapeToDTOConvertStrategy(this));
ndmElementConvertStrategy = new NdmElementToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
pointConvertStrategy = new Point2DToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
visualPropsConvertStrategy = new VisualPropertyToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
divisionConvertStrategy = new DivisionSizeToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger };
}
}
}

View File

@@ -0,0 +1,36 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class LinePolygonToDTOConvertStrategy : ConvertStrategy<LinePolygonShapeDTO, ILinePolygonShape>
{
private IUpdateStrategy<ILinePolygonShape> updateStrategy;
private IConvertStrategy<VertexDTO, IVertex> vertexConvertStrategy;
public LinePolygonToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override LinePolygonShapeDTO GetNewItem(ILinePolygonShape source)
{
ChildClass = this;
NewItem = new(source.Id);
updateStrategy = new LinePolygonShapeUpdateStrategy() { UpdateChildren = false };
vertexConvertStrategy = new VertexToDTOConvertStrategy(this);
updateStrategy.Update(NewItem, source);
NewItem.Clear();
foreach (var item in source.Vertices)
{
VertexDTO newVertex = vertexConvertStrategy.Convert(item);
NewItem.AddVertex(newVertex);
}
return NewItem;
}
}
}

View File

@@ -9,6 +9,7 @@ namespace DataAccess.DTOs
{
private IConvertStrategy<RectangleShapeDTO, IRectangleShape> rectangleConvertStrategy;
private IConvertStrategy<CircleShapeDTO, ICircleShape> circleConvertStrategy;
private IConvertStrategy<LinePolygonShapeDTO, ILinePolygonShape> linePolygonToDTOConvertStrategy;
public ShapeToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
@@ -32,6 +33,10 @@ namespace DataAccess.DTOs
{
ProcessCircle(circle);
}
else if (source is ILinePolygonShape linePolygon)
{
ProcessLinePolygon(linePolygon);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source) + ": shape type";
@@ -40,6 +45,13 @@ namespace DataAccess.DTOs
TraceLogger?.AddMessage($"Shape converting Id = {NewItem.Id} has been has been finished successfully", TraceLogStatuses.Debug);
}
private void ProcessLinePolygon(ILinePolygonShape linePolygon)
{
TraceLogger?.AddMessage($"Shape is line polygon", TraceLogStatuses.Debug);
linePolygonToDTOConvertStrategy = new DictionaryConvertStrategy<LinePolygonShapeDTO, ILinePolygonShape>(this, new LinePolygonToDTOConvertStrategy(this));
NewItem = linePolygonToDTOConvertStrategy.Convert(linePolygon);
}
private void ProcessCircle(ICircleShape circle)
{
TraceLogger?.AddMessage($"Shape is circle", TraceLogStatuses.Debug);

View File

@@ -0,0 +1,26 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
namespace DataAccess.DTOs
{
public class VertexToDTOConvertStrategy : ConvertStrategy<VertexDTO, IVertex>
{
private IUpdateStrategy<IVertex> updateStrategy;
private IConvertStrategy<Point2DDTO, IPoint2D> pointConvertStrategy;
public VertexToDTOConvertStrategy(IBaseConvertStrategy baseConvertStrategy) : base(baseConvertStrategy)
{
}
public override VertexDTO GetNewItem(IVertex source)
{
ChildClass = this;
NewItem = new(source.Id);
updateStrategy = new VertexUpdateStrategy() { UpdateChildren = false };
pointConvertStrategy = new Point2DToDTOConvertStrategy() { ReferenceDictionary = ReferenceDictionary, TraceLogger = TraceLogger};
updateStrategy.Update(NewItem, source);
NewItem.Point = pointConvertStrategy.Convert(source.Point);
return NewItem;
}
}
}

View File

@@ -2,13 +2,8 @@
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
namespace DataAccess.DTOs
{
public class VisualPropertyToDTOConvertStrategy : IConvertStrategy<VisualPropertyDTO, IVisualProperty>
{