Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 158c7094 authored by Harald Martini's avatar Harald Martini
Browse files

Updated Airdragmodified logic

parent c6b8a3a9
No related branches found
No related tags found
No related merge requests found
......@@ -76,7 +76,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
IMultistageAirdragViewModel MultistageAirdragViewModel { get; set; }
IMultistageAuxiliariesViewModel MultistageAuxiliariesViewModel { get; set; }
bool PrimaryVehicleHybridElectric { get; set; }
void SetAirdragData(IAirdragDeclarationInputData airdragData);
void SetVehicleInputData(IVehicleDeclarationInputData vehicleInputData);
}
......@@ -144,15 +143,22 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
IMultiStageViewModelFactory multistageViewModelFactory)
{
ConsolidatedVehicleData = consolidatedVehicleData;
_multiStageViewModelFactory = multistageViewModelFactory;
MultistageAirdragViewModel = _multiStageViewModelFactory.GetMultistageAirdragViewModel(consolidatedVehicleData?.Components?.AirdragInputData);
MultistageAirdragViewModel.AirdragViewModelChanged += ((sender, args) => {
if (sender is IMultistageAirdragViewModel vm) {
if (vm.AirDragViewModel != null) {
AirdragModifiedMultistage = true;
} else {
AirdragModifiedMultistage = false;
if (AirdragModifiedMultistageMandatory) {
if (vm.AirDragViewModel != null)
{
AirdragModifiedMultistage = true;
}
else
{
AirdragModifiedMultistage = false;
}
}
}
});
......@@ -160,10 +166,22 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
MultistageAuxiliariesViewModel =
_multiStageViewModelFactory.GetAuxiliariesViewModel(consolidatedVehicleData?.Components?
.BusAuxiliaries);
_airdragModifiedEditingEnabled = false;
CreateParameterViewModels();
if (consolidatedVehicleData?.AirdragModifiedMultistage != null)
{
_airdragModifiedMultistageMandatory = true;
AirdragModifiedMultistageEditingEnabled = true;
}
if (consolidatedVehicleData?.Components?.AirdragInputData != null)
{
_airdragModifiedMultistageMandatory = true;
AirdragModifiedMultistageEditingEnabled = true;
}
}
private void CreateParameterViewModels()
......@@ -319,17 +337,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
set { SetProperty(ref _consolidatedVehicleData, value); }
}
public void SetAirdragData(IAirdragDeclarationInputData airdragData)
{
throw new NotImplementedException();
MultistageAirdragViewModel.SetAirdragInputData(airdragInputData: airdragData);
}
public void SetBusAuxiliaries(IBusAuxiliariesDeclarationData busAuxData)
{
throw new NotImplementedException();
}
public void SetVehicleInputData(IVehicleDeclarationInputData vehicleInputData)
{
Manufacturer = vehicleInputData.Manufacturer;
......@@ -364,7 +371,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
PredictiveCruiseControlNullable = vehicleInputData.ADAS?.PredictiveCruiseControl;
ATEcoRollReleaseLockupClutch = vehicleInputData.ADAS?.ATEcoRollReleaseLockupClutch;
AirdragModifiedMultistage = vehicleInputData.AirdragModifiedMultistage;
AirdragModifiedMultistageEditingEnabled = false;
foreach (var multistageParameterViewModel in _parameterViewModels.Values)
{
multistageParameterViewModel.UpdateEditingEnabled();
......@@ -612,10 +618,16 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
return null;
}
}
set {
AirdragModifiedMultistage = value?.toNullableBool();
if (_parameterViewModels.ContainsKey(nameof(AirdragModifiedEnum))) {
_parameterViewModels[nameof(AirdragModifiedEnum)].CurrentContent = value;
set
{
var prevVal = AirdragModifiedMultistage;
var newVal = value?.toNullableBool();
if (prevVal != newVal) {
AirdragModifiedMultistage = value?.toNullableBool();
if (_parameterViewModels.ContainsKey(nameof(AirdragModifiedEnum)))
{
_parameterViewModels[nameof(AirdragModifiedEnum)].CurrentContent = value;
}
}
}
}
......@@ -633,42 +645,36 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
set => throw new NotImplementedException();
}
public bool? AirdragModifiedMultistage
{
get => _airdragModifiedMultistage;
set
{
if (SetProperty(ref _airdragModifiedMultistage, value)) {
AirdragModifiedEnum = value.toAirdragModifiedEnum();
};
}
}
public bool AirdragModifiedMultistageMandatory
{
get => _airdragModifiedMultistageMandatory;
set => SetProperty(ref _airdragModifiedMultistageMandatory, value);
}
private bool airdragModifiedMandatory = false;
public bool AirdragModifiedMultistageEditingEnabled
{
get
{
//IF MODIFIED ONCE IT HAS TO BE SET
if (airdragModifiedMandatory) {
}
return _airdragModifiedEditingEnabled;
}
set
{
var val = value;
if (_consolidatedVehicleData?.AirdragModifiedMultistage != null) {
if (AirdragModifiedMultistageMandatory) {
val = true;
} else {
val = false;
}
if (SetProperty(ref _airdragModifiedEditingEnabled, val)) {
......@@ -1129,19 +1135,10 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
}
#endregion
private IndexedStorage<bool> _editingEnabledDictionary;
private bool _airdragModifiedMultistageMandatory;
private int? _numberPassengersStandingLowerDeck;
private int? _numberPassengersStandingUpperDeck;
public IndexedStorage<bool> EditingEnabledDictionary
{
get
{
return _editingEnabledDictionary;
}
}
}
}
\ No newline at end of file
......@@ -109,6 +109,19 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
if (fileName == null) {
return;
}
var success = LoadAirdragFile(fileName);
if (success) {
AirdragFilePath = fileName;
} else {
_dependencies.DialogHelper.ShowMessageBox("Invalid input file", "Error", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
internal bool LoadAirdragFile(string fileName)
{
var success = true;
var errorStringBuilder = new StringBuilder();
try {
......@@ -118,10 +131,9 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
var airdragElements = xDoc.Descendants().Where(e => e.Name.LocalName == XMLNames.Component_AirDrag);
if (airdragElements.Count() == 1) {
//GET FROM FILE
var dataProviderVersion = XMLDeclarationAirdragDataProviderV20.QUALIFIED_XSD_TYPE;
var validator = new XMLValidator(doc);
var valid = validator.ValidateXML(TUGraz.VectoCore.Utils.XmlDocumentType
......@@ -129,42 +141,34 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
if (!valid) {
throw new VectoException("Invalid input file");
}
//dataProviderVersion = XMLHelper.GetVersion(doc.Node);
XElement airdragElement = airdragElements.First();
XmlNode airdragNode = airdragElement.ToXmlNode();
var airDragInputData = _dependencies.InjectFactory.CreateAirdragData(dataProviderVersion, null, airdragNode, fileName);
AirDragViewModel = _dependencies.ComponentViewModelFactory.CreateComponentViewModel(airDragInputData) as IAirDragViewModel;
var airDragInputData =
_dependencies.InjectFactory.CreateAirdragData(dataProviderVersion, null, airdragNode, fileName);
AirDragViewModel =
_dependencies.ComponentViewModelFactory.CreateComponentViewModel(airDragInputData) as IAirDragViewModel;
AirDragViewModel.IsReadOnly = true;
AirDragViewModel.LabelVisible = false;
success = true;
} else {
success = false;
}
}
catch (Exception e) {
_dependencies.DialogHelper.ShowMessageBox(e.Message,
"Invalid File",
} catch (Exception e) {
_dependencies.DialogHelper.ShowMessageBox(e.Message,
"Invalid File",
MessageBoxButton.OK,
MessageBoxImage.Error);
success = false;
return;
}
if (success) {
AirdragFilePath = fileName;
} else {
_dependencies.DialogHelper.ShowMessageBox("Invalid input file", "Error", MessageBoxButton.OK,
MessageBoxImage.Error);
}
return success;
}
private void ValidationErrorAction(XmlSeverityType arg1, ValidationEvent arg2)
{
var xmlException = arg2?.ValidationEventArgs?.Exception as XmlSchemaValidationException;
......
......@@ -383,9 +383,13 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
get
{
var list = new List<Tuple<HeatPumpType, HeatPumpMode>>();
foreach (var heatPumpConfiguration in HeatPumpConfigurationsPassenger) {
list.Add(new Tuple<HeatPumpType, HeatPumpMode>((HeatPumpType)heatPumpConfiguration.HeatPumpType, (HeatPumpMode)heatPumpConfiguration.HeatPumpMode));
if (HeatPumpConfigurationsPassenger != null) {
foreach (var heatPumpConfiguration in HeatPumpConfigurationsPassenger)
{
list.Add(new Tuple<HeatPumpType, HeatPumpMode>((HeatPumpType)heatPumpConfiguration.HeatPumpType, (HeatPumpMode)heatPumpConfiguration.HeatPumpMode));
}
}
return list;
}
}
......
......@@ -120,11 +120,16 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
if (outputFile == null) {
return;
}
SaveVif(vifData:this, outputFile:outputFile, dialogHelper:_dialogHelper.Value);
SaveVif(outputFile:outputFile);
}, () => true);
}
}
public void SaveVif(string outputFile)
{
SaveVif(vifData:this, outputFile:outputFile, dialogHelper:_dialogHelper.Value);
}
public static void SaveVif(IMultistageVIFInputData vifData, FileOutputVIFWriter writer, IDialogHelper dialogHelper = null)
{
SaveVif(vifData, null, writer, dialogHelper);
......
......@@ -53,7 +53,7 @@
ParameterViewModels[GrossVehicleMassRating]}"></ContentControl>
<ContentControl
<ContentControl Visibility="{Binding AirdragModifiedMultistageMandatory, Converter={StaticResource BooleanToVisibilityConverter}}"
Content="{Binding ParameterViewModels[AirdragModifiedEnum]}"/>
<ContentControl
......
......@@ -19,16 +19,16 @@ namespace Vecto3GUI2020Test.ViewModelTests
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));
//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));
//auxVm.HeatPumpTypePassengerCompartment = HeatPumpType.R_744;
//Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.N_A));
}
[Test]
......@@ -43,7 +43,7 @@ namespace Vecto3GUI2020Test.ViewModelTests
auxVm.HeatPumpTypeDriverCompartment = HeatPumpType.R_744;
Assert.IsFalse(auxVm.HeatPumpModePassengerCompartmentAllowedValues.Contains(HeatPumpMode.N_A));
Assert.IsFalse(auxVm.HeatPumpModeDriverCompartmentAllowedValues.Contains(HeatPumpMode.N_A));
}
......@@ -57,11 +57,11 @@ namespace Vecto3GUI2020Test.ViewModelTests
Assert.IsTrue(auxVm.HeatPumpGroupEditingEnabled);
auxVm.HeatPumpGroupEditingEnabled = false;
auxVm.ParameterViewModels[nameof(auxVm.HeatPumpTypePassengerCompartment)].CurrentContent =
auxVm.ParameterViewModels[nameof(auxVm.HeatPumpModeDriverCompartment)].CurrentContent =
HeatPumpType.R_744;
Assert.IsTrue(auxVm.HeatPumpGroupEditingEnabled);
auxVm.ParameterViewModels[nameof(auxVm.HeatPumpTypePassengerCompartment)].CurrentContent =
auxVm.ParameterViewModels[nameof(auxVm.HeatPumpModeDriverCompartment)].CurrentContent =
HeatPumpType.none;
......
......@@ -60,7 +60,42 @@ namespace Vecto3GUI2020Test.ViewModelTests
vm.MultiStageJobViewModel.ManufacturingStageViewModel.Vehicle as
DeclarationInterimStageBusVehicleViewModel_v2_8;
//var airdragName
Assert.IsNull(vehicleVM.AirdragModifiedMultistage);
var airdragViewModel = vehicleVM.MultistageAirdragViewModel as MultistageAirdragViewModel;
Assert.IsTrue(airdragViewModel.LoadAirdragFile(GetFullPath(airdragComponent)));
Assert.IsNull(vehicleVM.AirdragModifiedMultistage);
Assert.IsFalse(vehicleVM.AirdragModifiedMultistageMandatory);
vehicleVM.AirdragModifiedMultistageEditingEnabled = true;
Assert.IsFalse(vehicleVM.AirdragModifiedMultistageEditingEnabled);
//Set Mandatory Fields
vehicleVM.Manufacturer = "testManufacturer";
vehicleVM.ManufacturerAddress = "Address";
vehicleVM.VIN = "123456789";
//Save as new VIF
var multistageJobViewModel = vm.MultiStageJobViewModel as MultiStageJobViewModel_v0_1;
var outputName = "AidragLoadedInFirstStage";
multistageJobViewModel.SaveVif(GetFullPath($"{outputName}.xml"));
var resultFile = $"{outputName}.VIF_Report_2.xml";
Assert.IsTrue(checkFileNameExists(resultFile));
var secondstageVM = loadFile(resultFile);
Assert.IsNotNull(secondstageVM);
var secondStageVehicleVM =
(secondstageVM.MultiStageJobViewModel.ManufacturingStageViewModel.VehicleViewModel) as
DeclarationInterimStageBusVehicleViewModel_v2_8;
Assert.IsTrue(secondStageVehicleVM.AirdragModifiedMultistageEditingEnabled);
Assert.IsTrue(secondStageVehicleVM.AirdragModifiedMultistageMandatory);
Assert.IsNull(secondStageVehicleVM.ConsolidatedVehicleData.AirdragModifiedMultistage);
//try to disable AirdragModified
secondStageVehicleVM.AirdragModifiedMultistageEditingEnabled = false;
Assert.IsTrue(secondStageVehicleVM.AirdragModifiedMultistageEditingEnabled);
}
/// <summary>
/// no airdrag component set in VIF => AirdragModifiedMultistage is disabled
......@@ -73,7 +108,13 @@ namespace Vecto3GUI2020Test.ViewModelTests
vm.MultiStageJobViewModel.ManufacturingStageViewModel.Vehicle as
DeclarationInterimStageBusVehicleViewModel_v2_8;
Assert.IsNull(vehicleVM.AirdragModifiedMultistage);
Assert.IsNull(vehicleVM.AirdragModifiedMultistage);
Assert.IsFalse(vehicleVM.AirdragModifiedMultistageMandatory);
vehicleVM.AirdragModifiedMultistageEditingEnabled = true;
Assert.IsFalse(vehicleVM.AirdragModifiedMultistageEditingEnabled);
}
/// <summary>
......@@ -83,7 +124,19 @@ namespace Vecto3GUI2020Test.ViewModelTests
public void airdragModifiedMandatory()
{
//var vm = loadFile(primary_vehicle_only);
//var vehicleVM =
// vm.MultiStageJobViewModel.ManufacturingStageViewModel.Vehicle as
// DeclarationInterimStageBusVehicleViewModel_v2_8;
//Assert.IsNull(vehicleVM.AirdragModifiedMultistage);
//Assert.IsNull(vehicleVM.AirdragModifiedMultistage);
//Assert.IsFalse(vehicleVM.AirdragModifiedMultistageMandatory);
//vehicleVM.AirdragModifiedMultistageEditingEnabled = true;
//Assert.IsFalse(vehicleVM.AirdragModifiedMultistageEditingEnabled);
}
......
......@@ -32,6 +32,8 @@ namespace Vecto3GUI2020Test
protected const string stageInputFullSample = "vecto_vehicle-stage_input_full-sample.xml";
protected const string airdragComponent = "AidragComponent.xml";
//protected IXMLInputDataReader xmlInputReader;
protected IKernel _kernel;
private Mock<IDialogHelper> _mockDialogHelper = new Mock<IDialogHelper>();
......@@ -144,5 +146,12 @@ namespace Vecto3GUI2020Test
return _mockDialogHelper;
}
protected string GetFullPath(string fileName)
{
var path = Path.GetFullPath(DirPath + fileName);
Debug.WriteLine(path);
return path;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment