155 lines
5.2 KiB
C#
155 lines
5.2 KiB
C#
using AuroraUIComponent.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using VisionCommon;
|
|
using VisionUI;
|
|
using VisionUI.Camera;
|
|
using VisionUI.Pattern;
|
|
|
|
namespace WeldingCommon.Views
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for UCScannerCalibration.xaml
|
|
/// </summary>
|
|
public partial class UCScannerCalibration : UserControl
|
|
{
|
|
private UCScannerCalibrationViewModel _ViewModel;
|
|
|
|
private FovInfo _FovInfo;
|
|
private UserControl _CameraView;
|
|
|
|
|
|
public UCScannerCalibration(UCScannerCalibrationViewModel viewModel)
|
|
{
|
|
InitializeComponent();
|
|
|
|
_ViewModel = viewModel;
|
|
DataContext = _ViewModel;
|
|
|
|
_FovInfo = VisionRecipeManager.GetFovInfos().FirstOrDefault();
|
|
CreateCalibrationCameraView();
|
|
}
|
|
|
|
private void CreateCalibrationCameraView()
|
|
{
|
|
if (gridCalibrationCameraView.Children.Count == 0) {
|
|
var fovInfo = VisionRecipeManager.GetFovInfos().FirstOrDefault();
|
|
if (fovInfo != null) {
|
|
// 패턴을 찾는 공정이 있으므로 eDisplayType을 반드시 Pattern으로 해야 한다.
|
|
_CameraView = IpViewManager.CreateCameraView(fovInfo, eDisplayType.Pattern);
|
|
gridCalibrationCameraView.Children.Add(_CameraView);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
bool isVisible = (bool)e.NewValue;
|
|
if (isVisible == true) {
|
|
RefreshVisionRecipes();
|
|
CreatePatternListView();
|
|
} else {
|
|
CameraUcManager.Instance.StopLiveAll();
|
|
Dispose();
|
|
}
|
|
}
|
|
|
|
private void RefreshVisionRecipes()
|
|
{
|
|
_FovInfo = VisionRecipeManager.GetFovInfo(_FovInfo);
|
|
}
|
|
|
|
private void CreatePatternListView()
|
|
{
|
|
var patterrnListView = new PatternListView(_FovInfo);
|
|
var patternSettingViewModel = IpViewManager.CreateFovPatternListViewModel(_FovInfo, _CameraView);
|
|
|
|
patterrnListView.DataContext = patternSettingViewModel;
|
|
gridPatternListView.Children.Add(patterrnListView);
|
|
}
|
|
|
|
private void Dispose()
|
|
{
|
|
foreach (var child in gridPatternListView.Children) {
|
|
if (child is PatternListView patternListView) {
|
|
patternListView = null;
|
|
}
|
|
}
|
|
gridPatternListView.Children.Clear();
|
|
}
|
|
|
|
#region Grid VisionCorrectionList
|
|
private void PasteCommand_Executed_VisionCorrectionList(object sender, ExecutedRoutedEventArgs e)
|
|
{
|
|
if (GridEditorVisionCorrectionList.PasteFromClipboard(null)) {
|
|
GridEditorVisionCorrectionList.CommitEdit();
|
|
GridEditorVisionCorrectionList.Items.Refresh();
|
|
}
|
|
}
|
|
|
|
private void GridEditorVisionCorrectionList_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
|
|
{
|
|
if (_ViewModel != null) {
|
|
// 1Step Calibration을 위한 SelectedIndex 설정
|
|
var obj = sender as DataGrid;
|
|
_ViewModel.SelectedIndex = obj.SelectedIndex;
|
|
foreach (var item in e.RemovedCells) {
|
|
if (item.Item is CorrectionUnit) {
|
|
_ViewModel.SelectedVisionCorrectionList.Remove(item.Item as CorrectionUnit);
|
|
}
|
|
}
|
|
foreach (var item in e.AddedCells) {
|
|
if (item.Item is CorrectionUnit) {
|
|
var newItem = item.Item as CorrectionUnit;
|
|
if (!_ViewModel.SelectedVisionCorrectionList.Contains(newItem)) {
|
|
_ViewModel.SelectedVisionCorrectionList.Add(newItem);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GridEditorVisionCorrectionList_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (!IsVisible) {
|
|
_ViewModel.SelectedVisionCorrectionList.Clear();
|
|
GridEditorVisionCorrectionList.UnselectAllCells();
|
|
} else {
|
|
|
|
}
|
|
}
|
|
|
|
private void GridEditorVisionCorrectionList_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Escape) {
|
|
if (sender is DataGrid dg) {
|
|
dg.SelectedItem = null;
|
|
}
|
|
if (sender is ListBox lb) {
|
|
lb.SelectedItem = null;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void GridEditorVisionCorrectionList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
_ViewModel.MoveScanner();
|
|
}
|
|
}
|
|
}
|