aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ControllerItem.cs
blob: 8a9cba883ccde3dc90582daf2fa7cd6277892b8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Xml.Serialization;
using Tango.BL.Entities;
using Tango.SharedUI.Helpers;

namespace Tango.MachineStudio.Technician.TechItems
{
    /// <summary>
    /// Represents a single component value controller and monitor.
    /// </summary>
    /// <seealso cref="TechItem" />
    [TechItem(10)]
    public class ControllerItem : TechItem
    {
        /// <summary>
        /// Occurs when the controller value has changed.
        /// </summary>
        public event EventHandler<double> ValueChanged;

        private TechController _techController;
        /// <summary>
        /// Gets or sets the DB controller item.
        /// </summary>
        [XmlIgnore]
        public TechController TechController
        {
            get { return _techController; }
            set
            {
                _techController = value;
                RaisePropertyChangedAuto();
                TechName = _techController != null ? _techController.Description : null; ItemGuid = value != null ? value.Guid : null;

                if (_techController != null && !IsSetToDefault)
                {
                    OptimalRangeMinimum = _techController.Min;
                    OptimalRangeMaximum = _techController.Min + ((_techController.Max - _techController.Min) * 0.7d);
                    IsSetToDefault = true;
                }
            }
        }

        private double _value;
        /// <summary>
        /// Gets or sets the component value.
        /// </summary>
        [XmlIgnore]
        public double Value
        {
            get { return _value; }
            set
            {
                _value = value; RaisePropertyChangedAuto();
                ValueChanged?.Invoke(this, _value);
            }
        }

