452 lines
19 KiB
C#
452 lines
19 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using VisionAligner;
|
|
using VisionCalibrator;
|
|
using VisionDirector;
|
|
using VisionLight;
|
|
using VisionUI.Pattern;
|
|
using VisionCommon;
|
|
using VisionSequence.Aligner;
|
|
using VisionSequence.Pattern;
|
|
using VisionSequence.Setup;
|
|
using VisionSequence.Inspector;
|
|
using Aurora.Api.Manager;
|
|
using VisionUI.Setup;
|
|
using VisionUI.Camera;
|
|
using VisionUI.Aligner;
|
|
using VisionUI.Inspector;
|
|
using VisionUI.RecipeMenu;
|
|
using VisionUI.ProcTest;
|
|
using Aurora.View;
|
|
using WeldingCommon.Vision.Adapter;
|
|
using WeldingCommon.Vision.Device;
|
|
using VisionCommon.DB;
|
|
using System;
|
|
|
|
using VisionUI.CamCalibration;
|
|
using System.Windows;
|
|
using WeldingCommon.Vision.Common;
|
|
|
|
|
|
|
|
|
|
|
|
#if USE_COGNEX
|
|
using CogCamera;
|
|
using CogPattern;
|
|
#else
|
|
using MilCamera;
|
|
using MilPattern;
|
|
#endif
|
|
|
|
namespace WeldingCommon.Vision.Factory
|
|
{
|
|
/// <summary>
|
|
/// 비전 레시피, 디바이스, 뷰를 등록한다.
|
|
/// </summary>
|
|
public static class VisionFactory {
|
|
#region Register Setting
|
|
/// <summary>
|
|
/// 비전 셋팅을 등록한다.
|
|
/// </summary>
|
|
public static void RegisterSetting(IAuroraEnvironment auroraEnv, SettingRegister register) {
|
|
VisionEnv.AuroraEnv = auroraEnv;
|
|
register(VisionKeys.VisionSettingKey, new VisionSetting());
|
|
}
|
|
#endregion
|
|
|
|
#region Register Recipe
|
|
/// <summary>
|
|
/// 비전 레시피를 Aurora 모델이 아닌 레시피에 등록한다. (Default)
|
|
/// </summary>
|
|
public static void RegisterRecipe(RecipeRegister register) {
|
|
VisionSettingManager.Initialize();
|
|
|
|
var visionSetting = VisionSettingManager.VisionSetting;
|
|
if (visionSetting.RecipeModelType == eRecipeModelType.AuroraRecipe) {
|
|
EquipmentInfoManager.Initialize();
|
|
|
|
if (VisionSettingManager.VisionSetting.UseRecipeAutoUpdate) {
|
|
RecipeUpdater.Run(eRecipeModelType.AuroraRecipe);
|
|
}
|
|
register(VisionKeys.VisionRecipeKey, VisionRecipeManager.CreateVisionRecipeDef(),
|
|
(id, item) => new UCVisionRecipeMenuView { DataContext = new UCVisionRecipeMenuRecipe(VisionEnv.AuroraEnv) });
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Register Model (Optional)
|
|
/// <summary>
|
|
/// 비전 레시피를 Aurora 레시피가 아닌 모델에 등록한다. (선택사항)
|
|
/// </summary>
|
|
public static void RegisterModel(ModelRegister register) {
|
|
VisionSettingManager.Initialize();
|
|
|
|
var visionSetting = VisionSettingManager.VisionSetting;
|
|
if (visionSetting.RecipeModelType == eRecipeModelType.AuroraModel) {
|
|
EquipmentInfoManager.Initialize();
|
|
|
|
if (VisionSettingManager.VisionSetting.UseRecipeAutoUpdate) {
|
|
RecipeUpdater.Run(eRecipeModelType.AuroraModel);
|
|
}
|
|
register(
|
|
VisionKeys.VisionRecipeKey,
|
|
VisionRecipeManager.CreateVisionModelDef(),
|
|
(id, item) => new UCVisionRecipeMenuView { DataContext = new UCVisionRecipeMenuModel(VisionEnv.AuroraEnv) });
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Register Ingredient (Optional)
|
|
/// <summary>
|
|
/// 비전 레시피를 Aurora 레시피가 아닌 Ingredient에 등록한다. (선택사항)
|
|
/// </summary>
|
|
public static void RegisterIngredient(IngredientsRegister register) {
|
|
VisionSettingManager.Initialize();
|
|
|
|
var visionSetting = VisionSettingManager.VisionSetting;
|
|
if (visionSetting.RecipeModelType == eRecipeModelType.AuroraIngredient) {
|
|
EquipmentInfoManager.Initialize();
|
|
|
|
register(
|
|
VisionKeys.VisionRecipeKey,
|
|
VisionRecipeManager.CreateVisionIngredientDef(),
|
|
true,
|
|
(id, item) => new UCVisionRecipeMenuView { DataContext = new UCVisionRecipeMenuIngredient(VisionEnv.AuroraEnv) });
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Register Sequences
|
|
/// <summary>
|
|
/// 패턴 검출, 얼라인, 셋업 등 비전 관련 시퀀스들을 등록한다.
|
|
/// </summary>
|
|
public static void RegisterSequences(IAuroraEnvironment auroraEnv, SequenceRegister register) {
|
|
// 비전 시퀀스를 등록하기 전에 Ingredient가 Activate 되어야 한다.
|
|
ActivateVisionIngredient(auroraEnv);
|
|
|
|
//RegisterEquipSeqAdapters();
|
|
//ReviewSeqManager.RegisterSeq(auroraEnv, register);
|
|
AlignProcSeqManager.RegisterSeq(auroraEnv, register);
|
|
ManualGrabFindSeqManager.RegisterSeq(auroraEnv, register);
|
|
SetSetupRecipeEnabled();
|
|
|
|
if (VisionRecipeManager.CalibrationEnabled) {
|
|
register(VisionKeys.CalSeqKey, new SetupSeq_Calibration().Builder(VisionKeys.CalSeqKey));
|
|
register(VisionKeys.CalSubSeqKey, new SetupSeq_CalSub().Builder(VisionKeys.CalSubSeqKey));
|
|
}
|
|
if (VisionRecipeManager.AutoFocusEnabled) {
|
|
register(VisionKeys.AutoFocusSeqKey, new SetupSeq_AutoFocus().Builder()); // 오토포커스
|
|
}
|
|
if (VisionRecipeManager.CenterTuningEnabled) {
|
|
register(VisionKeys.CenterTuningSeqKey, new SetupSeq_CenterTuning().Builder()); // 센터튜닝
|
|
}
|
|
if (VisionRecipeManager.VisionRepeatEnabled) {
|
|
register(VisionKeys.VisionRepeatSeqKey, new SetupSeq_VisionRepeat().Builder()); // 비전반복도 (제자리)
|
|
register(VisionKeys.VisionRepeatDynamicSeqKey, new SetupSeq_DynamicRepeat().Builder()); // 비전반복도 (축이동)
|
|
}
|
|
|
|
RegisterInspSeqs(auroraEnv, register);
|
|
}
|
|
|
|
private static void ActivateVisionIngredient(IAuroraEnvironment auroraEnv) {
|
|
if (VisionSettingManager.VisionSetting.RecipeModelType == eRecipeModelType.AuroraIngredient) {
|
|
foreach (var ingredientName in auroraEnv.IngredientsManager.Ingredients()) {
|
|
var ingredient = auroraEnv.IngredientsManager.Ingredient(ingredientName);
|
|
// To-Do : 장비에서 필요한 Ingredient로 명시적으로 Activate 한다.
|
|
ingredient.ActivateItem("VisionRecipe_Test");
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void SetSetupRecipeEnabled() {
|
|
foreach (UnitInfo unitInfo in VisionRecipeManager.GetUnitInfos()) {
|
|
foreach (SubSysInfo subSysInfo in VisionRecipeManager.GetSubSysInfos(unitInfo)) {
|
|
var subSysRecipe = VisionRecipeManager.GetSubSysRecipe(subSysInfo);
|
|
if (subSysRecipe.SubSysSetupRecipe.CalSetupRecipe != null && !VisionRecipeManager.CalibrationEnabled) {
|
|
VisionRecipeManager.CalibrationEnabled = true;
|
|
}
|
|
if (subSysRecipe.SubSysSetupRecipe.CenterTuningRecipe != null && !VisionRecipeManager.CenterTuningEnabled) {
|
|
VisionRecipeManager.CenterTuningEnabled = true;
|
|
}
|
|
if (subSysRecipe.InspRecipe.AttachInspRecipe != null && !VisionRecipeManager.AttachInspEnabled) {
|
|
VisionRecipeManager.AttachInspEnabled = true;
|
|
}
|
|
|
|
foreach (FovInfo fovInfo in VisionRecipeManager.GetFovInfos(subSysInfo)) {
|
|
var fovRecipe = VisionRecipeManager.GetFovRecipe(fovInfo);
|
|
if (fovRecipe.FovSetupRecipe.AutoFocusRecipe != null && !VisionRecipeManager.AutoFocusEnabled) {
|
|
VisionRecipeManager.AutoFocusEnabled = true;
|
|
}
|
|
if (fovRecipe.FovSetupRecipe.VisionRepeatRecipe != null && !VisionRecipeManager.VisionRepeatEnabled) {
|
|
VisionRecipeManager.VisionRepeatEnabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 지원 검사기능 : 패턴거리 검사 / 패턴유무 검사 / QR코드 검사 / 부착 검사
|
|
/// 미지원 검사기능 : 도포 검사 / 이물 및 찍힘 검사 / 기타 양불 판별 검사
|
|
/// 미지원 검사 기능은 별도 검사 모듈을 활용하여 장비에서 직접 구현해야 한다.
|
|
/// </summary>
|
|
private static void RegisterInspSeqs(IAuroraEnvironment auroraEnv, SequenceRegister register) {
|
|
if (VisionRecipeManager.AttachInspEnabled) {
|
|
register(VisionKeys.AttachInspSeqKey, new AttachInspSeq_C2_F4_MV().Builder(VisionKeys.AttachInspSeqKey));
|
|
}
|
|
|
|
bool codeEnabled = false;
|
|
bool patternExistEnabled = false;
|
|
|
|
foreach (eUnitId unitId in VisionRecipeManager.GetUnitIds()) {
|
|
foreach (SubSysInfo subSysInfo in VisionRecipeManager.GetSubSysInfos(unitId)) {
|
|
SubSysRecipe subSysRecipe = VisionRecipeManager.GetSubSysRecipe(subSysInfo);
|
|
|
|
if (subSysRecipe.AlignRecipes.Count > 0) {
|
|
foreach (AlignRecipe alignRecipe in subSysRecipe.AlignRecipes) {
|
|
if (alignRecipe.InspParams.CodeEnabled) {
|
|
codeEnabled = true;
|
|
}
|
|
if (alignRecipe.InspParams.PatternExistEnabled) {
|
|
patternExistEnabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (codeEnabled) {
|
|
register(VisionKeys.BcrInspSeqKey, new InspSeq_BCR().Builder(VisionKeys.BcrInspSeqKey));
|
|
}
|
|
if (patternExistEnabled) {
|
|
register(VisionKeys.PatternExsitInspSeqKey, new InspSeq_PatternExist().Builder(VisionKeys.PatternExsitInspSeqKey));
|
|
}
|
|
// *참고 : 패턴거리 검사 시퀀스는 얼라인 시퀀스에 포함되어 있음.
|
|
}
|
|
#endregion
|
|
|
|
#region Register Devices
|
|
/// <summary>
|
|
/// 카메라, 조명 등 비전 관련 디바이스들을 등록한다.
|
|
/// </summary>
|
|
public static void RegisterDevices(IDeviceRegistry registry) {
|
|
RegisterEquipAdapters(); // Device 등록 전에 먼저 실행해야 한다.
|
|
LightFactory.Register(registry);
|
|
CameraFactory.Register(registry);
|
|
CalibratorFactory.Register();
|
|
CoordConverterFactory.Register();
|
|
AlignerFactory.Register();
|
|
MilPatternAgentFactory.Register();
|
|
MotionDirectorFactory.Register();
|
|
ForceOkHandlerFactory.Register();
|
|
VisionImageTesterFactory.Register();
|
|
VisionDBFactory.Register(registry);
|
|
}
|
|
#endregion
|
|
|
|
#region Register Equip Adapters
|
|
/// <summary>
|
|
/// 장비 시퀀스 어댑터를 등록한다.
|
|
/// </summary>
|
|
private static void RegisterEquipSeqAdapters() {
|
|
EquipAdapter.Instance.MachineSeqManager = new EquipSeqManager();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 비전과 장비를 연결해주는 어댑터 인터페이스를 등록한다.
|
|
/// </summary>
|
|
private static void RegisterEquipAdapters() {
|
|
EquipAdapter.Instance.EquipMode = new EquipMode();
|
|
EquipAdapter.Instance.EquipTrigger = new EquipTrigger();
|
|
EquipAdapter.Instance.VisionSetup = new VisionSetup();
|
|
EquipAdapter.Instance.VisionAlarm = new VisionAlarm();
|
|
EquipAdapter.Instance.TeachingMotionManager = new TeachingMotionManager();
|
|
EquipAdapter.Instance.AlignMotionManager = new AlignMotionManager();
|
|
EquipAdapter.Instance.PositionManager = new EquipPositionManager();
|
|
EquipAdapter.Instance.MachinePatternManager = new PatternManager();
|
|
}
|
|
#endregion
|
|
|
|
#region Register Views
|
|
/// <summary>
|
|
/// 메인 및 서브 메뉴에 포함된 비전 관련 뷰들을 등록한다.
|
|
/// </summary>
|
|
public static void RegisterViews(IViewManager manager) {
|
|
#region SetTheme
|
|
if (ApplicationExt.Theme_Color.Contains("Light")) {
|
|
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
|
|
// Light Theme
|
|
//Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/Theme/VisionLight.xaml")
|
|
Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/Theme/VisionLightSG.xaml")
|
|
});
|
|
} else {
|
|
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
|
|
// Dark Theme
|
|
Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/Theme/VisionDark.xaml")
|
|
});
|
|
}
|
|
|
|
// Vision Theme 적용
|
|
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
|
|
Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/VisionResources.xaml")
|
|
});
|
|
#endregion
|
|
|
|
VisionEventManager.Instance.Init();
|
|
|
|
var vision = new MainMenu(ViewIds.Vision, MenuIcon.GetMenuIcon(eMenuIcon.VIDEO), PermissionLevel.NONE);
|
|
|
|
vision.AddSubMenu(ViewIds.Pattern, new SubMenuPatternRegistrationView());
|
|
|
|
// Calibration
|
|
if (VisionRecipeManager.CalibrationEnabled) {
|
|
vision.AddSubMenu(ViewIds.Calibration, new SubMenuCalView());
|
|
}
|
|
|
|
// CamCalibration
|
|
vision.AddSubMenu(ViewIds.CamCalibration, new SubMenuCamCalibrationRegistrationView());
|
|
|
|
// Align
|
|
vision.AddSubMenu(ViewIds.Align, new SubMenuAlignView());
|
|
|
|
// Inspector
|
|
AddInspSubMenus(vision);
|
|
|
|
// AutoFocus
|
|
if (VisionRecipeManager.AutoFocusEnabled) {
|
|
vision.AddSubMenu(ViewIds.AutoFocus, new SubMenuAutoFocusView());
|
|
}
|
|
|
|
// CenterTuning
|
|
if (VisionRecipeManager.CenterTuningEnabled) {
|
|
vision.AddSubMenu(ViewIds.CenterTuning, new SubMenuCenterTuningView());
|
|
}
|
|
|
|
// VisionRepeat
|
|
if (VisionRecipeManager.VisionRepeatEnabled) {
|
|
vision.AddSubMenu(ViewIds.VisionRepeat, new SubMenuVisionRepeatView());
|
|
}
|
|
|
|
// AttachInsp
|
|
if (VisionRecipeManager.AttachInspEnabled) {
|
|
vision.AddSubMenu(ViewIds.AttachInsp, new SubMenuAttachInspView());
|
|
}
|
|
|
|
// ProcTest
|
|
if (VisionSettingManager.VisionSetting.UseProcTest) {
|
|
vision.AddSubMenu(ViewIds.ProcTest, new SubMenuProcTestView());
|
|
}
|
|
|
|
// MainCamWindow
|
|
if (VisionSettingManager.VisionSetting.UseMainCameraWindow) {
|
|
vision.AddSubMenu(ViewIds.MainCamWindow, new SubMenuMainCamWindow()); // 서브 메뉴 클릭시, 닫혔던 메인 카메라 윈도우를 다시 띄움
|
|
CameraUcManager.Instance.ShowMainCameraViewWindow();
|
|
}
|
|
|
|
manager.RegisterMainMenu(vision);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 지원 검사기능 : 패턴거리 검사 / 패턴유무 검사 / QR코드 검사 / 부착 검사
|
|
/// 미지원 검사기능 : 도포 검사 / 이물 및 찍힘 검사 / 기타 양불 판별 검사 등
|
|
/// 미지원 검사 기능은 별도 검사 모듈을 활용하여 장비에서 직접 구현해야 한다.
|
|
/// </summary>
|
|
private static void AddInspSubMenus(MainMenu vision) {
|
|
bool codeEnabled = false;
|
|
|
|
foreach (eUnitId unitId in VisionRecipeManager.GetUnitIds()) {
|
|
foreach (SubSysInfo subSysInfo in VisionRecipeManager.GetSubSysInfos(unitId)) {
|
|
SubSysRecipe subSysRecipe = VisionRecipeManager.GetSubSysRecipe(subSysInfo);
|
|
|
|
if (subSysRecipe.AlignRecipes.Count > 0) {
|
|
foreach (AlignRecipe alignRecipe in subSysRecipe.AlignRecipes) {
|
|
if (alignRecipe.InspParams.CodeEnabled) {
|
|
codeEnabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (codeEnabled) {
|
|
vision.AddSubMenu(ViewIds.BCR, new VisionUI.Pattern.SubMenuBcrLogView());
|
|
}
|
|
// *참고 : 패턴유무 검사 로그뷰는 따로 없음.
|
|
// *참고 : 패턴거리 검사 로그뷰는 얼라인 서브메뉴 내에 있음.
|
|
}
|
|
|
|
/// <summary>
|
|
/// 비전 뷰 ID
|
|
/// </summary>
|
|
public class ViewIds {
|
|
/// <summary>
|
|
/// Vision 뷰 ID
|
|
/// </summary>
|
|
public const string Vision = "Vision";
|
|
/// <summary>
|
|
/// Pattern 뷰 ID
|
|
/// </summary>
|
|
public const string Pattern = "Pattern";
|
|
/// <summary>
|
|
/// CamPattern 뷰 ID
|
|
/// </summary>
|
|
public const string CamPattern = "CamPattern";
|
|
/// <summary>
|
|
/// Calibration 뷰 ID
|
|
/// </summary>
|
|
public const string Calibration = "Calibration";
|
|
/// <summary>
|
|
/// CamCalibration 뷰 ID
|
|
/// </summary>
|
|
public const string CamCalibration = "CamCalibration";
|
|
/// <summary>
|
|
/// Align 뷰 ID
|
|
/// </summary>
|
|
public const string Align = "Align";
|
|
/// <summary>
|
|
/// AutoFocus 뷰 ID
|
|
/// </summary>
|
|
public const string AutoFocus = "AutoFocus";
|
|
/// <summary>
|
|
/// Center Tuning 뷰 ID
|
|
/// </summary>
|
|
public const string CenterTuning = "CenterTuning";
|
|
/// <summary>
|
|
/// Vision Repeat 뷰 ID
|
|
/// </summary>
|
|
public const string VisionRepeat = "VisionRepeat";
|
|
/// <summary>
|
|
/// Attach Inspection 뷰 ID
|
|
/// </summary>
|
|
public const string AttachInsp = "AttachInsp";
|
|
/// <summary>
|
|
/// Process Test 뷰 ID
|
|
/// </summary>
|
|
public const string ProcTest = "ProcTest";
|
|
/// <summary>
|
|
/// BCR 뷰 ID
|
|
/// </summary>
|
|
public const string BCR = "BCR";
|
|
/// <summary>
|
|
/// Main Camera Window 뷰 ID
|
|
/// </summary>
|
|
public const string MainCamWindow = "MainCamWindow";
|
|
/// <summary>
|
|
/// Recipe Setting 뷰 ID
|
|
/// </summary>
|
|
public const string RecipeSetting = "RecipeSetting";
|
|
}
|
|
#endregion
|
|
|
|
#region Register Language
|
|
/// <summary>
|
|
/// 언어 리소스를 등록한다.
|
|
/// </summary>
|
|
/// <param name="register">Aurora의 LangResourceRegister</param>
|
|
public static void RegisterLanguageResource(LangResourceRegister register) {
|
|
register(typeof(VisionCommonUI.Resources.StrTokens));
|
|
}
|
|
#endregion
|
|
}
|
|
} |