78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora;
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace CogPattern {
|
|
/// <summary>
|
|
/// Cognex 패턴 에이전트 생성 및 등록 관리
|
|
/// </summary>
|
|
public class CogPatternAgentFactory {
|
|
private static Logger _logger = new Logger(typeof(CogPatternAgentFactory).Name);
|
|
private static IDisposable _EventDisposable;
|
|
|
|
/// <summary>
|
|
/// 패턴 에이전트 생성 및 등록
|
|
/// </summary>
|
|
public static void Register() {
|
|
try {
|
|
VersionChecker.Print(Assembly.GetExecutingAssembly().GetName());
|
|
SetObservable();
|
|
SetPatternAgentManager();
|
|
}
|
|
catch (Exception e) {
|
|
_logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
private static void SetObservable() {
|
|
if (_EventDisposable == null) {
|
|
var observable = VisionEventId.GetRecipeUpdateObservable();
|
|
_EventDisposable = observable.Subscribe(_ => UpdatePatternAgentManager());
|
|
}
|
|
}
|
|
|
|
private static void SetPatternAgentManager() {
|
|
PatternAgentManager.Clear();
|
|
|
|
foreach (var unitId in VisionRecipeManager.GetUnitIds()) {
|
|
foreach (var subSysInfo in VisionRecipeManager.GetSubSysInfos(unitId)) {
|
|
foreach (var fovInfo in VisionRecipeManager.GetFovInfos(subSysInfo)) {
|
|
CreatePatternAgent(fovInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void UpdatePatternAgentManager() {
|
|
// 삭제된 에이전트 제거
|
|
PatternAgentManager.DeleteUnusedAgent(VisionRecipeManager.GetFovInfos());
|
|
|
|
foreach (var newUnitId in VisionRecipeManager.GetUnitIds()) {
|
|
var newSubSysInfos = VisionRecipeManager.GetSubSysInfos(newUnitId);
|
|
|
|
foreach (var newSubSysInfo in newSubSysInfos) {
|
|
var newFovInfos = VisionRecipeManager.GetFovInfos(newSubSysInfo);
|
|
|
|
foreach (var newFovInfo in newFovInfos) {
|
|
// 새로 생성된 에이전트 추가
|
|
if (PatternAgentManager.IsNewSubSysInfo(newFovInfo)) {
|
|
CreatePatternAgent(newFovInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void CreatePatternAgent(FovInfo fovInfo) {
|
|
var patternAgent = new CogPatternAgent(fovInfo);
|
|
PatternAgentManager.SetAgent(fovInfo, patternAgent);
|
|
}
|
|
}
|
|
}
|