Add import primitives to cross-section

This commit is contained in:
Evgeny Redikultsev
2025-11-02 14:07:06 +05:00
parent ba0d3e580b
commit 871be6cb46
14 changed files with 321 additions and 47 deletions

View File

@@ -1,12 +1,6 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes.Logics;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;
namespace StructureHelperCommon.Models.Shapes
{

View File

@@ -15,9 +15,9 @@ namespace StructureHelperCommon.Models.Shapes
/// <inheritdoc />
public Guid Id { get; }
/// <inheritdoc />
public double X { get; set; }
public double X { get; set; } = 0;
/// <inheritdoc />
public double Y { get; set; }
public double Y { get; set; } = 0;
public Point2D(Guid id)
{
@@ -26,6 +26,12 @@ namespace StructureHelperCommon.Models.Shapes
public Point2D() : this(Guid.NewGuid()) { }
public Point2D(double x, double y) : this()
{
X = x;
Y = y;
}
public object Clone()
{
var newItem = new Point2D();

View File

@@ -1,19 +1,27 @@
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using System;
using StructureHelperCommon.Services.Exports.Factories;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace StructureHelperCommon.Services.Exports
{
public class ShapesAllImportFromDxfLogic : IImportFromFileLogic
public class EntitiesImportFromDxfLogic : IImportFromFileLogic
{
public string FileName { get; set; }
public List<EntityObject> Entities { get; set; } = [];
public void Import()
{
string extension = Path.GetExtension(FileName).ToLowerInvariant();
if (extension == ".dxf")
{
GetEntities();
}
}
private void GetEntities()
{
// this check is optional but recommended before loading a DXF file
DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(FileName);

View File

@@ -1,11 +1,6 @@
using netDxf;
using netDxf.Tables;
using StructureHelperCommon.Infrastructures.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Services.Exports
{

View File

@@ -8,6 +8,6 @@ namespace StructureHelperCommon.Services.Exports
{
public interface IImportFromFileLogic : IImportLogic
{
string FileName { get; set; }
string? FileName { get; set; }
}
}

View File

@@ -1,18 +1,25 @@
using netDxf.Entities;
using System.Collections.Generic;
using System.Linq;
namespace StructureHelperCommon.Services.Exports
{
public class SinglePolyline2DImportFromDxfLogic : IImportFromFileLogic
{
public string FileName { get; set; }
public Polyline2D Polyline2D { get; private set; }
public string? FileName { get; set; }
public LayerNames LayerName { get; set; } = LayerNames.StructiralPrimitives;
public List<Polyline2D> Polyline2Ds { get; private set; } = [];
public void Import()
{
var importLogic = new ShapesAllImportFromDxfLogic() { FileName = FileName};
var importLogic = new EntitiesImportFromDxfLogic()
{
FileName = FileName
};
importLogic.Import();
var entities = importLogic.Entities;
Polyline2D = entities.Single(x => x is Polyline2D) as Polyline2D;
string layerName = new GetDxfLayerLogic().GetLayerName(LayerName);
var collection = entities.Where(x => x is Polyline2D && x.Layer.Name == layerName).ToList();
collection.ForEach(x => Polyline2Ds.Add(x as Polyline2D));
}
}
}