diff --git a/VECTO/GUI/GearboxForm.vb b/VECTO/GUI/GearboxForm.vb index 36231db0426ce74f8714dca3e0f668a0aaf57432..1151983a30e8928e9cf90550119a46592827bfed 100644 --- a/VECTO/GUI/GearboxForm.vb +++ b/VECTO/GUI/GearboxForm.vb @@ -20,6 +20,7 @@ Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore.Configuration +Imports TUGraz.VectoCore.InputData.FileIO.JSON Imports TUGraz.VectoCore.InputData.Impl Imports TUGraz.VectoCore.Models.Declaration Imports TUGraz.VectoCore.Models.SimulationComponent.Data @@ -820,11 +821,13 @@ Public Class GearboxForm Dim vectoJob As VectoJob = New VectoJob() With {.FilePath = VectoJobForm.VECTOfile} Dim vectoOk As Boolean = vectoJob.ReadFile() - Dim vehicle As Vehicle = New Vehicle() With {.FilePath = vectoJob.PathVeh(False)} - Dim vehicleOk As Boolean = vehicle.ReadFile(False) + + Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(vectoJob.PathVeh(False)), + IEngineeringInputDataProvider) + Dim vehicle As IVehicleEngineeringInputData = inputData.VehicleInputData 'Fld - If fldOk AndAlso vectoOk AndAlso vehicleOk Then + If fldOk AndAlso vectoOk AndAlso Not vehicle Is Nothing Then s = New Series s.Points.DataBindXY(fullLoadCurve.EngineSpeedList, fullLoadCurve.MaxTorqueList) @@ -910,13 +913,13 @@ Public Class GearboxForm End Sub - Private Function GetShiftLines(engineFullLoadCurve As EngineFullLoadCurve, vehicle As Vehicle, + Private Function GetShiftLines(engineFullLoadCurve As EngineFullLoadCurve, vehicle As IVehicleEngineeringInputData, gears As IList(Of ITransmissionInputData), gear As Integer) As ShiftPolygon Dim engine As CombustionEngineData = ConvertToEngineData(engineFullLoadCurve, VectoJobForm.EngineIdleSpeed) If gears.Count <= 1 Then Return Nothing End If - Dim rDyn As Meter = (vehicle.DynamicTyreRadius / 1000.0).SI(Of Meter)() + Dim rDyn As Meter = vehicle.DynamicTyreRadius If rDyn.IsEqual(0) Then If (vehicle.Axles.Count < 2) Then Return Nothing diff --git a/VECTO/GUI/VectoJobForm.vb b/VECTO/GUI/VectoJobForm.vb index ff84f9c9ecffae0a57a1327654afb0d381ff74c9..6d6bf71c96f77e4124b709e6c7f69ad44dd01f97 100644 --- a/VECTO/GUI/VectoJobForm.vb +++ b/VECTO/GUI/VectoJobForm.vb @@ -17,8 +17,10 @@ Imports System.Linq Imports System.Text.RegularExpressions Imports System.Windows.Forms.DataVisualization.Charting Imports TUGraz.VECTO.Input_Files +Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCommon.Utils +Imports TUGraz.VectoCore.InputData.FileIO.JSON Imports TUGraz.VectoCore.Models.Declaration ''' <summary> @@ -984,7 +986,7 @@ lbDlog: #End Region Public Sub UpdatePic() - Dim VEH0 As New Vehicle + Dim i As Integer Dim pmax As Double @@ -996,8 +998,7 @@ lbDlog: Dim HDVclass As String - 'Dim m0 As - + Dim s As Series Dim a As ChartArea Dim img As Bitmap @@ -1013,14 +1014,16 @@ lbDlog: PicVehicle.Image = Nothing PicBox.Image = Nothing + Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(TbVEH.Text), + IEngineeringInputDataProvider) + Dim vehicle = inputData.VehicleInputData - VEH0.FilePath = fFileRepl(TbVEH.Text, GetPath(VECTOfile)) - If VEH0.ReadFile(False) Then - Dim maxMass = (VEH0.MassMax * 1000).SI(Of Kilogram)() 'CSng(fTextboxToNumString(TbMassMass.Text)) + If Not vehicle Is Nothing Then + Dim maxMass = vehicle.GrossVehicleMassRating 'CSng(fTextboxToNumString(TbMassMass.Text)) Dim s0 As Segment = Nothing Try - s0 = DeclarationData.Segments.Lookup(VEH0.VehicleCategory, VEH0.AxleConfiguration, maxMass, 0.SI(Of Kilogram), True) + s0 = DeclarationData.Segments.Lookup(vehicle.VehicleCategory, vehicle.AxleConfiguration, maxMass, 0.SI(Of Kilogram), True) Catch End Try If Not s0 Is Nothing Then @@ -1041,9 +1044,9 @@ lbDlog: 'Image.FromFile(cDeclaration.ConvPicPath(HDVclass, False)) TbHVCclass.Text = "HDV Class " & HDVclass - TbVehCat.Text = VEH0.VehicleCategory.GetCategoryName() 'ConvVehCat(VEH0.VehCat, True) - TbMass.Text = VEH0.MassMax & " t" - TbAxleConf.Text = VEH0.AxleConfiguration.GetName() 'ConvAxleConf(VEH0.AxleConf) + TbVehCat.Text = vehicle.VehicleCategory.GetCategoryName() 'ConvVehCat(VEH0.VehCat, True) + TbMass.Text = (vehicle.GrossVehicleMassRating.Value() / 1000) & " t" + TbAxleConf.Text = vehicle.AxleConfiguration.GetName() 'ConvAxleConf(VEH0.AxleConf) End If diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb index b75b7ab57c148dbfaaf2279ce464ce0ff5771071..07f2c05adfbaf142c2a8bcfb77fc816353bbda9a 100644 --- a/VECTO/GUI/VehicleForm.vb +++ b/VECTO/GUI/VehicleForm.vb @@ -13,8 +13,10 @@ Option Infer On Imports System.IO Imports System.Linq Imports System.Text.RegularExpressions +Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCommon.Utils +Imports TUGraz.VectoCore.InputData.FileIO.JSON Imports TUGraz.VectoCore.Models.Declaration ''' <summary> @@ -100,7 +102,7 @@ Public Class VehicleForm 'Set HDVclasss Private Sub SetHdVclass() - If String.IsNullOrEmpty(TbMassMass.Text) Then + If String.IsNullOrEmpty(TbMassMass.Text) OrElse Not IsNumeric(TbMassMass.Text) Then TbHDVclass.Text = "-" Exit Sub End If @@ -318,15 +320,14 @@ Public Class VehicleForm If ChangeCheckCancel() Then Exit Sub - Dim veh = New Vehicle - veh.FilePath = file + Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(file), + IEngineeringInputDataProvider) + Dim veh = inputData.VehicleInputData + Dim retarder = inputData.RetarderInputData + Dim angularGear = inputData.AngularGearInputData + Dim pto = inputData.PTOTransmissionInputData - If Not veh.ReadFile Then - MsgBox("Cannot read " & file & "!") - Exit Sub - End If - - If Cfg.DeclMode <> veh.SavedInDeclMode Then + If Cfg.DeclMode <> veh.SavedInDeclarationMode Then Select Case WrongMode() Case 1 Close() @@ -337,25 +338,27 @@ Public Class VehicleForm End Select End If + Dim basePath As String = Path.GetDirectoryName(file) CbCat.SelectedValue = veh.VehicleCategory CbAxleConfig.SelectedValue = veh.AxleConfiguration - TbMassMass.Text = veh.MassMax.ToGUIFormat() + TbMassMass.Text = (veh.GrossVehicleMassRating.Value() / 1000).ToGUIFormat() - TbMass.Text = veh.Mass.ToGUIFormat() - TbMassExtra.Text = veh.MassExtra.ToGUIFormat() + TbMass.Text = veh.CurbWeightChassis.ToGUIFormat() + TbMassExtra.Text = veh.CurbWeightExtra.ToGUIFormat() TbLoad.Text = veh.Loading.ToGUIFormat() TBrdyn.Text = veh.DynamicTyreRadius.ToGUIFormat() CbCdMode.SelectedValue = veh.CrossWindCorrectionMode - TbCdFile.Text = veh.CrossWindCorrectionFile.OriginalPath + TbCdFile.Text = GetRelativePath(veh.CrosswindCorrectionMap.Source, basePath) + + CbRtType.SelectedValue = retarder.Type + TbRtRatio.Text = retarder.Ratio.ToGUIFormat() + TbRtPath.Text = GetRelativePath(retarder.LossMap.Source, basePath) - CbRtType.SelectedValue = veh.RetarderType - TbRtRatio.Text = veh.RetarderRatio.ToGUIFormat() - TbRtPath.Text = veh.RetarderLossMapFile.OriginalPath - cbAngularGearType.SelectedValue = veh.AngularGearType - tbAngularGearRatio.Text = veh.AngularGearRatio.ToGUIFormat() - tbAngularGearLossMapPath.Text = veh.AngularGearLossMapFile.OriginalPath + cbAngularGearType.SelectedValue = angularGear.Type + tbAngularGearRatio.Text = angularGear.Ratio.ToGUIFormat() + tbAngularGearLossMapPath.Text = GetRelativePath(angularGear.LossMap.Source, basePath) LvRRC.Items.Clear() Dim i = 0 @@ -365,22 +368,24 @@ Public Class VehicleForm If Cfg.DeclMode Then inertia = DeclarationData.Wheels.Lookup(a0.Wheels).Inertia.Value() - LvRRC.Items.Add(CreateListViewItem(i, Double.NaN, a0.TwinTire, a0.RRC, a0.FzISO, a0.Wheels, inertia)) + LvRRC.Items.Add(CreateListViewItem(i, Double.NaN, a0.TwinTyres, a0.RollResistanceCoefficient, + a0.TyreTestLoad.Value(), a0.Wheels, inertia)) Else - LvRRC.Items.Add(CreateListViewItem(i, a0.Share, a0.TwinTire, a0.RRC, a0.FzISO, a0.Wheels, a0.Inertia)) + LvRRC.Items.Add(CreateListViewItem(i, a0.AxleWeightShare, a0.TwinTyres, a0.RollResistanceCoefficient, + a0.TyreTestLoad.Value(), a0.Wheels, a0.Inertia.Value())) End If Next - TbMassExtra.Text = veh.MassExtra.ToGUIFormat() + 'TbMassExtra.Text = veh.MassExtra.ToGUIFormat() - TBcdA.Text = veh.CdA0.ToGUIFormat() + TBcdA.Text = veh.AirDragArea.ToGUIFormat() - cbPTOType.SelectedValue = veh.PTOType - tbPTOLossMap.Text = veh.PTOLossMap.OriginalPath - tbPTOCycle.Text = veh.PTOCycle.OriginalPath + cbPTOType.SelectedValue = pto.PTOTransmissionType + tbPTOLossMap.Text = GetRelativePath(pto.PTOLossMap.Source, basePath) + tbPTOCycle.Text = GetRelativePath(pto.PTOCycle.Source, basePath) DeclInit() diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb index a9242fbddfae8a3a770f82b9d58510c3d45ec705..d10e06fc86aad64ff1dfc2644c868f7b52ae8661 100644 --- a/VECTO/Input Files/Vehicle.vb +++ b/VECTO/Input Files/Vehicle.vb @@ -154,137 +154,6 @@ Public Class Vehicle SavedInDeclMode = False End Sub - Public Function ReadFile(Optional showMsg As Boolean = True) As Boolean - Const msgSrc = "VEH/ReadFile" - SetDefault() - - Dim json As New JSONParser - If Not json.ReadFile(_filePath) Then Return False - - Try - Dim header As JToken = json.Content.GetEx("Header") - Dim body As JToken = json.Content.GetEx("Body") - - _fileVersion = header.GetEx(Of Integer)("FileVersion") - If _fileVersion > 4 Then - SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") - Else - SavedInDeclMode = Cfg.DeclMode - End If - - Mass = body.GetEx(Of Double)("CurbWeight") - MassExtra = body.GetEx(Of Double)("CurbWeightExtra") - Loading = body.GetEx(Of Double)("Loading") - VehicleCategory = body("VehCat").ToString.ParseEnum(Of VehicleCategory)() 'ConvVehCat(body("VehCat").ToString) - AxleConfiguration = AxleConfigurationHelper.Parse(body("AxleConfig")("Type").ToString) - If _fileVersion < 2 Then - 'convert kg to ton - MassMax /= 1000 - Else - MassMax = body.GetEx(Of Double)("MassMax") - End If - - If _fileVersion < 7 Then - 'calc CdA from Cd and area value - CdA0 = (body.GetEx(Of Double)("Cd")) * (body.GetEx(Of Double)("CrossSecArea")) - Else - CdA0 = body.GetEx(Of Double)("CdA") - End If - - 'CdA02 = CdA0 - - CrossWindCorrectionMode = CrossWindCorrectionModeHelper.Parse(body("CdCorrMode").ToString) - If Not body("CdCorrFile") Is Nothing Then - CrossWindCorrectionFile.Init(_path, body.GetEx(Of String)("CdCorrFile")) - End If - - If body("Retarder") Is Nothing Then - RetarderType = RetarderType.None - Else - RetarderType = RetarderTypeHelper.Parse(body("Retarder")("Type").ToString) - Dim retarder As JToken = body.GetEx("Retarder") - If Not retarder("Ratio") Is Nothing Then - RetarderRatio = retarder.GetEx(Of Double)("Ratio") - End If - If Not retarder("File") Is Nothing Then - RetarderLossMapFile.Init(_path, retarder.GetEx(Of String)("File")) - End If - End If - - If body("AngularGear") Is Nothing Then - AngularGearType = AngularGearType.None - Else - AngularGearType = body("AngularGear")("Type").ToString.ParseEnum(Of AngularGearType)() - Dim angleDrive As JToken = body("AngularGear") - If Not angleDrive("Ratio") Is Nothing Then - AngularGearRatio = angleDrive.GetEx(Of Double)("Ratio") - End If - If Not body("AngularGear")("LossMap") Is Nothing Then - AngularGearLossMapFile.Init(_path, angleDrive.GetEx(Of String)("LossMap")) - End If - End If - - Dim inertiaTemp As Double - If _fileVersion < 3 Then - inertiaTemp = body.GetEx(Of Double)("WheelsInertia") - DynamicTyreRadius = 1000 * body.GetEx(Of Double)("WheelsDiaEff") / 2 - Else - DynamicTyreRadius = body.GetEx(Of Double)("rdyn") - End If - - Dim axleCount As Integer = body("AxleConfig")("Axles").Count() - For Each axleEntry In body.GetEx("AxleConfig").GetEx("Axles") - Dim axle = New Axle With { - .Share = (axleEntry.GetEx(Of Double)("AxleWeightShare")), - .TwinTire = (axleEntry.GetEx(Of Boolean)("TwinTyres")), - .RRC = (axleEntry.GetEx(Of Double)("RRCISO")), - .FzISO = (axleEntry.GetEx(Of Double)("FzISO"))} - - If _fileVersion < 3 Then - axle.Wheels = "-" - Dim numWheels As Integer = 2 - If axle.TwinTire Then numWheels = 4 - axle.Inertia = inertiaTemp / (numWheels * axleCount) - Else - axle.Wheels = (axleEntry.GetEx(Of String)("Wheels")).Replace("R ", "R") - axle.Inertia = (axleEntry.GetEx(Of Double)("Inertia")) - End If - Axles.Add(axle) - Next - - PTOType = PTOTransmission.NoPTO - If Not body("PTO") Is Nothing Then - Dim ptoTypeToken = body.GetEx("PTO")("Type") - - If String.IsNullOrWhiteSpace(ptoTypeToken.Value(Of String)) Then - PTOType = PTOTransmission.NoPTO - WorkerMsg(MessageType.Normal, "PTO automatically updated to '" + ptoTypeToken.Value(Of String)() + "'", msgSrc) - Else - Try - DeclarationData.PTOTransmission.Lookup(ptoTypeToken.Value(Of String)) - PTOType = ptoTypeToken.Value(Of String)() - Catch ex As Exception - WorkerMsg(MessageType.Normal, - "PTO '" + ptoTypeToken.Value(Of String)() + "' not found, automatically updated to '" + PTOTransmission.NoPTO + - "'", msgSrc) - PTOType = PTOTransmission.NoPTO - End Try - End If - - End If - - If Not PTOType.Equals(PTOTransmission.NoPTO) Then - PTOLossMap.Init(_path, body.GetEx("PTO").GetEx(Of String)("LossMap")) - PTOCycle.Init(_path, body.GetEx("PTO").GetEx(Of String)("Cycle")) - End If - - Catch ex As Exception - If showMsg Then WorkerMsg(MessageType.Err, "Failed to read Vehicle file! " & ex.Message, msgSrc) - Return False - End Try - - Return True - End Function Public Function SaveFile() As Boolean SavedInDeclMode = Cfg.DeclMode @@ -483,7 +352,7 @@ Public Class Vehicle End Get End Property - Public ReadOnly Property CrosswindCorrectionMap As DataTable _ + Public ReadOnly Property CrosswindCorrectionMap As TableData _ Implements IVehicleEngineeringInputData.CrosswindCorrectionMap Get Return VectoCSVFile.Read(CrossWindCorrectionFile.FullPath) diff --git a/VECTO/MainModule.vb b/VECTO/MainModule.vb index b068a602c4d80d9275300220150540665642c2c5..896b037bc845ac0be50c1b8f31414795dc7e0370 100644 --- a/VECTO/MainModule.vb +++ b/VECTO/MainModule.vb @@ -9,6 +9,7 @@ ' ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Collections.Generic +Imports System.IO Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore.Models.SimulationComponent.Data Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Engine @@ -61,4 +62,14 @@ Module MainModule Return My.Resources.Undef ' resourcePath & "Undef.png" End Select End Function + + Public Function GetRelativePath(filePath As String, basePath As String) As String + 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) + End If + Return filePath + End Function End Module diff --git a/VectoConsole/Program.cs b/VectoConsole/Program.cs index d6bd3f87c8ab7b189d6a28a0898cf4ca7334bc47..493c3c14e6c8e03f778807199aaa210930bb8a29 100644 --- a/VectoConsole/Program.cs +++ b/VectoConsole/Program.cs @@ -64,29 +64,29 @@ namespace VectoConsole Commandline Interface for Vecto. Synopsis: - vectocmd.exe [-h] [-v] FILE1.(vecto|xml) [FILE2.(vecto|xml) ...] + vectocmd.exe [-h] [-v] FILE1.(vecto|xml) [FILE2.(vecto|xml) ...] Description: - FILE1.vecto [FILE2.vecto ...]: A list of vecto-job files (with the - extension: .vecto). At least one file must be given. Delimited by - whitespace. - - -t: output information about execution times - -mod: write mod-data in addition to sum-data - -1Hz: convert mod-data to 1Hz resolution - -eng: switch to engineering mode (implies -mod) - -v: Shows verbose information (errors and warnings will be displayed) + FILE1.vecto [FILE2.vecto ...]: A list of vecto-job files (with the + extension: .vecto). At least one file must be given. Delimited by + whitespace. + + -t: output information about execution times + -mod: write mod-data in addition to sum-data + -1Hz: convert mod-data to 1Hz resolution + -eng: switch to engineering mode (implies -mod) + -v: Shows verbose information (errors and warnings will be displayed) -vv: Shows more verbose information (infos will be displayed) -vvv: Shows debug messages (slow!) -vvvv: Shows all verbose information (everything, slow!) - -V: show version information - -h: Displays this help. + -V: show version information + -h: Displays this help. Examples: - vecto.exe ""12t Delivery Truck.vecto"" 40t_Long_Haul_Truck.vecto - vecto.exe 24tCoach.vecto 40t_Long_Haul_Truck.vecto - vecto.exe -v 24tCoach.vecto - vecto.exe -v jobs\40t_Long_Haul_Truck.vecto + vecto.exe ""12t Delivery Truck.vecto"" 40t_Long_Haul_Truck.vecto + vecto.exe 24tCoach.vecto 40t_Long_Haul_Truck.vecto + vecto.exe -v 24tCoach.vecto + vecto.exe -v jobs\40t_Long_Haul_Truck.vecto vecto.exe -h "; diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index bbe30049c62d65b3b805d04dab6dae20cab20574..4d0cf7cb515046439d8e257c23f40cdd3acac2b8 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -29,11 +29,13 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.IO; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCore.Configuration; namespace TUGraz.VectoCore.InputData.FileIO.JSON { @@ -50,10 +52,19 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } + public static IInputDataProvider ReadComponentData(string filename) + { + if (Constants.FileExtensions.VectoJobFile.Equals(Path.GetExtension(filename), StringComparison.OrdinalIgnoreCase)) { + return ReadJsonJob(filename); + } + return new JSONComponentInputData(filename); + } + public static IInputDataProvider ReadJsonJob(string filename) { var json = ReadFile(filename); var version = ReadVersion(json); + switch (version) { case 2: return new JSONInputDataV2(json, filename);