This commit is contained in:
iambossTC 2025-04-14 17:03:37 +08:00
parent 90fe4a916a
commit 3346f74edc
3 changed files with 116 additions and 101 deletions

View File

@ -1,91 +1,103 @@
using Hi.Disp; using Hi.Disp;
using Hi.Disp.Flag;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using System.ComponentModel;
namespace Hi.WinForm.Disp namespace Hi.WinForm.Disp
{ {
/// <summary> /// <summary>
/// A <see cref="Form"/> contains <see cref="RenderingCanvas"/>. /// A <see cref="Form"/> contains <see cref="Disp.RenderingCanvas"/>.
/// This class is usually used for debug due to its simplicity. /// This class is usually used for debug due to its simplicity.
/// </summary> /// </summary>
public partial class RenderingForm : Form,IGetDispEngine public partial class RenderingForm : Form, IGetDispEngine
{ {
static readonly Form seedForm = new Form(); static readonly Form seedForm = new Form();
private static readonly ConcurrentDictionary<string, RenderingForm> displayerMap private static readonly ConcurrentDictionary<string, RenderingForm> displayerMap
= new ConcurrentDictionary<string, RenderingForm>(4, 4); = new ConcurrentDictionary<string, RenderingForm>(4, 4);
/// <summary> /// <summary>
/// See <see cref="Call(string, IDisplayee[])"/> to get the information. /// See <see cref="Call(string, IDisplayee[])"/> to get the information.
/// </summary> /// </summary>
public static ConcurrentDictionary<string, RenderingForm> DisplayerMap { get => displayerMap; } public static ConcurrentDictionary<string, RenderingForm> DisplayerMap { get => displayerMap; }
/// <summary> /// <summary>
/// Ctor. /// Ctor.
/// </summary> /// </summary>
/// <param name="displayees">displayees</param> /// <param name="displayees">displayees</param>
internal RenderingForm(params IDisplayee[] displayees) internal RenderingForm(params IDisplayee[] displayees)
{ {
InitializeComponent(); InitializeComponent();
Displayer = new RenderingCanvas(displayees); RenderingCanvas = new RenderingCanvas(displayees);
this.Controls.Add(Displayer); this.Controls.Add(RenderingCanvas);
//Displayer.DispEngine.Start(); //Displayer.DispEngine.Start();
} }
/// <summary> /// <summary>
/// The contained <see cref="RenderingCanvas"/>. /// The contained <see cref="Disp.RenderingCanvas"/>.
/// </summary> /// </summary>
public RenderingCanvas Displayer { get; } public RenderingCanvas RenderingCanvas { get; }
/// <summary> [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
/// Create and obtain a <see cref="RenderingForm"/> if the key has not existed; Otherwise, the old one is obtained. public IDisplayee Displayee
/// <paramref name="displayees"/> are set to the obtained <see cref="RenderingForm"/>. {
/// The dictionary of this function is <see cref="DisplayerMap"/>. get => GetDispEngine().Displayee;
/// </summary> set
/// <param name="key">key</param> {
/// <param name="displayees">The displayees set to the obtained <see cref="RenderingForm"/>.</param> var preDisplayee = GetDispEngine().Displayee;
/// <returns>A <see cref="RenderingForm"/> obtained by the key.</returns> GetDispEngine().Displayee = value;
public static RenderingForm Call(string key, params IDisplayee[] displayees) if (preDisplayee == null)
{ RenderingCanvas.DispEngine.SetViewToHomeView();
if (displayerMap.TryGetValue(key, out RenderingForm f)) }
{ }
f.Displayer.DispEngine.Displayee = new DispList(displayees); /// <summary>
return f; /// Create and obtain a <see cref="RenderingForm"/> if the key has not existed; Otherwise, the old one is obtained.
} /// <paramref name="displayees"/> are set to the obtained <see cref="RenderingForm"/>.
else /// The dictionary of this function is <see cref="DisplayerMap"/>.
{ /// </summary>
_ = seedForm.Handle; /// <param name="key">key</param>
seedForm.Invoke(new Action(() => /// <param name="displayees">The displayees set to the obtained <see cref="RenderingForm"/>.</param>
{ /// <returns>A <see cref="RenderingForm"/> obtained by the key.</returns>
RenderingForm ff = new RenderingForm(displayees) public static RenderingForm Call(string key, params IDisplayee[] displayees)
{ {
Text = key, if (displayerMap.TryGetValue(key, out RenderingForm f))
Visible = true {
}; f.RenderingCanvas.DispEngine.Displayee = new DispList(displayees);
displayerMap.TryAdd(key, ff); return f;
})); }
else
{
_ = seedForm.Handle;
seedForm.Invoke(new Action(() =>
{
RenderingForm ff = new RenderingForm(displayees)
{
Text = key,
Visible = true
};
displayerMap.TryAdd(key, ff);
}));
RenderingForm fff = null; RenderingForm fff = null;
while (!displayerMap.TryGetValue(key, out fff)) while (!displayerMap.TryGetValue(key, out fff))
Thread.Sleep(1); Thread.Sleep(1);
return fff; return fff;
} }
} }
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
Displayer.Dispose(); RenderingCanvas.Dispose();
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
/// <inheritdoc/> /// <inheritdoc/>
public DispEngine GetDispEngine() public DispEngine GetDispEngine()
{ {
return Displayer.DispEngine; return RenderingCanvas.DispEngine;
} }
} }
} }

View File

@ -7,7 +7,7 @@
<RootNamespace>$(AssemblyName)</RootNamespace> <RootNamespace>$(AssemblyName)</RootNamespace>
<Platforms>x64</Platforms> <Platforms>x64</Platforms>
<Description>WinForm Display module of HiAPI</Description> <Description>WinForm Display module of HiAPI</Description>
<VersionBuild>4</VersionBuild> <VersionBuild>13</VersionBuild>
<VersionPrefix>1.2.$(VersionBuild)</VersionPrefix> <VersionPrefix>1.2.$(VersionBuild)</VersionPrefix>
<PackageTags>HiAPI</PackageTags> <PackageTags>HiAPI</PackageTags>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>

View File

@ -1,32 +1,35 @@
using Hi.Disp; using Hi.Disp;
using Hi.Disp.Flag; using Hi.Disp.Flag;
using Hi.Geom; using Hi.Geom;
using Hi.Licenses;
using Hi.WinForm.Disp; using Hi.WinForm.Disp;
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
namespace Hi.WinForm namespace Hi.WinForm
{ {
static class Program static class Program
{ {
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{
DispEngine.Init();
Application.ApplicationExit += Application_ApplicationExit;
RenderingCanvas displayer = new RenderingCanvas(new CoordinateDrawing(),new Stl(Box3d.CenterUnitBox).ToFaceDrawing());
Form form = new Form();
form.Controls.Add(displayer);
Application.Run(form);
}
private static void Application_ApplicationExit(object sender, EventArgs e)
{ {
DispEngine.FinishDisp(); License.LogInAll();
DispEngine.Init();
Application.ApplicationExit += (object sender, EventArgs e) =>
{
DispEngine.FinishDisp();
License.LogOutAll();
};
RenderingCanvas displayer = new RenderingCanvas(
new CoordinateDrawing(), new Stl(Box3d.CenterUnitBox).ToFaceDrawing());
Form form = new Form();
form.Controls.Add(displayer);
Application.Run(form);
} }
} }
} }