initial commit

This commit is contained in:
2026-05-02 01:01:15 +02:00
parent 591399495c
commit fc73ff47ff
945 changed files with 11285 additions and 0 deletions

View 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));
}
}

View 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;
}
}
}

View 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; }
}

View 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);
}

View 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;
}
}
}

View 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);

View 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));
}