From e6e9f43bb877966522e3ed9cea6f0f65e376d71b Mon Sep 17 00:00:00 2001 From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at> Date: Tue, 8 Jun 2021 09:54:15 +0200 Subject: [PATCH] Airdrag modified is set to true when component is loaded, Airdrag modified is set to false when component is removed, Airdrag component is removed when airdrag modified is set to false --- .gitignore | 1 + .../Helper/MultistageParameterViewModel.cs | 17 ++++++++ .../Interfaces/Common/IViewModelBase.cs | 6 ++- .../InterimStageBusVehicleViewModel_v2_8.cs | 17 ++++---- .../MultistageAirdragViewModel.cs | 2 +- .../Interfaces/IMultistageAirdragViewModel.cs | 1 + .../ViewModelTests/LoadAndSaveVehicleData.cs | 5 ++- .../MultistageAuxiliariesViewModelTests.cs | 4 +- .../ViewModelTests/VehicleViewModelTests.cs | 40 ++++++++++++++++++- 9 files changed, 77 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 0f4bd7bb9e..0f6e6ab57c 100644 --- a/.gitignore +++ b/.gitignore @@ -218,3 +218,4 @@ Documentation/VehiclesReleaseComparisonDeclarationMode/tmp/ /VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/test.VIF_Report_5.xml /VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/tests.xml /VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/finalGroup41.VIF_Report_4.xml +/VectoCore/VectoCoreTest/TestData/XML/XMLReaderDeclaration/output diff --git a/VECTO3GUI2020/Helper/MultistageParameterViewModel.cs b/VECTO3GUI2020/Helper/MultistageParameterViewModel.cs index 1656da5d2d..7c3413d753 100644 --- a/VECTO3GUI2020/Helper/MultistageParameterViewModel.cs +++ b/VECTO3GUI2020/Helper/MultistageParameterViewModel.cs @@ -77,10 +77,12 @@ namespace VECTO3GUI2020.Helper Action<MultistageParameterViewModel> propertyChangedCallback = null, params ResourceManager[] resourceManagers) { + _propertyName = propertyName; PreviousContent = previousContent; _propertyChangedCallback = propertyChangedCallback; _parentViewModel = parentViewModel; + //_parentViewModel.PropertyChanged += ParentViewModelPropertyChanged; _propertyInfo = parentViewModel.GetType().GetProperty(propertyName); _viewMode = viewMode; @@ -110,6 +112,20 @@ namespace VECTO3GUI2020.Helper CurrentContent = _propertyInfo.GetValue(parentViewModel); } + private void ParentViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) + { + Debug.Assert((IViewModelBase)sender == _parentViewModel); + if (e.PropertyName != _propertyName) { + return; + } + + var valueFromParent = _propertyInfo.GetValue(sender); + if (valueFromParent != CurrentContent) { + CurrentContent = valueFromParent; + } + } + + private object CreateDummyContent() { var type = _type; @@ -278,6 +294,7 @@ namespace VECTO3GUI2020.Helper _propertyInfo.SetValue(_parentViewModel, _currentContent); _propertyChangedCallback?.Invoke(this); }; + OnPropertyChanged(nameof(CurrentContent)); } } diff --git a/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs b/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs index dff379d33b..39808350ec 100644 --- a/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs @@ -1,6 +1,8 @@ -namespace VECTO3GUI2020.ViewModel.Interfaces.Common +using System.ComponentModel; + +namespace VECTO3GUI2020.ViewModel.Interfaces.Common { - public interface IViewModelBase + public interface IViewModelBase : INotifyPropertyChanged { string Title { get; set; } } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs index b739a88820..f28774411e 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/InterimStageBusVehicleViewModel_v2_8.cs @@ -614,11 +614,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation { get { - if (AirdragModifiedMultistageEditingEnabled) { - return _airdragModifiedMultistage.toAirdragModifiedEnum(); - } else { - return null; - } + return _airdragModifiedMultistage.toAirdragModifiedEnum(); } set { @@ -626,10 +622,10 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation var newVal = value?.toNullableBool(); if (prevVal != newVal) { AirdragModifiedMultistage = value?.toNullableBool(); - if (_parameterViewModels.ContainsKey(nameof(AirdragModifiedEnum))) - { - _parameterViewModels[nameof(AirdragModifiedEnum)].CurrentContent = value; - } + } + if (_parameterViewModels.ContainsKey(nameof(AirdragModifiedEnum))) + { + _parameterViewModels[nameof(AirdragModifiedEnum)].CurrentContent = value; } } } @@ -654,6 +650,9 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set { if (SetProperty(ref _airdragModifiedMultistage, value)) { + if(value == false){ + MultistageAirdragViewModel.AirDragViewModel = null; + } AirdragModifiedEnum = value.toAirdragModifiedEnum(); }; } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs index cb78e564ef..34d5ce7038 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageAirdragViewModel.cs @@ -120,7 +120,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation } - internal bool LoadAirdragFile(string fileName) + public bool LoadAirdragFile(string fileName) { var success = true; var errorStringBuilder = new StringBuilder(); diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageAirdragViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageAirdragViewModel.cs index b88d8fbb8a..f56fe95e90 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageAirdragViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Interfaces/IMultistageAirdragViewModel.cs @@ -10,5 +10,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Interfaces IAirDragViewModel AirDragViewModel { get; set; } void SetAirdragInputData(IAirdragDeclarationInputData airdragInputData); + bool LoadAirdragFile(string fileName); } } \ No newline at end of file diff --git a/Vecto3GUI2020Test/ViewModelTests/LoadAndSaveVehicleData.cs b/Vecto3GUI2020Test/ViewModelTests/LoadAndSaveVehicleData.cs index 99e19a515b..a551fdf672 100644 --- a/Vecto3GUI2020Test/ViewModelTests/LoadAndSaveVehicleData.cs +++ b/Vecto3GUI2020Test/ViewModelTests/LoadAndSaveVehicleData.cs @@ -211,11 +211,12 @@ namespace Vecto3GUI2020Test Assert.IsNull(vehicleViewModel_v2_8.AirdragModifiedMultistage); Assert.IsNull(vehicleViewModel_v2_8.ConsolidatedAirdragModifiedEnum); - Assert.IsNull(vehicleViewModel_v2_8.AirdragModifiedEnum); + Assert.IsTrue(vehicleViewModel_v2_8.AirdragModifiedEnum == AIRDRAGMODIFIED.UNKNOWN || vehicleViewModel_v2_8.AirdragModifiedEnum == null); Assert.AreEqual(vehicleViewModel_v2_8.AirdragModifiedMultistageEditingEnabled, false); + Assert.Null(vehicleViewModel_v2_8.BusAuxiliaries); @@ -294,6 +295,8 @@ namespace Vecto3GUI2020Test Assert.AreEqual(500, vehicleViewModel.CurbMassChassis.Value());//CorrectedActualMass Assert.AreEqual(3500, vehicleViewModel.GrossVehicleMassRating.Value());//TechnicalPermissibleMaximumLadenMass Assert.AreEqual(false, vehicleViewModel.AirdragModifiedMultistage); + Assert.AreEqual(AIRDRAGMODIFIED.FALSE, vehicleViewModel.AirdragModifiedEnum); + Assert.AreEqual(AIRDRAGMODIFIED.FALSE, vehicleViewModel.ParameterViewModels[nameof(vehicleViewModel.AirdragModifiedEnum)].CurrentContent); Assert.AreEqual(TankSystem.Compressed, vehicleViewModel.TankSystem);//NgTankSystem Assert.AreEqual(RegistrationClass.II_III, vehicleViewModel.RegisteredClass);//ClassBus Assert.AreEqual(1, vehicleViewModel.NumberPassengerSeatsLowerDeck); diff --git a/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs b/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs index 09a3943e48..07c2f96cb7 100644 --- a/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs +++ b/Vecto3GUI2020Test/ViewModelTests/MultistageAuxiliariesViewModelTests.cs @@ -57,11 +57,11 @@ namespace Vecto3GUI2020Test.ViewModelTests Assert.IsTrue(auxVm.HeatPumpGroupEditingEnabled); auxVm.HeatPumpGroupEditingEnabled = false; - auxVm.ParameterViewModels[nameof(auxVm.HeatPumpModeDriverCompartment)].CurrentContent = + auxVm.ParameterViewModels[nameof(auxVm.HeatPumpTypeDriverCompartment)].CurrentContent = HeatPumpType.R_744; Assert.IsTrue(auxVm.HeatPumpGroupEditingEnabled); - auxVm.ParameterViewModels[nameof(auxVm.HeatPumpModeDriverCompartment)].CurrentContent = + auxVm.ParameterViewModels[nameof(auxVm.HeatPumpTypeDriverCompartment)].CurrentContent = HeatPumpType.none; diff --git a/Vecto3GUI2020Test/ViewModelTests/VehicleViewModelTests.cs b/Vecto3GUI2020Test/ViewModelTests/VehicleViewModelTests.cs index 51fa2cdc74..d978425dfc 100644 --- a/Vecto3GUI2020Test/ViewModelTests/VehicleViewModelTests.cs +++ b/Vecto3GUI2020Test/ViewModelTests/VehicleViewModelTests.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Utils; using VECTO3GUI2020.Annotations; +using VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle.Components; using VECTO3GUI2020.ViewModel.MultiStage.Implementation; namespace Vecto3GUI2020Test.ViewModelTests @@ -71,6 +72,8 @@ namespace Vecto3GUI2020Test.ViewModelTests vehicleVM.AirdragModifiedMultistageEditingEnabled = true; Assert.IsFalse(vehicleVM.AirdragModifiedMultistageEditingEnabled); + Assert.IsNull(vehicleVM.AirdragModifiedMultistage); + //Set Mandatory Fields vehicleVM.Manufacturer = "testManufacturer"; vehicleVM.ManufacturerAddress = "Address"; @@ -95,7 +98,6 @@ namespace Vecto3GUI2020Test.ViewModelTests //try to disable AirdragModified secondStageVehicleVM.AirdragModifiedMultistageEditingEnabled = false; Assert.IsTrue(secondStageVehicleVM.AirdragModifiedMultistageEditingEnabled); - } /// <summary> /// no airdrag component set in VIF => AirdragModifiedMultistage is disabled @@ -139,6 +141,42 @@ namespace Vecto3GUI2020Test.ViewModelTests } + [Test] + public void airdragModifiedSetToTrueWhenComponentIsLoaded() + { + var vm = loadFile(consolidated_multiple_stages_airdrag); + + var vehicleViewModel = vm.MultiStageJobViewModel.ManufacturingStageViewModel.VehicleViewModel as DeclarationInterimStageBusVehicleViewModel_v2_8; + + Assert.IsNull(vehicleViewModel.AirdragModifiedMultistage); + + + //Load airdrag file + var airdragLoaded = vehicleViewModel.MultistageAirdragViewModel.LoadAirdragFile(GetFullPath(airdragComponent)); + Assert.IsTrue(airdragLoaded, "Airdrag file was not loaded"); + + //Airdrag modified set to true if a component is loaded and the field is mandatory + Assert.IsTrue(vehicleViewModel.AirdragModifiedMultistage); + Assert.IsTrue(vehicleViewModel.AirdragModifiedMultistageMandatory); + Assert.AreEqual( + AIRDRAGMODIFIED.TRUE, + vehicleViewModel.ParameterViewModels[nameof(vehicleViewModel.AirdragModifiedEnum)].CurrentContent); + + //Airdrag modified set to false if the component is removed + vehicleViewModel.MultistageAirdragViewModel.AirDragViewModel = null; + Assert.IsFalse(vehicleViewModel.AirdragModifiedMultistage); + + //AirdragComponent is removed when airdragmodified is set to false; + //Load airdrag file + airdragLoaded = vehicleViewModel.MultistageAirdragViewModel.LoadAirdragFile(GetFullPath(airdragComponent)); + Assert.IsTrue(airdragLoaded, "Airdrag file was not loaded"); + + vehicleViewModel.AirdragModifiedMultistage = false; + Assert.IsNull(vehicleViewModel.MultistageAirdragViewModel.AirDragViewModel); + + + } + -- GitLab