using Aitex.Core.Common;
using Aitex.Core.RT.SCCore;
using Aitex.Core.UI.MVVM;
using Aitex.Sorter.Common;
using MECF.Framework.Common.OperationCenter;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using MECF.Framework.Common.Equipment;
namespace Aitex.Sorter.UI.Controls
{
///
/// Wafer.xaml 的交互逻辑
///
public partial class Wafer : UserControl
{
public static readonly DependencyProperty WaferItemProperty = DependencyProperty.Register(
"WaferItem", typeof(WaferInfo), typeof(Wafer),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
public WaferInfo WaferItem
{
get
{
return (WaferInfo)GetValue(WaferItemProperty);
}
set
{
SetValue(WaferItemProperty, value);
}
}
public bool IsEnableTextMenu
{
get { return (bool)GetValue(IsEnableTextMenuProperty); }
set { SetValue(IsEnableTextMenuProperty, value); }
}
// Using a DependencyProperty as the backing store for IsEnableTextMenu. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsEnableTextMenuProperty =
DependencyProperty.Register("IsEnableTextMenu", typeof(bool), typeof(Wafer), new PropertyMetadata(true));
public int Slot
{
get { return (int)GetValue(SlotProperty); }
set { SetValue(SlotProperty, value); }
}
// Using a DependencyProperty as the backing store for Slot. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SlotProperty =
DependencyProperty.Register("Slot", typeof(int), typeof(Wafer), new PropertyMetadata(-1));
public ModuleName Station
{
get { return (ModuleName)GetValue(StationProperty); }
set { SetValue(StationProperty, value); }
}
// Using a DependencyProperty as the backing store for Station. This enables animation, styling, binding, etc...
public static readonly DependencyProperty StationProperty =
DependencyProperty.Register("Station", typeof(ModuleName), typeof(Wafer), new PropertyMetadata(ModuleName.System));
public ICommand WaferTransferCommand
{
get { return (ICommand)GetValue(WaferTransferCommandProperty); }
set { SetValue(WaferTransferCommandProperty, value); }
}
public bool ShowSlot
{
get { return (bool)GetValue(ShowSlotProperty); }
set { SetValue(ShowSlotProperty, value); }
}
// Using a DependencyProperty as the backing store for ShowSlot. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowSlotProperty =
DependencyProperty.Register("ShowSlot", typeof(bool), typeof(Wafer), new PropertyMetadata(false));
public bool ShowControl
{
get { return (bool)GetValue(ShowControlProperty); }
set {
SetValue(ShowControlProperty, value);
}
}
public static readonly DependencyProperty ShowControlProperty =
DependencyProperty.Register("ShowControl", typeof(bool), typeof(Wafer), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.None));
// Using a DependencyProperty as the backing store for WaferMovementCommand. This enables animation, styling, binding, etc...
public static readonly DependencyProperty WaferTransferCommandProperty =
DependencyProperty.Register("WaferTransferCommand", typeof(ICommand), typeof(Wafer), new PropertyMetadata(null));
public WaferDisplayMode WaferIDDisplayMode
{
get { return (WaferDisplayMode)GetValue(WaferDisplayModeProperty); }
set { SetValue(WaferDisplayModeProperty, value); }
}
// Using a DependencyProperty as the backing store for WaferIDDisplayMode. This enables animation, styling, binding, etc...
public static readonly DependencyProperty WaferDisplayModeProperty =
DependencyProperty.Register("WaferIDDisplayMode", typeof(WaferDisplayMode), typeof(Wafer), new PropertyMetadata(WaferDisplayMode.None));
public ICommand WaferTransferOptionCommand
{
get { return (ICommand)GetValue(WaferTransferOptionCommandProperty); }
set { SetValue(WaferTransferOptionCommandProperty, value); }
}
// Using a DependencyProperty as the backing store for WaferTransferOptionCommand. This enables animation, styling, binding, etc...
public static readonly DependencyProperty WaferTransferOptionCommandProperty =
DependencyProperty.Register("WaferTransferOptionCommand", typeof(ICommand), typeof(Wafer), new PropertyMetadata(null));
public ICommand CreateDeleteWaferCommand
{
get { return (ICommand)GetValue(CreateDeleteWaferCommandProperty); }
set { SetValue(CreateDeleteWaferCommandProperty, value); }
}
// Using a DependencyProperty as the backing store for CreateDeleteWaferCommand. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CreateDeleteWaferCommandProperty =
DependencyProperty.Register("CreateDeleteWaferCommand", typeof(ICommand), typeof(Wafer), new PropertyMetadata(null));
private WaferStyle waferStyle = WaferStyle.Rect;
public WaferStyle WaferStyle
{
get
{
return waferStyle;
}
set
{
waferStyle = value;
}
}
public Wafer()
{
InitializeComponent();
CreateDeleteWaferCommand = new DelegateCommand(CreateDeleteWafer);
root.DataContext = this;
}
private void Wafer_MouseMove(object sender, MouseEventArgs e)
{
if (WaferItem == null)
{
return;
}
if (e.LeftButton == MouseButtonState.Pressed && (WaferItem.Status == WaferStatus.Normal || WaferItem.Status == WaferStatus.Dummy) && !WaferItem.IsSource)
{
var data = new DataObject();
data.SetData("Object", WaferItem);
data.SetData("Station", Station);
data.SetData("Slot", Slot);
DragDrop.DoDragDrop(sender as DependencyObject,
data,
DragDropEffects.Copy | DragDropEffects.Move);
}
}
private void Wafer_Drop(object sender, DragEventArgs e)
{
if (sender != null)
{
var target = (Border)sender;
target.BorderThickness = new Thickness(0);
if (target.ToolTip as ToolTip != null)
((ToolTip)target.ToolTip).IsOpen = false;
var sourceWafer = (WaferInfo)e.Data.GetData("Object");
var sourceStation = (ModuleName)e.Data.GetData("Station");
var sourceSlot = (int)e.Data.GetData("Slot");
if (sourceWafer == null)
{
return;
}
if (sourceStation == ModuleName.Robot && Station == ModuleName.Robot)
{
return;
}
WaferTransferOption transferOption = null;
if (WaferTransferOptionCommand != null)
{
transferOption = new WaferTransferOption();
WaferTransferOptionCommand.Execute(transferOption);
}
//if (sourceWafer.SubstE90Status == EnumE90Status.InProcess || sourceWafer.SubstE90Status== EnumE90Status.NeedProcessing)
//{
// return;
//}
var dialog = new WaferTransferDialog(sourceWafer, sourceStation, sourceSlot, Station, Slot, transferOption);
dialog.SetControlShow(ShowControl);
dialog.Owner = Window.GetWindow(this);
if (dialog.ShowDialog() == true)
{
if (sourceWafer.Status == WaferStatus.Dummy)
{
if (WaferTransferCommand != null)
{
WaferTransferCommand.Execute(new SorterRecipeTransferTableItem
{
SourceStation = sourceStation,
SourceSlot = sourceSlot,
DestinationStation = Station,
DestinationSlot = Slot,
IsAlign = dialog.Aligner,
IsTurnOver = dialog.TurnOver,
IsReadLaserMarker = dialog.ReadLaserMarker,
IsReadT7Code = dialog.ReadT7Code,
AlignAngle = dialog.AlignerAngle
});
}
}
else
{
var moveType = MoveType.Move;
MoveOption moveOption = 0;
if (dialog.Aligner)
{
moveOption |= MoveOption.Align;
}
if (dialog.TurnOver)
{
moveOption |= MoveOption.Turnover;
}
if (dialog.ReadLaserMarker)
{
moveOption |= MoveOption.ReadID;
}
if (dialog.ReadT7Code)
{
moveOption |= MoveOption.ReadID2;
}
var hand = (Hand)dialog.Blade;
object[] param;
if (hand == Hand.Both)
{
param = new object[]
{
moveType,
moveOption,
hand,
sourceStation,
sourceSlot,
Station,
Slot,
dialog.AlignerAngle
};
InvokeClient.Instance.Service.DoOperation(OperationName.MultiMoveWafer, param);
}
else
{
param = new object[]
{
moveType,
moveOption,
hand,
sourceStation,
sourceSlot,
Station,
Slot,
dialog.AlignerAngle
};
InvokeClient.Instance.Service.DoOperation(OperationName.MoveWafer.ToString(), param);
}
}
}
}
}
private void CreateDeleteWafer(string cmd)
{
var param = new object[] { Station, Slot, WaferStatus.Normal };
InvokeClient.Instance.Service.DoOperation(cmd, param);
}
private void Border_DragOver(object sender, DragEventArgs e)
{
var sourceWafer = (WaferInfo)e.Data.GetData("Object");
var sourceStation = (ModuleName)e.Data.GetData("Station");
var sourceSlot = (int)e.Data.GetData("Slot");
if (!(sourceStation == Station && sourceSlot == Slot))
{
var target = (Border)sender;
target.BorderThickness = new Thickness(1);
((ToolTip)target.ToolTip).Content = Slot + 1;
((ToolTip)target.ToolTip).IsOpen = true;
}
}
private void Border_DragLeave(object sender, DragEventArgs e)
{
var sourceWafer = (WaferInfo)e.Data.GetData("Object");
var sourceStation = (ModuleName)e.Data.GetData("Station");
var sourceSlot = (int)e.Data.GetData("Slot");
if (!(sourceStation == Station && sourceSlot == Slot))
{
var target = (Border)sender;
target.BorderThickness = new Thickness(0);
((ToolTip)target.ToolTip).IsOpen = false;
}
}
private void PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
e.Handled = IsEnableTextMenu ? false : true;
}
}
public enum WaferStyle
{
Rect,
Eclipse
}
public class WaferTransferOption
{
public WaferTransferOption()
{
Setting = new WaferTransferOptionSetting();
}
public bool Align { get; set; }
public bool TurnOver { get; set; }
public bool ReadLaserMarker { get; set; }
public bool ReadT7Code { get; set; }
public int Blade { get; set; }
public double AlignerAngle { get; set; }
public WaferTransferOptionSetting Setting { get; set; }
}
public class WaferTransferOptionSetting
{
public WaferTransferOptionSetting()
{
ShowAlign = true;
ShowLaserMarker = true;
ShowT7Code = true;
ShowTurnOver = false;
ShowBlade = true;
ShowTurnOverBeforeAlign = true;
}
public bool ShowAlign { get; set; }
public bool ShowLaserMarker { get; set; }
public bool ShowT7Code { get; set; }
public bool ShowTurnOver { get; set; } = false;
public bool ShowBlade { get; set; }
public bool ShowTurnOverBeforeAlign { get; set; } = false;
}
}