From f8e1ff79cc2fa09b52093c6e029392b3456ad8bb Mon Sep 17 00:00:00 2001 From: Roy Date: Sat, 10 Feb 2018 17:27:37 +0200 Subject: Added dispensers support on technician module. --- .../Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml | 12 ++ .../AnalogSwitch/AnalogSwitch.xaml.cs | 66 ++++++++ .../Visual_Studio/Tango.Visuals/Images/off.png | Bin 0 -> 14366 bytes Software/Visual_Studio/Tango.Visuals/Images/on.png | Bin 0 -> 19420 bytes Software/Visual_Studio/Tango.Visuals/Led/Led.xaml | 117 ++++++++++++++ .../Visual_Studio/Tango.Visuals/Led/Led.xaml.cs | 179 +++++++++++++++++++++ .../Tango.Visuals/Tango.Visuals.csproj | 25 +++ 7 files changed, 399 insertions(+) create mode 100644 Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml create mode 100644 Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml.cs create mode 100644 Software/Visual_Studio/Tango.Visuals/Images/off.png create mode 100644 Software/Visual_Studio/Tango.Visuals/Images/on.png create mode 100644 Software/Visual_Studio/Tango.Visuals/Led/Led.xaml create mode 100644 Software/Visual_Studio/Tango.Visuals/Led/Led.xaml.cs (limited to 'Software/Visual_Studio/Tango.Visuals') diff --git a/Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml b/Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml new file mode 100644 index 000000000..c7ae4fe57 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml @@ -0,0 +1,12 @@ + + + + + + diff --git a/Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml.cs b/Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml.cs new file mode 100644 index 000000000..2149409a1 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/AnalogSwitch/AnalogSwitch.xaml.cs @@ -0,0 +1,66 @@ +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.Effects; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.Visuals +{ + /// + /// Interaction logic for AnalogSwitch.xaml + /// + public partial class AnalogSwitch : UserControl + { + public event Action CheckedChanged; + + public AnalogSwitch() + { + InitializeComponent(); + this.PreviewMouseUp += AnalogSwitch_PreviewMouseUp; + } + + void AnalogSwitch_PreviewMouseUp(object sender, MouseButtonEventArgs e) + { + IsChecked = !IsChecked; + } + + public bool IsChecked + { + get { return (bool)GetValue(IsCheckedProperty); } + set { SetValue(IsCheckedProperty, value); } + } + + // Using a DependencyProperty as the backing store for IsChecked. This enables animation, styling, binding, etc... + public static readonly DependencyProperty IsCheckedProperty = + DependencyProperty.Register("IsChecked", typeof(bool), typeof(AnalogSwitch), new PropertyMetadata(false,new PropertyChangedCallback(CheckChanged))); + + private static void CheckChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + AnalogSwitch s = d as AnalogSwitch; + if ((bool)e.NewValue) + { + s.imgON.Visibility = Visibility.Visible; + s.imgOFF.Visibility = Visibility.Hidden; + } + else + { + s.imgOFF.Visibility = Visibility.Visible; + s.imgON.Visibility = Visibility.Hidden; + } + + if (s.CheckedChanged != null) s.CheckedChanged(s); + } + + + } +} diff --git a/Software/Visual_Studio/Tango.Visuals/Images/off.png b/Software/Visual_Studio/Tango.Visuals/Images/off.png new file mode 100644 index 000000000..67f2f4a6f Binary files /dev/null and b/Software/Visual_Studio/Tango.Visuals/Images/off.png differ diff --git a/Software/Visual_Studio/Tango.Visuals/Images/on.png b/Software/Visual_Studio/Tango.Visuals/Images/on.png new file mode 100644 index 000000000..9922b1901 Binary files /dev/null and b/Software/Visual_Studio/Tango.Visuals/Images/on.png differ diff --git a/Software/Visual_Studio/Tango.Visuals/Led/Led.xaml b/Software/Visual_Studio/Tango.Visuals/Led/Led.xaml new file mode 100644 index 000000000..b59ed5d15 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Led/Led.xaml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.Visuals/Led/Led.xaml.cs b/Software/Visual_Studio/Tango.Visuals/Led/Led.xaml.cs new file mode 100644 index 000000000..5a1e67913 --- /dev/null +++ b/Software/Visual_Studio/Tango.Visuals/Led/Led.xaml.cs @@ -0,0 +1,179 @@ +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; +using Tango.Core.Commands; + +namespace Tango.Visuals +{ + /// + /// Represents an LED like button that acts like a check box. + /// + public partial class Led : UserControl + { + #region Constructors + + public Led() + { + InitializeComponent(); + this.PreviewMouseUp += LedControl_PreviewMouseUp; + } + + #endregion + + #region Event Handlers + + void LedControl_PreviewMouseUp(object sender, MouseButtonEventArgs e) + { + if (IsPassive) return; + + IsChecked = !IsChecked; + + if (Command != null) + { + Command.Execute(null); + } + } + + #endregion + + #region Properties + + /// + /// Gets or sets whether the LED is on or off. + /// + public bool IsChecked + { + get { return (bool)GetValue(IsCheckedProperty); } + set { SetValue(IsCheckedProperty, value); } + } + public static readonly DependencyProperty IsCheckedProperty = + DependencyProperty.Register("IsChecked", typeof(bool), typeof(Led), new PropertyMetadata(false)); + + + /// + /// Gets or sets whether the control is enabled. + /// + public bool Enabled + { + get { return (bool)GetValue(EnabledProperty); } + set { SetValue(EnabledProperty, value); } + } + public static readonly DependencyProperty EnabledProperty = + DependencyProperty.Register("Enabled", typeof(bool), typeof(Led), new PropertyMetadata(true, new PropertyChangedCallback(EnabledChanged))); + private static void EnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + Led l = d as Led; + if ((bool)e.NewValue) + { + l.gridMask.Visibility = Visibility.Hidden; + l.grid.Visibility = Visibility.Visible; + } + else + { + l.gridMask.Visibility = Visibility.Visible; + l.grid.Visibility = Visibility.Hidden; + } + } + + + public Brush FillBrush + { + get { return (Brush)GetValue(FillBrushProperty); } + set { SetValue(FillBrushProperty, value); } + } + public static readonly DependencyProperty FillBrushProperty = + DependencyProperty.Register("FillBrush", typeof(Brush), typeof(Led), new PropertyMetadata(null)); + + + public double InnerOpacity + { + get { return (double)GetValue(InnerOpacityProperty); } + set { SetValue(InnerOpacityProperty, value); } + } + public static readonly DependencyProperty InnerOpacityProperty = + DependencyProperty.Register("InnerOpacity", typeof(double), typeof(Led), new PropertyMetadata(1.0)); + + + public bool IsPassive + { + get { return (bool)GetValue(IsPassiveProperty); } + set { SetValue(IsPassiveProperty, value); } + } + public static readonly DependencyProperty IsPassiveProperty = + DependencyProperty.Register("IsPassive", typeof(bool), typeof(Led), new PropertyMetadata(false)); + + + + public Brush CheckedBrush + { + get { return (Brush)GetValue(CheckedBrushProperty); } + set { SetValue(CheckedBrushProperty, value); } + } + public static readonly DependencyProperty CheckedBrushProperty = + DependencyProperty.Register("CheckedBrush", typeof(Brush), typeof(Led), new PropertyMetadata(null,CheckBrushChanged)); + + private static void CheckBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var control = d as Led; + control.Resources["inner"] = control.CheckedBrush; + } + + + + public Brush UnCheckedBrush + { + get { return (Brush)GetValue(UnCheckedBrushProperty); } + set { SetValue(UnCheckedBrushProperty, value); } + } + public static readonly DependencyProperty UnCheckedBrushProperty = + DependencyProperty.Register("UnCheckedBrush", typeof(Brush), typeof(Led), new PropertyMetadata(null,UnCheckedBrushChanged)); + + private static void UnCheckedBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var control = d as Led; + control.Resources["innerOff"] = control.UnCheckedBrush; + } + + + + #endregion + + #region Commands + + /// + /// Represents the command to bind for CanExecute event. + /// + public RelayCommand Command + { + get { return (RelayCommand)GetValue(CommandProperty); } + set { SetValue(CommandProperty, value); } + } + public static readonly DependencyProperty CommandProperty = + DependencyProperty.Register("Command", typeof(RelayCommand), typeof(Led), new PropertyMetadata(null, new PropertyChangedCallback(CommandChanged))); + private static void CommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + Led l = d as Led; + + if (l.Command != null) + { + l.Command.CanExecuteChanged += (x, y) => + { + l.IsEnabled = l.Command.CanExecute(null); + }; + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Visuals/Tango.Visuals.csproj b/Software/Visual_Studio/Tango.Visuals/Tango.Visuals.csproj index 4eaa3376e..53c87d0f5 100644 --- a/Software/Visual_Studio/Tango.Visuals/Tango.Visuals.csproj +++ b/Software/Visual_Studio/Tango.Visuals/Tango.Visuals.csproj @@ -52,6 +52,9 @@ GlobalVersionInfo.cs + + AnalogSwitch.xaml + PieAxisTicks.xaml @@ -73,6 +76,9 @@ Knob.xaml + + Led.xaml + YAxisDoubles.xaml @@ -90,6 +96,10 @@ VUMeter.xaml + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -110,6 +120,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -188,6 +202,17 @@ + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + + + + +