mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 06:01:06 -04:00
Core only uses System.Drawing.Color, which ships in the shared framework, so the System.Drawing.Common package (Windows-only beyond primitives) was an unneeded dependency of the cross-platform domain library. The desktop app keeps its own reference. CutParameters lives in OpenNest.Core but declared namespace OpenNest.Api, forcing Core and desktop files to import the Api namespace for a Core type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
3.4 KiB
C#
104 lines
3.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using OpenNest.CNC;
|
|
using OpenNest.Converters;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest
|
|
{
|
|
public static class Timing
|
|
{
|
|
public static TimingInfo GetTimingInfo(Program pgm)
|
|
{
|
|
var entities = ConvertProgram.ToGeometry(pgm);
|
|
var shapes = ShapeBuilder.GetShapes(
|
|
entities.Where(entity => entity.Layer != SpecialLayers.Rapid)
|
|
);
|
|
var info = new TimingInfo { PierceCount = shapes.Count };
|
|
|
|
var last = entities[0];
|
|
ProcessEntity(info, last, null);
|
|
|
|
for (int i = 1; i < entities.Count; i++)
|
|
{
|
|
var entity = entities[i];
|
|
ProcessEntity(info, entity, last);
|
|
last = entity;
|
|
}
|
|
|
|
return info;
|
|
}
|
|
|
|
public static TimingInfo GetTimingInfo(Plate plate)
|
|
{
|
|
var info = new TimingInfo();
|
|
var pos = new Vector(0, 0);
|
|
|
|
foreach (var part in plate.Parts)
|
|
{
|
|
var endpt = part.Program.EndPoint() + part.Location;
|
|
info += GetTimingInfo(part.Program);
|
|
info.TravelDistance += pos.DistanceTo(endpt);
|
|
pos = endpt;
|
|
}
|
|
|
|
// D9: once per physical sheet, before the quantity multiply below scales it with
|
|
// everything else cut on that sheet.
|
|
info.ClampRemovalMinutes = plate.ClampRemovalMinutes;
|
|
|
|
info *= plate.Quantity;
|
|
|
|
return info;
|
|
}
|
|
|
|
public static TimingInfo GetTimingInfo(Nest nest)
|
|
{
|
|
var info = new TimingInfo();
|
|
return nest.Plates.Aggregate(info, (current, plate) => current + GetTimingInfo(plate));
|
|
}
|
|
|
|
private static void ProcessEntity(TimingInfo info, Entity entity, Entity lastEntity)
|
|
{
|
|
if (entity.Layer == SpecialLayers.Cut)
|
|
{
|
|
info.CutDistance += entity.Length;
|
|
|
|
if (
|
|
entity.Type == EntityType.Line
|
|
&& lastEntity != null
|
|
&& lastEntity.Type == EntityType.Line
|
|
&& lastEntity.Layer == SpecialLayers.Cut
|
|
)
|
|
info.IntersectionCount++;
|
|
}
|
|
else if (entity.Layer == SpecialLayers.Rapid)
|
|
info.TravelDistance += entity.Length;
|
|
}
|
|
|
|
public static TimeSpan CalculateTime(TimingInfo info, CutParameters cutParams)
|
|
{
|
|
var time = new TimeSpan();
|
|
|
|
switch (cutParams.Units)
|
|
{
|
|
case Units.Inches:
|
|
time += TimeSpan.FromMinutes(info.CutDistance / cutParams.Feedrate);
|
|
time += TimeSpan.FromMinutes(info.TravelDistance / cutParams.RapidTravelRate);
|
|
break;
|
|
|
|
case Units.Millimeters:
|
|
time += TimeSpan.FromSeconds(info.CutDistance / cutParams.Feedrate);
|
|
time += TimeSpan.FromSeconds(info.TravelDistance / cutParams.RapidTravelRate);
|
|
break;
|
|
}
|
|
|
|
time += TimeSpan.FromTicks(info.PierceCount * cutParams.PierceTime.Ticks);
|
|
|
|
// D9: a flat per-removed-clamp time, already in minutes regardless of cutParams.Units.
|
|
time += TimeSpan.FromMinutes(info.ClampRemovalMinutes);
|
|
|
|
return time;
|
|
}
|
|
}
|
|
}
|