From f4929c38abd1389377d30fca6c9304d2d6639d30 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Thu, 16 Dec 2021 15:27:38 +0200 Subject: Undo/Redo Length of segment. --- .../Tango.PPC.JobsV2/Models/SegmentModel.cs | 15 +++++++-- .../Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj | 3 +- .../UndoRedoCommands/AddBrushStopCommand.cs | 7 +++- .../UndoRedoCommands/ChangeLengthCommand.cs | 39 ++++++++++++++++++++++ .../UndoRedoCommands/ChangeOffsetCommand.cs | 6 ++++ .../UndoRedoCommands/UndoRedoManager.cs | 1 + .../Modules/Tango.PPC.JobsV2/Views/JobView.xaml | 2 +- .../Modules/Tango.PPC.JobsV2/Views/JobView.xaml.cs | 19 +++++++++++ .../Tango.Touch/Controls/TouchNumericTextBox.cs | 19 +++++++++++ 9 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeLengthCommand.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/SegmentModel.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/SegmentModel.cs index 3730f56ac..3b4644a8d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/SegmentModel.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/SegmentModel.cs @@ -68,7 +68,17 @@ namespace Tango.PPC.Jobs.Models } } } + public void LengthBeforeChange(double value) + { + _lastLength = Length; + } + public void LengthChanged(double value) + { + UndoRedoManager.Instance.InsertAndExecuteCommand(new ChangeLengthCommand(this, _lastLength, value)); + _lastLength = Length; + } + protected Int32 _segmentindex; /// /// Gets or sets the index of the segment. @@ -439,6 +449,7 @@ namespace Tango.PPC.Jobs.Models RightOffset = 100; IsOffsetChanged = false; Length = 5; + _lastLength = 5; IsSelected = false; IsLast = false; _enableintersegment = false; @@ -680,10 +691,10 @@ namespace Tango.PPC.Jobs.Models /// protected void OnLengthChanged(double length) { - if (_lastLength != length) + //if (_lastLength != length) { BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); - _lastLength = Length; + //_lastLength = Length; //RaisePropertyChanged(nameof(LengthWithFactor)); RaisePropertyChanged(nameof(LengthWithInterSegment)); } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj index 43959f144..a38818ffb 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj @@ -286,6 +286,7 @@ + @@ -626,7 +627,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/AddBrushStopCommand.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/AddBrushStopCommand.cs index 18211a5d1..35d1629e0 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/AddBrushStopCommand.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/AddBrushStopCommand.cs @@ -24,6 +24,8 @@ namespace Tango.PPC.Jobs.UndoRedoCommands public void Execute() { + if (_segment == null) + return; //SolidColor if (_segment.BrushStops.Count == 0) { @@ -64,7 +66,10 @@ namespace Tango.PPC.Jobs.UndoRedoCommands public void UnExecute() { - if(_createdNewSegment != null) + if (_segment == null) + return; + + if (_createdNewSegment != null) { BrushStopModel secondbrush = _createdNewSegment.SecondBrushStop; _segment.AddOrReplaceSecondBrush(secondbrush); diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeLengthCommand.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeLengthCommand.cs new file mode 100644 index 000000000..558242c48 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeLengthCommand.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Jobs.Models; + +namespace Tango.PPC.Jobs.UndoRedoCommands +{ + public class ChangeLengthCommand : IUndoRedoCommand + { + private SegmentModel _segment; + private double _oldValue; + private double _newValue; + + public ChangeLengthCommand(SegmentModel segment, double oldvalue, double newValue) + { + _segment = segment; + _oldValue = oldvalue; + _newValue = newValue; + } + + public void Execute() + { + if (_segment == null) + return; + + _segment.Length = _newValue; + } + + public void UnExecute() + { + if (_segment == null) + return; + + _segment.Length = _oldValue; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeOffsetCommand.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeOffsetCommand.cs index f3776ecbe..d96817335 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeOffsetCommand.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/ChangeOffsetCommand.cs @@ -25,6 +25,9 @@ namespace Tango.PPC.Jobs.UndoRedoCommands } public void Execute() { + if (_segment == null) + return; + switch (_type) { case OffsetType.Left: @@ -49,6 +52,9 @@ namespace Tango.PPC.Jobs.UndoRedoCommands public void UnExecute() { + if (_segment == null) + return; + switch (_type) { case OffsetType.Left: diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/UndoRedoManager.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/UndoRedoManager.cs index 9e8a2a351..3b926f4eb 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/UndoRedoManager.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/UndoRedoCommands/UndoRedoManager.cs @@ -32,6 +32,7 @@ namespace Tango.PPC.Jobs.UndoRedoCommands _UndoCommands.Push(command); command.Execute(); } + public void Redo() { diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml index 4d4714497..ee5a58264 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml @@ -223,7 +223,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml.cs index 66c497e29..31a7f7918 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobView.xaml.cs @@ -16,6 +16,7 @@ using System.Windows.Shapes; using Tango.BL; using Tango.BL.Entities; using Tango.Core.DI; +using Tango.PPC.Jobs.Models; using Tango.PPC.Jobs.ViewContracts; using Tango.PPC.Jobs.ViewModels; using static Tango.SharedUI.Controls.NavigationControl; @@ -137,5 +138,23 @@ namespace Tango.PPC.Jobs.Views //scrollViewer.ScrollToTop(); } + private void Length_ValueChanged(object sender, Touch.Controls.DoubleValueChangedEventArgs e) + { + var segmentModel = (sender as FrameworkElement).DataContext as SegmentModel; + if(segmentModel != null) + { + segmentModel.LengthChanged(e.Value); + } + + } + private void Length_BeforeChangeValue(object sender, Touch.Controls.DoubleValueChangedEventArgs e) + { + var segmentModel = (sender as FrameworkElement).DataContext as SegmentModel; + if (segmentModel != null) + { + segmentModel.LengthBeforeChange(e.Value); + } + + } } } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs index ad185f1a3..224f2d25b 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs @@ -33,6 +33,20 @@ namespace Tango.Touch.Controls remove { RemoveHandler(ValueChangedEvent, value); } } + public static readonly RoutedEvent ValueChangedEndEvent = EventManager.RegisterRoutedEvent("ValueChangedEnd", RoutingStrategy.Bubble, typeof(DoubleValueChangedEventHandler), typeof(TouchNumericTextBox)); + public event DoubleValueChangedEventHandler ValueChangedEnd + { + add { AddHandler(ValueChangedEndEvent, value); } + remove { RemoveHandler(ValueChangedEndEvent, value); } + } + + public static readonly RoutedEvent TextGotFocusEvent = EventManager.RegisterRoutedEvent("TextGotFocus", RoutingStrategy.Bubble, typeof(DoubleValueChangedEventHandler), typeof(TouchNumericTextBox)); + public event DoubleValueChangedEventHandler TextGotFocus + { + add { AddHandler(TextGotFocusEvent, value); } + remove { RemoveHandler(TextGotFocusEvent, value); } + } + public double Value { get { return (double)GetValue(ValueProperty); } @@ -155,6 +169,8 @@ namespace Tango.Touch.Controls { _text_box.CaretIndex = _text_box.Text.Length; } + DoubleValueChangedEventArgs args = new DoubleValueChangedEventArgs(TextGotFocusEvent, this, Value); + RaiseEvent(args); } private object CoerceValue(DependencyObject d, object e) @@ -205,6 +221,9 @@ namespace Tango.Touch.Controls DoubleValueChangedEventArgs args = new DoubleValueChangedEventArgs(ValueChangedEvent, this, Value); RaiseEvent(args); + + DoubleValueChangedEventArgs args2 = new DoubleValueChangedEventArgs(ValueChangedEndEvent, this, Value); + RaiseEvent(args2); } private void _text_box_PreviewKeyDown(object sender, KeyEventArgs e) -- cgit v1.3.1