Add value diagram windows and view models

This commit is contained in:
Evgeny Redikultsev
2025-11-09 17:34:51 +05:00
parent 111b60a08d
commit 466b47f447
58 changed files with 1397 additions and 162 deletions

View File

@@ -1,7 +1,6 @@
using netDxf;
using netDxf.Entities;
using netDxf.Tables;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Shapes;
using System.Collections.Generic;
@@ -15,19 +14,19 @@ namespace StructureHelperCommon.Services.Exports
}
public class ShapesExportToDxfLogic : IExportToFileLogic
{
private const string ShapeTypeIsUnknown = ": Shape is unknown";
private const double metresToMillimeters = 1000.0;
private readonly List<(IShape shape, LayerNames layerName)> shapes = [];
private IGetDxfLayerLogic layerLogic = new GetDxfLayerLogic();
private IShapeConvertStrategy<EntityObject, IShape> shapeConvertStrategy = new ShapeToDxfEntityConvertStrategy() { Scale = metresToMillimeters};
public List<(IShape shape, LayerNames layerName)> Shapes { get; set; } = [];
public ShapesExportToDxfLogic(List<(IShape shape, LayerNames layerName)> shapes)
{
this.shapes.AddRange(shapes);
this.Shapes.AddRange(shapes);
}
public ShapesExportToDxfLogic(IShape shape, LayerNames layerName)
{
shapes.Add((shape, layerName));
Shapes.Add((shape, layerName));
}
public string FileName { get; set; }
@@ -35,45 +34,14 @@ namespace StructureHelperCommon.Services.Exports
public void Export()
{
DxfDocument dxf = new DxfDocument();
foreach (var shape in shapes)
foreach (var shape in Shapes)
{
ProcessShape(dxf, shape);
Layer layer = layerLogic.GetOrCreateLayer(dxf, shape.layerName);
var entity = shapeConvertStrategy.Convert(shape.shape);
entity.Layer = layer;
dxf.Entities.Add(entity);
}
dxf.Save(FileName);
}
private void ProcessShape(DxfDocument dxf, (IShape shape, LayerNames layerName) shape)
{
Layer layer = layerLogic.GetOrCreateLayer(dxf, shape.layerName);
ProcessShape(dxf, shape.shape, layer);
}
private void ProcessShape(DxfDocument dxf, IShape shape, Layer layer)
{
if (shape is ILinePolygonShape linePolygon)
{
ProcessLinePolygon(dxf, linePolygon, layer);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(shape) + ShapeTypeIsUnknown);
}
}
private void ProcessLinePolygon(DxfDocument dxf, ILinePolygonShape linePolygon, Layer layer)
{
List<Polyline2DVertex> polylineVertices = [];
foreach (var item in linePolygon.Vertices)
{
Polyline2DVertex vertex = new Polyline2DVertex(item.Point.X * metresToMillimeters, item.Point.Y * metresToMillimeters);
polylineVertices.Add(vertex);
}
Polyline2D polyline2D = new Polyline2D(polylineVertices)
{
Layer = layer,
IsClosed = linePolygon.IsClosed,
};
dxf.Entities.Add(polyline2D);
}
}
}