From dd4c3ef28fc91611faf4baaa851f8025a431d6c5 Mon Sep 17 00:00:00 2001 From: iamboss Date: Sat, 11 Apr 2026 11:19:36 +0800 Subject: [PATCH] refactor(Sample): adapt demos to XFactory IProgress signature Made-with: Cursor --- MachineTool/DemoBuildMachineTool.cs | 4 +- .../DemoBuildGeomOnlyMachiningProject.cs | 5 +- Machining/DemoBuildMachiningProject.cs | 10 +- Mech/DemoTopo1.cs | 135 +++++++++--------- 4 files changed, 78 insertions(+), 76 deletions(-) diff --git a/MachineTool/DemoBuildMachineTool.cs b/MachineTool/DemoBuildMachineTool.cs index 7e4d2b1..0f65dd3 100644 --- a/MachineTool/DemoBuildMachineTool.cs +++ b/MachineTool/DemoBuildMachineTool.cs @@ -1,4 +1,4 @@ -using Hi.Common.XmlUtils; +using Hi.Common.XmlUtils; using Hi.Geom; using Hi.Mech; using Hi.Mech.Topo; @@ -25,7 +25,7 @@ namespace Sample.MachineTool { static DemoBuildMachineTool() { - XFactory.Regs.Add(XName, (xml, baseDirectory, relFile, res) => new DemoBuildMachineTool()); + XFactory.Regs.Add(XName, (xml, baseDirectory, relFile, progress, res) => new DemoBuildMachineTool()); } /// /// Generates an XYZ-ABC machine tool instance from embedded resources. diff --git a/Machining/DemoBuildGeomOnlyMachiningProject.cs b/Machining/DemoBuildGeomOnlyMachiningProject.cs index 16774fe..838e1d8 100644 --- a/Machining/DemoBuildGeomOnlyMachiningProject.cs +++ b/Machining/DemoBuildGeomOnlyMachiningProject.cs @@ -1,4 +1,4 @@ -using Hi.Common.XmlUtils; +using Hi.Common.XmlUtils; using Hi.Geom; using Hi.MachiningProcs; using Hi.Mech.Topo; @@ -83,9 +83,10 @@ public static class DemoBuildGeomOnlyMachiningProject WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)), }; + IProgress progress = null; localProjectService.MachiningChain = XFactory.GenByFile( - "Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default); + "Resource", "MachineTool/PMC-B1/PMC-B1.mt", progress); localProjectService.MachiningChainFile = "PMC-B1/PMC-B1.mt"; localProjectService.SaveProject(); diff --git a/Machining/DemoBuildMachiningProject.cs b/Machining/DemoBuildMachiningProject.cs index a48f355..bda4826 100644 --- a/Machining/DemoBuildMachiningProject.cs +++ b/Machining/DemoBuildMachiningProject.cs @@ -1,4 +1,4 @@ -using System; +using System; using Hi.Milling.Apts; using Hi.Common.XmlUtils; using Hi.Geom; @@ -152,6 +152,8 @@ public static class DemoBuildMachiningProject localProjectService.LoadProject(projectPath); MachiningProject machiningProject = localProjectService.MachiningProject; + IProgress progress = null; + #region ConfigureMachiningToolHouse localProjectService.MachiningToolHouse = new MachiningToolHouse() { @@ -195,16 +197,16 @@ public static class DemoBuildMachiningProject IdealGeom = null, WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)), CuttingPara = XFactory.GenByFile( - "Resource/CuttingParameter", "Al6061T6.mp", GenMode.Default), + "Resource/CuttingParameter", "Al6061T6.mp", progress), WorkpieceMaterial = XFactory.GenByFile( - "Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", GenMode.Default), + "Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", progress), }; #endregion #region ConfigureMachineChain localProjectService.MachiningChain = XFactory.GenByFile( - "Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default); + "Resource", "MachineTool/PMC-B1/PMC-B1.mt", progress); #endregion machiningProject.MakeXmlSourceToFile(projectPath); diff --git a/Mech/DemoTopo1.cs b/Mech/DemoTopo1.cs index 9605857..f067c0d 100644 --- a/Mech/DemoTopo1.cs +++ b/Mech/DemoTopo1.cs @@ -4,79 +4,78 @@ using Hi.Disp; using Hi.Geom; using Hi.Mech.Topo; -namespace Sample.Mech +namespace Sample.Mech; + +/// +/// Demonstrates the creation and visualization of mechanical assemblies with kinematic linkages. +/// Shows how to build coordinate systems, establish kinematic relationships, and capture visual output. +/// +/// +/// ### Source Code +/// [!code-csharp[SampleCode](~/../Hi.Sample/Mech/DemoTopo1.cs)] +/// +public static class DemoTopo1 { - /// - /// Demonstrates the creation and visualization of mechanical assemblies with kinematic linkages. - /// Shows how to build coordinate systems, establish kinematic relationships, and capture visual output. - /// - /// - /// ### Source Code - /// [!code-csharp[SampleCode](~/../Hi.Sample/Mech/DemoTopo1.cs)] - /// - public static class DemoTopo1 - { - /// - /// Creates a demonstration assembly with kinematic linkages. - /// Builds a mechanical assembly with multiple anchors and branches, including both static and dynamic transformations. - /// - /// A tuple containing the assembly and root anchor - static (Asmb asmb,Anchor root) GetDemoAsmb() - { - #region DocSite.DemoTopo1 - //build coordinate systems and the assembly. - Asmb asmb = new Asmb { Name = "Mech" }; - Anchor O = new Anchor(asmb, "O"); - Anchor O1 = new Anchor(asmb, "O1"); - Anchor X = new Anchor(asmb, "X"); - Anchor Z = new Anchor(asmb, "Z"); - Anchor B = new Anchor(asmb, "B"); + /// + /// Creates a demonstration assembly with kinematic linkages. + /// Builds a mechanical assembly with multiple anchors and branches, including both static and dynamic transformations. + /// + /// A tuple containing the assembly and root anchor + static (Asmb asmb, Anchor root) GetDemoAsmb() + { + #region DocSite.DemoTopo1 + //build coordinate systems and the assembly. + Asmb asmb = new Asmb { Name = "Mech" }; + Anchor O = new Anchor(asmb, "O"); + Anchor O1 = new Anchor(asmb, "O1"); + Anchor X = new Anchor(asmb, "X"); + Anchor Z = new Anchor(asmb, "Z"); + Anchor B = new Anchor(asmb, "B"); - //build kinematic link - Branch.Attach(O, O1, new StaticTranslation(new Vec3d(0, 0, 80))); - Branch brnX = Branch.Attach(O1, X, new DynamicTranslation(new Vec3d(1, 0, 0))); - Branch brnZ = Branch.Attach(X, Z, new DynamicTranslation(new Vec3d(0, 0, 1))); - Branch brnB = Branch.Attach(Z, B, new DynamicRotation(new Vec3d(0, 1, 0), 0, new Vec3d(-100, 0, 0))); + //build kinematic link + Branch.Attach(O, O1, new StaticTranslation(new Vec3d(0, 0, 80))); + Branch brnX = Branch.Attach(O1, X, new DynamicTranslation(new Vec3d(1, 0, 0))); + Branch brnZ = Branch.Attach(X, Z, new DynamicTranslation(new Vec3d(0, 0, 1))); + Branch brnB = Branch.Attach(Z, B, new DynamicRotation(new Vec3d(0, 1, 0), 0, new Vec3d(-100, 0, 0))); - //drive the dynamic transformation by single value for each branch. - brnX.Step = 200; - brnZ.Step = 100; - brnB.Step = MathUtil.ToRad(-60); + //drive the dynamic transformation by single value for each branch. + brnX.Step = 200; + brnZ.Step = 100; + brnB.Step = MathUtil.ToRad(-60); - //Get and show the transform matrices relative to O. - Dictionary matMap = asmb.GetMat4dMap(O); - Console.WriteLine("Transform Matrix relative to O:"); - foreach (KeyValuePair keyValue in matMap) - Console.WriteLine($"{keyValue.Key.Name} : {keyValue.Value}"); - #endregion + //Get and show the transform matrices relative to O. + Dictionary matMap = asmb.GetMat4dMap(O); + Console.WriteLine("Transform Matrix relative to O:"); + foreach (KeyValuePair keyValue in matMap) + Console.WriteLine($"{keyValue.Key.Name} : {keyValue.Value}"); + #endregion - return (asmb,O); - } - - /// - /// Captures the assembly visualization and saves it to a file. - /// Initializes the display engine, sets up the assembly visualization with an isometric view, and saves a snapshot to a bitmap file. - /// - /// A tuple containing the assembly and root anchor for visualization - static void SnapshotToFile((Asmb asmb, Anchor root) src) - { - //all the drawing function has to call DispEngine.Init() before using. - DispEngine.Init(); - DispEngine.EnableSuppressDefaultLogo = true; + return (asmb, O); + } - using (DispEngine dispEngine = new DispEngine( - src.asmb.GetAsmbDraw(src.root))) - { - dispEngine.SetViewToIsometricView(); - dispEngine.Snapshot("DemoTopo1.bmp", 680, 480); - } - Console.WriteLine("Snapshot file output."); + /// + /// Captures the assembly visualization and saves it to a file. + /// Initializes the display engine, sets up the assembly visualization with an isometric view, and saves a snapshot to a bitmap file. + /// + /// A tuple containing the assembly and root anchor for visualization + static void SnapshotToFile((Asmb asmb, Anchor root) src) + { + //all the drawing function has to call DispEngine.Init() before using. + DispEngine.Init(); + DispEngine.EnableSuppressDefaultLogo = true; - DispEngine.FinishDisp(); - } - static void Main() - { - SnapshotToFile(GetDemoAsmb()); - } - } + using (DispEngine dispEngine = new DispEngine( + src.asmb.GetAsmbDraw(src.root))) + { + dispEngine.SetViewToIsometricView(); + dispEngine.Snapshot("DemoTopo1.bmp", 680, 480); + } + Console.WriteLine("Snapshot file output."); + + DispEngine.FinishDisp(); + } + static void Main() + { + SnapshotToFile(GetDemoAsmb()); + } }