Add value diagram windows and view models
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public interface IPoint2DRange : ISaveable
|
||||
public interface IPoint2DRange : ISaveable, ICloneable
|
||||
{
|
||||
IPoint2D StartPoint { get; set; }
|
||||
IPoint2D EndPoint { get; set; }
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using netDxf;
|
||||
using netDxf.Entities;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes.Logics
|
||||
{
|
||||
public class CircleToDxfCircleConvertStrategy : IShapeConvertStrategy<Circle, ICircleShape>
|
||||
{
|
||||
public double Dx { get; set; } = 0;
|
||||
public double Dy { get; set; } = 0;
|
||||
public double Scale { get; set; } = 1;
|
||||
|
||||
public Circle Convert(ICircleShape source)
|
||||
{
|
||||
Vector3 center = new Vector3() { X = Dx * Scale, Y = Dy * Scale};
|
||||
Circle circle = new Circle()
|
||||
{
|
||||
Radius = source.Diameter / 2 * Scale,
|
||||
Center = center,
|
||||
};
|
||||
return circle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using netDxf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StrMath = StructureMath.Geometry.Points;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class GetPointListByRange : IGetPointListByRange
|
||||
{
|
||||
public int StepNumber { get; set; } = 50;
|
||||
|
||||
public List<IPoint2D> GetPoints(IPoint2DRange range)
|
||||
{
|
||||
StrMath.Point2D StartPoint2D = new(range.StartPoint.X, range.StartPoint.Y);
|
||||
StrMath.Point2D EndPoint2D = new(range.EndPoint.X, range.EndPoint.Y);
|
||||
StrMath.PointRange pointRange = new() { StartPoint = StartPoint2D, EndPoint = EndPoint2D };
|
||||
var logic = new StrMath.PointRangeInterpolate() { DivisionNumber = StepNumber };
|
||||
var pointList = logic.InterpolateRange(pointRange);
|
||||
List<IPoint2D> result = [];
|
||||
foreach (var point in pointList)
|
||||
{
|
||||
result.Add(new Point2D(point.X, point.Y));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public interface IGetPointListByRange
|
||||
{
|
||||
int StepNumber { get; set; }
|
||||
List<IPoint2D> GetPoints(IPoint2DRange range);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public interface IShapeConvertStrategy<T, V> : IObjectConvertStrategy<T, V>
|
||||
{
|
||||
double Dx { get; set; }
|
||||
double Dy { get; set; }
|
||||
double Scale { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using netDxf.Entities;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class LinePolygonToPolyline2DConvertStrategy : IObjectConvertStrategy<Polyline2D, ILinePolygonShape>
|
||||
{
|
||||
public double Dx { get; set; } = 0;
|
||||
public double Dy { get; set; } = 0;
|
||||
public double Scale { get; set; } = 1;
|
||||
|
||||
public Polyline2D Convert(ILinePolygonShape linePolygon)
|
||||
{
|
||||
List<Polyline2DVertex> polylineVertices = [];
|
||||
foreach (var item in linePolygon.Vertices)
|
||||
{
|
||||
Polyline2DVertex vertex = new Polyline2DVertex((item.Point.X + Dx) * Scale, (item.Point.Y + Dy) * Scale);
|
||||
polylineVertices.Add(vertex);
|
||||
}
|
||||
Polyline2D polyline2D = new Polyline2D(polylineVertices)
|
||||
{
|
||||
IsClosed = linePolygon.IsClosed,
|
||||
};
|
||||
return polyline2D;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Services;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class Point2DRangeUpdateStrategy : IUpdateStrategy<IPoint2DRange>
|
||||
{
|
||||
private IUpdateStrategy<IPoint2D> pointUpdateStrategy;
|
||||
public void Update(IPoint2DRange targetObject, IPoint2DRange sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(targetObject, sourceObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
CheckObject.IsNull(targetObject.StartPoint, ": range start point");
|
||||
pointUpdateStrategy ??= new Point2DUpdateStrategy();
|
||||
pointUpdateStrategy.Update(targetObject.StartPoint, sourceObject.StartPoint);
|
||||
CheckObject.IsNull(targetObject.EndPoint, ": range end point");
|
||||
pointUpdateStrategy.Update(targetObject.EndPoint, sourceObject.EndPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class RectangleToLinePolygonConvertStrategy : IShapeConvertStrategy<LinePolygonShape, IRectangleShape>
|
||||
{
|
||||
private IRectangleShape rectangle;
|
||||
|
||||
public double Dx { get; set; } = 0.0;
|
||||
public double Dy { get; set; } = 0.0;
|
||||
public double Scale { get; set; } = 1.0;
|
||||
|
||||
|
||||
public LinePolygonShape Convert(IRectangleShape source)
|
||||
{
|
||||
rectangle = source;
|
||||
LinePolygonShape polygon = new(Guid.NewGuid());
|
||||
polygon.AddVertex(GetVertex(-1.0, 1.0));
|
||||
polygon.AddVertex(GetVertex(1.0, 1.0));
|
||||
polygon.AddVertex(GetVertex(1.0, -1.0));
|
||||
polygon.AddVertex(GetVertex(-1.0, -1.0));
|
||||
polygon.IsClosed = true;
|
||||
return polygon;
|
||||
}
|
||||
|
||||
private Vertex GetVertex(double kx, double ky)
|
||||
{
|
||||
double x = (kx * rectangle.Width / 2 + Dx) * Scale;
|
||||
double y = (ky * rectangle.Height / 2 + Dy) * Scale;
|
||||
return new(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using netDxf.Entities;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Shapes.Logics;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class ShapeToDxfEntityConvertStrategy : IShapeConvertStrategy<EntityObject, IShape>
|
||||
{
|
||||
private const string ShapeTypeIsUnknown = ": Shape is unknown";
|
||||
public double Dx { get; set; } = 0.0;
|
||||
public double Dy { get; set; } = 0.0;
|
||||
public double Scale { get; set; } = 1.0;
|
||||
|
||||
public EntityObject Convert(IShape source)
|
||||
{
|
||||
if (source is IRectangleShape rectangle)
|
||||
{
|
||||
var retangleConvertStrategy = new RectangleToLinePolygonConvertStrategy();
|
||||
var polyline2D = Convert(retangleConvertStrategy.Convert(rectangle));
|
||||
return polyline2D;
|
||||
}
|
||||
else if (source is ICircleShape circle)
|
||||
{
|
||||
var circleConvertStrategy = new CircleToDxfCircleConvertStrategy() { Dx = Dx, Dy = Dy, Scale = Scale };
|
||||
var circleEntity = circleConvertStrategy.Convert(circle);
|
||||
return circleEntity;
|
||||
}
|
||||
else if (source is ILinePolygonShape linePolygon)
|
||||
{
|
||||
var polygonConvertStrategy = new LinePolygonToPolyline2DConvertStrategy() { Dx = Dx, Dy = Dy, Scale = Scale };
|
||||
Polyline2D polyline2D = polygonConvertStrategy.Convert(linePolygon);
|
||||
return polyline2D;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(source) + ShapeTypeIsUnknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,13 @@ namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
Point2DRange newItem = new(Guid.NewGuid());
|
||||
var updateStrategy = new Point2DRangeUpdateStrategy();
|
||||
updateStrategy.Update(newItem, this);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
<Reference Include="LoaderCalculator">
|
||||
<HintPath>..\StructureHelper\Libraries\LoaderCalculator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StructureMath">
|
||||
<HintPath>..\StructureHelper\Libraries\StructureMath.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user