Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
' Copyright 2014 European Union.
' Licensed under the EUPL (the 'Licence');
'
' * You may not use this work except in compliance with the Licence.
' * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
' * Unless required by applicable law or agreed to in writing,
' software distributed under the Licence is distributed on an "AS IS" basis,
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
'
' See the LICENSE.txt for the specific language governing permissions and limitations.
Option Infer On
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports TUGraz.VECTO.Input_Files
Imports TUGraz.VectoCommon.Models
Imports TUGraz.VectoCommon.Utils
Public Class Vehicle
'V2 MassMax is now saved in [t] instead of [kg]
Private Const FormatVersion As Short = 7
Private FileVersion As Short
Private sFilePath As String
Private MyPath As String
Public Mass As Single
Public Loading As Single
Public CdA0 As Single
Public CdMode As CrossWindCorrectionMode
Public ReadOnly CdFile As SubPath
Private ReadOnly CdX As List(Of Single)
Private ReadOnly CdY As List(Of Single)
Public RtType As RetarderType 'tRtType '0=None, 1=Primary, 2=Secondary
Public RtRatio As Single = 0
Public ReadOnly RtFile As SubPath
Private ReadOnly RtnU As List(Of Single)
Private ReadOnly RtM As List(Of Single)
Public rdyn As Single
Public ReadOnly Axles As List(Of Axle)
Public VehCat As VehicleCategory
Public MassExtra As Single
Public MassMax As Single
Public AxleConf As AxleConfiguration
Public SavedInDeclMode As Boolean
Public AngularGearType As AngularGearType '0=None, 1=Separate, 2=Included
Public AngularGearRatio As Single
Public ReadOnly AngularGearLossMapFile As SubPath
Public Class Axle
Public RRC As Single
Public Share As Single
Public TwinTire As Boolean
Public FzISO As Single
Public Wheels As String
Public Inertia As Single
End Class
Public Sub New()
MyPath = ""
sFilePath = ""
CdFile = New SubPath
CdX = New List(Of Single)
CdY = New List(Of Single)
RtFile = New SubPath
AngularGearLossMapFile = New SubPath()
RtnU = New List(Of Single)
RtM = New List(Of Single)
Axles = New List(Of Axle)
SetDefault()
End Sub
Private Sub SetDefault()
Mass = 0
MassExtra = 0
Loading = 0
CdA0 = 0
' CdA0Act = CdA0
' CdA02 = 0
CdFile.Clear()
CdMode = CrossWindCorrectionMode.NoCorrection
CdX.Clear()
CdY.Clear()
rdyn = 0
RtType = RetarderType.None
RtRatio = 1
RtnU.Clear()
RtM.Clear()
RtFile.Clear()
AngularGearLossMapFile.Clear()
AngularGearType = AngularGearType.None
AngularGearLossMapFile.Clear()
AngularGearRatio = 1
Axles.Clear()
VehCat = VehicleCategory.RigidTruck 'tVehCat.Undef
MassMax = 0
AxleConf = AxleConfiguration.AxleConfig_4x2 'tAxleConf.Undef
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(sFilePath) Then Return False
Try
Dim header = json.Content("Header")
Dim body = json.Content("Body")
FileVersion = header("FileVersion")
If FileVersion > 4 Then
SavedInDeclMode = body("SavedInDeclMode")
Else
SavedInDeclMode = Cfg.DeclMode
End If
Mass = body("CurbWeight")
MassExtra = body("CurbWeightExtra")
Loading = body("Loading")
VehCat = body("VehCat").ToString.ParseEnum(Of VehicleCategory)() 'ConvVehCat(body("VehCat").ToString)
AxleConf = AxleConfigurationHelper.Parse(body("AxleConfig")("Type").ToString)
If FileVersion < 2 Then
'convert kg to ton
MassMax /= 1000
Else
MassMax = body("MassMax")
End If
If FileVersion < 7 Then
'calc CdA from Cd and area value
CdA0 = CSng(body("Cd")) * CSng(body("CrossSecArea"))
Else
CdA0 = body("CdA")
End If
'CdA02 = CdA0
CdMode = CrossWindCorrectionModeHelper.Parse(body("CdCorrMode").ToString)
If Not body("CdCorrFile") Is Nothing Then
CdFile.Init(MyPath, body("CdCorrFile"))
End If
If body("Retarder") Is Nothing Then
RtType = RetarderType.None
Else
RtType = RetarderTypeHelper.Parse(body("Retarder")("Type").ToString)
If Not body("Retarder")("Ratio") Is Nothing Then
RtRatio = body("Retarder")("Ratio")
End If
If Not body("Retarder")("File") Is Nothing Then
RtFile.Init(MyPath, body("Retarder")("File"))
End If
End If
If body("AngularGear") Is Nothing Then
AngularGearType = AngularGearType.None
Else
AngularGearType = body("AngularGear")("Type").ToString.ParseEnum(Of AngularGearType)()
If Not body("AngularGear")("Ratio") Is Nothing Then
AngularGearRatio = body("AngularGear")("Ratio")
End If
If Not body("AngularGear")("LossMap") Is Nothing Then
AngularGearLossMapFile.Init(MyPath, body("AngularGear")("LossMap"))
End If
End If
Dim inertiaTemp As Single
If FileVersion < 3 Then
inertiaTemp = body("WheelsInertia")
rdyn = 1000 * body("WheelsDiaEff") / 2
Else
rdyn = body("rdyn")
End If
Dim axleCount = body("AxleConfig")("Axles").Count()
For Each axleEntry In body("AxleConfig")("Axles")
Dim axle = New Axle With {
.Share = CSng(axleEntry("AxleWeightShare")),
.TwinTire = CBool(axleEntry("TwinTyres")),
.RRC = CSng(axleEntry("RRCISO")),
.FzISO = CSng(axleEntry("FzISO"))}
If FileVersion < 3 Then
axle.Wheels = "-"
axle.Inertia = inertiaTemp / (IIf(axle.TwinTire, 4, 2) * axleCount)
Else
axle.Wheels = CStr(axleEntry("Wheels")).Replace("R ", "R")
axle.Inertia = CSng(axleEntry("Inertia"))
End If
Axles.Add(axle)
Next
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
Dim json As New JSONParser
'Header
json.Content.Add("Header", New Dictionary(Of String, Object) From {
{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
{"Date", Now.ToUniversalTime().ToString("o")},
{"AppVersion", VECTOvers},
{"FileVersion", FormatVersion}})
'Body
Dim dic As Dictionary(Of String, Object)
dic = New Dictionary(Of String, Object) From {
{"SavedInDeclMode", Cfg.DeclMode},
{"VehCat", VehCat.ToString()},
{"CurbWeight", Mass},
{"CurbWeightExtra", MassExtra},
{"Loading", Loading},
{"MassMax", MassMax},
{"CdA", CdA0},
{"rdyn", rdyn},
{"CdCorrMode", CdMode.GetName()},
{"CdCorrFile", CdFile.PathOrDummy},
{"Retarder", New Dictionary(Of String, Object) From {
{"Type", RtType.GetName()},
{"Ratio", RtRatio},
{"File", RtFile.PathOrDummy}}},
{"AngularGear", New Dictionary(Of String, Object) From {
{"Type", AngularGearType.ToString()},
{"Ratio", AngularGearRatio},
{"LossMap", AngularGearLossMapFile.PathOrDummy}}},
{"AxleConfig", New Dictionary(Of String, Object) From {
{"Type", AxleConf.GetName()},
{"Axles", (From axle In Axles Select New Dictionary(Of String, Object) From {
{"Inertia", axle.Inertia},
{"Wheels", axle.Wheels},
{"AxleWeightShare", axle.Share},
{"TwinTyres", axle.TwinTire},
{"RRCISO", axle.RRC},
{"FzISO", axle.FzISO}})}}}
}
json.Content.Add("Body", dic)
Return json.WriteFile(sFilePath)
End Function
#Region "Properties"
Public Property FilePath() As String
Get
Return sFilePath
End Get
Set(value As String)
sFilePath = value
If sFilePath = "" Then
MyPath = ""
Else
MyPath = Path.GetDirectoryName(sFilePath) & "\"
End If
End Set
End Property
#End Region