62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace MilPattern {
|
|
/// <summary>
|
|
/// 카메라 전용 패턴 에이전트 생성 및 등록
|
|
/// </summary>
|
|
public class CamPatternAgentFactory {
|
|
private static Logger _logger = new Logger("CamPatternAgentFactory");
|
|
private static IDisposable _EventDisposable;
|
|
|
|
/// <summary>
|
|
/// 카메라 전용 패턴 에이전트 생성 및 등록
|
|
/// </summary>
|
|
public static void Register() {
|
|
try {
|
|
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() {
|
|
CamPatternAgentManager.Clear();
|
|
|
|
foreach (var camId in VisionRecipeManager.GetCamIds()) {
|
|
CreatePatternAgent(camId);
|
|
}
|
|
}
|
|
|
|
private static void UpdatePatternAgentManager() {
|
|
// 삭제된 에이전트 제거
|
|
var newCamIds = VisionRecipeManager.GetCamIds();
|
|
CamPatternAgentManager.DeleteUnusedAgent(newCamIds);
|
|
|
|
foreach (var camId in newCamIds) {
|
|
// 새로 생성된 에이전트 추가
|
|
if (CamPatternAgentManager.IsNewCamId(camId)) {
|
|
CreatePatternAgent(camId);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void CreatePatternAgent(eCamId camId) {
|
|
var patternAgent = new CamPatternAgent(camId);
|
|
CamPatternAgentManager.SetAgent(camId, patternAgent);
|
|
}
|
|
}
|
|
}
|