Newer
Older
' 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.ComponentModel.DataAnnotations
Imports System.IO
Imports System.Linq
Imports Newtonsoft.Json.Linq
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.InputData.Impl
Imports TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
Imports TUGraz.VectoCore.Models.Declaration
Imports TUGraz.VectoCore.Models.SimulationComponent.Data
Imports TUGraz.VectoCore.Utils
<CustomValidation(GetType(Vehicle), "ValidateVehicle")>
Public Class Vehicle
Implements IVehicleEngineeringInputData, IVehicleDeclarationInputData
'V2 MassMax is now saved in [t] instead of [kg]
Private Const FormatVersion As Short = 7
Private _fileVersion As Integer
Private _filePath As String
Private _path As String
Public Mass As Double
Public Loading As Double
Public CdA0 As Double
Public CrossWindCorrectionMode As CrossWindCorrectionMode
Public ReadOnly CrossWindCorrectionFile As SubPath
<ValidateObject()> Public RetarderType As RetarderType
Public RetarderRatio As Double = 0
Public ReadOnly RetarderLossMapFile As SubPath
Public DynamicTyreRadius As Double
Public ReadOnly Axles As List(Of Axle)
Public VehicleCategory As VehicleCategory
Public MassExtra As Double
Public MassMax As Double
Public AxleConfiguration As AxleConfiguration
Public SavedInDeclMode As Boolean
Public AngularGearType As AngularGearType
Public AngularGearRatio As Double
Public ReadOnly AngularGearLossMapFile As SubPath
Public PTOType As String
Public ReadOnly PTOLossMap As SubPath
Public ReadOnly PTOCycle As SubPath
Public Class Axle
Public RRC As Double
Public Share As Double
Public TwinTire As Boolean
Public FzISO As Double
Public Wheels As String
Public Inertia As Double
End Class
Public Sub New()
_path = ""
_filePath = ""
CrossWindCorrectionFile = New SubPath
RetarderLossMapFile = New SubPath
AngularGearLossMapFile = New SubPath()
Axles = New List(Of Axle)
PTOLossMap = New SubPath()
PTOCycle = New SubPath()
SetDefault()
End Sub
Public Shared Function ValidateVehicle(vehicle As Vehicle, validationContext As ValidationContext) As ValidationResult
Dim vehicleData As VehicleData
Dim modeService As ExecutionModeServiceContainer = TryCast(validationContext.GetService(GetType(ExecutionMode)),
ExecutionModeServiceContainer)
Dim mode = If(modeService Is Nothing, ExecutionMode.Declaration, modeService.Mode)
Try
If mode = ExecutionMode.Declaration Then
Dim doa = New DeclarationDataAdapter()
Dim segment = DeclarationData.Segments.Lookup(vehicle.VehicleCategory, vehicle.AxleConfiguration,
vehicle.GrossVehicleMassRating, vehicle.CurbWeightChassis)
vehicleData = doa.CreateVehicleData(vehicle, segment.Missions.First(),
segment.Missions.First().Loadings.First().Value)
Else
Dim doa = New EngineeringDataAdapter()
vehicleData = doa.CreateVehicleData(vehicle)
End If
Dim result = vehicleData.Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering))
If Not result.Any() Then Return ValidationResult.Success
Return New ValidationResult("Vehicle Configuration is invalid. ", result.Select(Function(r) r.ErrorMessage).ToList())
Catch ex As Exception
Return New ValidationResult(ex.Message)
End Try
Private Sub SetDefault()
Mass = 0
MassExtra = 0
Loading = 0
CdA0 = 0
' CdA0Act = CdA0
' CdA02 = 0
CrossWindCorrectionFile.Clear()
CrossWindCorrectionMode = CrossWindCorrectionMode.NoCorrection
DynamicTyreRadius = 0
RetarderType = RetarderType.None
RetarderRatio = 1
RetarderLossMapFile.Clear()
AngularGearLossMapFile.Clear()
AngularGearType = AngularGearType.None
AngularGearLossMapFile.Clear()
AngularGearRatio = 1
PTOType = PTOTransmission.NoPTO
PTOLossMap.Clear()
PTOCycle.Clear()
Axles.Clear()
VehicleCategory = VehicleCategory.RigidTruck 'tVehCat.Undef
AxleConfiguration = AxleConfiguration.AxleConfig_4x2 'tAxleConf.Undef
SavedInDeclMode = False
End Sub
Public Function SaveFile() As Boolean
SavedInDeclMode = Cfg.DeclMode
Dim validationResults = Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering))
If validationResults.Count > 0 Then
Dim messages = validationResults.Select(Function(r) r.ErrorMessage + String.Join(", ", r.MemberNames.Distinct()))
MsgBox("Invalid input." + Environment.NewLine + String.Join("; ", messages), MsgBoxStyle.OkOnly,
Return False
End If
Dim json As New JSONParser
'Header
Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
{"Date", Now.ToUniversalTime().ToString("o")},
{"AppVersion", VECTOvers},
{"FileVersion", FormatVersion}}
Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
{"SavedInDeclMode", Cfg.DeclMode},
{"VehCat", VehicleCategory.ToString()},
{"CurbWeight", Mass},
{"CurbWeightExtra", MassExtra},
{"Loading", Loading},
{"MassMax", MassMax},
{"CdA", CdA0},
{"rdyn", DynamicTyreRadius},
{"CdCorrMode", CrossWindCorrectionMode.GetName()},
{"CdCorrFile", CrossWindCorrectionFile.PathOrDummy},
{"Retarder", New Dictionary(Of String, Object) From {
{"Type", RetarderType.GetName()},
{"Ratio", RetarderRatio},
{"File", RetarderLossMapFile.PathOrDummy}}},
{"AngularGear", New Dictionary(Of String, Object) From {
{"Type", AngularGearType.ToString()},
{"Ratio", AngularGearRatio},
{"LossMap", AngularGearLossMapFile.PathOrDummy}}},
{"PTO", New Dictionary(Of String, Object) From {
{"Type", PTOType},
{"LossMap", PTOLossMap.PathOrDummy},
{"Cycle", PTOCycle.PathOrDummy}}},
{"AxleConfig", New Dictionary(Of String, Object) From {
{"Type", AxleConfiguration.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 = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
Return json.WriteFile(_filePath)
End Function
#Region "Properties"
Public Property FilePath() As String
Get
Return _filePath
End Get
Set(value As String)
_filePath = value
If _filePath = "" Then
_path = ""
_path = Path.GetDirectoryName(_filePath) & "\"
End If
End Set
End Property
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
#End Region
#Region "IInputData"
Public ReadOnly Property SavedInDeclarationMode As Boolean Implements IComponentInputData.SavedInDeclarationMode
Get
Return Cfg.DeclMode
End Get
End Property
Public ReadOnly Property Vendor As String Implements IComponentInputData.Vendor
Get
Return "N.A." ' TODO: MQ 20160908
End Get
End Property
Public ReadOnly Property ModelName As String Implements IComponentInputData.ModelName
Get
Return "N.A." ' Todo: MQ 20160908
End Get
End Property
Public ReadOnly Property Creator As String Implements IComponentInputData.Creator
Get
Return Lic.LicString
End Get
End Property
Public ReadOnly Property [Date] As String Implements IComponentInputData.[Date]
Get
Return Now.ToUniversalTime().ToString("o")
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
End Get
End Property
Public ReadOnly Property TypeId As String Implements IComponentInputData.TypeId
Get
Return "N.A." ' ToDo: MQ 20160908
End Get
End Property
Public ReadOnly Property DigestValue As String Implements IComponentInputData.DigestValue
Get
Return ""
End Get
End Property
Public ReadOnly Property IntegrityStatus As IntegrityStatus Implements IComponentInputData.IntegrityStatus
Get
Return IntegrityStatus.NotChecked
End Get
End Property
Public ReadOnly Property IVehicleDeclarationInputData_VehicleCategory As VehicleCategory _
Implements IVehicleDeclarationInputData.VehicleCategory
Get
Return VehicleCategory
End Get
End Property
Public ReadOnly Property IVehicleDeclarationInputData_AxleConfiguration As AxleConfiguration _
Implements IVehicleDeclarationInputData.AxleConfiguration
Get
Return AxleConfiguration
End Get
End Property
Public ReadOnly Property CurbWeightChassis As Kilogram Implements IVehicleDeclarationInputData.CurbWeightChassis
Get
Return MassExtra.SI(Of Kilogram)()
End Get
End Property
Public ReadOnly Property GrossVehicleMassRating As Kilogram _
Implements IVehicleDeclarationInputData.GrossVehicleMassRating
Get
Return MassMax.SI().Ton.Cast(Of Kilogram)()
End Get
End Property
Public ReadOnly Property AirDragArea As SquareMeter Implements IVehicleDeclarationInputData.AirDragArea
Get
Return CdA0.SI(Of SquareMeter)()
End Get
End Property
Public ReadOnly Property IVehicleEngineeringInputData_Axles As IList(Of IAxleEngineeringInputData) _
Implements IVehicleEngineeringInputData.Axles
Get
Return AxleWheels().Cast(Of IAxleEngineeringInputData)().ToList()
End Get
End Property
Public ReadOnly Property IVehicleDeclarationInputData_Axles As IList(Of IAxleDeclarationInputData) _
Implements IVehicleDeclarationInputData.Axles
Get
Return AxleWheels().Cast(Of IAxleDeclarationInputData)().ToList()
End Get
End Property
Private Function AxleWheels() As IEnumerable(Of AxleInputData)
Return Axles.Select(Function(axle) New AxleInputData With {
.Inertia = axle.Inertia.SI(Of KilogramSquareMeter)(),
.Wheels = axle.Wheels,
.AxleWeightShare = axle.Share,
.TwinTyres = axle.TwinTire,
.RollResistanceCoefficient = axle.RRC,
.TyreTestLoad = axle.FzISO.SI(Of Newton)()
})
End Function
Public ReadOnly Property CurbWeightExtra As Kilogram Implements IVehicleEngineeringInputData.CurbWeightExtra
Get
Return Mass.SI(Of Kilogram)()
End Get
End Property
Public ReadOnly Property CrosswindCorrectionMap As TableData _
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
Implements IVehicleEngineeringInputData.CrosswindCorrectionMap
Get
Return VectoCSVFile.Read(CrossWindCorrectionFile.FullPath)
End Get
End Property
Public ReadOnly Property IVehicleEngineeringInputData_CrossWindCorrectionMode As CrossWindCorrectionMode _
Implements IVehicleEngineeringInputData.CrossWindCorrectionMode
Get
Return CrossWindCorrectionMode.DeclarationModeCorrection
End Get
End Property
Public ReadOnly Property IVehicleEngineeringInputData_DynamicTyreRadius As Meter _
Implements IVehicleEngineeringInputData.DynamicTyreRadius
Get
Return DynamicTyreRadius.SI().Milli.Meter.Cast(Of Meter)()
End Get
End Property
Public ReadOnly Property IVehicleEngineeringInputData_Loading As Kilogram _
Implements IVehicleEngineeringInputData.Loading
Get
Return Loading.SI(Of Kilogram)()
End Get
End Property