From f70d2639099282432295c0949fe6da2c8dd4bb46 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 20 Mar 2018 12:34:34 +0200 Subject: Improved Tech Single Value Controller! --- .../Editors/ControllerElementEditor.xaml | 52 +++++++++++----------- .../PropertiesTemplates/ControllerTemplate.xaml | 3 ++ .../TechItems/ControllerItem.cs | 42 ++++++++++++++++- .../Tango.CircularGauge/CircularGaugeControl.cs | 32 +++++++++---- 4 files changed, 93 insertions(+), 36 deletions(-) (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml index 60b96bc9d..5cffffc90 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/ControllerElementEditor.xaml @@ -30,12 +30,13 @@ - - - - - - + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ControllerTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ControllerTemplate.xaml index 57d807b09..ffc726abf 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ControllerTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/ControllerTemplate.xaml @@ -34,6 +34,9 @@ + + Optimal Range: to + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ControllerItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ControllerItem.cs index 67266ee66..8a9cba883 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ControllerItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ControllerItem.cs @@ -30,7 +30,19 @@ namespace Tango.MachineStudio.Technician.TechItems public TechController TechController { get { return _techController; } - set { _techController = value; RaisePropertyChangedAuto(); TechName = _techController != null ? _techController.Description : null; ItemGuid = value != null ? value.Guid : null; } + 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; @@ -64,7 +76,6 @@ namespace Tango.MachineStudio.Technician.TechItems [XmlIgnore] public DateTime LastUpdateTime { get; set; } - private double _effectiveValue; /// /// Gets or sets the effective value received from the embedded device. @@ -85,6 +96,29 @@ namespace Tango.MachineStudio.Technician.TechItems } } + private double _optimalRangeMinimum; + /// + /// Gets or sets the optimal range. + /// + 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; } + /// /// Initializes a new instance of the class. /// @@ -115,6 +149,10 @@ namespace Tango.MachineStudio.Technician.TechItems { ControllerItem cloned = base.Clone() as ControllerItem; cloned.TechController = TechController; + cloned.OptimalRangeMinimum = OptimalRangeMinimum; + cloned.OptimalRangeMaximum = OptimalRangeMaximum; + cloned.IsSetToDefault = IsSetToDefault; + return cloned; } } diff --git a/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs b/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs index 1d1d598c6..7e8f1fa8c 100644 --- a/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs +++ b/Software/Visual_Studio/Tango.CircularGauge/CircularGaugeControl.cs @@ -57,6 +57,7 @@ namespace Tango.CircularGauge private Ellipse pointerCap; private Ellipse lightIndicator; private bool isInitialValueSet = false; + private List _rangeIndicators; private Double arcradius1; private Double arcradius2; private int animatingSpeedFactor = 6; @@ -265,7 +266,7 @@ namespace Tango.CircularGauge /// public static readonly DependencyProperty OptimalRangeColorProperty = - DependencyProperty.Register("OptimalRangeColor", typeof(Color), typeof(CircularGaugeControl), null); + DependencyProperty.Register("OptimalRangeColor", typeof(Color), typeof(CircularGaugeControl), new PropertyMetadata(Colors.White, (d, e) => (d as CircularGaugeControl).DrawRangeIndicator())); /// /// Dependency property to Get/Set the Above Optimal Range Color @@ -891,6 +892,12 @@ namespace Tango.CircularGauge #endregion #region Constructor + + public CircularGaugeControl() + { + _rangeIndicators = new List(); + } + static CircularGaugeControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CircularGaugeControl), new FrameworkPropertyMetadata(typeof(CircularGaugeControl))); @@ -915,6 +922,8 @@ namespace Tango.CircularGauge gauge.OptimalRangeEndValue = gauge.MaxValue; } + (d as CircularGaugeControl).DrawRangeIndicator(); + } private static void OnOptimalRangeStartValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -925,7 +934,7 @@ namespace Tango.CircularGauge gauge.OptimalRangeStartValue = gauge.MinValue; } - + (d as CircularGaugeControl).DrawRangeIndicator(); } public virtual void OnCurrentValueChanged(DependencyPropertyChangedEventArgs e) @@ -1269,6 +1278,13 @@ namespace Tango.CircularGauge /// private void DrawRangeIndicator() { + if (rootGrid == null) return; + + foreach (var indicator in _rangeIndicators) + { + rootGrid.Children.Remove(indicator); + } + Double realworldunit = (ScaleSweepAngle / (MaxValue - MinValue)); Double optimalStartAngle; Double optimalEndAngle; @@ -1319,7 +1335,7 @@ namespace Tango.CircularGauge Point D = GetCircumferencePoint(optimalStartAngleFromStart, arcradius1); bool isReflexAngle = Math.Abs(optimalStartAngleFromStart - ScaleStartAngle) > 180.0; - DrawSegment(A, B, C, D, isReflexAngle, BelowOptimalRangeColor); + _rangeIndicators.Add(DrawSegment(A, B, C, D, isReflexAngle, BelowOptimalRangeColor)); // Calculating the Points for the Optimal Range segment from the center of the gauge @@ -1328,7 +1344,7 @@ namespace Tango.CircularGauge Point C1 = GetCircumferencePoint(optimalEndAngleFromStart, arcradius2); Point D1 = GetCircumferencePoint(optimalEndAngleFromStart, arcradius1); bool isReflexAngle1 = Math.Abs(optimalEndAngleFromStart - optimalStartAngleFromStart) > 180.0; - DrawSegment(A1, B1, C1, D1, isReflexAngle1, OptimalRangeColor); + _rangeIndicators.Add(DrawSegment(A1, B1, C1, D1, isReflexAngle1, OptimalRangeColor)); // Calculating the Points for the Above Optimal Range segment from the center of the gauge @@ -1337,12 +1353,12 @@ namespace Tango.CircularGauge Point C2 = GetCircumferencePoint(endAngle, arcradius2); Point D2 = GetCircumferencePoint(endAngle, arcradius1); bool isReflexAngle2 = Math.Abs(endAngle - optimalEndAngleFromStart) > 180.0; - DrawSegment(A2, B2, C2, D2, isReflexAngle2, AboveOptimalRangeColor); + _rangeIndicators.Add(DrawSegment(A2, B2, C2, D2, isReflexAngle2, AboveOptimalRangeColor)); } //Drawing the segment with two arc and two line - private void DrawSegment(Point p1, Point p2, Point p3, Point p4, bool reflexangle, Color clr) + private Path DrawSegment(Point p1, Point p2, Point p3, Point p4, bool reflexangle, Color clr) { // Segment Geometry @@ -1383,8 +1399,6 @@ namespace Tango.CircularGauge else rangestrokecolor = Colors.White; - - rangeIndicator = new Path() { StrokeLineJoin = PenLineJoin.Round, @@ -1410,8 +1424,10 @@ namespace Tango.CircularGauge //Set Z index of range indicator rangeIndicator.SetValue(Canvas.ZIndexProperty, 150); // Adding the segment to the root grid + rootGrid.Children.Add(rangeIndicator); + return rangeIndicator; } #endregion -- cgit v1.3.1