From 75b20a8b48833e4627130b9af1972a946ce03448 Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Tue, 26 Apr 2022 16:52:26 +0200
Subject: [PATCH] VehicleForm: Updateing Retarder component in GUI

---
 VECTO/GUI/VehicleForm.vb | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb
index c8209f93ed..5f756f7ffd 100644
--- a/VECTO/GUI/VehicleForm.vb
+++ b/VECTO/GUI/VehicleForm.vb
@@ -462,6 +462,7 @@ Public Class VehicleForm
 									 GetRelativePath(em.MechanicalTransmissionLossMap.Source, basePath))
 			tbRatioEm.Text = em.RatioADC.ToGUIFormat()
 			cbEmPos.SelectedValue = em.Position
+			UpdateRetarderPosition(em.Position)
 
 			If (em.Position = PowertrainPosition.HybridP2_5) AndAlso Not em.RatioPerGear Is Nothing Then
 				lvRatioPerGear.Items.Clear()
@@ -1234,21 +1235,23 @@ Public Class VehicleForm
 
 	Private Sub cbEmPos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbEmPos.SelectedIndexChanged
 		gbRatiosPerGear.Enabled = PowertrainPosition.HybridP2_5.Equals(cbEmPos.SelectedValue)
+		UpdateRetarderPosition(CType(cbEmPos.SelectedValue, PowertrainPosition))
+	End Sub
+
 
+	Private Sub UpdateRetarderPosition(pos As PowertrainPosition)
 		Dim selectedValue = CbRtType.SelectedValue
-		CType(CbRtType.DataSource, DataView).RowFilter = $"Key <> {CInt(RetarderType.AxlegearInputRetarder)}"
 
-		If PowertrainPosition.BatteryElectricE4.Equals(cbEmPos.SelectedValue) Then
+		If PowertrainPosition.BatteryElectricE4.Equals(pos) OrElse PowertrainPosition.BatteryElectricE2.Equals(pos) Then
 			gbRetarderLosses.Enabled = False
 			TbRtRatio.Text = ""
 			TbRtPath.Text = ""
-			CType(CbRtType.DataSource, DataView).RowFilter = $"Key in ({CInt(RetarderType.None)})"
-
-		ElseIf PowertrainPosition.BatteryElectricE3.Equals(cbEmPos.SelectedValue) Then
+			CbRtType.SelectedIndex = 0
+			CType(CbRtType.DataSource, DataView).RowFilter = $"Key <> {CInt(RetarderType.AxlegearInputRetarder)}"
+		ElseIf PowertrainPosition.BatteryElectricE3.Equals(pos) Then
 			gbRetarderLosses.Enabled = True
 			CType(CbRtType.DataSource, DataView).RowFilter = $"Key in ({CInt(RetarderType.None)}, {CInt(RetarderType.AxlegearInputRetarder)})"
-
-		ElseIf PowertrainPosition.BatteryElectricE2.Equals(cbEmPos.SelectedValue) Then
+		Else
 			gbRetarderLosses.Enabled = True
 			CType(CbRtType.DataSource, DataView).RowFilter = $"Key <> {CInt(RetarderType.AxlegearInputRetarder)}"
 		End If
@@ -1256,7 +1259,6 @@ Public Class VehicleForm
 		If (selectedValue IsNot Nothing) Then
 			If Not selectedValue.Equals(CbRtType.SelectedValue) Then
 				MsgBox("Retarder has changed due to change of electric motor position. Please check.", MsgBoxStyle.Information)
-				CbRtType.SelectedValue = selectedValue
 			End If
 		End If
 	End Sub
-- 
GitLab