优化主界面显示为行列矩阵形式,实现鼠标左键双击对应窗体最大化,再次双击恢复之前布局。
已修改6个文件
已添加1个文件
256 ■■■■ 文件已修改
LB_SmartVision/Forms/Pages/ProcessPage/AllProcessesPage.cs 150 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_SmartVision/VisionForm.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_VisionControl/UserHSmartWindowControl.Designer.cs 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_VisionControl/UserHSmartWindowControl.cs 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_VisionProcesses/Alogrithms/VisualLargeModel/VisualSegmentationModel.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
LB_VisionProcesses/LB_VisionProcesses.csproj 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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))
                    {
                        // ç§»é™¤å‰å…ˆè§£ç»‘事件,避免内存泄漏
                        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;
                        // è§£ç»‘旧事件,避免重复绑定
                        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>
        /// å·¦é”®åŒå‡»äº‹ä»¶ï¼šå…¨å±æ˜¾ç¤ºå½“前ProcessControl
        /// </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;
            // éšè—æ‰€æœ‰å…¶ä»–ProcessControl,仅显示目标控件
            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>
        /// æ¢å¤çŸ©é˜µå¸ƒå±€ï¼ˆå¤ç”¨InitVisionUI的核心逻辑,避免代码重复)
        /// </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
    }
}
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,9 +57,10 @@
        {
            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 ;
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();
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;
LB_VisionControl/UserHSmartWindowControl.cs
@@ -1,9 +1,12 @@
using 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);
        }
    }
}
LB_VisionProcesses/Alogrithms/VisualLargeModel/VisualSegmentationModel.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
using 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
    {
    }
}
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" />