/// <summary> /// Creates a reference line cursor for a single channel. /// </summary> internal static BoundCursor CreateChannelReferenceCursor(ChannelViewModel channelVM) { var channelCaption = channelVM.Caption; var channelColor = CairoHelpers.ToCairoColor(channelVM.Color); var cursor = new ScopeCursor { Lines = ScopeCursorLines.Y, LineWeight = ScopeCursorLineWeight.Low, SelectableLines = ScopeCursorLines.Y, Markers = ScopeCursorMarkers.YFull, Color = channelColor, Captions = new [] { new ScopePositionCaption(() => channelCaption, ScopeHorizontalAlignment.Left, ScopeVerticalAlignment.Bottom, ScopeAlignmentReference.YPositionAndHorizontalRangeEdge, true, channelColor), new ScopePositionCaption(() => channelCaption, ScopeHorizontalAlignment.Right, ScopeVerticalAlignment.Bottom, ScopeAlignmentReference.YPositionAndHorizontalRangeEdge, true, channelColor), }, }; // === Create bindings. === // Bind the cursor's position. var binding = PB.Binding.Create(() => cursor.Position.Y == channelVM.ReferencePointPosition.Y); return(new BoundCursor(cursor, new [] { binding })); }
/// <summary> /// Creates a trigger criteria cursor for a level-based trigger. /// </summary> private static BoundCursor CreateTriggerCriteriaCursor( char triggerModeSymbol, Func <double> valueProvider, Func <ScopeCursor, ValueConverter <double, double>, PB.Binding> valueBindingProvider, Func <double> valueScaleFactorProvider, Func <double> referencePointPositionProvider, Func <double> referenceLevelProvider, string baseUnitString, Color levelColor, IEnumerable <INotifyPropertyChanged> influencingObjects) { var triggerCaption = string.Format("{0}{1}", _triggerSymbol, triggerModeSymbol); Func <String> levelTextProvider = () => UnitHelper.BuildValueText(baseUnitString, valueProvider()); var cairoColor = CairoHelpers.ToCairoColor(levelColor); var cursor = new ScopeCursor { Lines = ScopeCursorLines.Y, LineWeight = ScopeCursorLineWeight.Low, SelectableLines = ScopeCursorLines.Y, Markers = ScopeCursorMarkers.YFull, Color = cairoColor, Captions = new [] { new ScopePositionCaption(() => triggerCaption, ScopeHorizontalAlignment.Left, ScopeVerticalAlignment.Bottom, ScopeAlignmentReference.YPositionAndHorizontalRangeEdge, true, cairoColor), new ScopePositionCaption(() => triggerCaption, ScopeHorizontalAlignment.Right, ScopeVerticalAlignment.Bottom, ScopeAlignmentReference.YPositionAndHorizontalRangeEdge, true, cairoColor), new ScopePositionCaption(levelTextProvider, ScopeHorizontalAlignment.Right, ScopeVerticalAlignment.Top, ScopeAlignmentReference.YPositionAndHorizontalRangeEdge, true, cairoColor), }, }; // === Create value converters. === var valueConverter = new ValueConverter <double, double>( val => (val - referenceLevelProvider()) * valueScaleFactorProvider() + referencePointPositionProvider(), val => ((val - referencePointPositionProvider()) / valueScaleFactorProvider()) + referenceLevelProvider()); // === Create bindings. === // Bind the cursor's position. var binding = valueBindingProvider(cursor, valueConverter); // The trigger cursor's position depends on some additional values (except the primary value // it is bound to). Update it if any of these values changes. === influencingObjects.ForEachDo(influencingObject => { influencingObject.PropertyChanged += (sender, e) => { PB.Binding.InvalidateMember(() => valueConverter.DerivedValue); }; }); return(new BoundCursor(cursor, new [] { binding })); }
/// <summary> /// Creates a trigger point cursor. /// </summary> internal static BoundCursor CreateTriggerPointCursor(GraphbaseViewModel graphbaseVM) { var triggerVM = graphbaseVM.TriggerVM; Func <String> triggerStateCaptionProvider = () => triggerVM.State == TriggerState.Armed ? _armedCaption : triggerVM.State == TriggerState.Triggered ? _triggeredCaption : ""; Func <String> positionTextProvider = () => UnitHelper.BuildValueText(graphbaseVM.BaseUnitString, triggerVM.HorizontalPosition / graphbaseVM.ScaleFactor); var markerColor = CairoHelpers.ToCairoColor(graphbaseVM.Color); var cursor = new ScopeCursor { Lines = ScopeCursorLines.X, LineWeight = ScopeCursorLineWeight.Low, SelectableLines = ScopeCursorLines.X, Markers = ScopeCursorMarkers.XFull, Color = markerColor, Captions = new [] { new ScopePositionCaption(triggerStateCaptionProvider, ScopeHorizontalAlignment.Left, ScopeVerticalAlignment.Top, ScopeAlignmentReference.XPositionAndVerticalRangeEdge, true, markerColor), new ScopePositionCaption(triggerStateCaptionProvider, ScopeHorizontalAlignment.Left, ScopeVerticalAlignment.Bottom, ScopeAlignmentReference.XPositionAndVerticalRangeEdge, true, markerColor), new ScopePositionCaption(positionTextProvider, ScopeHorizontalAlignment.Right, ScopeVerticalAlignment.Top, ScopeAlignmentReference.XPositionAndVerticalRangeEdge, true, markerColor), }, }; // === Create bindings. === // Bind the cursor's position. var binding = PB.Binding.Create(() => cursor.Position.X == triggerVM.HorizontalPosition); return(new BoundCursor(cursor, new [] { binding })); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="embeddedCursor">The cursor embedded in this object.</param> /// <param name="bindings">The bindings used by this object.</param> public BoundCursor(ScopeCursor embeddedCursor, IEnumerable <PB.Binding> bindings) { EmbeddedCursor = embeddedCursor; _bindings = bindings; }