update ISO coordinate rendering for 3+2axis machine.

This commit is contained in:
2026-04-06 15:08:59 +08:00
parent 8dd5309e0e
commit 0fe9497552
219 changed files with 23941 additions and 12629 deletions
@@ -154,57 +154,56 @@ using System.Threading.Tasks;
using Hi.Common;
using Hi.Common.Messages;
namespace Sample.Common
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 common message and exception handling patterns in HiAPI applications
/// Demonstrates normal message handling
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoMessageAndExceptionHandling.cs)]
/// </remarks>
public static class DemoMessageAndExceptionHandling
internal static void DemoNormalMessages()
{
/// <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
{
#region Normal_Messages
MessageHost.ReportMessage("Operation completed successfully.");
MessageHost.ReportWarning("Please check your input.");
#endregion
// Your code here
throw new NotImplementedException("Demo exception");
}
/// <summary>
/// Demonstrates exception handling in synchronous code
/// </summary>
internal static void DemoSynchronousExceptionHandling()
catch (Exception ex)
{
#region Sync_Exception
try
{
// Your code here
throw new NotImplementedException("Demo exception");
}
catch (Exception ex)
{
ExceptionUtil.ShowException(ex, null);
}
#endregion
ExceptionUtil.ShowException(ex, null);
}
/// <summary>
/// Demonstrates exception handling in asynchronous code
/// </summary>
internal static async Task DemoAsynchronousExceptionHandling()
#endregion
}
/// <summary>
/// Demonstrates exception handling in asynchronous code
/// </summary>
internal static async Task DemoAsynchronousExceptionHandling()
{
#region Async_Exception
await Task.Run(() =>
{
#region Async_Exception
await Task.Run(() =>
{
// Your async operation here
throw new NotImplementedException("Demo async exception");
}).ShowIfCatched(null);
#endregion
}
// Your async operation here
throw new NotImplementedException("Demo async exception");
}).ShowIfCatched(null);
#endregion
}
}
</code></pre></div>
@@ -163,138 +163,137 @@ using Hi.Mech;
using Hi.Mech.Topo;
using Hi.Numerical;
namespace Sample.Common
namespace Sample.Common;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoSessionMessage.cs)]
/// &lt;/remarks&gt;
public static class DemoSessionMessage
{
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoSessionMessage.cs)]
/// &lt;/remarks&gt;
public static class DemoSessionMessage
#region Demo_UseSessionMessageHost
internal static void DemoUseSessionMessageHost(LocalProjectService localProjectService)
{
#region Demo_UseSessionMessageHost
internal static void DemoUseSessionMessageHost(LocalProjectService localProjectService)
SessionProgress sessionMessageHost = localProjectService.SessionProgress;
SessionProgress.FilterFlag filterFlags =
SessionProgress.FilterFlag.NC |
SessionProgress.FilterFlag.Progress |
SessionProgress.FilterFlag.Error;
string filterText = null;
var filteredSessionMessageList = sessionMessageHost
.GetFliteredList(filterFlags, filterText);
foreach (var sessionMessage in filteredSessionMessageList)
{
SessionMessageHost sessionMessageHost = localProjectService.SessionMessageHost;
//M.I.: Message Index.
Console.Write($&quot;M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}&quot;);
SessionMessageHost.FilterFlag filterFlags =
SessionMessageHost.FilterFlag.NC |
SessionMessageHost.FilterFlag.Progress |
SessionMessageHost.FilterFlag.Error;
string filterText = null;
var filteredSessionMessageList = sessionMessageHost
.GetFliteredList(filterFlags, filterText);
// For SessionMessageHost.FilterFlag.NC
var nc = sessionMessage.DirectInstantSourceCommand;
if (nc != null)
Console.Write($&quot;Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; &quot;);
foreach (var sessionMessage in filteredSessionMessageList)
{
//M.I.: Message Index.
Console.Write($&quot;M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}&quot;);
// For SessionMessageHost.FilterFlag.NC
var nc = sessionMessage.DirectInstantSourceCommand;
if (nc != null)
Console.Write($&quot;Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; &quot;);
// For SessionMessageHost.FilterFlag.Progress or Error.
var multiTagMessage = sessionMessage.MultiTagMessage;
if (multiTagMessage != null)
Console.WriteLine($&quot;Message/NC: {multiTagMessage.Message}&quot;);
var exception = sessionMessage.Exception;
if (exception != null)
Console.WriteLine($&quot;Message/NC: {exception.Message}&quot;);
}
File.WriteAllLines(&quot;output-session-messages.txt&quot;,
filteredSessionMessageList.Select(m =&gt;
$&quot;Msg[{m.Index}][{m.MessageRoleText}]: {m}&quot;));
// For SessionMessageHost.FilterFlag.Progress or Error.
var multiTagMessage = sessionMessage.MultiTagMessage;
if (multiTagMessage != null)
Console.WriteLine($&quot;Message/NC: {multiTagMessage.Message}&quot;);
var exception = sessionMessage.Exception;
if (exception != null)
Console.WriteLine($&quot;Message/NC: {exception.Message}&quot;);
}
#endregion
internal static void DemoUseSessionMessageHost2(LocalProjectService localProjectService)
{
SessionMessageHost sessionMessageHost = localProjectService.SessionMessageHost;
IMachiningChain machiningChain = localProjectService.MachiningChain;
PresentAttribute mrrPresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.Mrr_mm3ds)).GetCustomAttribute&lt;PresentAttribute&gt;();
string mrrUnit = mrrPresent?.TailUnitString;
string mrrFormat = mrrPresent?.DataFormatString;
PresentAttribute torquePresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.AvgAbsTorque_Nm)).GetCustomAttribute&lt;PresentAttribute&gt;();
string torqueUnit = torquePresent?.TailUnitString;
string torqueFormat = torquePresent?.DataFormatString;
SessionMessageHost.FilterFlag filterFlags =
SessionMessageHost.FilterFlag.Step |
SessionMessageHost.FilterFlag.NC |
SessionMessageHost.FilterFlag.Progress |
SessionMessageHost.FilterFlag.Error;
string filterText = null;
var filteredSessionMessageList = sessionMessageHost
.GetFliteredList(filterFlags, filterText);
foreach (var sessionMessage in filteredSessionMessageList)
{
//M.I.: Message Index.
Console.Write($&quot;M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}&quot;);
// For SessionMessageHost.FilterFlag.Step
var step = sessionMessage.MachiningStep;
if (step != null)
{
string[] machineCoordinateValueTexts = GetMachineCoordinateValueTexts(step, machiningChain);
var machineCoordinatesText = string.Join(&quot;; &quot;, Enumerable.Range(0, machiningChain.McCodes.Length)
.Select(i =&gt; $&quot;MC.{machiningChain.McCodes[i]}: {machineCoordinateValueTexts[i]}&quot;));
Console.Write($&quot;Time: {step.AccumulatedTime:G}; MRR = {step.Mrr_mm3ds.ToString(mrrFormat)} {mrrUnit}; Torque = {step.AvgAbsTorque_Nm?.ToString(torqueFormat)} {torqueUnit}; {machineCoordinatesText}; &quot;);
var nc_ = sessionMessageHost.GetSourceCommand(sessionMessage);
Console.WriteLine($&quot;Message/NC: {nc_.Line}; File: {nc_.FilePath}; LineNo: {nc_.GetLineNo()}&quot;);
}
// For SessionMessageHost.FilterFlag.NC
var nc = sessionMessage.DirectInstantSourceCommand;
if (nc != null)
{
Console.Write($&quot;Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; &quot;);
if (nc is HardNcLine ncLine)
Console.WriteLine($&quot;T: {ncLine.T}; S: {ncLine.S}; F: {ncLine.F}; NC-Flags: {ncLine.FlagsText}&quot;);
}
// For SessionMessageHost.FilterFlag.Progress or Error.
var multiTagMessage = sessionMessage.MultiTagMessage;
if (multiTagMessage != null)
Console.WriteLine($&quot;Message/NC: {multiTagMessage.Message}&quot;);
var exception = sessionMessage.Exception;
if (exception != null)
Console.WriteLine($&quot;Message/NC: {exception.Message}&quot;);
}
}
static string[] GetMachineCoordinateValueTexts(MachiningStep step, IMachiningChain machiningChain)
{
var mcTransformers = machiningChain.McTransformers;
string[] dst = new string[mcTransformers.Length];
if (mcTransformers != null)
{
for (int i = 0; i &lt; mcTransformers.Length; i++)
{
if (mcTransformers[i] == null)
continue;
if (mcTransformers[i] is DynamicRotation)
dst[i] = MathUtil.ToDeg(step.GetMcValue(i).Value).ToString(&quot;F4&quot;);
else
dst[i] = step.GetMcValue(i)?.ToString(&quot;F5&quot;);
}
}
return dst;
}
#region ShowStepPresent
internal static void ShowStepPresent(
UserService userEnv, MachiningStep machiningStep)
{
foreach (var entry in userEnv.DisplayedStepPresentAccessList)
{
var present = entry.Value.Present;
var valueText = string.Format(&quot;{0:&quot; + present.DataFormatString + &quot;}&quot;, entry.Value.GetValueFunc.Invoke(machiningStep));
Console.WriteLine($&quot;{present.ShortName}: {valueText} {present.TailUnitString} ({present.Name} [{entry.Key}])&quot;);
}
}
#endregion
File.WriteAllLines(&quot;output-session-messages.txt&quot;,
filteredSessionMessageList.Select(m =&gt;
$&quot;Msg[{m.Index}][{m.MessageRoleText}]: {m}&quot;));
}
#endregion
internal static void DemoUseSessionMessageHost2(LocalProjectService localProjectService)
{
SessionProgress sessionMessageHost = localProjectService.SessionProgress;
IMachiningChain machiningChain = localProjectService.MachiningChain;
PresentAttribute mrrPresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.Mrr_mm3ds)).GetCustomAttribute&lt;PresentAttribute&gt;();
string mrrUnit = mrrPresent?.TailUnitString;
string mrrFormat = mrrPresent?.DataFormatString;
PresentAttribute torquePresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.AvgAbsTorque_Nm)).GetCustomAttribute&lt;PresentAttribute&gt;();
string torqueUnit = torquePresent?.TailUnitString;
string torqueFormat = torquePresent?.DataFormatString;
SessionProgress.FilterFlag filterFlags =
SessionProgress.FilterFlag.Step |
SessionProgress.FilterFlag.NC |
SessionProgress.FilterFlag.Progress |
SessionProgress.FilterFlag.Error;
string filterText = null;
var filteredSessionMessageList = sessionMessageHost
.GetFliteredList(filterFlags, filterText);
foreach (var sessionMessage in filteredSessionMessageList)
{
//M.I.: Message Index.
Console.Write($&quot;M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}&quot;);
// For SessionMessageHost.FilterFlag.Step
var step = sessionMessage.MachiningStep;
if (step != null)
{
string[] machineCoordinateValueTexts = GetMachineCoordinateValueTexts(step, machiningChain);
var machineCoordinatesText = string.Join(&quot;; &quot;, Enumerable.Range(0, machiningChain.McCodes.Length)
.Select(i =&gt; $&quot;MC.{machiningChain.McCodes[i]}: {machineCoordinateValueTexts[i]}&quot;));
Console.Write($&quot;Time: {step.AccumulatedTime:G}; MRR = {step.Mrr_mm3ds.ToString(mrrFormat)} {mrrUnit}; Torque = {step.AvgAbsTorque_Nm?.ToString(torqueFormat)} {torqueUnit}; {machineCoordinatesText}; &quot;);
var nc_ = sessionMessageHost.GetSourceCommand(sessionMessage);
Console.WriteLine($&quot;Message/NC: {nc_.Line}; File: {nc_.FilePath}; LineNo: {nc_.GetLineNo()}&quot;);
}
// For SessionMessageHost.FilterFlag.NC
var nc = sessionMessage.DirectInstantSourceCommand;
if (nc != null)
{
Console.Write($&quot;Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; &quot;);
if (nc is HardNcLine ncLine)
Console.WriteLine($&quot;T: {ncLine.T}; S: {ncLine.S}; F: {ncLine.F}; NC-Flags: {ncLine.FlagsText}&quot;);
}
// For SessionMessageHost.FilterFlag.Progress or Error.
var multiTagMessage = sessionMessage.MultiTagMessage;
if (multiTagMessage != null)
Console.WriteLine($&quot;Message/NC: {multiTagMessage.Message}&quot;);
var exception = sessionMessage.Exception;
if (exception != null)
Console.WriteLine($&quot;Message/NC: {exception.Message}&quot;);
}
}
static string[] GetMachineCoordinateValueTexts(MachiningStep step, IMachiningChain machiningChain)
{
var mcTransformers = machiningChain.McTransformers;
string[] dst = new string[mcTransformers.Length];
if (mcTransformers != null)
{
for (int i = 0; i &lt; mcTransformers.Length; i++)
{
if (mcTransformers[i] == null)
continue;
if (mcTransformers[i] is DynamicRotation)
dst[i] = MathUtil.ToDeg(step.GetMcValue(i).Value).ToString(&quot;F4&quot;);
else
dst[i] = step.GetMcValue(i)?.ToString(&quot;F5&quot;);
}
}
return dst;
}
#region ShowStepPresent
internal static void ShowStepPresent(
UserService userEnv, MachiningStep machiningStep)
{
foreach (var entry in userEnv.DisplayedStepPresentAccessList)
{
var present = entry.Value.Present;
var valueText = string.Format(&quot;{0:&quot; + present.DataFormatString + &quot;}&quot;, entry.Value.GetValueFunc.Invoke(machiningStep));
Console.WriteLine($&quot;{present.ShortName}: {valueText} {present.TailUnitString} ({present.Name} [{entry.Key}])&quot;);
}
}
#endregion
}
</code></pre></div>
@@ -155,42 +155,40 @@ using System.Collections.Generic;
using Hi.Geom;
using Hi.Mech.Topo;
namespace Sample.Geom
namespace Sample.Geom;
/// &lt;summary&gt;
/// Demonstrates the creation and manipulation of geometric objects in HiAPI.
/// Shows how to create and transform various geometry types including boxes, cylindroids, and STL files.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Geom/DemoBuildGeom.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildGeom
{
/// &lt;summary&gt;
/// Demonstrates the creation and manipulation of geometric objects in HiAPI.
/// Shows how to create and transform various geometry types including boxes, cylindroids, and STL files.
/// Generates a collection of geometric objects for demonstration purposes.
/// Creates various geometry types including boxes, cylindroids, STL files, and transformed geometries.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Geom/DemoBuildGeom.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildGeom
/// &lt;returns&gt;A list of geometries implementing the IGetStl interface&lt;/returns&gt;
public static List&lt;IGetStl&gt; GenGeoms()
{
/// &lt;summary&gt;
/// Generates a collection of geometric objects for demonstration purposes.
/// Creates various geometry types including boxes, cylindroids, STL files, and transformed geometries.
/// &lt;/summary&gt;
/// &lt;returns&gt;A list of geometries implementing the IGetStl interface&lt;/returns&gt;
public static List&lt;IGetStl&gt; GenGeoms()
{
Box3d box = new Box3d(0, 0, -50, 70, 50, 0);
Cylindroid cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
Box3d box = new Box3d(0, 0, -50, 70, 50, 0);
Cylindroid cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
new PairZr(20,16),new PairZr(30,16)]);
Stl stl = new Stl(&quot;geom.stl&quot;);
StlFile stlFile = new StlFile(&quot;geom.stl&quot;);
TransformationGeom transformationGeom = new TransformationGeom()
{
Transformer = new GeneralTransform(1,
new StaticRotation(new Vec3d(0, 0, 1), MathUtil.ToRad(15), new Vec3d(0, 0, 0)),
new StaticTranslation(new Vec3d(0, 0, 0))),
Geom = stl
};
GeomCombination geomCombination = new GeomCombination(stlFile, transformationGeom);
return new List&lt;IGetStl&gt;([box, cylindroid, stl, stlFile, transformationGeom]);
}
Stl stl = new Stl(&quot;geom.stl&quot;);
StlFile stlFile = new StlFile(&quot;geom.stl&quot;);
TransformationGeom transformationGeom = new TransformationGeom()
{
Transformer = new GeneralTransform(1,
new StaticRotation(new Vec3d(0, 0, 1), MathUtil.ToRad(15), new Vec3d(0, 0, 0)),
new StaticTranslation(new Vec3d(0, 0, 0))),
Geom = stl
};
GeomCombination geomCombination = new GeomCombination(stlFile, transformationGeom);
return new List&lt;IGetStl&gt;([box, cylindroid, stl, stlFile, transformationGeom]);
}
}
</code></pre></div>
@@ -153,29 +153,28 @@ Shows the use of Box3d to encompass multiple geometric elements with a single bo
<pre><code class="lang-csharp" name="SampleCode">using Hi.Geom;
using System;
namespace Sample.Geom
{
/// &lt;summary&gt;
/// Demonstrates how to create and calculate bounding boxes for different geometric objects.
/// Shows the use of Box3d to encompass multiple geometric elements with a single boundary.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Geom/DemoIExpandToBox3d.cs)]
/// &lt;/remarks&gt;
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);
namespace Sample.Geom;
Box3d boundingbox = new Box3d(objA, objB, objC);
Console.WriteLine(&quot;boundingbox: &quot; + boundingbox);
#endregion
}
/// &lt;summary&gt;
/// Demonstrates how to create and calculate bounding boxes for different geometric objects.
/// Shows the use of Box3d to encompass multiple geometric elements with a single boundary.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Geom/DemoIExpandToBox3d.cs)]
/// &lt;/remarks&gt;
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(&quot;boundingbox: &quot; + boundingbox);
#endregion
}
}
</code></pre></div>
@@ -154,29 +154,28 @@ using Hi.Mech.Topo;
using Hi.NcMech.Xyzabc;
using Hi.Numerical.Xyzabc;
namespace Sample.MachineTool
namespace Sample.MachineTool;
/// &lt;summary&gt;
/// Demo Build Machine Tool without gemetries setting.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildMachineToolWithoutGeometrys
{
/// &lt;summary&gt;
/// Demo Build Machine Tool without gemetries setting.
/// Generates an empty machine tool with basic configuration.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/MachineTool/DemoBuildMachineToolWithoutGeometrys.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildMachineToolWithoutGeometrys
/// &lt;returns&gt;A configured but empty machine tool without solids.&lt;/returns&gt;
public static CodeXyzabcMachineTool GenEmptyMachineTool()
{
/// &lt;summary&gt;
/// Generates an empty machine tool with basic configuration.
/// &lt;/summary&gt;
/// &lt;returns&gt;A configured but empty machine tool without solids.&lt;/returns&gt;
public static CodeXyzabcMachineTool GenEmptyMachineTool()
{
CodeXyzabcChain chain = new CodeXyzabcChain(&quot;[O][C][w];[O][X][Y][Z][B][S][t]&quot;);
if (chain.ToolBuckleTransformer is StaticTranslation st)
st.Trans = new Vec3d(-200, 200, 400);
CodeXyzabcMachineTool xyzabcMachineTool = new CodeXyzabcMachineTool(chain);
return xyzabcMachineTool;
}
CodeXyzabcChain chain = new CodeXyzabcChain(&quot;[O][C][w];[O][X][Y][Z][B][S][t]&quot;);
if (chain.ToolBuckleTransformer is StaticTranslation st)
st.Trans = new Vec3d(-200, 200, 400);
CodeXyzabcMachineTool xyzabcMachineTool = new CodeXyzabcMachineTool(chain);
return xyzabcMachineTool;
}
}
</code></pre></div>
@@ -165,85 +165,84 @@ using Hi.Machining;
using Hi.HiNcKits;
using Hi.Milling.MillingTools;
namespace Sample.Machining
namespace Sample.Machining;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildGeomOnlyMachiningProject.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildGeomOnlyMachiningProject
{
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildGeomOnlyMachiningProject.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildGeomOnlyMachiningProject
internal static MillingCutter CreateGeomOnlyMillingCutter()
{
internal static MillingCutter CreateGeomOnlyMillingCutter()
MillingCutter millingCutter = new MillingCutter()
{
MillingCutter millingCutter = new MillingCutter()
UpperBeamGeom = new Cylindroid(
[new PairZr(40, 6), new PairZr(90, 6)]),
ShaperProfile = new AptProfile(
new ColumnApt()
{
UpperBeamGeom = new Cylindroid(
[new PairZr(40,6), new PairZr(90,6)]),
ShaperProfile = new AptProfile(
new ColumnApt()
{
Diameter_mm = 12,
FluteHeight_mm = 40
})
};
Diameter_mm = 12,
FluteHeight_mm = 40
})
};
return millingCutter;
}
return millingCutter;
}
static void Main()
static void Main()
{
LocalApp.AppBegin();
LocalProjectService localProjectService = new LocalProjectService();
var projectPath = &quot;C:/HiNC-Projects/NewProject/Main.hincproj&quot;;
var projectDirectory = Path.GetDirectoryName(projectPath);
Console.WriteLine($&quot;Directory of the New Project: {projectDirectory}&quot;);
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
CylindroidHolder cylindroidHolder = new CylindroidHolder()
{
LocalApp.AppBegin();
LocalProjectService localProjectService = new LocalProjectService();
var projectPath = &quot;C:/HiNC-Projects/NewProject/Main.hincproj&quot;;
var projectDirectory = Path.GetDirectoryName(projectPath);
Console.WriteLine($&quot;Directory of the New Project: {projectDirectory}&quot;);
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
CylindroidHolder cylindroidHolder = new CylindroidHolder()
{
Note = &quot;BT40&quot;,
Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
Note = &quot;BT40&quot;,
Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
new PairZr(20,16),new PairZr(30,16)])
};
localProjectService.MachiningToolHouse = new MachiningToolHouse()
};
localProjectService.MachiningToolHouse = new MachiningToolHouse()
{
[1] = new MillingTool()
{
[1] = new MillingTool()
{
Note = &quot;T1&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = cylindroidHolder,
Cutter = CreateGeomOnlyMillingCutter()
},
};
Note = &quot;T1&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = cylindroidHolder,
Cutter = CreateGeomOnlyMillingCutter()
},
};
localProjectService.Fixture = new Fixture()
{
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
};
localProjectService.Fixture = new Fixture()
{
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
};
localProjectService.Workpiece = new Workpiece()
{
InitResolution = 0.25,
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
IdealGeom = null,
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
};
localProjectService.Workpiece = new Workpiece()
{
InitResolution = 0.25,
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
IdealGeom = null,
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
};
localProjectService.MachiningChain
localProjectService.MachiningChain
= XFactory.GenByFile&lt;CodeXyzabcMachineTool&gt;(
&quot;Resource&quot;, &quot;MachineTool/PMC-B1/PMC-B1.mt&quot;, GenMode.Default);
localProjectService.MachiningChainFile = &quot;PMC-B1/PMC-B1.mt&quot;;
localProjectService.MachiningChainFile = &quot;PMC-B1/PMC-B1.mt&quot;;
localProjectService.SaveProject();
machiningProject.Dispose();
LocalApp.AppEnd();
}
localProjectService.SaveProject();
machiningProject.Dispose();
LocalApp.AppEnd();
}
}
</code></pre></div>
@@ -172,201 +172,200 @@ using System.IO;
using Hi.HiNcKits;
using Hi.Milling.MillingTools;
namespace Sample.Machining
namespace Sample.Machining;
/// &lt;summary&gt;
/// Demonstrates how to create and configure a &lt;see cref=&quot;MachiningProject&quot;/&gt; programmatically.
/// This sample shows how to set up &lt;see cref=&quot;MillingCutter&quot;/&gt;, &lt;see cref=&quot;CylindroidHolder&quot;/&gt;,
/// &lt;see cref=&quot;MillingTool&quot;/&gt;, &lt;see cref=&quot;Fixture&quot;/&gt;, &lt;see cref=&quot;Workpiece&quot;/&gt;,
/// and save the project configuration to a file.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildMachiningProject.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildMachiningProject
{
/// &lt;summary&gt;
/// Demonstrates how to create and configure a &lt;see cref=&quot;MachiningProject&quot;/&gt; programmatically.
/// This sample shows how to set up &lt;see cref=&quot;MillingCutter&quot;/&gt;, &lt;see cref=&quot;CylindroidHolder&quot;/&gt;,
/// &lt;see cref=&quot;MillingTool&quot;/&gt;, &lt;see cref=&quot;Fixture&quot;/&gt;, &lt;see cref=&quot;Workpiece&quot;/&gt;,
/// and save the project configuration to a file.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoBuildMachiningProject.cs)]
/// &lt;/remarks&gt;
public static class DemoBuildMachiningProject
internal static CylindroidHolder CreateCylindroidHolder()
{
internal static CylindroidHolder CreateCylindroidHolder()
#region ConfigureHolder
CylindroidHolder cylindroidHolder = new CylindroidHolder()
{
#region ConfigureHolder
CylindroidHolder cylindroidHolder = new CylindroidHolder()
{
Note = &quot;BT40&quot;,
Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
Note = &quot;BT40&quot;,
Cylindroid = new Cylindroid([ new PairZr(0,12),new PairZr(20,12),
new PairZr(20,16),new PairZr(30,16)])
};
#endregion
return cylindroidHolder;
}
#region CreateMillingCutter1
internal static MillingCutter CreateMillingCutter1()
{
double diameter_mm = 12;
double roundRadius_mm = 0.5;
MillingCutter millingCutter = new MillingCutter()
{
ShaperProfile = new AptProfile(
new ColumnApt()
{
Diameter_mm = diameter_mm,
Rc_mm = roundRadius_mm,
FluteHeight_mm = 40
}),
UpperBeamGeom = new ExtendedCylinder(90),
InnerBeamProfile = new FluteDependentRatioProfile(),
MillingCutterOptLimit = new MillingCutterOptOption(),
};
//build FluteContourTray property
double helixAngle_deg = 50;
double radialRakeAngle_deg = 15;
double bottomOuterRadius_mm = diameter_mm / 2 - roundRadius_mm;
millingCutter.FluteContourTray = new UniformContourTray()
{
TrackNum = 3,
BaselineOneContour = new FluteContour()
{
BaseSideContour = new ConstHelixSideContour(millingCutter)
{
Helix_deg = helixAngle_deg,
RadialRakeAngle_deg = radialRakeAngle_deg
},
BaseBottomContour = new SlideBottomContour()
{
//In most case, helix angle from side equal to rake angle from bottom.
AxialRakeAngle_deg = MathUtil.ToDeg(helixAngle_deg),
DiskAngle_deg = 1.5,
//In most case, rake angle from side equal to eccentric angle from bottom.
EccentricAngle_deg = radialRakeAngle_deg,
CutterLengthOnBottomProjection_mm = bottomOuterRadius_mm * 0.9,
OuterRadius_mm = bottomOuterRadius_mm
}
}
};
return millingCutter;
}
};
#endregion
return cylindroidHolder;
}
#region CreateMillingCutter2
internal static MillingCutter CreateMillingCutter2()
#region CreateMillingCutter1
internal static MillingCutter CreateMillingCutter1()
{
double diameter_mm = 12;
double roundRadius_mm = 0.5;
MillingCutter millingCutter = new MillingCutter()
{
MillingCutter millingCutter = new MillingCutter()
{
ShaperProfile = new AptProfile(new ColumnApt()
ShaperProfile = new AptProfile(
new ColumnApt()
{
Diameter_mm = 12,
Diameter_mm = diameter_mm,
Rc_mm = roundRadius_mm,
FluteHeight_mm = 40
}),
UpperBeamGeom = new Cylindroid(
[new PairZr(40, 6), new PairZr(90, 6)]),
InnerBeamProfile = new FluteDependentRatioProfile(),
MillingCutterOptLimit = new MillingCutterOptOption()
};
//build FluteContourTray property
double helixAngle_deg = 50;
double radialRakeAngle_deg = 15;
millingCutter.FluteContourTray = new UniformContourTray()
UpperBeamGeom = new ExtendedCylinder(90),
InnerBeamProfile = new FluteDependentRatioProfile(),
MillingCutterOptLimit = new MillingCutterOptOption(),
};
//build FluteContourTray property
double helixAngle_deg = 50;
double radialRakeAngle_deg = 15;
double bottomOuterRadius_mm = diameter_mm / 2 - roundRadius_mm;
millingCutter.FluteContourTray = new UniformContourTray()
{
TrackNum = 3,
BaselineOneContour = new FluteContour()
{
TrackNum = 3,
BaselineOneContour = new FluteContour()
BaseSideContour = new ConstHelixSideContour(millingCutter)
{
BaseSideContour = new ConstHelixSideContour(millingCutter)
{
Helix_deg = helixAngle_deg,
RadialRakeAngle_deg = radialRakeAngle_deg
},
//since no bottom cut, set bottom contour to null.
BaseBottomContour = null
Helix_deg = helixAngle_deg,
RadialRakeAngle_deg = radialRakeAngle_deg
},
BaseBottomContour = new SlideBottomContour()
{
//In most case, helix angle from side equal to rake angle from bottom.
AxialRakeAngle_deg = MathUtil.ToDeg(helixAngle_deg),
DiskAngle_deg = 1.5,
//In most case, rake angle from side equal to eccentric angle from bottom.
EccentricAngle_deg = radialRakeAngle_deg,
CutterLengthOnBottomProjection_mm = bottomOuterRadius_mm * 0.9,
OuterRadius_mm = bottomOuterRadius_mm
}
};
}
};
return millingCutter;
}
#endregion
internal static CustomSpinningProfile CreateCustomSpinningProfile()
{
return new CustomSpinningProfile(
new Cylindroid(new PairZr(0, 4), new PairZr(50, 4)));
}
#region TestMethod
[STAThread]
static void Main()
{
LocalApp.AppBegin();
LocalProjectService localProjectService = new LocalProjectService();
var projectPath = &quot;C:/HiNC-Projects/NewProject/Main.hincproj&quot;;
var projectDirectory = Path.GetDirectoryName(projectPath);
Console.WriteLine($&quot;Directory of the New Project: {projectDirectory}&quot;);
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
#region ConfigureMachiningToolHouse
localProjectService.MachiningToolHouse = new MachiningToolHouse()
{
[1] = new MillingTool()
{
Note = &quot;T1&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = CreateCylindroidHolder(),
Cutter = CreateMillingCutter1()
},
[2] = new MillingTool()
{
Note = &quot;T2&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = CreateCylindroidHolder(),
Cutter = CreateMillingCutter2()
},
[3] = new MillingTool()
{
Note = &quot;T3&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = CreateCylindroidHolder(),
Cutter = CreateMillingCutter1()
},
};
#endregion
#region ConfigureFixture
localProjectService.Fixture = new Fixture()
{
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
};
#endregion
#region ConfigureWorkpiece
localProjectService.Workpiece = new Workpiece()
{
InitResolution = 0.25,
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
IdealGeom = null,
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
CuttingPara = XFactory.GenByFile&lt;ICuttingPara&gt;(
&quot;Resource/CuttingParameter&quot;, &quot;Al6061T6.mp&quot;, GenMode.Default),
WorkpieceMaterial = XFactory.GenByFile&lt;WorkpieceMaterial&gt;(
&quot;Resource/WorkpieceMaterial&quot;, &quot;Al6061T6.WorkpieceMaterial&quot;, GenMode.Default),
};
#endregion
#region ConfigureMachineChain
localProjectService.MachiningChain
= XFactory.GenByFile&lt;CodeXyzabcMachineTool&gt;(
&quot;Resource&quot;, &quot;MachineTool/PMC-B1/PMC-B1.mt&quot;, GenMode.Default);
#endregion
machiningProject.MakeXmlSourceToFile(projectPath);
machiningProject.Dispose();
LocalApp.AppEnd();
}
#endregion
return millingCutter;
}
#endregion
#region CreateMillingCutter2
internal static MillingCutter CreateMillingCutter2()
{
MillingCutter millingCutter = new MillingCutter()
{
ShaperProfile = new AptProfile(new ColumnApt()
{
Diameter_mm = 12,
FluteHeight_mm = 40
}),
UpperBeamGeom = new Cylindroid(
[new PairZr(40, 6), new PairZr(90, 6)]),
InnerBeamProfile = new FluteDependentRatioProfile(),
MillingCutterOptLimit = new MillingCutterOptOption()
};
//build FluteContourTray property
double helixAngle_deg = 50;
double radialRakeAngle_deg = 15;
millingCutter.FluteContourTray = new UniformContourTray()
{
TrackNum = 3,
BaselineOneContour = new FluteContour()
{
BaseSideContour = new ConstHelixSideContour(millingCutter)
{
Helix_deg = helixAngle_deg,
RadialRakeAngle_deg = radialRakeAngle_deg
},
//since no bottom cut, set bottom contour to null.
BaseBottomContour = null
}
};
return millingCutter;
}
#endregion
internal static CustomSpinningProfile CreateCustomSpinningProfile()
{
return new CustomSpinningProfile(
new Cylindroid(new PairZr(0, 4), new PairZr(50, 4)));
}
#region TestMethod
[STAThread]
static void Main()
{
LocalApp.AppBegin();
LocalProjectService localProjectService = new LocalProjectService();
var projectPath = &quot;C:/HiNC-Projects/NewProject/Main.hincproj&quot;;
var projectDirectory = Path.GetDirectoryName(projectPath);
Console.WriteLine($&quot;Directory of the New Project: {projectDirectory}&quot;);
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
#region ConfigureMachiningToolHouse
localProjectService.MachiningToolHouse = new MachiningToolHouse()
{
[1] = new MillingTool()
{
Note = &quot;T1&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = CreateCylindroidHolder(),
Cutter = CreateMillingCutter1()
},
[2] = new MillingTool()
{
Note = &quot;T2&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = CreateCylindroidHolder(),
Cutter = CreateMillingCutter2()
},
[3] = new MillingTool()
{
Note = &quot;T3&quot;,
PreservedDistanceBetweenFluteAndSpindleNose_mm = 8,
Holder = CreateCylindroidHolder(),
Cutter = CreateMillingCutter1()
},
};
#endregion
#region ConfigureFixture
localProjectService.Fixture = new Fixture()
{
Geom = new Box3d(new Vec3d(-40, -40, 0), new Vec3d(40, 40, 10)),
GeomToWorkpieceTransformer = new StaticTranslation(new Vec3d(0, 0, 10)),
};
#endregion
#region ConfigureWorkpiece
localProjectService.Workpiece = new Workpiece()
{
InitResolution = 0.25,
InitGeom = new Box3d(0, 0, -50, 70, 50, 0),
IdealGeom = null,
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
CuttingPara = XFactory.GenByFile&lt;ICuttingPara&gt;(
&quot;Resource/CuttingParameter&quot;, &quot;Al6061T6.mp&quot;, GenMode.Default),
WorkpieceMaterial = XFactory.GenByFile&lt;WorkpieceMaterial&gt;(
&quot;Resource/WorkpieceMaterial&quot;, &quot;Al6061T6.WorkpieceMaterial&quot;, GenMode.Default),
};
#endregion
#region ConfigureMachineChain
localProjectService.MachiningChain
= XFactory.GenByFile&lt;CodeXyzabcMachineTool&gt;(
&quot;Resource&quot;, &quot;MachineTool/PMC-B1/PMC-B1.mt&quot;, GenMode.Default);
#endregion
machiningProject.MakeXmlSourceToFile(projectPath);
machiningProject.Dispose();
LocalApp.AppEnd();
}
#endregion
}
</code></pre></div>
@@ -159,38 +159,38 @@ using Hi.MachiningProcs;
using System;
using System.IO;
namespace Sample.Machining
namespace Sample.Machining;
/// &lt;summary&gt;
/// Demonstrates how to load and use an existing &lt;see cref=&quot;MachiningProject&quot;/&gt; instance.
/// This sample shows how to set up event handlers for messages and machining step objects,
/// execute NC files, and properly manage project resources using
/// &lt;see cref=&quot;IDisposable.Dispose&quot;/&gt;.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoUseMachiningProject.cs)]
/// &lt;/remarks&gt;
public static class DemoUseMachiningProject
{
/// &lt;summary&gt;
/// Demonstrates how to load and use an existing &lt;see cref=&quot;MachiningProject&quot;/&gt; instance.
/// This sample shows how to set up event handlers for messages and machining step objects,
/// execute NC files, and properly manage project resources using
/// &lt;see cref=&quot;IDisposable.Dispose&quot;/&gt;.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Machining/DemoUseMachiningProject.cs)]
/// &lt;/remarks&gt;
public static class DemoUseMachiningProject
static void Main()
{
static void Main()
{
LocalApp.AppBegin();
LocalProjectService localProjectService = new LocalProjectService();
LocalApp.AppBegin();
LocalProjectService localProjectService = new LocalProjectService();
#region ProjectLoading
var projectPath = &quot;C:/HiNC-Projects/DemoStandardPath/Main.hincproj&quot;;
Console.WriteLine($&quot;Load Project: {projectPath}&quot;);
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
#endregion
#region ProjectLoading
var projectPath = &quot;C:/HiNC-Projects/DemoStandardPath/Main.hincproj&quot;;
Console.WriteLine($&quot;Load Project: {projectPath}&quot;);
localProjectService.LoadProject(projectPath);
MachiningProject machiningProject = localProjectService.MachiningProject;
#endregion
#region EventHandling
Console.WriteLine($&quot;Set message event.&quot;);
#region EventHandling
Console.WriteLine($&quot;Set message event.&quot;);
using StreamWriter writer = new StreamWriter(&quot;msg.txt&quot;);
//show message if something abnormal.
localProjectService.SessionMessageHost.CollectionItemAdded += pack =&gt;
using StreamWriter writer = new StreamWriter(&quot;msg.txt&quot;);
//show message if something abnormal.
localProjectService.SessionProgress.CollectionItemAdded += pack =&gt;
{
if (pack.Tags.Contains(MessageFlag.Warning.ToString()) ||
pack.Tags.Contains(MessageFlag.Error.ToString()) ||
@@ -200,42 +200,42 @@ namespace Sample.Machining
writer.WriteLine($&quot;{pack.Message} At \&quot;{sourceCommand?.FilePath}\&quot; (Line {sourceCommand?.GetLineNo()}) \&quot;{sourceCommand?.Line}\&quot;&quot;);
}
};
Console.WriteLine($&quot;Set machining step event.&quot;);
//show MRR.
localProjectService.RuntimeApi.MachiningStepBuilt += (preStep, curStep) =&gt;
Console.WriteLine($&quot;Set machining step event.&quot;);
//show MRR.
localProjectService.RuntimeApi.MachiningStepBuilt += (preStep, curStep) =&gt;
{
var sourceCommand = curStep.SourceCommand;
var indexedFileLine=sourceCommand?.GetSentence()?.IndexedFileLine;
if (curStep.Mrr_mm3ds &gt; 500) //show only the step that contains large MRR.
Console.WriteLine($&quot;MRR = {curStep.Mrr_mm3ds} At \&quot;{sourceCommand?.FilePath}\&quot; (Line {sourceCommand?.GetLineNo()}) \&quot;{sourceCommand?.Line}\&quot;&quot;);
Console.WriteLine($&quot;MRR = {curStep.Mrr_mm3ds} At \&quot;{indexedFileLine?.FilePath}\&quot; (Line {indexedFileLine?.GetLineNo()}) \&quot;{indexedFileLine?.Line}\&quot;&quot;);
};
#endregion
#endregion
#region MachiningExecution
Console.WriteLine($&quot;Reset runtime status.&quot;);
localProjectService.ResetRuntime();
#region MachiningExecution
Console.WriteLine($&quot;Reset runtime status.&quot;);
localProjectService.ResetRuntime();
Console.WriteLine($&quot;Session begin.&quot;);
localProjectService.BeginSession();
localProjectService.RuntimeApi.MachiningResolution_mm = 1;
localProjectService.RuntimeApi.EnableCollisionDetection = true;
localProjectService.RuntimeApi.EnablePauseOnFailure = false;
localProjectService.RuntimeApi.EnablePhysics = false;
//the path from Shell-API is relative by project directory.
localProjectService.RuntimeApi.PlayNcFile(&quot;NC/side.ptp&quot;);
localProjectService.RuntimeApi.PlayNcFile(&quot;NC/circle.ptp&quot;);
localProjectService.EndSession();
Console.WriteLine($&quot;Session end.&quot;);
#endregion
Console.WriteLine($&quot;Session begin.&quot;);
localProjectService.BeginSession();
localProjectService.RuntimeApi.MachiningResolution_mm = 1;
localProjectService.RuntimeApi.EnableCollisionDetection = true;
localProjectService.RuntimeApi.EnablePauseOnFailure = false;
localProjectService.RuntimeApi.EnablePhysics = false;
//the path from Shell-API is relative by project directory.
localProjectService.RuntimeApi.PlayNcFile(&quot;NC/side.ptp&quot;);
localProjectService.RuntimeApi.PlayNcFile(&quot;NC/circle.ptp&quot;);
localProjectService.EndSession();
Console.WriteLine($&quot;Session end.&quot;);
#endregion
#region CleanupResources
Console.WriteLine($&quot;Close Project: {projectPath}&quot;);
machiningProject.Dispose();
#region CleanupResources
Console.WriteLine($&quot;Close Project: {projectPath}&quot;);
machiningProject.Dispose();
LocalApp.AppEnd();
LocalApp.AppEnd();
Console.WriteLine($&quot;Program end.&quot;);
#endregion
}
Console.WriteLine($&quot;Program end.&quot;);
#endregion
}
}
</code></pre></div>