aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/ReachGraphs/RealTimeGraphExReachMultiLineErase.cs
blob: 368d22e0729fb8e71ddbae9f457295758046005d (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace RealTimeGraphEx.ReachGraphs
{
    public class RealTimeGraphExReachMultiLineErase : RealTimeGraphExReachMultiLineScroll
    {
        #region Cross Thread Fields

        protected Brush _markerColor;
        protected bool _showMarker;
        protected bool _endReached;
        protected int _currentReplaceIndex;
        protected Rectangle marker;

        #endregion

        #region Constructors

        public RealTimeGraphExReachMultiLineErase()
            : base()
        {

        }

        #endregion

        #region Properties


        /// <summary>
        /// Gets or sets the graph marker color.
        /// </summary>
        public Brush MarkerColor
        {
            get { return (Brush)GetValue(MarkerColorProperty); }
            set { SetValue(MarkerColorProperty, value); }
        }
        public static readonly DependencyProperty MarkerColorProperty =
            DependencyProperty.Register("MarkerBrush", typeof(Brush), typeof(RealTimeGraphExReachMultiLineErase), new PropertyMetadata(Brushes.Red, new PropertyChangedCallback(CrossModelChanged)));

        /// <summary>
        /// Gets or sets whether to display the marker on the graph.
        /// </summary>
        public bool ShowMarker
        {
            get { return (bool)GetValue(ShowMarkerProperty); }
            set { SetValue(ShowMarkerProperty, value); }
        }
        public static readonly DependencyProperty ShowMarkerProperty =
            DependencyProperty.Register("ShowMarker", typeof(bool), typeof(RealTimeGraphExReachMultiLineErase), new PropertyMetadata(true, new PropertyChangedCallback(CrossModelChanged)));


        #endregion

        #region Override Methods

        protected override void Initialize()
        {
            base.Initialize();
            marker = new Rectangle() { VerticalAlignment = System.Windows.VerticalAlignment.Stretch, Width = 1, Fill = MarkerColor, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, Margin = new Thickness(-2, 0, 0, 0) };

            if (!gridLinesAndImageWrapperGrid.Children.Contains(marker))
            {
                gridLinesAndImageWrapperGrid.Children.Add(marker);
            }
        }

        protected override void OnSetCrossThreadFields()
        {
            base.OnSetCrossThreadFields();

            this.Dispatcher.Invoke(() =>
            {

                _markerColor = MarkerColor;
                _showMarker = ShowMarker;

            }, System.Windows.Threading.DispatcherPriority.Send);
        }

        protected override void OnClearGraph()
        {
            base.OnClearGraph();

            _currentReplaceIndex = 0;
            _endReached = false;

            this.Dispatcher.Invoke(() =>
            {
                marker.RenderTransform = new TranslateTransform(0, 0);
            });
        }

        protected internal override void OnRenderGraph()
        {
            if (_graphController != null && _graphController.dataSeriesCollection.Count > 0 && _graphController.TotalPoints > 0  && _width > 1 && _height > 1)
            {
                for (int i = 0; i < _graphController.dataSeriesCollection[0].Points.Count; i++) //Match
                {
                    if (xValueCounter <= _width)
                    {
                        if (!_endReached)
                        {
                            for (int j = 0; j < _graphController.dataSeriesCollection.Count; j++)
                            {
                                double value = _graphController.dataSeriesCollection[j].Points[i];
                                double valuePrecentage = value;

                                _graphPolygons[j].Add(xValueCounter, valuePrecentage, value);
                            }

                            xValueCounter += _scaleFactor;
                        }
                        else
                        {
                            for (int j = 0; j < _graphController.dataSeriesCollection.Count; j++)
                            {
                                double value = _graphController.dataSeriesCollection[j].Points[i];

                                double valuePrecentage = value;
                                _graphPolygons[j].Replace(xValueCounter, valuePrecentage, value, _currentReplaceIndex);

                                if (j == _graphController.dataSeriesCollection.Count - 1)
                                {
                                    _currentReplaceIndex++;
                                }
                            }

                            xValueCounter += _scaleFactor;

                            if (_currentReplaceIndex > _graphPolygons[0].TotalPoints - 1)
                            {
                                xValueCounter = 0;
                                _currentReplaceIndex = 0;
                            }
                        }
                    }
                    else
                    {
                        _endReached = true;
                        xValueCounter = 0;


                        for (int j = 0; j < _graphController.dataSeriesCollection.Count; j++)
                        {
                            double value = _graphController.dataSeriesCollection[j].Points[i];

                            double valuePrecentage = value;

                            _graphPolygons[j].Replace(xValueCounter, valuePrecentage, value, _currentReplaceIndex);

                            if (j == _graphController.dataSeriesCollection.Count - 1)
                            {
                                _currentReplaceIndex++;
                            }
                        }

                        xValueCounter += _scaleFactor;
                    }
                }


                updateCounter++;

                if (updateCounter >= 1 && !_isPaused)
                {
                    OnDrawVisuals();
                }
            }
        }

        protected override void OnDrawVisuals()
        {
            base.OnDrawVisuals();

            if (_graphPolygons.Count > 0)
            {
                double scale = _width / (_graphPolygons[0].TotalPoints - 1);

                this.Dispatcher.Invoke(() =>
                {
                    marker.RenderTransform = new TranslateTransform((_currentReplaceIndex * scale) - 2, 0);
                });
            }
        }

        #endregion
    }
}
"w"> IsMenuOpened = false; NavigationManager.NavigateTo(moduleName); } /// <summary> /// Handles the home command. /// </summary> private void NavigateHome() { LogManager.Log("Navigate home command pressed."); IsMenuOpened = false; NavigationManager.NavigateTo(NavigationView.HomeModule); } /// <summary> /// Represents an event that is raised when the sign-out operation is complete. /// </summary> private void SignOut() { LogManager.Log("SignOut command pressed."); AuthenticationProvider.LogOut(); IsMenuOpened = false; } /// <summary> /// Opens the first notification or display all. /// </summary> private void OpenFirstNotificationOrDisplayAll() { if (NotificationProvider.NotificationItems.Count == 1) { //Open first } else { IsNotificationsOpened = true; } } /// <summary> /// Restarts the application. /// </summary> private async void RestartApplication() { if (await NotificationProvider.ShowQuestion("Are you sure you want to restart the application?")) { ApplicationManager.Restart(); } } /// <summary> /// Powers off the machine. /// </summary> private async void PowerOffMachine() { IsMenuOpened = false; if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?")) { try { await MachineProvider.MachineOperator.PowerDown(); } catch (Exception ex) { LogManager.Log(ex, "Error triggering power down."); await NotificationProvider.ShowError(ex.FlattenMessage()); } } } /// <summary> /// Resets the machine. /// </summary> private async void ResetMachine() { IsMenuOpened = false; if (!await NotificationProvider.ShowQuestion("Are you sure you want to reset the machine?")) return; try { _resettingDevice = true; ResetCommand.RaiseCanExecuteChanged(); await MachineProvider.MachineOperator.Reset(); await NotificationProvider.ShowInfo("Machine was successfully restarted."); } catch (Exception ex) { await NotificationProvider.ShowError(ex.FlattenMessage()); } finally { _resettingDevice = false; ResetCommand.RaiseCanExecuteChanged(); } } #endregion #region Override Methods /// <summary> /// Called when the application has been started. /// </summary> public override void OnApplicationStarted() { base.OnApplicationStarted(); MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } /// <summary> /// Called when the instance of IPPCView is available. /// </summary> public override void OnViewAttached() { } public override void OnApplicationReady() { base.OnApplicationReady(); MachineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged; } private void MachineOperator_StatusChanged(object sender, MachineStatuses e) { InvokeUI(() => { PowerOffCommand.RaiseCanExecuteChanged(); ResetCommand.RaiseCanExecuteChanged(); }); } #endregion #region Public Methods /// <summary> /// Toggles the application technician mode. /// </summary> public void ToggleTechnicianMode() { if (!ApplicationManager.IsInTechnicianMode) { ApplicationManager.EnterTechnicianMode(); } else { ApplicationManager.ExitTechnicianMode(); } } #endregion #region Event Handlers /// <summary> /// Handles the PrintingStarted event of the MachineOperator. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="PrintingEventArgs"/> instance containing the event data.</param> private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) { _jobHandler = e.JobHandler; } #endregion } }