diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-10-11 10:26:41 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-10-11 10:26:41 +0300 |
| commit | 37293ed1bf4ca876d9b90a20cfd3e4ead8f4bbf9 (patch) | |
| tree | db6a793c1b43215cc9ddbb092b9d33f6781c9e5e /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML | |
| parent | b1c89925cd6e6da9666c7897f056634bf964dcb3 (diff) | |
| parent | 469ba6f2c0fdeeb942578084c3c6c1d76d040c2d (diff) | |
| download | Tango-37293ed1bf4ca876d9b90a20cfd3e4ead8f4bbf9.tar.gz Tango-37293ed1bf4ca876d9b90a20cfd3e4ead8f4bbf9.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML')
7 files changed, 182 insertions, 41 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config index bd3d48f6d..24aec371a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config @@ -41,6 +41,14 @@ <assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> </assemblyBinding> </runtime> </configuration>
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/RMLModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/RMLModule.cs index fdd8cb124..7d5882907 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/RMLModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/RMLModule.cs @@ -51,7 +51,7 @@ namespace Tango.MachineStudio.ColorLab { get { - return Permissions.RunColorLabModule; + return Permissions.RunRMLModule; } } 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 b9d77e95a..64501b4fc 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 @@ -8,7 +8,7 @@ <OutputType>library</OutputType> <RootNamespace>Tango.MachineStudio.RML</RootNamespace> <AssemblyName>Tango.MachineStudio.RML</AssemblyName> - <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <WarningLevel>4</WarningLevel> 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 be46e2148..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) @@ -210,15 +213,12 @@ namespace Tango.MachineStudio.RML.ViewModels ActiveProcessParametersTableView = CollectionViewSource.GetDefaultView(ActiveProcessParametersGroup.ProcessParametersTables); ActiveProcessParametersTableView.SortDescriptions.Add(new SortDescription(nameof(ProcessParametersTable.TableIndex), ListSortDirection.Ascending)); - CalibrationDataViewVM = new CalibrationDataViewVM(); + CalibrationDataViewVM = new CalibrationDataViewVM(_notification); LiquidTypesRmls = ActiveRML.LiquidTypesRmls; foreach (var liquidTypeRml in LiquidTypesRmls) { - CalibrationDataVM catVM = new CalibrationDataVM(); - catVM.Name = liquidTypeRml.LiquidType.Name; - catVM.Color = liquidTypeRml.LiquidType.Color; - catVM.LiquidType = liquidTypeRml.LiquidType; + CalibrationDataVM catVM = new CalibrationDataVM(liquidTypeRml.LiquidType); if (liquidTypeRml.DefaultCatData != null) { @@ -267,6 +267,8 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context.Dispose(); } + _active_context = ObservablesContext.CreateDefault(); + LoadRmlProperties(); Rml rml = new Rml(); @@ -280,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); @@ -289,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() @@ -359,9 +393,7 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context.LiquidTypesRmls.Add(liquidFactor); - CalibrationDataVM catVM = new CalibrationDataVM(); - catVM.Name = liquidFactor.LiquidType.Name; - catVM.Color = liquidFactor.LiquidType.Color; + CalibrationDataVM catVM = new CalibrationDataVM(liquidFactor.LiquidType); CalibrationDataViewVM.LiquidsCalibrationData.Add(catVM); @@ -384,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 aa6f39d9e..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"> @@ -196,7 +203,7 @@ </ItemsControl> </StackPanel> - <dragAndDrop:DraggingSurface x:Name="draggingSurface" /> + <dragAndDrop:DraggingSurface x:Name="draggingSurface" ClipToBounds="True" /> </Grid> </DockPanel> </Grid> @@ -206,7 +213,6 @@ <DockPanel> - <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="120"/> @@ -226,7 +232,9 @@ </Button> </Grid> </Border> - <ItemsControl ItemsSource="{Binding LiquidTypesRmls}" Margin="0 10 0 0"> + + <ScrollViewer x:Name="liquidsFactorsScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" Margin="15 0 20 0"> + <ItemsControl Width="{Binding ElementName=calibrationDataView,Path=ActualWidth}" ItemsSource="{Binding LiquidTypesRmls}" Margin="0 10 0 0"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid IsItemsHost="True" Rows="1"></UniformGrid> @@ -259,7 +267,8 @@ </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> - </DockPanel> + </ScrollViewer> + </DockPanel> </Grid> <Grid Grid.Row="2"> @@ -270,18 +279,22 @@ <DropShadowEffect Opacity="0.4" /> </Border.Effect> <Grid> - <TextBlock HorizontalAlignment="Left" Margin="20 0 0 0" FontSize="16">CALIBRATION DATA</TextBlock> - <Button ToolTip="Create excel file template" HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}" Height="Auto" VerticalAlignment="Bottom" Width="30" Padding="0" Command="{Binding CreateCalibrationDataExcelTemplateCommand}"> - <materialDesign:PackIcon Kind="FileExcel" Foreground="DimGray" Width="16" Height="20" /> - </Button> + <TextBlock HorizontalAlignment="Left" Margin="20 0 0 0" FontSize="16">CALIBRATION DATA</TextBlock> + <Button ToolTip="Create excel file template" FontSize="11" Foreground="#202020" HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}" Height="Auto" VerticalAlignment="Bottom" Padding="0" Command="{Binding CreateCalibrationDataExcelTemplateCommand}" Margin="0 0 5 0"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="FileExcel" Foreground="DimGray" Width="16" Height="26" /> + <TextBlock VerticalAlignment="Center" Margin="5 0 0 0">Create Empty Excel Template</TextBlock> + </StackPanel> + </Button> </Grid> </Border> - <colorLabViews:CalibrationDataView Margin="0 10 0 0" DataContext="{Binding CalibrationDataViewVM}" /> - </DockPanel> + <ScrollViewer x:Name="calibrationDataScrollViewer" ScrollChanged="calibrationDataScrollViewer_ScrollChanged" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto" Margin="15 0 20 0"> + <colorLabViews:CalibrationDataView x:Name="calibrationDataView" Margin="0 10 0 0" DataContext="{Binding CalibrationDataViewVM}" /> + </ScrollViewer> + </DockPanel> </Grid> </Grid> - </ScrollViewer> </DockPanel> </Grid> </Grid> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs index c1bc9ad4a..2a5d317c6 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml.cs @@ -47,5 +47,10 @@ namespace Tango.MachineStudio.RML.Views ProcessParametersTable dropped = e.Droppable.DataContext as ProcessParametersTable; _vm.OnProcessParametersTableDropped(dragged, dropped); } + + private void calibrationDataScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) + { + liquidsFactorsScrollViewer.ScrollToHorizontalOffset(e.HorizontalOffset); + } } } 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> |
