Add value diagram windows and view models
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using netDxf;
|
||||
using netDxf.Entities;
|
||||
using netDxf.Tables;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Services.Exports
|
||||
{
|
||||
public class EntitiesToDxfExportLogic : IExportToFileLogic
|
||||
{
|
||||
private const double metresToMillimeters = 1000.0;
|
||||
private IGetDxfLayerLogic layerLogic = new GetDxfLayerLogic();
|
||||
public List<(EntityObject entity, LayerNames layerName)> Entities { get; set; } = [];
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
public void Export()
|
||||
{
|
||||
DxfDocument dxf = new DxfDocument();
|
||||
foreach (var shape in Entities)
|
||||
{
|
||||
Layer layer = layerLogic.GetOrCreateLayer(dxf, shape.layerName);
|
||||
var entity = shape.entity;
|
||||
entity.Layer = layer;
|
||||
dxf.Entities.Add(entity);
|
||||
}
|
||||
dxf.Save(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user