From bfdd131e686f1ce1669751b8f283927ddd11d591 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 4 Oct 2016 16:27:12 +0200 Subject: [PATCH] surround opening files with try/catch; separate writing files to dedicated writer class, access values via inputdata interfaces --- VECTO/GUI/EngineForm.vb | 9 +- VECTO/GUI/GearboxForm.vb | 14 +- VECTO/GUI/MainForm.vb | 24 +++- VECTO/GUI/VectoJobForm.vb | 55 +++++--- VECTO/Input Files/Gearbox.vb | 6 +- VECTO/Input Files/VectoJob.vb | 120 +++++++++------- VECTO/Input Files/Vehicle.vb | 4 +- VECTO/MainModule.vb | 4 +- VECTO/OutputData/JSONWriter.vb | 130 +++++++++++------- .../VectoCommon/Models/RetarderType.cs | 5 + .../InputData/FileIO/JSON/JSONGearboxData.cs | 27 ++-- .../InputData/FileIO/JSON/JSONInputData.cs | 4 + .../Models/Declaration/AuxiliaryTypeHelper.cs | 8 +- 13 files changed, 264 insertions(+), 146 deletions(-) diff --git a/VECTO/GUI/EngineForm.vb b/VECTO/GUI/EngineForm.vb index e041ee0857..9c4e3c590f 100644 --- a/VECTO/GUI/EngineForm.vb +++ b/VECTO/GUI/EngineForm.vb @@ -72,7 +72,14 @@ Public Class EngineForm End Sub Private Sub ToolStripBtOpen_Click(sender As Object, e As EventArgs) Handles ToolStripBtOpen.Click - If EngineFileBrowser.OpenDialog(_engFile) Then OpenEngineFile(EngineFileBrowser.Files(0)) + If EngineFileBrowser.OpenDialog(_engFile) Then + Try + OpenEngineFile(EngineFileBrowser.Files(0)) + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Engine File") + End Try + + End If End Sub Private Sub ToolStripBtSave_Click(sender As Object, e As EventArgs) Handles ToolStripBtSave.Click diff --git a/VECTO/GUI/GearboxForm.vb b/VECTO/GUI/GearboxForm.vb index 9a4cf4c3ba..e9b6148383 100644 --- a/VECTO/GUI/GearboxForm.vb +++ b/VECTO/GUI/GearboxForm.vb @@ -122,7 +122,13 @@ Public Class GearboxForm End Sub Private Sub ToolStripBtOpen_Click(sender As Object, e As EventArgs) Handles ToolStripBtOpen.Click - If GearboxFileBrowser.OpenDialog(_gbxFile) Then OpenGbx(GearboxFileBrowser.Files(0)) + If GearboxFileBrowser.OpenDialog(_gbxFile) Then + Try + OpenGbx(GearboxFileBrowser.Files(0)) + Catch ex As Exception + MsgBox("Failed to open Gearbox File: " + ex.Message) + End Try + End If End Sub Private Sub ToolStripBtSave_Click(sender As Object, e As EventArgs) Handles ToolStripBtSave.Click @@ -273,15 +279,15 @@ Public Class GearboxForm TbStartAcc.Text = gearbox.StartAcceleration.ToGUIFormat() Dim torqueConverter As ITorqueConverterEngineeringInputData = gearbox.TorqueConverter - If torqueConverter Is Nothing Then + If torqueConverter Is Nothing OrElse gearbox.Type.ManualTransmission() Then TbTCfile.Text = "" TbTCrefrpm.Text = "" TbTCinertia.Text = "" TBTCShiftPolygon.Text = "" Else TbTCfile.Text = If(torqueConverter.TCData Is Nothing, "", GetRelativePath(torqueConverter.TCData.Source, basePath)) - TbTCrefrpm.Text = torqueConverter.ReferenceRPM.AsRPM.ToGUIFormat() - TbTCinertia.Text = torqueConverter.Inertia.ToGUIFormat() + TbTCrefrpm.Text = If(torqueConverter.ReferenceRPM Is Nothing, "", torqueConverter.ReferenceRPM.AsRPM.ToGUIFormat()) + TbTCinertia.Text = If(torqueConverter.Inertia Is Nothing, "", torqueConverter.Inertia.ToGUIFormat()) TBTCShiftPolygon.Text = If(torqueConverter.ShiftPolygon Is Nothing, "", GetRelativePath(torqueConverter.ShiftPolygon.Source, basePath)) End If diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index 9431fd31b5..5fd2ee9399 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -358,7 +358,11 @@ Public Class MainForm If GearboxForm.WindowState = FormWindowState.Minimized Then GearboxForm.WindowState = FormWindowState.Normal GearboxForm.BringToFront() End If - GearboxForm.OpenGbx(file) + Try + GearboxForm.OpenGbx(file) + Catch ex As Exception + MsgBox("Failed to open Gearbox File: " + ex.Message) + End Try Case ".VVEH" If Not VehicleForm.Visible Then VehicleForm.Show() @@ -380,7 +384,11 @@ Public Class MainForm If EngineForm.WindowState = FormWindowState.Minimized Then EngineForm.WindowState = FormWindowState.Normal EngineForm.BringToFront() End If - EngineForm.OpenEngineFile(file) + Try + EngineForm.OpenEngineFile(file) + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Engine File") + End Try Case ".VECTO" OpenVECTOeditor(file) Case ".VSIG" @@ -959,8 +967,10 @@ lbFound: mode = ExecutionMode.Declaration Else mode = ExecutionMode.Engineering - Physics.FuelDensity = Cfg.FuelDens.SI(Of KilogramPerCubicMeter)() 'New SI(Cfg.FuelDens).Kilo.Gramm.Per.Cubic.Dezi.Meter.Cast(Of KilogramPerCubicMeter)() - Physics.AirDensity = Cfg.AirDensity.SI(Of KilogramPerCubicMeter)() 'New SI(Cfg.AirDensity).Kilo.Gramm.Per.Cubic.Meter.Cast(Of KilogramPerCubicMeter)() + Physics.FuelDensity = Cfg.FuelDens.SI(Of KilogramPerCubicMeter)() _ + 'New SI(Cfg.FuelDens).Kilo.Gramm.Per.Cubic.Dezi.Meter.Cast(Of KilogramPerCubicMeter)() + Physics.AirDensity = Cfg.AirDensity.SI(Of KilogramPerCubicMeter)() _ + 'New SI(Cfg.AirDensity).Kilo.Gramm.Per.Cubic.Meter.Cast(Of KilogramPerCubicMeter)() Physics.CO2PerFuelWeight = Cfg.Co2PerFc End If @@ -1276,7 +1286,11 @@ lbFound: If x = "<New>" Then VectoJobForm.VectoNew() Else - VectoJobForm.VECTOload2Form(x) + Try + VectoJobForm.VECTOload2Form(x) + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vecto Job File") + End Try End If VectoJobForm.Activate() diff --git a/VECTO/GUI/VectoJobForm.vb b/VECTO/GUI/VectoJobForm.vb index 73e5f4513c..bb1d0152ec 100644 --- a/VECTO/GUI/VectoJobForm.vb +++ b/VECTO/GUI/VectoJobForm.vb @@ -271,8 +271,11 @@ Public Class VectoJobForm If EngineForm.WindowState = FormWindowState.Minimized Then EngineForm.WindowState = FormWindowState.Normal EngineForm.BringToFront() End If - - If Not Trim(f) = "" Then EngineForm.OpenEngineFile(f) + Try + If Not Trim(f) = "" Then EngineForm.OpenEngineFile(f) + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Engine File") + End Try End Sub 'Open Gearbox Editor @@ -297,8 +300,11 @@ Public Class VectoJobForm If GearboxForm.WindowState = FormWindowState.Minimized Then GearboxForm.WindowState = FormWindowState.Normal GearboxForm.BringToFront() End If - - If Not Trim(f) = "" Then GearboxForm.OpenGbx(f) + Try + If Not Trim(f) = "" Then GearboxForm.OpenGbx(f) + Catch ex As Exception + MsgBox("Failed to open Gearbox File: " + ex.Message) + End Try End Sub #End Region @@ -312,7 +318,14 @@ Public Class VectoJobForm 'Open Private Sub ToolStripBtOpen_Click(sender As Object, e As EventArgs) Handles ToolStripBtOpen.Click - If JobfileFileBrowser.OpenDialog(VectoFile, False, "vecto") Then VECTOload2Form(JobfileFileBrowser.Files(0)) + If JobfileFileBrowser.OpenDialog(VectoFile, False, "vecto") Then + Try + VECTOload2Form(JobfileFileBrowser.Files(0)) + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vecto Job File") + End Try + + End If End Sub 'Save @@ -508,19 +521,20 @@ Public Class VectoJobForm TbOverspeed.Text = driver.OverSpeedEcoRoll.OverSpeed.AsKmph.ToGUIFormat() TbUnderSpeed.Text = driver.OverSpeedEcoRoll.UnderSpeed.AsKmph.ToGUIFormat() TbVmin.Text = driver.OverSpeedEcoRoll.MinSpeed.AsKmph.ToGUIFormat() - CbLookAhead.Checked = driver.Lookahead.Enabled - 'TbAlookahead.Text = CStr(VEC0.ALookahead) - tbLacMinSpeed.Text = driver.Lookahead.MinSpeed.AsKmph.ToGUIFormat() - 'TbVminLA.Text = CStr(VEC0.VMinLa) - tbLacPreviewFactor.Text = driver.Lookahead.LookaheadDistanceFactor.ToGUIFormat() - tbDfCoastingOffset.Text = driver.Lookahead.CoastingDecisionFactorOffset.ToGUIFormat() - tbDfCoastingScale.Text = driver.Lookahead.CoastingDecisionFactorScaling.ToGUIFormat() - - tbLacDfTargetSpeedFile.Text = If(driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup Is Nothing, "", - GetRelativePath(driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source, _basePath)) - tbLacDfVelocityDropFile.Text = If(driver.Lookahead.CoastingDecisionFactorVelocityDropLookup Is Nothing, "", - GetRelativePath(driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source, _basePath)) - + If Not driver.Lookahead Is Nothing Then + CbLookAhead.Checked = driver.Lookahead.Enabled + 'TbAlookahead.Text = CStr(VEC0.ALookahead) + tbLacMinSpeed.Text = driver.Lookahead.MinSpeed.AsKmph.ToGUIFormat() + 'TbVminLA.Text = CStr(VEC0.VMinLa) + tbLacPreviewFactor.Text = driver.Lookahead.LookaheadDistanceFactor.ToGUIFormat() + tbDfCoastingOffset.Text = driver.Lookahead.CoastingDecisionFactorOffset.ToGUIFormat() + tbDfCoastingScale.Text = driver.Lookahead.CoastingDecisionFactorScaling.ToGUIFormat() + + tbLacDfTargetSpeedFile.Text = If(driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup Is Nothing, "", + GetRelativePath(driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source, _basePath)) + tbLacDfVelocityDropFile.Text = If(driver.Lookahead.CoastingDecisionFactorVelocityDropLookup Is Nothing, "", + GetRelativePath(driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source, _basePath)) + End If '------------------------------------------------------------- DeclInit() @@ -615,8 +629,9 @@ Public Class VectoJobForm If Cfg.DeclMode Then auxEntry.TechnologyList.Clear() - auxEntry.TechnologyList.AddRange(lv0.SubItems(AuxViewColumns.AuxInputOrTech).Text.Split(";"c).Select( - Function(x) Trim(x))) + auxEntry.TechnologyList.AddRange( + lv0.SubItems(AuxViewColumns.AuxInputOrTech).Text.Split(";"c).Select( + Function(x) Trim(x))) Else auxEntry.Path.Init(GetPath(file), lv0.SubItems(AuxViewColumns.AuxInputOrTech).Text) End If diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb index 8e8d83c23c..55c1eabc19 100644 --- a/VECTO/Input Files/Gearbox.vb +++ b/VECTO/Input Files/Gearbox.vb @@ -28,8 +28,7 @@ Imports TUGraz.VectoCore.Utils <CustomValidation(GetType(Gearbox), "ValidateGearbox")> Public Class Gearbox Implements IGearboxEngineeringInputData, IGearboxDeclarationInputData, IAxleGearInputData, - ITorqueConverterEngineeringInputData, - ITorqueConverterDeclarationInputData + ITorqueConverterEngineeringInputData, ITorqueConverterDeclarationInputData Private _myPath As String Private _filePath As String @@ -116,7 +115,7 @@ Public Class Gearbox Return False End If - Return JSONFileWriter.Instance.SaveGearbox(Me, _filePath) + Return JSONFileWriter.Instance.SaveGearbox(Me, Me, _filePath) End Function @@ -440,6 +439,7 @@ Public Class Gearbox Public ReadOnly Property TCData As TableData Implements ITorqueConverterDeclarationInputData.TCData Get + If Not File.Exists(_torqueConverterFile.FullPath) Then Return Nothing Return VectoCSVFile.Read(_torqueConverterFile.FullPath) End Get End Property diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb index 9670e4db67..38931b6bb0 100644 --- a/VECTO/Input Files/VectoJob.vb +++ b/VECTO/Input Files/VectoJob.vb @@ -15,6 +15,7 @@ Imports System.Collections.Generic Imports System.ComponentModel.DataAnnotations Imports System.IO Imports System.Linq +Imports System.Runtime.Remoting.Messaging Imports System.Text Imports Newtonsoft.Json.Linq Imports TUGraz.VECTO.Input_Files @@ -68,16 +69,16 @@ Public Class VectoJob Public UnderSpeed As Double Public EcoRollOn As Boolean - Public SavedInDeclMode As Boolean - Private _vehicleInputData As JSONComponentInputData - Private _engineInputData As JSONComponentInputData - Private _gearboxInputData As JSONComponentInputData Public LookAheadMinSpeed As Double Public Property StartStopMaxSpeed As Double Public Property StartStopTime As Double + 'Private _vehicleInputData As JSONComponentInputData + 'Private _engineInputData As JSONComponentInputData + 'Private _gearboxInputData As JSONComponentInputData + Public Class AuxEntry Public Type As String Public ReadOnly Path As SubPath @@ -184,7 +185,7 @@ Public Class VectoJob Public ReadOnly Property IDriverDeclarationInputData_SavedInDeclarationMode As Boolean _ Implements IDriverDeclarationInputData.SavedInDeclarationMode Get - Return SavedInDeclMode + Return Cfg.DeclMode End Get End Property @@ -310,9 +311,9 @@ Public Class VectoJob Private Shared Function ValidateEngineOnlyJob(vectoJob As VectoJob, executionMode As ExecutionMode) As ValidationResult Dim result As IList(Of ValidationResult) = New List(Of ValidationResult) - vectoJob._engineInputData = New JSONComponentInputData(vectoJob._engineFile.FullPath) + 'vectoJob._engineInputData = New JSONComponentInputData(vectoJob._engineFile.FullPath) - If vectoJob._engineInputData.EngineInputData Is Nothing Then _ + If vectoJob.EngineInputData Is Nothing Then _ result.Add(New ValidationResult("Engine File is missing or invalid")) If result.Any() Then Return _ @@ -326,18 +327,22 @@ Public Class VectoJob Dim jobData As VectoRunData - vectoJob._vehicleInputData = New JSONComponentInputData(vectoJob._vehicleFile.FullPath) - vectoJob._engineInputData = New JSONComponentInputData(vectoJob._engineFile.FullPath) - vectoJob._gearboxInputData = New JSONComponentInputData(vectoJob._gearboxFile.FullPath) + 'vectoJob._vehicleInputData = New JSONComponentInputData(vectoJob._vehicleFile.FullPath) + 'vectoJob._engineInputData = New JSONComponentInputData(vectoJob._engineFile.FullPath) + 'vectoJob._gearboxInputData = New JSONComponentInputData(vectoJob._gearboxFile.FullPath) Dim result As IList(Of ValidationResult) = New List(Of ValidationResult) - If vectoJob._vehicleInputData.VehicleInputData Is Nothing Then _ + Dim vehicleInputData As IVehicleEngineeringInputData = vectoJob.VehicleInputData + Dim engineInputData As IEngineEngineeringInputData = vectoJob.EngineInputData + Dim gearboxInputData As IGearboxEngineeringInputData = vectoJob.GearboxInputData + + If vehicleInputData Is Nothing Then _ result.Add(New ValidationResult("Vehicle File is missing or invalid")) - If vectoJob._engineInputData.EngineInputData Is Nothing Then _ + If engineInputData Is Nothing Then _ result.Add(New ValidationResult("Engine File is missing or invalid")) - If vectoJob._gearboxInputData.GearboxInputData Is Nothing Then _ + If gearboxInputData Is Nothing Then _ result.Add(New ValidationResult("Gearbox File is missing or invalid")) If result.Any() Then @@ -346,13 +351,13 @@ Public Class VectoJob End If Try If mode = ExecutionMode.Declaration Then - If Not vectoJob._vehicleInputData.VehicleInputData.SavedInDeclarationMode Then + If Not vehicleInputData.SavedInDeclarationMode Then result.Add(New ValidationResult("Vehicle File is not in Declaration Mode")) End If - If Not vectoJob._engineInputData.EngineInputData.SavedInDeclarationMode Then + If Not engineInputData.SavedInDeclarationMode Then result.Add(New ValidationResult("Engine File is not in Declaration Mode")) End If - If Not vectoJob._gearboxInputData.GearboxInputData.SavedInDeclarationMode Then + If Not gearboxInputData.SavedInDeclarationMode Then result.Add(New ValidationResult("Gearbox File is not in Declaration Mode")) End If If result.Any() Then @@ -364,13 +369,13 @@ Public Class VectoJob jobData = dataFactory.NextRun().First() Else - If vectoJob._vehicleInputData.VehicleInputData.SavedInDeclarationMode Then + If vehicleInputData.SavedInDeclarationMode Then result.Add(New ValidationResult("Vehicle File is not in Engineering Mode")) End If - If vectoJob._engineInputData.EngineInputData.SavedInDeclarationMode Then + If engineInputData.SavedInDeclarationMode Then result.Add(New ValidationResult("Engine File is not in Engineering Mode")) End If - If vectoJob._gearboxInputData.GearboxInputData.SavedInDeclarationMode Then + If gearboxInputData.SavedInDeclarationMode Then result.Add(New ValidationResult("Gearbox File is not in Engineering Mode")) End If If result.Any() Then @@ -393,10 +398,10 @@ Public Class VectoJob Catch ex As Exception Return New ValidationResult(ex.Message) - Finally - vectoJob._vehicleInputData = Nothing - vectoJob._engineInputData = Nothing - vectoJob._gearboxInputData = Nothing + 'Finally + ' vectoJob._vehicleInputData = Nothing + ' vectoJob._engineInputData = Nothing + ' vectoJob._gearboxInputData = Nothing End Try End Function @@ -410,96 +415,110 @@ Public Class VectoJob Public ReadOnly Property IDeclarationInputDataProvider_VehicleInputData As IVehicleDeclarationInputData _ Implements IDeclarationInputDataProvider.VehicleInputData Get - Return _vehicleInputData.VehicleInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).VehicleInputData End Get End Property - Public Function IDeclarationInputDataProvider_JobInputData() As IDeclarationJobInputData _ - Implements IDeclarationInputDataProvider.JobInputData - Return Me - End Function - Public ReadOnly Property VehicleInputData As IVehicleEngineeringInputData _ Implements IEngineeringInputDataProvider.VehicleInputData Get - Return _vehicleInputData.VehicleInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).VehicleInputData End Get End Property + + Public Function IDeclarationInputDataProvider_JobInputData() As IDeclarationJobInputData _ + Implements IDeclarationInputDataProvider.JobInputData + Return Me + End Function + + Public ReadOnly Property IDeclarationInputDataProvider_GearboxInputData As IGearboxDeclarationInputData _ Implements IDeclarationInputDataProvider.GearboxInputData Get - Return _gearboxInputData.GearboxInputData + If Not File.Exists(_gearboxFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_gearboxFile.FullPath).GearboxInputData End Get End Property Public ReadOnly Property GearboxInputData As IGearboxEngineeringInputData _ Implements IEngineeringInputDataProvider.GearboxInputData Get - Return _gearboxInputData.GearboxInputData + If Not File.Exists(_gearboxFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_gearboxFile.FullPath).GearboxInputData End Get End Property Public ReadOnly Property IDeclarationInputDataProvider_TorqueConverterInputData As ITorqueConverterDeclarationInputData _ Implements IDeclarationInputDataProvider.TorqueConverterInputData Get - Return _gearboxInputData.TorqueConverterInputData + If Not File.Exists(_gearboxFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_gearboxFile.FullPath).TorqueConverterInputData End Get End Property Public ReadOnly Property TorqueConverterInputData As ITorqueConverterEngineeringInputData _ Implements IEngineeringInputDataProvider.TorqueConverterInputData Get - Return _gearboxInputData.TorqueConverterInputData + If Not File.Exists(_gearboxFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_gearboxFile.FullPath).TorqueConverterInputData End Get End Property Public ReadOnly Property IDeclarationInputDataProvider_AxleGearInputData As IAxleGearInputData _ Implements IDeclarationInputDataProvider.AxleGearInputData Get - Return _gearboxInputData.AxleGearInputData + If Not File.Exists(_gearboxFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_gearboxFile.FullPath).AxleGearInputData End Get End Property Public ReadOnly Property AxleGearInputData As IAxleGearInputData _ Implements IEngineeringInputDataProvider.AxleGearInputData Get - Return _gearboxInputData.AxleGearInputData + If Not File.Exists(_gearboxFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_gearboxFile.FullPath).AxleGearInputData End Get End Property Public ReadOnly Property DeclarationInputDataProviderAngledriveInputData As IAngledriveInputData _ Implements IDeclarationInputDataProvider.AngledriveInputData Get - Return _vehicleInputData.AngledriveInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).AngledriveInputData End Get End Property Public ReadOnly Property AngledriveInputData As IAngledriveInputData _ Implements IEngineeringInputDataProvider.AngledriveInputData Get - Return _vehicleInputData.AngledriveInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).AngledriveInputData End Get End Property Public ReadOnly Property IDeclarationInputDataProvider_EngineInputData As IEngineDeclarationInputData _ Implements IDeclarationInputDataProvider.EngineInputData Get - Return _engineInputData.EngineInputData + If Not File.Exists(_engineFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_engineFile.FullPath).EngineInputData End Get End Property Public ReadOnly Property EngineInputData As IEngineEngineeringInputData _ Implements IEngineeringInputDataProvider.EngineInputData Get - Return _engineInputData.EngineInputData + If Not File.Exists(_engineFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_engineFile.FullPath).EngineInputData End Get End Property Public Function AuxiliaryInputData() As IAuxiliariesEngineeringInputData _ Implements IEngineeringInputDataProvider.AuxiliaryInputData - Return _vehicleInputData.AuxiliaryInputData() + Return Me End Function Public Function IDeclarationInputDataProvider_AuxiliaryInputData() As IAuxiliariesDeclarationInputData _ @@ -511,14 +530,16 @@ Public Class VectoJob Public ReadOnly Property IDeclarationInputDataProvider_RetarderInputData As IRetarderInputData _ Implements IDeclarationInputDataProvider.RetarderInputData Get - Return _vehicleInputData.RetarderInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).RetarderInputData End Get End Property Public ReadOnly Property RetarderInputData As IRetarderInputData _ Implements IEngineeringInputDataProvider.RetarderInputData Get - Return _vehicleInputData.RetarderInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).RetarderInputData End Get End Property @@ -539,14 +560,15 @@ Public Class VectoJob Public ReadOnly Property PTOTransmissionInputData As IPTOTransmissionInputData _ Implements IEngineeringInputDataProvider.PTOTransmissionInputData Get - Return _vehicleInputData.PTOTransmissionInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).PTOTransmissionInputData End Get End Property Public ReadOnly Property SavedInDeclarationMode As Boolean Implements IDeclarationJobInputData.SavedInDeclarationMode Get - Return SavedInDeclMode + Return Cfg.DeclMode End Get End Property @@ -561,13 +583,15 @@ Public Class VectoJob Public ReadOnly Property IEngineeringJobInputData_Vehicle As IVehicleEngineeringInputData _ Implements IEngineeringJobInputData.Vehicle Get - Return _vehicleInputData.VehicleInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).VehicleInputData End Get End Property Public ReadOnly Property Vehicle As IVehicleDeclarationInputData Implements IDeclarationJobInputData.Vehicle Get - Return _vehicleInputData.VehicleInputData + If Not File.Exists(_vehicleFile.FullPath) Then Return Nothing + Return New JSONComponentInputData(_vehicleFile.FullPath).VehicleInputData End Get End Property @@ -615,7 +639,7 @@ Public Class VectoJob Public ReadOnly Property IAuxiliariesDeclarationInputData_SavedInDeclarationMode As Boolean _ Implements IAuxiliariesDeclarationInputData.SavedInDeclarationMode Get - Return SavedInDeclMode + Return Cfg.DeclMode End Get End Property diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb index f43c5b6fde..8d983d9737 100644 --- a/VECTO/Input Files/Vehicle.vb +++ b/VECTO/Input Files/Vehicle.vb @@ -304,7 +304,7 @@ Public Class Vehicle Public ReadOnly Property CurbWeightChassis As Kilogram Implements IVehicleDeclarationInputData.CurbWeightChassis Get - Return MassExtra.SI(Of Kilogram)() + Return Mass.SI(Of Kilogram)() End Get End Property @@ -350,7 +350,7 @@ Public Class Vehicle Public ReadOnly Property CurbWeightExtra As Kilogram Implements IVehicleEngineeringInputData.CurbWeightExtra Get - Return Mass.SI(Of Kilogram)() + Return MassExtra.SI(Of Kilogram)() End Get End Property diff --git a/VECTO/MainModule.vb b/VECTO/MainModule.vb index 2c751604f6..86ff56db40 100644 --- a/VECTO/MainModule.vb +++ b/VECTO/MainModule.vb @@ -52,8 +52,8 @@ Module MainModule If (String.IsNullOrEmpty(filePath) OrElse String.IsNullOrEmpty(basePath)) Then Return "" End If - If (Path.GetDirectoryName(filePath).Equals(basePath, StringComparison.OrdinalIgnoreCase)) Then - Return Path.GetFileName(filePath) + If (Path.GetDirectoryName(filePath).StartsWith(basePath, StringComparison.OrdinalIgnoreCase)) Then + Return Path.GetFullPath(filePath).Substring(basePath.Length + If(basePath.EndsWith("\"), 0, 1)) End If Return filePath End Function diff --git a/VECTO/OutputData/JSONWriter.vb b/VECTO/OutputData/JSONWriter.vb index b43ed53f3b..de47c9e94e 100644 --- a/VECTO/OutputData/JSONWriter.vb +++ b/VECTO/OutputData/JSONWriter.vb @@ -1,9 +1,11 @@ Imports System.Collections.Generic +Imports System.IO Imports System.Linq Imports Newtonsoft.Json.Linq Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCore.InputData.Impl +Imports TUGraz.VectoCore.Models.Declaration Imports TUGraz.VectoCore.Models.SimulationComponent.Data Public Class JSONFileWriter @@ -41,13 +43,13 @@ Public Class JSONFileWriter body.Add("ModelName", eng.ModelName) - body.Add("Displacement", eng.Displacement.Value()) - body.Add("IdlingSpeed", eng.IdleSpeed.Value()) + body.Add("Displacement", eng.Displacement.ConvertTo().Cubic.Centi.Meter.Value().ToString()) + body.Add("IdlingSpeed", eng.IdleSpeed.AsRPM) body.Add("Inertia", eng.Inertia.Value()) - body.Add("FullLoadCurve", eng.FullLoadCurve.Source) + body.Add("FullLoadCurve", GetRelativePath(eng.FullLoadCurve.Source, Path.GetDirectoryName(filename))) - body.Add("FuelMap", eng.FuelConsumptionMap.Source) + body.Add("FuelMap", GetRelativePath(eng.FuelConsumptionMap.Source, Path.GetDirectoryName(filename))) body.Add("WHTC-Urban", eng.WHTCUrban) body.Add("WHTC-Rural", eng.WHTCRural) @@ -59,9 +61,9 @@ Public Class JSONFileWriter Return json.WriteFile(filename) End Function - Public Function SaveGearbox(gbx As IGearboxEngineeringInputData, filename As String) As Boolean + Public Function SaveGearbox(gbx As IGearboxEngineeringInputData, axl As IAxleGearInputData, filename As String) _ + As Boolean - Dim i As Integer Dim json As New JSONWriter 'Header @@ -83,18 +85,27 @@ Public Class JSONFileWriter body.Add("TracInt", gbx.TractionInterruption.Value()) Dim ls As New List(Of Dictionary(Of String, Object)) + Dim axlgDict As New Dictionary(Of String, Object) + axlgDict.Add("Ratio", axl.Ratio) + If axl.LossMap Is Nothing Then + axlgDict.Add("Efficiency", axl.Efficiency) + Else + axlgDict.Add("LossMap", GetRelativePath(axl.LossMap.Source, Path.GetDirectoryName(filename))) + End If + ls.Add(axlgDict) + For Each gear As ITransmissionInputData In gbx.Gears Dim gearDict As New Dictionary(Of String, Object) gearDict.Add("Ratio", gear.Ratio) If gear.LossMap Is Nothing Then gearDict.Add("Efficiency", gear.Efficiency) Else - gearDict.Add("LossMap", gear.LossMap.Source) - End If - If i > 0 Then - gearDict.Add("ShiftPolygon", gear.ShiftPolygon.Source) - gearDict.Add("MaxTorque", gear.MaxTorque.Value()) + gearDict.Add("LossMap", GetRelativePath(gear.LossMap.Source, Path.GetDirectoryName(filename))) End If + gearDict.Add("ShiftPolygon", If _ + (gbx.SavedInDeclarationMode AndAlso Not gear.ShiftPolygon Is Nothing, + GetRelativePath(gear.ShiftPolygon.Source, Path.GetDirectoryName(filename)), "")) + gearDict.Add("MaxTorque", If(gear.MaxTorque Is Nothing, "", gear.MaxTorque.Value().ToString())) ls.Add(gearDict) Next @@ -106,26 +117,29 @@ Public Class JSONFileWriter 'body.Add("EaryShiftUp", gbx.ShiftInside) body.Add("StartTqReserve", gbx.StartTorqueReserve) - body.Add("StartSpeed", gbx.StartSpeed) + body.Add("StartSpeed", gbx.StartSpeed.Value()) body.Add("StartAcc", gbx.StartAcceleration.Value()) body.Add("GearboxType", gbx.Type) Dim torqueConverter As ITorqueConverterEngineeringInputData = gbx.TorqueConverter Dim torqueConverterDict As New Dictionary(Of String, Object) - torqueConverterDict.Add("Enabled", Not torqueConverter Is Nothing) - If Not torqueConverter Is Nothing Then - torqueConverterDict.Add("File", torqueConverter.TCData.Source) + torqueConverterDict.Add("Enabled", Not torqueConverter Is Nothing AndAlso gbx.Type.AutomaticTransmission()) + If gbx.Type.AutomaticTransmission() AndAlso Not torqueConverter Is Nothing Then + torqueConverterDict.Add("File", GetRelativePath(torqueConverter.TCData.Source, Path.GetDirectoryName(filename))) torqueConverterDict.Add("RefRPM", torqueConverter.ReferenceRPM.AsRPM) torqueConverterDict.Add("Inertia", torqueConverter.Inertia.Value()) - torqueConverterDict.Add("ShiftPolygon", torqueConverter.ShiftPolygon.Source) + torqueConverterDict.Add("ShiftPolygon", + If _ + (gbx.SavedInDeclarationMode AndAlso Not torqueConverter.ShiftPolygon Is Nothing, + GetRelativePath(torqueConverter.ShiftPolygon.Source, Path.GetDirectoryName(filename)), "")) End If body.Add("TorqueConverter", torqueConverterDict) body.Add("DownshiftAferUpshiftDelay", gbx.DownshiftAferUpshiftDelay.Value()) body.Add("UpshiftAfterDownshiftDelay", gbx.UpshiftAfterDownshiftDelay.Value()) - body.Add("UpshiftMinAcceleration", gbx.UpshiftMinAcceleration) + body.Add("UpshiftMinAcceleration", gbx.UpshiftMinAcceleration.Value()) json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) @@ -151,9 +165,8 @@ Public Class JSONFileWriter Else retarderOut.Add("Type", retarder.Type.GetName()) retarderOut.Add("Ratio", retarder.Ratio) - If Not retarder.LossMap Is Nothing Then - retarderOut.Add("File", retarder.LossMap.Source) - End If + retarderOut.Add("File", + If(retarder.Type.IsDedicatedComponent AndAlso Not retarder.LossMap Is Nothing, retarder.LossMap.Source, "")) End If Dim ptoOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) @@ -161,33 +174,43 @@ Public Class JSONFileWriter ptoOut.Add("Type", "None") Else ptoOut.Add("Type", pto.PTOTransmissionType) - ptoOut.Add("LossMap", pto.PTOLossMap.Source) - ptoOut.Add("Cycle", pto.PTOCycle.Source) + ptoOut.Add("LossMap", + If(pto.PTOTransmissionType <> "None" AndAlso Not pto.PTOLossMap Is Nothing, pto.PTOLossMap.Source, "")) + ptoOut.Add("Cycle", + If(pto.PTOTransmissionType <> "None" AndAlso Not pto.PTOCycle Is Nothing, pto.PTOCycle.Source, "")) End If Dim angledriveOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { {"Type", angledrive.Type.ToString()}, {"Ratio", angledrive.Ratio}, - {"LossMap", angledrive.LossMap.Source}} + {"LossMap", + If _ + (angledrive.Type = AngledriveType.SeparateAngledrive AndAlso Not angledrive.LossMap Is Nothing, + angledrive.LossMap.Source, "")}} Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { {"SavedInDeclMode", Cfg.DeclMode}, {"VehCat", vehicle.VehicleCategory.ToString()}, {"CurbWeight", vehicle.CurbWeightChassis.Value()}, - {"CurbWeightExtra", vehicle.CurbWeightExtra}, - {"Loading", vehicle.Loading}, + {"CurbWeightExtra", vehicle.CurbWeightExtra.Value()}, + {"Loading", vehicle.Loading.Value()}, {"MassMax", vehicle.GrossVehicleMassRating.ConvertTo().Ton.Value()}, {"CdA", vehicle.AirDragArea.Value()}, - {"rdyn", vehicle.DynamicTyreRadius}, + {"rdyn", vehicle.DynamicTyreRadius.ConvertTo().Milli.Meter.Value()}, {"CdCorrMode", vehicle.CrossWindCorrectionMode.GetName()}, - {"CdCorrFile", vehicle.CrosswindCorrectionMap.Source}, + {"CdCorrFile", + If _ + ( + (vehicle.CrossWindCorrectionMode = CrossWindCorrectionMode.SpeedDependentCorrectionFactor OrElse + vehicle.CrossWindCorrectionMode = CrossWindCorrectionMode.VAirBetaLookupTable) AndAlso + Not vehicle.CrosswindCorrectionMap Is Nothing, vehicle.CrosswindCorrectionMap.Source, "")}, {"Retarder", retarderOut}, {"Angledrive", angledriveOut}, {"PTO", ptoOut}, {"AxleConfig", New Dictionary(Of String, Object) From { {"Type", vehicle.AxleConfiguration.GetName()}, {"Axles", (From axle In vehicle.Axles Select New Dictionary(Of String, Object) From { - {"Inertia", axle.Inertia}, + {"Inertia", axle.Inertia.Value()}, {"Wheels", axle.Wheels}, {"AxleWeightShare", axle.AxleWeightShare}, {"TwinTyres", axle.TwinTyres}, @@ -216,13 +239,14 @@ Public Class JSONFileWriter 'Body Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - body.Add("SavedInDeclMode", Cfg.DeclMode) 'SavedInDeclMode = Cfg.DeclMode Dim job As IEngineeringJobInputData = input.JobInputData() Dim aux As IAuxiliariesEngineeringInputData = input.AuxiliaryInputData() Dim driver As IDriverEngineeringInputData = input.DriverInputData + body.Add("SavedInDeclMode", job.SavedInDeclarationMode) + body.Add("EngineOnlyMode", job.EngineOnlyMode) If job.EngineOnlyMode Then @@ -234,14 +258,9 @@ Public Class JSONFileWriter End If 'Main Files - body.Add("VehicleFile", job.Vehicle.Source) - body.Add("EngineFile", input.EngineInputData.Source) - body.Add("GearboxFile", input.GearboxInputData.Source) - - 'Cycles - For Each cycle As ICycleData In job.Cycles - body.Add("Cycles", cycle.CycleData.Source) - Next + body.Add("VehicleFile", GetRelativePath(job.Vehicle.Source, Path.GetDirectoryName(filename))) + body.Add("EngineFile", GetRelativePath(input.EngineInputData.Source, Path.GetDirectoryName(filename))) + body.Add("GearboxFile", GetRelativePath(input.GearboxInputData.Source, Path.GetDirectoryName(filename))) 'AA-TB 'ADVANCED AUXILIARIES @@ -250,41 +269,48 @@ Public Class JSONFileWriter body.Add("AdvancedAuxiliaryFilePath", aux.AdvancedAuxiliaryFilePath) Dim pAdd As Double = 0.0 - Dim auxOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + Dim auxList As List(Of Object) = New List(Of Object) For Each auxEntry As IAuxiliaryEngineeringInputData In aux.Auxiliaries If auxEntry.AuxiliaryType = AuxiliaryDemandType.Constant Then pAdd += auxEntry.ConstantPowerDemand.Value() Continue For End If + Dim auxOut As Dictionary(Of String, Object) = New Dictionary(Of String, Object) Dim engineeringAuxEntry As IAuxiliaryDeclarationInputData = TryCast(auxEntry, IAuxiliaryDeclarationInputData) If engineeringAuxEntry Is Nothing Then auxOut.Add("Type", auxEntry.AuxiliaryType.ToString()) auxOut.Add("Path", auxEntry.DemandMap.Source) + auxOut.Add("Technology", New String() {}) Else auxOut.Add("ID", auxEntry.ID) auxOut.Add("Technology", engineeringAuxEntry.Technology) + auxOut.Add("Type", AuxiliaryTypeHelper.ParseKey(auxEntry.ID).Name()) End If - + auxList.Add(auxOut) Next - body.Add("Aux", auxOut) + body.Add("Aux", auxList) - If Not Cfg.DeclMode Then + If Not job.SavedInDeclarationMode Then body.Add("Padd", pAdd) End If - body.Add("VACC", driver.AccelerationCurve.Source) + If Not job.SavedInDeclarationMode Then + body.Add("VACC", driver.AccelerationCurve.Source) + End If body.Add("StartStop", New Dictionary(Of String, Object) From { {"Enabled", driver.StartStop.Enabled}, {"MaxSpeed", driver.StartStop.MaxSpeed.Value()}, {"MinTime", driver.StartStop.MinTime.Value()}, {"Delay", driver.StartStop.Delay.Value()}}) - body.Add("LAC", New Dictionary(Of String, Object) From { - {"Enabled", driver.Lookahead.Enabled}, - {"PreviewDistanceFactor", driver.Lookahead.LookaheadDistanceFactor}, - {"DF_offset", driver.Lookahead.CoastingDecisionFactorOffset}, - {"DF_scaling", driver.Lookahead.CoastingDecisionFactorScaling}, - {"DF_targetSpeedLookup", driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source}, - {"Df_velocityDropLookup", driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source}}) + If Not job.SavedInDeclarationMode Then + body.Add("LAC", New Dictionary(Of String, Object) From { + {"Enabled", driver.Lookahead.Enabled}, + {"PreviewDistanceFactor", driver.Lookahead.LookaheadDistanceFactor}, + {"DF_offset", driver.Lookahead.CoastingDecisionFactorOffset}, + {"DF_scaling", driver.Lookahead.CoastingDecisionFactorScaling}, + {"DF_targetSpeedLookup", driver.Lookahead.CoastingDecisionFactorTargetSpeedLookup.Source}, + {"Df_velocityDropLookup", driver.Lookahead.CoastingDecisionFactorVelocityDropLookup.Source}}) + End If 'Overspeed / EcoRoll Dim overspeedDic As Dictionary(Of String, Object) = New Dictionary(Of String, Object) @@ -296,6 +322,12 @@ Public Class JSONFileWriter overspeedDic.Add("UnderSpeed", driver.OverSpeedEcoRoll.UnderSpeed.Value()) body.Add("OverSpeedEcoRoll", overspeedDic) + 'Cycles + If Not job.SavedInDeclarationMode Then + body.Add("Cycles", + job.Cycles.Select(Function(x) GetRelativePath(x.CycleData.Source, Path.GetDirectoryName(filename))).ToArray()) + End If + json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) Return json.WriteFile(filename) End Function diff --git a/VectoCommon/VectoCommon/Models/RetarderType.cs b/VectoCommon/VectoCommon/Models/RetarderType.cs index e17974111b..496af4853f 100644 --- a/VectoCommon/VectoCommon/Models/RetarderType.cs +++ b/VectoCommon/VectoCommon/Models/RetarderType.cs @@ -86,5 +86,10 @@ namespace TUGraz.VectoCommon.Models throw new ArgumentOutOfRangeException("retarder", retarder, null); } } + + public static bool IsDedicatedComponent(this RetarderType retarder) + { + return retarder == RetarderType.TransmissionInputRetarder || retarder == RetarderType.TransmissionOutputRetarder; + } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs index 94f2717f73..f72f374986 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs @@ -70,8 +70,9 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { get { - return ReadTableData(Body.GetEx(JsonKeys.Gearbox_TorqueConverter) - .GetEx<string>("ShiftPolygon"), "TorqueConverter Shift Polygon", false); + return Body[JsonKeys.Gearbox_TorqueConverter] != null && Body[JsonKeys.Gearbox_TorqueConverter]["ShiftPolygon"] != null ? + ReadTableData(Body.GetEx(JsonKeys.Gearbox_TorqueConverter) + .GetEx<string>("ShiftPolygon"), "TorqueConverter Shift Polygon", false):null; } } } @@ -266,8 +267,10 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON Efficiency = gear[JsonKeys.Gearbox_Gear_Efficiency] != null ? gear[JsonKeys.Gearbox_Gear_Efficiency].Value<double>() : double.NaN, - ShiftPolygon = ReadTableData(gear.GetEx<string>(JsonKeys.Gearbox_Gear_ShiftPolygonFile), - string.Format("Gear {0} shiftPolygon", gearNumber), false), + ShiftPolygon = gear[JsonKeys.Gearbox_Gear_ShiftPolygonFile] != null + ? ReadTableData(gear.GetEx<string>(JsonKeys.Gearbox_Gear_ShiftPolygonFile), + string.Format("Gear {0} shiftPolygon", gearNumber), false) + : null, }; } @@ -349,10 +352,10 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { get { - return + return Body[JsonKeys.Gearbox_TorqueConverter_ReferenceRPM] != null ? Body.GetEx(JsonKeys.Gearbox_TorqueConverter) .GetEx<double>(JsonKeys.Gearbox_TorqueConverter_ReferenceRPM) - .RPMtoRad(); + .RPMtoRad() : null; } } @@ -360,9 +363,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { get { - return - ReadTableData(Body.GetEx(JsonKeys.Gearbox_TorqueConverter).GetEx<string>(JsonKeys.Gearbox_TorqueConverter_TCMap), - "TorqueConverter Data", false); + return Body[JsonKeys.Gearbox_TorqueConverter] != null && + Body[JsonKeys.Gearbox_TorqueConverter][JsonKeys.Gearbox_TorqueConverter_TCMap] != null + ? ReadTableData(Body.GetEx(JsonKeys.Gearbox_TorqueConverter).GetEx<string>(JsonKeys.Gearbox_TorqueConverter_TCMap), + "TorqueConverter Data", false) + : null; } } @@ -370,10 +375,10 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { get { - return + return Body[JsonKeys.Gearbox_TorqueConverter] != null && Body[JsonKeys.Gearbox_TorqueConverter][JsonKeys.Gearbox_TorqueConverter_Inertia] != null ? Body.GetEx(JsonKeys.Gearbox_TorqueConverter) .GetEx<double>(JsonKeys.Gearbox_TorqueConverter_Inertia) - .SI<KilogramSquareMeter>(); + .SI<KilogramSquareMeter>() : null; } } diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index 82dfbc07ba..bbd61cfc25 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -394,6 +394,10 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { get { + if (Body[JsonKeys.DriverData_LookaheadCoasting] == null) { + return null; + } + var lac = Body.GetEx(JsonKeys.DriverData_LookaheadCoasting); var distanceScalingFactor = lac["PreviewDistanceFactor"] != null ? lac.GetEx<double>("PreviewDistanceFactor") diff --git a/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs b/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs index e037090a0d..ade1eb6c92 100644 --- a/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs +++ b/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using TUGraz.VectoCommon.Models; using TUGraz.VectoCore.Configuration; @@ -32,6 +33,11 @@ namespace TUGraz.VectoCore.Models.Declaration return StrToAux.TryGetValue(s, out aux) ? aux : AuxiliaryType.Fan; } + public static AuxiliaryType ParseKey(string s) + { + return AuxToKey.FirstOrDefault(x => x.Value.Equals(s, StringComparison.InvariantCultureIgnoreCase)).Key; + } + public static string ToString(AuxiliaryType t) { return AuxToStr[t]; -- GitLab