aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2023-10-10 13:43:20 +0300
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2023-10-10 13:44:22 +0300
commit5003e43a9ad367bb01807dd907623ed51149a72f (patch)
treee1cdb576dbd0c0c7f8a52dbbf205425a37a7f3a1 /Software/Visual_Studio
parent38200150dd731b158448316835b069d3fef2bc8f (diff)
downloadTango-5003e43a9ad367bb01807dd907623ed51149a72f.tar.gz
Tango-5003e43a9ad367bb01807dd907623ed51149a72f.zip
MyColors -added export & import buttons.
Related Work Items: #8814
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionView.xaml37
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionViewVM.cs93
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/FavoriteColor.cs17
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/MyColors/MyColorsEngine.cs41
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml2
5 files changed, 170 insertions, 20 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionView.xaml
index 3ec03eff7..c60fed143 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionView.xaml
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionView.xaml
@@ -691,25 +691,25 @@
<Grid.Background>
<SolidColorBrush Color="{StaticResource TangoDisabledBackgroundColor}" Opacity="0.65" />
</Grid.Background>
- <Border Margin="72 20 69 325" CornerRadius="20" Background="{StaticResource TangoPrimaryBackgroundBrush}">
+ <Border Margin="72 30 69 290" CornerRadius="20" Background="{StaticResource TangoPrimaryBackgroundBrush}">
<Border.Effect>
<DropShadowEffect Opacity="0.5" ShadowDepth="6" Color="Silver" BlurRadius="10" Direction="270"/>
</Border.Effect>
<Border CornerRadius="20" Background="{StaticResource TangoPrimaryBackgroundBrush}">
<Grid>
<DockPanel >
- <Grid DockPanel.Dock="Bottom" Height="137">
- <Rectangle Height="1" Stroke="{StaticResource TangoDividerBrush}" HorizontalAlignment="Stretch"/>
- <Grid Margin="48 30 0 0" >
+ <Grid DockPanel.Dock="Bottom" Height="136">
+ <Rectangle Height="3" Stroke="{StaticResource TangoDividerBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0 10 0 0"/>
+ <Grid Margin="48 10 0 0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
- <touch:TouchImageButton HorizontalAlignment="Left" Width="28" Height="38" Margin="0 20 23 0" EnableDropShadow="False" Background="Transparent" BorderThickness="0" Command="{ Binding AddGroupCommand}" Image="{StaticResource Add_group_mycolors}"/>
- <TextBlock Grid.Column="1" Margin="20 20 0 0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="{StaticResource TangoButtonFontSize}" FontWeight="SemiBold" Visibility="{Binding AddGroupMode, Converter={StaticResource BooleanToVisibilityInverseConverter}}">Add Group</TextBlock>
+ <touch:TouchImageButton HorizontalAlignment="Left" Width="28" Height="38" Margin="0 0 23 0" EnableDropShadow="False" Background="Transparent" BorderThickness="0" Command="{ Binding AddGroupCommand}" Image="{StaticResource Add_group_mycolors}"/>
+ <TextBlock Grid.Column="1" Margin="20 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="{StaticResource TangoButtonFontSize}" FontWeight="SemiBold" Visibility="{Binding AddGroupMode, Converter={StaticResource BooleanToVisibilityInverseConverter}}">Add Group</TextBlock>
<DockPanel Visibility="{Binding AddGroupMode, Converter={StaticResource BooleanToVisibilityConverter}}" Grid.Column="1" Margin=" 20 0 0 20">
- <touch:TouchTextBox DockPanel.Dock="Left" Margin="0 0 80 0" x:Name="newGroupNametext" MinWidth="200" Height="Auto" Text="{Binding NewGroupName, Mode=TwoWay,UpdateSourceTrigger=LostFocus}"></touch:TouchTextBox>
- <touch:TouchButton DockPanel.Dock="Right" Width="160" Height="40" CornerRadius="20" Background="Transparent" EnableDropShadow="False" TextElement.Foreground="{StaticResource TangoKeyboardKeyDarkTextBrush}" HorizontalAlignment="Right" Margin="10 26 20 0" VerticalAlignment="Bottom"
+ <touch:TouchTextBox DockPanel.Dock="Left" Margin="0 0 80 0" x:Name="newGroupNametext" MinWidth="350" Height="Auto" Text="{Binding NewGroupName, Mode=TwoWay,UpdateSourceTrigger=LostFocus}" VerticalAlignment="Center"></touch:TouchTextBox>
+ <touch:TouchButton DockPanel.Dock="Right" Width="160" Height="40" CornerRadius="20" Background="Transparent" EnableDropShadow="False" TextElement.Foreground="{StaticResource TangoKeyboardKeyDarkTextBrush}" HorizontalAlignment="Right" Margin="10 20 20 0" VerticalAlignment="Center"
BorderThickness="1" BorderBrush="{StaticResource TangoKeyboardKeyDarkBrush}" Command="{Binding AddNewGroupCommand}" CommandParameter="{Binding ElementName=newGroupNametext, Path=Text}">Add</touch:TouchButton>
</DockPanel>
@@ -720,25 +720,30 @@
<TextBlock DockPanel.Dock="Left" Margin="43 53 0 28" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="{StaticResource TangoHeaderFontSize}" FontWeight="SemiBold">My Colors</TextBlock>
<touch:TouchImageButton DockPanel.Dock="Top" Width="32" Height="32" Image="{StaticResource Close_mycolorsdlg}" HorizontalAlignment="Right" Margin="0 20 23 0" EnableDropShadow="False" Background="Transparent" BorderThickness="0" Command="{Binding CloseMyColorsCommand}"/>
</DockPanel>
- <StackPanel Orientation="Vertical" Margin="0">
- <DockPanel>
+ <StackPanel Orientation="Vertical" Margin="0 20 0 0">
+ <DockPanel VerticalAlignment="Top">
<touch:TouchButton DockPanel.Dock="Right" Height="48" Command="{Binding DataContext.EditColorsLibrariesCommand, ElementName=colorSelectionView}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 0 30 10" Background="Transparent" ShadowDepth="0" ShadowColor="Transparent">
- <StackPanel Height="48" Width="160" Orientation="Horizontal">
- <touch:TouchIcon Margin="0 7 0 0" VerticalAlignment="Center" Foreground="{StaticResource TangoBlackInkBrush}" Height="16.5" Icon="PencilAltSolid" />
- <TextBlock Text="{Binding EditColorButtonName, Mode=TwoWay, TargetNullValue=EDIT}" Height="30" Margin="25 10 0 0" FontSize="{StaticResource TangoButtonFontSize}" FontWeight="SemiBold" VerticalAlignment="Center" Foreground="{StaticResource TangoBlackInkBrush}" ></TextBlock>
+ <StackPanel Height="48" Width="160" Orientation="Horizontal" >
+ <touch:TouchIcon Margin="0 9 0 0" Foreground="{StaticResource TangoBlackInkBrush}" Height="25" Icon="PencilAltSolid" />
+ <TextBlock Text="{Binding EditColorButtonName, Mode=TwoWay, TargetNullValue=EDIT}" Height="30" Margin="25 12 0 0" FontSize="{StaticResource TangoButtonFontSize}" FontWeight="SemiBold" VerticalAlignment="Bottom" Foreground="{StaticResource TangoBlackInkBrush}" ></TextBlock>
</StackPanel>
</touch:TouchButton>
- <Grid DockPanel.Dock="Left" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="60 0 0 0" Width="280">
+ <Grid DockPanel.Dock="Left" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="60 0 0 0" Width="280" Height="48">
<DockPanel>
<Image DockPanel.Dock="Left" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="40" Height="40" Source="{StaticResource SearchImage}"/>
<!--<touch:TouchIcon DockPanel.Dock="Left" Foreground="{StaticResource TangoGrayBrush}" Width="20" Height="20" VerticalAlignment="Bottom" Icon="Magnify" />-->
- <touch:TouchTextBox Margin="5 0 0 0" Width="300" Text="{Binding SearchColorText,Mode=TwoWay, UpdateSourceTrigger=LostFocus}" ></touch:TouchTextBox>
+ <touch:TouchTextBox Margin="15 0 0 0" Width="300" Text="{Binding SearchColorText,Mode=TwoWay, UpdateSourceTrigger=LostFocus}" VerticalAlignment="Center" ></touch:TouchTextBox>
</DockPanel>
</Grid>
</DockPanel>
- <ListBox x:Name="listLibraries" Grid.Row="1" Margin="10 0 10 60" ItemsSource="{Binding Libraries}" Style="{StaticResource ListBoxVerticalScroll}"
+ <ListBox x:Name="listLibraries" Margin="10 16 10 10" ItemsSource="{Binding Libraries}" Style="{StaticResource ListBoxVerticalScroll}"
ScrollViewer.VerticalScrollBarVisibility="Visible" Width="560" ItemTemplate="{StaticResource ColorLibrary_Template}" Height="580">
</ListBox>
+
+ <StackPanel Height="38" Width="160" Orientation="Horizontal" HorizontalAlignment="Left" Margin=" 50 20 20 0" VerticalAlignment="Bottom">
+ <touch:TouchIconButton Margin="0 7 0 10" VerticalAlignment="Bottom" Foreground="{StaticResource TangoBlackInkBrush}" Width="26" Icon="Upload" Command="{Binding UploadFileCommand}"/>
+ <touch:TouchIconButton Margin="30 7 0 10" VerticalAlignment="Bottom" Foreground="{StaticResource TangoBlackInkBrush}" Width="26" Icon="Download" Command="{Binding DownloadFileCommand}"/>
+ </StackPanel>
</StackPanel>
</DockPanel>
</Grid>
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionViewVM.cs
index 37f5c3f7b..cc8ddc84e 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/ColorSelectionViewVM.cs
@@ -1,9 +1,11 @@
using ColorMine.ColorSpaces;
+using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -457,7 +459,25 @@ namespace Tango.PPC.Jobs.Dialogs
set { _editColorButtonName = value;
RaisePropertyChangedAuto();}
}
-
+
+ private PPCSettings _settings;
+ /// <summary>
+ /// Gets the main PPC settings.
+ /// </summary>
+ public PPCSettings Settings
+ {
+ get
+ {
+ if (_settings == null)
+ {
+ _settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
+ }
+
+ return _settings;
+ }
+ private set { _settings = value; }
+ }
+
#endregion
#region commands
@@ -483,6 +503,8 @@ namespace Tango.PPC.Jobs.Dialogs
public RelayCommand<object> DeleteColorCommand { get; set; }
public RelayCommand VectorFineTuningCommand { get; set; }
+ public RelayCommand UploadFileCommand { get; set; }
+ public RelayCommand DownloadFileCommand { get; set; }
#endregion
@@ -534,6 +556,9 @@ namespace Tango.PPC.Jobs.Dialogs
EditColorsLibraryCommand = new RelayCommand<ColorLibrary>(EditColorsLibrary);
EditColorsLibrariesCommand = new RelayCommand(EditColorsLibraries);
DeleteColorCommand = new RelayCommand<object>(DeleteColor);
+ UploadFileCommand = new RelayCommand(UploadFile);
+ DownloadFileCommand = new RelayCommand(DownloadFile);
+
MyColorsMode = false;
EditColorsGroupMode = false;
SaveMyColorMode = false;
@@ -637,9 +662,7 @@ namespace Tango.PPC.Jobs.Dialogs
CheckIsSelectedColorInLibrary();
SelectedBrushStop.ConvertColor();//test OOG
}
-
-
private void OnSelectedtabChanged()
{
switch (SelectedColorTab)
@@ -1148,6 +1171,70 @@ namespace Tango.PPC.Jobs.Dialogs
}
}
+ private async void UploadFile()
+ {
+ if (Settings.StorageRootPath == null || false == Directory.Exists(Settings.StorageRootPath))
+ {
+ Settings.StorageRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Twine", "Storage");
+ Directory.CreateDirectory(Settings.StorageRootPath);
+ }
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.InitialDirectory = Path.GetFullPath(Settings.StorageRootPath);
+ dlg.RestoreDirectory = true;
+ dlg.Filter = "Tango Update My Colors|*.colr";
+ dlg.FileName = "MyColors";
+ dlg.DefaultExt = ".colr";
+ if (dlg.ShowDialog().Value)
+ {
+ try
+ {
+ IsFree = false;
+ MyColorsEngine.Default.ToFile(dlg.FileName);
+ await NotificationProvider.ShowSuccess("My colors file saved successfully.");
+ LogManager.Log($"My colors file saved successfully to file {dlg.FileName}.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error saving My colors to file.");
+ await NotificationProvider.ShowError($"Error creating My colors file:\n{ex.Message}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
+ }
+ }
+
+ private void DownloadFile()
+ {
+ if (Settings.StorageRootPath == null || false == Directory.Exists(Settings.StorageRootPath))
+ {
+ Settings.StorageRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Twine", "Storage");
+ Directory.CreateDirectory(Settings.StorageRootPath);
+ }
+ if (Directory.Exists(Settings.StorageRootPath))
+ {
+ Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
+ {
+ InitialDirectory = Settings.StorageRootPath,
+ Title = "Browse My Colors Files",
+
+ CheckFileExists = true,
+ CheckPathExists = true,
+
+ DefaultExt = "colr",
+ Filter = "job files (*.colr)|*.colr",
+ ReadOnlyChecked = true,
+ ShowReadOnly = true
+ };
+ if (openFileDialog.ShowDialog().Value)
+ {
+ MyColorsEngine.Default.FromFile(openFileDialog.FileName);
+ Libraries = MyColorsEngine.Default.GetAll().ToObservableCollection();
+ }
+ }
+ }
+
private void LoadLibraryDictionary()
{
_colorSpaceToFavoriteColorDictionary = new Dictionary<ColorSpaces, List<FavoriteColor>>();
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/FavoriteColor.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/FavoriteColor.cs
index 00c8293bd..1d7b7c7c2 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/FavoriteColor.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Models/FavoriteColor.cs
@@ -10,6 +10,7 @@ using System.Windows;
using ColorMine.ColorSpaces;
using Tango.Core;
using LiteDB;
+using Newtonsoft.Json;
namespace Tango.PPC.Jobs.Models
{
@@ -86,14 +87,18 @@ namespace Tango.PPC.Jobs.Models
}
[BsonIgnore]
+ [JsonIgnore]
public SolidColorBrush Brush
{
get { return new SolidColorBrush(Color); }
}
[BsonIgnore]
+ [JsonIgnore]
private bool _isSelected;
+
[BsonIgnore]
+ [JsonIgnore]
public bool IsSelected
{
get { return _isSelected; }
@@ -117,5 +122,17 @@ namespace Tango.PPC.Jobs.Models
ColorSpace = ColorSpaces.Volume;
IsSelected = false;
}
+
+ public bool Equals(FavoriteColor color)
+ {
+ if(color == null)
+ return false;
+
+ return (ColorSpace == color.ColorSpace
+ && Cyan == color.Cyan && Magenta == color.Magenta && Yellow == color.Yellow && Black ==color.Black
+ && Red == color.Red && Green == color.Green && Blue == color.Blue
+ && L == color.L && A == color.A && B == color.B
+ && Hue == color.Hue && Saturation == color.Saturation && Brightness == color.Brightness);
+ }
}
}
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/MyColors/MyColorsEngine.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/MyColors/MyColorsEngine.cs
index 27dabc2e7..2963d290b 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/MyColors/MyColorsEngine.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/MyColors/MyColorsEngine.cs
@@ -6,11 +6,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PPC.Jobs.Models;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
namespace Tango.PPC.Jobs.MyColors
{
public class MyColorsEngine : IDisposable
{
+ private JsonSerializerSettings _settings;
+
private LiteDatabase _db;
private ILiteCollection<ColorLibrary> _collection;
@@ -35,6 +39,14 @@ namespace Tango.PPC.Jobs.MyColors
Directory.CreateDirectory(dbFolder);
_db = new LiteDatabase($"Filename={Path.Combine(dbFolder, "color_library.db")}");
_collection = _db.GetCollection<ColorLibrary>("Libraries");
+
+ _settings = new JsonSerializerSettings()
+ {
+ TypeNameHandling = TypeNameHandling.Auto,
+ Formatting = Formatting.Indented,
+ ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
+ PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
+ };
}
public void UpdateLibrary(ColorLibrary library)
@@ -72,5 +84,34 @@ namespace Tango.PPC.Jobs.MyColors
{
_collection.Delete(library.ID);
}
+
+ public void ToFile( string flePath)
+ {
+ string jsonCollection = JsonConvert.SerializeObject(GetAll(), _settings);
+ File.WriteAllText(flePath, jsonCollection);
+ }
+
+ public void FromFile(String fileName)
+ {
+ string json = File.ReadAllText(fileName);
+ List<ColorLibrary> colorCollection = JsonConvert.DeserializeObject<List<ColorLibrary>>(json, _settings);
+ foreach(var colorLib in colorCollection)
+ {
+ var currentLib = _collection.FindOne(x => x.Name == colorLib.Name);
+ if (currentLib != null)
+ {
+ var newlist = colorLib.ColorList.Where(s => !currentLib.ColorList.Any(p => p.Equals(s)));
+ foreach( var x in newlist)
+ currentLib.ColorList.Add(x);
+
+ UpdateLibrary(currentLib);
+ }
+ else
+ {
+ _collection.Insert(colorLib);
+ }
+
+ }
+ }
}
}
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml
index d348b2cc7..a10524e71 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml
@@ -962,7 +962,7 @@
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<DockPanel x:Name="ColorPropertiesPanel" VerticalAlignment="Top" >
- <StackPanel x:Name="AdvansedOptions" DockPanel.Dock="Right" Orientation="Horizontal" VerticalAlignment="Top" Margin="0 5 18 0" Height="55" HorizontalAlignment="Right" Width="Auto" Visibility="{Binding ShowAdvanced, Converter={StaticResource BooleanToVisibilityConverter}}">
+ <StackPanel x:Name="AdvansedOptions" DockPanel.Dock="Right" Orientation="Horizontal" Margin="0 5 18 0" Height="55" HorizontalAlignment="Right" Width="Auto" Visibility="{Binding ShowAdvanced, Converter={StaticResource BooleanToVisibilityConverter}}" VerticalAlignment="Center">
<TextBlock FontSize="20" VerticalAlignment="Center" >Advanced Options</TextBlock>
<touch:TouchToggleSlider Style="{StaticResource TangoToggleButtonGreenAccent}" Height="28" CornerRadius="14" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10 0 0 0" Width="54" IsChecked="{Binding IsBasicMode, Converter={StaticResource BooleanInverseConverter}, Mode=TwoWay}"></touch:TouchToggleSlider>
</StackPanel>