diff --git a/VECTO/GUI/GearboxForm.vb b/VECTO/GUI/GearboxForm.vb index 1151983a30e8928e9cf90550119a46592827bfed..16ff1fae24b8e26519933fd2e4eb67a0513d000d 100644 --- a/VECTO/GUI/GearboxForm.vb +++ b/VECTO/GUI/GearboxForm.vb @@ -126,7 +126,7 @@ Public Class GearboxForm End Sub Private Sub ToolStripBtOpen_Click(sender As Object, e As EventArgs) Handles ToolStripBtOpen.Click - If GearboxFileBrowser.OpenDialog(GbxFile) Then openGBX(GearboxFileBrowser.Files(0)) + If GearboxFileBrowser.OpenDialog(GbxFile) Then OpenGbx(GearboxFileBrowser.Files(0)) End Sub Private Sub ToolStripBtSave_Click(sender As Object, e As EventArgs) Handles ToolStripBtSave.Click @@ -216,23 +216,16 @@ Public Class GearboxForm End Sub 'Open file - Public Sub openGBX(ByVal file As String) - Dim GBX0 As Gearbox - Dim i As Integer - 'Dim lv0 As ListViewItem + Public Sub OpenGbx(file As String) If ChangeCheckCancel() Then Exit Sub - GBX0 = New Gearbox - - GBX0.FilePath = file - - If Not GBX0.ReadFile Then - MsgBox("Cannot read " & file & "!") - Exit Sub - End If + Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(file), + IEngineeringInputDataProvider) + Dim gearbox As IGearboxEngineeringInputData = inputData.GearboxInputData + Dim axlegear As IAxleGearInputData = inputData.AxleGearInputData - If Cfg.DeclMode <> GBX0.SavedInDeclMode Then + If Cfg.DeclMode <> gearbox.SavedInDeclarationMode Then Select Case WrongMode() Case 1 Close() @@ -240,57 +233,49 @@ Public Class GearboxForm MainForm.OpenVectoFile(file) Case -1 Exit Sub - Case Else '0 - 'Continue... End Select End If - TbName.Text = GBX0.ModelName - TbTracInt.Text = GBX0.TracIntrSi.ToString - TBI_getr.Text = GBX0.GbxInertia.ToString - - 'ChTCon.Checked = GBX0.TorqueConverterEnabled + TbName.Text = gearbox.ModelName + TbTracInt.Text = gearbox.TractionInterruption.ToGUIFormat() + TBI_getr.Text = gearbox.Inertia.ToGUIFormat() LvGears.Items.Clear() - For i = 0 To GBX0.GearRatios.Count - 1 - - If i = 0 Then - 'lv0 = New ListViewItem("Axle") - LvGears.Items.Add(CreateListviewItem("Axle", "-", GBX0.GearRatios(i), GBX0.GearLossMap(i, True), - GBX0.ShiftPolygonFile(i, True), - GBX0.MaxTorque(i))) - Else - 'lv0 = New ListViewItem(i.ToString("00")) - LvGears.Items.Add(CreateListviewItem(i.ToString("00"), "-", GBX0.GearRatios(i), GBX0.GearLossMap(i, True), - GBX0.ShiftPolygonFile(i, True), GBX0.MaxTorque(i))) - End If + LvGears.Items.Add(CreateListviewItem("Axle", "-", axlegear.Ratio, axlegear.LossMap.Source, "", "")) + For Each gear As ITransmissionInputData In gearbox.Gears + LvGears.Items.Add(CreateListviewItem(gear.Gear.ToString("00"), "-", gear.Ratio, gear.LossMap.Source, + gear.ShiftPolygon.Source, If(gear.MaxTorque Is Nothing, "", gear.MaxTorque.ToGUIFormat()))) Next - ChSkipGears.Checked = GBX0.SkipGears - TbTqResv.Text = GBX0.TorqueResv.ToString - TbShiftTime.Text = GBX0.ShiftTime.ToString - TbTqResvStart.Text = GBX0.TorqueResvStart.ToString - TbStartSpeed.Text = GBX0.StartSpeed.ToString - TbStartAcc.Text = GBX0.StartAcc.ToString - ChShiftInside.Checked = GBX0.ShiftInside - - TbTCfile.Text = GBX0.TorqueConverterFile(True) - TbTCrefrpm.Text = GBX0.TorqueConverterReferenceRpm.ToGUIFormat() - TbTCinertia.Text = GBX0.TorqueConverterInertia.ToGUIFormat() - TBTCShiftPolygon.Text = GBX0.TorqueConverterShiftPolygonFile - - tbUpshiftMinAcceleration.Text = GBX0.UpshiftMinAcceleration.ToGUIFormat() - tbDownshiftAfterUpshift.Text = GBX0.DownshiftAfterUpshift.ToGUIFormat() - tbUpshiftAfterDownshift.Text = GBX0.UpshiftAfterDownshift.ToGUIFormat() - - CbGStype.SelectedValue = GBX0.Type - 'If CType(GBX0.gs_Type, Integer) <= Me.CbGStype.Items.Count - 1 Then - ' Me.CbGStype.SelectedIndex = CType(GBX0.gs_Type, Integer) - 'Else - ' Me.CbGStype.SelectedIndex = 0 - 'End If + ChSkipGears.Checked = gearbox.SkipGears + TbTqResv.Text = gearbox.TorqueReserve.ToGUIFormat() + TbShiftTime.Text = gearbox.ShiftTime.ToGUIFormat() + TbTqResvStart.Text = gearbox.StartTorqueReserve.ToGUIFormat() + TbStartSpeed.Text = gearbox.StartSpeed.ToGUIFormat() + TbStartAcc.Text = gearbox.StartAcceleration.ToGUIFormat() + ChShiftInside.Checked = gearbox.EarlyShiftUp + + Dim torqueConverter As ITorqueConverterEngineeringInputData = gearbox.TorqueConverter + If torqueConverter Is Nothing Then + TbTCfile.Text = "" + TbTCrefrpm.Text = "" + TbTCinertia.Text = "" + TBTCShiftPolygon.Text = "" + Else + TbTCfile.Text = torqueConverter.TCData.Source + TbTCrefrpm.Text = torqueConverter.ReferenceRPM.AsRPM.ToGUIFormat() + TbTCinertia.Text = torqueConverter.Inertia.ToGUIFormat() + TBTCShiftPolygon.Text = torqueConverter.ShiftPolygon.Source + End If + + tbUpshiftMinAcceleration.Text = gearbox.UpshiftMinAcceleration.ToGUIFormat() + tbDownshiftAfterUpshift.Text = gearbox.DownshiftAferUpshiftDelay.ToGUIFormat() + tbUpshiftAfterDownshift.Text = gearbox.UpshiftAfterDownshiftDelay.ToGUIFormat() + + CbGStype.SelectedValue = gearbox.Type + DeclInit() @@ -306,13 +291,13 @@ Public Class GearboxForm End Sub Private Function CreateListviewItem(gear As String, tc As String, ratio As Double, getrMap As String, - shiftPolygon As String, fldFile As String) As ListViewItem + shiftPolygon As String, maxTorque As String) As ListViewItem Dim retVal As ListViewItem = New ListViewItem(gear) 'retVal.SubItems.Add(tc) retVal.SubItems.Add(ratio.ToGUIFormat()) retVal.SubItems.Add(getrMap) retVal.SubItems.Add(shiftPolygon) - retVal.SubItems.Add(fldFile) + retVal.SubItems.Add(maxTorque) Return retVal End Function diff --git a/VECTO/GUI/VectoJobForm.vb b/VECTO/GUI/VectoJobForm.vb index 6d6bf71c96f77e4124b709e6c7f69ad44dd01f97..281f0ae1dc657c2062c747ba3f1e789c52e03168 100644 --- a/VECTO/GUI/VectoJobForm.vb +++ b/VECTO/GUI/VectoJobForm.vb @@ -8,7 +8,7 @@ ' 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 +'Option Infer On Imports System.Collections.Generic Imports System.Drawing.Imaging @@ -21,7 +21,9 @@ Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore.InputData.FileIO.JSON +Imports TUGraz.VectoCore.InputData.Reader Imports TUGraz.VectoCore.Models.Declaration +Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox ''' <summary> ''' Job Editor. Create/Edit VECTO job files (.vecto) @@ -292,7 +294,7 @@ Public Class VectoJobForm GearboxForm.BringToFront() End If - If Not Trim(f) = "" Then GearboxForm.openGBX(f) + If Not Trim(f) = "" Then GearboxForm.OpenGbx(f) End Sub #End Region @@ -365,7 +367,7 @@ Public Class VectoJobForm VECTOnew() 'Read GEN - Dim VEC0 = New VectoJob + Dim VEC0 As VectoJob = New VectoJob VEC0.FilePath = file Try If Not VEC0.ReadFile() Then @@ -422,8 +424,9 @@ Public Class VectoJobForm LvAux.Items.Clear() + Dim AuxEntryKV As KeyValuePair(Of String, VectoJob.AuxEntry) For Each AuxEntryKV In VEC0.AuxPaths - Dim lv0 = New ListViewItem + Dim lv0 As ListViewItem = New ListViewItem lv0.SubItems(0).Text = AuxEntryKV.Key lv0.SubItems.Add(AuxEntryKV.Value.Type) If Cfg.DeclMode Then @@ -434,8 +437,9 @@ Public Class VectoJobForm LvAux.Items.Add(lv0) Next + Dim sb As SubPath For Each sb In VEC0.CycleFiles - Dim lv0 = New ListViewItem + Dim lv0 As ListViewItem = New ListViewItem lv0.Text = sb.OriginalPath LvCycles.Items.Add(lv0) Next @@ -497,10 +501,10 @@ Public Class VectoJobForm If cboAdvancedAuxiliaries.SelectedIndex > 0 Then 'resolve absolute path for auxiliary file. - Dim absoluteAAUxFile = ResolveAAUXFilePath(GetPath(VECTOfile), txtAdvancedAuxiliaryFile.Text) + Dim absoluteAAUxFile As String = ResolveAAUXFilePath(GetPath(VECTOfile), txtAdvancedAuxiliaryFile.Text) - Dim aaAssemblyName = DirectCast(cboAdvancedAuxiliaries.SelectedItem, AdvancedAuxiliary).AssemblyName - Dim aaAssemblyVersion = DirectCast(cboAdvancedAuxiliaries.SelectedItem, AdvancedAuxiliary).AuxiliaryVersion + Dim aaAssemblyName As String = DirectCast(cboAdvancedAuxiliaries.SelectedItem, AdvancedAuxiliary).AssemblyName + Dim aaAssemblyVersion As String = DirectCast(cboAdvancedAuxiliaries.SelectedItem, AdvancedAuxiliary).AuxiliaryVersion If Not ValidateAAUXFile(absoluteAAUxFile, aaAssemblyName, aaAssemblyVersion, message) Then @@ -513,7 +517,7 @@ Public Class VectoJobForm End If - Dim vec0 = New VectoJob + Dim vec0 As VectoJob = New VectoJob vec0.FilePath = file 'Files ------------------------------------------------- ----------------- @@ -522,7 +526,7 @@ Public Class VectoJobForm vec0.PathEng = TbENG.Text For Each lv0 As ListViewItem In LvCycles.Items - Dim sb = New SubPath + Dim sb As SubPath = New SubPath sb.Init(GetPath(file), lv0.Text) vec0.CycleFiles.Add(sb) Next @@ -545,7 +549,7 @@ Public Class VectoJobForm vec0.AdvancedAuxiliaryFilePath = txtAdvancedAuxiliaryFile.Text For Each lv0 As ListViewItem In LvAux.Items - Dim auxEntry = New VectoJob.AuxEntry + Dim auxEntry As VectoJob.AuxEntry = New VectoJob.AuxEntry If Cfg.DeclMode Then auxEntry.TechnologyList.Clear() @@ -792,7 +796,7 @@ lbDlog: Exit Sub End If - Dim selItem = LvAux.SelectedItems(0) + Dim selItem As ListViewItem = LvAux.SelectedItems(0) _auxDialog.VehPath = GetPath(VECTOfile) _auxDialog.CbType.SelectedIndex = -1 @@ -881,6 +885,7 @@ lbDlog: Dim genDir As String = GetPath(VECTOfile) If DrivingCycleFileBrowser.OpenDialog("", True) Then + Dim s As String For Each s In DrivingCycleFileBrowser.Files LvCycles.Items.Add(GetFilenameWithoutDirectory(s, genDir)) Next @@ -990,20 +995,13 @@ lbDlog: Dim i As Integer Dim pmax As Double - Dim f As CsvFile - Dim lM As List(Of Single) - Dim lup As List(Of Single) - Dim ldown As List(Of Single) - Dim line As String() - - Dim HDVclass As String - + Dim s As Series Dim a As ChartArea Dim img As Bitmap - Dim EngOK = False + Dim EngOK As Boolean = False TbHVCclass.Text = "" TbVehCat.Text = "" @@ -1016,14 +1014,15 @@ lbDlog: Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(TbVEH.Text), IEngineeringInputDataProvider) - Dim vehicle = inputData.VehicleInputData + Dim vehicle As IVehicleEngineeringInputData = inputData.VehicleInputData If Not vehicle Is Nothing Then - Dim maxMass = vehicle.GrossVehicleMassRating 'CSng(fTextboxToNumString(TbMassMass.Text)) + Dim maxMass As Kilogram = vehicle.GrossVehicleMassRating 'CSng(fTextboxToNumString(TbMassMass.Text)) Dim s0 As Segment = Nothing Try - s0 = DeclarationData.Segments.Lookup(vehicle.VehicleCategory, vehicle.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 @@ -1031,6 +1030,7 @@ lbDlog: If Cfg.DeclMode Then LvCycles.Items.Clear() + Dim m0 As Mission For Each m0 In s0.Missions LvCycles.Items.Add(m0.MissionType.ToString()) Next @@ -1051,19 +1051,19 @@ lbDlog: End If - Dim OkCount = 0 + Dim OkCount As Integer = 0 - Dim ENG0 = New Engine + Dim ENG0 As Engine = New Engine ENG0.FilePath = fFileRepl(TbENG.Text, GetPath(VECTOfile)) 'Create plot - Dim MyChart = New Chart + Dim MyChart As Chart = New Chart MyChart.Width = PicBox.Width MyChart.Height = PicBox.Height a = New ChartArea - Dim FLD0 = New EngineFullLoadCurve + Dim FLD0 As EngineFullLoadCurve = New EngineFullLoadCurve If ENG0.ReadFile(False) Then @@ -1100,7 +1100,7 @@ lbDlog: TbEngTxt.Text = (ENG0.Displacement / 1000).ToString("0.0") & " l " & pmax.ToString("#") & " kW " & ENG0.ModelName - Dim MAP0 = New FuelconsumptionMap + Dim MAP0 As FuelconsumptionMap = New FuelconsumptionMap MAP0.FilePath = ENG0.PathMAP If MAP0.ReadFile(False) Then @@ -1119,18 +1119,17 @@ lbDlog: End If - Dim GBX0 = New Gearbox - GBX0.FilePath = fFileRepl(TbGBX.Text, GetPath(VECTOfile)) + Dim gearbox As IGearboxEngineeringInputData = inputData.GearboxInputData - If GBX0.ReadFile(False) Then + If Not gearbox Is Nothing Then - TbGbxTxt.Text = GBX0.GearCount & "-Speed " & GBX0.Type.ShortName() & " " & GBX0.ModelName + TbGbxTxt.Text = gearbox.Gears.Count & "-Speed " & gearbox.Type.ShortName() & " " & gearbox.ModelName If Cfg.DeclMode Then If EngOK Then - For i = 1 To GBX0.GearCount + For i = 1 To gearbox.Gears.Count FLD0.FilePath = ENG0.PathFLD @@ -1179,52 +1178,27 @@ lbDlog: Else - f = New CsvFile - For i = 1 To GBX0.GearCount - - lM = New List(Of Single) - lup = New List(Of Single) - ldown = New List(Of Single) - - If f.OpenRead(GBX0.ShiftPolygonFile(i)) Then - - f.ReadLine() - - Try - - Do While Not f.EndOfFile - line = f.ReadLine - lM.Add(CSng(line(0))) - lup.Add(CSng(line(1))) - ldown.Add(CSng(line(2))) - Loop - - s = New Series - s.Points.DataBindXY(lup, lM) - s.ChartType = SeriesChartType.FastLine - s.BorderWidth = 2 - s.Color = Color.DarkRed - s.Name = "Upshift curve" - ' MyChart.Series.Add(s) 'MQ 2016-06-20: do not plot shift lines in engine dialog - - s = New Series - s.Points.DataBindXY(ldown, lM) - s.ChartType = SeriesChartType.FastLine - s.BorderWidth = 2 - s.Color = Color.DarkRed - s.Name = "Downshift curve" - 'MyChart.Series.Add(s) 'MQ 2016-06-20:do not plot shift lines in engine dialog - - OkCount += 1 - - f.Close() - - Catch ex As Exception - f.Close() - End Try - - End If - + For Each gear As ITransmissionInputData In gearbox.Gears + Dim shiftPolygon As ShiftPolygon = ShiftPolygonReader.Create(gear.ShiftPolygon) + s = New Series + s.Points.DataBindXY(shiftPolygon.Upshift.Select(Function(x) x.AngularSpeed), + shiftPolygon.Upshift.Select(Function(x) x.Torque)) + s.ChartType = SeriesChartType.FastLine + s.BorderWidth = 2 + s.Color = Color.DarkRed + s.Name = "Upshift curve" + ' MyChart.Series.Add(s) 'MQ 2016-06-20: do not plot shift lines in engine dialog + + s = New Series + s.Points.DataBindXY(shiftPolygon.Downshift.Select(Function(x) x.AngularSpeed), + shiftPolygon.Downshift.Select(Function(x) x.Torque)) + s.ChartType = SeriesChartType.FastLine + s.BorderWidth = 2 + s.Color = Color.DarkRed + s.Name = "Downshift curve" + 'MyChart.Series.Add(s) 'MQ 2016-06-20:do not plot shift lines in engine dialog + + OkCount += 1 Next End If diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb index 07f2c05adfbaf142c2a8bcfb77fc816353bbda9a..42b43120bd9652d18cc86919e29fd69e7c9261a3 100644 --- a/VECTO/GUI/VehicleForm.vb +++ b/VECTO/GUI/VehicleForm.vb @@ -8,7 +8,7 @@ ' 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 +'Option Infer On Imports System.IO Imports System.Linq @@ -149,8 +149,9 @@ Public Class VehicleForm If Not s0 Is Nothing Then _hdVclass = s0.VehicleClass.GetClassNumber() Dim axleCount As Integer = s0.Missions(0).AxleWeightDistribution.Count() - Dim i0 = LvRRC.Items.Count + Dim i0 As Integer = LvRRC.Items.Count + Dim i As Integer If axleCount > i0 Then For i = 1 To axleCount - LvRRC.Items.Count LvRRC.Items.Add(CreateListViewItem(i + i0, Double.NaN, False, Double.NaN, Double.NaN, "", Double.NaN)) @@ -242,8 +243,9 @@ Public Class VehicleForm 'Help Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click If File.Exists(MyAppPath & "User Manual\help.html") Then - Dim registryString = My.Computer.Registry.ClassesRoot.OpenSubKey("\http\shell\open\command\").GetValue("").ToString - Dim defaultBrowserPath = Regex.Match(registryString, "(\"".*?\"")").Captures(0).ToString + Dim registryString As String = + My.Computer.Registry.ClassesRoot.OpenSubKey("\http\shell\open\command\").GetValue("").ToString + Dim defaultBrowserPath As String = Regex.Match(registryString, "(\"".*?\"")").Captures(0).ToString Process.Start(defaultBrowserPath, String.Format("""{0}{1}""", MyAppPath, "User Manual\help.html#vehicle-editor")) Else MsgBox("User Manual not found!", MsgBoxStyle.Critical) @@ -316,18 +318,17 @@ Public Class VehicleForm 'Open VEH Sub OpenVehicle(file As String) - Dim inertia As Double If ChangeCheckCancel() Then Exit Sub 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 + Dim vehicle As IVehicleEngineeringInputData = inputData.VehicleInputData + Dim retarder As IRetarderInputData = inputData.RetarderInputData + Dim angularGear As IAngularGearInputData = inputData.AngularGearInputData + Dim pto As IPTOTransmissionInputData = inputData.PTOTransmissionInputData - If Cfg.DeclMode <> veh.SavedInDeclarationMode Then + If Cfg.DeclMode <> vehicle.SavedInDeclarationMode Then Select Case WrongMode() Case 1 Close() @@ -339,17 +340,17 @@ Public Class VehicleForm End If Dim basePath As String = Path.GetDirectoryName(file) - CbCat.SelectedValue = veh.VehicleCategory - CbAxleConfig.SelectedValue = veh.AxleConfiguration - TbMassMass.Text = (veh.GrossVehicleMassRating.Value() / 1000).ToGUIFormat() + CbCat.SelectedValue = vehicle.VehicleCategory + CbAxleConfig.SelectedValue = vehicle.AxleConfiguration + TbMassMass.Text = (vehicle.GrossVehicleMassRating.Value() / 1000).ToGUIFormat() - TbMass.Text = veh.CurbWeightChassis.ToGUIFormat() - TbMassExtra.Text = veh.CurbWeightExtra.ToGUIFormat() - TbLoad.Text = veh.Loading.ToGUIFormat() - TBrdyn.Text = veh.DynamicTyreRadius.ToGUIFormat() + TbMass.Text = vehicle.CurbWeightChassis.ToGUIFormat() + TbMassExtra.Text = vehicle.CurbWeightExtra.ToGUIFormat() + TbLoad.Text = vehicle.Loading.ToGUIFormat() + TBrdyn.Text = vehicle.DynamicTyreRadius.ToGUIFormat() - CbCdMode.SelectedValue = veh.CrossWindCorrectionMode - TbCdFile.Text = GetRelativePath(veh.CrosswindCorrectionMap.Source, basePath) + CbCdMode.SelectedValue = vehicle.CrossWindCorrectionMode + TbCdFile.Text = GetRelativePath(vehicle.CrosswindCorrectionMap.Source, basePath) CbRtType.SelectedValue = retarder.Type TbRtRatio.Text = retarder.Ratio.ToGUIFormat() @@ -361,13 +362,14 @@ Public Class VehicleForm tbAngularGearLossMapPath.Text = GetRelativePath(angularGear.LossMap.Source, basePath) LvRRC.Items.Clear() - Dim i = 0 - For Each a0 In veh.Axles + Dim i As Integer = 0 + Dim a0 As IAxleEngineeringInputData + For Each a0 In vehicle.Axles i += 1 If Cfg.DeclMode Then - inertia = DeclarationData.Wheels.Lookup(a0.Wheels).Inertia.Value() + Dim inertia As Double = DeclarationData.Wheels.Lookup(a0.Wheels).Inertia.Value() LvRRC.Items.Add(CreateListViewItem(i, Double.NaN, a0.TwinTyres, a0.RollResistanceCoefficient, a0.TyreTestLoad.Value(), a0.Wheels, inertia)) Else @@ -381,7 +383,7 @@ Public Class VehicleForm 'TbMassExtra.Text = veh.MassExtra.ToGUIFormat() - TBcdA.Text = veh.AirDragArea.ToGUIFormat() + TBcdA.Text = vehicle.AirDragArea.ToGUIFormat() cbPTOType.SelectedValue = pto.PTOTransmissionType tbPTOLossMap.Text = GetRelativePath(pto.PTOLossMap.Source, basePath) @@ -423,7 +425,7 @@ Public Class VehicleForm 'Save VEH Private Function SaveVehicle(file As String) As Boolean - Dim veh = New Vehicle + Dim veh As Vehicle = New Vehicle veh.FilePath = file veh.Mass = TbMass.Text.ToDouble() @@ -446,7 +448,7 @@ Public Class VehicleForm veh.VehicleCategory = CType(CbCat.SelectedValue, VehicleCategory) 'CType(CbCat.SelectedIndex, tVehCat) For Each entry As ListViewItem In LvRRC.Items - Dim a0 = New Vehicle.Axle + Dim a0 As Vehicle.Axle = New Vehicle.Axle a0.Share = entry.SubItems(AxleTbl.RelativeLoad).Text.ToDouble(0) a0.TwinTire = (entry.SubItems(AxleTbl.TwinTyres).Text = "yes") a0.RRC = entry.SubItems(AxleTbl.RRC).Text.ToDouble(0) @@ -715,7 +717,7 @@ Public Class VehicleForm Private Sub EditAxleItem() If LvRRC.SelectedItems.Count = 0 Then Exit Sub - Dim lv0 = LvRRC.SelectedItems(0) + Dim lv0 As ListViewItem = LvRRC.SelectedItems(0) _axlDlog.TbAxleShare.Text = lv0.SubItems(AxleTbl.RelativeLoad).Text _axlDlog.CbTwinT.Checked = (lv0.SubItems(AxleTbl.TwinTyres).Text = "yes") diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb index 97359c9f52b5014dedcefb8c9bae623d79e27b81..0b10618d1cd207df3a146b453bb1385b98e4983b 100644 --- a/VECTO/Input Files/Gearbox.vb +++ b/VECTO/Input Files/Gearbox.vb @@ -9,14 +9,28 @@ ' ' See the LICENSE.txt for the specific language governing permissions and limitations. 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.Models.SimulationComponent.Data.Gearbox +Imports TUGraz.VectoCore.Utils + +<CustomValidation(GetType(Gearbox), "ValidateGearbox")> Public Class Gearbox + Implements IGearboxEngineeringInputData, IGearboxDeclarationInputData, IAxleGearInputData, + ITorqueConverterEngineeringInputData, + ITorqueConverterDeclarationInputData + Private Const FormatVersion As Short = 6 Private _fileVersion As Integer @@ -96,6 +110,20 @@ Public Class Gearbox End Sub Public Function SaveFile() As Boolean + + SavedInDeclMode = Cfg.DeclMode + + Dim validationResults As IList(Of ValidationResult) = + Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) + + If validationResults.Count > 0 Then + Dim messages As IEnumerable(Of String) = + validationResults.Select(Function(r) r.ErrorMessage + String.Join(", ", r.MemberNames.Distinct())) + MsgBox("Invalid input." + Environment.NewLine + String.Join("; ", messages), MsgBoxStyle.OkOnly, + "Failed to save gearbox") + Return False + End If + Dim i As Integer Dim json As New JSONParser @@ -118,7 +146,7 @@ Public Class Gearbox body.Add("Inertia", GbxInertia) body.Add("TracInt", TracIntrSi) - Dim ls As New List(Of Object) + Dim ls As New List(Of Dictionary(Of String, Object)) For i = 0 To GearRatios.Count - 1 Dim gearDict As New Dictionary(Of String, Object) gearDict.Add("Ratio", GearRatios(i)) @@ -165,110 +193,6 @@ Public Class Gearbox Return json.WriteFile(_filePath) End Function - Public Function ReadFile(Optional ByVal showMsg As Boolean = True) As Boolean - Dim i As Integer - Dim json As New JSONParser - Dim dic As JToken - - Const msgSrc As String = "GBX/ReadFile" - - SetDefault() - - If Not json.ReadFile(_filePath) Then Return False - - Try - - _fileVersion = json.Content.GetEx("Header").GetEx(Of Integer)("FileVersion") - - Dim body As JToken = json.Content.GetEx("Body") - If _fileVersion > 3 Then - SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") - Else - SavedInDeclMode = Cfg.DeclMode - End If - - ModelName = body.GetEx(Of String)("ModelName") - GbxInertia = body.GetEx(Of Double)("Inertia") - TracIntrSi = body.GetEx(Of Double)("TracInt") - - i = -1 - For Each dic In body.GetEx("Gears") - i += 1 - - GearRatios.Add(dic.GetEx(Of Double)("Ratio")) - GearLossmaps.Add(New SubPath) - - If dic("Efficiency") Is Nothing Then - GearLossmaps(i).Init(_myPath, dic.GetEx(Of String)("LossMap")) - Else - GearLossmaps(i).Init(_myPath, dic.GetEx(Of Double)("Efficiency").ToString()) - End If - - MaxTorque.Add(dic.GetEx(Of String)("MaxTorque")) - GearshiftFiles.Add(New SubPath) - - If i = 0 Then - GearshiftFiles(i).Init(_myPath, Constants.NoFile) - Else - If _fileVersion < 2 Then - GearshiftFiles(i).Init(_myPath, body.GetEx(Of String)("ShiftPolygons")) - Else - GearshiftFiles(i).Init(_myPath, dic.GetEx(Of String)("ShiftPolygon")) - End If - End If - - Next - - TorqueResv = body.GetEx(Of Double)("TqReserve") - SkipGears = body.GetEx(Of Boolean)("SkipGears") - ShiftTime = body.GetEx(Of Double)("ShiftTime") - TorqueResvStart = body.GetEx(Of Double)("StartTqReserve") - StartSpeed = body.GetEx(Of Double)("StartSpeed") - StartAcc = body.GetEx(Of Double)("StartAcc") - ShiftInside = body.GetEx(Of Boolean)("EaryShiftUp") - - Type = json.Content("Body")("GearboxType").ToString.ParseEnum(Of GearboxType)() - - If body("UpshiftMinAcceleration") Is Nothing Then - UpshiftMinAcceleration = 0.1 - Else - UpshiftMinAcceleration = body.GetEx(Of Double)("UpshiftMinAcceleration") - End If - If body("DownshiftAferUpshiftDelay") Is Nothing Then - DownshiftAfterUpshift = 10 - Else - DownshiftAfterUpshift = body.GetEx(Of Double)("DownshiftAferUpshiftDelay") - End If - - If body("UpshiftAfterDownshiftDelay") Is Nothing Then - UpshiftAfterDownshift = 10 - Else - UpshiftAfterDownshift = body.GetEx(Of Double)("UpshiftAfterDownshiftDelay") - End If - - - If json.Content("Body")("TorqueConverter") Is Nothing Then - TorqueConverterEnabled = False - Else - Dim torqueConverter As JToken = body.GetEx("TorqueConverter") - TorqueConverterEnabled = torqueConverter.GetEx(Of Boolean)("Enabled") - _torqueConverterFile.Init(_myPath, torqueConverter.GetEx(Of String)("File")) - TorqueConverterReferenceRpm = torqueConverter.GetEx(Of Double)("RefRPM") - If _fileVersion > 2 Then - TorqueConverterInertia = torqueConverter.GetEx(Of Double)("Inertia") - End If - If _fileVersion > 5 Then - TorqueConverterShiftPolygonFile = torqueConverter.GetEx(Of String)("ShiftPolygon") - End If - End If - Catch ex As Exception - If showMsg Then WorkerMsg(MessageType.Err, "Failed to read VECTO file! " & ex.Message, msgSrc) - Return False - End Try - - Return True - End Function - Public Function GearCount() As Integer Return GearRatios.Count - 1 @@ -327,5 +251,268 @@ Public Class Gearbox _torqueConverterFile.Init(_myPath, value) End Set End Property + + + ' ReSharper disable once UnusedMember.Global -- used by Validation + Public Shared Function ValidateGearbox(gearbox As Gearbox, validationContext As ValidationContext) As ValidationResult + Dim modeService As ExecutionModeServiceContainer = TryCast(validationContext.GetService(GetType(ExecutionMode)), + ExecutionModeServiceContainer) + Dim mode As ExecutionMode = If(modeService Is Nothing, ExecutionMode.Declaration, modeService.Mode) + + Dim axlegearData As AxleGearData + Dim gearboxData As GearboxData + + Try + 'Dim vectoJob As VectoJob = New VectoJob() With {.FilePath = VectoJobForm.VECTOfile} + Dim inputData As IEngineeringInputDataProvider = + TryCast(JSONInputDataFactory.ReadComponentData(VectoJobForm.VECTOfile), + IEngineeringInputDataProvider) + 'Dim vehicle As IVehicleEngineeringInputData = inputData.VehicleInputData + Dim engine As CombustionEngineData + Dim rdyn As Meter = 0.5.SI(Of Meter)() + If mode = ExecutionMode.Declaration Then + Dim doa As DeclarationDataAdapter = New DeclarationDataAdapter() + + engine = doa.CreateEngineData(inputData.EngineInputData, gearbox.Type) + + axlegearData = doa.CreateAxleGearData(gearbox, False) + gearboxData = doa.CreateGearboxData(gearbox, engine, axlegearData.AxleGear.Ratio, rdyn, False) + Else + Dim doa As EngineeringDataAdapter = New EngineeringDataAdapter() + engine = doa.CreateEngineData(inputData.EngineInputData, gearbox) + axlegearData = doa.CreateAxleGearData(gearbox, True) + gearboxData = doa.CreateGearboxData(gearbox, engine, axlegearData.AxleGear.Ratio, rdyn, True) + End If + + Dim result As IList(Of ValidationResult) = + gearboxData.Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) + If result.Any() Then + Return _ + New ValidationResult("Gearbox Configuration is invalid. ", result.Select(Function(r) r.ErrorMessage).ToList()) + End If + + result = axlegearData.Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) + If result.Any() Then + Return _ + New ValidationResult("Gearbox Configuration is invalid. ", result.Select(Function(r) r.ErrorMessage).ToList()) + End If + + Return ValidationResult.Success + + Catch ex As Exception + Return New ValidationResult(ex.Message) + End Try + End Function + + + 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 20160915 + 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") + End Get + End Property + + Public ReadOnly Property TypeId As String Implements IComponentInputData.TypeId + Get + Return "N.A." ' todo MQ 20160915 + 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 IComponentInputData_ModelName As String Implements IComponentInputData.ModelName + Get + Return "N.A." ' todo MQ 20160915 + End Get + End Property + + Public ReadOnly Property IGearboxDeclarationInputData_Type As GearboxType Implements IGearboxDeclarationInputData.Type + Get + Return Type + End Get + End Property + + Public ReadOnly Property Gears As IList(Of ITransmissionInputData) Implements IGearboxDeclarationInputData.Gears + Get + Dim ls As IList(Of ITransmissionInputData) = New List(Of ITransmissionInputData) + Dim i As Integer + For i = 1 To GearRatios.Count - 1 + Dim gearDict As New TransmissionInputData With { + .Ratio = GearRatios(i) + } + If File.Exists(GearshiftFiles(i).OriginalPath) Then + gearDict.ShiftPolygon = VectoCSVFile.Read(GearshiftFiles(i).OriginalPath) + End If + If Not String.IsNullOrWhiteSpace(MaxTorque(i)) AndAlso IsNumeric(MaxTorque(i)) Then + gearDict.MaxTorque = MaxTorque(i).ToDouble().SI(Of NewtonMeter)() + End If + If IsNumeric(GearLossMap(i, True)) Then + gearDict.Efficiency = GearLossMap(i, True).ToDouble() + Else + gearDict.LossMap = VectoCSVFile.Read(GearLossmaps(i).PathOrDummy) + End If + + ls.Add(gearDict) + Next + Return ls + End Get + End Property + + Public ReadOnly Property ReferenceRPM As PerSecond Implements ITorqueConverterEngineeringInputData.ReferenceRPM + Get + Return TorqueConverterReferenceRpm.RPMtoRad() + End Get + End Property + + Public ReadOnly Property ITorqueConverterEngineeringInputData_Inertia As KilogramSquareMeter _ + Implements ITorqueConverterEngineeringInputData.Inertia + Get + Return TorqueConverterInertia.SI(Of KilogramSquareMeter)() + End Get + End Property + + Public ReadOnly Property Inertia As KilogramSquareMeter Implements IGearboxEngineeringInputData.Inertia + Get + Return GbxInertia.SI(Of KilogramSquareMeter)() + End Get + End Property + + Public ReadOnly Property ShiftPolygon As TableData Implements ITorqueConverterEngineeringInputData.ShiftPolygon + Get + Return VectoCSVFile.Read(TorqueConverterShiftPolygonFile) + End Get + End Property + + Public ReadOnly Property TractionInterruption As Second Implements IGearboxEngineeringInputData.TractionInterruption + Get + Return TracIntrSi.SI(Of Second)() + End Get + End Property + + Public ReadOnly Property EarlyShiftUp As Boolean Implements IGearboxEngineeringInputData.EarlyShiftUp + Get + Return ShiftInside + End Get + End Property + + Public ReadOnly Property TorqueReserve As Double Implements IGearboxEngineeringInputData.TorqueReserve + Get + Return TorqueResv + End Get + End Property + + Public ReadOnly Property StartAcceleration As MeterPerSquareSecond _ + Implements IGearboxEngineeringInputData.StartAcceleration + Get + Return StartAcc.SI(Of MeterPerSquareSecond)() + End Get + End Property + + Public ReadOnly Property StartTorqueReserve As Double Implements IGearboxEngineeringInputData.StartTorqueReserve + Get + Return TorqueResvStart + End Get + End Property + + Public ReadOnly Property TorqueConverter As ITorqueConverterEngineeringInputData _ + Implements IGearboxEngineeringInputData.TorqueConverter + Get + Return Me + End Get + End Property + + Public ReadOnly Property DownshiftAferUpshiftDelay As Second _ + Implements IGearboxEngineeringInputData.DownshiftAferUpshiftDelay + Get + Return DownshiftAfterUpshift.SI(Of Second)() + End Get + End Property + + Public ReadOnly Property UpshiftAfterDownshiftDelay As Second _ + Implements IGearboxEngineeringInputData.UpshiftAfterDownshiftDelay + Get + Return UpshiftAfterDownshift.SI(Of Second)() + End Get + End Property + + Public ReadOnly Property IGearboxEngineeringInputData_UpshiftMinAcceleration As MeterPerSquareSecond _ + Implements IGearboxEngineeringInputData.UpshiftMinAcceleration + Get + Return UpshiftMinAcceleration.SI(Of MeterPerSquareSecond)() + End Get + End Property + + Public ReadOnly Property IGearboxEngineeringInputData_SkipGears As Boolean _ + Implements IGearboxEngineeringInputData.SkipGears + Get + Return SkipGears + End Get + End Property + + Public ReadOnly Property IGearboxEngineeringInputData_StartSpeed As MeterPerSecond _ + Implements IGearboxEngineeringInputData.StartSpeed + Get + Return StartSpeed.SI(Of MeterPerSecond)() + End Get + End Property + + Public ReadOnly Property IGearboxEngineeringInputData_ShiftTime As Second _ + Implements IGearboxEngineeringInputData.ShiftTime + Get + Return ShiftTime.SI(Of Second)() + End Get + End Property + + Public ReadOnly Property TCData As TableData Implements ITorqueConverterDeclarationInputData.TCData + Get + Return VectoCSVFile.Read(_torqueConverterFile.OriginalPath) + End Get + End Property + + + Public ReadOnly Property Ratio As Double Implements IAxleGearInputData.Ratio + Get + Return GearRatios(0) + End Get + End Property + + Public ReadOnly Property LossMap As TableData Implements IAxleGearInputData.LossMap + Get + Return VectoCSVFile.Read(GearLossmaps(0).PathOrDummy) + End Get + End Property + + Public ReadOnly Property Efficiency As Double Implements IAxleGearInputData.Efficiency + Get + Return GearLossMap(0, True).ToDouble() + End Get + End Property End Class diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb index d10e06fc86aad64ff1dfc2644c868f7b52ae8661..eb8af084c94d53ac025b57b795bfb5f6439c83f7 100644 --- a/VECTO/Input Files/Vehicle.vb +++ b/VECTO/Input Files/Vehicle.vb @@ -8,7 +8,7 @@ ' 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 +'Option Infer On Imports System.Collections.Generic Imports System.ComponentModel.DataAnnotations @@ -91,27 +91,29 @@ Public Class Vehicle End Sub + ' ReSharper disable once UnusedMember.Global -- used for Validation 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) + Dim mode As ExecutionMode = 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) + Dim doa As DeclarationDataAdapter = New DeclarationDataAdapter() + Dim segment As 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() + Dim doa As EngineeringDataAdapter = New EngineeringDataAdapter() vehicleData = doa.CreateVehicleData(vehicle) End If - Dim result = vehicleData.Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) + Dim result As IList(Of ValidationResult) = + vehicleData.Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) If Not result.Any() Then Return ValidationResult.Success @@ -158,10 +160,11 @@ Public Class Vehicle Public Function SaveFile() As Boolean SavedInDeclMode = Cfg.DeclMode - Dim validationResults = Validate(If(Cfg.DeclMode, ExecutionMode.Declaration, ExecutionMode.Engineering)) + Dim validationResults As IList(Of ValidationResult) = + 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())) + Dim messages As IEnumerable(Of String) = validationResults.Select(Function(r) r.ErrorMessage + String.Join(", ", r.MemberNames.Distinct())) MsgBox("Invalid input." + Environment.NewLine + String.Join("; ", messages), MsgBoxStyle.OkOnly, "Failed to save vehicle") Return False