using Hi.Wpf.Disp;
using System;
using Hi.MongoUtils;
using Hi.Licenses;
using Hi.MachiningProcs;
using Hi.Common.FileLines;
using Hi.MillingSteps;
using System.Windows;
using Hi.Disp;
namespace Sample.Wpf.Machining
{
///
/// This example demonstrates how to integrate HiAPI's machining visualization capabilities into a WPF application. It utilizes the Hi.Wpf.Disp namespace to render machining processes in a 3D environment and implement user interaction features like strip position selection. The sample shows how to set up the rendering pipeline, handle camera controls, and connect machining data with the visualization system. This example is essential for developers building interactive CAM applications that require both rich visualization capabilities and user interaction with the machining model.
///
///
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Machining/DemoRenderingMachiningProcessAndStripPosSelection.cs)]
///
public static class DemoRenderingMachiningProcessAndStripPosSelection
{
[STAThread]
public static void Main(string[] args)
{
#region Initialize Environment
License.LogInAll();
DispEngine.Init();
MongoServer.Default = MongoServer.Run(new MongoRunnerOptions()
{
MongoPort = 28100
});
#endregion
#region Load Machining Project
var projectPath = "C:/HiNC-Projects/DemoStandardPath/Main.hincproj";
Console.WriteLine($"Load Project: {projectPath}");
MachiningProject machiningProject = MachiningProject.LoadFile(projectPath);
machiningProject.ShellApi.MillingStepSelected += (MillingStep step) =>
{
var sourceCommand = step.SourceCommand;
Console.WriteLine($"Step Selected: MRR = {step.Mrr_mm3ds} At \"{sourceCommand?.FilePath}\" (Line {sourceCommand?.GetLineNo()}) \"{sourceCommand?.Line}\"");
};
machiningProject.PacePlayer.Start();
#endregion
#region Configure Rendering Options
var projectDisplayee = new MachiningProjectDisplayee(machiningProject);
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.Mech] = true;
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.Fixture] = true;
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.WorkpieceGeom] = true;
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.ClStrip] = true;
projectDisplayee.RenderingFlagBitArray[(int)RenderingFlag.DimensionBar] = true;
#endregion
#region Create and Run WPF Application
Application app = new Application
{
ShutdownMode = ShutdownMode.OnMainWindowClose
};
app.Exit += (o, e) =>
{
machiningProject.Dispose();
MongoServer.Default.Dispose();
DispEngine.FinishDisp();
License.LogOutAll();
Console.WriteLine($"App exit.");
};
app.Run(new RenderingWindow()
{
Title = "Demo",
Displayee = projectDisplayee
});
#endregion
}
}
}