initial commit
This commit is contained in:
33
src/TraceCad.Core/Model/ArcEntity.cs
Normal file
33
src/TraceCad.Core/Model/ArcEntity.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using TraceCad.Core.Geometry;
|
||||
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public sealed record ArcEntity(
|
||||
Guid Id,
|
||||
string Layer,
|
||||
Point2 Center,
|
||||
double Radius,
|
||||
double StartAngleDeg,
|
||||
double EndAngleDeg,
|
||||
bool IsClockwise) : Entity(Id, Layer)
|
||||
{
|
||||
public Point2 StartPoint => PointAtAngle(StartAngleDeg);
|
||||
|
||||
public Point2 EndPoint => PointAtAngle(EndAngleDeg);
|
||||
|
||||
public override IEnumerable<Point2> SnapPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return StartPoint;
|
||||
yield return EndPoint;
|
||||
yield return Center;
|
||||
}
|
||||
}
|
||||
|
||||
public Point2 PointAtAngle(double angleDeg)
|
||||
{
|
||||
var radians = angleDeg * Math.PI / 180.0;
|
||||
return new Point2(Center.X + (Math.Cos(radians) * Radius), Center.Y + (Math.Sin(radians) * Radius));
|
||||
}
|
||||
}
|
||||
18
src/TraceCad.Core/Model/CircleEntity.cs
Normal file
18
src/TraceCad.Core/Model/CircleEntity.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using TraceCad.Core.Geometry;
|
||||
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public sealed record CircleEntity(
|
||||
Guid Id,
|
||||
string Layer,
|
||||
Point2 Center,
|
||||
double Radius) : Entity(Id, Layer)
|
||||
{
|
||||
public override IEnumerable<Point2> SnapPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return Center;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/TraceCad.Core/Model/Entity.cs
Normal file
8
src/TraceCad.Core/Model/Entity.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using TraceCad.Core.Geometry;
|
||||
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public abstract record Entity(Guid Id, string Layer)
|
||||
{
|
||||
public abstract IEnumerable<Point2> SnapPoints { get; }
|
||||
}
|
||||
10
src/TraceCad.Core/Model/Layer.cs
Normal file
10
src/TraceCad.Core/Model/Layer.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public sealed record Layer(string Name, bool Visible = true, bool Locked = false, bool Exportable = true)
|
||||
{
|
||||
public static Layer Cut { get; } = new("CUT");
|
||||
public static Layer Construction { get; } = new("CONSTRUCTION", Exportable: false);
|
||||
public static Layer Reference { get; } = new("REFERENCE", Exportable: false);
|
||||
public static Layer Dimensions { get; } = new("DIMENSIONS", Exportable: false);
|
||||
public static Layer Debug { get; } = new("DEBUG", Visible: false, Exportable: false);
|
||||
}
|
||||
21
src/TraceCad.Core/Model/LineEntity.cs
Normal file
21
src/TraceCad.Core/Model/LineEntity.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using TraceCad.Core.Geometry;
|
||||
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public sealed record LineEntity(
|
||||
Guid Id,
|
||||
string Layer,
|
||||
Point2 Start,
|
||||
Point2 End) : Entity(Id, Layer)
|
||||
{
|
||||
public double Length => Start.DistanceTo(End);
|
||||
|
||||
public override IEnumerable<Point2> SnapPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return Start;
|
||||
yield return End;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/TraceCad.Core/Model/ReferenceImage.cs
Normal file
14
src/TraceCad.Core/Model/ReferenceImage.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public sealed record ReferenceTransform(
|
||||
double OriginX,
|
||||
double OriginY,
|
||||
double ScaleX,
|
||||
double ScaleY,
|
||||
double RotationDeg);
|
||||
|
||||
public sealed record ReferenceImage(
|
||||
string ImagePath,
|
||||
double Opacity,
|
||||
bool Locked,
|
||||
ReferenceTransform Transform);
|
||||
59
src/TraceCad.Core/Model/SketchDocument.cs
Normal file
59
src/TraceCad.Core/Model/SketchDocument.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace TraceCad.Core.Model;
|
||||
|
||||
public sealed class SketchDocument
|
||||
{
|
||||
public const int CurrentVersion = 1;
|
||||
|
||||
public int Version { get; set; } = CurrentVersion;
|
||||
|
||||
public string Units { get; set; } = "mm";
|
||||
|
||||
public double Width { get; set; } = 210.0;
|
||||
|
||||
public double Height { get; set; } = 297.0;
|
||||
|
||||
public ReferenceImage? Reference { get; set; }
|
||||
|
||||
public List<Layer> Layers { get; } = new();
|
||||
|
||||
public List<Entity> Entities { get; } = new();
|
||||
|
||||
public static SketchDocument CreateDefault()
|
||||
{
|
||||
var document = new SketchDocument();
|
||||
document.Layers.AddRange(new[]
|
||||
{
|
||||
Layer.Cut,
|
||||
Layer.Construction,
|
||||
Layer.Reference,
|
||||
Layer.Dimensions,
|
||||
Layer.Debug
|
||||
});
|
||||
return document;
|
||||
}
|
||||
|
||||
public void AddEntity(Entity entity)
|
||||
{
|
||||
if (Entities.Any(existing => existing.Id == entity.Id))
|
||||
{
|
||||
throw new InvalidOperationException($"Entity '{entity.Id}' already exists.");
|
||||
}
|
||||
|
||||
Entities.Add(entity);
|
||||
}
|
||||
|
||||
public bool RemoveEntity(Guid id)
|
||||
{
|
||||
var index = Entities.FindIndex(entity => entity.Id == id);
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Entities.RemoveAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Layer? FindLayer(string name) =>
|
||||
Layers.FirstOrDefault(layer => string.Equals(layer.Name, name, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
Reference in New Issue
Block a user