From 46431fb658701489f8d5de4475b02df728c51f36 Mon Sep 17 00:00:00 2001
From: chunxiaqiu <1057644574@qq.com>
Date: 星期三, 18 三月 2026 15:48:26 +0800
Subject: [PATCH] 新增:读码器功能模块,集成华睿读码器并初步实现读码功能

---
 LB_SmartVisionCommon/FilterManager.cs |  152 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/LB_SmartVisionCommon/FilterManager.cs b/LB_SmartVisionCommon/FilterManager.cs
new file mode 100644
index 0000000..2e2c949
--- /dev/null
+++ b/LB_SmartVisionCommon/FilterManager.cs
@@ -0,0 +1,152 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LB_SmartVisionCommon
+{
+    public class FilterManager
+    {
+        private Dictionary<FilterType, RecordFilterData> _filters;
+        private readonly string _dataFilePath;
+        private RecordFilterData _currentFilter;
+        private static FilterManager _instance;
+        /// <summary>
+        /// 绾跨▼閿�
+        /// </summary>
+        private static readonly object _lock = new object();
+        private FilterManager(string dataFilePath = "filters.json")
+        {
+            _dataFilePath = dataFilePath;
+            _filters = new Dictionary<FilterType, RecordFilterData>();
+            _currentFilter = null;
+            LoadUsers();
+        }
+        public static FilterManager Instance
+        {
+            get
+            {
+                // 鍙岄噸妫�鏌ラ攣瀹氱‘淇濈嚎绋嬪畨鍏�
+                if (_instance == null)
+                {
+                    lock (_lock)
+                    {
+                        if (_instance == null)
+                        {
+                            _instance = new FilterManager();
+                        }
+                    }
+                }
+                return _instance;
+            }
+        }
+
+        /// <summary>
+        /// 娣诲姞婊ゆ尝绠楀瓙
+        /// </summary>
+        /// <param name="user"></param>
+        /// <returns></returns>
+        public bool AddFilter(RecordFilterData filter)
+        {
+            if (_currentFilter == null)
+            {
+                _currentFilter = filter;
+            }
+            try
+            {
+                RecordFilterData recordFilterData = new RecordFilterData();
+                recordFilterData.MaskWidth = filter.MaskWidth;
+                recordFilterData.MaskHight = filter.MaskHight;
+                recordFilterData.GaussSize = filter.GaussSize;
+                recordFilterData.FilterName = filter.FilterName;
+                _filters.Add(recordFilterData.FilterName, recordFilterData);
+            }
+            catch (Exception ex) 
+            {
+                MessageBox.Show("璇ョ畻瀛愬凡瀛樺湪");
+            }
+            SaveUsers();
+            return true;
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鍥惧儚澧炲己绠楀瓙
+        /// </summary>
+        /// <param name="filterName"></param>
+        /// <returns></returns>
+        public bool DeleteUser(RecordFilterData filter)
+        {
+            try
+            {
+                // 1. 浠庡瓧鍏镐腑鍒犻櫎
+                if (_filters.ContainsKey(filter.FilterName))
+                {
+                    _filters.Remove(filter.FilterName);
+                }
+
+                // 2. 濡傛灉鍒犻櫎鐨勬槸褰撳墠婊ゆ尝锛屾竻绌篲currentFilter
+                if (_currentFilter != null && _currentFilter.FilterName == filter.FilterName)
+                {
+                    _currentFilter = null;
+                }
+
+                // 3. 淇濆瓨鏇存敼
+                SaveUsers();
+
+                return true;
+            }
+            catch (Exception ex)
+            {
+                // 璁板綍鏃ュ織
+                Console.WriteLine($"鍒犻櫎婊ゆ尝澶辫触: {ex.Message}");
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鎵�鏈夌敤鎴峰垪琛�
+        /// </summary>
+        /// <returns>List<RecordUserData></returns>
+        public List<RecordFilterData> GetAllUsers()
+        {
+            return _filters.Select(u => u.Value.Clone()).ToList();
+        }
+
+        #region json鏂囦欢淇濆瓨鍔犺浇
+        /// <summary>
+        /// 淇濆瓨鐢ㄦ埛鏁版嵁鍒癑SON鏂囦欢
+        /// </summary>
+        private void SaveUsers()
+        {
+            try
+            {
+                ConfigManager<Dictionary<FilterType, RecordFilterData>>.SaveConfig<Dictionary<FilterType, RecordFilterData>>(_filters, _dataFilePath);
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"淇濆瓨鍥惧儚澧炲己绠楀瓙澶辫触锛歿ex.Message}", "閿欒", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+        }
+
+        /// <summary>
+        /// 浠嶫SON鏂囦欢鍔犺浇鐢ㄦ埛鏁版嵁
+        /// </summary>
+        private void LoadUsers()
+        {
+            try
+            {
+                if (File.Exists(_dataFilePath))
+                {
+                    _filters = ConfigManager<Dictionary<FilterType, RecordFilterData>>.LoadConfig<Dictionary<FilterType, RecordFilterData>>(_dataFilePath) ?? new Dictionary<FilterType, RecordFilterData>();
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show($"鍔犺浇鍥惧儚澧炲己绠楀瓙澶辫触锛歿ex.Message}", "閿欒", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                _filters = new Dictionary<FilterType, RecordFilterData>();
+            }
+        }
+        #endregion
+    }
+}

--
Gitblit v1.9.3