        private int _updateInterval;
        /// <summary>
        /// Gets or sets the update interval.
        /// </summary>
        public int UpdateInterval
        {
            get { return _updateInterval; }
            set { _updateInterval = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Gets or sets the last update time.
        /// </summary>
        [XmlIgnore]
        public DateTime LastUpdateTime { get; set; }

        private double _effectiveValue;
        /// <summary>
        /// Gets or sets the effective value received from the embedded device.
        /// </summary>
        [XmlIgnore]
        public double EffectiveValue
        {
            get { return _effectiveValue; }
            set
            {
                LastUpdateTime = DateTime.Now;

                if (_effectiveValue != value)
                {
                    _effectiveValue = value;
                    RaisePropertyChangedAuto();
                }
            }
        }

        private double _optimalRangeMinimum;
        /// <summary>
        /// Gets or sets the optimal range.
        /// </summary>
        public double OptimalRangeMinimum
        {
            get { return _optimalRangeMinimum; }
            set
            {
                _optimalRangeMinimum = value;
                RaisePropertyChangedAuto();
            }
        }

        private double _optimalRangeMaximum;
        public double OptimalRangeMaximum
        {
            get { return _optimalRangeMaximum; }
            set { _optimalRangeMaximum = value; RaisePropertyChangedAuto(); }
        }

        public bool IsSetToDefault { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerItem"/> class.
        /// </summary>
        public ControllerItem() : base()
        {
            Name = "Value Controller";
            Description = "Single component value controller";
            Image = ResourceHelper.GetImageFromResources("Images/controller.png");
            Color = Colors.DodgerBlue;
            LastUpdateTime = DateTime.Now;
            UpdateInterval = 10;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerItem"/> class.
        /// </summary>
        /// <param name="techController">The db tech controller.</param>
        public ControllerItem(TechController techController) : this()
        {
            TechController = techController;
        }

        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns></returns>
        public override TechItem Clone()
        {
            ControllerItem cloned = base.Clone() as ControllerItem;
            cloned.TechController = TechController;
            cloned.OptimalRangeMinimum = OptimalRangeMinimum;
            cloned.OptimalRangeMaximum = OptimalRangeMaximum;
            cloned.IsSetToDefault = IsSetToDefault;
            
            return cloned;
        }
    }
}
ryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="0" Duration="00:00:0.2" /> </Storyboard> </BeginStoryboard> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> </Border.Style> <Grid> <Grid.RowDefinitions> <RowDefinition Height="1.4*"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="188*"/> <ColumnDefinition Width="261*"/> </Grid.ColumnDefinitions> <Image Source="/Images/power-machine.png" Margin="30" /> <UniformGrid Grid.Column="1" Rows="3"> <touch:TouchButton Style="{StaticResource PowerButton}" Command="{Binding PowerOffCommand}">Turn Off</touch:TouchButton> <touch:TouchButton Style="{StaticResource PowerButton}">Stand By</touch:TouchButton> <touch:TouchButton Style="{StaticResource PowerButton}" Command="{Binding ResetCommand}">Reset</touch:TouchButton> </UniformGrid> </Grid> <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="25 0" Opacity="0.3" StrokeThickness="1" Stroke="{StaticResource TangoDividerBrush}" /> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="188*"/> <ColumnDefinition Width="261*"/> </Grid.ColumnDefinitions> <Image Source="/Images/power-tablet.png" Margin="30" /> <touch:TouchButton Command="{Binding RestartApplicationCommand}" Grid.Column="1" Style="{StaticResource PowerButton}">Restart</touch:TouchButton> </Grid> </Grid> </Border> <Border Background="{StaticResource TangoMidBackgroundBrush}" RenderTransformOrigin="0.5,1" VerticalAlignment="Bottom"> <Border.Style> <Style TargetType="Border"> <Setter Property="RenderTransform"> <Setter.Value> <ScaleTransform ScaleX="1" ScaleY="1" /> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding IsPowerOpened}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="0" Duration="00:00:0.2" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="1" Duration="00:00:0.2" /> </Storyboard> </BeginStoryboard> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> </Border.Style> <touch:TouchButton Style="{StaticResource TangoFlatButton}" Padding="40 25" Foreground="{StaticResource TangoDarkForegroundBrush}" Command="{Binding PowerCommand}"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> <Image Source="/Images/menu/power.png" VerticalAlignment="Center" Width="32" Height="32"></Image> <TextBlock VerticalAlignment="Center" Margin="40 0 0 0" Foreground="{StaticResource TangoPrimaryAccentBrush}">Power</TextBlock> </StackPanel> </touch:TouchButton> </Border> </Grid> </Grid> </Border> </touch:TouchSideMenu.MenuContent> <touch:TouchNotificationBar NotificationBarVisibility="{Binding NotificationProvider.NotificationsVisible,Converter={StaticResource BooleanToVisibilityConverter}}" HasNotifications="{Binding NotificationProvider.HasNotificationItems}" Notifications="{Binding NotificationProvider.NotificationItems}" ItemExpandedPropertyPath="IsExpanded"> <touch:TouchNotificationBar.NotificationTemplate> <DataTemplate> <components:Ripple Padding="0"> <Grid Background="Transparent"> <touch:TouchClickableControl Command="{Binding PressedCommand}"> <ContentControl Content="{Binding Converter={StaticResource ItemBaseConverter}}"/> </touch:TouchClickableControl> <touch:TouchIconButton Visibility="{Binding CanClose,Converter={StaticResource BooleanToVisibilityConverter}}" DockPanel.Dock="Right" Background="Transparent" Padding="35" Style="{StaticResource TangoRoundTouchIconButton}" Command="{Binding CloseCommand}" CommandParameter="{Binding}" HorizontalAlignment="Right" MaxHeight="90" Width="{Binding RelativeSource={RelativeSource Self},Path=ActualHeight}" Icon="Close" Foreground="{StaticResource TangoDarkForegroundBrush}" /> </Grid> </components:Ripple> </DataTemplate> </touch:TouchNotificationBar.NotificationTemplate> <DockPanel> <Border BorderThickness="0 0 0 1" BorderBrush="{StaticResource TangoDividerBrush}" DockPanel.Dock="Top"> <DockPanel> <Border BorderThickness="0 0 1 0" BorderBrush="{StaticResource TangoDividerBrush}"> <touch:TouchHamburgerButton IsHitTestVisible="{Binding NavigationManager.IsNavigating,Converter={StaticResource BooleanInverseConverter}}" IsEnabled="{Binding NavigationManager.IsBackEnabled}" Width="100" Height="100" Padding="15" Command="{Binding MenuOrBackCommand}" EnableDropShadow="False" Foreground="{StaticResource TangoPrimaryAccentBrush}" IsBack="{Binding NavigationManager.CanNavigateBack}"> </touch:TouchHamburgerButton> </Border> <Grid DockPanel.Dock="Right" Margin="0 0 20 0"> <StackPanel Orientation="Horizontal"> <StackPanel x:Name="techPressElement" VerticalAlignment="Center" Background="Transparent"> <locaControls:MachineStatusControl HorizontalAlignment="Center" DataContext="{Binding MachineProvider.MachineOperator}" /> <TextBlock Margin="0 10 0 0" Text="{Binding MachineProvider.MachineOperator.Status,Converter={StaticResource EnumToDescriptionConverter}}"></TextBlock> </StackPanel> <touch:TouchButton Margin="40 0 0 0" Height="65" Padding="50 0" MinWidth="200" CornerRadius="35" BlurRadius="20" Command="{Binding NotificationProvider.CurrentAppButton.Command}" IsEnabled="{Binding NotificationProvider.CurrentAppButton.IsEnabled}" Content="{Binding NotificationProvider.CurrentAppButton.Text}" Visibility="{Binding NotificationProvider.CurrentAppButton,Converter={StaticResource IsNullToVisibilityConverter}}"></touch:TouchButton> </StackPanel> </Grid> <Grid> <Grid Margin="20 0 60 0" Height="80" Visibility="{Binding NotificationProvider.HasAppBarItems,Converter={StaticResource BooleanToVisibilityConverter}}"> <ItemsControl ItemsSource="{Binding NotificationProvider.AppBarItems}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid IsItemsHost="True" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Grid Background="{StaticResource TangoPrimaryBackgroundBrush}"> <ContentControl Content="{Binding Converter={StaticResource AppBarItemConverter}}"></ContentControl> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> <!--External Header Content Here--> <!--<commonControls:AsyncAdornerControl> <commonControls:AsyncAdornerControl.Style> <Style TargetType="commonControls:AsyncAdornerControl"> <Setter Property="Visibility" Value="Hidden"></Setter> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding NotificationProvider.IsInGlobalBusyState}" Value="True" /> <Condition Binding="{Binding IsMenuOpened}" Value="False" /> </MultiDataTrigger.Conditions> <Setter Property="Visibility" Value="Visible"></Setter> </MultiDataTrigger> </Style.Triggers> </Style> </commonControls:AsyncAdornerControl.Style> <StackPanel VerticalAlignment="Center"> <touch:TouchGifAnimation Source="/Images/preloader_rectangles.gif" EnableAnimation="{Binding NotificationProvider.IsInGlobalBusyState}" /> </StackPanel> </commonControls:AsyncAdornerControl>--> </Grid> </DockPanel> </Border> <Grid Background="{StaticResource TangoKeyboardBackground}"> <controls:NavigationControl x:Name="NavigationControl" x:FieldModifier="public" TransitionAlwaysFades="False" TransitionType="Zoom" KeepElementsAttached="False" UseDefferedRendering="True"> <!--MODULES GOES HERE--> </controls:NavigationControl> </Grid> </DockPanel> </touch:TouchNotificationBar> </touch:TouchSideMenu> <Grid PreviewMouseUp="Grid_PreviewMouseUp" IsHitTestVisible="True" Background="Transparent" Visibility="{Binding ApplicationManager.IsScreenLocked,Converter={StaticResource BooleanToVisibilityConverter}}"> <touch:TouchIcon HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="40" Icon="Lock" Width="60" Height="60" Opacity="0.5" Foreground="{StaticResource TangoSuccessBrush}" /> </Grid> </Grid> </UserControl>