aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-25 20:18:10 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-25 20:18:10 +0300
commit0389f1e2c0a1fd48aefef9f677d6aa89fb92704a (patch)
tree6acf891fcf6d6868255d0cf9d9b273b3ee46c1ff /Software/Visual_Studio/MachineStudio/Modules
parent9bc0807514a69d97fceab11d77bee02aff4eb3d9 (diff)
downloadTango-0389f1e2c0a1fd48aefef9f677d6aa89fb92704a.tar.gz
Tango-0389f1e2c0a1fd48aefef9f677d6aa89fb92704a.zip
Improved RML delete procedure on Machine Studio.
Enabled text copying from MS Message Box. Improved RML loading UX.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj8
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs117
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RmlDeleteDialogViewVM.cs95
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml82
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml.cs28
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml2
6 files changed, 295 insertions, 37 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj
index 145a0e06e..38d289c58 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Tango.MachineStudio.RML.csproj
@@ -106,6 +106,7 @@
<Compile Include="ViewModels\LiquidVolumeVM.cs" />
<Compile Include="ViewModels\MainViewVM.cs" />
<Compile Include="ViewModels\RgbVM.cs" />
+ <Compile Include="ViewModels\RmlDeleteDialogViewVM.cs" />
<Compile Include="Views\AddLiquidFactorView.xaml.cs">
<DependentUpon>AddLiquidFactorView.xaml</DependentUpon>
</Compile>
@@ -124,6 +125,9 @@
<Compile Include="Views\ProcessParametersView.xaml.cs">
<DependentUpon>ProcessParametersView.xaml</DependentUpon>
</Compile>
+ <Compile Include="Views\RmlDeleteDialogView.xaml.cs">
+ <DependentUpon>RmlDeleteDialogView.xaml</DependentUpon>
+ </Compile>
<Compile Include="Views\RmlsView.xaml.cs">
<DependentUpon>RmlsView.xaml</DependentUpon>
</Compile>
@@ -244,6 +248,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="Views\RmlDeleteDialogView.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Views\RmlsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
index cbb171cd6..548ea7d8c 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
@@ -181,7 +181,7 @@ namespace Tango.MachineStudio.RML.ViewModels
private ColorCalibrationViewVM _colorCalibrationVM;
public ColorCalibrationViewVM ColorCalibrationVM
{
- get { return _colorCalibrationVM; }
+ get { return _colorCalibrationVM; }
set { _colorCalibrationVM = value; RaisePropertyChangedAuto(); }
}
@@ -282,40 +282,57 @@ namespace Tango.MachineStudio.RML.ViewModels
private async void LoadRmls()
{
- if (_rmls_context != null) _rmls_context.Dispose();
-
- _rmls_context = ObservablesContext.CreateDefault();
- Rmls = await new RmlsCollectionBuilder(_rmls_context).SetAll().WithLiquidFactors().WithMediaProperties().BuildAsync();
- //Load CCT file names...
- var ccts = await _rmls_context.Ccts.Select(x => new
- {
- x.Guid,
- x.FileName
- }).ToListAsync();
-
- foreach (var rml in Rmls)
+ try
{
- var cct = ccts.SingleOrDefault(x => x.Guid == rml.CctGuid);
+ IsFree = false;
- if (cct != null)
+ using (_notification.PushTaskItem("Loading Rmls..."))
{
- rml.Cct = new Cct()
+ if (_rmls_context != null) _rmls_context.Dispose();
+
+ _rmls_context = ObservablesContext.CreateDefault();
+ Rmls = await new RmlsCollectionBuilder(_rmls_context).SetAll().WithLiquidFactors().WithMediaProperties().BuildAsync();
+ //Load CCT file names...
+ var ccts = await _rmls_context.Ccts.Select(x => new
+ {
+ x.Guid,
+ x.FileName
+ }).ToListAsync();
+
+ foreach (var rml in Rmls)
+ {
+ var cct = ccts.SingleOrDefault(x => x.Guid == rml.CctGuid);
+
+ if (cct != null)
+ {
+ rml.Cct = new Cct()
+ {
+ Guid = cct.Guid,
+ FileName = cct.FileName,
+ };
+ }
+ }
+ RmlsCollectionView = CollectionViewSource.GetDefaultView(Rmls);
+ RmlsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Rml.LastUpdated), ListSortDirection.Descending));
+ //RmlsCollectionView.Filter = new Predicate<object>(FilterCollection);
+
+ RmlsCollectionView.Filter = (rml) =>
{
- Guid = cct.Guid,
- FileName = cct.FileName,
+ Rml r = rml as Rml;
+ return String.IsNullOrWhiteSpace(RMLFilter)
+ || r.Name.ToLower().Contains(RMLFilter.ToLower());
};
+
}
}
- RmlsCollectionView = CollectionViewSource.GetDefaultView(Rmls);
- RmlsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Rml.LastUpdated), ListSortDirection.Descending));
- //RmlsCollectionView.Filter = new Predicate<object>(FilterCollection);
-
- RmlsCollectionView.Filter = (rml) =>
+ catch (Exception ex)
{
- Rml r = rml as Rml;
- return String.IsNullOrWhiteSpace(RMLFilter)
- || r.Name.ToLower().Contains(RMLFilter.ToLower());
- };
+ LogManager.Log(ex, $"Error loading RMLS.\n{ex.FlattenMessage()}");
+ }
+ finally
+ {
+ IsFree = true;
+ }
}
private async void LoadActiveRML(String guid)
@@ -537,34 +554,62 @@ namespace Tango.MachineStudio.RML.ViewModels
{
if (_notification.ShowQuestion("Removing the selected thread will result in the loss of all related process parameters and default calibration data. Are you sure you want to delete the selected RML?"))
{
- IsFree = false;
-
using (_notification.PushTaskItem("Removing RML..."))
{
try
{
+ IsFree = false;
+
var rml_jobs = await _rmls_context.Jobs.Where(x => x.RmlGuid == SelectedRML.Guid).Include(x => x.Machine).OrderBy(x => x.Machine.SerialNumber).ToListAsync();
if (rml_jobs.Count > 0)
{
- _notification.ShowError($"The following jobs must be removed or change thread type before the selected thread can be deleted:\n{String.Join("\n", rml_jobs.Select(x => $"{x.Machine.SerialNumber} => {x.Name}"))}");
- return;
+ var vm = new RmlDeleteDialogViewVM(SelectedRML, Rmls.ToList(), rml_jobs.ToList());
+ _notification.ShowModalDialog<RmlDeleteDialogViewVM, RmlDeleteDialogView>(vm, (x) => { }, () => { });
+
+ if (!vm.DialogResult)
+ {
+ return;
+ }
+
+ //Perform actions...
+ using (var db = ObservablesContext.CreateDefault())
+ {
+ foreach (var jobAction in vm.JobsActions)
+ {
+ if (jobAction.Action == RmlDeleteDialogViewVM.RmlDeleteJobAction.Delete)
+ {
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.JobDeleted, _authentication.CurrentUser.Guid, jobAction.Job.Name, jobAction.Job.Guid, $"Job deleted due to RML '{SelectedRML.Name}' being removed.");
+ await jobAction.Job.DeleteCascadeAsync(db);
+ }
+ else if (jobAction.Action == RmlDeleteDialogViewVM.RmlDeleteJobAction.Change)
+ {
+ var job = await db.Jobs.SingleOrDefaultAsync(x => x.Guid == jobAction.Job.Guid);
+ job.RmlGuid = jobAction.TargetRml.Guid;
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.JobSaved, _authentication.CurrentUser.Guid, jobAction.Job.Name, jobAction.Job.Guid, $"Job RML changed to '{jobAction.TargetRml.Name}' due to RML '{SelectedRML.Name}' being removed.");
+ }
+ }
+
+ await db.SaveChangesAsync();
+ }
}
await SelectedRML.DeleteCascadeAsync(_rmls_context);
-
_actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlDeleted, _authentication.CurrentUser, SelectedRML.Name, SelectedRML, "RML deleted from Machine Studio.");
LoadRmls();
}
catch (Exception ex)
{
- LogManager.Log(ex, $"Error removing selected RML {SelectedRML.Name}.");
- _notification.ShowError($"An error occurred while trying to remove the selected RML.\n{ex.Message}");
+ LogManager.Log(ex, $"Error removing selected RML {SelectedRML?.Name}.");
+ _notification.ShowError($"An error occurred while trying to remove the selected RML.\n{ex.FlattenMessage()}");
+ LoadRmls();
+ }
+ finally
+ {
+ IsFree = true;
}
}
-
- IsFree = true;
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RmlDeleteDialogViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RmlDeleteDialogViewVM.cs
new file mode 100644
index 000000000..b4c6c6274
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/RmlDeleteDialogViewVM.cs
@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.Core;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.RML.ViewModels
+{
+ public class RmlDeleteDialogViewVM : DialogViewVM
+ {
+ public enum RmlDeleteJobAction
+ {
+ Delete,
+ Change
+ }
+
+ public class RmlDeleteJob : ExtendedObject
+ {
+ public Job Job { get; set; }
+ public Machine Machine { get; set; }
+ private RmlDeleteJobAction _action;
+
+ public RmlDeleteJobAction Action
+ {
+ get { return _action; }
+ set { _action = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(IsDelete)); }
+ }
+
+ public bool IsDelete
+ {
+ get { return Action == RmlDeleteJobAction.Delete; }
+ }
+
+
+ public Rml TargetRml { get; set; }
+
+ public override string ToString()
+ {
+ return $"{Machine.SerialNumber} => {Job.Name} => {Action} {(Action == RmlDeleteJobAction.Change ? $" => {TargetRml.Name}" : String.Empty)}";
+ }
+ }
+
+ private List<Job> _jobsToDelete;
+
+ private List<RmlDeleteJob> _jobsActions;
+ public List<RmlDeleteJob> JobsActions
+ {
+ get { return _jobsActions; }
+ set { _jobsActions = value; RaisePropertyChangedAuto(); }
+ }
+
+ public Rml Rml { get; set; }
+
+ public List<Rml> Rmls { get; set; }
+
+ public List<RmlDeleteJobAction> Actions { get; set; }
+
+ public RmlDeleteDialogViewVM(Rml rml, List<Rml> rmls, List<Job> jobsToDelete)
+ {
+ Rml = rml;
+ Rmls = rmls.Where(x => x.Guid != rml.Guid).ToList();
+ _jobsToDelete = jobsToDelete;
+ JobsActions = new List<RmlDeleteJob>();
+
+ Actions = new List<RmlDeleteJobAction>()
+ {
+ RmlDeleteJobAction.Delete,
+ RmlDeleteJobAction.Change
+ };
+ }
+
+ public override void OnShow()
+ {
+ base.OnShow();
+
+ List<RmlDeleteJob> list = new List<RmlDeleteJob>();
+
+ foreach (var job in _jobsToDelete)
+ {
+ RmlDeleteJob deleteJob = new RmlDeleteJob();
+ deleteJob.Job = job;
+ deleteJob.Action = RmlDeleteJobAction.Delete;
+ deleteJob.Machine = job.Machine;
+ deleteJob.TargetRml = Rmls.FirstOrDefault(x => x.Guid != Rml.Guid);
+
+ list.Add(deleteJob);
+ }
+
+ JobsActions = list;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml
new file mode 100644
index 000000000..7745848c1
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml
@@ -0,0 +1,82 @@
+<UserControl x:Class="Tango.MachineStudio.RML.Views.RmlDeleteDialogView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+ xmlns:vm="clr-namespace:Tango.MachineStudio.RML.ViewModels"
+ xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI"
+ xmlns:local="clr-namespace:Tango.MachineStudio.RML.Views"
+ mc:Ignorable="d"
+ d:DesignHeight="400" d:DesignWidth="700" Height="600" Width="900" Background="{StaticResource Dialog.Background}" d:DataContext="{d:DesignInstance Type=vm:RmlDeleteDialogViewVM, IsDesignTimeCreatable=False}" Foreground="{StaticResource Dialog.Foreground}">
+
+ <UserControl.Resources>
+ <converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter" />
+ </UserControl.Resources>
+
+ <Grid Margin="10">
+ <DockPanel>
+ <Grid DockPanel.Dock="Top">
+ <StackPanel Orientation="Horizontal">
+ <Grid>
+ <materialDesign:PackIcon Kind="Alert" Foreground="{StaticResource OrangeBrush}" Width="42" Height="42" />
+ </Grid>
+ <TextBlock Margin="20 0 0 0" VerticalAlignment="Center" FontSize="22">
+ <Run>DELETE</Run>
+ <Run></Run>
+ <Run Text="{Binding Rml.Name}"></Run>
+ </TextBlock>
+ </StackPanel>
+ </Grid>
+
+ <Grid DockPanel.Dock="Bottom">
+ <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right" DockPanel.Dock="Bottom">
+ <Button Command="{Binding CloseCommand}" Width="140" Height="40" Margin="0 0 10 0">
+ CANCEL
+ </Button>
+ <Button Command="{Binding OKCommand}" IsDefault="True" Width="140" Height="40">
+ DELETE
+ </Button>
+ </StackPanel>
+ </Grid>
+
+ <Grid>
+ <DockPanel Margin="0 10 0 0">
+ <TextBlock DockPanel.Dock="Top" Margin="5">
+ <Run>The following jobs must be removed or change thread type before the selected thread can be deleted.</Run>
+ </TextBlock>
+ <DataGrid Margin="0 10 0 10" SelectionUnit="FullRow" SelectionMode="Single" ItemsSource="{Binding JobsActions}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False">
+ <DataGrid.Columns>
+ <DataGridTextColumn Header="MACHINE" Width="Auto" Binding="{Binding Machine.SerialNumber}" IsReadOnly="True" />
+ <DataGridTextColumn Header="JOB" Width="200" Binding="{Binding Job.Name}" IsReadOnly="True" />
+ <DataGridComboBoxColumn Header="ACTION" Width="100" SelectedItemBinding="{Binding Action}">
+ <DataGridComboBoxColumn.ElementStyle>
+ <Style TargetType="{x:Type ComboBox}">
+ <Setter Property="ItemsSource" Value="{Binding Path=DataContext.Actions, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
+ </Style>
+ </DataGridComboBoxColumn.ElementStyle>
+ <DataGridComboBoxColumn.EditingElementStyle>
+ <Style TargetType="{x:Type ComboBox}">
+ <Setter Property="ItemsSource" Value="{Binding Path=DataContext.Actions, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
+ </Style>
+ </DataGridComboBoxColumn.EditingElementStyle>
+ </DataGridComboBoxColumn>
+ <DataGridComboBoxColumn Header="TARGET RML" SelectedItemBinding="{Binding TargetRml}" Width="1*" DisplayMemberPath="Name">
+ <DataGridComboBoxColumn.ElementStyle>
+ <Style TargetType="{x:Type ComboBox}">
+ <Setter Property="ItemsSource" Value="{Binding Path=DataContext.Rmls, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
+ </Style>
+ </DataGridComboBoxColumn.ElementStyle>
+ <DataGridComboBoxColumn.EditingElementStyle>
+ <Style TargetType="{x:Type ComboBox}">
+ <Setter Property="ItemsSource" Value="{Binding Path=DataContext.Rmls, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
+ </Style>
+ </DataGridComboBoxColumn.EditingElementStyle>
+ </DataGridComboBoxColumn>
+ </DataGrid.Columns>
+ </DataGrid>
+ </DockPanel>
+ </Grid>
+ </DockPanel>
+ </Grid>
+</UserControl>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.xaml.cs
new file mode 100644
index 000000000..96254c03a
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlDeleteDialogView.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.MachineStudio.RML.Views
+{
+ /// <summary>
+ /// Interaction logic for RmlDeleteDialogView.xaml
+ /// </summary>
+ public partial class RmlDeleteDialogView : UserControl
+ {
+ public RmlDeleteDialogView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml
index 7c7194554..777af7c52 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml
@@ -18,7 +18,7 @@
<converters:ColorToIntegerConverter x:Key="ColorToIntegerConverter"></converters:ColorToIntegerConverter>
</UserControl.Resources>
- <Grid>
+ <Grid IsEnabled="{Binding IsFree}">
<DockPanel Margin="100 100 100 50" MaxWidth="1200">
<Grid DockPanel.Dock="Top">
<Image Source="../Images/threads.png" Width="300" Margin="10" />