87 lines
3.1 KiB
C#
87 lines
3.1 KiB
C#
using Aurora.Api;
|
|
using Aurora.View;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Forms;
|
|
using VisionCommon;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using VisionSequence.Pattern;
|
|
|
|
namespace MilUI {
|
|
public class SelectedImagePath {
|
|
public string ImagePath { get; set; }
|
|
public SelectedImagePath(string imagePath) {
|
|
ImagePath = imagePath;
|
|
}
|
|
}
|
|
public class VisionImageTestSettingViewModel : NotifyPropertyChangedBase {
|
|
|
|
private ObservableCollection<SelectedImagePath> imagePaths = new ObservableCollection<SelectedImagePath>();
|
|
public ObservableCollection<SelectedImagePath> ImagePaths { get => imagePaths; set => SetProperty(ref imagePaths, value); }
|
|
|
|
private readonly Logger _Logger = new Logger(typeof(VisionImageTestSettingViewModel).Name);
|
|
private FovInfo _FovInfo;
|
|
private PatternInfo _PatternInfo;
|
|
private Action<PatternInfo> _GrabFindFunc;
|
|
private eVisionTestType _VisionTestType;
|
|
private string[] _ImageExtensions = { ".bmp", ".png", ".jpg", ".jpeg" };
|
|
|
|
public VisionImageTestSettingViewModel(FovInfo fovInfo, eVisionTestType visionTestType, ObservableCollection<SelectedImagePath> imagePaths, PatternInfo patternInfo = null) {
|
|
_FovInfo = fovInfo;
|
|
_VisionTestType = visionTestType;
|
|
if (patternInfo != null) {
|
|
_PatternInfo = patternInfo;
|
|
}
|
|
ImagePaths = imagePaths;
|
|
}
|
|
|
|
public void Clear() {
|
|
ImagePaths.Clear();
|
|
}
|
|
|
|
public void GetFolder() {
|
|
var openFolderDialog = new FolderBrowserDialog();
|
|
if (openFolderDialog.ShowDialog() == DialogResult.OK) {
|
|
var folderPath = openFolderDialog.SelectedPath;
|
|
GetImagePathInFolder(folderPath);
|
|
}
|
|
}
|
|
|
|
public void GetImages() {
|
|
var openFileDialog = new OpenFileDialog();
|
|
openFileDialog.Multiselect = true;
|
|
openFileDialog.Filter = "Image files (*.png;*.bmp;*.jpeg;*.jpg)|*.png;*.bmp;*.jpeg;*.jpg|All files (*.*)|*.*";
|
|
openFileDialog.InitialDirectory = ImagePathManager.GetRootDirPath();
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
|
foreach(var path in openFileDialog.FileNames) {
|
|
ImagePaths.Add(new SelectedImagePath(path));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void GetImagePathInFolder(string folderPath) {
|
|
var imagePaths = Directory.GetFiles(folderPath)
|
|
.Where(file => _ImageExtensions.Contains(Path.GetExtension(file).ToLower()))
|
|
.ToList();
|
|
|
|
foreach(var path in imagePaths) {
|
|
ImagePaths.Add(new SelectedImagePath(path));
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsImageFile(string path) {
|
|
string extension = Path.GetExtension(path).ToLower();
|
|
|
|
return Array.Exists(_ImageExtensions, ext => ext == extension);
|
|
}
|
|
|
|
}
|
|
}
|