migrate
This commit is contained in:
parent
90fe4a916a
commit
3346f74edc
@ -1,91 +1,103 @@
|
||||
using Hi.Disp;
|
||||
using Hi.Disp.Flag;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Hi.WinForm.Disp
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="Form"/> contains <see cref="RenderingCanvas"/>.
|
||||
/// This class is usually used for debug due to its simplicity.
|
||||
/// </summary>
|
||||
public partial class RenderingForm : Form,IGetDispEngine
|
||||
{
|
||||
static readonly Form seedForm = new Form();
|
||||
private static readonly ConcurrentDictionary<string, RenderingForm> displayerMap
|
||||
= new ConcurrentDictionary<string, RenderingForm>(4, 4);
|
||||
/// <summary>
|
||||
/// See <see cref="Call(string, IDisplayee[])"/> to get the information.
|
||||
/// </summary>
|
||||
public static ConcurrentDictionary<string, RenderingForm> DisplayerMap { get => displayerMap; }
|
||||
/// <summary>
|
||||
/// Ctor.
|
||||
/// </summary>
|
||||
/// <param name="displayees">displayees</param>
|
||||
internal RenderingForm(params IDisplayee[] displayees)
|
||||
{
|
||||
InitializeComponent();
|
||||
Displayer = new RenderingCanvas(displayees);
|
||||
this.Controls.Add(Displayer);
|
||||
//Displayer.DispEngine.Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// The contained <see cref="RenderingCanvas"/>.
|
||||
/// </summary>
|
||||
public RenderingCanvas Displayer { get; }
|
||||
/// <summary>
|
||||
/// 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"/>.
|
||||
/// The dictionary of this function is <see cref="DisplayerMap"/>.
|
||||
/// </summary>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="displayees">The displayees set to the obtained <see cref="RenderingForm"/>.</param>
|
||||
/// <returns>A <see cref="RenderingForm"/> obtained by the key.</returns>
|
||||
public static RenderingForm Call(string key, params IDisplayee[] displayees)
|
||||
{
|
||||
if (displayerMap.TryGetValue(key, out RenderingForm f))
|
||||
{
|
||||
f.Displayer.DispEngine.Displayee = new DispList(displayees);
|
||||
return f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = seedForm.Handle;
|
||||
seedForm.Invoke(new Action(() =>
|
||||
{
|
||||
RenderingForm ff = new RenderingForm(displayees)
|
||||
{
|
||||
Text = key,
|
||||
Visible = true
|
||||
};
|
||||
displayerMap.TryAdd(key, ff);
|
||||
}));
|
||||
/// <summary>
|
||||
/// A <see cref="Form"/> contains <see cref="Disp.RenderingCanvas"/>.
|
||||
/// This class is usually used for debug due to its simplicity.
|
||||
/// </summary>
|
||||
public partial class RenderingForm : Form, IGetDispEngine
|
||||
{
|
||||
static readonly Form seedForm = new Form();
|
||||
private static readonly ConcurrentDictionary<string, RenderingForm> displayerMap
|
||||
= new ConcurrentDictionary<string, RenderingForm>(4, 4);
|
||||
/// <summary>
|
||||
/// See <see cref="Call(string, IDisplayee[])"/> to get the information.
|
||||
/// </summary>
|
||||
public static ConcurrentDictionary<string, RenderingForm> DisplayerMap { get => displayerMap; }
|
||||
/// <summary>
|
||||
/// Ctor.
|
||||
/// </summary>
|
||||
/// <param name="displayees">displayees</param>
|
||||
internal RenderingForm(params IDisplayee[] displayees)
|
||||
{
|
||||
InitializeComponent();
|
||||
RenderingCanvas = new RenderingCanvas(displayees);
|
||||
this.Controls.Add(RenderingCanvas);
|
||||
//Displayer.DispEngine.Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// The contained <see cref="Disp.RenderingCanvas"/>.
|
||||
/// </summary>
|
||||
public RenderingCanvas RenderingCanvas { get; }
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public IDisplayee Displayee
|
||||
{
|
||||
get => GetDispEngine().Displayee;
|
||||
set
|
||||
{
|
||||
var preDisplayee = GetDispEngine().Displayee;
|
||||
GetDispEngine().Displayee = value;
|
||||
if (preDisplayee == null)
|
||||
RenderingCanvas.DispEngine.SetViewToHomeView();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 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"/>.
|
||||
/// The dictionary of this function is <see cref="DisplayerMap"/>.
|
||||
/// </summary>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="displayees">The displayees set to the obtained <see cref="RenderingForm"/>.</param>
|
||||
/// <returns>A <see cref="RenderingForm"/> obtained by the key.</returns>
|
||||
public static RenderingForm Call(string key, params IDisplayee[] displayees)
|
||||
{
|
||||
if (displayerMap.TryGetValue(key, out RenderingForm f))
|
||||
{
|
||||
f.RenderingCanvas.DispEngine.Displayee = new DispList(displayees);
|
||||
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;
|
||||
while (!displayerMap.TryGetValue(key, out fff))
|
||||
Thread.Sleep(1);
|
||||
return fff;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
Displayer.Dispose();
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public DispEngine GetDispEngine()
|
||||
{
|
||||
return Displayer.DispEngine;
|
||||
}
|
||||
}
|
||||
RenderingForm fff = null;
|
||||
while (!displayerMap.TryGetValue(key, out fff))
|
||||
Thread.Sleep(1);
|
||||
return fff;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
RenderingCanvas.Dispose();
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public DispEngine GetDispEngine()
|
||||
{
|
||||
return RenderingCanvas.DispEngine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||
<Platforms>x64</Platforms>
|
||||
<Description>WinForm Display module of HiAPI</Description>
|
||||
<VersionBuild>4</VersionBuild>
|
||||
<VersionBuild>13</VersionBuild>
|
||||
<VersionPrefix>1.2.$(VersionBuild)</VersionPrefix>
|
||||
<PackageTags>HiAPI</PackageTags>
|
||||
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
|
||||
|
41
Program.cs
41
Program.cs
@ -1,32 +1,35 @@
|
||||
using Hi.Disp;
|
||||
using Hi.Disp.Flag;
|
||||
using Hi.Geom;
|
||||
using Hi.Licenses;
|
||||
using Hi.WinForm.Disp;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Hi.WinForm
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
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)
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user