329 lines
14 KiB
C#
329 lines
14 KiB
C#
using Aurora.View;
|
|
using DevExpress.Data.Browsing;
|
|
using DevExpress.Xpf.Core.Native;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using VisionCommon;
|
|
using VisionUI.Layout;
|
|
|
|
namespace VisionUI.RecipeMenu {
|
|
/// <summary>
|
|
/// 모터 타입
|
|
/// </summary>
|
|
public enum eMotorType {
|
|
Teaching, Align
|
|
}
|
|
/// <summary>
|
|
/// 비전레시피 메뉴 뷰모델 베이스
|
|
/// </summary>
|
|
public partial class UCVisionRecipeMenuViewModelBase : NotifyPropertyChangedBase {
|
|
///<summary>프로퍼티 선택 커맨드</summary>
|
|
public ICommand CMD_SelectProperty { get; }
|
|
///<summary>Fov Align 인지 확인 여부</summary>
|
|
public bool IsFovAlign {
|
|
get {
|
|
if (SelectedSubsystemPropertyName != null && selectedSubsysItem != null) {
|
|
if (SelectedSubsystemPropertyName == "AlignRecipes" || SelectedSubsystemPropertyName == "FovRecipes") {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 모든 값들을 Property grid로 표현 (Subsystem 관련 내용 나왔을때 Custom View 사용 x)
|
|
/// </summary>
|
|
public bool OnlyPropertyGrid = false;
|
|
|
|
#region Selected 관련 properties
|
|
private UnitRecipe selectedUnitItem;
|
|
|
|
public UnitRecipe SelectedUnitItem { get => selectedUnitItem; set => SetProperty(ref selectedUnitItem, value); }
|
|
|
|
private SubSysRecipe selectedSubsysItem;
|
|
/// <summary>
|
|
/// 선택된 서브시스템 아이템
|
|
/// </summary>
|
|
public SubSysRecipe SelectedSubsysItem {
|
|
get => selectedSubsysItem; set {
|
|
if (SelectedSubsysItem != null && StaticCoordSettingVM != null && SelectedSubsystemPropertyName == "Layout") {
|
|
//StaticCoordSettingVM.SaveRecipe();
|
|
}
|
|
SetProperty(ref selectedSubsysItem, value);
|
|
NotifyPropertyChanged(nameof(IsEnabledSelectedSubSysItem));
|
|
if (IsEnabledSelectedSubSysItem) {
|
|
NotifyPropertyChanged(nameof(StaticDirection));
|
|
NotifyPropertyChanged(nameof(MotorDirection));
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeX));
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeY));
|
|
MotorDirectionT = SelectedSubsysItem.LayoutRecipe.MotorDirection.DirectionT;
|
|
FovDistX = SelectedSubsysItem.CalRecipe.FovDistance.X;
|
|
FovDistY = SelectedSubsysItem.CalRecipe.FovDistance.Y;
|
|
UsingTeachingMotorSetting = eMotorType.Teaching;
|
|
}
|
|
SelectProperty(null);
|
|
}
|
|
}
|
|
private string _SelectedSubsystemPropertyName;
|
|
/// <summary>
|
|
/// 선택된 서브시스템속성 이름
|
|
/// </summary>
|
|
public string SelectedSubsystemPropertyName {
|
|
get => _SelectedSubsystemPropertyName; set {
|
|
if (SelectedSubsysItem != null && StaticCoordSettingVM != null && SelectedSubsystemPropertyName == "Layout") {
|
|
//StaticCoordSettingVM.SaveRecipe();
|
|
}
|
|
SetProperty(ref _SelectedSubsystemPropertyName, value);
|
|
NotifyPropertyChanged(nameof(IsFovAlign));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 자재좌표 방향
|
|
/// </summary>
|
|
public eCoordSysType StaticDirection {
|
|
get => CoordSystem.ToCoordSysType(SelectedSubsysItem.CalRecipe.CoordSystem);
|
|
set => SelectedSubsysItem.CalRecipe.CoordSystem = CoordSystem.ToCoordSystem(value, SelectedSubsysItem.CalRecipe.CoordSystem.DirectionT);
|
|
}
|
|
/// <summary>
|
|
/// 모터 좌표 방향
|
|
/// </summary>
|
|
public eCoordSysType MotorDirection {
|
|
get {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
return CoordSystem.ToCoordSysType(SelectedSubsysItem.LayoutRecipe.AlignMotorDirection);
|
|
}
|
|
else {
|
|
return CoordSystem.ToCoordSysType(SelectedSubsysItem.LayoutRecipe.MotorDirection);
|
|
}
|
|
}
|
|
set {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
SelectedSubsysItem.LayoutRecipe.AlignMotorDirection = CoordSystem.ToCoordSystem(value, SelectedSubsysItem.LayoutRecipe.AlignMotorDirection.DirectionT);
|
|
}
|
|
else {
|
|
SelectedSubsysItem.LayoutRecipe.MotorDirection = CoordSystem.ToCoordSystem(value, SelectedSubsysItem.LayoutRecipe.MotorDirection.DirectionT);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _useAlignMotor;
|
|
/// <summary>
|
|
/// 얼라인 모터 사용 여부
|
|
/// </summary>
|
|
public bool UseAlignMotor {
|
|
get => _useAlignMotor;
|
|
set {
|
|
SetProperty(ref _useAlignMotor, value);
|
|
if (!UseAlignMotor) {
|
|
UsingTeachingMotorSetting = eMotorType.Teaching;
|
|
SelectedSubsysItem.LayoutRecipe.AlignMotorDirection = (CoordSystem)SelectedSubsysItem.LayoutRecipe.MotorDirection.Clone();
|
|
SelectedSubsysItem.LayoutRecipe.AlignMoveObjectTypeX = SelectedSubsysItem.LayoutRecipe.Clone().MoveObjectTypeX;
|
|
SelectedSubsysItem.LayoutRecipe.AlignMoveObjectTypeY = SelectedSubsysItem.LayoutRecipe.Clone().MoveObjectTypeY;
|
|
}
|
|
SelectedSubsysItem.LayoutRecipe.IsAlignMotor = _useAlignMotor;
|
|
NotifyPropertyChanged(nameof(MotorDirection));
|
|
NotifyPropertyChanged(nameof(MotorDirectionT));
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeX));
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeY));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Theta 모터 방향
|
|
/// </summary>
|
|
public eDirection MotorDirectionT {
|
|
get {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
return SelectedSubsysItem.LayoutRecipe.AlignMotorDirection.DirectionT;
|
|
}
|
|
else {
|
|
return SelectedSubsysItem.LayoutRecipe.MotorDirection.DirectionT;
|
|
}
|
|
}
|
|
set {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
SelectedSubsysItem.LayoutRecipe.AlignMotorDirection.DirectionT = value;
|
|
}
|
|
else {
|
|
SelectedSubsysItem.LayoutRecipe.MotorDirection.DirectionT = value;
|
|
if (!UseAlignMotor) {
|
|
SelectedSubsysItem.LayoutRecipe.AlignMotorDirection.DirectionT = value;
|
|
}
|
|
}
|
|
NotifyPropertyChanged(nameof(MotorDirectionT));
|
|
}
|
|
}
|
|
|
|
private double _FovDistX;
|
|
/// <summary>
|
|
/// Fov Distance X값
|
|
/// </summary>
|
|
public double FovDistX {
|
|
get => _FovDistX;
|
|
set {
|
|
SetProperty(ref _FovDistX, value);
|
|
SelectedSubsysItem.CalRecipe.FovDistance.X = _FovDistX;
|
|
}
|
|
}
|
|
|
|
private double _FovDistY;
|
|
/// <summary>
|
|
/// Fov Ditance Y값
|
|
/// </summary>
|
|
public double FovDistY {
|
|
get => _FovDistY;
|
|
set {
|
|
SetProperty(ref _FovDistY, value);
|
|
SelectedSubsysItem.CalRecipe.FovDistance.Y = _FovDistY;
|
|
}
|
|
}
|
|
|
|
private eMotorType _usingTeachingMotorSetting;
|
|
/// <summary>
|
|
/// 사용된 모터세팅
|
|
/// </summary>
|
|
public eMotorType UsingTeachingMotorSetting {
|
|
get => _usingTeachingMotorSetting;
|
|
set {
|
|
SetProperty(ref _usingTeachingMotorSetting, value);
|
|
NotifyPropertyChanged(nameof(MotorDirection));
|
|
NotifyPropertyChanged(nameof(MotorDirectionT));
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeX));
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeY));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 이동할 객체 X축 타입
|
|
/// StaticMove | CamMove
|
|
/// </summary>
|
|
public eMoveObject MoveObjectTypeX {
|
|
get {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
return SelectedSubsysItem.LayoutRecipe.AlignMoveObjectTypeX;
|
|
}
|
|
else {
|
|
return SelectedSubsysItem.LayoutRecipe.MoveObjectTypeX;
|
|
}
|
|
}
|
|
set {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
SelectedSubsysItem.LayoutRecipe.AlignMoveObjectTypeX = value;
|
|
}
|
|
else {
|
|
SelectedSubsysItem.LayoutRecipe.MoveObjectTypeX = value;
|
|
if (!UseAlignMotor) {
|
|
SelectedSubsysItem.LayoutRecipe.MoveObjectTypeX = value;
|
|
}
|
|
}
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeX));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 이동할 객체 Y축 타입
|
|
/// StaticMove | CamMove
|
|
/// </summary>
|
|
public eMoveObject MoveObjectTypeY {
|
|
get {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
return SelectedSubsysItem.LayoutRecipe.AlignMoveObjectTypeY;
|
|
}
|
|
else {
|
|
return SelectedSubsysItem.LayoutRecipe.MoveObjectTypeY;
|
|
}
|
|
}
|
|
set {
|
|
if (UseAlignMotor && UsingTeachingMotorSetting == eMotorType.Align) {
|
|
SelectedSubsysItem.LayoutRecipe.AlignMoveObjectTypeY = value;
|
|
}
|
|
else {
|
|
SelectedSubsysItem.LayoutRecipe.MoveObjectTypeY = value;
|
|
if (!UseAlignMotor) {
|
|
SelectedSubsysItem.LayoutRecipe.MoveObjectTypeY = value;
|
|
}
|
|
}
|
|
NotifyPropertyChanged(nameof(MoveObjectTypeY));
|
|
}
|
|
}
|
|
|
|
private StaticCoordSettingViewModel _staticCoordSettingVM;
|
|
/// <summary>
|
|
/// 자재좌표세팅 뷰 모델
|
|
/// </summary>
|
|
public StaticCoordSettingViewModel StaticCoordSettingVM { get => _staticCoordSettingVM; set => SetProperty(ref _staticCoordSettingVM, value); }
|
|
|
|
// Property View
|
|
private string visionPropertyViewHeader;
|
|
/// <summary>비전 속성 뷰 헤더</summary>
|
|
public string VisionPropertyViewHeader { get => visionPropertyViewHeader; set => SetProperty(ref visionPropertyViewHeader, value); }
|
|
|
|
private object visionPropertyView;
|
|
/// <summary>비전 속성 뷰</summary>
|
|
public object VisionPropertyView { get => visionPropertyView; set => SetProperty(ref visionPropertyView, value); }
|
|
|
|
/// <summary>서브시스템 아이템이 선택되었는지 여부 확인</summary>
|
|
public bool IsEnabledSelectedSubSysItem { get => SelectedSubsysItem != null; }
|
|
#endregion
|
|
|
|
private void SelectProperty(object obj) {
|
|
// Selected 된 값에 대해 View Update 해주는 부분
|
|
VisionPropertyViewHeader = (SelectedSubsysItem != null) ?
|
|
string.Format($"{SelectedUnitItem.UnitName} / {SelectedSubsysItem.SubSysName}") : string.Empty;
|
|
|
|
if (obj is string selected) {
|
|
Log.I($"Selected : {selected}");
|
|
if (selected == "Layout") {
|
|
StaticCoordSettingVM = new StaticCoordSettingViewModel(SelectedSubsysItem);
|
|
VisionPropertyView = new UCLayoutView() { DataContext = this };
|
|
}
|
|
else {
|
|
VisionPropertyView = new UCDevPropertyGrid() { DataContext = typeof(SubSysRecipe).GetProperty(selected).GetValue(SelectedSubsysItem) };
|
|
}
|
|
SelectedSubsystemPropertyName = selected; // 변경 해준다.
|
|
}
|
|
if (SelectedSubsystemPropertyName != null && obj is null) {
|
|
UpdatePropertyView();
|
|
}
|
|
NotifyPropertyChanged(nameof(IsFovAlign));
|
|
}
|
|
|
|
private void UpdatePropertyView() {
|
|
if (SelectedSubsysItem != null) {
|
|
if (VisionPropertyView is UCDevPropertyGrid grid) {
|
|
if (SelectedSubsystemPropertyName == "InspRecipe") { // 같은 내용은 NotifyEvent cashe가 없어서 이벤트 Routed를 위한 초기화 작업 필수. (InspRecipe)
|
|
grid.DataContext = null; // Refresh 개념
|
|
}
|
|
grid.DataContext = typeof(SubSysRecipe).GetProperty(SelectedSubsystemPropertyName).GetValue(SelectedSubsysItem);
|
|
NotifyPropertyChanged(nameof(VisionPropertyView));
|
|
NotifyPropertyChanged(nameof(IsFovAlign));
|
|
}
|
|
else if (VisionPropertyView is UCLayoutView view) {
|
|
StaticCoordSettingVM = new StaticCoordSettingViewModel(SelectedSubsysItem);
|
|
view.DataContext = this;
|
|
NotifyPropertyChanged(nameof(VisionPropertyView));
|
|
NotifyPropertyChanged(nameof(IsFovAlign));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 처음 들어갔을 때 Selected Item을 index 가 0 인 값으로 설정해 주기 위한 Method
|
|
/// </summary>
|
|
public void ShowInitZeroIndexValue() {
|
|
// 맨 상단의 것 처리하도록 구현
|
|
if (SelectedVisionDef.UnitRecipes?.Count() > 0) {
|
|
SelectedUnitItem = SelectedVisionDef.UnitRecipes[0];
|
|
if (SelectedVisionDef.UnitRecipes[0].SubSysRecipes?.Count() > 0) {
|
|
SelectedSubsysItem = SelectedVisionDef.UnitRecipes[0].SubSysRecipes[0];
|
|
}
|
|
}
|
|
}
|
|
//#endregion
|
|
}
|
|
}
|