Files
Hi.Sample/MachineTool/DemoBuildMachineTool.cs
T
iambossandClaude Opus 5 f83f8b9fb1 refactor(demos): follow the Table-B1 rename and the marked resource names
The shipped machine tool is now MachineTool/Table-B1.default/Table-B1.mt
and the shipped cutting-parameter / workpiece-material files carry the
`.default` marker, so the three hard-coded resource paths move with them.
These samples are compiled into the public docsite verbatim, so a stale
path here ships as documentation.

Also removes the commented-out PmcB1MachineToolSource line and renames
the class summary, both of which put the retired name on the public docs.

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

90 lines
3.3 KiB
C#

using Hi.Common.XmlUtils;
using Hi.Geom;
using Hi.Mech;
using Hi.Mech.Topo;
using Hi.NcMech;
using Hi.NcMech.Solids;
using Hi.NcMech.Xyzabc;
using Hi.Numerical.Xyzabc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
namespace Sample.MachineTool
{
/// <summary>
/// Provides access to the Table-B1 machine tool model.
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/MachineTool/DemoBuildMachineTool.cs)]
/// </remarks>
public class DemoBuildMachineTool : IGetCodeXyzabcMachineTool
{
/// <summary>
/// Registers this type's deserializer with the given <see cref="XFactory"/>
/// (or <see cref="XFactory.Default"/> when <paramref name="factory"/> is
/// <c>null</c>). Idempotent.
/// </summary>
public static void Reg(XFactory factory = null)
{
factory ??= XFactory.Default;
factory.Generators.TryAdd(XName, (xml, baseDirectory, relFile, progress, res) => new DemoBuildMachineTool());
}
/// <summary>
/// Generates an XYZ-ABC machine tool instance from embedded resources.
/// </summary>
/// <returns>A configured machine tool model.</returns>
public static CodeXyzabcMachineTool GenXyzabcMachineTool()
{
CodeXyzabcChain chain = new CodeXyzabcChain("[O][Y][X][C][w];[O][Z][B][S][t]");
if (chain.ToolBuckleTransformer is StaticTranslation st)
st.Trans = new Vec3d(-72.40, 72.40, 176.44);
chain.TransformerB.Pivot = new Vec3d(-72.4, -177.4, 225.94);
Dictionary<string, Solid> solidMap = new Dictionary<string, Solid>()
{
["O"] = new Solid(new Stl("MachineTool/base.stl")),
["X"] = new Solid(new Stl("MachineTool/X.stl")),
["Y"] = new Solid(new Stl("MachineTool/Y.stl")),
["Z"] = new Solid(new Stl("MachineTool/Z.stl")),
["B"] = new Solid(new Stl("MachineTool/B.stl")),
["C"] = new Solid(new Stl("MachineTool/C.stl")),
["S"] = new Solid(new Stl("MachineTool/spindle.stl")),
};
chain.AnchorToSolid.BuildAnchorToSolid(
chain.Asmb.GetDescendantAnchors(), solidMap);
CodeXyzabcMachineTool dst = new CodeXyzabcMachineTool(chain);
dst.GenerateCollisionIndexPairs();
return dst;
}
/// <summary>
/// The cached machine tool instance.
/// </summary>
CodeXyzabcMachineTool MachineTool { get; }
/// <summary>
/// Default constructor that initializes the machine tool model.
/// </summary>
public DemoBuildMachineTool()
{
MachineTool = GenXyzabcMachineTool();
}
#region XML IO
/// <summary>
/// XML element name for serialization.
/// </summary>
public static string XName = nameof(DemoBuildMachineTool);
/// <inheritdoc/>
public XElement ToXElement() => new XElement(XName);
#endregion
/// <inheritdoc/>
public CodeXyzabcMachineTool GetXyzabcMachineTool() => MachineTool;
/// <inheritdoc/>
public IMachiningChain GetMachiningChain() => MachineTool;
}
}