diff --git a/VECTO3GUI2020/Helper/EnumHelper.cs b/VECTO3GUI2020/Helper/EnumHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..16c063f1d9184a28dfb1067035f9a39b56250620 --- /dev/null +++ b/VECTO3GUI2020/Helper/EnumHelper.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.ObjectModel; +using System.Linq; +using TUGraz.VectoCommon.Models; +using VECTO3GUI2020.Annotations; + +namespace VECTO3GUI2020.Helper +{ + using System.Runtime.CompilerServices; + + + + internal static class EnumHelper + { + private static ObservableCollection<T> GetValuesAsObservableCollection<T, TInput>(bool exclude, + params TInput[] items) + where TInput : System.Enum + where T : System.Enum + + { + var values = Enum.GetValues(typeof(TInput)).Cast<TInput>().ToList().Where(e => { + var contains = items.Contains(e); + var result = contains; + if (exclude) { + result = !contains; + } + + return result; + }); + return new ObservableCollection<T>(values.Cast<T>()); + } + + public static ObservableCollection<T> GetValuesAsObservableCollectionIncluding<T, TInput>(params TInput[] items) + where TInput : System.Enum + where T : System.Enum + + { + return GetValuesAsObservableCollection<T, TInput>(false, items); + } + + public static ObservableCollection<T> GetValuesAsObservableCollectionExcluding<T, TInput>(params TInput[] items) + where TInput : System.Enum + where T : System.Enum + + { + return GetValuesAsObservableCollection<T, TInput>(true, items); + } + + + + + } +} \ No newline at end of file diff --git a/VECTO3GUI2020/Helper/Extension.cs b/VECTO3GUI2020/Helper/Extension.cs deleted file mode 100644 index b7bb02b8f317a41e61c84ba4fe7efe3dd48b3358..0000000000000000000000000000000000000000 --- a/VECTO3GUI2020/Helper/Extension.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace VECTO3GUI2020.Helper -{ - public class Extension - { - - } -} \ No newline at end of file diff --git a/VECTO3GUI2020/Properties/AssemblyInfo.cs b/VECTO3GUI2020/Properties/AssemblyInfo.cs index f37064a9b870f31c27572d9137ff1e85d2e68931..ce2e072c25beaaf6359070384b2240d511303f57 100644 --- a/VECTO3GUI2020/Properties/AssemblyInfo.cs +++ b/VECTO3GUI2020/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows; @@ -13,6 +14,7 @@ using System.Windows; [assembly: AssemblyCopyright("Copyright © 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +[assembly: InternalsVisibleTo("Vecto3GUI2020Test")] // Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly // für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index 8f8bbfc551b2a3b7f807ab7819f193314d2b74df..68c4221d5862a07679ee2355f34180f75a1c6019 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -137,7 +137,7 @@ <Compile Include="Helper\Converter\XToBoolConverter.cs" /> <Compile Include="Helper\DoubleValidation.cs" /> <Compile Include="Helper\Exceptions.cs" /> - <Compile Include="Helper\Extension.cs" /> + <Compile Include="Helper\EnumHelper.cs" /> <Compile Include="Helper\IWindowHelper.cs" /> <Compile Include="Helper\DialogHelper.cs" /> <Compile Include="Helper\WindowHelper.cs" /> diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs index c43d35ebfec72e6e48c0f8ffc43c1e4a6c940abe..e1524ad0a8afc56f392f06fbaeaaa8724b89423c 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs @@ -24,6 +24,7 @@ using VECTO3GUI2020.ViewModel.Interfaces.JobEdit.Vehicle.Components; using VECTO3GUI2020.ViewModel.MultiStage.Implementation; using VECTO3GUI2020.ViewModel.MultiStage.Interfaces; using Convert = System.Convert; +using EnumHelper = VECTO3GUI2020.Helper.EnumHelper; namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { @@ -457,10 +458,9 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set => SetProperty(ref _vehicleCode, value); } - public ObservableCollection<Enum> VehicleCodeAllowedValues { get; } = - new ObservableCollection<Enum>(Enum.GetValues(typeof(VehicleCode)).Cast<Enum>().ToList().Where( - (e => (VehicleCode)e != TUGraz.VectoCommon.Models.VehicleCode.NOT_APPLICABLE))); - + public ObservableCollection<Enum> VehicleCodeAllowedValues { get; } = + EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, VehicleCode>((TUGraz.VectoCommon.Models.VehicleCode.NOT_APPLICABLE)); + public bool? LowEntry { diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAuxiliariesViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAuxiliariesViewModel.cs index f41ebb6fabc2f4b64831af84da257d90ea83b69f..24d013f4105c409cfcfdf74e4f90a5dcd7543a77 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAuxiliariesViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAuxiliariesViewModel.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Xml; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.BusAuxiliaries.Interfaces; +using VECTO3GUI2020.Helper; using VECTO3GUI2020.ViewModel.Implementation.Common; +using EnumHelper = VECTO3GUI2020.Helper.EnumHelper; namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { @@ -155,28 +158,98 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation public HeatPumpType? HeatPumpTypeDriverCompartment { get => _heatPumpTypeDriverCompartment; - set => SetProperty(ref _heatPumpTypeDriverCompartment, value); + set + { + if (value == HeatPumpType.none) { + HeatPumpModeDriverCompartmentAllowedValues = + EnumHelper.GetValuesAsObservableCollectionIncluding<Enum, HeatPumpMode>(items:HeatPumpMode.N_A); + HeatPumpModeDriverCompartment = HeatPumpMode.N_A; + } else { + HeatPumpModeDriverCompartmentAllowedValues = + EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, HeatPumpMode>( + items: HeatPumpMode.N_A); + HeatPumpModeDriverCompartment = HeatPumpMode.cooling; + } + + + SetProperty(ref _heatPumpTypeDriverCompartment, value); + } } + public HeatPumpMode? HeatPumpModeDriverCompartment { get => _heatPumpModeDriverCompartment; - set => SetProperty(ref _heatPumpModeDriverCompartment, value); + set + { + SetProperty(ref _heatPumpModeDriverCompartment, value); + } + } + + private ObservableCollection<Enum> _heatPumpModeDriverCompartmentAllowedValues = + EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, HeatPumpMode>(HeatPumpMode.N_A); + public ObservableCollection<Enum> HeatPumpModeDriverCompartmentAllowedValues + { + get + { + return _heatPumpModeDriverCompartmentAllowedValues; + } + private set + { + SetProperty(ref _heatPumpModeDriverCompartmentAllowedValues, value); + } } + + + public HeatPumpType? HeatPumpTypePassengerCompartment { get => _heatPumpTypePassengerCompartment; - set => SetProperty(ref _heatPumpTypePassengerCompartment, value); + set + { + SetProperty(ref _heatPumpTypePassengerCompartment, value); + if (value == HeatPumpType.none) + { + HeatPumpModePassengerCompartmentAllowedValues = + EnumHelper.GetValuesAsObservableCollectionIncluding<Enum, HeatPumpMode>(items: HeatPumpMode.N_A); + HeatPumpModePassengerCompartment = HeatPumpMode.N_A; + } + else + { + HeatPumpModePassengerCompartmentAllowedValues = + EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, HeatPumpMode>( + items: HeatPumpMode.N_A); + HeatPumpModePassengerCompartment = HeatPumpMode.cooling; + } + } } public HeatPumpMode? HeatPumpModePassengerCompartment { get => _heatPumpModePassengerCompartment; - set => SetProperty(ref _heatPumpModePassengerCompartment, value); + set + { + SetProperty(ref _heatPumpModePassengerCompartment, value); + + } } -#endregion + private ObservableCollection<Enum> _heatPumpModePassengerCompartmentAllowedValues = + EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, HeatPumpMode>(HeatPumpMode.N_A); + public ObservableCollection<Enum> HeatPumpModePassengerCompartmentAllowedValues + { + get + { + return _heatPumpModePassengerCompartmentAllowedValues; + } + private set + { + SetProperty(ref _heatPumpModePassengerCompartmentAllowedValues, value); + } + } + + #endregion #region IElectricConsumersDeclaration //LED lights @@ -228,6 +301,8 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation } private CompressorDrive _compressorDrive; + + public CompressorDrive CompressorDrive { get => _compressorDrive; diff --git a/VECTO3GUI2020/Views/Multistage/ManufacturingStageAuxiliariesView.xaml b/VECTO3GUI2020/Views/Multistage/ManufacturingStageAuxiliariesView.xaml index 27c7ae37a583c40ddc6409478d4a03b271913bf6..0b9e70fcc9d0f0d0b53feb6767ccb779ba5608a8 100644 --- a/VECTO3GUI2020/Views/Multistage/ManufacturingStageAuxiliariesView.xaml +++ b/VECTO3GUI2020/Views/Multistage/ManufacturingStageAuxiliariesView.xaml @@ -45,6 +45,7 @@ EditingEnabled="{Binding HeatPumpGroupEditingEnabled}" PreviousContent="{Binding ConsolidatedInputData.HVACAux.HeatPumpModeDriverCompartment}" Content="{Binding HeatPumpModeDriverCompartment}" + ListItems="{Binding HeatPumpModeDriverCompartmentAllowedValues}" ShowCheckBox="False"/> <customControls:MultiStageParameter Mode="COMBOBOX" EditingEnabled="{Binding HeatPumpGroupEditingEnabled}" @@ -55,6 +56,7 @@ EditingEnabled="{Binding HeatPumpGroupEditingEnabled}" PreviousContent="{Binding ConsolidatedInputData.HVACAux.HeatPumpModePassengerCompartment}" Content="{Binding HeatPumpModePassengerCompartment}" + ListItems="{Binding HeatPumpModePassengerCompartmentAllowedValues}" ShowCheckBox="False"/> <Separator/> <customControls:MultiStageParameter Mode="TEXTBOX" diff --git a/Vecto3GUI2020Test/ViewModelTests/ExtensionTests.cs b/Vecto3GUI2020Test/ViewModelTests/ExtensionTests.cs new file mode 100644 index 0000000000000000000000000000000000000000..50d9531a52b15491bf75126f42deb6ff1e0c3818 --- /dev/null +++ b/Vecto3GUI2020Test/ViewModelTests/ExtensionTests.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.ObjectModel; +using NUnit.Framework; +using TUGraz.VectoCommon.Models; +using VECTO3GUI2020.Helper; + +namespace Vecto3GUI2020Test.ViewModelTests +{ + [TestFixture] + public class ExtensionTests + { + + [Test] + public void TestGetValuesAsObservableCollectionEnumExtension() + { + + VehicleCode? vehicleCode = null; + var collection1 = EnumHelper.GetValuesAsObservableCollectionExcluding<Enum, VehicleCode>(VehicleCode.NOT_APPLICABLE, VehicleCode.CF); + + Assert.False(collection1.Contains(VehicleCode.NOT_APPLICABLE)); + Assert.False(collection1.Contains(VehicleCode.CF)); + + Assert.True(collection1.Contains(VehicleCode.CA)); + + Assert.True(collection1.Contains(VehicleCode.CB)); + Assert.True(collection1.Contains(VehicleCode.CC)); + Assert.True(collection1.Contains(VehicleCode.CD)); + Assert.True(collection1.Contains(VehicleCode.CE)); + Assert.True(collection1.Contains(VehicleCode.CG)); + Assert.True(collection1.Contains(VehicleCode.CH)); + Assert.True(collection1.Contains(VehicleCode.CI)); + Assert.True(collection1.Contains(VehicleCode.CJ)); + + + + var collection2 = EnumHelper.GetValuesAsObservableCollectionIncluding<Enum, VehicleCode>(VehicleCode.CA); + Assert.True(collection2.Contains(VehicleCode.CA)); + Assert.False(collection2.Contains(VehicleCode.NOT_APPLICABLE)); + } + + + } +} \ No newline at end of file diff --git a/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs b/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs new file mode 100644 index 0000000000000000000000000000000000000000..779851c00a74913f92f61c1dff663d6e3a9b3da2 --- /dev/null +++ b/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using TUGraz.VectoCommon.BusAuxiliaries; +using VECTO3GUI2020.ViewModel.MultiStage.Implementation; + +namespace Vecto3GUI2020Test.ViewModelTests +{ + [TestFixture] + public class MultistageAuxiliariesViewModelTests : ViewModelTestBase + { + + //[Test] + //public void TestAllowedValuesHeatPumpMode() + //{ + // var vm = loadFile(consolidated_multiple_stages_airdrag); + + + // var vehicle = vm.MultiStageJobViewModel.ManufacturingStageViewModel.Vehicle as + // DeclarationInterimStageBusVehicleViewModel_v2_8; + + // var auxVm = vehicle.MultistageAuxiliariesViewModel as MultistageAuxiliariesViewModel; + + + // auxVm.HeatPumpTypeDriverCompartment = HeatPumpType.none; + // Assert.IsTrue(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.N_A)); + // Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.cooling)); + // Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.heating)); + // Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.heating_and_cooling)); + + + // auxVm.HeatPumpTypeDriverCompartment = HeatPumpType.R_744; + // Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.N_A)); + + + + //} + + [Test] + public void TestAllowedValuesHeatPumpModePassenger() + { + + var auxVm = new MultistageAuxiliariesViewModel(null); + auxVm.HeatPumpTypePassengerCompartment = HeatPumpType.none; + Assert.IsTrue(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.N_A)); + Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.cooling)); + Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.heating)); + Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.heating_and_cooling)); + + + auxVm.HeatPumpTypePassengerCompartment = HeatPumpType.R_744; + Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.N_A)); + } + + [Test] + public void TestAllowedValuesHeatPumpModeDriver() + { + var auxVm = new MultistageAuxiliariesViewModel(null); + auxVm.HeatPumpTypeDriverCompartment = HeatPumpType.none; + Assert.IsTrue(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.N_A)); + Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.cooling)); + Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.heating)); + Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.heating_and_cooling)); + + + auxVm.HeatPumpTypeDriverCompartment = HeatPumpType.R_744; + Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.N_A)); + } + + + + + + + } +}