using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.Editors;
using Tango.BL.Entities;
using Tango.MachineStudio.Technician.TechItems;
using Tango.Core;
namespace Tango.MachineStudio.Technician.Editors
{
[ContentProperty("InnerContent")]
public partial class ThreadMotionElementEditor : ElementEditor
{
///
/// Initializes a new instance of the class.
///
public ThreadMotionElementEditor()
: base()
{
InitializeComponent();
}
///
/// Initializes a new instance of the class.
///
/// The framework element.
public ThreadMotionElementEditor(ThreadMotionItem motorItem)
: this()
{
ThreadMotionItem = motorItem;
DataContext = ThreadMotionItem;
}
///
/// Initializes a new instance of the class.
///
/// The framework element.
/// The bounds.
public ThreadMotionElementEditor(ThreadMotionItem threadMotionItem, Rect bounds)
: this(threadMotionItem)
{
Left = bounds.Left;
Top = bounds.Top;
Width = bounds.Width;
Height = bounds.Height;
}
private ThreadMotionItem _threadMotionItem;
public ThreadMotionItem ThreadMotionItem
{
get { return _threadMotionItem; }
set
{
_threadMotionItem = value; RaisePropertyChanged(nameof(ThreadMotionItem));
}
}
///
/// Clones this instance.
///
///
public override IElementEditor Clone()
{
try
{
var clonedItem = ThreadMotionItem.Clone() as ThreadMotionItem;
ThreadMotionElementEditor cloned = new ThreadMotionElementEditor(clonedItem);
cloned.Top = Top;
cloned.Left = Left;
cloned.Width = Width;
cloned.Height = Height;
cloned.Angle = Angle;
return cloned;
}
catch (Exception ex)
{
throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex);
}
}
///
/// Gets the hosted element.
///
[ParameterIgnore]
public override Object HostedElement
{
get { return ThreadMotionItem; }
}
private void OnForwardPressed(object sender, MouseButtonEventArgs e)
{
(e.Source as FrameworkElement).CaptureMouse();
ThreadMotionItem.RaiseAction(MotorActionType.ForwardPressed);
AnimateRight();
}
private void OnForwardReleased(object sender, MouseButtonEventArgs e)
{
(e.Source as FrameworkElement).ReleaseMouseCapture();
ThreadMotionItem.RaiseAction(MotorActionType.ForwardReleased);
StopAnimation();
}
private void OnBackwardPressed(object sender, MouseButtonEventArgs e)
{
(e.Source as FrameworkElement).CaptureMouse();
ThreadMotionItem.RaiseAction(MotorActionType.BackwardPressed);
AnimateLeft();
}
private void OnBackwardReleased(object sender, MouseButtonEventArgs e)
{
(e.Source as FrameworkElement).ReleaseMouseCapture();
ThreadMotionItem.RaiseAction(MotorActionType.BackwardReleased);
StopAnimation();
}
private void OnHomingStarted(object sender, RoutedEventArgs e)
{
ThreadMotionItem.RaiseAction(MotorActionType.HomingForwardStarted);
AnimateLeft();
}
private void OnHomingStopped(object sender, RoutedEventArgs e)
{
ThreadMotionItem.RaiseAction(MotorActionType.HomingStopped);
StopAnimation();
}
private void AnimateRight()
{
WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Play();
}
private void AnimateLeft()
{
WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Play();
}
public void StopAnimation()
{
this.Dispatcher.Invoke(() =>
{
WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Pause();
});
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}