327 lines
13 KiB
HTML
327 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Class DemoMillingByCutterLocation | HiAPI-C# 2025 </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="Class DemoMillingByCutterLocation | HiAPI-C# 2025 ">
|
|
|
|
|
|
<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.Machining.DemoMillingByCutterLocation">
|
|
|
|
|
|
|
|
<h1 id="Sample_Machining_DemoMillingByCutterLocation" data-uid="Sample.Machining.DemoMillingByCutterLocation" class="text-break">
|
|
Class DemoMillingByCutterLocation
|
|
</h1>
|
|
|
|
<div class="facts text-secondary">
|
|
<dl><dt>Namespace</dt><dd><a class="xref" href="Sample.html">Sample</a>.<a class="xref" href="Sample.Machining.html">Machining</a></dd></dl>
|
|
<dl><dt>Assembly</dt><dd>Hi.Sample.Wpf.dll</dd></dl>
|
|
</div>
|
|
|
|
<div class="markdown summary"></div>
|
|
<div class="markdown conceptual"></div>
|
|
|
|
<div class="codewrapper">
|
|
<pre><code class="lang-csharp hljs">public static class DemoMillingByCutterLocation</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">DemoMillingByCutterLocation</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_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;
|
|
using Hi.Disp;
|
|
using Hi.Geom;
|
|
using Hi.Geom.Resolution;
|
|
using Hi.HiNcKits;
|
|
using Hi.MachiningProcs;
|
|
using Hi.Numerical.Acts;
|
|
using Hi.WpfPlus.Disp;
|
|
using HiMachining.Milling;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace Sample.Machining
|
|
{
|
|
/// <remarks>
|
|
/// ### Source Code
|
|
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Machining/DemoMillingByCutterLocation.cs)]
|
|
/// </remarks>
|
|
public static class DemoMillingByCutterLocation
|
|
{
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
int h = 2;
|
|
string stlFile_CylinderR20 = $"Cache/CylinderH{h}R20.stl";
|
|
string stlFile_CylinderR19 = $"Cache/CylinderH{h}R19.stl";
|
|
string stlFile_CylinderR18 = $"Cache/CylinderH{h}R18.stl";
|
|
new Cylindroid(new PairZr(-h, 20), new PairZr(0, 20))
|
|
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR20);
|
|
new Cylindroid(new PairZr(-h, 19), new PairZr(0, 19))
|
|
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR19);
|
|
new Cylindroid(new PairZr(-h, 18), new PairZr(0, 18))
|
|
.GenStl(new PolarResolution2d(1, MathUtil.ToRad(15))).WriteBin(stlFile_CylinderR18);
|
|
|
|
LocalApp.AppBegin();
|
|
|
|
LocalProjectService localProjectService = new LocalProjectService();
|
|
|
|
#region ProjectLoading
|
|
//var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
|
|
var projectPath = "C:/HiNC-Projects/demo-test-1/Main.hincproj";
|
|
Console.WriteLine($"Load Project: {projectPath}");
|
|
localProjectService.LoadProject(projectPath);
|
|
var project = localProjectService.MachiningProject;
|
|
#endregion
|
|
|
|
var projectDisplayee = new MachiningProjectDisplayee(localProjectService);
|
|
var device = new ClMillingDevice();
|
|
localProjectService.MachiningEquipment.MachiningChain = device;
|
|
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.Workpiece.InitResolution = resolution_mm;
|
|
|
|
RuntimeApi runtimeApi = localProjectService.RuntimeApi;
|
|
runtimeApi.SetNcResolutionFixed(9999, 15);
|
|
runtimeApi.EnableCollisionDetection = false;
|
|
runtimeApi.EnablePhysics = false;
|
|
runtimeApi.MachiningResolution_mm = resolution_mm;
|
|
|
|
//RunConsole(project, projectDisplayee, resolution_mm);
|
|
RunWindow(localProjectService, projectDisplayee, resolution_mm);
|
|
}
|
|
static void RunConsole(LocalProjectService projectService,
|
|
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
|
{
|
|
RunSession(projectService, resolution_mm);
|
|
DispEngine dispEngine = new DispEngine(projectDisplayee);
|
|
dispEngine.SetViewToIsometricView();
|
|
dispEngine.SketchView = projectService.ClStrip.GetFittingView(dispEngine.SketchView);
|
|
dispEngine.SketchView = dispEngine.SketchView.Scale(0.5);
|
|
dispEngine.Snapshot($"Cache/result.bmp", 1000, 1000);
|
|
|
|
projectService.GetLocalProjectService().CloseProject();
|
|
LocalApp.AppEnd();
|
|
Console.WriteLine($"App exit.");
|
|
}
|
|
static void RunWindow(LocalProjectService projectService,
|
|
MachiningProjectDisplayee projectDisplayee, double resolution_mm)
|
|
{
|
|
var task = Task.Run(() =>
|
|
{
|
|
RunSession(projectService, resolution_mm);
|
|
Console.WriteLine($"task done.");
|
|
}).ShowIfCatched(null);
|
|
|
|
#region Create and Run WPF Application
|
|
Application app = new Application
|
|
{
|
|
ShutdownMode = ShutdownMode.OnMainWindowClose
|
|
};
|
|
app.Exit += (o, e) =>
|
|
{
|
|
projectService.GetLocalProjectService().CloseProject();
|
|
LocalApp.AppEnd();
|
|
Console.WriteLine($"App exit.");
|
|
};
|
|
app.Run(new RenderingWindow()
|
|
{
|
|
Title = "Demo",
|
|
Displayee = projectDisplayee
|
|
});
|
|
#endregion
|
|
}
|
|
static void RunSession(LocalProjectService localProjectService, double resolution_mm)
|
|
{
|
|
var project=localProjectService.MachiningProject;
|
|
RuntimeApi runtimeApi = localProjectService.RuntimeApi;
|
|
|
|
localProjectService.BeginSession();
|
|
double radius = 20;
|
|
double z = -1;
|
|
localProjectService.Act(new ActToolingTeleport(1));//equip tool
|
|
localProjectService.Act(new ActClTeleport(new DVec3d(radius, 0, z, 0, 0, 1)));//goto initial position
|
|
//run an arbitrary contour.
|
|
int divNum = 36;
|
|
for (int i = 0; i <= divNum; i++)
|
|
{
|
|
var cl = new DVec3d(
|
|
radius * Math.Cos(i * Math.PI * 2 / divNum),
|
|
radius * Math.Sin(i * Math.PI * 2 / divNum), z,
|
|
0, 0, 1);
|
|
Console.WriteLine($"{cl.Point.CsvText},{cl.Normal.CsvText},");
|
|
localProjectService.Act(new ActClStep(cl));
|
|
}
|
|
double diffLimit_mm = resolution_mm * 2;
|
|
runtimeApi.Diff(resolution_mm * 2);
|
|
Console.WriteLine($"IsDifferenceAceptable: {IsDifferenceAceptable(localProjectService, diffLimit_mm)}");
|
|
localProjectService.EndSession();
|
|
}
|
|
static bool IsDifferenceAceptable(LocalProjectService localProjectService, double diffLimit)
|
|
{
|
|
foreach (var attachment in localProjectService.Workpiece.DiffAttachmentBag)
|
|
{
|
|
if (double.IsNaN(attachment.Diff) || Math.Abs(attachment.Diff) > diffLimit)
|
|
{
|
|
Console.WriteLine($"Diff: {attachment.Diff}");
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
</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>
|