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 { /// /// Provides access to the PMC-B1 machine tool model. /// public class DemoBuildMachineTool : IGetCodeXyzabcMachineTool { static DemoBuildMachineTool() { XFactory.Default.Regs.Add(XName, (xml, baseDirectory, relFile, res) => new DemoBuildMachineTool()); } /// /// Generates an XYZ-ABC machine tool instance from embedded resources. /// /// A configured machine tool model. 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 solidMap = new Dictionary() { ["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; } /// /// The cached machine tool instance. /// CodeXyzabcMachineTool MachineTool { get; } /// /// Default constructor that initializes the machine tool model. /// public DemoBuildMachineTool() { MachineTool = GenXyzabcMachineTool(); } #region XML IO //public PmcB1MachineToolSource(XElement src, object res) : this() { } /// /// XML element name for serialization. /// public static string XName = nameof(DemoBuildMachineTool); /// public XElement ToXElement() => new XElement(XName); #endregion /// public CodeXyzabcMachineTool GetXyzabcMachineTool() => MachineTool; /// public IMachiningChain GetMachiningChain() => MachineTool; /// public ISolidMachiningChain GetSolidMachiningChain() => MachineTool; } }