fix: preserve bend lines through drawing split — clip, offset, and carry metadata
DrawingSplitter now clips bend lines to each piece's region using Liang-Barsky line clipping and offsets them to the new origin. Bend properties (direction, angle, radius, note text) are preserved through the entire split pipeline instead of being lost during re-import. CadConverterForm applies the same origin offset to bends before passing them to the splitter, and creates FileListItems directly from split results to avoid re-detection overwriting the bend metadata. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -231,14 +231,25 @@ namespace OpenNest.Forms
|
||||
shape.Cutouts.ForEach(c => drawEntities.AddRange(c.Entities));
|
||||
|
||||
var pgm = ConvertGeometry.ToProgram(drawEntities);
|
||||
var originOffset = Vector.Zero;
|
||||
if (pgm.Codes.Count > 0 && pgm[0].Type == CodeType.RapidMove)
|
||||
{
|
||||
var rapid = (RapidMove)pgm[0];
|
||||
pgm.Offset(-rapid.EndPoint);
|
||||
originOffset = rapid.EndPoint;
|
||||
pgm.Offset(-originOffset);
|
||||
pgm.Codes.RemoveAt(0);
|
||||
}
|
||||
|
||||
var drawing = new Drawing(item.Name, pgm);
|
||||
drawing.Bends = item.Bends.Select(b => new Bend
|
||||
{
|
||||
StartPoint = new Vector(b.StartPoint.X - originOffset.X, b.StartPoint.Y - originOffset.Y),
|
||||
EndPoint = new Vector(b.EndPoint.X - originOffset.X, b.EndPoint.Y - originOffset.Y),
|
||||
Direction = b.Direction,
|
||||
Angle = b.Angle,
|
||||
Radius = b.Radius,
|
||||
NoteText = b.NoteText,
|
||||
}).ToList();
|
||||
|
||||
using var form = new SplitDrawingForm(drawing);
|
||||
if (form.ShowDialog(this) != DialogResult.OK || form.ResultDrawings?.Count <= 1)
|
||||
@@ -255,25 +266,41 @@ namespace OpenNest.Forms
|
||||
var newItems = new List<string>();
|
||||
|
||||
var splitWriter = new SplitDxfWriter();
|
||||
var splitItems = new List<FileListItem>();
|
||||
|
||||
for (var i = 0; i < form.ResultDrawings.Count; i++)
|
||||
{
|
||||
var splitDrawing = form.ResultDrawings[i];
|
||||
|
||||
// Assign bends from the source item — spatial filtering is a future enhancement
|
||||
splitDrawing.Bends.AddRange(item.Bends);
|
||||
|
||||
var splitName = $"{baseName}-{i + 1}.dxf";
|
||||
var splitPath = GetUniquePath(Path.Combine(writableDir, splitName));
|
||||
|
||||
splitWriter.Write(splitPath, splitDrawing);
|
||||
newItems.Add(splitPath);
|
||||
|
||||
// Re-import geometry but keep bends from the split drawing
|
||||
var importer = new DxfImporter();
|
||||
importer.SplinePrecision = Settings.Default.ImportSplinePrecision;
|
||||
var result = importer.Import(splitPath);
|
||||
|
||||
var splitItem = new FileListItem
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(splitPath),
|
||||
Entities = result.Entities,
|
||||
Path = splitPath,
|
||||
Quantity = item.Quantity,
|
||||
Customer = item.Customer,
|
||||
Bends = splitDrawing.Bends ?? new List<Bend>(),
|
||||
Bounds = result.Entities.GetBoundingBox(),
|
||||
EntityCount = result.Entities.Count
|
||||
};
|
||||
splitItems.Add(splitItem);
|
||||
}
|
||||
|
||||
// Remove original and add split files
|
||||
// Remove original and add split items directly (preserving bend info)
|
||||
fileList.RemoveAt(index);
|
||||
foreach (var path in newItems)
|
||||
AddFile(path);
|
||||
foreach (var splitItem in splitItems)
|
||||
fileList.AddItem(splitItem);
|
||||
|
||||
if (writableDir != sourceDir)
|
||||
MessageBox.Show($"Split files written to: {writableDir}", "Split Output",
|
||||
|
||||
Reference in New Issue
Block a user