add geom GUI to HiNC-2025-win-desktop.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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
|
||||
MessageKit.AddMessage("Operation completed successfully.");
|
||||
MessageKit.AddWarning("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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Hi.Common;
|
||||
using Hi.Common.FileLines;
|
||||
using Hi.Geom;
|
||||
using Hi.HiNcKits;
|
||||
using Hi.MachiningProcs;
|
||||
using Hi.MachiningSteps;
|
||||
using Hi.Mech;
|
||||
using Hi.Mech.Topo;
|
||||
using Hi.Numerical;
|
||||
|
||||
namespace Sample.Common
|
||||
{
|
||||
/// <remarks>
|
||||
/// ### Source Code
|
||||
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoSessionMessage.cs)]
|
||||
/// </remarks>
|
||||
public static class DemoSessionMessage
|
||||
{
|
||||
#region Demo_UseSessionMessageHost
|
||||
internal static void DemoUseSessionMessageHost(MachiningProject project)
|
||||
{
|
||||
SessionMessageHost sessionMessageHost = project.SessionMessageHost;
|
||||
|
||||
SessionMessageHost.FilterFlag filterFlags =
|
||||
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($"M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}");
|
||||
|
||||
// For SessionMessageHost.FilterFlag.NC
|
||||
var nc = sessionMessage.DirectInstantSourceCommand;
|
||||
if (nc != null)
|
||||
Console.Write($"Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; ");
|
||||
|
||||
// For SessionMessageHost.FilterFlag.Progress or Error.
|
||||
var multiTagMessage = sessionMessage.MultiTagMessage;
|
||||
if (multiTagMessage != null)
|
||||
Console.WriteLine($"Message/NC: {multiTagMessage.Message}");
|
||||
var exception = sessionMessage.Exception;
|
||||
if (exception != null)
|
||||
Console.WriteLine($"Message/NC: {exception.Message}");
|
||||
}
|
||||
File.WriteAllLines("output-session-messages.txt",
|
||||
filteredSessionMessageList.Select(m =>
|
||||
$"Msg[{m.Index}][{m.MessageRoleText}]: {m}"));
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal static void DemoUseSessionMessageHost2(MachiningProject project)
|
||||
{
|
||||
SessionMessageHost sessionMessageHost = project.SessionMessageHost;
|
||||
IMachiningChain machiningChain = project.MachiningEquipment?.MachiningChain;
|
||||
|
||||
PresentAttribute mrrPresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.Mrr_mm3ds)).GetCustomAttribute<PresentAttribute>();
|
||||
string mrrUnit = mrrPresent?.TailUnitString;
|
||||
string mrrFormat = mrrPresent?.DataFormatString;
|
||||
PresentAttribute torquePresent = typeof(MachiningStep).GetProperty(nameof(MachiningStep.AvgAbsTorque_Nm)).GetCustomAttribute<PresentAttribute>();
|
||||
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($"M.I.: {sessionMessage.Index}; Role: {sessionMessage.MessageRoleText}");
|
||||
|
||||
// For SessionMessageHost.FilterFlag.Step
|
||||
var step = sessionMessage.MachiningStep;
|
||||
if (step != null)
|
||||
{
|
||||
string[] machineCoordinateValueTexts = GetMachineCoordinateValueTexts(step, machiningChain);
|
||||
var machineCoordinatesText = string.Join("; ", Enumerable.Range(0, machiningChain.McCodes.Length)
|
||||
.Select(i => $"MC.{machiningChain.McCodes[i]}: {machineCoordinateValueTexts[i]}"));
|
||||
Console.Write($"Time: {step.AccumulatedTime:G}; MRR = {step.Mrr_mm3ds.ToString(mrrFormat)} {mrrUnit}; Torque = {step.AvgAbsTorque_Nm?.ToString(torqueFormat)} {torqueUnit}; {machineCoordinatesText}; ");
|
||||
var nc_ = sessionMessageHost.GetSourceCommand(sessionMessage);
|
||||
Console.WriteLine($"Message/NC: {nc_.Line}; File: {nc_.FilePath}; LineNo: {nc_.GetLineNo()}");
|
||||
}
|
||||
|
||||
// For SessionMessageHost.FilterFlag.NC
|
||||
var nc = sessionMessage.DirectInstantSourceCommand;
|
||||
if (nc != null)
|
||||
{
|
||||
Console.Write($"Message/NC: {nc.Line}; File: {nc.FilePath}; LineNo: {nc.GetLineNo()}; ");
|
||||
if (nc is NcLine ncLine)
|
||||
Console.WriteLine($"T: {ncLine.T}; S: {ncLine.S}; F: {ncLine.F}; NC-Flags: {ncLine.FlagsText}");
|
||||
}
|
||||
|
||||
// For SessionMessageHost.FilterFlag.Progress or Error.
|
||||
var multiTagMessage = sessionMessage.MultiTagMessage;
|
||||
if (multiTagMessage != null)
|
||||
Console.WriteLine($"Message/NC: {multiTagMessage.Message}");
|
||||
var exception = sessionMessage.Exception;
|
||||
if (exception != null)
|
||||
Console.WriteLine($"Message/NC: {exception.Message}");
|
||||
}
|
||||
}
|
||||
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 < mcTransformers.Length; i++)
|
||||
{
|
||||
if (mcTransformers[i] == null)
|
||||
continue;
|
||||
if (mcTransformers[i] is DynamicRotation)
|
||||
dst[i] = MathUtil.ToDeg(step.GetMcValue(i).Value).ToString("F4");
|
||||
else
|
||||
dst[i] = step.GetMcValue(i)?.ToString("F5");
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
#region ShowStepPresent
|
||||
internal static void ShowStepPresent(
|
||||
UserEnv userEnv, MachiningStep machiningStep)
|
||||
{
|
||||
foreach (var entry in userEnv.DisplayedStepPresentAccessList)
|
||||
{
|
||||
var present = entry.Value.Present;
|
||||
var valueText = string.Format("{0:" + present.DataFormatString + "}", entry.Value.GetValueFunc.Invoke(machiningStep));
|
||||
Console.WriteLine($"{present.ShortName}: {valueText} {present.TailUnitString} ({present.Name} [{entry.Key}])");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user