diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-03 12:36:24 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-03 12:36:24 +0300 |
| commit | f2a27972ca652ef568e5eede22d86f9698a08cca (patch) | |
| tree | 6c55d21cba6bfa8587d95fd27e17a5ec423b3b0d /Software/Visual_Studio/Utilities | |
| parent | bd1221e36ee3e493dc25bd32559f846519fe60d0 (diff) | |
| parent | 05fc7b1f37ecc809acf65422a799a4d761b78acb (diff) | |
| download | Tango-f2a27972ca652ef568e5eede22d86f9698a08cca.tar.gz Tango-f2a27972ca652ef568e5eede22d86f9698a08cca.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Utilities')
14 files changed, 446 insertions, 61 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs index 2d4775a37..58c5dfedf 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs @@ -11,6 +11,9 @@ using System.Linq.Expressions; using System.Diagnostics; using OxyPlot; using System.Collections.ObjectModel; +using Tango.Documents; +using System.IO; +using Tango.Core.Helpers; namespace Tango.DispenserAnalyzer.UI.Analyzers { @@ -38,7 +41,7 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers if (index % 2 == 1)//testing Flow-error { - List<DispenserSample> filteredValues = rangeTestValues.Skip(1800).ToList(); + List<DispenserSample> filteredValues = rangeTestValues.Skip((int)Settings.GetValueByName(AnalyzerSettingsEnum.ExcludeAnalysis)).ToList(); //Move Average data List<Task> tasks = new List<Task>(); @@ -57,11 +60,12 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers Task.WaitAll(tasks.ToArray()); //calculate difference Max Min values for each 300 values - int periodCalcMaxMin = 500; + int periodCalcMaxMin = (int)Settings.GetValueByName(AnalyzerSettingsEnum.MaxMinRange); + int intervalCalcMaxMin = (int)Settings.GetValueByName(AnalyzerSettingsEnum.MaxMinIntervals); List<int> differenceMaxMin = new List<int>(); List<int> differenceMaxMinToLocationArr = new List<int>(); int location_index = 0; - for (int i = 0; i < (filteredValues.Count - periodCalcMaxMin); i+= 300) + for (int i = 0; i < (filteredValues.Count - periodCalcMaxMin); i+= intervalCalcMaxMin) { var rangeItems =(filteredValues.Skip(i).Take(periodCalcMaxMin).ToList()); int range = (int)(rangeItems.Max(t => t.Pressure) - rangeItems.Min(t => t.Pressure)); @@ -71,7 +75,7 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers } FlowAverageAnalyzerResult averageResult = new FlowAverageAnalyzerResult(); averageResult.AverageValue = filteredValues.Average(t => t.Pressure); - averageResult.Result = (averageResult.AverageValue <= 1850 && averageResult.AverageValue >= 1400) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; + averageResult.Result = (averageResult.AverageValue <= Settings.GetValueByName(AnalyzerSettingsEnum.AvgMaxValue) && averageResult.AverageValue >= Settings.GetValueByName(AnalyzerSettingsEnum.AvgMinValue)) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; results.Add(averageResult); FlowAnalyzerResult result = new FlowAnalyzerResult(++flowtestNumber); @@ -85,8 +89,8 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers int avgMinIndex = rangeTestValues.Select(x => x.Index).Min(); int avgMaxIndex = rangeTestValues.Select(x => x.Index).Max(); double totalsec = TimeSpan.FromMilliseconds((avgMaxIndex - avgMinIndex) * 100).TotalSeconds; - result.Time = totalsec.ToString() + " sec (succeed for period < 4.5)"; ; - result.Result = (totalsec < 4.5) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; + result.Time = totalsec.ToString() + $" sec (succeed for period < {AnalyzerSettingsEnum.FlowPBUPassFail})"; ; + result.Result = (totalsec < Settings.GetValueByName(AnalyzerSettingsEnum.FlowPBUPassFail)) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; results.Add(result); } } @@ -155,12 +159,17 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers } RangeToTimeChart.Title = $"Flow Time Location To Range {TestNumber}"; RangeToTimeChart.UpdateData(); + string filename = FileHelper.GetFileToSaveFlowRangeToTimeData(TestNumber); + if(filename.IsNotNullOrEmpty() && rangeToTimePoints.Count > 0) + { + ExportnDataToExcel(rangeToTimePoints.ToList(), filename); + } } private double BuildMeasurementError(List<int> range_values) { int count = range_values.Count(); - return (count - (count * 0.99)); + return (count - (int)Settings.GetValueByName(AnalyzerSettingsEnum.TakeOffMaxMin)); } /// <summary> @@ -187,11 +196,48 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers break; } } - //Result = (range <= 25 && range >= 20) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; + var res = range / AverageValue * 100; - Result = res <= 1.5 ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; + Result = res <= Settings.GetValueByName(AnalyzerSettingsEnum.MaxError) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; return max_key; } + + /// <summary> + /// Exports the calibration data to excel. + /// </summary> + /// <param name="calibrationPoints">The calibration points.</param> + /// <param name="fileName">Name of the file.</param> + public static void ExportnDataToExcel(List<DataPoint> dataPoints, String fileName) + { + try + { + CreateDataExcelTemplate(fileName); + + using (ExcelWriter writer = new ExcelWriter(fileName)) + { + writer.WriteData(dataPoints, "RangeToTimeData"); + } + } + catch (Exception ex) + { + Debug.WriteLine("Error: ", ex.Message); + } + } + + /// <summary> + /// Creates the calibration data excel template. + /// </summary> + /// <param name="fileName">Name of the file.</param> + public static void CreateDataExcelTemplate(String fileName) + { + var stream = EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.DispenserAnalyzer.UI.Models.FlowRangeToTimeResults.xlsx"); + + using (FileStream fs = new FileStream(fileName, FileMode.Create)) + { + stream.Seek(0, SeekOrigin.Begin); + stream.CopyTo(fs); + } + } } public class MovingAverageFilter diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs index edc89f030..c4c5f6c65 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs @@ -29,7 +29,7 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers int avgMaxIndex = rangeTestValues.Select(x => x.Index).Max(); double totalsec = TimeSpan.FromMilliseconds((avgMaxIndex - avgMinIndex) * 100).TotalSeconds; result.Time = totalsec.ToString() + " sec"; - result.Result = (totalsec <= 12 && totalsec >= 7) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; + result.Result = (totalsec < Settings.GetValueByName(AnalyzerSettingsEnum.PBUPassFail)) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; results.Add(result); } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml index 73d8ea48c..8969f50af 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Tango.DispenserAnalyzer.UI" - StartupUri="MainWindow.xaml"> + Startup="Application_Startup"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml.cs index 6250d17a1..c1876d806 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml.cs @@ -13,5 +13,12 @@ namespace Tango.DispenserAnalyzer.UI /// </summary> public partial class App : Application { + private void Application_Startup(object sender, StartupEventArgs e) + { + MainWindow wnd = new MainWindow(); + if (e.Args.Length >= 1) + wnd.SetOpenFileFromArgument(e.Args[0]); + wnd.Show(); + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/FileHelper.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/FileHelper.cs new file mode 100644 index 000000000..7172a4ff1 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/FileHelper.cs @@ -0,0 +1,44 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI +{ + public static class FileHelper + { + private const string FILE_EXTENSION = ".pdf"; + private const string FILE_EXEL_EXTENSION = ".xlsx"; + + public static string OpenFilePath{ get; set; } + + public static string GetResultFilePath() + { + if (File.Exists(OpenFilePath)) + { + var ext = Path.GetExtension(OpenFilePath); + var dir = Path.GetDirectoryName(OpenFilePath); + var resultFile = Path.Combine(dir, string.Format("{0}-result{1}", Path.GetFileNameWithoutExtension(OpenFilePath), FILE_EXTENSION)); + return resultFile; + } + return ""; + } + + public static string GetFileToSaveFlowRangeToTimeData( int extNumber) + { + if (File.Exists(OpenFilePath)) + { + var ext = Path.GetExtension(OpenFilePath); + var dir = Path.GetDirectoryName(OpenFilePath); + var resultFile = Path.Combine(dir, string.Format("{0}_rangeToTime{1}{2}", Path.GetFileNameWithoutExtension(OpenFilePath), extNumber.ToString(), FILE_EXEL_EXTENSION)); + return resultFile; + } + return ""; + } + + + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs index 9797d203b..43a573a7d 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs @@ -48,6 +48,15 @@ namespace Tango.DispenserAnalyzer.UI ax.Maximum = ax.Minimum = Double.NaN; } + public void SetOpenFileFromArgument( string openFilePath) + { + if(_vm != null) + { + _vm.OpenFilePath = openFilePath; + _vm.Generate(); + } + } + private void TextBlock_PreviewDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/FlowRangeToTimeResults.xlsx b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/FlowRangeToTimeResults.xlsx Binary files differnew file mode 100644 index 000000000..5f0e4b651 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/FlowRangeToTimeResults.xlsx diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/SettingsModel.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/SettingsModel.cs index 0d9e20288..5540e4b25 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/SettingsModel.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/SettingsModel.cs @@ -4,11 +4,24 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; +using Tango.Core.Commands; namespace Tango.DispenserAnalyzer.UI.Models -{ - public class SettingsModel: ExtendedObject +{ + public interface ISettingsModel { + string PropertyName { get; set; } + double PropertyValue { get; set; } + double DefaultValue { get; set; } + string DefaultValueDisplay { get; set; } + double MinRangeValue { get; set; } + double MaxRangeValue { get; set; } + bool IsRangeVisible { get; set; } + } + + public class SettingsModel: ExtendedObject, ISettingsModel + { + public AnalyzerSettingsEnum _enumName; private string _propertyName; public string PropertyName @@ -22,7 +35,23 @@ namespace Tango.DispenserAnalyzer.UI.Models public double PropertyValue { get { return _propertyvalue; } - set { _propertyvalue = value; RaisePropertyChangedAuto(); } + set { + if( _propertyvalue != value) + { + _propertyvalue = value; + RaisePropertyChangedAuto(); + OnPropertyvalueChanged(); + } + } + } + + private void OnPropertyvalueChanged() + { + if(SettingValueEvent != null) + { + SettingValueEvent?.Invoke(this, new EventArgs()); + } + } private double _defaultValue; @@ -41,12 +70,78 @@ namespace Tango.DispenserAnalyzer.UI.Models set { _defaultValueDisplay = value; } } + private double _minDefaultRangeValue; + public double MinDefaultRangeValue + { + get { return _minDefaultRangeValue; } + set { _minDefaultRangeValue = value; RaisePropertyChangedAuto(); } + } + + private double _maxDefaultRangeValue; + public double MaxDefaultRangeValue + { + get { return _maxDefaultRangeValue; } + set { _maxDefaultRangeValue = value; RaisePropertyChangedAuto(); } + } + + private double _minRangeValue; + public double MinRangeValue + { + get { return _minRangeValue; } + set { + if (_minRangeValue != value) + { + _minRangeValue = value; + RaisePropertyChangedAuto(); + OnPropertyvalueChanged(); + } + } + } - public SettingsModel( string propertyName, string defaultValueDisplay, double defaultValue) + private double _maxRangeValue; + public double MaxRangeValue { - PropertyName = propertyName; + get { return _maxRangeValue; } + set { + if (_maxRangeValue != value) + { + _maxRangeValue = value; + RaisePropertyChangedAuto(); + OnPropertyvalueChanged(); + } + } + } + public bool IsRangeVisible { get; set; } + + public event EventHandler SettingValueEvent; + + public RelayCommand SetDefaultCommand { get; set; } + + + public SettingsModel(AnalyzerSettingsEnum enumName, string defaultValueDisplay, bool isrange = false) + { + _enumName = enumName; + PropertyName = _enumName.ToDescription(); DefaultValueDisplay = defaultValueDisplay; - DefaultValue = defaultValue; + DefaultValue = Settings.GetDefaultValueByName(enumName); + PropertyValue = Settings.GetValueByName(enumName); + IsRangeVisible = isrange; + MinDefaultRangeValue = IsRangeVisible ? Settings.GetDefaultValueByName(AnalyzerSettingsEnum.AvgMinValue) : 0.0; + MaxDefaultRangeValue = IsRangeVisible ? Settings.GetDefaultValueByName(AnalyzerSettingsEnum.AvgMaxValue) : 0.0; + MinRangeValue = IsRangeVisible? Settings.GetValueByName(AnalyzerSettingsEnum.AvgMinValue) : 0.0; + MaxRangeValue = IsRangeVisible? Settings.GetValueByName(AnalyzerSettingsEnum.AvgMaxValue) : 0.0; + SetDefaultCommand = new RelayCommand(SetDefault); + } + + private void SetDefault() + { + if(IsRangeVisible) + { + MinRangeValue = MinDefaultRangeValue; + MaxRangeValue = MaxDefaultRangeValue; + return; + } + PropertyValue = DefaultValue; } } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs new file mode 100644 index 000000000..9a1f10aed --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI +{ + public enum AnalyzerSettingsEnum + { + //Undetermined + [Description("PBU Pass fail")] + PBUPassFail, + [Description("PBU Pass fail")] + FlowPBUPassFail, + [Description("Exclude from analysis")] + ExcludeAnalysis, + [Description("Avg value")] + AvgMaxValue, + [Description("Avg value")] + AvgMinValue, + [Description("Max-Min range")] + MaxMinRange, + [Description("Max Min intervals")] + MaxMinIntervals, + [Description("Max error")] + MaxError, + [Description("Take off 'Max-min' values(out of highest results)")] + TakeOffMaxMin, + + } + + public static class Settings + { + public static Dictionary<AnalyzerSettingsEnum, double> DefaultValues { get; set; } + public static Dictionary<AnalyzerSettingsEnum, double> CurrentValues { get; set; } + + static Settings() + { + DefaultValues = new Dictionary<AnalyzerSettingsEnum, double>(); + + DefaultValues[AnalyzerSettingsEnum.PBUPassFail] = 4.5; + DefaultValues[AnalyzerSettingsEnum.FlowPBUPassFail] = 4.5; + DefaultValues[AnalyzerSettingsEnum.ExcludeAnalysis] = 1800; + DefaultValues[AnalyzerSettingsEnum.AvgMinValue] = 1400; + DefaultValues[AnalyzerSettingsEnum.AvgMaxValue] = 1850; + DefaultValues[AnalyzerSettingsEnum.MaxMinRange] = 500; + DefaultValues[AnalyzerSettingsEnum.MaxMinIntervals] = 300; + DefaultValues[AnalyzerSettingsEnum.MaxError] = 1.5; + DefaultValues[AnalyzerSettingsEnum.TakeOffMaxMin] = 3; + + CurrentValues = new Dictionary<AnalyzerSettingsEnum, double>(); + CurrentValues[AnalyzerSettingsEnum.PBUPassFail] = 4.5; + CurrentValues[AnalyzerSettingsEnum.FlowPBUPassFail] = 4.5; + CurrentValues[AnalyzerSettingsEnum.ExcludeAnalysis] = 1800; + CurrentValues[AnalyzerSettingsEnum.AvgMinValue] = 1400; + CurrentValues[AnalyzerSettingsEnum.AvgMaxValue] = 1850; + CurrentValues[AnalyzerSettingsEnum.MaxMinRange] = 500; + CurrentValues[AnalyzerSettingsEnum.MaxMinIntervals] = 300; + CurrentValues[AnalyzerSettingsEnum.MaxError] = 1.5; + CurrentValues[AnalyzerSettingsEnum.TakeOffMaxMin] = 3; + } + public static double GetValueByName(AnalyzerSettingsEnum name) + { + double value; + if (CurrentValues.TryGetValue(name, out value)) + { + return value; + } + return 0.0; + } + public static void SetValueByName(AnalyzerSettingsEnum name, double value) + { + CurrentValues[name] = value; + } + public static double GetDefaultValueByName(AnalyzerSettingsEnum name) + { + double value; + if (DefaultValues.TryGetValue(name, out value)) + { + return value; + } + return 0.0; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj index 7efcaa58d..01a5a7122 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj @@ -29,8 +29,8 @@ <ProductName>Dispenser Analyser</ProductName> <PublisherName>Twine</PublisherName> <OpenBrowserOnPublish>false</OpenBrowserOnPublish> - <ApplicationRevision>4</ApplicationRevision> - <ApplicationVersion>1.2.1.%2a</ApplicationVersion> + <ApplicationRevision>2</ApplicationRevision> + <ApplicationVersion>2.1.1.%2a</ApplicationVersion> <UseApplicationTrust>true</UseApplicationTrust> <CreateDesktopShortcut>true</CreateDesktopShortcut> <PublishWizardCompleted>true</PublishWizardCompleted> @@ -140,10 +140,12 @@ <Compile Include="Analyzers\ReliabilityTestAnalyser.cs" /> <Compile Include="Analyzers\SealingAnalyzer.cs" /> <Compile Include="Analysis\AnalyzerAttribute.cs" /> + <Compile Include="FileHelper.cs" /> <Compile Include="Models\DispenserCsvRow.cs" /> <Compile Include="Models\DispenserSample.cs" /> <Compile Include="Models\DispenserSampleCommand.cs" /> <Compile Include="Models\SettingsModel.cs" /> + <Compile Include="Settings.cs" /> <Compile Include="ViewModels\MainWindowVM.cs" /> <Compile Include="ViewModels\SettingsVM.cs" /> <Compile Include="View\SettingsWnd.xaml.cs"> @@ -184,6 +186,7 @@ <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> </EmbeddedResource> + <EmbeddedResource Include="Models\FlowRangeToTimeResults.xlsx" /> <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> @@ -203,6 +206,10 @@ <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project> <Name>Tango.CSV</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.Documents\Tango.Documents.csproj"> + <Project>{ca87a608-7b17-4c98-88f2-42abee10f4c1}</Project> + <Name>Tango.Documents</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.SharedUI\Tango.SharedUI.csproj"> <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> <Name>Tango.SharedUI</Name> diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml index 9d818a05b..2bfa2bba1 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml @@ -6,7 +6,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.DispenserAnalyzer.UI.View" mc:Ignorable="d" - Title="Settings" Height="630" Width="800" FontSize="22" ResizeMode="NoResize" WindowStyle="ToolWindow"> + Title="Settings" Height="630" Width="800" FontSize="22" ResizeMode="NoResize" WindowStyle="ToolWindow" Closing="Window_Closing"> <Window.Resources> <Style TargetType="{x:Type TextBlock}" x:Key="WrapText"> <Setter Property="TextWrapping" Value="Wrap"/> @@ -71,11 +71,44 @@ <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> </Style> - <DataGrid x:Key="PropertyDataGrid" HorizontalAlignment="Left" VerticalScrollBarVisibility ="Auto" SelectionUnit="FullRow" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" + <DataGrid x:Key="PropertyDataGrid" x:Shared="False" HorizontalAlignment="Left" VerticalScrollBarVisibility ="Auto" SelectionUnit="FullRow" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding .}" GridLinesVisibility="None" SelectionMode="Single" AlternatingRowBackground="#F6F6F6" FontSize="12" > <DataGrid.Columns> <DataGridTextColumn Header="Property Name" Binding="{Binding PropertyName}" Width="150" ElementStyle="{StaticResource WrapText}"/> - <DataGridTextColumn Header="Property Value" Binding="{Binding PropertyValue}" Width="150" IsReadOnly="False"></DataGridTextColumn> + <DataGridTemplateColumn Header="Property Value" Width="150"> + <DataGridTemplateColumn.CellTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <TextBox Text="{Binding PropertyValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="50" VerticalAlignment="Top"> + <TextBox.Style> + <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource MaterialDesignTextBox}"> + <Setter Property="Visibility" Value="Visible"/> + <Style.Triggers> + <DataTrigger Binding="{Binding IsRangeVisible}" Value="true"> + <Setter Property="Visibility" Value="Collapsed"/> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBox.Style> + </TextBox> + <DockPanel HorizontalAlignment="Stretch" Width="150"> + <DockPanel.Style> + <Style TargetType="{x:Type DockPanel}"> + <Setter Property="Visibility" Value="Collapsed"/> + <Style.Triggers> + <DataTrigger Binding="{Binding IsRangeVisible}" Value="true"> + <Setter Property="Visibility" Value="Visible"/> + </DataTrigger> + </Style.Triggers> + </Style> + </DockPanel.Style> + <TextBox DockPanel.Dock="Left" Name="MinRangeValue" Width="50" Text="{Binding MinRangeValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/> + <TextBox DockPanel.Dock="Right" Name="MaxRangeValue" Width="50" Text="{Binding MaxRangeValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/> + </DockPanel> + </StackPanel> + </DataTemplate> + </DataGridTemplateColumn.CellTemplate> + </DataGridTemplateColumn> <DataGridTextColumn Header="Default Value" Binding="{Binding DefaultValueDisplay}" Width="150" ElementStyle="{StaticResource WrapText}" /> <DataGridTemplateColumn Header="" Width="1*"> <DataGridTemplateColumn.CellStyle> @@ -104,13 +137,14 @@ <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center"> - <Button Width="80" Padding="2" Height="26" FontSize="12" Margin="0 8">Set Default</Button> + <Button Width="80" Padding="2" Height="26" FontSize="12" Margin="0 8" Command="{Binding SetDefaultCommand}">Set Default</Button> </Grid> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> + </Window.Resources> @@ -124,27 +158,29 @@ </Grid.ColumnDefinitions> <Grid Grid.Row="0"> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition/> - </Grid.RowDefinitions> - <Grid Grid.Row="0" VerticalAlignment="Top"> - <Border Margin="20 20 20 0" BorderBrush="LightGray" BorderThickness="0.6" CornerRadius="4" Height="36"> - <Border.Effect> - <DropShadowEffect/> - </Border.Effect> - </Border> - <Border Margin="20 20 20 0" BorderBrush="LightGray" BorderThickness="0.6" CornerRadius="4" Height="34" Background="#C4EEFC"> - <TextBlock FontSize="22" Padding="2">Pressure build up test</TextBlock> - </Border> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="Auto"/> + </Grid.RowDefinitions> + <Grid Grid.Row="0" VerticalAlignment="Top"> + <Border Margin="20 20 20 0" BorderBrush="LightGray" BorderThickness="0.6" CornerRadius="4" Height="36"> + <Border.Effect> + <DropShadowEffect/> + </Border.Effect> + </Border> + <Border Margin="20 20 20 0" BorderBrush="LightGray" BorderThickness="0.6" CornerRadius="4" Height="34" Background="#C4EEFC"> + <TextBlock FontSize="22" Padding="2">Pressure build up test</TextBlock> + </Border> + </Grid> + <ContentControl x:Name="PBUTestControl" Grid.Row="1" Content="{StaticResource PropertyDataGrid}" DataContext="{Binding Path=PBUTestSettings}" Margin="20 0 20 0"></ContentControl> </Grid> - <ContentControl Grid.Row="1" Margin="20 3 20 0" Content="{StaticResource PropertyDataGrid}" DataContext="{Binding Path=PBUTestSettings}"></ContentControl> </Grid> <Grid Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Stretch"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> - <RowDefinition Height="1*"/> + <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid Grid.Row="0" VerticalAlignment="Top"> <Border Margin="20 20 20 0" BorderBrush="LightGray" BorderThickness="0.6" CornerRadius="4" Height="36"> @@ -156,11 +192,11 @@ <TextBlock FontSize="22" Padding="2">Flow test</TextBlock> </Border> </Grid> - <ContentControl Grid.Row="1" Content="{StaticResource PropertyDataGrid}" DataContext="{Binding Path=FlowTestSettings}" Margin="20 0 20 0"></ContentControl> + <ContentControl x:Name="FlowTestControl" Grid.Row="1" Content="{StaticResource PropertyDataGrid}" DataContext="{Binding Path=FlowTestSettings}" Margin="20 0 20 0"></ContentControl> </Grid> </Grid> <Grid Grid.Row="2" > - <Button Width="80" HorizontalAlignment="Right" Margin="20">Save</Button> + <Button Width="80" HorizontalAlignment="Right" Margin="20" Click="SaveButton_Click" IsDefault="True">Save</Button> </Grid> </Grid> </Window> diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml.cs index f0e35726e..9879d8f7a 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml.cs @@ -20,13 +20,20 @@ namespace Tango.DispenserAnalyzer.UI.View /// </summary> public partial class SettingsWnd : Window { + private SettingsVM vm; public SettingsWnd() { InitializeComponent(); - DataContext = new SettingsVM(); + vm = new SettingsVM(); + DataContext = vm; Loaded += Window_loaded; } + public Dictionary<AnalyzerSettingsEnum, double> GetChanges() + { + return vm.GetChanges(); + } + private void Window_loaded(object sender, RoutedEventArgs e) { Application curApp = Application.Current; @@ -34,5 +41,14 @@ namespace Tango.DispenserAnalyzer.UI.View this.Left = mainWindow.Left + (mainWindow.Width - this.ActualWidth) / 2; this.Top = mainWindow.Top + (mainWindow.Height - this.ActualHeight) / 2; } + + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + vm.Dispose(); + } + public void SaveButton_Click(object sender, RoutedEventArgs e) + { + this.DialogResult = true; + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs index ab571ec43..70034b6e7 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs @@ -161,16 +161,22 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels _isRunning = false; this.Points = new List<DataPoint>(); - } #region Settings - + public void OpenSettingWnd() { SettingsWnd settings = new SettingsWnd(); settings.Owner = System.Windows.Application.Current.MainWindow; - settings.ShowDialog(); + if(true == settings.ShowDialog()) + { + Dictionary<AnalyzerSettingsEnum, double> changes = settings.GetChanges(); + foreach (KeyValuePair<AnalyzerSettingsEnum, double> entry in changes) + { + Settings.SetValueByName(entry.Key, entry.Value); + } + } } #endregion @@ -220,6 +226,7 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels ResetSettings(); if(File.Exists(OpenFilePath)) { + FileHelper.OpenFilePath = OpenFilePath; FileName = Path.GetFileName(OpenFilePath); } } @@ -230,9 +237,9 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels { return (OpenFilePath!= null && OpenFilePath.Length != 0 && File.Exists(OpenFilePath)); } - private async void Generate() + public async void Generate() { - if (IsFileLocked(OpenFilePath)) + if (false == File.Exists(OpenFilePath) || IsFileLocked(OpenFilePath) ) return; ResetSettings(); @@ -328,13 +335,9 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels await Task.Delay(200); try { - if (File.Exists(OpenFilePath)) + var resultFile = FileHelper.GetResultFilePath(); + if (resultFile.IsNotNullOrEmpty()) { - var fileName = Path.GetFileNameWithoutExtension(OpenFilePath); - fileName += "_result"; - var ext = Path.GetExtension(OpenFilePath); - var dir = Path.GetDirectoryName(OpenFilePath); - var resultFile = Path.Combine(dir, string.Format("{0}-result{1}", Path.GetFileNameWithoutExtension(OpenFilePath), FILE_EXTENSION)); SaveResultsAsXps(resultFile); } } @@ -359,6 +362,8 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels int index = 0; foreach (var item in all_plots) { + var seriesdata = item.Series[0].ItemsSource; + item.RaiseEvent(new System.Windows.RoutedEventArgs(OxyPlot.Wpf.PlotView.LoadedEvent)); item.InvalidatePlot(true); if (item.IsMeasureValid && item.ActualHeight > 0) diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs index 99b6e948a..d5c54ab08 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs @@ -9,7 +9,7 @@ using Tango.SharedUI; namespace Tango.DispenserAnalyzer.UI.ViewModels { - public class SettingsVM : ViewModel + public class SettingsVM : ViewModel, IDisposable { private ObservableCollection<SettingsModel> _PBUSettings; @@ -27,28 +27,61 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels set { _flowTestSettings = value; RaisePropertyChangedAuto(); } } + private Dictionary<AnalyzerSettingsEnum, double> changedValues; + public SettingsVM() { _PBUSettings = new ObservableCollection<SettingsModel>(); InitPBUTestSettings(); _flowTestSettings = new ObservableCollection<SettingsModel>(); + changedValues = new Dictionary<AnalyzerSettingsEnum, double>(); InitFlowTestSettings(); } private void InitPBUTestSettings() { - _PBUSettings.Add(new SettingsModel("PBU Pass fail", "4.5 sec", 4.5)); + var setting = new SettingsModel(AnalyzerSettingsEnum.PBUPassFail, "4.5 sec"); + setting.SettingValueEvent += new EventHandler(OnSettingValueChanged); + _PBUSettings.Add(setting); } private void InitFlowTestSettings() { - _flowTestSettings.Add(new SettingsModel("PBU Pass fail", "4.5 sec", 4.5)); - _flowTestSettings.Add(new SettingsModel("Exclude from analysis", "1800 reads", 1800)); - _flowTestSettings.Add(new SettingsModel("Avg value", "1400-1850 [mbar]", 1400)); - _flowTestSettings.Add(new SettingsModel("Max-Min range", "500 reads", 500)); - _flowTestSettings.Add(new SettingsModel("Max Min intervals", "300 reads", 300)); - _flowTestSettings.Add(new SettingsModel("Max error", "1.5%", 1.5)); - _flowTestSettings.Add(new SettingsModel("Take off 'Max-min' values (out of highest results)", "3", 3)); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.FlowPBUPassFail, "4.5 sec")); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.ExcludeAnalysis, "1800 reads")); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.AvgMinValue, "1400-1850 [mbar]", true)); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.MaxMinRange, "500 reads")); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.MaxMinIntervals, "300 reads")); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.MaxError, "1.5%")); + _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.TakeOffMaxMin, "3")); + + _flowTestSettings.ToList().ForEach(x => x.SettingValueEvent += new EventHandler(OnSettingValueChanged)); + } + + private void OnSettingValueChanged(object sender, EventArgs e) + { + if(sender is SettingsModel) + { + SettingsModel settingModel = sender as SettingsModel; + if(settingModel.IsRangeVisible) + { + changedValues[AnalyzerSettingsEnum.AvgMinValue] = settingModel.MinRangeValue; + changedValues[AnalyzerSettingsEnum.AvgMaxValue] = settingModel.MaxRangeValue; + } + else + changedValues[settingModel._enumName] = settingModel.PropertyValue; + } + } + + public Dictionary<AnalyzerSettingsEnum, double> GetChanges() + { + return changedValues; + } + + public void Dispose() + { + _PBUSettings.ToList().ForEach(x => x.SettingValueEvent -= OnSettingValueChanged); + _flowTestSettings.ToList().ForEach(x => x.SettingValueEvent -= OnSettingValueChanged); } } } |
