diff --git a/CSE/ApplicationEvents.vb b/CSE/ApplicationEvents.vb index 8d6cfe808d462bfa4f1134bc1847fd3f608cf141..f6c95fb6083e36a22c4b0c7128ffa461080a4a3d 100644 --- a/CSE/ApplicationEvents.vb +++ b/CSE/ApplicationEvents.vb @@ -64,8 +64,8 @@ fbWorkDir = New cFileBrowser("DIR", True) - fbVEH = New cFileBrowser("VEH") - fbVEH.Extensions = New String() {"csveh"} + fbVEH = New cFileBrowser("VEH.json") + fbVEH.Extensions = New String() {"csveh.json"} fbAMB = New cFileBrowser("AMB") fbAMB.Extensions = New String() {"csamb"} diff --git a/CSE/Calculation/main_calculation_call.vb b/CSE/Calculation/main_calculation_call.vb index ebe66dcb4a7214280c6e99038da8a8024cd82a42..5dc65282b3758dde18ef026c7ae084b0c7f069fd 100644 --- a/CSE/Calculation/main_calculation_call.vb +++ b/CSE/Calculation/main_calculation_call.vb @@ -16,13 +16,12 @@ If Cali Then ' Declarations - Dim vehicle As New cVehicle Dim MSC As New cMSC Dim vMSC As New cVirtMSC ' Read the input data fInfWarErrBW(7, False, "Reading Input Files...") - readInputVeh(vehicle) + Dim vehicle As New cVehicle(Vehspez) ReadInputMSC(MSC, MSCCSpez, Cali) ReadDataFile(DataSpez(1), MSC) @@ -55,7 +54,6 @@ fOutCalcRes(DataSpez, Cali) Else ' Declarations - Dim vehicle As New cVehicle Dim MSC As New cMSC Dim vMSC As New cVirtMSC @@ -64,7 +62,7 @@ ' Read the input files fInfWarErrBW(7, False, "Reading Input Files...") - readInputVeh(vehicle) + Dim vehicle As New cVehicle(Vehspez) ReadInputMSC(MSC, MSCTSpez, Cali) ReadWeather(Ambspez) @@ -448,8 +446,8 @@ ' Calculate the steps For h = 5 To 95 Step Pstep - vwind_x = vwind_x_ha * Math.Pow((((h / 100) * vehicleX.vehHeight) / vehicleX.flowMeterHeight), 0.2) - vwind_y = vwind_y_ha * Math.Pow((((h / 100) * vehicleX.vehHeight) / vehicleX.flowMeterHeight), 0.2) + vwind_x = vwind_x_ha * Math.Pow((((h / 100) * vehicleX.vehHeight) / vehicleX.anemometerHeight), 0.2) + vwind_y = vwind_y_ha * Math.Pow((((h / 100) * vehicleX.vehHeight) / vehicleX.anemometerHeight), 0.2) vairX = vairX + (Math.Sqrt((vwind_x + CalcData(tCompCali.v_veh_c)(i) / 3.6) ^ 2 + vwind_y ^ 2)) * vehicleX.vehHeight * Pstep / 100 vwindX = vwindX + (Math.Sqrt(vwind_x ^ 2 + vwind_y ^ 2)) * vehicleX.vehHeight * Pstep / 100 betaX = betaX + (Math.Atan(vwind_y / (vwind_x + CalcData(tCompCali.v_veh_c)(i) / 3.6)) * 180 / Math.PI) * vehicleX.vehHeight * Pstep / 100 diff --git a/CSE/Calculation/sub_linear_regression.vb b/CSE/Calculation/sub_linear_regression.vb index 6c6ce0d175add141a8e778e0bb808e12e516f9d7..2952990aba780394a871fec2126849f01db0372f 100644 --- a/CSE/Calculation/sub_linear_regression.vb +++ b/CSE/Calculation/sub_linear_regression.vb @@ -400,7 +400,7 @@ ' Find the correct curve For i = 0 To GenShape.veh_class.Count - 1 - If GenShape.veh_class(i) = vehicleX.vehClass And GenShape.veh_conf(i) = vehicleX.vehConfig Then + If GenShape.veh_class(i) = vehicleX.classCode And CBool(GenShape.veh_conf(i)) = vehicleX.IsRigid Then pos = i Exit For End If diff --git a/CSE/Classes/cVehicle.vb b/CSE/Classes/cVehicle.vb index 0cba208d2e416304674239f6961580540dcc23a7..d2a5777c892c124f3f4cd60724feccf8c67ce31e 100644 --- a/CSE/Classes/cVehicle.vb +++ b/CSE/Classes/cVehicle.vb @@ -1,12 +1,245 @@ -Public Class cVehicle - Public vehClass As Integer ' Vehicle class code [1-16] - Public vehConfig As Integer ' Vehicle configuration - Public vehWidth As Double ' mask width [m] - Public vehHeight As Double ' Vehicle height [m] - Public flowMeterHeight As Double ' Anemomenter height [m] - Public testMass As Double ' Vehicle test mass [kg] - Public wheelsInertia As Double ' Wheels inertia [kgm2] - Public axleRatio As Double ' Axle ratio - Public gearRatio_high As Double ' Gear ratio high speed - Public gearRatio_low As Double ' Gear ratio low speed +Imports Newtonsoft.Json.Linq +Imports Newtonsoft.Json.Schema + +Public Enum VehicleConfig + Rigid + Tractor +End Enum + +Public Class cVehicle + Inherits cJsonFile + + Protected Overrides Function HeaderOverlay() As JObject + Return JObject.Parse(<json>{ + "Title": "vecto-cse VEHICLE", + "FileVersion": "1.0.0", + }</json>.Value) + End Function + + + ' Defaults specified here. + Protected Overrides Function BodyContent() As JObject + Return JObject.Parse(<json>{ + "vehClass": null, + "configuration": null, + "vehWidth": null, + "vehHeight": null, + "anemometerHeight": null, + "testMass": null, + "wheelsInertia": null, + "gearRatio_low": null, + "gearRatio_high": null, + "axleRatio": null, + }</json>.Value) + End Function + + ' Default-prefs specified here. + Public Overrides Function BodySchema() As JObject + Return JObject.Parse(JSchemaStr()) + End Function + + ''' <param name="allowAdditionalProps">when false, more strict validation</param> + Public Shared Function JSchemaStr(Optional ByVal allowAdditionalProps As Boolean = True) As String + Dim allowAdditionalProps_str As String = IIf(allowAdditionalProps, "true", "false") + Return <json>{ + "title": "Schema for vecto-cse VEHICLE", + "type": "object", "additionalProperties": <%= allowAdditionalProps_str %>, + "required": true, + "properties": { + "classCode": { + "title": "Class code [1-16]", + "type": "integer", + "required": true, + "description": "The class the vehicle belongs to according to the legislation. +The generic parameters for classes are stored in the GenShape.shp", + }, + "configuration": { + "title": "Vehicle Configuration", + "enum": ["rigid", "tractor"], + "required": true, + "title": "Vehicle is rigid or track'n tractor?", + }, + "vehWidth": { + "title": "Mask width [m]", + "type":"number", + "required": true, + }, + "vehHeight": { + "title": "Vehicle height [m]", + "type":"number", + "required": true, + } , + "anemometerHeight": { + "title": "Anemomenter height [m]", + "type":"number", + "required": true, + }, + "testMass": { + "title": "Vehicle test mass [kg]", + "type":"number", + "required": true, + }, + "wheelsInertia": { + "title": "Wheels inertia [kg*m2]", + "type":"number", + "required": true, + }, + "gearRatio_low": { + "title": "Gear ratio low speed", + "type":"number", + "required": true, + }, + "gearRatio_high": { + "title": "Gear ratio high speed", + "type":"number", + "required": true, + }, + "axleRatio": { + "title": "Axle ratio", + "type":"number", + "required": true, + }, + } + }</json>.Value + End Function + + + ''' <summary>Reads from file or creates defaults</summary> + ''' <param name="inputFilePath">If unspecifed, default prefs used, otherwise data read from file</param> + ''' <remarks>See cJsonFile() constructor</remarks> + Sub New(Optional ByVal inputFilePath As String = Nothing, Optional ByVal skipValidation As Boolean = False) + MyBase.New(inputFilePath, skipValidation) + End Sub + + + ''' <exception cref="SystemException">includes all validation errors</exception> + ''' <param name="strictBody">when true, no additional json-properties allowed in the data, when nothing, use value from Header</param> + Protected Overrides Sub ValidateBody(ByVal strictBody As Boolean, ByVal validateMsgs As IList(Of String)) + '' Check version + '' + Dim fromVersion = "1.0.0--" + Dim toVersion = "2.0.0--" ' The earliest pre-release. + If Not IsSemanticVersionsSupported(Me.FileVersion, fromVersion, toVersion) Then + validateMsgs.Add(format("Unsupported FileVersion({0}, was not in between [{1}, {2})", Me.FileVersion, fromVersion, toVersion)) + Return + End If + + '' Check schema + '' + Dim schema = JsonSchema.Parse(JSchemaStr(Not strictBody)) + ValidateJson(Body, schema, validateMsgs) + + If validateMsgs.Any() Then Return + + '' Check others + '' + '' Check if vehicle class with the given configuration class is available + For i = 0 To GenShape.veh_class.Count - 1 + If GenShape.veh_class(i) = Me.classCode AndAlso CBool(GenShape.veh_conf(i)) = Me.IsRigid Then + fa_pe = GenShape.fa_pe(i) + Return + End If + Next i + + '' The configuration was not found! + '' + validateMsgs.Add(format("The vehicle (class: {0}, configuration {1}) was not found in the generic shape file. \n\iPlease add it in .", Me.classCode, Me.configuration)) + BWorker.CancelAsync() + Return + End Sub + + + +#Region "json props" + Public Property classCode As Integer + Get + Return Me.Body("classCode") + End Get + Set(ByVal value As Integer) + Me.Body("classCode") = value + End Set + End Property + Public Property configuration As VehicleConfig + Get + Dim value As String = Me.Body("configuration") + + Return [Enum].Parse(GetType(VehicleConfig), value, True) + End Get + Set(ByVal value As VehicleConfig) + Me.Body("configuration") = value.ToString() + End Set + End Property + Public Property vehWidth As Double + Get + Return Me.Body("vehWidth") + End Get + Set(ByVal value As Double) + Me.Body("vehWidth") = value + End Set + End Property + Public Property vehHeight As Double + Get + Return Me.Body("vehHeight") + End Get + Set(ByVal value As Double) + Me.Body("vehHeight") = value + End Set + End Property + Public Property anemometerHeight As Double + Get + Return Me.Body("anemometerHeight") + End Get + Set(ByVal value As Double) + Me.Body("anemometerHeight") = value + End Set + End Property + Public Property testMass As Double + Get + Return Me.Body("testMass") + End Get + Set(ByVal value As Double) + Me.Body("testMass") = value + End Set + End Property + Public Property wheelsInertia As Double + Get + Return Me.Body("wheelsInertia") + End Get + Set(ByVal value As Double) + Me.Body("wheelsInertia") = value + End Set + End Property + Public Property gearRatio_low As Double + Get + Return Me.Body("gearRatio_low") + End Get + Set(ByVal value As Double) + Me.Body("gearRatio_low") = value + End Set + End Property + Public Property gearRatio_high As Double + Get + Return Me.Body("gearRatio_high") + End Get + Set(ByVal value As Double) + Me.Body("gearRatio_high") = value + End Set + End Property + Public Property axleRatio As Double + Get + Return Me.Body("axleRatio") + End Get + Set(ByVal value As Double) + Me.Body("axleRatio") = value + End Set + End Property +#End Region ' "json props" + + Public ReadOnly Property IsRigid As Boolean + Get + Return Me.configuration = VehicleConfig.Rigid + End Get + End Property + + End Class diff --git a/CSE/GUI/minor_routines_GUI.vb b/CSE/GUI/minor_routines_GUI.vb index 679dad9bf66eba03a005b0baf8264566f185e73d..8a98e7bf9c998febc0736f1380ad18af64e8cdfb 100644 --- a/CSE/GUI/minor_routines_GUI.vb +++ b/CSE/GUI/minor_routines_GUI.vb @@ -237,7 +237,7 @@ Module minor_routines_GUI End If ' Control the input files - fControlInput(Vehspez, 1, "csveh") + fControlInput(Vehspez, 1, "csveh.json") fControlInput(Ambspez, 2, "csamb") fControlInput(MSCCSpez, 3, "csms") fControlInput(MSCTSpez, 4, "csms") diff --git a/CSE/Import/read_input.vb b/CSE/Import/read_input.vb index c3732e795f4bf704a3df52bb3fcb931298e60d8a..e10b711c872634622bf61c020448aabd537939dd 100644 --- a/CSE/Import/read_input.vb +++ b/CSE/Import/read_input.vb @@ -1,73 +1,5 @@ ' Read the input data Public Module read_input - ' Read the vehicle file - Public Function readInputVeh(ByRef vehicleX As cVehicle) As Boolean - ' Input files - Dim i As Integer - Dim vehT As Boolean = False - Using FileInVehSpez As New cFile_V3 - - ' Read the filelist with the vehicle spezifications - ' Output on the GUI - fInfWarErrBW(5, False, "Read vehicle file") - - ' Open the vehicle spezification file - If Not FileInVehSpez.OpenRead(Vehspez) Then - ' Error if the file is not available - fInfWarErrBW(9, False, "Can´t find the vehicle specification file: " & Vehspez) - Return False - End If - - ' Import routine - vehicleX.vehClass = FileInVehSpez.ReadLine(0) - vehicleX.vehConfig = FileInVehSpez.ReadLine(0) - vehicleX.testMass = FileInVehSpez.ReadLine(0) - vehicleX.wheelsInertia = FileInVehSpez.ReadLine(0) - vehicleX.axleRatio = FileInVehSpez.ReadLine(0) - vehicleX.gearRatio_high = FileInVehSpez.ReadLine(0) - vehicleX.gearRatio_low = FileInVehSpez.ReadLine(0) - vehicleX.flowMeterHeight = FileInVehSpez.ReadLine(0) - vehicleX.vehHeight = FileInVehSpez.ReadLine(0) - vehicleX.vehWidth = FileInVehSpez.ReadLine(0) - - End Using - - - ' Abfrage ob genügend eingabefiles vorhanden sind - If endofall Then - fInfWarErrBW(9, False, "Not enough inputfiles in the vehicle specification file") - BWorker.CancelAsync() - Return False - End If - - ' Check if vehicl class is available - If Not GenShape.veh_class.Contains(vehicleX.vehClass) Then - ' Error if the vehicle class is not available - fInfWarErrBW(9, False, "The given vehicle class is not specified in the generic shape file. Please add this class to the generic shape file!") - BWorker.CancelAsync() - Return False - End If - - ' Check if vehicle class with the given configuration class is available - For i = 0 To GenShape.veh_class.Count - 1 - If GenShape.veh_class(i) = vehicleX.vehClass And GenShape.veh_conf(i) = vehicleX.vehConfig Then - vehT = True - fa_pe = GenShape.fa_pe(i) - Exit For - End If - Next i - - ' Check if the configuration is found - If Not vehT Then - ' Error if the vehicle configuration is not available - fInfWarErrBW(9, False, "The given vehicle configuration is not specified in the generic shape file. Please add this class to the generic shape file!") - BWorker.CancelAsync() - Return False - End If - - Return True - End Function - ' Read the measurement section config file Function ReadInputMSC(ByRef MSCX As cMSC, ByVal MSCfile As String, Optional ByVal calibration As Boolean = True) As Boolean ' Declarations diff --git a/DemoData/VehicleDemo.csveh b/DemoData/VehicleDemo.csveh deleted file mode 100644 index e7e922265d60a897347d9848de23748005f5274e..0000000000000000000000000000000000000000 --- a/DemoData/VehicleDemo.csveh +++ /dev/null @@ -1,21 +0,0 @@ -c VECTO-CSE vehicle file -c vehicle class code (1-16) -4 -c vehicle configuration (0=rigid; 1=truck/tractor&trailer) -0 -c vehicle test mass [kg] -25000 -c wheels inertia [kgm²] -90 -c axle ratio [-] -3.6 -c gear ratio high speed [-] -1 -c gear ratio low speed [-] -2.5 -c anemometer height [m] -4.55 -c vehicle height [m] -3.5 -c vehicle width [m] -2.45 diff --git a/DemoData/VehicleDemo.csveh.json b/DemoData/VehicleDemo.csveh.json new file mode 100644 index 0000000000000000000000000000000000000000..6008120a97fe6214df975623a0f1ba5310f3de33 --- /dev/null +++ b/DemoData/VehicleDemo.csveh.json @@ -0,0 +1,21 @@ +{ + "Header": { + "Title": "vecto-cse VEHICLE", + "FileVersion": "1.0.0", + "AppVersion": "2.0.1-pre1", + "ModifiedDate": "2014/05/28 00:33:50 +02:00", + "Strict": true, + }, + "Body": { + "classCode": 4, + "configuration": "rigid", + "vehWidth": 2.45, + "vehHeight": 3.5, + "anemometerHeight": 4.55, + "testMass": 25000.0, + "wheelsInertia": 90.0, + "gearRatio_low": 2.5, + "gearRatio_high": 1, + "axleRatio": 3.6, + } +} \ No newline at end of file