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 ++ 14 files changed, 435 insertions(+), 105 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 (limited to 'Software/Visual_Studio/MachineStudio') 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 -- cgit v1.3.1