style: apply CSharpier formatting to all C# sources
Repo-wide sweep with the pinned CSharpier 1.3.0 tool. Whitespace and line-wrapping only; OpenNest.Engine.Tests (109) and OpenNest.IO.Tests pass after reformat, full solution builds 0 errors. Added .csharpierignore so csproj/config XML keeps its existing layout (CSharpier's XML wrapping churns attributes with zero benefit). Formatting is now enforceable: dotnet csharpier check . passes.
This commit is contained in:
@@ -9,12 +9,15 @@ using OpenNest.CNC;
|
||||
|
||||
namespace OpenNest.Posts.Cincinnati
|
||||
{
|
||||
public sealed class CincinnatiPostProcessor : IConfigurablePostProcessor, IPostProcessorNestAware, IMaterialProvidingPostProcessor
|
||||
public sealed class CincinnatiPostProcessor
|
||||
: IConfigurablePostProcessor,
|
||||
IPostProcessorNestAware,
|
||||
IMaterialProvidingPostProcessor
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
Converters = { new JsonStringEnumConverter() },
|
||||
};
|
||||
|
||||
public string Name => "Cincinnati CL-707";
|
||||
@@ -30,8 +33,8 @@ namespace OpenNest.Posts.Cincinnati
|
||||
if (Config?.MaterialLibraries == null)
|
||||
return System.Array.Empty<string>();
|
||||
|
||||
return Config.MaterialLibraries
|
||||
.Select(e => e.Material)
|
||||
return Config
|
||||
.MaterialLibraries.Select(e => e.Material)
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s));
|
||||
}
|
||||
|
||||
@@ -83,9 +86,7 @@ namespace OpenNest.Posts.Cincinnati
|
||||
var vars = CreateVariableManager();
|
||||
|
||||
// 2. Filter to non-empty plates
|
||||
var plates = nest.Plates
|
||||
.Where(p => p.Parts.Count > 0)
|
||||
.ToList();
|
||||
var plates = nest.Plates.Where(p => p.Parts.Count > 0).ToList();
|
||||
|
||||
// 3. Register user variables from drawing programs
|
||||
var userVarMapping = RegisterUserVariables(vars, plates);
|
||||
@@ -97,36 +98,55 @@ namespace OpenNest.Posts.Cincinnati
|
||||
|
||||
// Resolve cut library from nest material/thickness for preamble
|
||||
var firstPlate = plates.FirstOrDefault();
|
||||
var initialCutLibrary = resolver.ResolveCutLibrary(nest.Material?.Name ?? "", nest.Thickness, gas);
|
||||
var initialCutLibrary = resolver.ResolveCutLibrary(
|
||||
nest.Material?.Name ?? "",
|
||||
nest.Thickness,
|
||||
gas
|
||||
);
|
||||
|
||||
// 5. Build part sub-program registry (if enabled)
|
||||
Dictionary<(int, long), int> partSubprograms = null;
|
||||
List<(int subNum, string name, Program program)> subprogramEntries = null;
|
||||
|
||||
if (Config.UsePartSubprograms)
|
||||
(partSubprograms, subprogramEntries) = CincinnatiPartSubprogramWriter.BuildRegistry(plates, Config.PartSubprogramStart);
|
||||
(partSubprograms, subprogramEntries) = CincinnatiPartSubprogramWriter.BuildRegistry(
|
||||
plates,
|
||||
Config.PartSubprogramStart
|
||||
);
|
||||
|
||||
// 5b. Build hole sub-program registry (SubProgramCalls across all parts)
|
||||
var holeStartNumber = Config.PartSubprogramStart
|
||||
+ (subprogramEntries?.Count ?? 0);
|
||||
var (holeMapping, holeEntries) = CincinnatiPartSubprogramWriter.BuildHoleRegistry(plates, holeStartNumber);
|
||||
var holeStartNumber = Config.PartSubprogramStart + (subprogramEntries?.Count ?? 0);
|
||||
var (holeMapping, holeEntries) = CincinnatiPartSubprogramWriter.BuildHoleRegistry(
|
||||
plates,
|
||||
holeStartNumber
|
||||
);
|
||||
|
||||
// 6. Create writers
|
||||
var preamble = new CincinnatiPreambleWriter(Config);
|
||||
var sheetWriter = new CincinnatiSheetWriter(Config, vars,
|
||||
holeMapping.Count > 0 ? holeMapping : null);
|
||||
var sheetWriter = new CincinnatiSheetWriter(
|
||||
Config,
|
||||
vars,
|
||||
holeMapping.Count > 0 ? holeMapping : null
|
||||
);
|
||||
|
||||
// 7. Build material description from nest
|
||||
var material = nest.Material;
|
||||
var materialDesc = material != null
|
||||
? $"{material.Name}{(string.IsNullOrEmpty(material.Grade) ? "" : $", {material.Grade}")}"
|
||||
: "";
|
||||
var materialDesc =
|
||||
material != null
|
||||
? $"{material.Name}{(string.IsNullOrEmpty(material.Grade) ? "" : $", {material.Grade}")}"
|
||||
: "";
|
||||
|
||||
// 8. Write to stream
|
||||
using var writer = new StreamWriter(outputStream, Encoding.UTF8, 1024, leaveOpen: true);
|
||||
|
||||
// Main program
|
||||
preamble.WriteMainProgram(writer, nest.Name ?? "NEST", materialDesc, plates, initialCutLibrary);
|
||||
preamble.WriteMainProgram(
|
||||
writer,
|
||||
nest.Name ?? "NEST",
|
||||
materialDesc,
|
||||
plates,
|
||||
initialCutLibrary
|
||||
);
|
||||
|
||||
// Variable declaration subprogram
|
||||
preamble.WriteVariableDeclaration(writer, vars);
|
||||
@@ -137,25 +157,50 @@ namespace OpenNest.Posts.Cincinnati
|
||||
var plate = plates[i];
|
||||
var layoutIndex = i + 1;
|
||||
var subNumber = Config.SheetSubprogramStart + i;
|
||||
var cutLibrary = resolver.ResolveCutLibrary(nest.Material?.Name ?? "", nest.Thickness, gas);
|
||||
sheetWriter.Write(writer, plate, nest.Name ?? "NEST", layoutIndex, subNumber,
|
||||
cutLibrary, etchLibrary, partSubprograms, userVarMapping);
|
||||
var cutLibrary = resolver.ResolveCutLibrary(
|
||||
nest.Material?.Name ?? "",
|
||||
nest.Thickness,
|
||||
gas
|
||||
);
|
||||
sheetWriter.Write(
|
||||
writer,
|
||||
plate,
|
||||
nest.Name ?? "NEST",
|
||||
layoutIndex,
|
||||
subNumber,
|
||||
cutLibrary,
|
||||
etchLibrary,
|
||||
partSubprograms,
|
||||
userVarMapping
|
||||
);
|
||||
}
|
||||
|
||||
// Part sub-programs (if enabled)
|
||||
if (subprogramEntries != null)
|
||||
{
|
||||
var partSubWriter = new CincinnatiPartSubprogramWriter(Config,
|
||||
holeMapping.Count > 0 ? holeMapping : null);
|
||||
var sheetDiagonal = firstPlate != null
|
||||
? System.Math.Sqrt(firstPlate.Size.Width * firstPlate.Size.Width
|
||||
+ firstPlate.Size.Length * firstPlate.Size.Length)
|
||||
: 100.0;
|
||||
var partSubWriter = new CincinnatiPartSubprogramWriter(
|
||||
Config,
|
||||
holeMapping.Count > 0 ? holeMapping : null
|
||||
);
|
||||
var sheetDiagonal =
|
||||
firstPlate != null
|
||||
? System.Math.Sqrt(
|
||||
firstPlate.Size.Width * firstPlate.Size.Width
|
||||
+ firstPlate.Size.Length * firstPlate.Size.Length
|
||||
)
|
||||
: 100.0;
|
||||
|
||||
foreach (var (subNum, name, pgm) in subprogramEntries)
|
||||
{
|
||||
partSubWriter.Write(writer, pgm, name, subNum,
|
||||
initialCutLibrary, etchLibrary, sheetDiagonal);
|
||||
partSubWriter.Write(
|
||||
writer,
|
||||
pgm,
|
||||
name,
|
||||
subNum,
|
||||
initialCutLibrary,
|
||||
etchLibrary,
|
||||
sheetDiagonal
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,16 +208,26 @@ namespace OpenNest.Posts.Cincinnati
|
||||
if (holeEntries.Count > 0)
|
||||
{
|
||||
var holeSubWriter = new CincinnatiPartSubprogramWriter(Config);
|
||||
var sheetDiagonal = firstPlate != null
|
||||
? System.Math.Sqrt(firstPlate.Size.Width * firstPlate.Size.Width
|
||||
+ firstPlate.Size.Length * firstPlate.Size.Length)
|
||||
: 100.0;
|
||||
var sheetDiagonal =
|
||||
firstPlate != null
|
||||
? System.Math.Sqrt(
|
||||
firstPlate.Size.Width * firstPlate.Size.Width
|
||||
+ firstPlate.Size.Length * firstPlate.Size.Length
|
||||
)
|
||||
: 100.0;
|
||||
|
||||
foreach (var (subNum, pgm) in holeEntries)
|
||||
{
|
||||
CincinnatiPartSubprogramWriter.EnsureLeadingRapid(pgm);
|
||||
holeSubWriter.Write(writer, pgm, "HOLE", subNum,
|
||||
initialCutLibrary, etchLibrary, sheetDiagonal);
|
||||
holeSubWriter.Write(
|
||||
writer,
|
||||
pgm,
|
||||
"HOLE",
|
||||
subNum,
|
||||
initialCutLibrary,
|
||||
etchLibrary,
|
||||
sheetDiagonal
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,13 +241,17 @@ namespace OpenNest.Posts.Cincinnati
|
||||
}
|
||||
|
||||
private Dictionary<(int drawingId, string varName), int> RegisterUserVariables(
|
||||
ProgramVariableManager vars, List<Plate> plates)
|
||||
ProgramVariableManager vars,
|
||||
List<Plate> plates
|
||||
)
|
||||
{
|
||||
var mapping = new Dictionary<(int drawingId, string varName), int>();
|
||||
var nextNumber = Config.UserVariableStart;
|
||||
|
||||
// Track global variables by name so they share a single number
|
||||
var globalNumbers = new Dictionary<string, int>(System.StringComparer.OrdinalIgnoreCase);
|
||||
var globalNumbers = new Dictionary<string, int>(
|
||||
System.StringComparer.OrdinalIgnoreCase
|
||||
);
|
||||
|
||||
// Collect unique drawings from all plates
|
||||
var seenDrawings = new HashSet<int>();
|
||||
@@ -285,19 +344,31 @@ namespace OpenNest.Posts.Cincinnati
|
||||
private ProgramVariableManager CreateVariableManager()
|
||||
{
|
||||
var vars = new ProgramVariableManager();
|
||||
vars.GetOrCreate("ProcessFeedrate", 148); // Set by G89, no expression
|
||||
vars.GetOrCreate("ProcessFeedrate", 148); // Set by G89, no expression
|
||||
vars.GetOrCreate("LeadInFeedrate", 126, $"[#148*{Config.LeadInFeedratePercent}]");
|
||||
vars.GetOrCreate("LeadInArcLine2Feedrate", 127, $"[#148*{Config.LeadInArcLine2FeedratePercent}]");
|
||||
vars.GetOrCreate("CircleFeedrate", 128, Config.CircleFeedrateMultiplier.ToString("0.#"));
|
||||
vars.GetOrCreate(
|
||||
"LeadInArcLine2Feedrate",
|
||||
127,
|
||||
$"[#148*{Config.LeadInArcLine2FeedratePercent}]"
|
||||
);
|
||||
vars.GetOrCreate(
|
||||
"CircleFeedrate",
|
||||
128,
|
||||
Config.CircleFeedrateMultiplier.ToString("0.#")
|
||||
);
|
||||
vars.GetOrCreate("LeadOutFeedrate", 129, $"[#148*{Config.LeadOutFeedratePercent}]");
|
||||
|
||||
if (Config.ArcFeedrate == ArcFeedrateMode.Variables)
|
||||
{
|
||||
foreach (var range in Config.ArcFeedrateRanges)
|
||||
{
|
||||
var name = $"ArcFeedR{range.MaxRadius.ToString("0.###", System.Globalization.CultureInfo.InvariantCulture)}";
|
||||
vars.GetOrCreate(name, range.VariableNumber,
|
||||
$"[#148*{range.FeedratePercent.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)}]");
|
||||
var name =
|
||||
$"ArcFeedR{range.MaxRadius.ToString("0.###", System.Globalization.CultureInfo.InvariantCulture)}";
|
||||
vars.GetOrCreate(
|
||||
name,
|
||||
range.VariableNumber,
|
||||
$"[#148*{range.FeedratePercent.ToString("0.##", System.Globalization.CultureInfo.InvariantCulture)}]"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user