diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index 35b7eeb..527e678 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -84,6 +84,9 @@ namespace JoyD.Windows.CS.Toprie // 项目路径,用于数据文件的存取 private string _projectPath = ""; + // 配置是否已经加载的标志位 + private bool _isConfigLoaded = false; + // 加载的测温区配置 private readonly List _loadedTemperatureZones = new List(); @@ -102,17 +105,19 @@ namespace JoyD.Windows.CS.Toprie set { // 只有当值发生变化时才进行同步 - if (_projectPath != value) + if (_projectPath != value) + { + _projectPath = value; + // 如果DeviceManager已经初始化,则同步更新其ProjectPath属性 + if (_deviceManager != null) { - _projectPath = value; - // 如果DeviceManager已经初始化,则同步更新其ProjectPath属性 - if (_deviceManager != null) - { - _deviceManager.ProjectPath = _projectPath; - } - // 加载配置文件 - LoadAllConfigs(); + _deviceManager.ProjectPath = _projectPath; } + // 加载配置文件 + LoadAllConfigs(); + // 设置配置已加载标志 + _isConfigLoaded = true; + } } } @@ -123,10 +128,14 @@ namespace JoyD.Windows.CS.Toprie { try { - if (string.IsNullOrEmpty(_projectPath)) - return; + if (string.IsNullOrWhiteSpace(_projectPath)) _projectPath = ""; - string configPath = Path.Combine(_projectPath, "测温区信息.csv"); + // 配置文件存储在Config子目录中 + string configDir = Path.Combine(_projectPath, "Config"); + // 确保Config目录存在 + Directory.CreateDirectory(configDir); + + string configPath = Path.Combine(configDir, "测温区信息.csv"); if (!File.Exists(configPath)) return; @@ -187,10 +196,14 @@ namespace JoyD.Windows.CS.Toprie { try { - if (string.IsNullOrEmpty(_projectPath)) - return; + if (string.IsNullOrWhiteSpace(_projectPath)) _projectPath = ""; - string configPath = Path.Combine(_projectPath, "温差数据.csv"); + // 配置文件存储在Config子目录中 + string configDir = Path.Combine(_projectPath, "Config"); + // 确保Config目录存在 + Directory.CreateDirectory(configDir); + + string configPath = Path.Combine(configDir, "温差数据.csv"); if (!File.Exists(configPath)) return; @@ -560,6 +573,13 @@ namespace JoyD.Windows.CS.Toprie // 设置静态属性 DeviceManager.MaxReconnectAttempts = 5; + + // 初始化时加载配置文件,只执行一次 + if (!_isConfigLoaded) + { + LoadAllConfigs(); + _isConfigLoaded = true; + } // 注册图像接收事件 _deviceManager.ImageReceived += DeviceManager_ImageReceived; @@ -2873,14 +2893,33 @@ namespace JoyD.Windows.CS.Toprie // 4. 如果勾选了全局温度且未勾选区域温度,则显示全局温度(居中显示),否则显示区域温度(居中显示) bool isGlobalTemperatureMode = _showGlobalTemperature && !_showAreaTemperature; - // 5. 如果勾选了区域温度,则显示区域框,否则不显示区域框 + // 5. 如果勾选了区域温度,则显示区域框和编号,否则不显示区域框 if (_showAreaTemperature) { try { - // 由于DeviceManager没有V8属性,暂时跳过区域框的绘制 - // 注意:在实际应用中,应该通过正确的API获取区域位置信息 - Console.WriteLine("区域温度显示已启用,但暂未实现区域框绘制功能"); + // 使用固定的字体和格式对象绘制区域编号 + using (Font font = new Font("微软雅黑", 10, FontStyle.Bold)) + { + // 遍历已加载的测温区列表,绘制每个区域的框线和编号 + foreach (TemperatureZone zone in _loadedTemperatureZones) + { + // 创建画笔,使用区域的颜色作为框线颜色 + using (Pen pen = new Pen(zone.Color, 2)) + { + // 绘制区域框线 + g.DrawRectangle(pen, zone.X, zone.Y, zone.Width, zone.Height); + } + + // 创建画刷,使用区域的颜色作为文字颜色 + using (Brush brush = new SolidBrush(zone.Color)) + { + // 绘制区域编号,编号显示在区域左上角 + PointF numberPosition = new PointF(zone.X + 5, zone.Y + 5); + g.DrawString(zone.Index.ToString(), font, brush, numberPosition); + } + } + } } catch (Exception ex) {