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>
96 lines
3.5 KiB
C#
96 lines
3.5 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
|
|
{
|
|
/// <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 GeneralXyzabcMachineTool 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);
|
|
|
|
GeneralXyzabcMachineTool dst = new GeneralXyzabcMachineTool(chain);
|
|
dst.GenerateCollisionIndexPairs();
|
|
return dst;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The cached machine tool instance.
|
|
/// </summary>
|
|
GeneralXyzabcMachineTool 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
|
|
/// <summary>
|
|
/// Gets the built machine tool.
|
|
/// </summary>
|
|
/// <returns>Machine tool.</returns>
|
|
public GeneralXyzabcMachineTool GetXyzabcMachineTool() => MachineTool;
|
|
/// <summary>
|
|
/// Gets the machine tool as a machining chain.
|
|
/// </summary>
|
|
/// <returns>Machining chain.</returns>
|
|
public IMachiningChain GetMachiningChain() => MachineTool;
|
|
}
|
|
}
|