From 5cda8b0a3ab579dd6f33b1cb19a1d295dc661d28 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 29 Jan 2018 18:45:10 +0200 Subject: Added gradient display of color Brush Stops. --- .../Converters/SegmentToGradientStopsConverter.cs | 41 ++ .../Tango.MachineStudio.Developer.csproj | 1 + .../ViewModels/MainViewVM.cs | 24 +- .../Views/MainView.xaml | 514 ++++++++++++--------- .../Views/MainView.xaml.cs | 40 +- 5 files changed, 390 insertions(+), 230 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs new file mode 100644 index 000000000..1588b7740 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; +using Tango.DAL.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class SegmentToGradientStopsConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + try + { + Segment segment = value as Segment; + + GradientStopCollection stops = new GradientStopCollection(); + + foreach (var stop in segment.BrushStops) + { + stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); + } + + return stops; + } + catch + { + return null; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 2bbd57b86..47604e64d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -75,6 +75,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 4e3b4ec13..a3be7a2d6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -37,7 +37,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public ObservablesEntitiesAdapter Adapter { get; set; } - private Machine _selectedMachine; + protected Machine _selectedMachine; /// /// Gets or sets the selected machine. /// @@ -90,6 +90,7 @@ namespace Tango.MachineStudio.Developer.ViewModels } private ProcessParametersTablesGroup _selectedGroupHistory; + /// /// Gets or sets the selected process parameters tables group history. /// @@ -348,9 +349,12 @@ namespace Tango.MachineStudio.Developer.ViewModels private void SetSegmentBrushStopsInkVolumes(Segment segment) { - foreach (var stop in segment.BrushStops) + if (!DesignMode) { - stop.SetInkVolumes(SelectedMachine.Configuration); + foreach (var stop in segment.BrushStops) + { + stop.SetInkVolumes(SelectedMachine.Configuration); + } } } @@ -470,7 +474,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedJob != null) { Segment seg = new Segment(); - seg.Name = "New Seg"; + seg.Name = "Untitled Segment"; SelectedJob.Segments.Add(seg); } } @@ -496,7 +500,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { SelectedMachine.Jobs.Add(new Job() { - Name = "New Job", + Name = "Untitled Job", CreationDate = DateTime.UtcNow, }); } @@ -582,6 +586,16 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + /// + /// Switch the brush stop position in the segment. + /// + /// The dragged stop. + /// The dropped stop. + public void OnDropBrushStop(BrushStop draggedStop, BrushStop droppedStop) + { + SelectedSegment.BrushStops.Swap(draggedStop, droppedStop); + } + /// /// Removes the graph. /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index 73c00fea8..9c761309c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -19,7 +19,7 @@ xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.Developer.Views" mc:Ignorable="d" - d:DesignHeight="1080" d:DesignWidth="1920" Background="White" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=True}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="1080" d:DesignWidth="1920" Background="White" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + + + + @@ -295,7 +342,7 @@ - + @@ -448,7 +495,7 @@ - + @@ -503,10 +550,18 @@ - - - SEGMENT BRUSH - + + + + SEGMENT BRUSH + + + + + + + + @@ -516,224 +571,203 @@ - - - - - - - - - - - - - - - - - - Color Space + + + + + + + + + + + + + + + + + + + Color Space + + - + + + + + + - - - - - - - - - - - + + + + + @@ -821,6 +855,7 @@ + @@ -940,7 +975,37 @@ Show Graphs - + + + + + + + MONITORING @@ -1113,5 +1178,6 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs index c4e853433..52febe37b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs @@ -14,6 +14,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; using Tango.DAL.Observables; using Tango.DragAndDrop; +using Tango.MachineStudio.Developer.Converters; using Tango.MachineStudio.Developer.ViewModels; namespace Tango.MachineStudio.Developer.Views @@ -43,7 +44,7 @@ namespace Tango.MachineStudio.Developer.Views _vm = DataContext as MainViewVM; }; - chkGraphs.Checked += (x, y) => { graphRowDefinition.Height = new GridLength(161, GridUnitType.Star); }; + chkGraphs.Checked += (x, y) => { graphRowDefinition.Height = new GridLength(440, GridUnitType.Pixel); }; chkGraphs.Unchecked += (x, y) => { graphRowDefinition.Height = new GridLength(80, GridUnitType.Pixel); }; } @@ -54,5 +55,42 @@ namespace Tango.MachineStudio.Developer.Views _vm.OnDropAvailableSensor(e.Draggable.DataContext as Sensor); } } + + private void ColorPickerCombo_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) + { + UpdateGradientBrushDisplay(); + } + + private void Offset_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + UpdateGradientBrushDisplay(); + } + + private void UpdateGradientBrushDisplay() + { + if (_vm.SelectedSegment != null) + { + SegmentToGradientStopsConverter converter = new SegmentToGradientStopsConverter(); + GradientStopCollection stops = converter.Convert(_vm.SelectedSegment, null, null, null) as GradientStopCollection; + gradientBrush.GradientStops = stops; + } + else + { + gradientBrush.GradientStops = new GradientStopCollection(); + } + } + + private void OnBrushStopBorderDrop(object sender, DropEventArgs e) + { + if (e.Draggable.DataContext is BrushStop) + { + _vm.OnDropBrushStop(e.Draggable.DataContext as BrushStop, e.Droppable.DataContext as BrushStop); + } + } + + private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + UpdateGradientBrushDisplay(); + } } } -- cgit v1.3.1