Files
Hi.Sample/Machining/DemoBuildGeomOnlyMachiningProject.cs
T
iambossandClaude Opus 5 7beb671352 refactor(demos): build sample machine tools as GeneralXyzabcMachineTool
Follows the CodeXyzabcMachineTool retirement in HiMech. DemoBuildMachineTool
drops IGetCodeXyzabcMachineTool, which no longer exists, and spells out the
doc comments the inherited interface used to supply.

The two GenByFile<CodeXyzabcMachineTool> call sites are fixed rather than
merely renamed: they read Resource machine tools rooted at
<GeneralXyzabcMachineTool>, so the factory's `as` cast handed back null and
the demo project got no machining chain at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 19:57:54 +08:00

100 lines
2.8 KiB
C#

using Hi.Common.XmlUtils;
using Hi.Geom;
using Hi.MachiningProcs;
using Hi.Mech.Topo;
using Hi.Milling.Apts;
using Hi.Milling.Cutters;
using Hi.NcMech.Fixtures;
using Hi.NcMech.Workpieces;
using Hi.NcMech.Xyzabc;
using System.Collections.Generic;
using System.IO;
using System;
using Hi.NcMech.Holders;
using Hi.Machining;
using Hi.HiNcKits;
using Hi.Milling.MillingTools;
using Microsoft.Extensions.Logging;
namespace Sample.Machining;
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildGeomOnlyMachiningProject.cs)]
/// </remarks>
public static class DemoBuildGeomOnlyMachiningProject
{
internal static MillingCutter CreateGeomOnlyMillingCutter()
{
MillingCutter millingCutter = new MillingCutter()
{
UpperBeamGeom = new Cylindroid(
[new PairZr(40, 6), new PairZr(90, 6)]),
ShaperProfile = new AptProfile(
new ColumnApt()
{
Diameter_mm = 12,
FluteHeight_mm = 40
})
};
return millingCutter;
}
static void Main()
{
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
LocalProjectService localProjectService = new LocalProjectService();
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
var projectDirectory = Path.GetDirectoryName(projectPath);
Console.WriteLine($"Directory of the New Project: {projectDirectory}");
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
CylindroidHolder cylindroidHolder = new CylindroidHolder()
{
Note = "BT40",
Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
new PairZr(20,16),new PairZr(30,16)])
};
localProjectService.MachiningToolHouse = new MachiningToolHouse()
{
[1] = new MillingTool()
{
Note = "T1",
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = cylindroidHolder,
Cutter = CreateGeomOnlyMillingCutter()
},
};
localProjectService.Fixture = new Fixture()
{
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
};
localProjectService.Workpiece = new Workpiece()
{
InitResolution = 0.25,
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
IdealGeom = null,
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
};
IProgress<object> progress = null;
localProjectService.MachiningChain
= XFactory.GenByFile<GeneralXyzabcMachineTool>(
"Resource", "MachineTool/Table-B1.default/Table-B1.mt", progress);
localProjectService.MachiningChainFile = "Table-B1.default/Table-B1.mt";
localProjectService.SaveProject();
machiningProject.Dispose();
LocalApp.AppEnd();
}
}