aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-10-07 15:41:33 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-10-07 15:41:33 +0300
commitbdfe1503bafb8634d29f7229a8b5378d472ac540 (patch)
treec9c36e94bca4d93202ada0f25830972e7d856dd1 /Software/Visual_Studio/MachineStudio
parente32bafa30d3b5bf083851196b0c9b94202628a6c (diff)
downloadTango-bdfe1503bafb8634d29f7229a8b5378d472ac540.tar.gz
Tango-bdfe1503bafb8634d29f7229a8b5378d472ac540.zip
Completed RML Module !!!!!!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs116
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml7
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml44
3 files changed, 147 insertions, 20 deletions
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 9e8286fa5..70073ad62 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
@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Win32;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -8,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Data;
using Tango.BL;
using Tango.BL.Builders;
+using Tango.BL.Calibration;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.MachineStudio.ColorLab.ViewModels;
@@ -15,6 +17,7 @@ using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.RML.Contracts;
using Tango.MachineStudio.RML.Views;
+using Tango.PMR.ColorLab;
namespace Tango.MachineStudio.RML.ViewModels
{
@@ -154,18 +157,21 @@ namespace Tango.MachineStudio.RML.ViewModels
/// </summary>
public RelayCommand BackToRmlsCommand { get; set; }
+ public RelayCommand SaveCommand { get; set; }
+
public MainViewVM(INotificationProvider notificationProvider)
{
_notification = notificationProvider;
ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null);
RemoveRmlCommand = new RelayCommand(RemoveSelectedRml);
AddRmlCommand = new RelayCommand(AddNewRml);
- BackToRmlsCommand = new RelayCommand(BackToRmls);
- AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable);
- RemoveProcessParametersTableCommand = new RelayCommand<ProcessParametersTable>(RemoveProcessParametersTable);
- AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor);
- RemoveLiquidFactorCommand = new RelayCommand<LiquidTypesRml>(RemoveLiquidFactor);
+ BackToRmlsCommand = new RelayCommand(BackToRmls, () => IsFree);
+ AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable, () => IsFree);
+ RemoveProcessParametersTableCommand = new RelayCommand<ProcessParametersTable>(RemoveProcessParametersTable, () => IsFree);
+ AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor, () => IsFree);
+ RemoveLiquidFactorCommand = new RelayCommand<LiquidTypesRml>(RemoveLiquidFactor, () => IsFree);
CreateCalibrationDataExcelTemplateCommand = new RelayCommand(CreateCalibrationDataExcelTemplate);
+ SaveCommand = new RelayCommand(Save, () => IsFree);
}
public override void OnApplicationReady()
@@ -175,13 +181,10 @@ namespace Tango.MachineStudio.RML.ViewModels
private async void LoadRmls()
{
- using (_rmls_context = ObservablesContext.CreateDefault())
- {
- await Task.Factory.StartNew(() =>
- {
- Rmls = _rmls_context.Rmls.ToList().ToObservableCollection();
- });
- }
+ if (_rmls_context != null) _rmls_context.Dispose();
+
+ _rmls_context = ObservablesContext.CreateDefault();
+ Rmls = await new RmlsCollectionBuilder(_rmls_context).Set().WithLiquidFactors().WithMediaProperties().BuildAsync();
}
private async void LoadActiveRML(String guid)
@@ -264,6 +267,8 @@ namespace Tango.MachineStudio.RML.ViewModels
_active_context.Dispose();
}
+ _active_context = ObservablesContext.CreateDefault();
+
LoadRmlProperties();
Rml rml = new Rml();
@@ -277,6 +282,19 @@ namespace Tango.MachineStudio.RML.ViewModels
rml.LinearMassDensityUnit = LinearMassDensityUnits.FirstOrDefault();
rml.FiberShape = FiberShapes.FirstOrDefault();
rml.FiberSynth = FiberSynths.FirstOrDefault();
+
+ ProcessParametersTablesGroup group = new ProcessParametersTablesGroup();
+ group.Name = "Active Group";
+ group.Active = true;
+ group.ProcessParametersTables.Add(new ProcessParametersTable()
+ {
+ Name = "Process Table 1",
+ });
+
+ group.Rml = rml;
+
+ _active_context.ProcessParametersTablesGroups.Add(group);
+ _active_context.ProcessParametersTables.Add(group.ProcessParametersTables[0]);
_active_context.Rmls.Add(rml);
await _active_context.SaveChangesAsync();
LoadActiveRML(rml.Guid);
@@ -286,9 +304,28 @@ namespace Tango.MachineStudio.RML.ViewModels
}
}
- private void RemoveSelectedRml()
+ private async void RemoveSelectedRml()
{
+ if (_notification.ShowQuestion("Removing the selected RML 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
+ {
+ await SelectedRML.DeleteCascadeAsync(_rmls_context);
+ 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}");
+ }
+ }
+
+ IsFree = true;
+ }
}
private void AddProcessParametersTable()
@@ -379,7 +416,56 @@ namespace Tango.MachineStudio.RML.ViewModels
private void CreateCalibrationDataExcelTemplate()
{
-
+ SaveFileDialog dlg = new SaveFileDialog();
+ try
+ {
+ dlg.Title = $"Create excel template file";
+ dlg.Filter = "Excel Files|*.xlsx";
+ dlg.DefaultExt = ".xlsx";
+ dlg.FileName = "Calibration File Template";
+ if (dlg.ShowDialog().Value)
+ {
+ CalibrationHelper.CreateCalibrationDataExcelTemplate(dlg.FileName);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error generating excel calibration template file " + dlg.FileName);
+ _notification.ShowError("An error occurred while trying to generate the calibration file.");
+ }
+ }
+
+ private async void Save()
+ {
+ IsFree = false;
+
+ try
+ {
+ using (_notification.PushTaskItem("Saving RML..."))
+ {
+ foreach (var calDataVM in CalibrationDataViewVM.LiquidsCalibrationData)
+ {
+ var liquidTypeRml = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType == calDataVM.LiquidType);
+ CalibrationData calData = new CalibrationData();
+ calData.LiquidType = (PMR.ColorLab.LiquidType)liquidTypeRml.LiquidType.Code;
+ calData.CalibrationPoints.AddRange(calDataVM.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y }));
+ liquidTypeRml.PutCalibrationData(calData);
+ }
+
+ ActiveRML.LastUpdated = DateTime.UtcNow;
+
+ await _active_context.SaveChangesAsync();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error saving RML {ActiveRML.Name}");
+ _notification.ShowError($"An error occurred while trying to save the current RML.\n{ex.Message}");
+ }
+
+ LoadActiveRML(ActiveRML.Guid);
+
+ IsFree = true;
}
private void BackToRmls()
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml
index 2ddd060f8..d72b6c7d3 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml
@@ -31,6 +31,13 @@
</Button>
<TextBlock Text="{Binding ActiveRML.Name}" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="34"></TextBlock>
</StackPanel>
+
+ <Button HorizontalAlignment="Right" Width="170" Height="45" Margin="0 0 20 0" VerticalAlignment="Center" Command="{Binding SaveCommand}">
+ <StackPanel Orientation="Horizontal">
+ <materialDesign:PackIcon Kind="ContentSaveAll" Width="24" Height="24" />
+ <TextBlock VerticalAlignment="Center" Margin="10 0 0 0">SAVE</TextBlock>
+ </StackPanel>
+ </Button>
</Grid>
<Grid DockPanel.Dock="Bottom">
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 b597c1dd2..06a28c1e4 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
@@ -4,7 +4,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:global="clr-namespace:Tango.MachineStudio.RML"
+ xmlns:observables="clr-namespace:Tango.BL.Entities;assembly=Tango.BL"
xmlns:vm="clr-namespace:Tango.MachineStudio.RML.ViewModels"
+ xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI"
xmlns:local="clr-namespace:Tango.MachineStudio.RML.Views"
@@ -13,6 +15,7 @@
<UserControl.Resources>
<converters:DateTimeUTCToShortDateTimeConverter x:Key="DateTimeUTCToShortDateTimeConverter" />
+ <converters:ColorToIntegerConverter x:Key="ColorToIntegerConverter"></converters:ColorToIntegerConverter>
</UserControl.Resources>
<Grid>
@@ -38,8 +41,8 @@
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Margin="50 0 0 0" MinWidth="200" Height="60" Command="{Binding ManageRmlCommand}">
<StackPanel Orientation="Horizontal">
- <TextBlock FontSize="18" VerticalAlignment="Center">MANAGE</TextBlock>
- <materialDesign:PackIcon Margin="5 0 0 0" Kind="ChevronRight" Width="30" Height="30" />
+ <materialDesign:PackIcon Kind="Pencil" Width="24" Height="24" />
+ <TextBlock Margin="10 0 0 0" FontSize="18">EDIT</TextBlock>
</StackPanel>
</Button>
</StackPanel>
@@ -54,9 +57,40 @@
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
- <DataGridTextColumn Header="NAME" Binding="{Binding Name}" Width="1*" />
- <DataGridTextColumn Header="LAST UPDATED" Binding="{Binding LastUpdated,Converter={StaticResource DateTimeUTCToShortDateTimeConverter}}" Width="1*" />
- <DataGridTextColumn Header="MANUFACTURER" Binding="{Binding Manufacturer}" Width="1*" />
+ <DataGridTextColumn Header="NAME" Binding="{Binding Name}" Width="Auto" />
+ <DataGridTextColumn Header="MANUFACTURER" Binding="{Binding Manufacturer}" Width="Auto" />
+ <DataGridTextColumn Header="MATERIAL" Binding="{Binding MediaMaterial.Name}" Width="Auto" />
+ <DataGridTextColumn Header="PURPOSE" Binding="{Binding MediaPurpose.Name}" Width="Auto" />
+ <DataGridTextColumn Header="LAST UPDATED" Binding="{Binding LastUpdated,Converter={StaticResource DateTimeUTCToShortDateTimeConverter}}" Width="Auto" />
+ <DataGridTemplateColumn Header="LIQUID FACTORS" Width="1*">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <ItemsControl ItemsSource="{Binding LiquidTypesRmls}" Margin="0 10 0 0">
+ <ItemsControl.ItemsPanel>
+ <ItemsPanelTemplate>
+ <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" IsItemsHost="True"></StackPanel>
+ </ItemsPanelTemplate>
+ </ItemsControl.ItemsPanel>
+ <ItemsControl.ItemTemplate>
+ <DataTemplate DataType="{x:Type observables:LiquidTypesRml}">
+ <Grid Width="47" Height="40" Margin="10 -10 0 0">
+ <shapes:Hexagon StrokeThickness="1" Stroke="Gray">
+ <shapes:Hexagon.Fill>
+ <LinearGradientBrush Opacity="0.7" >
+ <GradientStop Color="{Binding LiquidType.Color,Converter={StaticResource ColorToIntegerConverter}}"/>
+ <GradientStop Color="White" Offset="1"/>
+ </LinearGradientBrush>
+ </shapes:Hexagon.Fill>
+ </shapes:Hexagon>
+
+ <TextBlock FontSize="8" Width="40" TextTrimming="CharacterEllipsis" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent" Foreground="Black" Text="{Binding LiquidType.Name}" FontStyle="Italic"></TextBlock>
+ </Grid>
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>