207 lines
8.5 KiB
C#
207 lines
8.5 KiB
C#
using Aurora.Api;
|
|
using MilUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using VisionCommon;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
using VisionUI;
|
|
|
|
namespace WeldingCommon.Vision.Common
|
|
{
|
|
/// <summary>
|
|
/// 프로젝트 간에 상호 참조를 해결하기 위해 일부 이벤트들을 미리 등록 해놓은 클래스
|
|
/// </summary>
|
|
public class VisionEventManager
|
|
{
|
|
private bool _IsObservableSet = false;
|
|
|
|
private static VisionEventManager instance = null;
|
|
public static VisionEventManager Instance {
|
|
get {
|
|
if (instance == null) {
|
|
instance = new VisionEventManager();
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
SetObservable();
|
|
}
|
|
|
|
private void SetObservable()
|
|
{
|
|
if (!_IsObservableSet) {
|
|
VisionEnv.AuroraEnv.EventObservable.
|
|
AsObservable(VisionEventId.SHOW_CAM_DEVICE_SETTING_WINDOW).Subscribe(msg => ShowCamDeviceSettingWindow(msg));
|
|
VisionEnv.AuroraEnv.EventObservable.
|
|
AsObservable(VisionEventId.SHOW_REGISTER_PATTERN_WINDOW).Subscribe(msg => ShowRegisterPatternWindow(msg));
|
|
VisionEnv.AuroraEnv.EventObservable.
|
|
AsObservable(VisionEventId.SHOW_PATTERN_SETTING_WINDOW).Subscribe(msg => ShowPatternSettingWindow(msg));
|
|
VisionEnv.AuroraEnv.EventObservable.
|
|
AsObservable(VisionEventId.SHOW_PATTERN_SETTING_WINDOW_FORCE_OK).Subscribe(msg => ShowPatternSettingWindow_ForceOk(msg));
|
|
_IsObservableSet = true;
|
|
VisionEnv.AuroraEnv.EventObservable.
|
|
AsObservable(VisionEventId.CLOSE_VISION_IMAGE_TEST).Subscribe(msg => CloseVisionImageTest(msg));
|
|
}
|
|
}
|
|
|
|
#region Camera
|
|
private void ShowCamDeviceSettingWindow(EventMessage msg)
|
|
{
|
|
if (msg.Param != null) {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
var param = (Tuple<FovInfo, ICameraDisplay>)msg.Param;
|
|
VisionUI.CamDeviceSettingWindow.Instance?.Show(param.Item1, param.Item2);
|
|
}));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Pattern
|
|
private Window _Window;
|
|
private PatternListViewModel _PatternListViewModel;
|
|
private int _SelectedIdx = 0;
|
|
|
|
private void ShowRegisterPatternWindow(EventMessage msg)
|
|
{
|
|
if (msg.Param != null) {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
var param = (Tuple<PatternAgentBase, PatternInfo, Window, PatternListViewModel, int>)msg.Param;
|
|
|
|
PatternAgentBase patternAgent = param.Item1;
|
|
PatternInfo patternInfo = param.Item2;
|
|
_Window = param.Item3;
|
|
_PatternListViewModel = param.Item4;
|
|
_SelectedIdx = param.Item5;
|
|
|
|
if (_Window == null || !(_Window is IPatternSettingWindow)) {
|
|
_PatternListViewModel.IsViewEnabled = false;
|
|
_Window = new RegisterPatternWindow(patternAgent, patternInfo);
|
|
(_Window as IPatternSettingWindow).ResetPosition();
|
|
_Window.Closed += OnWindowClosed;
|
|
_Window.Owner = Application.Current.MainWindow;
|
|
_Window.Show();
|
|
} else {
|
|
_PatternListViewModel.ResetWindow();
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void ShowPatternSettingWindow(EventMessage msg)
|
|
{
|
|
if (msg.Param != null) {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
var param = (Tuple<PatternAgentBase, PatternInfo, ICameraDisplay, FovInfo, Window, PatternListViewModel, int>)msg.Param;
|
|
|
|
PatternAgentBase patternAgent = param.Item1;
|
|
PatternInfo patternInfo = param.Item2;
|
|
ICameraDisplay cameraDisplay = param.Item3;
|
|
FovInfo fovInfo = param.Item4;
|
|
_Window = param.Item5;
|
|
_PatternListViewModel = param.Item6;
|
|
_SelectedIdx = param.Item7;
|
|
|
|
if (_Window == null || !(_Window is IPatternSettingWindow)) {
|
|
_PatternListViewModel.IsViewEnabled = false;
|
|
patternAgent.ReloadPattern(patternInfo);
|
|
_Window = PatternViewUtil.CreatePatternSettingWindow(
|
|
patternAgent, patternInfo.Clone() as PatternInfo, _PatternListViewModel.CamViewBase.GetDisplay(), fovInfo);
|
|
|
|
if (_Window == null) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_PatternNotFound);
|
|
} else {
|
|
(_Window as IPatternSettingWindow).ResetPosition();
|
|
_Window.Closed += OnWindowClosed;
|
|
_Window.Show();
|
|
}
|
|
} else {
|
|
_PatternListViewModel.ResetWindow();
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void OnWindowClosed(object sender, EventArgs e)
|
|
{
|
|
_Window = null;
|
|
if (_PatternListViewModel != null) {
|
|
_PatternListViewModel.IsViewEnabled = true;
|
|
_PatternListViewModel.InitPatternList(_SelectedIdx);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region ForceOk
|
|
private Window _Window_ForceOk;
|
|
private ForceOkView _ForceOkView;
|
|
|
|
private void ShowPatternSettingWindow_ForceOk(EventMessage msg)
|
|
{
|
|
if (msg.Param != null) {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
var param = (Tuple<PatternAgentBase, PatternInfo, ICameraDisplay, FovInfo, Window, ForceOkView>)msg.Param;
|
|
|
|
PatternAgentBase patternAgent = param.Item1;
|
|
PatternInfo patternInfo = param.Item2;
|
|
ICameraDisplay cameraDisplay = param.Item3;
|
|
FovInfo fovInfo = param.Item4;
|
|
_Window_ForceOk = param.Item5;
|
|
_ForceOkView = param.Item6;
|
|
|
|
if (_Window_ForceOk == null) {
|
|
patternAgent.ReloadPattern(patternInfo);
|
|
_Window_ForceOk = PatternViewUtil.CreatePatternSettingWindow(
|
|
patternAgent, patternAgent.GetMainPatternInfo(patternInfo), cameraDisplay, fovInfo);
|
|
|
|
if (_Window_ForceOk != null) {
|
|
(_Window_ForceOk as IPatternSettingWindow).ResetPosition();
|
|
_Window_ForceOk.Closed += OnWindowClosed;
|
|
_Window_ForceOk.Show();
|
|
}
|
|
} else {
|
|
if (_Window_ForceOk.WindowState == WindowState.Minimized) {
|
|
_Window_ForceOk.WindowState = WindowState.Normal;
|
|
}
|
|
(_Window_ForceOk as IPatternSettingWindow).ResetPosition();
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void OnWindowClosed_ForceOk(object sender, EventArgs e)
|
|
{
|
|
_ForceOkView.Clear();
|
|
}
|
|
#endregion
|
|
|
|
#region Vision Image Test
|
|
private void CloseVisionImageTest(EventMessage msg)
|
|
{
|
|
if (msg.Param != null) {
|
|
Application.Current.Dispatcher.BeginInvoke(new Action(() => {
|
|
var param = (Tuple<object, int>)msg.Param;
|
|
|
|
PatternListViewModel patternListViewModel = param.Item1 as PatternListViewModel;
|
|
int selectedIdx = param.Item2;
|
|
|
|
patternListViewModel.IsViewEnabled = true;
|
|
patternListViewModel.InitPatternList(selectedIdx);
|
|
}));
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |