refactor(mcp): use CadImporter for DXF import
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
using ModelContextProtocol.Server;
|
using ModelContextProtocol.Server;
|
||||||
using OpenNest.Converters;
|
|
||||||
using OpenNest.Geometry;
|
|
||||||
using OpenNest.IO;
|
using OpenNest.IO;
|
||||||
using OpenNest.Shapes;
|
using OpenNest.Shapes;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@@ -96,24 +94,18 @@ namespace OpenNest.Mcp.Tools
|
|||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return $"Error: file not found: {path}";
|
return $"Error: file not found: {path}";
|
||||||
|
|
||||||
var geometry = Dxf.GetGeometry(path);
|
try
|
||||||
|
{
|
||||||
|
var drawing = CadImporter.ImportDrawing(path, new CadImportOptions { Name = name });
|
||||||
|
_session.Drawings.Add(drawing);
|
||||||
|
|
||||||
if (geometry.Count == 0)
|
var bbox = drawing.Program.BoundingBox();
|
||||||
return "Error: failed to read DXF file or no geometry found";
|
return $"Imported drawing '{drawing.Name}': bbox={bbox.Width:F2} x {bbox.Length:F2}";
|
||||||
|
}
|
||||||
var normalized = ShapeProfile.NormalizeEntities(geometry);
|
catch (System.Exception ex)
|
||||||
var pgm = ConvertGeometry.ToProgram(normalized);
|
{
|
||||||
|
return $"Error: failed to import '{path}': {ex.Message}";
|
||||||
if (pgm == null)
|
}
|
||||||
return "Error: failed to convert geometry to program";
|
|
||||||
|
|
||||||
var drawingName = name ?? Path.GetFileNameWithoutExtension(path);
|
|
||||||
var drawing = new Drawing(drawingName, pgm);
|
|
||||||
drawing.Color = Drawing.GetNextColor();
|
|
||||||
_session.Drawings.Add(drawing);
|
|
||||||
|
|
||||||
var bbox = pgm.BoundingBox();
|
|
||||||
return $"Imported drawing '{drawingName}': bbox={bbox.Width:F2} x {bbox.Length:F2}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[McpServerTool(Name = "create_drawing")]
|
[McpServerTool(Name = "create_drawing")]
|
||||||
|
|||||||
Reference in New Issue
Block a user