Hi.Sample.Wpf/Disp/DemoPick2.cs

79 lines
2.1 KiB
C#

using Hi.Geom;
using Hi.Disp;
using System;
using Hi.Coloring;
namespace Sample.Disp
{
/// <summary>
/// Demonstrates advanced object picking with multiple pickable objects.
/// Shows how to create and manage multiple pickable objects with different visual appearances.
/// Implements proper resource cleanup through the IDisposable interface.
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample.Wpf/Disp/DemoPick2.cs)]
/// </remarks>
public class DemoPick2 : IDisplayee, IDisposable
{
readonly Pickable pickableA = new ShowEventPickable { Tag = "A" };
readonly Pickable pickableB = new ShowEventPickable { Tag = "B" };
readonly Pickable pickableC = new ShowEventPickable { Tag = "C" };
/// <inheritdoc/>
public void Display(Bind bind)
{
bind.PickID = pickableA.PickingID;
bind.RGB = ColorUtil.GetDiscreteRgb(1);
new Box3d(0, 0, 0, 1, 1, 1).DisplayFace(bind);
bind.PickID = pickableB.PickingID;
bind.RGB = ColorUtil.GetDiscreteRgb(2);
new Box3d(0, 0, 1, 1, 1, 2).DisplayFace(bind);
bind.PickID = pickableC.PickingID;
bind.RGB = ColorUtil.GetDiscreteRgb(3);
new Box3d(0, 0, 2, 1, 1, 3).DisplayFace(bind);
bind.PickID = 0;
}
/// <inheritdoc/>
public void ExpandToBox3d(Box3d dst)
{
dst.Expand(new Vec3d(0, 0, 0));
dst.Expand(new Vec3d(1, 1, 3));
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
/// <inheritdoc/>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
pickableA.Dispose();
pickableB.Dispose();
pickableC.Dispose();
}
disposedValue = true;
}
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
}
#endregion
/// <summary>
/// Entry point for the DemoPick2 example.
/// Creates and displays multiple pickable objects with distinct colors and positions.
/// Demonstrates separation of picking behavior from visual representation.
/// </summary>
static void Main()
{
DemoUtil.RunApplication("DemoPick2", new DemoPick2());
}
}
}