68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
namespace MilPattern {
|
|
/// <summary>
|
|
/// FOV 전용 패턴 에이전트 생성 및 등록
|
|
/// </summary>
|
|
public class FovPatternAgentFactory {
|
|
private static Logger _logger = new Logger("PatternAgentFactory");
|
|
private static IDisposable _EventDisposable;
|
|
|
|
/// <summary>
|
|
/// FOV 전용 패턴 에이전트 생성 및 등록
|
|
/// </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() {
|
|
FovPatternAgentManager.Clear();
|
|
|
|
foreach (var unitId in VisionRecipeManager.GetUnitIds()) {
|
|
foreach (var subSysInfo in VisionRecipeManager.GetSubSysInfos(unitId)) {
|
|
CreatePatternAgent(subSysInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void UpdatePatternAgentManager() {
|
|
// 삭제된 에이전트 제거
|
|
FovPatternAgentManager.DeleteUnusedAgent(VisionRecipeManager.GetSubSysInfos());
|
|
|
|
foreach (var newUnitId in VisionRecipeManager.GetUnitIds()) {
|
|
var newSubSysInfos = VisionRecipeManager.GetSubSysInfos(newUnitId);
|
|
|
|
foreach (var subSysInfo in newSubSysInfos) {
|
|
// 새로 생성된 에이전트 추가
|
|
if (FovPatternAgentManager.IsNewSubSysInfo(subSysInfo)) {
|
|
CreatePatternAgent(subSysInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void CreatePatternAgent(SubSysInfo subSysInfo) {
|
|
var patternAgent = new FovPatternAgent(subSysInfo);
|
|
FovPatternAgentManager.SetAgent(subSysInfo, patternAgent);
|
|
}
|
|
}
|
|
}
|