diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-10-03 10:04:11 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-10-03 10:04:11 +0300 |
| commit | 2ccc5a2e78f306d3c434c764e34509d4db92d8d8 (patch) | |
| tree | 399f8c061fa698c36d06da9ebc101d65b02df26e /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels | |
| parent | b9e2c008322ce474ce6e0b18da9a786c128de8d9 (diff) | |
| parent | a6496a02892d653a70bc9e0d37856b1a7d3cd74b (diff) | |
| download | Tango-2ccc5a2e78f306d3c434c764e34509d4db92d8d8.tar.gz Tango-2ccc5a2e78f306d3c434c764e34509d4db92d8d8.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
2 files changed, 216 insertions, 5 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/InsufficientLiquidQuantityViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/InsufficientLiquidQuantityViewVM.cs new file mode 100644 index 000000000..e18fc842f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/InsufficientLiquidQuantityViewVM.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Operation; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class InsufficientLiquidQuantityViewVM : DialogViewVM + { + public InsufficientLiquidQuantityException Exception { get; set; } + + public InsufficientLiquidQuantityViewVM(InsufficientLiquidQuantityException ex) + { + Exception = ex; + } + } +} 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 ac5354a74..27d43bd20 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 @@ -48,6 +48,8 @@ using Tango.MachineStudio.Common.Navigation; using System.Diagnostics; using Tango.Core.ExtensionMethods; using Tango.ColorConversion; +using Tango.PMR.Exports; +using Microsoft.WindowsAPICodePack.Dialogs; namespace Tango.MachineStudio.Developer.ViewModels { @@ -552,14 +554,35 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _enableColorConversion = value; RaisePropertyChangedAuto(); } } + /// <summary> + /// Gets or sets the authentication provider. + /// </summary> public IAuthenticationProvider AuthenticationProvider { get; set; } + /// <summary> + /// Gets or sets the module settings. + /// </summary> public DeveloperModuleSettings Settings { get { return _settings; } set { _settings = value; RaisePropertyChangedAuto(); } } + private bool _autoProcessSelection; + /// <summary> + /// Gets or sets a value indicating whether [automatic process selection]. + /// </summary> + public bool AutoProcessSelection + { + get { return _autoProcessSelection; } + set + { + _autoProcessSelection = value; + RaisePropertyChangedAuto(); + Settings.AutoProcessSelection = _autoProcessSelection; + } + } + #endregion #region Commands @@ -704,6 +727,16 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> public RelayCommand ResetProcessParametersCommand { get; set; } + /// <summary> + /// Gets or sets the import job file command. + /// </summary> + public RelayCommand ImportJobFileCommand { get; set; } + + /// <summary> + /// Gets or sets the export job file command. + /// </summary> + public RelayCommand ExportJobFileCommand { get; set; } + #endregion #region Constructors @@ -765,6 +798,8 @@ namespace Tango.MachineStudio.Developer.ViewModels DisplayJobEmbroideryFileCommand = new RelayCommand<Job>(DisplayJobEmbroideryFile, () => CanWork); ReloadMachinesCommand = new RelayCommand(() => LoadMachine(), () => CanWork && SelectedMachine != null); ResetProcessParametersCommand = new RelayCommand(ResetProcessParameters, () => CanWork && MachineOperator != null); + ImportJobFileCommand = new RelayCommand(ImportJobFile, () => SelectedMachine != null && CanWork); + ExportJobFileCommand = new RelayCommand(ExportJobFile, () => SelectedMachine != null && SelectedMachineJob != null && CanWork); ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; @@ -795,6 +830,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { Settings = SettingsManager.Default.GetOrCreate<DeveloperModuleSettings>(); + AutoProcessSelection = Settings.AutoProcessSelection; + SelectedJobs = new ObservableCollection<Job>(); JobEvents = new ObservableCollection<MachinesEvent>(); @@ -827,7 +864,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { while (true) { - if (!_rml_has_no_cct && EnableColorConversion && !_disable_gamut_check && IsJobVisible && IsVisible && ActiveJob != null && ActiveJob.Segments != null) + if (!_rml_has_no_cct && EnableColorConversion && !_disable_gamut_check && IsJobVisible && IsVisible && ActiveJob != null && ActiveJob.Segments != null && SelectedProcessParametersTable != null) { try { @@ -839,7 +876,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { try { - var output = _converter.Convert(stop); + var output = _converter.Convert(stop, false); stop.Red = output.SingleCoordinates.Red; stop.Green = output.SingleCoordinates.Green; @@ -853,7 +890,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { try { - stop.IsOutOfGamut = _converter.IsOutOfGamut(stop); + var output = _converter.Convert(stop, false); + output.ApplyOnBrushStopLiquidVolumes(stop, SelectedProcessParametersTable); stop.OutOfGamutChecked = true; } catch { } @@ -863,6 +901,23 @@ namespace Tango.MachineStudio.Developer.ViewModels catch { } } + if (AutoProcessSelection && IsJobVisible && IsVisible && ActiveJob != null && ActiveJob.Segments != null && !_rml_has_no_cct && !_disable_gamut_check) + { + try + { + var recommendedProcess = _converter.GetRecommendedProcessParameters(ActiveJob, RmlProcessParametersTableGroup); + + if (recommendedProcess != null && recommendedProcess != SelectedProcessParametersTable) + { + SelectedProcessParametersTable = recommendedProcess; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error resolving recommended process parameters."); + } + } + Thread.Sleep(500); } } @@ -874,7 +929,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _hiveOpened = true; try { - HiveSuggestions = _converter.Convert(SelectedBrushStop).CreateHiveSuggestions(); + HiveSuggestions = _converter.Convert(SelectedBrushStop, true).CreateHiveSuggestions(); } catch (Exception ex) { @@ -915,7 +970,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (!_color_changed_from_hive && _hiveOpened) { SelectedBrushStop.Corrected = false; - HiveSuggestions = _converter.Convert(SelectedBrushStop).CreateHiveSuggestions(); + HiveSuggestions = _converter.Convert(SelectedBrushStop, true).CreateHiveSuggestions(); } } @@ -1337,6 +1392,26 @@ namespace Tango.MachineStudio.Developer.ViewModels stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); } + if (AutoProcessSelection) + { + LogManager.Log("Auto process parameters selection enabled. Trying to resolve the recommended process parameters..."); + try + { + var recommendedProcess = _converter.GetRecommendedProcessParameters(ActiveJob, RmlProcessParametersTableGroup); + + if (recommendedProcess != null && recommendedProcess != SelectedProcessParametersTable) + { + SelectedProcessParametersTable = recommendedProcess; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error resolving recommended process parameters."); + _notification.ShowError("An error occurred while trying to resolve the recommended process parameters.Please try to disable the auto selection."); + return; + } + } + JobEvents.Clear(); IsJobFailed = false; IsJobCanceled = false; @@ -1445,6 +1520,16 @@ namespace Tango.MachineStudio.Developer.ViewModels //Finally Canceled.. }; } + catch (InsufficientLiquidQuantityException ex) + { + _notification.ShowModalDialog<InsufficientLiquidQuantityViewVM, InsufficientLiquidQuantityView>(new InsufficientLiquidQuantityViewVM(ex), (x) => + { + + MachineOperator.EnableJobLiquidQuantityValidation = false; + StartJob(); + + }, () => { }); + } catch (Exception ex) { LogManager.Log(ex); @@ -2417,6 +2502,112 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion + #region Job Import/Export + + private async void ExportJobFile() + { + if (SelectedJobs != null && SelectedJobs.Count > 1) + { + CommonOpenFileDialog dlg = new CommonOpenFileDialog(); + dlg.Title = "Select a folder to place all job files."; + dlg.IsFolderPicker = true; + + if (dlg.ShowDialog() == CommonFileDialogResult.Ok) + { + foreach (var job in SelectedJobs) + { + using (_notification.PushTaskItem($"Exporting job '{job.Name}'...")) + { + try + { + LogManager.Log($"Exporting job file {job.Name}"); + + var jobFile = await job.ToJobFile(); + File.WriteAllBytes(Path.Combine(dlg.FileName, job.Name + ".job"), jobFile.ToBytes()); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting job file."); + _notification.ShowError($"An error occurred while trying to export job '{job.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + } + else + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Export Job File"; + dlg.Filter = "Twine Job Files|*.job"; + dlg.DefaultExt = ".job"; + dlg.FileName = SelectedMachineJob.Name; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem($"Exporting job '{SelectedMachineJob.Name}'...")) + { + try + { + LogManager.Log($"Exporting job file {SelectedMachineJob.Name}"); + + var jobFile = await SelectedMachineJob.ToJobFile(); + File.WriteAllBytes(dlg.FileName, jobFile.ToBytes()); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting job file."); + _notification.ShowError($"An error occurred while trying to export job '{SelectedMachineJob.Name}'.\n{ex.FlattenMessage()}"); + } + } + } + } + } + + private async void ImportJobFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Import Job File"; + dlg.Filter = "Twine Job Files|*.job"; + dlg.Multiselect = true; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem($"Importing job files...")) + { + try + { + IsFree = false; + + LogManager.Log($"Importing job files..."); + + foreach (var file in dlg.FileNames) + { + var bytes = File.ReadAllBytes(file); + var jobFile = JobFile.Parser.ParseFrom(bytes); + var job = await Job.FromJobFile(jobFile, SelectedMachine.Guid, AuthenticationProvider.CurrentUser.Guid); + + _machineDbContext.Jobs.Add(job); + } + + await _machineDbContext.SaveChangesAsync(); + + IsFree = true; + + _notification.ShowInfo($"Jobs imported successfully."); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error importing job file."); + _notification.ShowError($"An error occurred while trying to import the selected job file.\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } + } + } + } + + #endregion + #region Override Methods protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) |
