From 4e48c569f1cae820ffade8a786354b2ba79b50b4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 6 Mar 2018 18:28:51 +0200 Subject: Some improvements on hive. --- .../Tango.MachineStudio.ColorLab.csproj | 1 + .../ViewModels/MainViewVM.cs | 62 +++++++++- .../ViewModels/RgbVM.cs | 69 +++++++++++ .../Views/MainView.xaml | 33 ++--- .../Views/MainView.xaml.cs | 11 ++ .../ViewModels/MainViewVM.cs | 2 +- .../Views/EmbroideryImportView.xaml | 2 +- .../Views/JobView.xaml | 4 +- .../Views/JobView.xaml.cs | 2 +- .../Controls/HiveColorPickerControl.xaml | 35 +----- .../Controls/HiveColorPickerControl.xaml.cs | 118 +++++++++++------- .../Controls/HiveComboControl.xaml | 54 ++++++++ .../Controls/HiveComboControl.xaml.cs | 136 +++++++++++++++++++++ .../Tango.MachineStudio.Common.csproj | 11 ++ .../ExtensionMethods/DependencyObjectExtensions.cs | 2 +- .../Tango.Editors/StringExtensions.cs | 107 ---------------- .../Tango.Editors/Tango.Editors.csproj | 9 +- .../Tango.PMR/ColorLab/ConversionInput.cs | 65 +++++++++- .../Tango.SharedUI/Controls/HiveControl.xaml.cs | 35 +++++- 19 files changed, 535 insertions(+), 223 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/RgbVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs delete mode 100644 Software/Visual_Studio/Tango.Editors/StringExtensions.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj index 91bc51933..44e55a12e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj @@ -89,6 +89,7 @@ + MainView.xaml diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index 8260f000a..c6cc95930 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -5,15 +5,19 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; using Tango.BL; using Tango.BL.Entities; +using Tango.MachineStudio.Common.Controls; using Tango.SharedUI; +using Tango.SharedUI.Controls; namespace Tango.MachineStudio.ColorLab.ViewModels { public class MainViewVM : ViewModel { private ObservablesContext _dbContext; + private HiveComboControl _hiveCombo; #region Properties @@ -57,6 +61,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels set { _selectedMachine = value; RaisePropertyChangedAuto(); + OnSelectedMachineChanged(); } } @@ -86,7 +91,9 @@ namespace Tango.MachineStudio.ColorLab.ViewModels } private ObservableCollection _liquidVolumes; - + /// + /// Gets or sets the liquid volumes. + /// public ObservableCollection LiquidVolumes { get { return _liquidVolumes; } @@ -94,24 +101,74 @@ namespace Tango.MachineStudio.ColorLab.ViewModels } private ObservableCollection _liquidsCalibrationData; - + /// + /// Gets or sets the liquids calibration data. + /// public ObservableCollection LiquidsCalibrationData { get { return _liquidsCalibrationData; } set { _liquidsCalibrationData = value; RaisePropertyChangedAuto(); } } + private RgbVM _sourceColor; + /// + /// Gets or sets the color of the source. + /// + public RgbVM SourceColor + { + get { return _sourceColor; } + set { _sourceColor = value; RaisePropertyChangedAuto(); } + } + + private HexagonControl _selectedHexagon; + /// + /// Gets or sets the selected hexagon. + /// + public HexagonControl SelectedHexagon + { + get { return _selectedHexagon; } + set { _selectedHexagon = value; RaisePropertyChangedAuto(); } + } + #endregion public MainViewVM() : base() { _dbContext = ObservablesContext.CreateDefault(); + SourceColor = new RgbVM(); + SourceColor.ColorChanged += SourceColor_ColorChanged; Machines = _dbContext.Machines.ToObservableCollection(); ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); Rmls = _dbContext.Rmls.ToObservableCollection(); } + private void SourceColor_ColorChanged(object sender, Color color) + { + if (_hiveCombo != null) + { + _hiveCombo.GenerateDemoModeHiveColors(color); + _hiveCombo.SelectHeagon(_hiveCombo.CenterHexagon); + } + } + + public void PutComboHiveControl(HiveComboControl hiveCombo) + { + _hiveCombo = hiveCombo; + } + + #region Liquid Volumes + + private void OnSelectedMachineChanged() + { + if (SelectedMachine != null) + { + LiquidVolumes = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { Color = x.LiquidType.Color, Name = x.LiquidType.Name }).ToObservableCollection(); + } + } + + #endregion + #region RML private void InvalidateLiquidFactorsAndProcessTables() @@ -120,7 +177,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { LiquidTypesRmls = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidType).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); //RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.ToList().SingleOrDefault(x => x.Active); - LiquidVolumes = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => new LiquidVolumeVM() { Color = x.LiquidType.Color, Name = x.LiquidType.Name }).ToObservableCollection(); LiquidsCalibrationData = new ObservableCollection(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/RgbVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/RgbVM.cs new file mode 100644 index 000000000..badb238fb --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/RgbVM.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.SharedUI; + +namespace Tango.MachineStudio.ColorLab.ViewModels +{ + public class RgbVM : ViewModel + { + public event EventHandler ColorChanged; + + public RgbVM() + { + Color = Colors.DimGray; + } + + private double _red; + public double Red + { + get { return _red; } + set { _red = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _green; + public double Green + { + get { return _green; } + set { _green = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private double _blue; + public double Blue + { + get { return _blue; } + set { _blue = value; SynchronizeColor(); RaisePropertyChangedAuto(); } + } + + private Color _color; + public Color Color + { + get { return _color; } + set { _color = value; RaisePropertyChanged(nameof(Color)); SynchronizeComponents(); } + } + + private void SynchronizeColor() + { + _color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue); + RaisePropertyChanged(nameof(Color)); + ColorChanged?.Invoke(this, _color); + } + + private void SynchronizeComponents() + { + _red = Color.R; + _green = Color.G; + _blue = Color.B; + + RaisePropertyChanged(nameof(Red)); + RaisePropertyChanged(nameof(Green)); + RaisePropertyChanged(nameof(Blue)); + RaisePropertyChanged(nameof(Color)); + + ColorChanged?.Invoke(this, Color); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml index 92ef15231..72a1bdd4e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml @@ -8,6 +8,7 @@ xmlns:observables="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:vm="clr-namespace:Tango.MachineStudio.ColorLab.ViewModels" xmlns:brushPicker="clr-namespace:Tango.BrushPicker;assembly=Tango.BrushPicker" @@ -164,9 +165,9 @@ - + + - @@ -179,41 +180,33 @@ - - - - - - - - - + - - + + - - + + - - + + SOURCE / INVERSE RGB - SUGGESTIONS + SUGGESTIONS LIQUID VOLUMES - + @@ -281,7 +274,7 @@ COMPOSITE - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml.cs index 1a96386f6..d78750050 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml.cs @@ -12,6 +12,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.MachineStudio.ColorLab.ViewModels; namespace Tango.MachineStudio.ColorLab.Views { @@ -20,9 +21,19 @@ namespace Tango.MachineStudio.ColorLab.Views /// public partial class MainView : UserControl { + private MainViewVM _vm; + public MainView() { InitializeComponent(); + + this.Loaded += MainView_Loaded; + } + + private void MainView_Loaded(object sender, RoutedEventArgs e) + { + _vm = DataContext as MainViewVM; + _vm.PutComboHiveControl(hiveCombo); } } } 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 566dc7a16..dfaeb7044 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 @@ -1710,7 +1710,7 @@ namespace Tango.MachineStudio.Developer.ViewModels Red = stop.Color.R, Green = stop.Color.G, Blue = stop.Color.B, - OffsetPercent = stop.Offset, + OffsetPercent = stop.Offset * 100d, ColorSpace = _machineDbContext.ColorSpaces.ToList().SingleOrDefault(x => x.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()), }); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml index 42d0bb106..8d25719e8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml @@ -46,7 +46,7 @@ Region Brush - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 1dea01de7..4c0784d1d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -157,13 +157,13 @@ - + - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index 905caa96d..0c99dfe5f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -125,7 +125,7 @@ namespace Tango.MachineStudio.Developer.Views } - private void HiveColorPickerControl_SelectedColorChanged(object sender, Color e) + private void HiveColorPickerControl_SelectedColorChanged(object sender, Color color) { UpdateGradientBrushDisplay(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml index 2aa11c63c..d65bd5d8f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml @@ -6,46 +6,19 @@ xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls" xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.Common.Controls" mc:Ignorable="d" - d:DesignHeight="250" d:DesignWidth="550" Background="White"> + Height="250" Width="650" Background="White"> - - + - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs index 7d1a1dc81..41b362889 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.SharedUI.Controls; namespace Tango.MachineStudio.Common.Controls { @@ -21,7 +23,12 @@ namespace Tango.MachineStudio.Common.Controls public partial class HiveColorPickerControl : UserControl { public event EventHandler SelectedColorChanged; - private bool _preventHiveSelectedColorChange; + public event EventHandler SelectedHiveColorChanged; + public event EventHandler SelectedHexagonChanged; + public event EventHandler LAxisValueChanged; + public event EventHandler ResolutionChanged; + + private bool _preventColorCanvasEvent; public bool DemoMode { @@ -39,93 +46,112 @@ namespace Tango.MachineStudio.Common.Controls public static readonly DependencyProperty ResolutionProperty = DependencyProperty.Register("Resolution", typeof(int), typeof(HiveColorPickerControl), new PropertyMetadata(1, (d, e) => (d as HiveColorPickerControl).OnResolutionChanged())); - public Color SelectedColor + public Color? SelectedColor { - get { return (Color)GetValue(SelectedColorProperty); } + get { return (Color?)GetValue(SelectedColorProperty); } set { SetValue(SelectedColorProperty, value); } } public static readonly DependencyProperty SelectedColorProperty = - DependencyProperty.Register("SelectedColor", typeof(Color), typeof(HiveColorPickerControl), new PropertyMetadata(Colors.Red, (d, e) => (d as HiveColorPickerControl).OnSelectedColorChanged())); + DependencyProperty.Register("SelectedColor", typeof(Color?), typeof(HiveColorPickerControl), new PropertyMetadata(null, (d, e) => (d as HiveColorPickerControl).OnSelectedColorChanged())); + + public HexagonControl SelectedHexagon + { + get { return (HexagonControl)GetValue(SelectedHexagonProperty); } + set { SetValue(SelectedHexagonProperty, value); } + } + public static readonly DependencyProperty SelectedHexagonProperty = + DependencyProperty.Register("SelectedHexagon", typeof(HexagonControl), typeof(HiveColorPickerControl), new PropertyMetadata(null, (d, e) => (d as HiveColorPickerControl).OnSelectedHexagonChanged())); - public Color SelectedHiveColor + public Color? SelectedHiveColor { - get { return (Color)GetValue(SelectedHiveColorProperty); } + get { return (Color?)GetValue(SelectedHiveColorProperty); } set { SetValue(SelectedHiveColorProperty, value); } } public static readonly DependencyProperty SelectedHiveColorProperty = - DependencyProperty.Register("SelectedHiveColor", typeof(Color), typeof(HiveColorPickerControl), new PropertyMetadata(Colors.Red)); + DependencyProperty.Register("SelectedHiveColor", typeof(Color?), typeof(HiveColorPickerControl), new PropertyMetadata(null, (d, e) => (d as HiveColorPickerControl).OnSelectedHiveColorChanged())); + + public int LAxisValue + { + get { return (int)GetValue(LAxisValueProperty); } + set { SetValue(LAxisValueProperty, value); } + } + public static readonly DependencyProperty LAxisValueProperty = + DependencyProperty.Register("LAxisValue", typeof(int), typeof(HiveColorPickerControl), new PropertyMetadata(0, (d, e) => (d as HiveColorPickerControl).OnLAxisValueChanged())); + public HiveColorPickerControl() { InitializeComponent(); - hive.Loaded += Hive_Loaded; + this.Bind(ResolutionProperty, hiveCombo, HiveComboControl.ResolutionProperty, BindingMode.TwoWay); + this.Bind(SelectedHexagonProperty, hiveCombo, HiveComboControl.SelectedHexagonProperty, BindingMode.OneWay); + this.Bind(LAxisValueProperty, hiveCombo, HiveComboControl.LAxisValueProperty, BindingMode.OneWay); + + + hiveCombo.HiveGenerated += HiveCombo_HiveGenerated; } - private void Hive_Loaded(object sender, RoutedEventArgs e) + private void HiveCombo_HiveGenerated(object sender, EventArgs e) { - OnSelectedColorChanged(); + hiveCombo.GenerateDemoModeHiveColors(SelectedColor.Value); + } + + private void OnSelectedHiveColorChanged() + { + //_preventColorCanvasEvent = true; + //colorCanvas.SelectedColor = SelectedHiveColor; + //_preventColorCanvasEvent = false; + + SelectedHiveColorChanged?.Invoke(this, SelectedHiveColor.Value); } private void OnSelectedColorChanged() { - if (DemoMode) + if (SelectedColor != null) { - if (!_preventHiveSelectedColorChange) + _preventColorCanvasEvent = true; + colorCanvas.SelectedColor = SelectedColor; + _preventColorCanvasEvent = false; + + if (DemoMode) { - GenerateDemoModeHiveColors(); + hiveCombo.GenerateDemoModeHiveColors(SelectedColor.Value); } - SelectedColorChanged?.Invoke(this, SelectedColor); + + SelectedColorChanged?.Invoke(this, SelectedColor.Value); } } - private void hive_HexagonSelected(object sender, SharedUI.Controls.HexagonControl hexagon) + private void OnSelectedHexagonChanged() { - SelectedHiveColor = (hexagon.Fill as SolidColorBrush).Color; - - _preventHiveSelectedColorChange = true; - SelectedColor = SelectedHiveColor; - _preventHiveSelectedColorChange = false; + SelectedHexagonChanged?.Invoke(this, SelectedHexagon); + SelectedHiveColor = (SelectedHexagon.Fill as SolidColorBrush).Color; } - private void OnResolutionChanged() + private void OnLAxisValueChanged() { - GenerateDemoModeHiveColors(); + LAxisValueChanged?.Invoke(this, LAxisValue); } - private void GenerateDemoModeHiveColors() + private void OnResolutionChanged() { - if (hive.CenterHexagon != null) - { - Random rnd = new Random(); - - (hive.CenterHexagon.Fill as SolidColorBrush).Color = SelectedColor; - - int counter = 0; - - foreach (var hexagon in hive.Hexagons.Where(x => x != hive.CenterHexagon).OrderBy(x => rnd.Next())) - { - (hexagon.Fill as SolidColorBrush).Color = Color.FromRgb((byte)Math.Min(SelectedColor.R + counter++, 255), (byte)Math.Min((SelectedColor.G + counter++), 255), (byte)Math.Min((SelectedColor.B + counter++), 255)); - - counter += (int)(4d * ((double)Resolution / 4d)); - } - } + hiveCombo.GenerateDemoModeHiveColors(SelectedColor.Value); } - private void OnResolutionUpClicked(object sender, RoutedEventArgs e) + private void ColorCanvas_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) { - if (Resolution < 10) + if (!_preventColorCanvasEvent) { - Resolution++; + SelectedColor = e.NewValue.Value; + hiveCombo.SelectHeagon(hiveCombo.CenterHexagon); } } - private void OnResolutionDownClicked(object sender, RoutedEventArgs e) + private void hiveCombo_SelectedHexagonChanged(object sender, HexagonControl e) { - if (Resolution > 1) - { - Resolution--; - } + SelectedHexagon = e; + SelectedHiveColor = (SelectedHexagon.Fill as SolidColorBrush).Color; + SelectedHexagonChanged?.Invoke(this, SelectedHexagon); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml new file mode 100644 index 000000000..692b3f818 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs new file mode 100644 index 000000000..342a1f1c9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Logging; +using Tango.SharedUI.Controls; + +namespace Tango.MachineStudio.Common.Controls +{ + /// + /// Interaction logic for HiveComboControl.xaml + /// + public partial class HiveComboControl : UserControl + { + public event EventHandler SelectedColorChanged; + public event EventHandler SelectedHexagonChanged; + public event EventHandler LAxisValueChanged; + public event EventHandler ResolutionChanged; + public event EventHandler HiveGenerated; + + public int Resolution + { + get { return (int)GetValue(ResolutionProperty); } + set { SetValue(ResolutionProperty, value); } + } + public static readonly DependencyProperty ResolutionProperty = + DependencyProperty.Register("Resolution", typeof(int), typeof(HiveComboControl), new PropertyMetadata(1, (d, e) => (d as HiveComboControl).OnResolutionChanged())); + + public HexagonControl SelectedHexagon + { + get { return (HexagonControl)GetValue(SelectedHexagonProperty); } + set { SetValue(SelectedHexagonProperty, value); } + } + public static readonly DependencyProperty SelectedHexagonProperty = + DependencyProperty.Register("SelectedHexagon", typeof(HexagonControl), typeof(HiveComboControl), new PropertyMetadata(null, (d, e) => (d as HiveComboControl).OnSelectedHexagonChanged())); + + public int LAxisValue + { + get { return (int)GetValue(LAxisValueProperty); } + set { SetValue(LAxisValueProperty, value); } + } + public static readonly DependencyProperty LAxisValueProperty = + DependencyProperty.Register("LAxisValue", typeof(int), typeof(HiveComboControl), new PropertyMetadata(0, (d, e) => (d as HiveComboControl).OnLAxisValueChanged())); + + public HexagonControl CenterHexagon + { + get { return hive.CenterHexagon; } + } + + + public HiveComboControl() + { + InitializeComponent(); + + hive.HiveGenerated += (x, e) => HiveGenerated?.Invoke(this, new EventArgs()); + } + + private void OnLAxisValueChanged() + { + LAxisValueChanged?.Invoke(this, LAxisValue); + } + + private void OnSelectedHexagonChanged() + { + SelectedHexagonChanged?.Invoke(this, SelectedHexagon); + } + + private void OnResolutionChanged() + { + ResolutionChanged?.Invoke(this, Resolution); + } + + public void GenerateDemoModeHiveColors(Color originalColor) + { + if (hive.CenterHexagon != null) + { + Random rnd = new Random(); + + (hive.CenterHexagon.Fill as SolidColorBrush).Color = originalColor; + + int counter = 0; + + foreach (var hexagon in hive.Hexagons.Where(x => x != hive.CenterHexagon).OrderBy(x => rnd.Next())) + { + (hexagon.Fill as SolidColorBrush).Color = Color.FromRgb((byte)Math.Min(originalColor.R + counter++, 255), (byte)Math.Min((originalColor.G + counter++), 255), (byte)Math.Min((originalColor.B + counter++), 255)); + + counter += (int)(4d * ((double)Resolution / 4d)); + } + } + } + + private void OnResolutionUpClicked(object sender, RoutedEventArgs e) + { + if (Resolution < 10) + { + Resolution++; + } + } + + private void OnResolutionDownClicked(object sender, RoutedEventArgs e) + { + if (Resolution > 1) + { + Resolution--; + } + } + + private void OnRowHiveHexagonSelected(object sender, HexagonControl hexagon) + { + int l = 2 - hexagon.Row; + LogManager.Default.Log("L ROW: " + l.ToString()); + } + + private void OnHexagonSelected(object sender, HexagonControl e) + { + SelectedHexagon = e; + } + + public void SelectHeagon(HexagonControl hexagon) + { + hive.SelectHexagon(hexagon); + SelectedHexagonChanged?.Invoke(this, hexagon); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 457646223..2347919d6 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -76,6 +76,9 @@ HiveColorPickerControl.xaml + + HiveComboControl.xaml + RealTimeGraphMultiControl.xaml @@ -114,6 +117,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -212,6 +219,10 @@ {4206ac58-3b57-4699-8835-90bf6db01a61} Tango.Integration + + {BC932DBD-7CDB-488C-99E4-F02CF441F55E} + Tango.Logging + {e4927038-348d-4295-aaf4-861c58cb3943} Tango.PMR diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs index 3e7da4cfb..e36fe607c 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs @@ -55,7 +55,7 @@ public static class DependencyObjectExtensions /// Binding mode. /// Binding converter. /// - public static Binding Bind(this DependencyObject target, DependencyProperty targetDP, DependencyObject source, DependencyProperty sourceDP, BindingMode mode, IValueConverter converter = null) + public static Binding Bind(this DependencyObject target, DependencyProperty targetDP, DependencyObject source, DependencyProperty sourceDP, BindingMode mode, IValueConverter converter) { Binding binding = new Binding(); binding.Mode = mode; diff --git a/Software/Visual_Studio/Tango.Editors/StringExtensions.cs b/Software/Visual_Studio/Tango.Editors/StringExtensions.cs deleted file mode 100644 index 0f5923512..000000000 --- a/Software/Visual_Studio/Tango.Editors/StringExtensions.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -/// -/// -/// A collection of extension methods. -/// -internal static class StringExtensions -{ - private static Regex titleRegEx; - - /// - /// Initializes the class. - /// - static StringExtensions() - { - titleRegEx = new Regex(@" - (?<=[A-Z])(?=[A-Z][a-z]) | - (?<=[^A-Z])(?=[A-Z]) | - (?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace); - } - - /// - /// Returns true if the string is not null or contains white spaces. - /// - /// The string. - /// - internal static bool IsValid(this String str) - { - return !String.IsNullOrWhiteSpace(str); - } - - /// - /// Determines whether the string contains an existing file path. - /// - /// The path. - /// - internal static bool IsFileExists(this String path) - { - return System.IO.File.Exists(path); - } - - /// - /// Determines whether the string is valid as a file system path. - /// - /// The path. - /// - internal static bool IsPathValid(this String path) - { - return path.IsValid() && path.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1; - } - - /// - /// Returns a friendly file size of the file path. - /// - /// The file path. - /// - internal static String GetFileSizeString(this String filePath) - { - FileInfo f = new FileInfo(filePath); - double length = f.Length; - - string[] sizes = { "B", "KB", "MB", "GB" }; - double len = length; - int order = 0; - while (len >= 1024 && order + 1 < sizes.Length) - { - order++; - len = len / 1024; - } - - // Adjust the format string to your preferences. For example "{0:0.#}{1}" would - // show a single decimal place, and no space. - return String.Format("{0:0.##} {1}", len, sizes[order]); - } - - /// - /// If string is a path, returns the file name. - /// - /// The file path. - /// - internal static String GetFileName(this String filePath) - { - return Path.GetFileName(filePath); - } - - /// - /// If string is a path, returns the file extension. - /// - /// The file path. - /// - internal static String GetFileExtension(this String filePath) - { - return Path.GetExtension(filePath); - } - - internal static String ToTitle(this String str) - { - return titleRegEx.Replace(str, " "); - } -} - diff --git a/Software/Visual_Studio/Tango.Editors/Tango.Editors.csproj b/Software/Visual_Studio/Tango.Editors/Tango.Editors.csproj index 217048e63..1eaeddb9c 100644 --- a/Software/Visual_Studio/Tango.Editors/Tango.Editors.csproj +++ b/Software/Visual_Studio/Tango.Editors/Tango.Editors.csproj @@ -76,7 +76,6 @@ - @@ -109,7 +108,7 @@ - + @@ -166,5 +165,11 @@ Settings.Designer.cs + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.PMR/ColorLab/ConversionInput.cs b/Software/Visual_Studio/Tango.PMR/ColorLab/ConversionInput.cs index 20f133b7c..9678ca13e 100644 --- a/Software/Visual_Studio/Tango.PMR/ColorLab/ConversionInput.cs +++ b/Software/Visual_Studio/Tango.PMR/ColorLab/ConversionInput.cs @@ -23,18 +23,19 @@ namespace Tango.PMR.ColorLab { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "ChVDb252ZXJzaW9uSW5wdXQucHJvdG8SElRhbmdvLlBNUi5Db2xvckxhYhoW", - "SW5wdXRDb29yZGluYXRlcy5wcm90bxoQQ29sb3JTcGFjZS5wcm90byL5AQoP", + "SW5wdXRDb29yZGluYXRlcy5wcm90bxoQQ29sb3JTcGFjZS5wcm90byKeAgoP", "Q29udmVyc2lvbklucHV0Eg8KB1RocmVhZEwYASABKAESDwoHVGhyZWFkQRgC", "IAEoARIPCgdUaHJlYWRCGAMgASgBEjIKCkNvbG9yU3BhY2UYBCABKA4yHi5U", "YW5nby5QTVIuQ29sb3JMYWIuQ29sb3JTcGFjZRI+ChBJbnB1dENvb3JkaW5h", "dGVzGAUgASgLMiQuVGFuZ28uUE1SLkNvbG9yTGFiLklucHV0Q29vcmRpbmF0", "ZXMSEwoLRm9yd2FyZERhdGEYBiABKAwSEwoLSW52ZXJzZURhdGEYByABKAwS", - "FQoNU2VnbWVudExlbmd0aBgIIAEoAUIeChxjb20udHdpbmUudGFuZ28ucG1y", - "LmNvbG9ybGFiYgZwcm90bzM=")); + "FQoNU2VnbWVudExlbmd0aBgIIAEoARITCgtEZWx0YUNocm9tYRgJIAEoARIO", + "CgZEZWx0YUwYCiABKAFCHgocY29tLnR3aW5lLnRhbmdvLnBtci5jb2xvcmxh", + "YmIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Tango.PMR.ColorLab.InputCoordinatesReflection.Descriptor, global::Tango.PMR.ColorLab.ColorSpaceReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ColorLab.ConversionInput), global::Tango.PMR.ColorLab.ConversionInput.Parser, new[]{ "ThreadL", "ThreadA", "ThreadB", "ColorSpace", "InputCoordinates", "ForwardData", "InverseData", "SegmentLength" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.ColorLab.ConversionInput), global::Tango.PMR.ColorLab.ConversionInput.Parser, new[]{ "ThreadL", "ThreadA", "ThreadB", "ColorSpace", "InputCoordinates", "ForwardData", "InverseData", "SegmentLength", "DeltaChroma", "DeltaL" }, null, null, null) })); } #endregion @@ -73,6 +74,8 @@ namespace Tango.PMR.ColorLab { forwardData_ = other.forwardData_; inverseData_ = other.inverseData_; segmentLength_ = other.segmentLength_; + deltaChroma_ = other.deltaChroma_; + deltaL_ = other.deltaL_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -168,6 +171,28 @@ namespace Tango.PMR.ColorLab { } } + /// Field number for the "DeltaChroma" field. + public const int DeltaChromaFieldNumber = 9; + private double deltaChroma_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DeltaChroma { + get { return deltaChroma_; } + set { + deltaChroma_ = value; + } + } + + /// Field number for the "DeltaL" field. + public const int DeltaLFieldNumber = 10; + private double deltaL_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DeltaL { + get { return deltaL_; } + set { + deltaL_ = value; + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as ConversionInput); @@ -189,6 +214,8 @@ namespace Tango.PMR.ColorLab { if (ForwardData != other.ForwardData) return false; if (InverseData != other.InverseData) return false; if (SegmentLength != other.SegmentLength) return false; + if (DeltaChroma != other.DeltaChroma) return false; + if (DeltaL != other.DeltaL) return false; return true; } @@ -203,6 +230,8 @@ namespace Tango.PMR.ColorLab { if (ForwardData.Length != 0) hash ^= ForwardData.GetHashCode(); if (InverseData.Length != 0) hash ^= InverseData.GetHashCode(); if (SegmentLength != 0D) hash ^= SegmentLength.GetHashCode(); + if (DeltaChroma != 0D) hash ^= DeltaChroma.GetHashCode(); + if (DeltaL != 0D) hash ^= DeltaL.GetHashCode(); return hash; } @@ -245,6 +274,14 @@ namespace Tango.PMR.ColorLab { output.WriteRawTag(65); output.WriteDouble(SegmentLength); } + if (DeltaChroma != 0D) { + output.WriteRawTag(73); + output.WriteDouble(DeltaChroma); + } + if (DeltaL != 0D) { + output.WriteRawTag(81); + output.WriteDouble(DeltaL); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -274,6 +311,12 @@ namespace Tango.PMR.ColorLab { if (SegmentLength != 0D) { size += 1 + 8; } + if (DeltaChroma != 0D) { + size += 1 + 8; + } + if (DeltaL != 0D) { + size += 1 + 8; + } return size; } @@ -309,6 +352,12 @@ namespace Tango.PMR.ColorLab { if (other.SegmentLength != 0D) { SegmentLength = other.SegmentLength; } + if (other.DeltaChroma != 0D) { + DeltaChroma = other.DeltaChroma; + } + if (other.DeltaL != 0D) { + DeltaL = other.DeltaL; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -354,6 +403,14 @@ namespace Tango.PMR.ColorLab { SegmentLength = input.ReadDouble(); break; } + case 73: { + DeltaChroma = input.ReadDouble(); + break; + } + case 81: { + DeltaL = input.ReadDouble(); + break; + } } } } diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs index 81fc1250d..5fba6eaa0 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/HiveControl.xaml.cs @@ -25,6 +25,8 @@ namespace Tango.SharedUI.Controls { public event EventHandler HexagonSelected; + public event EventHandler HiveGenerated; + public ObservableCollection Hexagons { get { return (ObservableCollection)GetValue(HexagonsProperty); } @@ -65,6 +67,21 @@ namespace Tango.SharedUI.Controls public static readonly DependencyProperty CenterHexagonProperty = DependencyProperty.Register("CenterHexagon", typeof(HexagonControl), typeof(HiveControl), new PropertyMetadata(null)); + public int HiveWidth + { + get { return (int)GetValue(HiveWidthProperty); } + set { SetValue(HiveWidthProperty, value); } + } + public static readonly DependencyProperty HiveWidthProperty = + DependencyProperty.Register("HiveWidth", typeof(int), typeof(HiveControl), new PropertyMetadata(5)); + + public int HiveHeight + { + get { return (int)GetValue(HiveHeightProperty); } + set { SetValue(HiveHeightProperty, value); } + } + public static readonly DependencyProperty HiveHeightProperty = + DependencyProperty.Register("HiveHeight", typeof(int), typeof(HiveControl), new PropertyMetadata(5)); public HiveControl() { @@ -78,13 +95,10 @@ namespace Tango.SharedUI.Controls this.Loaded += HiveControl_Loaded; } - public int HiveHeight { get; set; } - - public int HiveWidth { get; set; } - private void HiveControl_Loaded(object sender, RoutedEventArgs e) { GenerateHive(); + HiveGenerated?.Invoke(this,new EventArgs()); } private void GenerateHive() @@ -155,7 +169,20 @@ namespace Tango.SharedUI.Controls private void Hexagon_MouseUp(object sender, MouseButtonEventArgs e) { HexagonControl hexagon = sender as HexagonControl; + ToggleHexagonSelection(hexagon); + } + public void SelectHexagon(HexagonControl hexagon) + { + SelectedHexagons.Clear(); + SelectedHexagons.Add(hexagon); + Hexagons.ToList().ForEach(x => x.IsSelected = false); + hexagon.IsSelected = true; + HexagonSelected?.Invoke(this, hexagon); + } + + private void ToggleHexagonSelection(HexagonControl hexagon) + { bool selected = !hexagon.IsSelected; if (MaxSelections > Hexagons.Where(x => x.IsSelected).Count()) -- cgit v1.3.1