123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- using OpenSEMI.Ctrlib.Types;
- using System;
- using System.Collections.Generic;
- 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;
- namespace OpenSEMI.Ctrlib.Controls
- {
-
- public delegate void DragDropHandler(object sender, DragDropEventArgs e);
- public class DragDropEventArgs : EventArgs
- {
- public Slot TranferFrom { get; set; }
- public Slot TranferTo { get; set; }
- public DragDropEventArgs(Slot p_TranferFrom, Slot p_TranferTo)
- {
- this.TranferFrom = p_TranferFrom;
- this.TranferTo = p_TranferTo;
- }
- }
- [Flags]
- public enum SlotBorderStatus
- {
- MouseOver = 1,
- TransferSource = 2,
- TransferTarget = 4,
- Selected = 8,
- None = 16
- }
- public class Slot : ContentControl
- {
- public event MouseButtonEventHandler SlotMouseButtonDown;
- public event DragDropHandler WaferTransferStarted;
- static Slot()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(Slot), new FrameworkPropertyMetadata(typeof(Slot)));
- }
-
- public bool IsDraggable { get; set; }
- public bool IsLeftMouseDown { get; set; } //confirm drag source is current slot
-
- public string ViewType
- {
- get { return (string)GetValue(ViewTypeProperty); }
- set { SetValue(ViewTypeProperty, value); }
- }
- public static readonly DependencyProperty ViewTypeProperty =
- DependencyProperty.Register("ViewType", typeof(string), typeof(Slot),
- new UIPropertyMetadata("Front"));
-
-
- public int WaferStatus
- {
- get { return (int)GetValue(WaferStatusProperty); }
- set { SetValue(WaferStatusProperty, value); }
- }
- public static readonly DependencyProperty WaferStatusProperty =
- DependencyProperty.Register("WaferStatus", typeof(int), typeof(Slot),
- new UIPropertyMetadata(0, new PropertyChangedCallback(WaferStatusChangedCallBack)));
-
- public int SlotID
- {
- get { return (int)GetValue(SlotIDProperty); }
- set { SetValue(SlotIDProperty, value); }
- }
- public static readonly DependencyProperty SlotIDProperty =
- DependencyProperty.Register("SlotID", typeof(int), typeof(Slot), new UIPropertyMetadata(-1));
-
- public string ModuleID
- {
- get { return (string)GetValue(ModuleIDProperty); }
- set { SetValue(ModuleIDProperty, value); }
- }
- public static readonly DependencyProperty ModuleIDProperty =
- DependencyProperty.Register("ModuleID", typeof(string), typeof(Slot), new UIPropertyMetadata(string.Empty));
-
- public bool IsDragSource
- {
- get { return (bool)GetValue(IsDragSourceProperty); }
- set { SetValue(IsDragSourceProperty, value); }
- }
- public static readonly DependencyProperty IsDragSourceProperty =
- DependencyProperty.Register("IsDragSource", typeof(bool), typeof(Slot),
- new UIPropertyMetadata(false, new PropertyChangedCallback(IsDragSourcePropertyChangedCallBack)));
-
- public bool IsDropTarget
- {
- get { return (bool)GetValue(IsDropTargetProperty); }
- set { SetValue(IsDropTargetProperty, value); }
- }
- public static readonly DependencyProperty IsDropTargetProperty =
- DependencyProperty.Register("IsDropTarget", typeof(bool), typeof(Slot),
- new UIPropertyMetadata(false, new PropertyChangedCallback(IsDropTargetPropertyChangedCallBack)));
-
- public bool IsDragEnter
- {
- get { return (bool)GetValue(IsDragEnterProperty); }
- set { SetValue(IsDragEnterProperty, value); }
- }
- public static readonly DependencyProperty IsDragEnterProperty =
- DependencyProperty.Register("IsDragEnter", typeof(bool), typeof(Slot),
- new UIPropertyMetadata(false, new PropertyChangedCallback(IsDragEnterPropertyChangedCallBack)));
-
- public bool IsSelected
- {
- get { return (bool)GetValue(IsSelectedProperty); }
- set { SetValue(IsSelectedProperty, value); }
- }
- public static readonly DependencyProperty IsSelectedProperty =
- DependencyProperty.Register("IsSelected", typeof(bool), typeof(Slot),
- new UIPropertyMetadata(false, new PropertyChangedCallback(IsSelectedPropertyChangedCallBack)));
-
- public bool HasWafer
- {
- get { return (bool)GetValue(HasWaferProperty); }
- set { SetValue(HasWaferProperty, value); }
- }
- public static readonly DependencyProperty HasWaferProperty =
- DependencyProperty.Register("HasWafer", typeof(bool), typeof(Slot),
- new UIPropertyMetadata(false, HasWaferChanged));
-
- public SlotBorderStatus BorderStatus
- {
- get { return (SlotBorderStatus)GetValue(BorderStatusProperty); }
- set { SetValue(BorderStatusProperty, value); }
- }
- public static readonly DependencyProperty BorderStatusProperty =
- DependencyProperty.Register("BorderStatus", typeof(SlotBorderStatus), typeof(Slot),
- new UIPropertyMetadata(SlotBorderStatus.None));
-
- public string SourceName
- {
- get { return (string)GetValue(SourceNameProperty); }
- set { SetValue(SourceNameProperty, value); }
- }
- public static readonly DependencyProperty SourceNameProperty =
- DependencyProperty.Register("SourceName", typeof(string), typeof(Slot), new UIPropertyMetadata(string.Empty));
-
-
- public bool CanDragDrop
- {
- get { return (bool)GetValue(CanDragDropProperty); }
- set { SetValue(CanDragDropProperty, value); }
- }
- public static readonly DependencyProperty CanDragDropProperty =
- DependencyProperty.Register("CanDragDrop", typeof(bool), typeof(Slot), new UIPropertyMetadata(true, new PropertyChangedCallback(CanDragDropPropertyChangedCallBack)));
-
- public string WaferTooltip
- {
- get { return (string)GetValue(WaferTooltipProperty); }
- set { SetValue(WaferTooltipProperty, value); }
- }
- public static readonly DependencyProperty WaferTooltipProperty =
- DependencyProperty.Register("WaferTooltip", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
-
- public string WaferTooltipExt
- {
- get { return (string)GetValue(WaferTooltipExtProperty); }
- set { SetValue(WaferTooltipExtProperty, value); }
- }
- public static readonly DependencyProperty WaferTooltipExtProperty =
- DependencyProperty.Register("WaferTooltipExt", typeof(string), typeof(Slot), new PropertyMetadata(string.Empty));
-
- public Visibility DuplicatedVisibility
- {
- get { return (Visibility)GetValue(DuplicatedVisibilityProperty); }
- set { SetValue(DuplicatedVisibilityProperty, value); }
- }
- public static readonly DependencyProperty DuplicatedVisibilityProperty =
- DependencyProperty.Register("DuplicatedVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Collapsed));
- public Visibility WaferVisibility
- {
- get { return (Visibility)GetValue(WaferVisibilityProperty); }
- set { SetValue(WaferVisibilityProperty, value); }
- }
- public static readonly DependencyProperty WaferVisibilityProperty =
- DependencyProperty.Register("WaferVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Visible));
- public Visibility WaferSamllVisibility
- {
- get { return (Visibility)GetValue(WaferSamllVisibilityProperty); }
- set { SetValue(WaferSamllVisibilityProperty, value); }
- }
- public static readonly DependencyProperty WaferSamllVisibilityProperty =
- DependencyProperty.Register("WaferSamllVisibility", typeof(Visibility), typeof(Slot), new UIPropertyMetadata(Visibility.Collapsed));
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- DragDropStatusControl(this);
- }
- protected override void OnDragEnter(DragEventArgs e)
- {
- base.OnDragEnter(e);
- this.IsDragEnter = true;
- }
- protected override void OnDragLeave(DragEventArgs e)
- {
- base.OnDragLeave(e);
- this.IsDragEnter = false;
- }
- protected override void OnMouseDown(MouseButtonEventArgs e)
- {
- base.OnMouseDown(e);
- if (MouseButtonState.Pressed == e.LeftButton)
- IsLeftMouseDown = true;
- e.Handled = true;
- }
- protected override void OnMouseUp(MouseButtonEventArgs e)
- {
- base.OnMouseUp(e);
- IsLeftMouseDown = false;
- MouseButtonEventHandler handler = SlotMouseButtonDown;
- if (handler != null)
- {
- handler(this, e);
- }
- }
- protected override void OnMouseEnter(MouseEventArgs e)
- {
- base.OnMouseEnter(e);
- this.BorderStatus = this.BorderStatus | SlotBorderStatus.MouseOver;
- }
- protected override void OnMouseLeave(MouseEventArgs e)
- {
- base.OnMouseLeave(e);
- IsLeftMouseDown = false;
- this.BorderStatus = this.BorderStatus & (~SlotBorderStatus.MouseOver);
- }
- private static void DragDropStatusControl(Slot p_slot)
- {
- p_slot.AllowDrop = false;
- p_slot.IsDraggable = false;
- if (p_slot.CanDragDrop)
- {
- if (!p_slot.IsDropTarget && p_slot.WaferStatus == 0)
- p_slot.AllowDrop = true;
- if (!p_slot.IsDragSource && p_slot.WaferStatus != 0)
- p_slot.IsDraggable = true;
- }
- }
- private static void IsDropTargetPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
- {
- Slot m_slot = d as Slot;
- if (m_slot.IsDropTarget)
- m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.TransferTarget; //add
- else
- m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.TransferTarget); //remove
- DragDropStatusControl(m_slot);
- }
- private static void IsDragSourcePropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
- {
- Slot m_slot = d as Slot;
- if (m_slot.IsDragSource)
- m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.TransferSource; //add
- else
- m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.TransferSource); //remove
- DragDropStatusControl(m_slot);
- }
- private static void IsSelectedPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
- {
- Slot m_slot = d as Slot;
- if (m_slot.IsSelected)
- m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.Selected; //add
- else
- m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.Selected); //remove
- }
- private static void CanDragDropPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
- {
- Slot m_slot = d as Slot;
- DragDropStatusControl(m_slot);
- }
- private static void IsDragEnterPropertyChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
- {
- Slot m_slot = d as Slot;
- if (m_slot.IsDragEnter)
- m_slot.BorderStatus = m_slot.BorderStatus | SlotBorderStatus.TransferTarget; //add
- else
- m_slot.BorderStatus = m_slot.BorderStatus & (~SlotBorderStatus.TransferTarget); //remove
- }
- private static void WaferStatusChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args)
- {
- Slot m_slot = d as Slot;
- m_slot.IsDragSource = false;
- m_slot.IsDropTarget = false;
- m_slot.IsDragEnter = false;
- DragDropStatusControl(m_slot);
- }
- public static void HasWaferChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- Slot m_slot = d as Slot;
- if (m_slot != null)
- {
- if (m_slot.HasWafer)
- m_slot.WaferStatus = 7;
- else
- m_slot.WaferStatus = 0;
- }
- }
- protected override void OnPreviewMouseMove(MouseEventArgs e)
- {
- base.OnPreviewMouseMove(e);
- if (e.LeftButton == MouseButtonState.Pressed && IsDraggable && IsLeftMouseDown)
- {
- DataObject data = new DataObject(typeof(Slot), this);
- DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
- }
- }
- protected override void OnDrop(DragEventArgs e)
- {
- if (this.AllowDrop)
- {
- try
- {
- IDataObject data = e.Data;
- if (data.GetDataPresent(typeof(Slot)))
- {
- Slot m_dragSource = (Slot)data.GetData(typeof(Slot));
- m_dragSource.IsDragSource = true; //source
- this.IsDropTarget = true; //target
- if (WaferTransferStarted != null)
- {
- DragDropEventArgs m_arg = new DragDropEventArgs(m_dragSource, this);
- WaferTransferStarted(this, m_arg);
- }
- }
- else //to support another type of wafer
- {
- //var sourceWafer = (WaferInfo)e.Data.GetData("Object");
- var sourceStation = e.Data.GetData("Station").ToString();
- var sourceSlot = (int)e.Data.GetData("Slot");
- Slot m_dragSource = new Slot() { ModuleID = sourceStation, SlotID = sourceSlot };
- if (WaferTransferStarted != null)
- {
- DragDropEventArgs m_arg = new DragDropEventArgs(m_dragSource, this);
- WaferTransferStarted(this, m_arg);
- }
- }
- }
- catch
- {
- }
- }
- }
-
- public bool IsValidSlot()
- {
- if (this.ModuleID.Length >0 && this.SlotID >= 0)
- return true;
- else
- return false;
- }
- public bool IsSameSlot(Slot slot)
- {
- if (slot.IsValidSlot() && this.IsValidSlot())
- {
- if (this.ModuleID == slot.ModuleID && this.SlotID == slot.SlotID)
- return true;
- }
- return false;
- }
- public void ClearDragDropStatus()
- {
- this.IsDragEnter = false;
- this.IsDragSource = false;
- this.IsDropTarget = false;
- }
-
- }
- }
|