using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace OpenNest.Posts.CincinnatiCIFiber
{
///
/// Configuration for the Cincinnati CI Fiber (TF5200 / nLight CLX) post-processor.
/// All layer macro names, header variable names and the material code map are
/// editable so the post can serve other CI Fiber tables, not only the 4020.
///
public class CIFiberPostConfig
{
/// Emitted in the "( CONFIGURATION - ... )" header comment.
[DisplayName("Configuration name")]
public string ConfigurationName { get; set; } = "CI FIBER 8K";
///
/// Decimal places for posted coordinates and header values. The sample
/// machine program posts 3 decimals for inch units.
///
[DisplayName("Posted accuracy")]
public int PostedAccuracy { get; set; } = 3;
/// Value for V.E.UNIT when the nest is in inches.
[DisplayName("Unit code (inches)")]
public int InchUnitCode { get; set; } = 1;
///
/// Value for V.E.UNIT when the nest is in millimeters. The TF5200
/// metric unit code is unconfirmed; adjust if the controller rejects 0.
///
[DisplayName("Unit code (millimeters)")]
public int MetricUnitCode { get; set; } = 0;
/// Emit the V.E.SHEET_WEIGHT header variable (value 0).
[DisplayName("Emit sheet weight")]
public bool EmitSheetWeight { get; set; } = false;
/// Skip contours whose moves are all LayerType.Scribe (marks).
[DisplayName("Skip scribe layer")]
public bool SkipScribe { get; set; } = true;
/// Maximum plate length (X) this configuration drives; 0 disables the check.
[DisplayName("Maximum table X")]
public double MaxTableX { get; set; } = 160.25;
/// Maximum plate width (Y) this configuration drives; 0 disables the check.
[DisplayName("Maximum table Y")]
public double MaxTableY { get; set; } = 81.25;
/// Comment text after the "( PART:" prefix for each part.
[DisplayName("Part comment")]
public string PartComment { get; set; } = "";
/// Skippable global subroutine used to cancel comp / park between features.
[DisplayName("Layer: cancel (L0)")]
public string LayerCancel { get; set; } = "L0";
/// Skippable global subroutine for interior lead-in plus G41.
[DisplayName("Layer: interior leadin (L2)")]
public string LayerInteriorLeadin { get; set; } = "L2";
/// Skippable global subroutine for exterior lead-in plus G42.
[DisplayName("Layer: exterior leadin (L4)")]
public string LayerExteriorLeadin { get; set; } = "L4";
/// Skippable global subroutine that switches the cut layer on.
[DisplayName("Layer: cut on (L6)")]
public string LayerCut { get; set; } = "L6";
/// Skippable global subroutine at the end of each contour (head separation / comp off).
[DisplayName("Layer: cut end (ZHSOFF)")]
public string LayerCutEnd { get; set; } = "ZHSOFF";
/// External program called once at program start.
[DisplayName("Start macro")]
public string ProgramStartMacro { get; set; } = "PROGRAMSTART.NC";
/// External program called after the last sheet.
[DisplayName("End macro")]
public string ProgramEndMacro { get; set; } = "PROGRAMEND.NC";
/// Material name (case-insensitive) to machine material code map for V.E.MATERIAL.
[DisplayName("Material codes")]
public Dictionary MaterialCodes { get; set; } =
new(StringComparer.OrdinalIgnoreCase) { ["Mild Steel"] = "MSN" };
/// Fallback V.E.MATERIAL code when the material name has no mapping.
[DisplayName("Default material code")]
public string DefaultMaterialCode { get; set; } = "MSN";
public string ResolveMaterialCode(string materialName)
{
if (!string.IsNullOrWhiteSpace(materialName)
&& MaterialCodes != null
&& MaterialCodes.TryGetValue(materialName.Trim(), out var code)
&& !string.IsNullOrWhiteSpace(code))
return code;
return DefaultMaterialCode ?? "MSN";
}
///
/// Throws if the plate exceeds the configured table envelope.
/// Zero limits disable the check.
///
public void ValidateTableSize(double lengthX, double widthY)
{
if (MaxTableX > 0 && lengthX > MaxTableX + ToleranceEpsilon)
throw new InvalidOperationException(
$"Plate length {lengthX:0.###} exceeds maximum table X {MaxTableX:0.###}."
);
if (MaxTableY > 0 && widthY > MaxTableY + ToleranceEpsilon)
throw new InvalidOperationException(
$"Plate width {widthY:0.###} exceeds maximum table Y {MaxTableY:0.###}."
);
}
private const double ToleranceEpsilon = 1e-6;
}
}