From 1cb5f05ba4e2822edaa5376830587ab7ab6ce177 Mon Sep 17 00:00:00 2001 From: iambossTC Date: Sun, 13 Apr 2025 00:19:07 +0800 Subject: [PATCH] add docfx samples. --- Geom/DemoBuildGeom.cs | 3 +- Geom/DemoIExpandToBox3d.cs | 24 ++++++ HelloHiAPI.cs | 30 +++++++ Hi.Sample.csproj | 14 ++-- MachineTool/DemoBuildMachineTool.cs | 3 +- .../DemoBuildMachineToolWithoutGeometrys.cs | 15 +--- Machining/DemoBuildMachiningProject.cs | 3 +- Machining/DemoUseMachiningProject.cs | 1 - Mech/DemoTopo1.cs | 81 +++++++++++++++++++ Properties/launchSettings.json | 3 +- 10 files changed, 147 insertions(+), 30 deletions(-) create mode 100644 Geom/DemoIExpandToBox3d.cs create mode 100644 HelloHiAPI.cs create mode 100644 Mech/DemoTopo1.cs diff --git a/Geom/DemoBuildGeom.cs b/Geom/DemoBuildGeom.cs index ebc00ae..bc01a81 100644 --- a/Geom/DemoBuildGeom.cs +++ b/Geom/DemoBuildGeom.cs @@ -5,8 +5,7 @@ using Hi.Mech.Topo; namespace Sample.Geom { /// - /// ## Source Code - /// + /// ### Source Code /// [!code-csharp[SampleCode](~/../Hi.Sample/Geom/DemoBuildGeom.cs)] /// public static class DemoBuildGeom diff --git a/Geom/DemoIExpandToBox3d.cs b/Geom/DemoIExpandToBox3d.cs new file mode 100644 index 0000000..3ed05a2 --- /dev/null +++ b/Geom/DemoIExpandToBox3d.cs @@ -0,0 +1,24 @@ +using Hi.Geom; +using System; + +namespace Sample.Geom +{ + /// + /// ### Source Code + /// [!code-csharp[SampleCode](~/../Hi.Sample/Geom/DemoIExpandToBox3d.cs)] + /// + public static class DemoIExpandToBox3d + { + static void Main() + { + #region DocSite.CountBoundingBox + Box3d objA = new Box3d(0, 0, 0, 1, 1, 1); + Box3d objB = new Box3d(-1, -2, -3, 3, 2, 1); + Vec3d objC = new Vec3d(-2, 3, -5); + + Box3d boundingbox = new Box3d(objA, objB, objC); + Console.WriteLine("boundingbox: " + boundingbox); + #endregion + } + } +} diff --git a/HelloHiAPI.cs b/HelloHiAPI.cs new file mode 100644 index 0000000..baa5fd6 --- /dev/null +++ b/HelloHiAPI.cs @@ -0,0 +1,30 @@ +using Hi.Disp; +using Hi.Licenses; +using Hi.MongoUtils; +using System; + +namespace Sample +{ + public static class HelloHiAPI + { + static int Main(string[] args) + { + Console.WriteLine("HiAPI starting."); + License.LogInAll(); + DispEngine.Init(); + MongoServer.Default = MongoServer.Run(new MongoRunnerOptions() + { + MongoPort = 28100 + }); + + Console.WriteLine("Hello World! HiAPI."); + + MongoServer.Default.Dispose(); + DispEngine.FinishDisp(); + License.LogOutAll(); + Console.WriteLine("HiAPI exited."); + + return 0; + } + } +} diff --git a/Hi.Sample.csproj b/Hi.Sample.csproj index 6ee9e63..90db735 100644 --- a/Hi.Sample.csproj +++ b/Hi.Sample.csproj @@ -9,7 +9,7 @@ HiAPI samples. - Demo;Maintenance + Debug;Release 0 1.4.$(VersionBuild) $(AssemblyName) @@ -18,9 +18,11 @@ Tech Coordinate Co., Ltd. Tech Coordinate Co., Ltd. bin\$(Platform).$(Configuration)\ + DEBUG;TRACE + Sample.Mech.DemoTopo1 - + @@ -29,14 +31,8 @@ - + - - - DEBUG;TRACE - Sample.Machining.DemoUseMachiningProject - - \ No newline at end of file diff --git a/MachineTool/DemoBuildMachineTool.cs b/MachineTool/DemoBuildMachineTool.cs index 48eb248..26d4338 100644 --- a/MachineTool/DemoBuildMachineTool.cs +++ b/MachineTool/DemoBuildMachineTool.cs @@ -18,8 +18,7 @@ namespace Sample.MachineTool /// Provides access to the PMC-B1 machine tool model. /// /// - /// ## Source Code - /// + /// ### Source Code /// [!code-csharp[SampleCode](~/../Hi.Sample/MachineTool/DemoBuildMachineTool.cs)] /// public class DemoBuildMachineTool : IGetCodeXyzabcMachineTool diff --git a/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs b/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs index 24649df..b7c9847 100644 --- a/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs +++ b/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs @@ -9,8 +9,7 @@ namespace Sample.MachineTool /// Demo Build Machine Tool without gemetries setting. /// /// - /// ## Source Code - /// + /// ### Source Code /// [!code-csharp[SampleCode](~/../Hi.Sample/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs)] /// public static class DemoBuildMachineToolWithoutGeometrys @@ -27,17 +26,5 @@ namespace Sample.MachineTool CodeXyzabcMachineTool xyzabcMachineTool = new CodeXyzabcMachineTool(chain); return xyzabcMachineTool; } - /// - /// Generates and saves an empty machine tool URI to a file. - /// - /// The base directory to save the machine tool file. - /// The machine tool URI object that was created and saved. - public static CodeXyzabcMachineToolUri GenEmptyMachineToolUri(string baseDirectory) - { - CodeXyzabcMachineToolUri machineToolUri = new CodeXyzabcMachineToolUri(@"Samples/EmpytMachineTool.mt", - GenEmptyMachineTool()); - machineToolUri.SaveToUri(baseDirectory); - return machineToolUri; - } } } diff --git a/Machining/DemoBuildMachiningProject.cs b/Machining/DemoBuildMachiningProject.cs index c5f55ab..1524b17 100644 --- a/Machining/DemoBuildMachiningProject.cs +++ b/Machining/DemoBuildMachiningProject.cs @@ -22,12 +22,13 @@ using System.IO; namespace Sample.Machining { + + /// /// This example demonstrates how to create a complete machining project from scratch using HiAPI. It shows the step-by-step process of building all necessary components, including defining custom milling cutters with specific parameters (helix angle, rake angle, etc.), configuring tool holders, setting up a machining tool house with multiple tools, defining the fixture and workpiece geometry, and configuring the machine chain. The sample also demonstrates how to set workpiece material properties and generate the final project XML file. This example is particularly valuable for developers who need to programmatically create complete machining projects without using the HiNC GUI. /// /// /// ### Source Code - /// /// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildMachiningProject.cs)] /// public static class DemoBuildMachiningProject diff --git a/Machining/DemoUseMachiningProject.cs b/Machining/DemoUseMachiningProject.cs index 6729980..fa15d80 100644 --- a/Machining/DemoUseMachiningProject.cs +++ b/Machining/DemoUseMachiningProject.cs @@ -12,7 +12,6 @@ namespace Sample.Machining /// /// /// ### Source Code - /// /// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoUseMachiningProject.cs)] /// public static class DemoUseMachiningProject diff --git a/Mech/DemoTopo1.cs b/Mech/DemoTopo1.cs new file mode 100644 index 0000000..2429458 --- /dev/null +++ b/Mech/DemoTopo1.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using Hi.Disp; +using Hi.Geom; +using Hi.Mech.Topo; + +namespace Sample.Mech +{ + public class Test : IDisplayee + { + /// + public void Display(Bind bind) + { + throw new NotImplementedException(); + } + /// + public void ExpandToBox3d(Box3d dst) + { + throw new NotImplementedException(); + } + } + + /// + /// ### Source Code + /// [!code-csharp[SampleCode](~/../Hi.Sample/Mech/DemoTopo1.cs)] + /// + public static class DemoTopo1 + { + public 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))); + + //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 + + return (asmb,O); + } + public static void SnapshotToFile((Asmb asmb, Anchor root) src) + { + //all the drawing function has to call DispEngine.Init() before using. + DispEngine.Init(); + DispEngine.EnableSuppressDefaultLogo = true; + + 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()); + } + } +} diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index adae572..4aaf323 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -6,7 +6,8 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "https://localhost:52376;http://localhost:52377" + "applicationUrl": "https://localhost:52376;http://localhost:52377", + "nativeDebugging": true } } } \ No newline at end of file