merge frame part of DispUtil to DispFrameUtil.

This commit is contained in:
iamboss 2026-02-15 16:08:00 +08:00
parent 688762ab70
commit c1f3fefdc0
3 changed files with 548 additions and 490 deletions

View File

@ -11,20 +11,20 @@ using System.Collections.Generic;
using Hi.Geom;
using Microsoft.Win32; // Add this for SystemEvents
namespace Hi.WpfPlus.Disp
namespace Hi.WpfPlus.Disp;
#region WPF Rendering Canvas
/// <summary>
/// Provides a WPF rendering canvas for 3D visualization of HiAPI components.
/// Handles user interactions, rendering, and integration with the DispEngine system.
/// </summary>
/// <remarks>
/// This canvas provides the core rendering capabilities for WPF applications using HiAPI.
/// It manages mouse, keyboard, and touch events, and transforms them into appropriate
/// actions in the 3D environment.
/// </remarks>
public class RenderingCanvas : UserControl, IDisposable
{
#region WPF Rendering Canvas
/// <summary>
/// Provides a WPF rendering canvas for 3D visualization of HiAPI components.
/// Handles user interactions, rendering, and integration with the DispEngine system.
/// </summary>
/// <remarks>
/// This canvas provides the core rendering capabilities for WPF applications using HiAPI.
/// It manages mouse, keyboard, and touch events, and transforms them into appropriate
/// actions in the 3D environment.
/// </remarks>
public class RenderingCanvas : UserControl, IDisposable
{
#region Core_Properties
/// <summary>
/// The DispEngine instance that handles rendering and user interactions
@ -469,6 +469,5 @@ namespace Hi.WpfPlus.Disp
GC.SuppressFinalize(this);
}
#endregion
}
#endregion
}
#endregion

View File

@ -3,13 +3,13 @@ using System;
using System.Windows;
using System.Windows.Media;
namespace Hi.WpfPlus.Disp
namespace Hi.WpfPlus.Disp;
/// <summary>
/// Window for 3D rendering.
/// </summary>
public class RenderingWindow : Window, IGetDispEngine
{
/// <summary>
/// Window for 3D rendering.
/// </summary>
public class RenderingWindow : Window, IGetDispEngine
{
/// <summary>
/// Gets the rendering canvas control used for displaying 3D content.
/// </summary>
@ -51,5 +51,4 @@ namespace Hi.WpfPlus.Disp
RenderingCanvas.DispEngine.SetViewToHomeView();
}
}
}
}

60
Disp/WpfDisp.cs Normal file
View File

@ -0,0 +1,60 @@
using Google.Protobuf.WellKnownTypes;
using Hi.Disp;
using Hi.Geom;
using System.Collections.Concurrent;
using System.Windows;
namespace Hi.WpfPlus.Disp;
/// <summary>
/// Registers WPF as the display framework for <see cref="DispFrameUtil"/>,
/// supporting multiple windows identified by key.
/// </summary>
/// <remarks>
/// <para>
/// Usage pattern: call <see cref="DispFrameUtil.Call"/> to queue display content,
/// then call <see cref="Run"/> to start the WPF application and show windows.
/// </para>
/// <para>
/// Each unique key creates a separate <see cref="RenderingWindow"/>.
/// Calling <see cref="DispFrameUtil.Call"/> with the same key updates the existing window.
/// </para>
/// <example>
/// <code>
/// // Queue display content (before or after Run)
/// DispFrameUtil.CallDispFrame("Window1", displayee1);
/// DispFrameUtil.CallDispFrame("Window2", displayee2);
/// // Start the WPF application (blocks until all windows are closed)
/// DispFrameWpf.Run();
/// </code>
/// </example>
/// </remarks>
public static class WpfDisp
{
static readonly ConcurrentDictionary<string, RenderingWindow> KeyToWindowDictionary = new();
static WpfDisp()
{
DispFrameUtil.UpdateByDispEngineConfigFunc = ApplyConfig;
}
public static void Init() { }
static void ApplyConfig(string key, DispEngineConfig config)
{
if (!KeyToWindowDictionary.TryGetValue(key, out var window))
{
window = new RenderingWindow() { Title = key };
window.Closed += (s, e) => KeyToWindowDictionary.TryRemove(key, out _);
KeyToWindowDictionary[key] = window;
window.Show();
}
var dispEngine = window.GetDispEngine();
if (config.Displayee != null)
dispEngine.Displayee = config.Displayee;
if (config.SketchView == null)
config.SketchView = config.Displayee?.GetBox3d()?.FrontView;
if (config.SketchView != null)
dispEngine.SketchView = config.SketchView;
}
}