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
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