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 {
///
/// 모터 타입
///
public enum eMotorType {
Teaching, Align
}
///
/// 비전레시피 메뉴 뷰모델 베이스
///
public partial class UCVisionRecipeMenuViewModelBase : NotifyPropertyChangedBase {
///프로퍼티 선택 커맨드
public ICommand CMD_SelectProperty { get; }
///Fov Align 인지 확인 여부
public bool IsFovAlign {
get {
if (SelectedSubsystemPropertyName != null && selectedSubsysItem != null) {
if (SelectedSubsystemPropertyName == "AlignRecipes" || SelectedSubsystemPropertyName == "FovRecipes") {
return true;
}
}
return false;
}
}
///
/// 모든 값들을 Property grid로 표현 (Subsystem 관련 내용 나왔을때 Custom View 사용 x)
///
public bool OnlyPropertyGrid = false;
#region Selected 관련 properties
private UnitRecipe selectedUnitItem;
public UnitRecipe SelectedUnitItem { get => selectedUnitItem; set => SetProperty(ref selectedUnitItem, value); }
private SubSysRecipe selectedSubsysItem;
///
/// 선택된 서브시스템 아이템
///
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;
///
/// 선택된 서브시스템속성 이름
///
public string SelectedSubsystemPropertyName {
get => _SelectedSubsystemPropertyName; set {
if (SelectedSubsysItem != null && StaticCoordSettingVM != null && SelectedSubsystemPropertyName == "Layout") {
//StaticCoordSettingVM.SaveRecipe();
}
SetProperty(ref _SelectedSubsystemPropertyName, value);
NotifyPropertyChanged(nameof(IsFovAlign));
}
}
///
/// 자재좌표 방향
///
public eCoordSysType StaticDirection {
get => CoordSystem.ToCoordSysType(SelectedSubsysItem.CalRecipe.CoordSystem);
set => SelectedSubsysItem.CalRecipe.CoordSystem = CoordSystem.ToCoordSystem(value, SelectedSubsysItem.CalRecipe.CoordSystem.DirectionT);
}
///
/// 모터 좌표 방향
///
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;
///
/// 얼라인 모터 사용 여부
///
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));
}
}
///
/// Theta 모터 방향
///
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;
///
/// Fov Distance X값
///
public double FovDistX {
get => _FovDistX;
set {
SetProperty(ref _FovDistX, value);
SelectedSubsysItem.CalRecipe.FovDistance.X = _FovDistX;
}
}
private double _FovDistY;
///
/// Fov Ditance Y값
///
public double FovDistY {
get => _FovDistY;
set {
SetProperty(ref _FovDistY, value);
SelectedSubsysItem.CalRecipe.FovDistance.Y = _FovDistY;
}
}
private eMotorType _usingTeachingMotorSetting;
///
/// 사용된 모터세팅
///
public eMotorType UsingTeachingMotorSetting {
get => _usingTeachingMotorSetting;
set {
SetProperty(ref _usingTeachingMotorSetting, value);
NotifyPropertyChanged(nameof(MotorDirection));
NotifyPropertyChanged(nameof(MotorDirectionT));
NotifyPropertyChanged(nameof(MoveObjectTypeX));
NotifyPropertyChanged(nameof(MoveObjectTypeY));
}
}
///
/// 이동할 객체 X축 타입
/// StaticMove | CamMove
///
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));
}
}
///
/// 이동할 객체 Y축 타입
/// StaticMove | CamMove
///
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;
///
/// 자재좌표세팅 뷰 모델
///
public StaticCoordSettingViewModel StaticCoordSettingVM { get => _staticCoordSettingVM; set => SetProperty(ref _staticCoordSettingVM, value); }
// Property View
private string visionPropertyViewHeader;
/// 비전 속성 뷰 헤더
public string VisionPropertyViewHeader { get => visionPropertyViewHeader; set => SetProperty(ref visionPropertyViewHeader, value); }
private object visionPropertyView;
/// 비전 속성 뷰
public object VisionPropertyView { get => visionPropertyView; set => SetProperty(ref visionPropertyView, value); }
/// 서브시스템 아이템이 선택되었는지 여부 확인
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));
}
}
}
///
/// 처음 들어갔을 때 Selected Item을 index 가 0 인 값으로 설정해 주기 위한 Method
///
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
}
}