fix SoftNcRunner GM code normalization.
This commit is contained in:
@@ -1,236 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Class DemoMessageAndExceptionHandling | HiAPI-C# 2025 </title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="title" content="Class DemoMessageAndExceptionHandling | HiAPI-C# 2025 ">
|
||||
|
||||
<meta name="description" content="Demonstrates common message and exception handling patterns in HiAPI applications">
|
||||
<link rel="icon" href="../img/HiAPI.favicon.ico">
|
||||
<link rel="stylesheet" href="../public/docfx.min.css">
|
||||
<link rel="stylesheet" href="../public/main.css">
|
||||
<meta name="docfx:navrel" content="../toc.html">
|
||||
<meta name="docfx:tocrel" content="toc.html">
|
||||
|
||||
<meta name="docfx:rel" content="../">
|
||||
|
||||
|
||||
|
||||
<meta name="loc:inThisArticle" content="In this article">
|
||||
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
||||
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
||||
<meta name="loc:tocFilter" content="Filter by title">
|
||||
<meta name="loc:nextArticle" content="Next">
|
||||
<meta name="loc:prevArticle" content="Previous">
|
||||
<meta name="loc:themeLight" content="Light">
|
||||
<meta name="loc:themeDark" content="Dark">
|
||||
<meta name="loc:themeAuto" content="Auto">
|
||||
<meta name="loc:changeTheme" content="Change theme">
|
||||
<meta name="loc:copy" content="Copy">
|
||||
<meta name="loc:downloadPdf" content="Download PDF">
|
||||
|
||||
<script type="module" src="./../public/docfx.min.js"></script>
|
||||
|
||||
<script>
|
||||
const theme = localStorage.getItem('theme') || 'auto'
|
||||
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
|
||||
<header class="bg-body border-bottom">
|
||||
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
||||
<div class="container-xxl flex-nowrap">
|
||||
<a class="navbar-brand" href="../index.html">
|
||||
<img id="logo" class="svg" src="../img/HiAPI.logo.png" alt="">
|
||||
|
||||
</a>
|
||||
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="bi bi-three-dots"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navpanel">
|
||||
<div id="navbar">
|
||||
<form class="search" role="search" id="search">
|
||||
<i class="bi bi-search"></i>
|
||||
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main class="container-xxl">
|
||||
<div class="toc-offcanvas">
|
||||
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
||||
<div class="offcanvas-header">
|
||||
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<nav class="toc" id="toc"></nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="actionbar">
|
||||
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
||||
<i class="bi bi-list"></i>
|
||||
</button>
|
||||
|
||||
<nav id="breadcrumb"></nav>
|
||||
</div>
|
||||
|
||||
<article data-uid="Sample.Common.DemoMessageAndExceptionHandling">
|
||||
|
||||
|
||||
|
||||
<h1 id="Sample_Common_DemoMessageAndExceptionHandling" data-uid="Sample.Common.DemoMessageAndExceptionHandling" class="text-break">
|
||||
Class DemoMessageAndExceptionHandling
|
||||
</h1>
|
||||
|
||||
<div class="facts text-secondary">
|
||||
<dl><dt>Namespace</dt><dd><a class="xref" href="Sample.html">Sample</a>.<a class="xref" href="Sample.Common.html">Common</a></dd></dl>
|
||||
<dl><dt>Assembly</dt><dd>Hi.Sample.dll</dd></dl>
|
||||
</div>
|
||||
|
||||
<div class="markdown summary"><p>Demonstrates common message and exception handling patterns in HiAPI applications</p>
|
||||
</div>
|
||||
<div class="markdown conceptual"></div>
|
||||
|
||||
<div class="codewrapper">
|
||||
<pre><code class="lang-csharp hljs">public static class DemoMessageAndExceptionHandling</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritance">
|
||||
<dt>Inheritance</dt>
|
||||
<dd>
|
||||
<div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
|
||||
<div><span class="xref">DemoMessageAndExceptionHandling</span></div>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
<dl class="typelist inheritedMembers">
|
||||
<dt>Inherited Members</dt>
|
||||
<dd>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
|
||||
</div>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2 id="Sample_Common_DemoMessageAndExceptionHandling_remarks">Remarks</h2>
|
||||
<div class="markdown level0 remarks"><h3 id="source-code">Source Code</h3>
|
||||
<pre><code class="lang-csharp" name="SampleCode">using System;
|
||||
using System.Threading.Tasks;
|
||||
using Hi.Common;
|
||||
using Hi.Common.Messages;
|
||||
|
||||
namespace Sample.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Demonstrates common message and exception handling patterns in HiAPI applications
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoMessageAndExceptionHandling.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoMessageAndExceptionHandling
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstrates normal message handling
|
||||
/// </summary>
|
||||
internal static void DemoNormalMessages()
|
||||
{
|
||||
#region Normal_Messages
|
||||
MessageUtil.ReportMessage("Operation completed successfully.");
|
||||
MessageUtil.ReportWarning("Please check your input.");
|
||||
#endregion
|
||||
}
|
||||
/// <summary>
|
||||
/// Demonstrates exception handling in synchronous code
|
||||
/// </summary>
|
||||
internal static void DemoSynchronousExceptionHandling()
|
||||
{
|
||||
#region Sync_Exception
|
||||
try
|
||||
{
|
||||
// Your code here
|
||||
throw new NotImplementedException("Demo exception");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionUtil.ShowException(ex, null);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
/// <summary>
|
||||
/// Demonstrates exception handling in asynchronous code
|
||||
/// </summary>
|
||||
internal static async Task DemoAsynchronousExceptionHandling()
|
||||
{
|
||||
#region Async_Exception
|
||||
await Task.Run(() =>
|
||||
{
|
||||
// Your async operation here
|
||||
throw new NotImplementedException("Demo async exception");
|
||||
}).ShowIfCatched(null);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
</code></pre></div>
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<div class="contribution d-print-none">
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="affix">
|
||||
<nav id="affix"></nav>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="container-xxl search-results" id="search-results"></div>
|
||||
|
||||
<footer class="border-top text-secondary">
|
||||
<div class="container-xxl">
|
||||
<div class="flex-fill">
|
||||
<span> Copyright © 2025 <a href='https://superhightech.com.tw'>Tech Coordinate</a>. All rights reserved. <a href='https://superhightech.com.tw'>超級高科技股份有限公司</a> © 2025 版權所有 </span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -94,11 +94,6 @@
|
||||
<h3 id="classes">
|
||||
Classes
|
||||
</h3>
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="Sample.Common.DemoMessageAndExceptionHandling.html">DemoMessageAndExceptionHandling</a></dt>
|
||||
<dd><p>Demonstrates common message and exception handling patterns in HiAPI applications</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="jumplist">
|
||||
<dt><a class="xref" href="Sample.Common.DemoSessionMessage.html">DemoSessionMessage</a></dt>
|
||||
<dd></dd>
|
||||
|
||||
@@ -155,6 +155,7 @@ Handles common initialization and cleanup tasks for visualization examples.</p>
|
||||
using Hi.HiNcKits;
|
||||
using Hi.Licenses;
|
||||
using Hi.WpfPlus.Disp;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Windows;
|
||||
|
||||
namespace Sample.Disp;
|
||||
@@ -179,7 +180,8 @@ public static class DemoUtil
|
||||
/// <param name="displayee">The object that implements IDisplayee to be rendered</param>
|
||||
public static void RunApplication(string title, IDisplayee displayee)
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample.Wpf"));
|
||||
Application app = new Application();
|
||||
app.Exit += (o, e) =>
|
||||
{
|
||||
|
||||
@@ -153,6 +153,7 @@ Shows the basic setup of display engine, MongoDB server, licensing, and other co
|
||||
It demonstrates proper initialization and teardown of key components.</p>
|
||||
<h3 id="source-code">Source Code</h3>
|
||||
<pre><code class="lang-csharp" name="SampleCode">using Hi.HiNcKits;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace Sample
|
||||
@@ -172,7 +173,8 @@ namespace Sample
|
||||
static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("HiAPI starting.");
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
|
||||
Console.WriteLine("Hello World! HiAPI.");
|
||||
|
||||
|
||||
@@ -182,7 +182,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());
|
||||
}
|
||||
/// <summary>
|
||||
/// Generates an XYZ-ABC machine tool instance from embedded resources.
|
||||
|
||||
+5
-2
@@ -164,6 +164,7 @@ using Hi.NcMech.Holders;
|
||||
using Hi.Machining;
|
||||
using Hi.HiNcKits;
|
||||
using Hi.Milling.MillingTools;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Sample.Machining;
|
||||
|
||||
@@ -192,7 +193,8 @@ public static class DemoBuildGeomOnlyMachiningProject
|
||||
|
||||
static void Main()
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
|
||||
@@ -232,9 +234,10 @@ public static class DemoBuildGeomOnlyMachiningProject
|
||||
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
|
||||
};
|
||||
|
||||
IProgress<object> progress = null;
|
||||
localProjectService.MachiningChain
|
||||
= XFactory.GenByFile<CodeXyzabcMachineTool>(
|
||||
"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();
|
||||
|
||||
@@ -171,6 +171,7 @@ using Hi.MachiningProcs;
|
||||
using System.IO;
|
||||
using Hi.HiNcKits;
|
||||
using Hi.Milling.MillingTools;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Sample.Machining;
|
||||
|
||||
@@ -296,7 +297,8 @@ public static class DemoBuildMachiningProject
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
|
||||
@@ -305,6 +307,8 @@ public static class DemoBuildMachiningProject
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
|
||||
IProgress<object> progress = null;
|
||||
|
||||
#region ConfigureMachiningToolHouse
|
||||
localProjectService.MachiningToolHouse = new MachiningToolHouse()
|
||||
{
|
||||
@@ -348,16 +352,16 @@ public static class DemoBuildMachiningProject
|
||||
IdealGeom = null,
|
||||
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
|
||||
CuttingPara = XFactory.GenByFile<ICuttingPara>(
|
||||
"Resource/CuttingParameter", "Al6061T6.mp", GenMode.Default),
|
||||
"Resource/CuttingParameter", "Al6061T6.mp", progress),
|
||||
WorkpieceMaterial = XFactory.GenByFile<WorkpieceMaterial>(
|
||||
"Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", GenMode.Default),
|
||||
"Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", progress),
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region ConfigureMachineChain
|
||||
localProjectService.MachiningChain
|
||||
= XFactory.GenByFile<CodeXyzabcMachineTool>(
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default);
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", progress);
|
||||
#endregion
|
||||
|
||||
machiningProject.MakeXmlSourceToFile(projectPath);
|
||||
|
||||
@@ -148,7 +148,7 @@ Class DemoMillingByCutterLocation
|
||||
|
||||
<h2 id="Sample_Machining_DemoMillingByCutterLocation_remarks">Remarks</h2>
|
||||
<div class="markdown level0 remarks"><h3 id="source-code">Source Code</h3>
|
||||
<pre><code class="lang-csharp" name="SampleCode">using Hi.Common;
|
||||
<pre><code class="lang-csharp" name="SampleCode">using Hi.Common.Messages;
|
||||
using Hi.Disp;
|
||||
using Hi.Geom;
|
||||
using Hi.Geom.Resolution;
|
||||
@@ -157,6 +157,7 @@ using Hi.MachiningProcs;
|
||||
using Hi.Numerical.Acts;
|
||||
using Hi.WpfPlus.Disp;
|
||||
using HiMachining.Milling;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
@@ -184,7 +185,8 @@ namespace Sample.Machining
|
||||
new Cylindroid(new PairZr(-h, 18), new PairZr(0, 18))
|
||||
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR18);
|
||||
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample.Wpf"));
|
||||
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
@@ -202,8 +204,8 @@ namespace Sample.Machining
|
||||
localProjectService.ClStrip.IsShowDot = true;
|
||||
double resolution_mm = 0.5;
|
||||
var projectDir = Path.GetDirectoryName(projectPath);
|
||||
localProjectService.Workpiece.InitGeom = new StlFile(stlFile_CylinderR20, projectDir);
|
||||
localProjectService.Workpiece.IdealGeom = new StlFile(stlFile_CylinderR19, projectDir);
|
||||
localProjectService.WorkpieceService.InitGeom = new StlFile(stlFile_CylinderR20, projectDir);
|
||||
localProjectService.WorkpieceService.IdealGeom = new StlFile(stlFile_CylinderR19, projectDir);
|
||||
localProjectService.Workpiece.InitResolution = resolution_mm;
|
||||
|
||||
RuntimeApi runtimeApi = localProjectService.RuntimeApi;
|
||||
@@ -236,7 +238,7 @@ namespace Sample.Machining
|
||||
{
|
||||
RunSession(projectService, resolution_mm);
|
||||
Console.WriteLine($"task done.");
|
||||
}).ShowIfCatched(null);
|
||||
}).CatchExceptions(ex => Console.WriteLine(ex));
|
||||
|
||||
#region Create and Run WPF Application
|
||||
Application app = new Application
|
||||
@@ -284,7 +286,7 @@ namespace Sample.Machining
|
||||
}
|
||||
static bool IsDifferenceAceptable(LocalProjectService localProjectService, double diffLimit)
|
||||
{
|
||||
foreach (var attachment in localProjectService.Workpiece.DiffAttachmentBag)
|
||||
foreach (var attachment in localProjectService.WorkpieceService.DiffAttachmentBag)
|
||||
{
|
||||
if (double.IsNaN(attachment.Diff) || Math.Abs(attachment.Diff) > diffLimit)
|
||||
{
|
||||
|
||||
+6
-3
@@ -158,6 +158,7 @@ using Hi.Common.FileLines;
|
||||
using System.Windows;
|
||||
using Hi.MachiningSteps;
|
||||
using Hi.HiNcKits;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Sample.Machining
|
||||
{
|
||||
@@ -175,7 +176,8 @@ namespace Sample.Machining
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample.Wpf"));
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
#region Load Machining Project
|
||||
@@ -184,10 +186,11 @@ namespace Sample.Machining
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
|
||||
localProjectService.RuntimeApi.MachiningStepSelected += (MachiningStep step) =>
|
||||
localProjectService.RuntimeApi.SessionStepSelected += (MachiningStep step) =>
|
||||
{
|
||||
var sourceCommand = step.SourceCommand;
|
||||
Console.WriteLine($"Step Selected: MRR = {step.Mrr_mm3ds} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
|
||||
var indexedFileLine = sourceCommand.GetSentence().FirstIndexedFileLine;
|
||||
Console.WriteLine($"Step Selected: MRR = {step.Mrr_mm3ds} At \"{indexedFileLine?.FilePath}\" (Line {indexedFileLine?.GetLineNo()}) \"{indexedFileLine?.Line}\"");
|
||||
};
|
||||
localProjectService.PacePlayer.Start();
|
||||
#endregion
|
||||
|
||||
@@ -156,6 +156,7 @@ execute NC files, and properly manage project resources using
|
||||
using Hi.Common.Messages;
|
||||
using Hi.HiNcKits;
|
||||
using Hi.MachiningProcs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -175,7 +176,8 @@ public static class DemoUseMachiningProject
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
LocalApp.AppBegin();
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
#region ProjectLoading
|
||||
@@ -202,10 +204,10 @@ public static class DemoUseMachiningProject
|
||||
};
|
||||
Console.WriteLine($"Set machining step event.");
|
||||
//show MRR.
|
||||
localProjectService.RuntimeApi.MachiningStepBuilt += (preStep, curStep) =>
|
||||
localProjectService.RuntimeApi.SessionStepBuilt += (preStep, curStep) =>
|
||||
{
|
||||
var sourceCommand = curStep.SourceCommand;
|
||||
var indexedFileLine=sourceCommand?.GetSentence()?.IndexedFileLine;
|
||||
var indexedFileLine=sourceCommand?.GetSentence()?.FirstIndexedFileLine;
|
||||
if (curStep.Mrr_mm3ds > 500) //show only the step that contains large MRR.
|
||||
Console.WriteLine($"MRR = {curStep.Mrr_mm3ds} At \"{indexedFileLine?.FilePath}\" (Line {indexedFileLine?.GetLineNo()}) \"{indexedFileLine?.Line}\"");
|
||||
};
|
||||
|
||||
@@ -156,80 +156,79 @@ using Hi.Disp;
|
||||
using Hi.Geom;
|
||||
using Hi.Mech.Topo;
|
||||
|
||||
namespace Sample.Mech
|
||||
namespace Sample.Mech;
|
||||
|
||||
/// <summary>
|
||||
/// Demonstrates the creation and visualization of mechanical assemblies with kinematic linkages.
|
||||
/// Shows how to build coordinate systems, establish kinematic relationships, and capture visual output.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample/Mech/DemoTopo1.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoTopo1
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstrates the creation and visualization of mechanical assemblies with kinematic linkages.
|
||||
/// Shows how to build coordinate systems, establish kinematic relationships, and capture visual output.
|
||||
/// Creates a demonstration assembly with kinematic linkages.
|
||||
/// Builds a mechanical assembly with multiple anchors and branches, including both static and dynamic transformations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample/Mech/DemoTopo1.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoTopo1
|
||||
/// <returns>A tuple containing the assembly and root anchor</returns>
|
||||
static (Asmb asmb, Anchor root) GetDemoAsmb()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a demonstration assembly with kinematic linkages.
|
||||
/// Builds a mechanical assembly with multiple anchors and branches, including both static and dynamic transformations.
|
||||
/// </summary>
|
||||
/// <returns>A tuple containing the assembly and root anchor</returns>
|
||||
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<Anchor, Mat4d> matMap = asmb.GetMat4dMap(O);
|
||||
Console.WriteLine("Transform Matrix relative to O:");
|
||||
foreach (KeyValuePair<Anchor, Mat4d> keyValue in matMap)
|
||||
Console.WriteLine($"{keyValue.Key.Name} : {keyValue.Value}");
|
||||
#endregion
|
||||
|
||||
return (asmb, O);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="src">A tuple containing the assembly and root anchor for visualization</param>
|
||||
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)))
|
||||
{
|
||||
#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<Anchor, Mat4d> matMap = asmb.GetMat4dMap(O);
|
||||
Console.WriteLine("Transform Matrix relative to O:");
|
||||
foreach (KeyValuePair<Anchor, Mat4d> keyValue in matMap)
|
||||
Console.WriteLine($"{keyValue.Key.Name} : {keyValue.Value}");
|
||||
#endregion
|
||||
|
||||
return (asmb,O);
|
||||
dispEngine.SetViewToIsometricView();
|
||||
dispEngine.Snapshot("DemoTopo1.bmp", 680, 480);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="src">A tuple containing the assembly and root anchor for visualization</param>
|
||||
static void SnapshotToFile((Asmb asmb, Anchor root) src)
|
||||
{
|
||||
//all the drawing function has to call DispEngine.Init() before using.
|
||||
DispEngine.Init();
|
||||
DispEngine.EnableSuppressDefaultLogo = true;
|
||||
Console.WriteLine("Snapshot file output.");
|
||||
|
||||
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());
|
||||
}
|
||||
DispEngine.FinishDisp();
|
||||
}
|
||||
static void Main()
|
||||
{
|
||||
SnapshotToFile(GetDemoAsmb());
|
||||
}
|
||||
}
|
||||
</code></pre></div>
|
||||
|
||||
@@ -27,9 +27,6 @@
|
||||
<a href="Sample.Common.html" name="" title="Sample.Common">Sample.Common</a>
|
||||
|
||||
<ul class="nav level2">
|
||||
<li>
|
||||
<a href="Sample.Common.DemoMessageAndExceptionHandling.html" name="" title="DemoMessageAndExceptionHandling">DemoMessageAndExceptionHandling</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Sample.Common.DemoSessionMessage.html" name="" title="DemoSessionMessage">DemoSessionMessage</a>
|
||||
</li>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user