Add logic for export to DXF
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using StructureHelper.Windows.Errors;
|
||||
using StructureHelper.Windows.ViewModels.Errors;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Services.Exports;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using System;
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
using netDxf;
|
||||
using netDxf.Entities;
|
||||
using netDxf.Header;
|
||||
using netDxf.Tables;
|
||||
using StructureHelper.Infrastructure;
|
||||
using StructureHelper.Infrastructure.UI.GraphicalPrimitives;
|
||||
using StructureHelper.Services.Exports;
|
||||
using StructureHelper.Windows.BeamShears;
|
||||
using StructureHelper.Windows.Shapes.Logics;
|
||||
using StructureHelper.Windows.UserControls.WorkPlanes;
|
||||
using StructureHelper.Windows.ViewModels;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Services.Exports;
|
||||
using StructureHelperLogics.Models.BeamShears;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -21,6 +25,7 @@ namespace StructureHelper.Windows.Shapes
|
||||
public class PolygonShapeViewModel : OkCancelViewModelBase
|
||||
{
|
||||
private const int minVertexCount = 3;
|
||||
|
||||
private readonly IPoint2D absoluteCenter;
|
||||
private readonly IPoint2D localCenter;
|
||||
private readonly ILinePolygonShape polygonShape;
|
||||
@@ -76,24 +81,14 @@ namespace StructureHelper.Windows.Shapes
|
||||
|
||||
private void ExportToDxf(object commandParameter)
|
||||
{
|
||||
// your DXF file name
|
||||
string file = "sample.dxf";
|
||||
|
||||
// create a new document, by default it will create an AutoCad2000 DXF version
|
||||
DxfDocument doc = new DxfDocument();
|
||||
// an entity
|
||||
List<Polyline2DVertex> polylineVertices = [];
|
||||
foreach (var item in vertices)
|
||||
var inputData = new ExportToFileInputData
|
||||
{
|
||||
Polyline2DVertex vertex = new Polyline2DVertex(item.Point.X, item.Point.Y);
|
||||
polylineVertices.Add(vertex);
|
||||
}
|
||||
Polyline2D polyline2D = new Polyline2D(polylineVertices) { IsClosed = true};
|
||||
//polyline2D.Layer =
|
||||
// add your entities here
|
||||
doc.Entities.Add(polyline2D);
|
||||
// save to file
|
||||
doc.Save(file);
|
||||
Filter = "dxf |*.dxf",
|
||||
Title = "Save in *.dxf File"
|
||||
};
|
||||
var logic = new ShapesExportToDxfLogic(polygonShape, LayerNames.StructiralPrimitives);
|
||||
var exportService = new ExportToFileService(inputData, logic);
|
||||
exportService.Export();
|
||||
}
|
||||
|
||||
private void FlipHorizontal(object obj)
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
namespace StructureHelperCommon.Services.Exports
|
||||
{
|
||||
public interface IExportResultLogic
|
||||
{
|
||||
129
StructureHelperCommon/Services/Exports/ShapesExportToDxfLogic.cs
Normal file
129
StructureHelperCommon/Services/Exports/ShapesExportToDxfLogic.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using netDxf;
|
||||
using netDxf.Entities;
|
||||
using netDxf.Tables;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
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 enum LayerNames
|
||||
{
|
||||
StructiralPrimitives,
|
||||
StructuralOpenings,
|
||||
StructuralRebars
|
||||
}
|
||||
public class ShapesExportToDxfLogic : IExportResultLogic
|
||||
{
|
||||
private const string PrimitivesLayer = "STR-PRM";
|
||||
private const string OpeningsLayer = "STR-OPN";
|
||||
private const string RebarLayer = "STR-REB";
|
||||
private const string LayerNameIsUnKnown = ": Layer name is unknown";
|
||||
private const string ShapeTypeIsUnknown = ": Shape is unknown";
|
||||
private readonly List<(IShape shape, LayerNames layerName)> shapes = [];
|
||||
|
||||
public ShapesExportToDxfLogic(List<(IShape shape, LayerNames layerName)> shapes)
|
||||
{
|
||||
this.shapes.AddRange(shapes);
|
||||
}
|
||||
|
||||
public ShapesExportToDxfLogic(IShape shape, LayerNames layerName)
|
||||
{
|
||||
shapes.Add((shape, layerName));
|
||||
}
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
public void Export()
|
||||
{
|
||||
DxfDocument dxf = new DxfDocument();
|
||||
foreach (var shape in shapes)
|
||||
{
|
||||
ProcessShape(dxf, shape);
|
||||
}
|
||||
Layer primitiveLayer = new Layer(PrimitivesLayer)
|
||||
{
|
||||
Color = AciColor.Blue
|
||||
};
|
||||
dxf.Layers.Add(primitiveLayer);
|
||||
|
||||
// save to file
|
||||
dxf.Save(FileName);
|
||||
}
|
||||
|
||||
private void ProcessShape(DxfDocument dxf, (IShape shape, LayerNames layerName) shape)
|
||||
{
|
||||
Layer layer = 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, item.Point.Y);
|
||||
polylineVertices.Add(vertex);
|
||||
}
|
||||
Polyline2D polyline2D = new Polyline2D(polylineVertices)
|
||||
{
|
||||
Layer = layer,
|
||||
IsClosed = linePolygon.IsClosed,
|
||||
};
|
||||
dxf.Entities.Add(polyline2D);
|
||||
}
|
||||
|
||||
private Layer GetOrCreateLayer(DxfDocument dxf, LayerNames layerName)
|
||||
{
|
||||
string newLayerName = GetLayerName(layerName);
|
||||
Layer newLayer = dxf.Layers.Contains("newLayerName")
|
||||
? dxf.Layers["newLayerName"]
|
||||
: new Layer("newLayerName")
|
||||
{
|
||||
Color = GetLayerColor(layerName)
|
||||
};
|
||||
|
||||
if (!dxf.Layers.Contains(newLayerName))
|
||||
dxf.Layers.Add(newLayer);
|
||||
return newLayer;
|
||||
}
|
||||
|
||||
private string GetLayerName(LayerNames layerName)
|
||||
{
|
||||
if (layerName == LayerNames.StructiralPrimitives) { return PrimitivesLayer; }
|
||||
else if (layerName == LayerNames.StructuralOpenings) { return OpeningsLayer; }
|
||||
else if (layerName == LayerNames.StructuralRebars) { return RebarLayer; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
||||
}
|
||||
}
|
||||
|
||||
private AciColor GetLayerColor(LayerNames layerName)
|
||||
{
|
||||
if (layerName == LayerNames.StructiralPrimitives) { return AciColor.Blue; }
|
||||
else if (layerName == LayerNames.StructuralOpenings) { return AciColor.DarkGray; }
|
||||
else if (layerName == LayerNames.StructuralRebars) { return AciColor.Magenta; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ExcelDataReader" Version="3.8.0" />
|
||||
<PackageReference Include="netDxf" Version="2023.11.10" />
|
||||
<PackageReference Include="NLog" Version="6.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StructureHelperCommon.Services.Exports;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
{
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperCommon.Services.Exports;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.Geometry;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StructureHelperCommon.Services.Exports;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using StructureHelperCommon.Services.Exports;
|
||||
using System.Text;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user