From d5fd706b42a43f2b6399ae714ee45f49bb1fd66a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 8 May 2019 09:51:19 +0300 Subject: MERGE --- .../Tango.UnitTesting/SendGrid/SendGrid_TST.cs | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs index 785fa42bf..9465676ef 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs @@ -3,10 +3,14 @@ using SendGrid; using SendGrid.Helpers.Mail; using System; using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; +using Tango.PMR.TCC; namespace Tango.UnitTesting.SendGrid { @@ -35,5 +39,59 @@ namespace Tango.UnitTesting.SendGrid Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Accepted); } + + [TestMethod] + public void Send_Template_Email() + { + var client = new SendGridClient(KEY); + SendGridMessage msg = new SendGridMessage(); + msg.SetFrom("test@example.com"); + msg.AddTo("roy.mail.net@gmail.com"); + msg.Subject = "SnapMatch Color Result"; + msg.SetTemplateId("d-619b8adc604d4f6fa486d7bbc9e3c2cc"); + + Bitmap rect = new Bitmap(80, 80); + using (Graphics g = Graphics.FromImage(rect)) + { + g.Clear(Color.FromArgb(255, 0, 0)); + } + + String image64 = String.Empty; + + using (MemoryStream ms = new MemoryStream()) + { + rect.Save(ms, ImageFormat.Jpeg); + ms.Position = 0; + image64 = Convert.ToBase64String(ms.ToArray()); + } + + var dynamicTemplateData = new ExampleTemplateData + { + Name = "Roy", + Message = "This is my personal note...", + ImageSource = image64, + }; + + msg.SetTemplateData(dynamicTemplateData); + + + DetectionColorFile file = new DetectionColorFile(); + file.RawColor = new DetectionColor() { R = 10, G = 20, B = 30 }; + file.ProcessedColor = new DetectionColor() { R = 11, G = 21, B = 31 }; + + var base64 = Convert.ToBase64String(file.ToBytes()); + msg.AddAttachment("SnapMatch Color.tcc", base64, "application/octet-stream"); + + var result = client.SendEmailAsync(msg).GetAwaiter().GetResult(); + + Assert.IsTrue(result.StatusCode == HttpStatusCode.Accepted); + } + + public class ExampleTemplateData + { + public String Name { get; set; } + public String ImageSource { get; set; } + public String Message { get; set; } + } } } -- cgit v1.3.1 From a46fd6cec3dc8aa99e7a3067de4c0617b232ff88 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 8 May 2019 13:35:30 +0300 Subject: Working on TCC... --- .../Android_Studio/ColorCapture/app/build.gradle | 4 +-- .../views/capture/CaptureFragmentVM.java | 6 ++--- Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes .../Controllers/ColorDetectionController.cs | 16 +++++++----- .../Tango.UnitTesting/SendGrid/SendGrid_TST.cs | 29 +++------------------ 6 files changed, 18 insertions(+), 37 deletions(-) (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Android_Studio/ColorCapture/app/build.gradle b/Software/Android_Studio/ColorCapture/app/build.gradle index 0ca125d7f..b74f3a18c 100644 --- a/Software/Android_Studio/ColorCapture/app/build.gradle +++ b/Software/Android_Studio/ColorCapture/app/build.gradle @@ -6,7 +6,7 @@ android { applicationId "com.twine.colorcapture" minSdkVersion 22 targetSdkVersion 27 - versionCode 1 + versionCode 2 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { @@ -23,7 +23,7 @@ android { buildTypes { debug { - buildConfigField "String", "WEB_SERVICE_ADDRESS", "\"http://10.100.102.88:45455/api/\"" + buildConfigField "String", "WEB_SERVICE_ADDRESS", "\"http://192.168.1.229:45455/api/\"" buildConfigField "String", "WEB_SERVICE_APP_ID", "\"Tdf793i4ughsiduf8749509237885ehgfdlkghlT\"" } diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java index 263aad444..1d92323ea 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java @@ -249,12 +249,12 @@ public class CaptureFragmentVM extends ViewModelBase implement { notificationProvider.showDialog(new WelcomeDialog(), (vm) -> { + SettingsManager.getInstance().setWelcomeScreenShown(true); + SettingsManager.save(); + isCardDetected.set(false); view.startCamera(); }); - - SettingsManager.getInstance().setWelcomeScreenShown(true); - SettingsManager.save(); } else { diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 6cd05b1c4..5ecfefac1 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 9a2f05be1..4ad4ff344 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs b/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs index e2560ff41..d508c2f10 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs @@ -196,19 +196,21 @@ namespace Tango.TCC.Service.Controllers ResultByEmailResponse response = new ResultByEmailResponse(); var client = new SendGridClient(TCCServiceConfig.SEND_GRID_API_KEY); - //var from = new EmailAddress(request.From); - //var subject = "SnapMatch Color Result"; - //var to = new EmailAddress(request.To); SendGridMessage msg = new SendGridMessage(); msg.SetFrom(request.From); msg.AddTo(request.To); msg.Subject = "SnapMatch Color Result"; + msg.SetTemplateId("d-619b8adc604d4f6fa486d7bbc9e3c2cc"); - + var dynamicTemplateData = new + { + Message = request.Message, + R = request.DetectionResponse.ProcessedColor.R, + G = request.DetectionResponse.ProcessedColor.G, + B = request.DetectionResponse.ProcessedColor.B, + }; - //var plainTextContent = request.Message; - //var htmlContent = $"
{request.Message}."; - //var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); + msg.SetTemplateData(dynamicTemplateData); DetectionColorFile file = new DetectionColorFile(); file.RawColor = request.DetectionResponse.RawColor; diff --git a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs index 9465676ef..ca0ba1143 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs @@ -50,26 +50,12 @@ namespace Tango.UnitTesting.SendGrid msg.Subject = "SnapMatch Color Result"; msg.SetTemplateId("d-619b8adc604d4f6fa486d7bbc9e3c2cc"); - Bitmap rect = new Bitmap(80, 80); - using (Graphics g = Graphics.FromImage(rect)) + var dynamicTemplateData = new { - g.Clear(Color.FromArgb(255, 0, 0)); - } - - String image64 = String.Empty; - - using (MemoryStream ms = new MemoryStream()) - { - rect.Save(ms, ImageFormat.Jpeg); - ms.Position = 0; - image64 = Convert.ToBase64String(ms.ToArray()); - } - - var dynamicTemplateData = new ExampleTemplateData - { - Name = "Roy", Message = "This is my personal note...", - ImageSource = image64, + R = 0, + G = 255, + B = 0, }; msg.SetTemplateData(dynamicTemplateData); @@ -86,12 +72,5 @@ namespace Tango.UnitTesting.SendGrid Assert.IsTrue(result.StatusCode == HttpStatusCode.Accepted); } - - public class ExampleTemplateData - { - public String Name { get; set; } - public String ImageSource { get; set; } - public String Message { get; set; } - } } } -- cgit v1.3.1 From e5200c6ba6a1b13525cc1261992ad61b03f93951 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Fri, 10 May 2019 14:49:12 +0300 Subject: Implemented TWN & TCC Import on PPC. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../Dialogs/ImportColorProfileView.xaml | 35 ++++++++ .../Dialogs/ImportColorProfileView.xaml.cs | 28 ++++++ .../Dialogs/ImportColorProfileViewVM.cs | 16 ++++ .../Tango.PPC.Jobs/Dialogs/ImportJobView.xaml | 10 +-- .../Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml | 28 ++++++ .../Dialogs/ImportTwnFileView.xaml.cs | 28 ++++++ .../Tango.PPC.Jobs/Dialogs/ImportTwnFileViewVM.cs | 17 ++++ .../PPC/Modules/Tango.PPC.Jobs/Images/emb-file.png | Bin 0 -> 2588 bytes .../Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj | 26 +++++- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 100 ++++++++++++++++++++- .../PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml | 2 +- .../Visual_Studio/PPC/Tango.PPC.UI/app.manifest | 2 +- .../ExtensionMethods/ByteArrayExtensions.cs | 33 +++++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 3 +- .../Visual_Studio/Tango.Explorer/Images/color.png | Bin 2287 -> 6704 bytes Software/Visual_Studio/Tango.Pulse/TwnFile.cs | 5 ++ .../Visual_Studio/Tango.Pulse/TwnFileReader.cs | 1 + .../Tango.UnitTesting/Pulse/Pulse_TST.cs | 42 +++++++++ 20 files changed, 365 insertions(+), 11 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Images/emb-file.png create mode 100644 Software/Visual_Studio/Tango.Core/ExtensionMethods/ByteArrayExtensions.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index dff95607f..43db581e7 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index d83b8d16c..b956aa006 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml new file mode 100644 index 000000000..41010261e --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml @@ -0,0 +1,35 @@ + + + + + CANCEL + IMPORT + + + + Import SnapMatch Color + + A SnapMatch color detection result file has been selected from the storage device. press 'IMPORT' to create a new job from this color. + + + + + Detected Color + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml.cs new file mode 100644 index 000000000..f919b9df8 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +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; + +namespace Tango.PPC.Jobs.Dialogs +{ + /// + /// Interaction logic for ImportJobView.xaml + /// + public partial class ImportColorProfileView : UserControl + { + public ImportColorProfileView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileViewVM.cs new file mode 100644 index 000000000..100236d8e --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportColorProfileViewVM.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.Core.Commands; +using Tango.SharedUI; + +namespace Tango.PPC.Jobs.Dialogs +{ + public class ImportColorProfileViewVM : DialogViewVM + { + public Color Color { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml index 6d719aba9..ac27cc00d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportJobView.xaml @@ -6,13 +6,13 @@ xmlns:local="clr-namespace:Tango.PPC.Jobs.Dialogs" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" mc:Ignorable="d" - Background="{StaticResource TangoPrimaryBackgroundBrush}" d:DesignHeight="555" d:DesignWidth="560" Width="550" Height="450" d:DataContext="{d:DesignInstance Type=local:ImportJobViewVM, IsDesignTimeCreatable=False}"> + Background="{StaticResource TangoPrimaryBackgroundBrush}" d:DesignHeight="555" d:DesignWidth="560" Width="570" Height="700" d:DataContext="{d:DesignInstance Type=local:ImportJobViewVM, IsDesignTimeCreatable=False}"> - - CANCEL - IMPORT - + + CANCEL + IMPORT + IMPORT JOB diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml new file mode 100644 index 000000000..0cd9540ec --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml @@ -0,0 +1,28 @@ + + + + + CANCEL + IMPORT + + + + Import Embroidery File + + An embroidery design file has been selected from the storage device. press 'IMPORT' to create a new job from this design. + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml.cs new file mode 100644 index 000000000..a04406374 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +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; + +namespace Tango.PPC.Jobs.Dialogs +{ + /// + /// Interaction logic for ImportJobView.xaml + /// + public partial class ImportTwnFileView : UserControl + { + public ImportTwnFileView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileViewVM.cs new file mode 100644 index 000000000..5792413b8 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/ImportTwnFileViewVM.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using Tango.Core.Commands; +using Tango.SharedUI; + +namespace Tango.PPC.Jobs.Dialogs +{ + public class ImportTwnFileViewVM : DialogViewVM + { + public BitmapSource Thumbnail { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Images/emb-file.png b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Images/emb-file.png new file mode 100644 index 000000000..a369eb899 Binary files /dev/null and b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Images/emb-file.png differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index 792e32521..8659367b3 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -46,6 +46,7 @@ + ..\..\..\packages\Expression.Blend.Sdk.1.0.2\lib\net45\System.Windows.Interactivity.dll @@ -91,6 +92,14 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -173,6 +182,14 @@ BasicColorCorrectionView.xaml + + ImportTwnFileView.xaml + + + ImportColorProfileView.xaml + + + FineTuningPaletteView.xaml @@ -282,6 +299,10 @@ {e4927038-348d-4295-aaf4-861c58cb3943} Tango.PMR + + {8435223d-db6b-45e3-a08b-45b7416f8481} + Tango.Pulse + {d8f1ad85-526a-4f50-b6dc-d437af63d8d8} Tango.Settings @@ -420,10 +441,13 @@ + + + - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index 2ea3b98b8..530eae385 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -30,6 +30,9 @@ using Tango.PMR.Exports; using Tango.Settings; using Tango.Integration.ExternalBridge; using System.Windows.Media; +using Tango.PMR.TCC; +using Tango.Pulse; +using System.Windows.Media.Imaging; namespace Tango.PPC.Jobs.ViewModels { @@ -376,7 +379,7 @@ namespace Tango.PPC.Jobs.ViewModels /// /// Adds a new job. /// - private async void AddNewJob(Color? colorProfile = null) + private async void AddNewJob(Color? colorProfile = null, TwnFile twnFile = null) { try { @@ -410,10 +413,13 @@ namespace Tango.PPC.Jobs.ViewModels vm.SelectedColorSpace = space.IsUserSpace() ? space : ColorSpaces.Twine; } - if (colorProfile != null) + if (colorProfile != null || twnFile != null) { vm.SupportedColorSpaces = new List() { ColorSpaces.RGB }; vm.SelectedColorSpace = vm.SupportedColorSpaces.First(); + + vm.SupportedJobTypes = new List() { JobTypes.Embroidery }; + vm.SelectedJobType = vm.SupportedJobTypes.First(); } if (machine.SupportedJobTypes.Count != 1 || machine.SupportedColorSpaces.Count != 1) @@ -461,6 +467,44 @@ namespace Tango.PPC.Jobs.ViewModels job.AddSolidSegment(colorProfile.Value, machine.DefaultSegmentLength > 0 ? machine.DefaultSegmentLength : 100); } + if (twnFile != null) + { + job.Name = twnFile.Name; + job.NumberOfUnits = Math.Max(twnFile.NumberOfCopies, 1); + job.EmbroideryFileName = twnFile.Name + "." + twnFile.EmbroideryFileFormat; + job.EmbroideryFileData = twnFile.EmbroideryFile; + job.EmbroideryJpeg = twnFile.ThumbnailData; + + job.Segments.Clear(); + + int index = 1; + + foreach (var segment in twnFile.Segments) + { + Segment s = new Segment(); + s.Job = job; + s.SegmentIndex = index++; + s.Name = "Embroidery Segment"; + s.Length = segment.Length / 100d; + + int sIndex = 1; + + foreach (var stop in segment.BrushStops) + { + BrushStop st = new BrushStop(); + st.Segment = s; + st.StopIndex = sIndex++; + st.OffsetPercent = stop.Offset * 100d; + st.Red = stop.R; + st.Green = stop.G; + st.Blue = stop.B; + s.BrushStops.Add(st); + } + + job.Segments.Add(s); + } + } + _db.Jobs.Add(job); await _db.SaveChangesAsync(); @@ -621,6 +665,8 @@ namespace Tango.PPC.Jobs.ViewModels { base.OnApplicationReady(); StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Job.Extension, HandleJobFileLoaded); + StorageProvider.RegisterFileHandler(ExplorerFileDefinition.ColorProfile.Extension, HandleColorProfileFileLoaded); + StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Pulse.Extension, HandlePulseFileLoaded); } public override void OnNavigatedTo() @@ -714,6 +760,56 @@ namespace Tango.PPC.Jobs.ViewModels #endregion + #region Handle TCC File Loading From Storage + + private async void HandleColorProfileFileLoaded(ExplorerFileItem tccFile) + { + try + { + DetectionColorFile tcc = DetectionColorFile.Parser.ParseFrom(File.ReadAllBytes(tccFile.Path)); + + var vm = await NotificationProvider.ShowDialog(new ImportColorProfileViewVM() + { + Color = Color.FromRgb( + (byte)tcc.ProcessedColor.R, + (byte)tcc.ProcessedColor.G, + (byte)tcc.ProcessedColor.B), + }); + + if (vm.DialogResult) + { + AddNewJob(vm.Color); + } + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error occurred while trying to import detection color from file {tccFile.Path}."); + await NotificationProvider.ShowError($"An error occurred while trying to import the selected detection color.\n{ex.Message}"); + } + } + + #endregion + + #region Handle Pulse TWN Loading From Storage + + private async void HandlePulseFileLoaded(ExplorerFileItem twnFile) + { + TwnFile twn = TwnFile.FromFile(twnFile.Path); + BitmapSource preview = twn.Thumbnail.ToBitmapSource(); + + var vm = await NotificationProvider.ShowDialog(new ImportTwnFileViewVM() + { + Thumbnail = preview, + }); + + if (vm.DialogResult) + { + AddNewJob(null, twn); + } + } + + #endregion + #region Color Profile Request private void ExternalBridgeService_ColorProfileRequest(object sender, ColorProfileRequestEventArgs e) diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml index 30a1a4a07..aa04398f1 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml @@ -166,7 +166,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index d72e75011..efc5f8179 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - + diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ByteArrayExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ByteArrayExtensions.cs new file mode 100644 index 000000000..27a05c39d --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ByteArrayExtensions.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +public static class ByteArrayExtensions +{ + /// + /// Creates a new BitmapImage from the byte array. + /// + /// The image data. + /// + private static BitmapImage ToBitmapImage(this byte[] data) + { + if (data == null || data.Length == 0) return null; + var image = new BitmapImage(); + using (var mem = new MemoryStream(data)) + { + mem.Position = 0; + image.BeginInit(); + image.CreateOptions = BitmapCreateOptions.PreservePixelFormat; + image.CacheOption = BitmapCacheOption.OnLoad; + image.UriSource = null; + image.StreamSource = mem; + image.EndInit(); + } + image.Freeze(); + return image; + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 963ec0b79..8d762ee55 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -86,6 +86,7 @@ GlobalVersionInfo.cs + @@ -196,7 +197,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Explorer/Images/color.png b/Software/Visual_Studio/Tango.Explorer/Images/color.png index 44ca22ae2..ead2991e0 100644 Binary files a/Software/Visual_Studio/Tango.Explorer/Images/color.png and b/Software/Visual_Studio/Tango.Explorer/Images/color.png differ diff --git a/Software/Visual_Studio/Tango.Pulse/TwnFile.cs b/Software/Visual_Studio/Tango.Pulse/TwnFile.cs index 75653c03e..40ee58476 100644 --- a/Software/Visual_Studio/Tango.Pulse/TwnFile.cs +++ b/Software/Visual_Studio/Tango.Pulse/TwnFile.cs @@ -52,6 +52,11 @@ namespace Tango.Pulse /// public Bitmap Thumbnail { get; set; } + /// + /// Gets or sets the thumbnail data. + /// + public byte[] ThumbnailData { get; set; } + /// /// Array of Brush Segment. The number of brush segments must be defined in the header. /// diff --git a/Software/Visual_Studio/Tango.Pulse/TwnFileReader.cs b/Software/Visual_Studio/Tango.Pulse/TwnFileReader.cs index 2efa94936..81fcf4519 100644 --- a/Software/Visual_Studio/Tango.Pulse/TwnFileReader.cs +++ b/Software/Visual_Studio/Tango.Pulse/TwnFileReader.cs @@ -64,6 +64,7 @@ namespace Tango.Pulse //pixels while maintaining aspect ratio. MemoryStream ms = new MemoryStream(reader.ReadBytes((int)thumbnail_size)); twnFile.Thumbnail = new Bitmap(ms); + twnFile.ThumbnailData = ms.ToArray(); //Array of Brush Segment. The number of brush segments must be defined in the header. diff --git a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs index 073841997..65bb31208 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs @@ -82,5 +82,47 @@ namespace Tango.UnitTesting.Pulse Helper.ShowInExplorer(imgFile); } + + [TestMethod] + public void Create_Twn_Sample_File() + { + String abcFile = Path.Combine(Helper.GetResourcePath(), "Pulse", "ABC.dst"); + + TwnFile twnFile = new TwnFile(); + twnFile.Name = "My design"; + twnFile.NumberOfCopies = 1; + twnFile.MediaID = 0; + twnFile.SpoolingMethod = SpoolingMethods.SpoolPerSegment; + + Bitmap thumbnail = new Bitmap(1280, 720); + using (Graphics g = Graphics.FromImage(thumbnail)) + { + g.Clear(Color.Gray); + g.DrawString("My design", new Font(new FontFamily("Arial"), 70), Brushes.Red, 1280 / 2, 720 / 2); + } + twnFile.Thumbnail = thumbnail; + + twnFile.EmbroideryFileFormat = "dst"; + twnFile.EmbroideryFile = File.ReadAllBytes(abcFile); + + //Add gradient segment. + TwnSegment gradientSegment = new TwnSegment(); + gradientSegment.Length = 100 * 10; //10 meters. + gradientSegment.BrushStops.Add(new TwnStop(255, 0, 0, 0)); //0% + gradientSegment.BrushStops.Add(new TwnStop(0, 0, 255, 1)); //100% + twnFile.Segments.Add(gradientSegment); + + //Add solid segment. + TwnSegment solidSegment = new TwnSegment(); + solidSegment.Length = 100 * 20; //20 meters. + solidSegment.BrushStops.Add(new TwnStop(0, 255, 0, 0)); + twnFile.Segments.Add(solidSegment); + + var twnFilePath = TemporaryManager.Default.CreateFile(".twn"); + + twnFile.ToFile(twnFilePath); + + twnFilePath.Display(); + } } } -- cgit v1.3.1