From 72cf329ce1c456222fcc5276bb65e67cbf6760f0 Mon Sep 17 00:00:00 2001
From: C3204 <zhengyabo@lanpucloud.cn>
Date: 星期四, 22 一月 2026 14:52:39 +0800
Subject: [PATCH] 优化主界面显示为行列矩阵形式,实现鼠标左键双击对应窗体最大化,再次双击恢复之前布局。
---
LB_SmartVision/VisionForm.cs | 1
LB_VisionControl/UserHSmartWindowControl.Designer.cs | 36 ++++---
LB_VisionProcesses/LB_VisionProcesses.csproj | 4
LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs | 26 ++++
LB_VisionProcesses/Alogrithms/VisualLargeModel/VisualSegmentationModel.cs | 13 ++
LB_SmartVision/Forms/Pages/ProcessPage/AllProcessesPage.cs | 150 ++++++++++++++++++++++++++----
LB_VisionControl/UserHSmartWindowControl.cs | 28 +++++
7 files changed, 214 insertions(+), 44 deletions(-)
diff --git a/LB_SmartVision/Forms/Pages/ProcessPage/AllProcessesPage.cs b/LB_SmartVision/Forms/Pages/ProcessPage/AllProcessesPage.cs
index 01ab907..74e7fc7 100644
--- a/LB_SmartVision/Forms/Pages/ProcessPage/AllProcessesPage.cs
+++ b/LB_SmartVision/Forms/Pages/ProcessPage/AllProcessesPage.cs
@@ -9,7 +9,12 @@
public partial class AllProcessesPage : TabPage
{
public ObservableConcurrentDictionary<string, ProcessControl> dicProcessControls = new ObservableConcurrentDictionary<string, ProcessControl>();
-
+ // 淇濆瓨鎺т欢鍘熷甯冨眬锛堝昂瀵�+浣嶇疆锛夛紝鐢ㄤ簬鎭㈠鐭╅樀甯冨眬
+ private Dictionary<string, (Size Size, Point Location)> _originalControlLayouts = new Dictionary<string, (Size, Point)>();
+ // 鏍囪鏄惁澶勪簬鍏ㄥ睆鐘舵��
+ private bool _isFullScreen = false;
+ // 璁板綍褰撳墠鍏ㄥ睆鐨勬帶浠舵爣棰�
+ private string _fullScreenControlTitle = string.Empty;
/// <summary>
/// 瀹炰緥鍖栨祦绋嬬晫闈�
/// </summary>
@@ -49,8 +54,16 @@
{
if (dicProcessControls.ContainsKey(title))
{
+ // 绉婚櫎鍓嶅厛瑙g粦浜嬩欢锛岄伩鍏嶅唴瀛樻硠婕�
+ var control = dicProcessControls[title];
+ control.event_MouseDoubleClick -= ProcessControl_DoubleClick;
+
this.controlsPanel.Controls.Remove(dicProcessControls[title]);
dicProcessControls.TryRemove(title, out _);
+
+ // 绉婚櫎鍘熷甯冨眬璁板綍
+ if (_originalControlLayouts.ContainsKey(title))
+ _originalControlLayouts.Remove(title);
}
}
}
@@ -61,45 +74,142 @@
if (GlobalVar.dicProcesses.ContainsKey(layout.ProcessName))
enableLayout++;
}
-
+ //鎬昏鏁帮紝鍚戜笅鍙栨暣
+ int matrixRows = (int)Math.Floor(Math.Sqrt(enableLayout));
+ if (enableLayout == 0 || matrixRows == 0)
+ {
+ _originalControlLayouts.Clear();
+ _isFullScreen = false;
+ _fullScreenControlTitle = string.Empty;
+ // 鏃犲惎鐢ㄥ竷灞�鏃剁洿鎺ヨ繑鍥烇紝閬垮厤闄ら浂閿欒
+ return;
+ }
+ //鎬诲垪鏁帮紝鍚戜笂鍙栨暣
+ int matrixColumns = (int)Math.Ceiling((double)enableLayout / matrixRows);
int index = 0;
+ // 璁$畻姣忎釜ProcessControl鐨勫昂瀵革紙鎸夎鍒楀潎鍒嗛潰鏉垮ぇ灏忥級
+ int controlWidth = this.controlsPanel.Width / matrixColumns;
+ int controlHeight = this.controlsPanel.Height / matrixRows;
+ // 姣忔閲嶆瀯甯冨眬鏃舵竻绌哄師濮嬭褰�
+ _originalControlLayouts.Clear();
for (int i = 0; i < GlobalVar.dicLayout.Count; i++)
{
string name = GlobalVar.dicLayout[i].ProcessName;
string title = GlobalVar.dicLayout[i].Title;
+
if (GlobalVar.dicProcesses.ContainsKey(name))
{
+ // 璁$畻褰撳墠鎺т欢鐨勮鍒楃储寮�
+ int colIndex = index % matrixColumns; // 鍒楃储寮曪紙0,1,0,1...锛�
+ int rowIndex = index / matrixColumns; // 琛岀储寮曪紙0,0,1,1...锛�
+ // 璁$畻鍘熷浣嶇疆鍜屽昂瀵革紙鐭╅樀甯冨眬锛�
+ Size originalSize = new Size(controlWidth, controlHeight);
+ Point originalLocation = new Point(colIndex * controlWidth, rowIndex * controlHeight);
+ ProcessControl processControl;
if (dicProcessControls.ContainsKey(title))
{
- ProcessControl processControl = dicProcessControls[title];
- processControl.Size
- = new Size(this.controlsPanel.Size.Width / enableLayout
- , this.controlsPanel.Size.Height);
- processControl.Location
- = new Point(processControl.Size.Width * index, 0);
-
- if (GlobalVar.dicProcesses[name].GetImage(GlobalVar.dicLayout[i], out _, out HObject RecordImage))
- dicProcessControls[title].ShowHoImage(RecordImage);
+ // 澶嶇敤宸叉湁鎺т欢锛屾洿鏂板昂瀵稿拰浣嶇疆
+ processControl = dicProcessControls[title];
+ processControl.Size = originalSize;
+ processControl.Location = originalLocation;
+ processControl.Visible = true;
+ // 瑙g粦鏃т簨浠讹紝閬垮厤閲嶅缁戝畾
+ processControl.event_MouseDoubleClick -= ProcessControl_DoubleClick;
}
else
{
- ProcessControl processControl = new ProcessControl(GlobalVar.dicLayout[i]);
- processControl.Size
- = new Size(this.controlsPanel.Size.Width / enableLayout
- , this.controlsPanel.Size.Height);
- processControl.Location
- = new Point(processControl.Size.Width * index, 0);
+ // 鏂板缓鎺т欢锛屾寜鐭╅樀甯冨眬璧嬪�煎昂瀵稿拰浣嶇疆
+ processControl = new ProcessControl(GlobalVar.dicLayout[i]);
+ processControl.Size = originalSize;
+ processControl.Location = originalLocation;
processControl.SetTitle(title);
+ // 娣诲姞鍒板瓧鍏稿拰闈㈡澘
dicProcessControls.TryAdd(title, processControl);
this.controlsPanel.Controls.Add(processControl);
- if (GlobalVar.dicProcesses[name].GetImage(GlobalVar.dicLayout[i], out _, out HObject RecordImage))
- dicProcessControls[title].ShowHoImage(RecordImage);
}
- index++;
+
+ // 缁戝畾鍙屽嚮浜嬩欢锛堝乏閿級鍜岄紶鏍囨寜涓嬩簨浠讹紙鍙抽敭鍙屽嚮锛�
+ processControl.event_MouseDoubleClick += ProcessControl_DoubleClick;
+
+ // 淇濆瓨鍘熷甯冨眬锛堢煩闃电姸鎬侊級
+ _originalControlLayouts[title] = (originalSize, originalLocation);
+
+ // 鏇存柊鍥剧墖
+ if (GlobalVar.dicProcesses[name].GetImage(GlobalVar.dicLayout[i], out _, out HObject recordImage))
+ dicProcessControls[title].ShowHoImage(recordImage);
+
+ index++; // 浠呭惎鐢ㄧ殑甯冨眬绱㈠紩閫掑
+ }
+ }
+ // 濡傛灉褰撳墠鏄叏灞忕姸鎬侊紝鎭㈠鐭╅樀甯冨眬鍚庨噸缃姸鎬�
+ if (_isFullScreen)
+ {
+ _isFullScreen = false;
+ _fullScreenControlTitle = string.Empty;
+ }
+ }
+ #region 鍙屽嚮浜嬩欢澶勭悊锛堝叏灞�/鎭㈠甯冨眬锛�
+ /// <summary>
+ /// 宸﹂敭鍙屽嚮浜嬩欢锛氬叏灞忔樉绀哄綋鍓峆rocessControl
+ /// </summary>
+ private void ProcessControl_DoubleClick(object sender, EventArgs e)
+ {
+ if (_isFullScreen)
+ {
+ RestoreMatrixLayout();
+ return;
+ }
+
+ var targetControl = sender as ProcessControl;
+ if (targetControl == null || string.IsNullOrEmpty(targetControl.Title)) return;
+
+ // 璁板綍鍏ㄥ睆鐨勬帶浠舵爣棰�
+ _fullScreenControlTitle = targetControl.Title;
+ _isFullScreen = true;
+
+ // 闅愯棌鎵�鏈夊叾浠朠rocessControl锛屼粎鏄剧ず鐩爣鎺т欢
+ foreach (var kvp in dicProcessControls)
+ {
+ if (kvp.Key != _fullScreenControlTitle)
+ {
+ kvp.Value.Visible = false;
+ }
+ else
+ {
+ // 鐩爣鎺т欢璁句负闈㈡澘澶у皬锛屼綅缃�(0,0)锛堝叏灞忥級
+ kvp.Value.Size = this.controlsPanel.Size;
+ kvp.Value.Location = new Point(0, 0);
+ kvp.Value.BringToFront(); // 纭繚鍦ㄦ渶涓婂眰
}
}
}
+
+ /// <summary>
+ /// 鎭㈠鐭╅樀甯冨眬锛堝鐢↖nitVisionUI鐨勬牳蹇冮�昏緫锛岄伩鍏嶄唬鐮侀噸澶嶏級
+ /// </summary>
+ private void RestoreMatrixLayout()
+ {
+ // 1. 閲嶇疆鍏ㄥ睆鐘舵��
+ _isFullScreen = false;
+ _fullScreenControlTitle = string.Empty;
+
+ // 2. 鎭㈠鎵�鏈夋帶浠剁殑鍘熷灏哄銆佷綅缃拰鍙鎬�
+ foreach (var kvp in dicProcessControls)
+ {
+ string title = kvp.Key;
+ var control = kvp.Value;
+
+ // 3. 浠庡師濮嬪竷灞�瀛楀吀涓仮澶嶅昂瀵稿拰浣嶇疆
+ if (_originalControlLayouts.TryGetValue(title, out var originalLayout))
+ {
+ control.Size = originalLayout.Size;
+ control.Location = originalLayout.Location;
+ }
+ control.Visible = true; // 鏄剧ず鎺т欢
+ }
+ }
+ #endregion
}
}
diff --git a/LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs b/LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs
index 1642a11..41f0e6b 100644
--- a/LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs
+++ b/LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs
@@ -10,6 +10,25 @@
{
UserHSmartWindowControl UserHSmartWindowControl = new UserHSmartWindowControl();
+ public string Title = string.Empty;
+
+ public event Control_MouseDown event_MouseDown;
+ public event Control_MouseDoubleClick event_MouseDoubleClick;
+ private void event_mouseDown(object sender, MouseEventArgs e)
+ {
+ if (event_MouseDown != null)
+ {
+ event_MouseDown(sender, e);
+ }
+ }
+ private void event_mouseDoubleClick(object sender, MouseEventArgs e)
+ {
+ if (event_MouseDoubleClick != null)
+ {
+ event_MouseDoubleClick(this, e);
+ }
+ }
+
ProcessRunBll ProcessRunBll
{
get
@@ -38,12 +57,13 @@
{
this.panel1.Controls.Add(this.UserHSmartWindowControl);
this.UserHSmartWindowControl.Dock = DockStyle.Fill;
-
+ this.UserHSmartWindowControl.event_MouseDoubleClick += event_mouseDoubleClick;
+ this.UserHSmartWindowControl.event_MouseDown += event_mouseDown;
SetTitle(_Layout.ProcessName);
-
+ Title = _Layout.Title;
if (ProcessRunBll != null)
this.label1.Text = $"鎬绘暟锛歿ProcessRunBll.total}";
- this.isClosed = false ;
+ this.isClosed = false;
var TaskPhotoContinue = Task.Factory.StartNew(() =>
{
ThreadCircleRun();
diff --git a/LB_SmartVision/VisionForm.cs b/LB_SmartVision/VisionForm.cs
index 2b0d895..14f66c7 100644
--- a/LB_SmartVision/VisionForm.cs
+++ b/LB_SmartVision/VisionForm.cs
@@ -1402,6 +1402,7 @@
GlobalVar.strProductName = com_ProductName.SelectedItem?.ToString();
foreach (BaseCamera camera in GlobalVar.dicCameras.Values)
{
+ camera.TriggerRunMessageReceived -= TriggerRunMessageReceived;
camera.Dispose();
}
GlobalVar.dicCameras.Clear();
diff --git a/LB_VisionControl/UserHSmartWindowControl.Designer.cs b/LB_VisionControl/UserHSmartWindowControl.Designer.cs
index e4cc615..5ab5f65 100644
--- a/LB_VisionControl/UserHSmartWindowControl.Designer.cs
+++ b/LB_VisionControl/UserHSmartWindowControl.Designer.cs
@@ -44,14 +44,15 @@
//
// RightContextMenuStrip
//
+ RightContextMenuStrip.ImageScalingSize = new Size(20, 20);
RightContextMenuStrip.Items.AddRange(new ToolStripItem[] { resizeImageStripMenuItem, autoSizeStripMenuItem, mouseIndexStripMenuItem });
RightContextMenuStrip.Name = "RightContextMenuStrip";
- RightContextMenuStrip.Size = new Size(149, 70);
+ RightContextMenuStrip.Size = new Size(169, 82);
//
// resizeImageStripMenuItem
//
resizeImageStripMenuItem.Name = "resizeImageStripMenuItem";
- resizeImageStripMenuItem.Size = new Size(148, 22);
+ resizeImageStripMenuItem.Size = new Size(168, 26);
resizeImageStripMenuItem.Text = "閲嶆柊缂╂斁鍥惧儚";
resizeImageStripMenuItem.Click += resizeImageStripMenuItem_Click;
//
@@ -60,39 +61,41 @@
autoSizeStripMenuItem.Checked = true;
autoSizeStripMenuItem.CheckState = CheckState.Checked;
autoSizeStripMenuItem.Name = "autoSizeStripMenuItem";
- autoSizeStripMenuItem.Size = new Size(148, 22);
+ autoSizeStripMenuItem.Size = new Size(168, 26);
autoSizeStripMenuItem.Text = "鍥惧儚鑷姩閫傚簲";
autoSizeStripMenuItem.Click += autoSizeStripMenuItem_Click;
//
// mouseIndexStripMenuItem
//
mouseIndexStripMenuItem.Name = "mouseIndexStripMenuItem";
- mouseIndexStripMenuItem.Size = new Size(148, 22);
+ mouseIndexStripMenuItem.Size = new Size(168, 26);
mouseIndexStripMenuItem.Text = "榧犳爣绱㈠紩鍍忕礌";
mouseIndexStripMenuItem.Click += mouseIndexStripMenuItem_Click;
//
// BtmStatusStrip
//
+ BtmStatusStrip.ImageScalingSize = new Size(20, 20);
BtmStatusStrip.Items.AddRange(new ToolStripItem[] { StatusLabel });
- BtmStatusStrip.Location = new Point(0, 220);
+ BtmStatusStrip.Location = new Point(0, 280);
BtmStatusStrip.Name = "BtmStatusStrip";
- BtmStatusStrip.Padding = new Padding(1, 0, 16, 0);
- BtmStatusStrip.Size = new Size(274, 22);
+ BtmStatusStrip.Padding = new Padding(1, 0, 20, 0);
+ BtmStatusStrip.Size = new Size(342, 22);
BtmStatusStrip.TabIndex = 44;
BtmStatusStrip.Text = "statusStrip1";
//
// StatusLabel
//
StatusLabel.Name = "StatusLabel";
- StatusLabel.Size = new Size(0, 17);
+ StatusLabel.Size = new Size(0, 16);
//
// pnl
//
pnl.Controls.Add(hWindowControl);
pnl.Dock = DockStyle.Fill;
pnl.Location = new Point(0, 0);
+ pnl.Margin = new Padding(4);
pnl.Name = "pnl";
- pnl.Size = new Size(274, 220);
+ pnl.Size = new Size(342, 280);
pnl.TabIndex = 45;
//
// hWindowControl
@@ -104,29 +107,30 @@
hWindowControl.Dock = DockStyle.Fill;
hWindowControl.HDoubleClickToFitContent = true;
hWindowControl.HDrawingObjectsModifier = HalconDotNet.HSmartWindowControl.DrawingObjectsModifier.None;
- hWindowControl.HImagePart = new Rectangle(0, 88, 2591, 1767);
+ hWindowControl.HImagePart = new Rectangle(-321, -152, 3233, 2247);
hWindowControl.HKeepAspectRatio = true;
hWindowControl.HMoveContent = true;
hWindowControl.HZoomContent = HalconDotNet.HSmartWindowControl.ZoomContent.WheelForwardZoomsIn;
hWindowControl.Location = new Point(0, 0);
- hWindowControl.Margin = new Padding(4);
+ hWindowControl.Margin = new Padding(5);
hWindowControl.Name = "hWindowControl";
- hWindowControl.Size = new Size(274, 220);
+ hWindowControl.Size = new Size(342, 280);
hWindowControl.TabIndex = 43;
- hWindowControl.WindowSize = new Size(274, 220);
+ hWindowControl.WindowSize = new Size(342, 280);
hWindowControl.HMouseMove += hWindowControl_HMouseMove;
hWindowControl.HMouseDown += hWindowControl_HMouseDown;
hWindowControl.HMouseUp += hWindowControl_HMouseUp;
+ hWindowControl.HMouseDoubleClick += hWindowControl_HMouseDoubleClick;
//
// UserHSmartWindowControl
//
- AutoScaleDimensions = new SizeF(96F, 96F);
+ AutoScaleDimensions = new SizeF(120F, 120F);
AutoScaleMode = AutoScaleMode.Dpi;
Controls.Add(pnl);
Controls.Add(BtmStatusStrip);
- Margin = new Padding(4);
+ Margin = new Padding(5);
Name = "UserHSmartWindowControl";
- Size = new Size(274, 242);
+ Size = new Size(342, 302);
Load += UserHSmartWindowControl_Load;
SizeChanged += UserHSmartWindowControl_SizeChanged;
MouseWheel += UserHSmartWindowControl_HMouseWheel;
diff --git a/LB_VisionControl/UserHSmartWindowControl.cs b/LB_VisionControl/UserHSmartWindowControl.cs
index 473f2a7..f91ead5 100644
--- a/LB_VisionControl/UserHSmartWindowControl.cs
+++ b/LB_VisionControl/UserHSmartWindowControl.cs
@@ -1,9 +1,12 @@
锘縰sing HalconDotNet;
using Sunny.UI.Win32;
using System.Diagnostics;
+using System.Windows.Forms;
namespace LB_VisionControl
{
+ public delegate void Control_MouseDown(object sender, MouseEventArgs e);
+ public delegate void Control_MouseDoubleClick(object sender, MouseEventArgs e);
public partial class UserHSmartWindowControl : UserControl
{
public UserHSmartWindowControl()
@@ -19,7 +22,22 @@
// 璁剧疆榛樿瀛椾綋涓� 20鍙� mono瀛椾綋鍔犵矖
set_display_font(this.hWindowControl.HalconWindow, 20, "mono", "true", "false");
}
-
+ public event Control_MouseDown event_MouseDown;
+ public event Control_MouseDoubleClick event_MouseDoubleClick;
+ private void event_mouseDown(object sender, MouseEventArgs e)
+ {
+ if (event_MouseDown != null)
+ {
+ event_MouseDown(sender, e);
+ }
+ }
+ private void event_mouseDoubleClick(object sender, MouseEventArgs e)
+ {
+ if (event_MouseDoubleClick != null)
+ {
+ event_MouseDoubleClick(sender, e);
+ }
+ }
private void UserHSmartWindowControl_Load(object sender, EventArgs e)
{
// 鍚敤鍙岀紦鍐插噺灏戦棯鐑�
@@ -969,6 +987,8 @@
default:
break;
}
+ MouseEventArgs mouseEventArgs = new MouseEventArgs(e.Button, e.Clicks, (int)e.X, (int)e.Y, e.Delta);
+ event_mouseDown(sender, mouseEventArgs);
}
catch { }
}
@@ -1171,5 +1191,11 @@
{
ShowHoImage(hImage);
}
+
+ private void hWindowControl_HMouseDoubleClick(object sender, HMouseEventArgs e)
+ {
+ MouseEventArgs mouseEventArgs = new MouseEventArgs(e.Button, e.Clicks, (int)e.X, (int)e.Y, e.Delta);
+ event_mouseDoubleClick(sender, mouseEventArgs);
+ }
}
}
diff --git a/LB_VisionProcesses/Alogrithms/VisualLargeModel/VisualSegmentationModel.cs b/LB_VisionProcesses/Alogrithms/VisualLargeModel/VisualSegmentationModel.cs
new file mode 100644
index 0000000..fd642fa
--- /dev/null
+++ b/LB_VisionProcesses/Alogrithms/VisualLargeModel/VisualSegmentationModel.cs
@@ -0,0 +1,13 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LB_VisionProcesses.Alogrithms.VisualLargeModel
+{
+ [Process("瑙嗚鍒嗗壊妯″瀷", Category = "娣卞害瀛︿範宸ュ叿", Description = "鍒涘缓瑙嗚鍒嗗壊妯″瀷宸ュ叿")]
+ public class VisualSegmentationModel : TAlgorithm
+ {
+ }
+}
diff --git a/LB_VisionProcesses/LB_VisionProcesses.csproj b/LB_VisionProcesses/LB_VisionProcesses.csproj
index b35e3ee..8db9084 100644
--- a/LB_VisionProcesses/LB_VisionProcesses.csproj
+++ b/LB_VisionProcesses/LB_VisionProcesses.csproj
@@ -36,10 +36,6 @@
</ItemGroup>
<ItemGroup>
- <Folder Include="Alogrithms\VisualLargeModel\" />
- </ItemGroup>
-
- <ItemGroup>
<ProjectReference Include="..\LB_SmartVisionCameraDevice\LB_SmartVisionCameraDevice.csproj" />
<ProjectReference Include="..\LB_SmartVisionCommon\LB_SmartVisionCommon.csproj" />
<ProjectReference Include="..\LB_VisionControl\LB_VisionControl.csproj" />
--
Gitblit v1.9.3