From 1fed69ea4a88d884b9cac51e5c2c88e2458b7989 Mon Sep 17 00:00:00 2001 From: "VKMTHD\\franzjosefkober" <franz.josef.kober@ivt.tugraz.at> Date: Tue, 21 Apr 2020 14:09:08 +0200 Subject: [PATCH] Airdarg GUI update --- .../Converter/BoolVisibilityConverter.cs | 27 +++++ VECTO3GUI/Helper/Converter/EnumConverter.cs | 27 +++++ VECTO3GUI/VECTO3GUI.csproj | 2 + VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs | 105 +++++++++++++++++- .../ViewModel/Interfaces/IAirdragViewModel.cs | 7 +- .../Declaration/AirdragDeclarationView.xaml | 90 ++++++++++----- 6 files changed, 228 insertions(+), 30 deletions(-) create mode 100644 VECTO3GUI/Helper/Converter/BoolVisibilityConverter.cs create mode 100644 VECTO3GUI/Helper/Converter/EnumConverter.cs diff --git a/VECTO3GUI/Helper/Converter/BoolVisibilityConverter.cs b/VECTO3GUI/Helper/Converter/BoolVisibilityConverter.cs new file mode 100644 index 0000000000..a44b95593a --- /dev/null +++ b/VECTO3GUI/Helper/Converter/BoolVisibilityConverter.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace VECTO3GUI.Helper.Converter +{ + public class BoolVisibilityConverter : BaseConverter , IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool) { + return (bool)value ? Visibility.Visible : Visibility.Collapsed; + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return value; + } + } +} diff --git a/VECTO3GUI/Helper/Converter/EnumConverter.cs b/VECTO3GUI/Helper/Converter/EnumConverter.cs new file mode 100644 index 0000000000..5cbc7c8bd7 --- /dev/null +++ b/VECTO3GUI/Helper/Converter/EnumConverter.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using VECTO3GUI.ViewModel.Impl; + +namespace VECTO3GUI.Helper.Converter +{ + public class EnumConverter : BaseConverter , IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is AirdragConfig) { + return ((AirdragConfig)value).GetLabel(); + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/VECTO3GUI/VECTO3GUI.csproj b/VECTO3GUI/VECTO3GUI.csproj index e4299fb9d4..3302fc1ff6 100644 --- a/VECTO3GUI/VECTO3GUI.csproj +++ b/VECTO3GUI/VECTO3GUI.csproj @@ -158,7 +158,9 @@ <SubType>Designer</SubType> </ApplicationDefinition> <Compile Include="Helper\AvalonEditBehaviour.cs" /> + <Compile Include="Helper\Converter\BoolVisibilityConverter.cs" /> <Compile Include="Helper\Converter\ComponentTitleConverter.cs" /> + <Compile Include="Helper\Converter\EnumConverter.cs" /> <Compile Include="Helper\Extension.cs" /> <Compile Include="Helper\FileDialogHelper.cs" /> <Compile Include="Helper\OutputWindowHelper.cs" /> diff --git a/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs b/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs index 15afc8d838..2fb91a5acc 100644 --- a/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AirdragViewModel.cs @@ -1,14 +1,57 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; +using System.Linq; +using System.Windows.Forms; +using System.Windows.Input; +using System.Xml; +using Ninject; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.FileIO.XML; +using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Reader; using TUGraz.VectoCore.Utils; +using VECTO3GUI.Helper; using VECTO3GUI.Model.TempDataObject; +using VECTO3GUI.Util; using VECTO3GUI.ViewModel.Interfaces; namespace VECTO3GUI.ViewModel.Impl { + public enum AirdragConfig + { + WithoutAirdrag, + UseMeasurementData, + Unknown + } + + public static class AirdragConfigHelper + { + public static string GetLabel(this AirdragConfig airdrag) + { + switch (airdrag) + { + case AirdragConfig.WithoutAirdrag: + return "Without Airdrag"; + case AirdragConfig.UseMeasurementData: + return "Use Measurement Data"; + } + return string.Empty; + } + + public static AirdragConfig GetAirdragConfig(string name) + { + switch (name) + { + case "Without Airdrag": + return AirdragConfig.WithoutAirdrag; + case "Use Measurement Data": + return AirdragConfig.UseMeasurementData; + } + return AirdragConfig.Unknown; + } + } + + public class AirdragViewModel : AbstractComponentViewModel, IAirdragViewModel { private string _manufacturer; @@ -21,6 +64,11 @@ namespace VECTO3GUI.ViewModel.Impl private IAirdragDeclarationInputData _airdragData; private AirdragComponentData _componentData; + private bool _isEditable; + + private ICommand _airdragConfig; + private ICommand _loadFileCommand; + #region Implementation of IAirdragViewModel @@ -110,17 +158,26 @@ namespace VECTO3GUI.ViewModel.Impl #endregion + public bool IsEditable + { + get { return _isEditable; } + set { SetProperty(ref _isEditable, value); } + } + + protected override void InputDataChanged() { var inputData = JobViewModel.InputDataProvider as IDeclarationInputDataProvider; _airdragData = inputData?.JobInputData.Vehicle.Components.AirdragInputData; SetAirdragValues(_airdragData); + IsEditable = true; } private void SetAirdragValues(IAirdragDeclarationInputData airdrag) { UseMeasuredValues = airdrag != null; - if (airdrag == null) { + if (airdrag == null) + { _componentData = new AirdragComponentData(this, true); return; } @@ -136,6 +193,44 @@ namespace VECTO3GUI.ViewModel.Impl ClearChangedProperties(); } + #region Commands + + public ICommand AirdragConfigCommand + { + get + { + return _airdragConfig ?? (_airdragConfig = new RelayCommand<AirdragConfig>(DoAirdragConfig)); + } + } + + private void DoAirdragConfig(AirdragConfig config) + { + IsEditable = config == AirdragConfig.UseMeasurementData; + } + + + public ICommand LoadFileCommand + { + get + { + return _loadFileCommand ?? (_loadFileCommand = new RelayCommand(DoLoadFile, CanLoadFile)); + } + } + + private bool CanLoadFile() + { + return IsEditable; + } + + private void DoLoadFile() + { + var filePath = FileDialogHelper.ShowSelectFilesDialog(false)?.FirstOrDefault(); + ReadSelectedXml(null); + } + #endregion + + + private void SetAirdragArea(IAirdragDeclarationInputData airdrag) { DeclaredCdxA = airdrag.AirDragArea; @@ -154,5 +249,11 @@ namespace VECTO3GUI.ViewModel.Impl ClearChangedProperties(); return _componentData; } + + private void ReadSelectedXml(string filePath) + { + if (filePath == null) + return; + } } } diff --git a/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs index 13d4fde2b6..c018b15fb8 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IAirdragViewModel.cs @@ -1,4 +1,5 @@ -using TUGraz.VectoCommon.InputData; +using System.Windows.Input; +using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Utils; namespace VECTO3GUI.ViewModel.Interfaces @@ -6,5 +7,9 @@ namespace VECTO3GUI.ViewModel.Interfaces public interface IAirdragViewModel : IAirdrag, IComponentViewModel { IAirdragDeclarationInputData ModelData { get; } + bool IsEditable { get; } + ICommand LoadFileCommand { get; } + ICommand AirdragConfigCommand { get; } + } } diff --git a/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml b/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml index 13dcea6b88..009760e99d 100644 --- a/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml +++ b/VECTO3GUI/Views/ComponentViews/Declaration/AirdragDeclarationView.xaml @@ -6,8 +6,8 @@ xmlns:interfaces="clr-namespace:VECTO3GUI.ViewModel.Interfaces" xmlns:customControls="clr-namespace:VECTO3GUI.Views.CustomControls" xmlns:helper="clr-namespace:VECTO3GUI.Helper" + xmlns:impl="clr-namespace:VECTO3GUI.ViewModel.Impl" xmlns:converter="clr-namespace:VECTO3GUI.Helper.Converter" - xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="800"> @@ -16,44 +16,80 @@ </d:AirdragDeclarationView.DataContext> <Grid> - <StackPanel Orientation="Vertical" Width="400" HorizontalAlignment="Left" Grid.IsSharedSizeScope="True"> + <Grid.RowDefinitions> + <RowDefinition Height="10"/> + <RowDefinition Height="150"/> + <RowDefinition /> + </Grid.RowDefinitions> - <customControls:CheckboxParameter - Caption="Use Measured Values" CaptionWidthGroup="lblWidth" - Value="{Binding UseMeasuredValues}" UnitWidthGroup="unitWidth"/> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="10"/> + <ColumnDefinition /> + </Grid.ColumnDefinitions> - <customControls:VectoParameterControl - Caption="Manufacturer" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" - Value="{Binding Manufacturer}" /> + <GroupBox Header="Aridrag Configuration" Grid.Row="1" Grid.Column="1" Width="500" HorizontalAlignment="Left" VerticalAlignment="Top"> - <customControls:VectoParameterControl - Caption="Model" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" - Value="{Binding Model}" /> + <StackPanel Orientation="Vertical"> + <RadioButton GroupName="AirdragConfig" Margin="5" + Content="{Binding Source={x:Static impl:AirdragConfig.WithoutAirdrag}, Converter={converter:EnumConverter}}" + Command="{Binding AirdragConfigCommand}" CommandParameter="{Binding Source={x:Static impl:AirdragConfig.WithoutAirdrag}}"/> + + <RadioButton GroupName="AirdragConfig" Margin="5" + Content="{Binding Source={x:Static impl:AirdragConfig.UseMeasurementData}, Converter={converter:EnumConverter}}" + Command="{Binding AirdragConfigCommand}" CommandParameter="{ Binding Source={x:Static impl:AirdragConfig.UseMeasurementData}}" + IsChecked="{Binding IsEditable}"/> - <!-- <mah:DateTimePicker --> - <!-- SelectedDate="{Binding Date}" --> - <!-- Culture="en-In" --> - <!-- SelectedTimeFormat="Short" --> - <!-- SelectedDateFormat="Short"/> --> + <StackPanel Orientation="Horizontal" Margin="30,10,10,10"> + <Label Content="Load Component File:"/> + <Button Content="Load File" Width="80" Margin="10,0,0,0" + Command="{Binding LoadFileCommand}"/> + </StackPanel> - <customControls:VectoParameterControl - Caption="Date" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" - Value="{Binding Date}" /> + </StackPanel> - <customControls:VectoParameterControl - Caption="Certification Number" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" - Value="{Binding CertificationNumber}" /> - <customControls:VectoParameterControl + </GroupBox> + + <GroupBox Header="Aridrag Data" Width="500" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" Height="250" VerticalAlignment="Top" + Visibility="{Binding IsEditable, Converter={converter:BoolVisibilityConverter}}"> + + + <StackPanel Orientation="Vertical" Width="450" HorizontalAlignment="Left" Grid.IsSharedSizeScope="True"> + + <customControls:VectoParameterControl + Caption="Manufacturer" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" + Value="{Binding Manufacturer}" IsEnabled="{Binding IsEditable}" /> + + <customControls:VectoParameterControl + Caption="Model" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" + Value="{Binding Model}" IsEnabled="{Binding IsEditable}" /> + + <!-- <mah:DateTimePicker --> + <!-- SelectedDate="{Binding Date}" --> + <!-- Culture="en-In" --> + <!-- SelectedTimeFormat="Short" --> + <!-- SelectedDateFormat="Short"/> --> + + <customControls:VectoParameterControl + Caption="Date" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" + Value="{Binding Date}" IsEnabled="{Binding IsEditable}"/> + + <customControls:VectoParameterControl + Caption="Certification Number" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" + Value="{Binding CertificationNumber}" IsEnabled="{Binding IsEditable}" /> + + <customControls:VectoParameterControl Caption="App Version" Unit="" CaptionWidthGroup="vehicleLbl" UnitWidthGroup="unitWidth" - Value="{Binding AppVersion}" /> + Value="{Binding AppVersion}" IsEnabled="{Binding IsEditable}" /> - <customControls:VectoParameterControl + <customControls:VectoParameterControl Caption="DeclaredCd x A 0" CaptionWidthGroup="lblWidth" Unit="{helper:SIUnit DeclaredCdxA}" UnitWidthGroup="unitWidth" Value="{Binding DeclaredCdxA, Converter={converter:SIValueConverter}, ConverterParameter=double}" - IsEnabled="{Binding UseMeasuredValues}"/> + IsEnabled="{Binding IsEditable}"/> + + </StackPanel> - </StackPanel> + </GroupBox> </Grid> </UserControl> -- GitLab