From fa32c3d17229159c0c6789b24a738bafe885a8cf Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Wed, 7 Sep 2016 17:52:45 +0200 Subject: [PATCH] switched to strict mode for VECTO GUI: adaptations for type safety --- VECTO/ApplicationEvents.vb | 1 - VECTO/Configuration.vb | 43 ++--- VECTO/File Browser/FileBrowser.vb | 80 ++++----- VECTO/File Browser/FileBrowserDialog.vb | 20 +-- VECTO/GUI/EngineForm.vb | 30 ++-- VECTO/GUI/FileSignDialog.vb | 4 +- VECTO/GUI/GUI_Subs.vb | 22 +-- VECTO/GUI/GearboxForm.vb | 168 ++++++++++--------- VECTO/GUI/GearboxGearDialog.vb | 7 +- VECTO/GUI/GraphForm.vb | 73 ++++---- VECTO/GUI/MainForm.vb | 147 ++++++++-------- VECTO/GUI/Settings.vb | 3 +- VECTO/GUI/VectoJobForm.vb | 180 ++++++++++---------- VECTO/GUI/VehicleAuxiliariesDialog.vb | 19 ++- VECTO/GUI/VehicleForm.vb | 204 +++++++++++------------ VECTO/Input Files/Engine.vb | 60 +++---- VECTO/Input Files/EngineFullLoadCurve.vb | 35 ++-- VECTO/Input Files/FuelconsumptionMap.vb | 23 +-- VECTO/Input Files/Gearbox.vb | 122 +++++++------- VECTO/Input Files/SubPath.vb | 4 +- VECTO/Input Files/VectoJob.vb | 169 ++++++++++--------- VECTO/Input Files/Vehicle.vb | 128 +++++++------- VECTO/JSONparser.vb | 65 +++++--- VECTO/MainModule.vb | 11 +- VECTO/VECTO.vbproj | 19 ++- VECTO/VECTO_Global.vb | 45 ++--- VECTO/VECTO_Types.vb | 4 +- 27 files changed, 870 insertions(+), 816 deletions(-) diff --git a/VECTO/ApplicationEvents.vb b/VECTO/ApplicationEvents.vb index a701ab0812..83a924fdf0 100644 --- a/VECTO/ApplicationEvents.vb +++ b/VECTO/ApplicationEvents.vb @@ -95,7 +95,6 @@ Namespace My End If 'Initialise Classes - sKey = New csKey JobFileList = New List(Of String) 'DEV = New cDEV diff --git a/VECTO/Configuration.vb b/VECTO/Configuration.vb index 37a05ba474..65ee58a6e0 100644 --- a/VECTO/Configuration.vb +++ b/VECTO/Configuration.vb @@ -10,6 +10,8 @@ ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Collections.Generic Imports System.IO +Imports Newtonsoft.Json.Linq +Imports TUGraz.VectoCore.InputData.FileIO.JSON Imports TUGraz.VectoCore.Models.Declaration Public Class Configuration @@ -17,12 +19,12 @@ Public Class Configuration Public GnUfromCycle As Boolean Public ModOut As Boolean Public Mod1Hz As Boolean - Public LogSize As Single - Public AirDensity As Single + Public LogSize As Double + Public AirDensity As Double Public OpenCmd As String Public OpenCmdName As String - Public FuelDens As Single - Public CO2perFC As Single + Public FuelDens As Double + Public CO2perFC As Double Public FirstRun As Boolean Public DeclMode As Boolean @@ -62,28 +64,27 @@ Public Class Configuration Dim json As New JSONParser If Not json.ReadFile(FilePath) Then - GUImsg(MessageType.Err, "Failed to load settings! Using default settings.") + GUIMsg(MessageType.Err, "Failed to load settings! Using default settings.") Exit Sub End If - Try + Dim body As JToken = json.Content.GetEx("Body") Try - Mod1Hz = json.Content("Body")("Mod1Hz") + Mod1Hz = body.GetEx(Of Boolean)("Mod1Hz") Catch End Try - - ModOut = json.Content("Body")("ModOut") - GnUfromCycle = json.Content("Body")("UseGnUfromCycle") - LogSize = json.Content("Body")("LogSize") - AirDensity = json.Content("Body")("AirDensity") - FuelDens = json.Content("Body")("FuelDensity") - CO2perFC = json.Content("Body")("CO2perFC") - OpenCmd = json.Content("Body")("OpenCmd") - OpenCmdName = json.Content("Body")("OpenCmdName") - FirstRun = json.Content("Body")("FirstRun") - DeclMode = json.Content("Body")("DeclMode") + ModOut = body.GetEx(Of Boolean)("ModOut") + GnUfromCycle = body.GetEx(Of Boolean)("UseGnUfromCycle") + LogSize = body.GetEx(Of Double)("LogSize") + AirDensity = body.GetEx(Of Double)("AirDensity") + FuelDens = body.GetEx(Of Double)("FuelDensity") + CO2perFC = body.GetEx(Of Double)("CO2perFC") + OpenCmd = body.GetEx(Of String)("OpenCmd") + OpenCmdName = body.GetEx(Of String)("OpenCmdName") + FirstRun = body.GetEx(Of Boolean)("FirstRun") + DeclMode = body.GetEx(Of Boolean)("DeclMode") Catch ex As Exception - GUImsg(MessageType.Err, "Error while loading settings!") + GUIMsg(MessageType.Err, "Error while loading settings!") End Try End Sub @@ -96,7 +97,7 @@ Public Class Configuration dic.Add("Date", Now.ToUniversalTime().ToString("o")) dic.Add("AppVersion", VECTOvers) dic.Add("FileVersion", FormatVersion) - json.Content.Add("Header", dic) + json.Content.Add("Header", JToken.FromObject(dic)) dic = New Dictionary(Of String, Object) dic.Add("ModOut", ModOut) @@ -109,7 +110,7 @@ Public Class Configuration dic.Add("OpenCmdName", OpenCmdName) dic.Add("FirstRun", FirstRun) dic.Add("DeclMode", DeclMode) - json.Content.Add("Body", dic) + json.Content.Add("Body", JToken.FromObject(dic)) json.WriteFile(FilePath) End Sub diff --git a/VECTO/File Browser/FileBrowser.vb b/VECTO/File Browser/FileBrowser.vb index 6b7fbda483..36c2693ecf 100644 --- a/VECTO/File Browser/FileBrowser.vb +++ b/VECTO/File Browser/FileBrowser.vb @@ -21,28 +21,28 @@ ''' File history is unique for each ID. Folder history is global. ''' </remarks> Public Class FileBrowser - Private Initialized As Boolean - Private ReadOnly MyID As String - Private MyExt As String() - Private Dlog As FileBrowserDialog - Private NoExt As Boolean - Private ReadOnly bFolderBrowser As Boolean - Private ReadOnly bLightMode As Boolean + Private _initialized As Boolean + Private ReadOnly _id As String + Private _extensionList As String() + Private _dialog As FileBrowserDialog + Private _noExtension As Boolean + Private ReadOnly _folderBrowser As Boolean + Private ReadOnly _lightMode As Boolean ''' <summary> ''' New cFileBrowser instance ''' </summary> - ''' <param name="ID">Needed to save the file history when not using LightMode.</param> - ''' <param name="FolderBrowser">Browse folders instead of files.</param> - ''' <param name="LightMode">If enabled file history is not saved.</param> + ''' <param name="id">Needed to save the file history when not using LightMode.</param> + ''' <param name="folderBrowser">Browse folders instead of files.</param> + ''' <param name="lightMode">If enabled file history is not saved.</param> ''' <remarks></remarks> - Public Sub New(ID As String, Optional ByVal FolderBrowser As Boolean = False, - Optional ByVal LightMode As Boolean = False) - Initialized = False - MyID = ID - NoExt = True - bFolderBrowser = FolderBrowser - bLightMode = LightMode + Public Sub New(id As String, Optional ByVal folderBrowser As Boolean = False, + Optional ByVal lightMode As Boolean = False) + _initialized = False + _id = ID + _noExtension = True + _folderBrowser = folderBrowser + _lightMode = lightMode End Sub ''' <summary> @@ -55,7 +55,7 @@ Public Class FileBrowser ''' <remarks></remarks> Public Function OpenDialog(path As String, Optional ByVal multiFile As Boolean = False, Optional ByVal ext As String = "") As Boolean - Return CustomDialog(path, True, False, tFbExtMode.MultiExt, multiFile, ext, "Open") + Return CustomDialog(path, True, False, FileBrowserFileExtensionMode.MultiExt, multiFile, ext, "Open") End Function ''' <summary> @@ -68,11 +68,11 @@ Public Class FileBrowser ''' <remarks></remarks> Public Function SaveDialog(path As String, Optional ByVal forceExt As Boolean = True, Optional ByVal ext As String = "") _ As Boolean - Dim x As tFbExtMode + Dim x As FileBrowserFileExtensionMode If forceExt Then - x = tFbExtMode.ForceExt + x = FileBrowserFileExtensionMode.ForceExt Else - x = tFbExtMode.SingleExt + x = FileBrowserFileExtensionMode.SingleExt End If Return CustomDialog(path, False, True, x, False, ext, "Save As") End Function @@ -89,10 +89,10 @@ Public Class FileBrowser ''' <param name="title">Dialog title.</param> ''' <returns></returns> ''' <remarks></remarks> - Public Function CustomDialog(path As String, fileMustExist As Boolean, overwriteCheck As Boolean, extMode As tFbExtMode, + Public Function CustomDialog(path As String, fileMustExist As Boolean, overwriteCheck As Boolean, extMode As FileBrowserFileExtensionMode, multiFile As Boolean, ext As String, Optional title As String = "File Browser") As Boolean - If Not Initialized Then Init() - Return Dlog.Browse(path, fileMustExist, overwriteCheck, extMode, multiFile, ext, title) + If Not _initialized Then Init() + Return _dialog.Browse(path, fileMustExist, overwriteCheck, extMode, multiFile, ext, title) End Function 'Manually update File History @@ -102,8 +102,8 @@ Public Class FileBrowser ''' <param name="path">File to be added to file history.</param> ''' <remarks></remarks> Public Sub UpdateHistory(path As String) - If Not Initialized Then Init() - Dlog.UpdateHistory(path) + If Not _initialized Then Init() + _dialog.UpdateHistory(path) End Sub ''' <summary> @@ -111,19 +111,19 @@ Public Class FileBrowser ''' </summary> ''' <remarks></remarks> Public Sub Close() - If Initialized Then - Dlog.SaveAndClose() - Initialized = False + If _initialized Then + _dialog.SaveAndClose() + _initialized = False End If - Dlog = Nothing + _dialog = Nothing End Sub Private Sub Init() - Dlog = New FileBrowserDialog(bLightMode) - Dlog.ID = MyID - If Not NoExt Then Dlog.Extensions = MyExt - If bFolderBrowser Then Dlog.SetFolderBrowser() - Initialized = True + _dialog = New FileBrowserDialog(_lightMode) + _dialog.ID = _id + If Not _noExtension Then _dialog.Extensions = _extensionList + If _folderBrowser Then _dialog.SetFolderBrowser() + _initialized = True End Sub ''' <summary> @@ -134,11 +134,11 @@ Public Class FileBrowser ''' <remarks></remarks> Public Property Extensions As String() Get - Return MyExt + Return _extensionList End Get Set(value As String()) - MyExt = value - NoExt = False + _extensionList = value + _noExtension = False End Set End Property @@ -150,8 +150,8 @@ Public Class FileBrowser ''' <remarks></remarks> Public ReadOnly Property Files As String() Get - If Initialized Then - Return Dlog.Files + If _initialized Then + Return _dialog.Files Else Return New String() {""} End If diff --git a/VECTO/File Browser/FileBrowserDialog.vb b/VECTO/File Browser/FileBrowserDialog.vb index b1498f0eea..daabb651ae 100644 --- a/VECTO/File Browser/FileBrowserDialog.vb +++ b/VECTO/File Browser/FileBrowserDialog.vb @@ -136,7 +136,7 @@ Public Class FileBrowserDialog 'Single File path = Trim(TextBoxPath.Text) 'Primary extension (eg for bForceExt) - ext = Trim(ComboBoxExt.Text.Split(",")(0)) + ext = Trim(ComboBoxExt.Text.Split(","c)(0)) 'If file without path then append path If Mid(path, 2, 1) <> ":" Then path = _myFolder & path 'If instead of File a Folder is entered: Switch to Folder and Abort @@ -186,7 +186,7 @@ Public Class FileBrowserDialog End Sub 'Browse - Custom Dialog - Public Function Browse(path As String, fileMustExist As Boolean, overwriteCheck As Boolean, extMode As tFbExtMode, + Public Function Browse(path As String, fileMustExist As Boolean, overwriteCheck As Boolean, extMode As FileBrowserFileExtensionMode, multiFile As Boolean, ext As String, caption As String) As Boolean If Not _initialized Then Init() @@ -201,7 +201,7 @@ Public Class FileBrowserDialog 'Options _bOverwriteCheck = overwriteCheck _bFileMustExist = fileMustExist - _bForceExt = (extMode = tFbExtMode.ForceExt) + _bForceExt = (extMode = FileBrowserFileExtensionMode.ForceExt) 'Form Config ListViewFiles.MultiSelect = multiFile @@ -216,13 +216,13 @@ Public Class FileBrowserDialog ComboBoxExt.SelectedIndex = 0 Else Select Case extMode - Case tFbExtMode.ForceExt + Case FileBrowserFileExtensionMode.ForceExt If ext = "" Then ext = _extListSingle(0).ToString ComboBoxExt.Items.AddRange(_extListSingle.ToArray) ComboBoxExt.Text = ext ComboBoxExt.Enabled = False - Case tFbExtMode.MultiExt, tFbExtMode.SingleExt - If extMode = tFbExtMode.MultiExt Then + Case FileBrowserFileExtensionMode.MultiExt, FileBrowserFileExtensionMode.SingleExt + If extMode = FileBrowserFileExtensionMode.MultiExt Then ComboBoxExt.Items.AddRange(_extListMulti.ToArray) Else ComboBoxExt.Items.AddRange(_extListSingle.ToArray) @@ -389,7 +389,7 @@ Public Class FileBrowserDialog _extListMulti = New ArrayList For x = 0 To UBound(_myExt) _extListMulti.Add(_myExt(x)) - For Each line In _myExt(x).Split(",") + For Each line In _myExt(x).Split(","c) _extListSingle.Add(Trim(line)) Next Next @@ -643,8 +643,8 @@ Public Class FileBrowserDialog If path = FavText Then Dim favdlog = New FileBrowserFavoritesDialog If favdlog.ShowDialog(Me) = DialogResult.OK Then - For x = 10 To 19 - path = favdlog.ListBox1.Items(x - 10) + For x As Integer = 10 To 19 + path = favdlog.ListBox1.Items(x - 10).ToString() If path = NoFavString Then FileBrowserFolderHistory(x) = EmptyText Else @@ -811,7 +811,7 @@ Public Class FileBrowserDialog If Trim(ComboBoxExt.Text.ToString) = "" Then extStr = New String() {"*"} Else - extStr = ComboBoxExt.Text.ToString.Split(",") + extStr = ComboBoxExt.Text.ToString.Split(","c) End If 'Delete File-List diff --git a/VECTO/GUI/EngineForm.vb b/VECTO/GUI/EngineForm.vb index 523ac42874..d75f7ea3fd 100644 --- a/VECTO/GUI/EngineForm.vb +++ b/VECTO/GUI/EngineForm.vb @@ -52,10 +52,8 @@ Public Class EngineForm If Not Cfg.DeclMode Then Exit Sub - TbInertia.Text = - CStr( - DeclarationData.Engine.EngineInertia((fTextboxToNumString(TbDispl.Text) / 1000.0 / 1000.0).SI(Of CubicMeter), - GearboxType.AMT).Value()) + TbInertia.Text = DeclarationData.Engine.EngineInertia((TbDispl.Text.ToDouble() / 1000.0 / 1000.0).SI(Of CubicMeter), + GearboxType.AMT).ToGUIFormat() End Sub @@ -176,9 +174,9 @@ Public Class EngineForm TbMAP.Text = ENG0.PathMAP(True) TbFLD.Text = ENG0.PathFLD(True) - TbWHTCurban.Text = ENG0.WHTCurban - TbWHTCrural.Text = ENG0.WHTCrural - TbWHTCmw.Text = ENG0.WHTCmw + TbWHTCurban.Text = ENG0.WHTCurban.ToGUIFormat() + TbWHTCrural.Text = ENG0.WHTCrural.ToGUIFormat() + TbWHTCmw.Text = ENG0.WHTCmw.ToGUIFormat() DeclInit() @@ -212,17 +210,17 @@ Public Class EngineForm engine.ModelName = TbName.Text If Trim(engine.ModelName) = "" Then engine.ModelName = "Undefined" - engine.Displacement = CSng(fTextboxToNumString(TbDispl.Text)) - engine.EngineInertia = CSng(fTextboxToNumString(TbInertia.Text)) - engine.IdleSpeed = CSng(fTextboxToNumString(TbNleerl.Text)) + engine.Displacement = TbDispl.Text.ToDouble() + engine.EngineInertia = TbInertia.Text.ToDouble() + engine.IdleSpeed = TbNleerl.Text.ToDouble() engine.PathFLD = TbFLD.Text engine.PathMAP = TbMAP.Text - engine.WHTCurban = CSng(fTextboxToNumString(TbWHTCurban.Text)) - engine.WHTCrural = CSng(fTextboxToNumString(TbWHTCrural.Text)) - engine.WHTCmw = CSng(fTextboxToNumString(TbWHTCmw.Text)) + engine.WHTCurban = TbWHTCurban.Text.ToDouble() + engine.WHTCrural = TbWHTCrural.Text.ToDouble() + engine.WHTCmw = TbWHTCmw.Text.ToDouble() If Not engine.SaveFile Then @@ -332,7 +330,7 @@ Public Class EngineForm fldfile = fFileRepl(TbFLD.Text, GetPath(_engFile)) - If fldfile <> sKey.NoFile AndAlso File.Exists(fldfile) Then + If fldfile <> Constants.NoFile AndAlso File.Exists(fldfile) Then OpenFiles(fFileRepl(TbMAP.Text, GetPath(_engFile)), fldfile) Else OpenFiles(fFileRepl(TbMAP.Text, GetPath(_engFile))) @@ -359,7 +357,7 @@ Public Class EngineForm Dim chart As Chart Dim s As Series Dim a As ChartArea - Dim img As Image + Dim img As Bitmap PicBox.Image = Nothing @@ -494,7 +492,7 @@ Public Class EngineForm fldfile = fFileRepl(TbFLD.Text, GetPath(_engFile)) - If fldfile <> sKey.NoFile AndAlso File.Exists(fldfile) Then + If fldfile <> Constants.NoFile AndAlso File.Exists(fldfile) Then OpenFiles(fldfile) End If End Sub diff --git a/VECTO/GUI/FileSignDialog.vb b/VECTO/GUI/FileSignDialog.vb index 9431398f0b..d9e6ddcad9 100644 --- a/VECTO/GUI/FileSignDialog.vb +++ b/VECTO/GUI/FileSignDialog.vb @@ -141,7 +141,7 @@ Public Class FileSignDialog Dim fb As New FileBrowser("sig", False, True) fb.Extensions = New String() {"vsig"} - If fb.CustomDialog(TbSigFile.Text, False, False, tFbExtMode.ForceExt, False, "vsig") Then + If fb.CustomDialog(TbSigFile.Text, False, False, FileBrowserFileExtensionMode.ForceExt, False, "vsig") Then TbSigFile.Text = fb.Files(0) End If @@ -205,7 +205,7 @@ Public Class FileSignDialog 'Remove File Private Sub RemoveFile() - Dim i0 As Int16 + Dim i0 As Integer If lvFiles.Items.Count = 0 Then Exit Sub diff --git a/VECTO/GUI/GUI_Subs.vb b/VECTO/GUI/GUI_Subs.vb index 43cc81fd32..9ed1673e61 100644 --- a/VECTO/GUI/GUI_Subs.vb +++ b/VECTO/GUI/GUI_Subs.vb @@ -8,6 +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. +Imports System.Globalization ''' <summary> ''' Methods for GUI interaction @@ -20,7 +21,7 @@ Public Module GUI_Subs 'Status Message => Msg-Listview Public Sub WorkerMsg(ByVal id As MessageType, ByVal msg As String, ByVal source As String, Optional ByVal link As String = "") - Dim workProg As New BackgroundWorkerMessage(tWorkMsgType.StatusListBox) + Dim workProg As New BackgroundWorkerMessage(WorkerMessageType.StatusListBox) workProg.ID = id Select Case id Case MessageType.Err @@ -41,8 +42,8 @@ Public Module GUI_Subs 'Status message ' ReSharper disable once InconsistentNaming - Public Sub GUIMsg(ByVal ID As MessageType, ByVal Msg As String) - MainForm.MSGtoForm(ID, Msg, "", "") + Public Sub GUIMsg(ByVal id As MessageType, ByVal msg As String) + MainForm.MSGtoForm(id, msg, "", "") End Sub 'Statusbar @@ -59,7 +60,7 @@ Public Module GUI_Subs 'Class used to pass Messages from BackgroundWorker to GUI Private Class BackgroundWorkerMessage - Public Sub New(msgTarget As tWorkMsgType) + Public Sub New(msgTarget As WorkerMessageType) Source = "" End Sub @@ -82,13 +83,12 @@ Public Module GUI_Subs #Region "Textbox text conversion for file open/save operations" 'Text-to-number - Public Function fTextboxToNumString(ByVal txt As String) As String - If Not IsNumeric(txt) Then - Return "0" - Else - Return txt - End If - End Function + 'Public Function ParseNumber(txt As String) As Double + ' If Not IsNumeric(txt) Then + ' Return 0 + ' End If + ' Return Double.Parse(txt, CultureInfo.InvariantCulture) + 'End Function #End Region diff --git a/VECTO/GUI/GearboxForm.vb b/VECTO/GUI/GearboxForm.vb index d2cfded1da..36231db042 100644 --- a/VECTO/GUI/GearboxForm.vb +++ b/VECTO/GUI/GearboxForm.vb @@ -91,26 +91,26 @@ Public Class GearboxForm 'Set generic values for Declaration mode. Private Sub DeclInit() - Dim GStype As GearboxType + Dim gbxType As GearboxType Dim lv0 As ListViewItem If Not Cfg.DeclMode Then Exit Sub - TBI_getr.Text = DeclarationData.Gearbox.Inertia.Value() 'cDeclaration.GbInertia + TBI_getr.Text = DeclarationData.Gearbox.Inertia.ToGUIFormat() 'cDeclaration.GbInertia - GStype = CbGStype.SelectedValue 'CType(Me.CbGStype.SelectedIndex, tGearbox) + gbxType = CType(CbGStype.SelectedValue, GearboxType) 'CType(Me.CbGStype.SelectedIndex, tGearbox) - TbTracInt.Text = GStype.TractionInterruption().Value() - TbShiftTime.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.Value() 'cDeclaration.ShiftTime(GStype) + TbTracInt.Text = gbxType.TractionInterruption().ToGUIFormat() + TbShiftTime.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.ToGUIFormat() 'cDeclaration.ShiftTime(GStype) - TbTqResv.Text = DeclarationData.Gearbox.TorqueReserve ' cDeclaration.TqResv - TbTqResvStart.Text = DeclarationData.Gearbox.TorqueReserveStart 'cDeclaration.TqResvStart - TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.Value() 'cDeclaration.StartSpeed - TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.Value() ' cDeclaration.StartAcc + TbTqResv.Text = DeclarationData.Gearbox.TorqueReserve.ToGUIFormat() ' cDeclaration.TqResv + TbTqResvStart.Text = DeclarationData.Gearbox.TorqueReserveStart.ToGUIFormat() 'cDeclaration.TqResvStart + TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.ToGUIFormat() 'cDeclaration.StartSpeed + TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.ToGUIFormat() ' cDeclaration.StartAcc - tbUpshiftMinAcceleration.Text = DeclarationData.Gearbox.UpshiftMinAcceleration.Value() - tbDownshiftAfterUpshift.Text = DeclarationData.Gearbox.DownshiftAfterUpshiftDelay.Value() - tbUpshiftAfterDownshift.Text = DeclarationData.Gearbox.UpshiftAfterDownshiftDelay.Value() + tbUpshiftMinAcceleration.Text = DeclarationData.Gearbox.UpshiftMinAcceleration.ToGUIFormat() + tbDownshiftAfterUpshift.Text = DeclarationData.Gearbox.DownshiftAfterUpshiftDelay.ToGUIFormat() + tbUpshiftAfterDownshift.Text = DeclarationData.Gearbox.UpshiftAfterDownshiftDelay.ToGUIFormat() 'ChTCon.Checked = GStype.AutomaticTransmission() For Each lv0 In LvGears.Items @@ -189,7 +189,7 @@ Public Class GearboxForm LvGears.Items.Clear() - LvGears.Items.Add(CreateListviewItem("Axle", "-", 0, 0, "", "")) + LvGears.Items.Add(CreateListviewItem("Axle", "-", 0, "0", "", "")) 'Me.ChSkipGears.Checked = False 'set by CbGStype.SelectedIndexChanged 'Me.ChShiftInside.Checked = False 'set by CbGStype.SelectedIndexChanged @@ -276,13 +276,13 @@ Public Class GearboxForm ChShiftInside.Checked = GBX0.ShiftInside TbTCfile.Text = GBX0.TorqueConverterFile(True) - TbTCrefrpm.Text = GBX0.TorqueConverterReferenceRpm - TbTCinertia.Text = GBX0.TorqueConverterInertia + TbTCrefrpm.Text = GBX0.TorqueConverterReferenceRpm.ToGUIFormat() + TbTCinertia.Text = GBX0.TorqueConverterInertia.ToGUIFormat() TBTCShiftPolygon.Text = GBX0.TorqueConverterShiftPolygonFile - tbUpshiftMinAcceleration.Text = GBX0.UpshiftMinAcceleration - tbDownshiftAfterUpshift.Text = GBX0.DownshiftAfterUpshift - tbUpshiftAfterDownshift.Text = GBX0.UpshiftAfterDownshift + 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 @@ -304,11 +304,11 @@ Public Class GearboxForm UpdatePic() End Sub - Private Function CreateListviewItem(gear As String, tc As String, ratio As Single, getrMap As String, + Private Function CreateListviewItem(gear As String, tc As String, ratio As Double, getrMap As String, shiftPolygon As String, fldFile As String) As ListViewItem Dim retVal As ListViewItem = New ListViewItem(gear) 'retVal.SubItems.Add(tc) - retVal.SubItems.Add(ratio) + retVal.SubItems.Add(ratio.ToGUIFormat()) retVal.SubItems.Add(getrMap) retVal.SubItems.Add(shiftPolygon) retVal.SubItems.Add(fldFile) @@ -330,7 +330,7 @@ Public Class GearboxForm 'Save file Private Function saveGBX(ByVal file As String) As Boolean Dim GBX0 As Gearbox - Dim i As Int16 + Dim i As Integer GBX0 = New Gearbox GBX0.FilePath = file @@ -338,8 +338,8 @@ Public Class GearboxForm GBX0.ModelName = TbName.Text If Trim(GBX0.ModelName) = "" Then GBX0.ModelName = "Undefined" - GBX0.TracIntrSi = fTextboxToNumString(TbTracInt.Text) - GBX0.GbxInertia = fTextboxToNumString(TBI_getr.Text) + GBX0.TracIntrSi = TbTracInt.Text.ToDouble() + GBX0.GbxInertia = TBI_getr.Text.ToDouble() For i = 0 To LvGears.Items.Count - 1 'GBX0.IsTCgear.Add(Me.LvGears.Items(i).SubItems(GearboxTbl.TorqueConverter).Text = "on" And i > 0) @@ -353,25 +353,25 @@ Public Class GearboxForm GBX0.MaxTorque.Add(LvGears.Items(i).SubItems(GearboxTbl.MaxTorque).Text) Next - GBX0.TorqueResv = fTextboxToNumString(TbTqResv.Text) + GBX0.TorqueResv = TbTqResv.Text.ToDouble() GBX0.SkipGears = ChSkipGears.Checked - GBX0.ShiftTime = fTextboxToNumString(TbShiftTime.Text) - GBX0.TorqueResvStart = fTextboxToNumString(TbTqResvStart.Text) - GBX0.StartSpeed = fTextboxToNumString(TbStartSpeed.Text) - GBX0.StartAcc = fTextboxToNumString(TbStartAcc.Text) + GBX0.ShiftTime = TbShiftTime.Text.ToDouble() + GBX0.TorqueResvStart = TbTqResvStart.Text.ToDouble() + GBX0.StartSpeed = TbStartSpeed.Text.ToDouble() + GBX0.StartAcc = TbStartAcc.Text.ToDouble() GBX0.ShiftInside = ChShiftInside.Checked - GBX0.Type = CbGStype.SelectedValue + GBX0.Type = CType(CbGStype.SelectedValue, GearboxType) GBX0.TorqueConverterEnabled = GBX0.Type.AutomaticTransmission() GBX0.TorqueConverterFile = TbTCfile.Text - GBX0.TorqueConverterReferenceRpm = fTextboxToNumString(TbTCrefrpm.Text) - GBX0.TorqueConverterInertia = fTextboxToNumString(TbTCinertia.Text) + GBX0.TorqueConverterReferenceRpm = TbTCrefrpm.Text.ToDouble() + GBX0.TorqueConverterInertia = TbTCinertia.Text.ToDouble() GBX0.TorqueConverterShiftPolygonFile = TBTCShiftPolygon.Text - GBX0.DownshiftAfterUpshift = fTextboxToNumString(tbDownshiftAfterUpshift.Text) - GBX0.UpshiftAfterDownshift = fTextboxToNumString(tbUpshiftAfterDownshift.Text) - GBX0.UpshiftMinAcceleration = fTextboxToNumString(tbUpshiftMinAcceleration.Text) + GBX0.DownshiftAfterUpshift = tbDownshiftAfterUpshift.Text.ToDouble() + GBX0.UpshiftAfterDownshift = tbUpshiftAfterDownshift.Text.ToDouble() + GBX0.UpshiftMinAcceleration = tbUpshiftMinAcceleration.Text.ToDouble() If Not GBX0.SaveFile Then MsgBox("Cannot safe to " & file, MsgBoxStyle.Critical) @@ -507,14 +507,14 @@ Public Class GearboxForm 'Enable/Disable settings for specific transmission types Private Sub CbGStype_SelectedIndexChanged(sender As Object, e As EventArgs) _ Handles CbGStype.SelectedIndexChanged - Dim GStype As GearboxType = CbGStype.SelectedItem.Value + Dim gStype As GearboxType = CType(CbGStype.SelectedValue, GearboxType) Change() - ChShiftInside.Enabled = (GStype.EarlyShiftGears()) - ChSkipGears.Enabled = (GStype.SkipGears()) + ChShiftInside.Enabled = (gStype.EarlyShiftGears()) + ChSkipGears.Enabled = (gStype.SkipGears()) 'ChTCon.Enabled = (GStype.AutomaticTransmission()) - PnTC.Enabled = GStype.AutomaticTransmission() + PnTC.Enabled = gStype.AutomaticTransmission() End Sub @@ -628,8 +628,8 @@ Public Class GearboxForm 'Remove Gear Private Sub RemoveGear(ByVal NoChange As Boolean) - Dim i0 As Int16 - Dim i As Int16 + Dim i0 As Integer + Dim i As Integer Dim lv0 As ListViewItem If LvGears.Items.Count < 2 Then Exit Sub @@ -708,15 +708,15 @@ Public Class GearboxForm Dim lup As List(Of Single) = Nothing Dim ldown As List(Of Single) = Nothing Dim line As String() - Dim MyChart As Chart + Dim chart As Chart Dim s As Series Dim a As ChartArea - Dim img As Image - Dim Gear As Integer - Dim fldOK As Boolean + Dim img As Bitmap + Dim gear As Integer + Dim fldOk As Boolean Dim fldpath As String - Dim FLD0 As EngineFullLoadCurve = Nothing - Dim ShiftOK As Boolean + Dim fullLoadCurve As EngineFullLoadCurve = Nothing + Dim shiftOk As Boolean PicBox.Image = Nothing @@ -729,24 +729,24 @@ Public Class GearboxForm If LvGears.SelectedItems.Count > 0 AndAlso LvGears.SelectedIndices(0) > 0 Then path = fFileRepl(LvGears.SelectedItems(0).SubItems(GearboxTbl.ShiftPolygons).Text, GetPath(GbxFile)) 'fldpath = fFileRepl(LvGears.SelectedItems(0).SubItems(GearboxTbl.MaxTorque).Text, fPATH(GbxFile)) - Gear = LvGears.SelectedIndices(0) + gear = LvGears.SelectedIndices(0) Else path = fFileRepl(LvGears.Items(1).SubItems(GearboxTbl.ShiftPolygons).Text, GetPath(GbxFile)) 'fldpath = fFileRepl(Me.LvGears.Items(1).SubItems(GearboxTbl.MaxTorque).Text, fPATH(GbxFile)) - Gear = 1 + gear = 1 End If f = New CsvFile - ShiftOK = f.OpenRead(path) + shiftOk = f.OpenRead(path) - fldpath = VectoJobForm.FLDfile + fldpath = VectoJobForm.EngineFullLoadFile - fldOK = Not IsNothing(fldpath) AndAlso fldpath.Trim <> "" + fldOk = Not IsNothing(fldpath) AndAlso fldpath.Trim <> "" - If fldOK Then - FLD0 = New EngineFullLoadCurve - FLD0.FilePath = fldpath - fldOK = FLD0.ReadFile(True, False) + If fldOk Then + fullLoadCurve = New EngineFullLoadCurve + fullLoadCurve.FilePath = fldpath + fldOk = fullLoadCurve.ReadFile(True, False) End If Else @@ -761,7 +761,7 @@ Public Class GearboxForm End Try 'Read ShiftPolygon - If ShiftOK Then + If shiftOk Then 'Header f.ReadLine() @@ -785,29 +785,29 @@ Public Class GearboxForm Exit Sub End Try - If lM.Count < 2 Then ShiftOK = False + If lM.Count < 2 Then shiftOk = False End If 'Create plot - If Not ShiftOK And Not fldOK Then Exit Sub + If Not shiftOk And Not fldOk Then Exit Sub - MyChart = New Chart - MyChart.Width = PicBox.Width - MyChart.Height = PicBox.Height + chart = New Chart + chart.Width = PicBox.Width + chart.Height = PicBox.Height a = New ChartArea 'Shiftpolygons from file - If ShiftOK Then + If shiftOk Then 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) + chart.Series.Add(s) s = New Series s.Points.DataBindXY(ldown, lM) @@ -815,7 +815,7 @@ Public Class GearboxForm s.BorderWidth = 2 s.Color = Color.DarkRed s.Name = "Downshift curve" - MyChart.Series.Add(s) + chart.Series.Add(s) End If Dim vectoJob As VectoJob = New VectoJob() With {.FilePath = VectoJobForm.VECTOfile} @@ -824,22 +824,22 @@ Public Class GearboxForm Dim vehicleOk As Boolean = vehicle.ReadFile(False) 'Fld - If fldOK AndAlso vectoOk AndAlso vehicleOk Then + If fldOk AndAlso vectoOk AndAlso vehicleOk Then s = New Series - s.Points.DataBindXY(FLD0.EngineSpeedList, FLD0.MaxTorqueList) + s.Points.DataBindXY(fullLoadCurve.EngineSpeedList, fullLoadCurve.MaxTorqueList) s.ChartType = SeriesChartType.FastLine s.BorderWidth = 2 s.Color = Color.DarkBlue s.Name = "Full load" - MyChart.Series.Add(s) + chart.Series.Add(s) - If VectoJobForm.Visible AndAlso VectoJobForm.n_idle > 0 Then + If VectoJobForm.Visible AndAlso VectoJobForm.EngineIdleSpeed > 0 Then 'If FLD0.Init(VectoJobForm.n_idle) Then 'Dim fullLoadCurve As FullLoadCurve = ConvertToFullLoadCurve(FLD0.LnU, FLD0.LTq) Dim gears As IList(Of ITransmissionInputData) = ConvertToGears(LvGears.Items) - Dim shiftLines As ShiftPolygon = GetShiftLines(FLD0, vehicle, gears, Gear) + Dim shiftLines As ShiftPolygon = GetShiftLines(fullLoadCurve, vehicle, gears, gear) If (CType(CbGStype.SelectedValue, GearboxType).ManualTransmission() AndAlso Not IsNothing(shiftLines)) Then @@ -847,26 +847,28 @@ Public Class GearboxForm 's.Points.DataBindXY(Shiftpoly.gs_nUup, Shiftpoly.gs_TqUp) s.Points.DataBindXY( - shiftLines.Upshift.Select(Function(pt) pt.AngularSpeed.Value() / Constants.RPMToRad).ToList(), + shiftLines.Upshift.Select(Function(pt) pt.AngularSpeed.Value() / TUGraz.VectoCore.Configuration.Constants.RPMToRad). + ToList(), shiftLines.Upshift.Select(Function(pt) pt.Torque.Value()).ToList()) s.ChartType = SeriesChartType.FastLine s.BorderWidth = 2 s.Color = Color.DarkRed s.BorderDashStyle = ChartDashStyle.Dash s.Name = "Upshift curve (generic)" - MyChart.Series.Add(s) + chart.Series.Add(s) s = New Series 's.Points.DataBindXY(Shiftpoly.gs_nUdown, Shiftpoly.gs_TqDown) s.Points.DataBindXY( - shiftLines.Downshift.Select(Function(pt) pt.AngularSpeed.Value() / Constants.RPMToRad).ToList(), + shiftLines.Downshift.Select(Function(pt) pt.AngularSpeed.Value() / TUGraz.VectoCore.Configuration.Constants.RPMToRad) _ + .ToList(), shiftLines.Downshift.Select(Function(pt) pt.Torque.Value()).ToList()) s.ChartType = SeriesChartType.FastLine s.BorderWidth = 2 s.Color = Color.DarkRed s.BorderDashStyle = ChartDashStyle.Dash s.Name = "Downshift curve (generic)" - MyChart.Series.Add(s) + chart.Series.Add(s) End If 'End If End If @@ -894,23 +896,23 @@ Public Class GearboxForm a.BackColor = Color.GhostWhite - MyChart.ChartAreas.Add(a) + chart.ChartAreas.Add(a) - MyChart.Titles.Add("Gear " & Gear & " shift polygons") - MyChart.Titles(0).Font = New Font("Helvetica", 12) + chart.Titles.Add("Gear " & gear & " shift polygons") + chart.Titles(0).Font = New Font("Helvetica", 12) - MyChart.Update() + chart.Update() - img = New Bitmap(MyChart.Width, MyChart.Height, PixelFormat.Format32bppArgb) - MyChart.DrawToBitmap(img, New Rectangle(0, 0, PicBox.Width, PicBox.Height)) + img = New Bitmap(chart.Width, chart.Height, PixelFormat.Format32bppArgb) + chart.DrawToBitmap(img, New Rectangle(0, 0, PicBox.Width, PicBox.Height)) PicBox.Image = img End Sub Private Function GetShiftLines(engineFullLoadCurve As EngineFullLoadCurve, vehicle As Vehicle, - gears As IList(Of ITransmissionInputData), gear As UInteger) As ShiftPolygon - Dim engine As CombustionEngineData = ConvertToEngineData(engineFullLoadCurve, VectoJobForm.n_idle) + gears As IList(Of ITransmissionInputData), gear As Integer) As ShiftPolygon + Dim engine As CombustionEngineData = ConvertToEngineData(engineFullLoadCurve, VectoJobForm.EngineIdleSpeed) If gears.Count <= 1 Then Return Nothing End If @@ -941,7 +943,7 @@ Public Class GearboxForm Then retVal.Add( New TransmissionInputData() _ - With {.Ratio = Double.Parse(value, CultureInfo.InvariantCulture)}) + With {.Ratio = value}) End If Next @@ -984,3 +986,5 @@ Public Class GearboxForm End If End Sub End Class + + diff --git a/VECTO/GUI/GearboxGearDialog.vb b/VECTO/GUI/GearboxGearDialog.vb index b4de37c3b5..2f54d2fc04 100644 --- a/VECTO/GUI/GearboxGearDialog.vb +++ b/VECTO/GUI/GearboxGearDialog.vb @@ -9,6 +9,7 @@ ' ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Windows.Forms +Imports TUGraz.VectoCommon.Utils ''' <summary> @@ -30,7 +31,7 @@ Public Class GearboxGearDialog Exit Sub End If - If IsNumeric(TbMapPath.Text) AndAlso (TbMapPath.Text < 0 OrElse TbMapPath.Text > 1) Then + If IsNumeric(TbMapPath.Text) AndAlso (TbMapPath.Text.ToDouble() < 0 OrElse TbMapPath.Text.ToDouble() > 1) Then MsgBox("Efficiency is invalid! Must be between 0 and 1.") TbMapPath.Focus() TbMapPath.SelectAll() @@ -61,7 +62,7 @@ Public Class GearboxGearDialog Exit Sub End If - If IsNumeric(TbMapPath.Text) AndAlso (TbMapPath.Text < 0 OrElse TbMapPath.Text > 1) Then + If IsNumeric(TbMapPath.Text) AndAlso (TbMapPath.Text.ToDouble() < 0 OrElse TbMapPath.Text.ToDouble() > 1) Then MsgBox("Efficiency is invalid! Must be between 0 and 1.") TbMapPath.Focus() TbMapPath.SelectAll() @@ -96,7 +97,7 @@ Public Class GearboxGearDialog Exit Sub End If - If IsNumeric(TbMapPath.Text) AndAlso (TbMapPath.Text < 0 OrElse TbMapPath.Text > 1) Then + If IsNumeric(TbMapPath.Text) AndAlso (TbMapPath.Text.ToDouble() < 0 OrElse TbMapPath.Text.ToDouble() > 1) Then MsgBox("Efficiency is invalid! Must be between 0 and 1.") TbMapPath.Focus() TbMapPath.SelectAll() diff --git a/VECTO/GUI/GraphForm.vb b/VECTO/GUI/GraphForm.vb index e577284338..cc57a3a95c 100644 --- a/VECTO/GUI/GraphForm.vb +++ b/VECTO/GUI/GraphForm.vb @@ -15,6 +15,7 @@ Imports System.IO Imports System.Linq Imports System.Text.RegularExpressions Imports System.Windows.Forms.DataVisualization.Charting +Imports TUGraz.VectoCommon.Utils Public Class GraphForm Private _filepath As String @@ -22,10 +23,10 @@ Public Class GraphForm Private _distanceList As List(Of Single) Private _timeList As List(Of Single) - Private _xMin As Single - Private _xMax As Single + Private _xMin As Double + Private _xMax As Double - Private _xMax0 As Single + Private _xMax0 As Double Public Sub New() @@ -132,8 +133,8 @@ Public Class GraphForm SetxMax0() - TbXmin.Text = 0 - TbXmax.Text = _xMax0 + TbXmin.Text = 0.ToGUIFormat() + TbXmax.Text = _xMax0.ToGUIFormat() Text = GetFilenameWithoutPath(_filepath, True) @@ -191,9 +192,9 @@ Public Class GraphForm Dim chartSeries As Series = New Series If overDist Then - chartSeries.Points.DataBindXY(_distanceList, _channels(listViewItem.Tag).Values) + chartSeries.Points.DataBindXY(_distanceList, _channels(CType(listViewItem.Tag, Integer)).Values) Else - chartSeries.Points.DataBindXY(_timeList, _channels(listViewItem.Tag).Values) + chartSeries.Points.DataBindXY(_timeList, _channels(CType(listViewItem.Tag, Integer)).Values) End If chartSeries.ChartType = SeriesChartType.FastLine @@ -289,18 +290,18 @@ Public Class GraphForm chart.Update() - Dim img As Image = New Bitmap(chart.Width, chart.Height, PixelFormat.Format32bppArgb) + Dim img As Bitmap = New Bitmap(chart.Width, chart.Height, PixelFormat.Format32bppArgb) chart.DrawToBitmap(img, New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height)) PictureBox1.Image = img End Sub - Private Function AutoIntervalXAxis() As Single - Dim xyd(3) As Single - Dim xya(3) As Single + Private Function AutoIntervalXAxis() As Double + Dim xyd(3) As Double + Dim xya(3) As Double Dim i As Int16 - Dim inv As Single = (_xMax - _xMin) / 10 + Dim inv As Double = (_xMax - _xMin) / 10 Dim grx As Long = 20 Do While 10 ^ grx > inv @@ -315,8 +316,8 @@ Public Class GraphForm xya(i) = Math.Abs(inv - xyd(i)) Next - Dim xyamin As Single = xya(0) - Dim xydmin As Single = xyd(0) + Dim xyamin As Double = xya(0) + Dim xydmin As Double = xyd(0) For i = 1 To 3 If xya(i) < xyamin Then xyamin = xya(i) @@ -394,7 +395,7 @@ Public Class GraphForm dlog.RbRight.Checked = True End If - dlog.ComboBox1.SelectedIndex = lv0.Tag + dlog.ComboBox1.SelectedIndex = CType(lv0.Tag, Integer) If dlog.ShowDialog = DialogResult.OK Then i = dlog.ComboBox1.SelectedIndex @@ -413,7 +414,7 @@ Public Class GraphForm End Sub Private Sub RemoveChannel() - Dim i0 As Int16 + Dim i0 As Integer If ListView1.Items.Count = 0 Then Exit Sub @@ -459,31 +460,31 @@ Public Class GraphForm Private Sub CbXaxis_SelectedIndexChanged(sender As Object, e As EventArgs) _ Handles CbXaxis.SelectedIndexChanged SetxMax0() - TbXmin.Text = 0 - TbXmax.Text = _xMax0 + TbXmin.Text = 0.ToGUIFormat() + TbXmax.Text = _xMax0.ToGUIFormat() UpdateGraph() End Sub Private Sub BtReset_Click(sender As Object, e As EventArgs) Handles BtReset.Click _xMin = 0 _xMax = _xMax0 - TbXmin.Text = 0 - TbXmax.Text = _xMax0 + TbXmin.Text = 0.ToGUIFormat() + TbXmax.Text = _xMax0.ToGUIFormat() End Sub Private Sub TbXmin_TextChanged(sender As Object, e As EventArgs) Handles TbXmin.TextChanged - If IsNumeric(TbXmin.Text) Then _xMin = TbXmin.Text + If IsNumeric(TbXmin.Text) Then _xMin = TbXmin.Text.ToDouble() UpdateGraph() End Sub Private Sub TbXmax_TextChanged(sender As Object, e As EventArgs) Handles TbXmax.TextChanged - If IsNumeric(TbXmax.Text) Then _xMax = TbXmax.Text + If IsNumeric(TbXmax.Text) Then _xMax = TbXmax.Text.ToDouble() UpdateGraph() End Sub Private Sub ToolStripButton3_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click - Dim FGraph As New GraphForm - FGraph.Show() + Dim graph As New GraphForm + graph.Show() End Sub Private Sub F_Graph_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged @@ -491,7 +492,7 @@ Public Class GraphForm End Sub Private Sub BtZoomIn_Click(sender As Object, e As EventArgs) Handles BtZoomIn.Click - Dim d As Single + Dim d As Double d = (_xMax - _xMin) / 10 @@ -504,12 +505,12 @@ Public Class GraphForm _xMin = Math.Round(_xMin, 0) End If - TbXmin.Text = _xMin - TbXmax.Text = _xMax + TbXmin.Text = _xMin.ToGUIFormat() + TbXmax.Text = _xMax.ToGUIFormat() End Sub Private Sub BtZoomOut_Click(sender As Object, e As EventArgs) Handles BtZoomOut.Click - Dim d As Single + Dim d As Double d = (_xMax - _xMin) / 10 @@ -522,12 +523,12 @@ Public Class GraphForm _xMin = Math.Round(_xMin, 0) End If - TbXmin.Text = _xMin - TbXmax.Text = _xMax + TbXmin.Text = _xMin.ToGUIFormat() + TbXmax.Text = _xMax.ToGUIFormat() End Sub Private Sub BtMoveL_Click(sender As Object, e As EventArgs) Handles BtMoveL.Click - Dim d As Single + Dim d As Double If _xMin <= 0 Then Exit Sub @@ -541,12 +542,12 @@ Public Class GraphForm _xMin = Math.Round(_xMin, 0) End If - TbXmin.Text = _xMin - TbXmax.Text = _xMax + TbXmin.Text = _xMin.ToGUIFormat() + TbXmax.Text = _xMax.ToGUIFormat() End Sub Private Sub BtMoveR_Click(sender As Object, e As EventArgs) Handles BtMoveR.Click - Dim d As Single + Dim d As Double If _xMax >= _xMax0 Then Exit Sub @@ -560,8 +561,8 @@ Public Class GraphForm _xMin = Math.Round(_xMin, 0) End If - TbXmin.Text = _xMin - TbXmax.Text = _xMax + TbXmin.Text = _xMin.ToGUIFormat() + TbXmax.Text = _xMax.ToGUIFormat() End Sub Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index 89a6b435dd..1bc09c7026 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -271,9 +271,9 @@ Public Class MainForm Public Shared Sub LogMethod(level As String, message As String) Try If level = "Warn" Then - VectoWorkerV3.ReportProgress(100, New With {.Target = "ListBoxWarning", .Message = message}) + VectoWorkerV3.ReportProgress(100, New VectoProgress With {.Target = "ListBoxWarning", .Message = message}) ElseIf level = "Error" Or level = "Fatal" Then - VectoWorkerV3.ReportProgress(100, New With {.Target = "ListBoxError", .Message = message}) + VectoWorkerV3.ReportProgress(100, New VectoProgress With {.Target = "ListBoxError", .Message = message}) End If Catch e As InvalidOperationException @@ -464,7 +464,7 @@ Public Class MainForm Private Sub ListGEN_DragDrop(sender As Object, e As DragEventArgs) _ Handles LvGEN.DragDrop Dim f As String() - f = CType(e.Data.GetData(DataFormats.FileDrop), Array) + f = CType(e.Data.GetData(DataFormats.FileDrop), String()) AddToJobListView(f) End Sub @@ -556,12 +556,12 @@ Public Class MainForm 'Add File to job listview (multiple files) Private Sub AddToJobListView(Path As String(), Optional ByVal Txt As String = " ") - Dim pDim As Int16 - Dim p As Int16 - Dim f As Int16 + Dim pDim As Integer + Dim p As Integer + Dim f As Integer Dim fList As String() - Dim fListDim As Int16 = -1 - Dim ListViewItem0 As ListViewItem + Dim fListDim As Integer = -1 + Dim listViewItem As ListViewItem 'If VECTO runs: Cancel operation (because Mode-change during calculation is not very clever) If VectoWorkerV3.IsBusy Then Exit Sub @@ -609,12 +609,12 @@ Public Class MainForm End If 'Otherwise: Add File (without WorkDir) - ListViewItem0 = New ListViewItem(Path(p)) 'fFileWD(Path(p))) - ListViewItem0.SubItems.Add(" ") - ListViewItem0.Checked = True - ListViewItem0.Selected = True - LvGEN.Items.Add(ListViewItem0) - ListViewItem0.EnsureVisible() + listViewItem = New ListViewItem(Path(p)) 'fFileWD(Path(p))) + listViewItem.SubItems.Add(" ") + listViewItem.Checked = True + listViewItem.Selected = True + LvGEN.Items.Add(listViewItem) + listViewItem.EnsureVisible() lbFound: Next @@ -912,7 +912,9 @@ lbFound: Status("Launching VECTO ...") JobFileList.Clear() - JobFileList.AddRange(From listViewItem In LvGEN.CheckedItems Select fFileRepl(listViewItem.SubItems(0).Text)) + JobFileList.AddRange( + From listViewItem As ListViewItem In LvGEN.CheckedItems.Cast(Of ListViewItem)() + Select fFileRepl(listViewItem.SubItems(0).Text)) SetOptions() Cfg.Save() @@ -936,6 +938,7 @@ lbFound: End If End Sub + Private Sub VectoWorkerV3_OnDoWork(sender As BackgroundWorker, e As DoWorkEventArgs) AllowSleepOFF() @@ -961,7 +964,8 @@ lbFound: For Each jobFile As String In JobFileList Try - sender.ReportProgress(0, New With {.Target = "ListBox", .Message = "Reading File " + jobFile, .Link = jobFile}) + sender.ReportProgress(0, + New VectoProgress With {.Target = "ListBox", .Message = "Reading File " + jobFile, .Link = jobFile}) Dim dataProvider As IInputDataProvider = JSONInputDataFactory.ReadJsonJob(jobFile) Dim fileWriter As FileOutputWriter = New FileOutputWriter(jobFile) @@ -974,11 +978,12 @@ lbFound: fileWriters.Add(runId, fileWriter) Next - sender.ReportProgress(0, New With {.Target = "ListBox", .Message = "Finished Reading Data for job: " + jobFile}) + sender.ReportProgress(0, + New VectoProgress With {.Target = "ListBox", .Message = "Finished Reading Data for job: " + jobFile}) Catch ex As Exception MsgBox(String.Format("ERROR running job {0}: {1}", jobFile, ex.Message), MsgBoxStyle.Critical) - sender.ReportProgress(0, New With {.Target = "ListBoxError", .Message = ex.Message}) + sender.ReportProgress(0, New VectoProgress With {.Target = "ListBoxError", .Message = ex.Message}) Return End Try Next @@ -986,12 +991,11 @@ lbFound: 'print detected cycles For Each cycle As JobContainer.CycleTypeDescription In jobContainer.GetCycleTypes() sender.ReportProgress(0, - New With {.Target = "ListBox", .Message = String.Format("Detected Cycle {0}: {1}", cycle.Name, cycle.CycleType)}) + New VectoProgress _ + With {.Target = "ListBox", .Message = String.Format("Detected Cycle {0}: {1}", cycle.Name, cycle.CycleType)}) Next - sender.ReportProgress(0, - New _ - With {.Target = "ListBox", + sender.ReportProgress(0, New VectoProgress With {.Target = "ListBox", .Message = _ String.Format("Starting Simulation ({0} Jobs, {1} Runs)", JobFileList.Count, jobContainer.GetProgress().Count)}) @@ -1010,7 +1014,8 @@ lbFound: Dim sumProgress As Double = progress.Sum(Function(pair) pair.Value.Progress) Dim duration As Double = (DateTime.Now() - start).TotalSeconds - sender.ReportProgress(Int((sumProgress * 100.0) / progress.Count), New With {.Target = "Status", + sender.ReportProgress(Convert.ToInt32((sumProgress * 100.0) / progress.Count), + New VectoProgress With {.Target = "Status", .Message = _ String.Format("Duration: {0:0}s, Current Progress: {1:P} ({2})", duration, sumProgress / progress.Count, String.Join(", ", progress.Select(Function(pair) String.Format("{0,4:P}", pair.Value.Progress))))}) @@ -1032,14 +1037,15 @@ lbFound: fileWriters.Clear() For Each progressEntry As KeyValuePair(Of Integer, JobContainer.ProgressEntry) In jobContainer.GetProgress() - sender.ReportProgress(100, New With {.Target = "ListBox", + sender.ReportProgress(100, New VectoProgress With {.Target = "ListBox", .Message = String.Format("{0,-60} {1,8:P} {2,10:F2}s - {3}", String.Format("{0} {1} {2}", progressEntry.Value.RunName, progressEntry.Value.CycleName, progressEntry.Value.RunSuffix), progressEntry.Value.Progress, progressEntry.Value.ExecTime / 1000.0, IIf(progressEntry.Value.Success, "Success", "Aborted"))}) If (Not progressEntry.Value.Success) Then - sender.ReportProgress(100, New With {.Target = "ListBox", .Message = progressEntry.Value.Error.Message}) + sender.ReportProgress(100, + New VectoProgress With {.Target = "ListBox", .Message = progressEntry.Value.Error.Message}) End If Next @@ -1047,23 +1053,19 @@ lbFound: For Each job As String In JobFileList Dim report As String = New FileOutputWriter(job).PDFReportName If File.Exists(report) Then - sender.ReportProgress(100, - New _ - With {.Target = "ListBox", + sender.ReportProgress(100, New VectoProgress With {.Target = "ListBox", .Message = String.Format("PDF-Report for '{0}' written to {1}", Path.GetFileName(job), report), .Link = "<RUN>" + report}) End If Next If File.Exists(sumFileWriter.SumFileName) Then - sender.ReportProgress(100, New With {.Target = "ListBox", + sender.ReportProgress(100, New VectoProgress With {.Target = "ListBox", .Message = String.Format("Sum File written to {0}", sumFileWriter.SumFileName), .Link = sumFileWriter.SumFileName}) End If - sender.ReportProgress(100, - New _ - With {.Target = "ListBox", + sender.ReportProgress(100, New VectoProgress With {.Target = "ListBox", .Message = String.Format("Simulation Finished in {0:0}s", (DateTime.Now() - start).TotalSeconds)}) End Sub @@ -1072,25 +1074,22 @@ lbFound: fileWriters As Dictionary(Of Integer, FileOutputWriter)) For Each p As KeyValuePair(Of Integer, JobContainer.ProgressEntry) In progress Dim modFilename As String = fileWriters(p.Key).GetModDataFileName(p.Value.RunName, p.Value.CycleName, - p.Value.RunSuffix + IIf(Cfg.Mod1Hz, "_1Hz", "")) + p.Value.RunSuffix + If(Cfg.Mod1Hz, "_1Hz", "")) Dim runName As String = String.Format("{0} {1} {2}", p.Value.RunName, p.Value.CycleName, p.Value.RunSuffix) If Not p.Value.Error Is Nothing Then - VectoWorkerV3.ReportProgress(0, - New _ - With {.Target = "ListBoxError", + VectoWorkerV3.ReportProgress(0, New VectoProgress With {.Target = "ListBoxError", .Message = String.Format("Finished Run {0} with ERROR: {1}", runName, p.Value.Error.Message), .Link = modFilename}) Else VectoWorkerV3.ReportProgress(0, - New With {.Target = "ListBox", .Message = String.Format("Finished Run {0} successfully.", runName)}) + New VectoProgress _ + With {.Target = "ListBox", .Message = String.Format("Finished Run {0} successfully.", runName)}) End If If (File.Exists(modFilename)) Then - VectoWorkerV3.ReportProgress(0, - New _ - With {.Target = "ListBox", + VectoWorkerV3.ReportProgress(0, New VectoProgress With {.Target = "ListBox", .Message = String.Format("Run {0}: Modal Results written to {1}", runName, modFilename), .Link = modFilename }) End If @@ -1098,21 +1097,24 @@ lbFound: End Sub Private Sub VectoWorkerV3_OnProgressChanged(sender As Object, e As ProgressChangedEventArgs) - Select Case e.UserState.Target + Dim progress As VectoProgress = TryCast(e.UserState, VectoProgress) + If progress Is Nothing Then Exit Sub + + Select Case progress.Target Case "ListBox" - If e.UserState.GetType().GetProperty("Link") Is Nothing Then - MSGtoForm(MessageType.Normal, e.UserState.Message, "", "") + If progress.Link Is Nothing Then + MSGtoForm(MessageType.Normal, progress.Message, "", "") Else - MSGtoForm(MessageType.Normal, e.UserState.Message, "", e.UserState.Link) + MSGtoForm(MessageType.Normal, progress.Message, "", progress.Link) End If Case "ListBoxWarning" - MSGtoForm(MessageType.Warn, e.UserState.Message, "", "") + MSGtoForm(MessageType.Warn, progress.Message, "", "") Return Case "ListBoxError" - MSGtoForm(MessageType.Err, e.UserState.Message, "", "") + MSGtoForm(MessageType.Err, progress.Message, "", "") Return Case "Status" - Status(e.UserState.Message) + Status(progress.Message) End Select ToolStripProgBarOverall.Value = e.ProgressPercentage @@ -1535,32 +1537,32 @@ lbFound: Private mouseDownOnListView As Boolean Private Class GUItest - Private RowLim As Int16 = 9 - Private ColLim As Int16 = 45 + Private RowLim As Integer = 9 + Private ColLim As Integer = 45 Public TestActive As Boolean = False Private TestAborted As Boolean - Private xCtrl As Int16 - Private xPanel As Int16 - Private Scr As Int32 + Private xCtrl As Integer + Private xPanel As Integer + Private Scr As Integer Private PRbAlt As Boolean - Private ReadOnly Ctrls(RowLim + 1) As Int16 - Private ReadOnly Pnls(RowLim + 1) As Int16 - Private CtrlC As Int16 - Private CtrlCL As Int16 - Private PnDir As Int16 - Private PnDirC As Int16 - Private PnDirCL As Int16 - Private PnDirRnd As Int16 - Private CtrlRnd As Int16 - Private DiffC As Int16 - Private DiffLvl As Int16 - Private bInit As Int16 + Private ReadOnly Ctrls(RowLim + 1) As Integer + Private ReadOnly Pnls(RowLim + 1) As Integer + Private CtrlC As Integer + Private CtrlCL As Integer + Private PnDir As Integer + Private PnDirC As Integer + Private PnDirCL As Integer + Private PnDirRnd As Integer + Private CtrlRnd As Integer + Private DiffC As Integer + Private DiffLvl As Integer + Private bInit As Integer Private ReadOnly MyForm As MainForm Private ReadOnly KeyCode As List(Of Integer) Private Sub TestRun() - Dim z As Int16 + Dim z As Integer xPanel = ColLim - 10 xCtrl = ColLim - 10 @@ -1763,7 +1765,7 @@ LbRace: End Sub Private Sub sSetCtrl() - Dim x As Int16 + Dim x As Integer If Scr < 10 Then Exit Sub Ctrls(RowLim + 1) = 0 CtrlC += 1 @@ -1846,15 +1848,15 @@ Lb1: End Sub Private Sub sLists() - Dim x As Int16 + Dim x As Integer For x = 2 To RowLim + 1 Ctrls(x - 1) = Ctrls(x) Pnls(x - 1) = Pnls(x) Next End Sub - Public Sub New(Form As MainForm) - MyForm = Form + Public Sub New(form As MainForm) + MyForm = form KeyCode = New List(Of Integer) KeyCode.Add(Keys.Up) KeyCode.Add(Keys.Up) @@ -1917,4 +1919,11 @@ Lb1: Private Sub RbDev_CheckedChanged(sender As Object, e As EventArgs) Handles RbDev.CheckedChanged End Sub + + + Private Class VectoProgress + Public Target As String + Public Message As String + Public Link As String + End Class End Class diff --git a/VECTO/GUI/Settings.vb b/VECTO/GUI/Settings.vb index 1503e05c3d..a98ae8bdf3 100644 --- a/VECTO/GUI/Settings.vb +++ b/VECTO/GUI/Settings.vb @@ -10,6 +10,7 @@ ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.IO Imports System.Text.RegularExpressions +Imports TUGraz.VectoCommon.Utils ''' <summary> ''' Settings form @@ -24,7 +25,7 @@ Public Class Settings Private Sub LoadSettings() - TextBoxLogSize.Text = Cfg.LogSize + TextBoxLogSize.Text = Cfg.LogSize.ToGUIFormat() TbAirDensity.Text = CStr(Cfg.AirDensity) TbOpenCmd.Text = Cfg.OpenCmd TbOpenCmdName.Text = Cfg.OpenCmdName diff --git a/VECTO/GUI/VectoJobForm.vb b/VECTO/GUI/VectoJobForm.vb index 7469061cbc..c8af0b15b1 100644 --- a/VECTO/GUI/VectoJobForm.vb +++ b/VECTO/GUI/VectoJobForm.vb @@ -27,16 +27,16 @@ Imports TUGraz.VectoCore.Models.Declaration ''' <remarks></remarks> Public Class VectoJobForm Public VECTOfile As String - Private Changed As Boolean = False + Private _changed As Boolean = False - Private pgDriver As TabPage + Private _pgDriver As TabPage - Private pgDriverON As Boolean = True + Private _pgDriverOn As Boolean = True - Private AuxDlog As VehicleAuxiliariesDialog + Private _auxDialog As VehicleAuxiliariesDialog - Public n_idle As Single - Public FLDfile As String + Public EngineIdleSpeed As Double + Public EngineFullLoadFile As String 'AA-TB 'Populate Advanced Auxiliaries @@ -51,14 +51,14 @@ Public Class VectoJobForm 'Initialise form Private Sub F02_GEN_Load(sender As Object, e As EventArgs) Handles Me.Load - Dim x As Int16 + Dim x As Integer - n_idle = -1 - FLDfile = "" + EngineIdleSpeed = -1 + EngineFullLoadFile = "" - AuxDlog = New VehicleAuxiliariesDialog + _auxDialog = New VehicleAuxiliariesDialog - pgDriver = TabPgDriver + _pgDriver = TabPgDriver For x = 0 To TabControl1.TabCount - 1 TabControl1.TabPages(x).Show() @@ -83,7 +83,7 @@ Public Class VectoJobForm ButAuxRem.Enabled = Not Cfg.DeclMode PnEcoRoll.Enabled = Not Cfg.DeclMode - Changed = False + _changed = False 'AA-TB PopulateAdvancedAuxiliaries() @@ -108,35 +108,37 @@ Public Class VectoJobForm If Not RdEcoRoll.Checked Then RdOverspeed.Checked = True CbLookAhead.Checked = True - TbSSspeed.Text = DeclarationData.Driver.StartStop.MaxSpeed.AsKmph() 'cDeclaration.SSspeed - TbSStime.Text = DeclarationData.Driver.StartStop.MinTime.Value() 'cDeclaration.SStime - TbSSdelay.Text = DeclarationData.Driver.StartStop.Delay.Value() ' cDeclaration.SSdelay - - tbLacPreviewFactor.Text = DeclarationData.Driver.LookAhead.LookAheadDistanceFactor + TbSSspeed.Text = DeclarationData.Driver.StartStop.MaxSpeed.AsKmph().ToGUIFormat() 'cDeclaration.SSspeed + TbSStime.Text = DeclarationData.Driver.StartStop.MinTime.ToGUIFormat() 'cDeclaration.SStime + TbSSdelay.Text = DeclarationData.Driver.StartStop.Delay.ToGUIFormat() ' cDeclaration.SSdelay + tbLacPreviewFactor.Text = DeclarationData.Driver.LookAhead.LookAheadDistanceFactor.ToGUIFormat() tbLacDfTargetSpeedFile.Text = "" tbLacDfVelocityDropFile.Text = "" - TbOverspeed.Text = DeclarationData.Driver.OverSpeedEcoRoll.OverSpeed.AsKmph() 'cDeclaration.Overspeed - TbUnderSpeed.Text = DeclarationData.Driver.OverSpeedEcoRoll.UnderSpeed.AsKmph() ' cDeclaration.Underspeed - TbVmin.Text = DeclarationData.Driver.OverSpeedEcoRoll.MinSpeed.AsKmph() 'cDeclaration.ECvmin + TbOverspeed.Text = DeclarationData.Driver.OverSpeedEcoRoll.OverSpeed.AsKmph().ToGUIFormat() 'cDeclaration.Overspeed + TbUnderSpeed.Text = DeclarationData.Driver.OverSpeedEcoRoll.UnderSpeed.AsKmph().ToGUIFormat() _ + ' cDeclaration.Underspeed + TbVmin.Text = DeclarationData.Driver.OverSpeedEcoRoll.MinSpeed.AsKmph().ToGUIFormat() 'cDeclaration.ECvmin If _ LvAux.Items.Count <> 5 OrElse - (LvAux.Items(0).Text <> sKey.AUX.Fan OrElse LvAux.Items(1).Text <> sKey.AUX.SteerPump OrElse - LvAux.Items(2).Text <> sKey.AUX.HVAC OrElse LvAux.Items(3).Text <> sKey.AUX.ElecSys OrElse - LvAux.Items(4).Text <> sKey.AUX.PneumSys) Then + (LvAux.Items(0).Text <> Constants.AuxiliaryKey.Fan OrElse LvAux.Items(1).Text <> Constants.AuxiliaryKey.SteerPump OrElse + LvAux.Items(2).Text <> Constants.AuxiliaryKey.HVAC OrElse LvAux.Items(3).Text <> Constants.AuxiliaryKey.ElecSys OrElse + LvAux.Items(4).Text <> Constants.AuxiliaryKey.PneumSys) Then LvAux.Items.Clear() - LvAux.Items.Add(GetTechListForAux(sKey.AUX.Fan, "Fan", DeclarationData.Fan)) + LvAux.Items.Add(GetTechListForAux(Constants.AuxiliaryKey.Fan, "Fan", DeclarationData.Fan)) - LvAux.Items.Add(GetTechListForAux(sKey.AUX.SteerPump, "Steering pump", DeclarationData.SteeringPump)) + LvAux.Items.Add(GetTechListForAux(Constants.AuxiliaryKey.SteerPump, "Steering pump", DeclarationData.SteeringPump)) - LvAux.Items.Add(GetTechListForAux(sKey.AUX.HVAC, "HVAC", DeclarationData.HeatingVentilationAirConditioning)) + LvAux.Items.Add(GetTechListForAux(Constants.AuxiliaryKey.HVAC, "HVAC", + DeclarationData.HeatingVentilationAirConditioning)) - LvAux.Items.Add(GetTechListForAux(sKey.AUX.ElecSys, "Electric System", DeclarationData.ElectricSystem)) + LvAux.Items.Add(GetTechListForAux(Constants.AuxiliaryKey.ElecSys, "Electric System", DeclarationData.ElectricSystem)) - LvAux.Items.Add(GetTechListForAux(sKey.AUX.PneumSys, "Pneumatic System", DeclarationData.PneumaticSystem)) + LvAux.Items.Add(GetTechListForAux(Constants.AuxiliaryKey.PneumSys, "Pneumatic System", + DeclarationData.PneumaticSystem)) End If End Sub @@ -160,14 +162,14 @@ Public Class VectoJobForm 'Show/Hide "Driver Assist" Tab Private Sub SetDrivertab(onOff As Boolean) If onOff Then - If Not pgDriverON Then - pgDriverON = True - TabControl1.TabPages.Insert(1, pgDriver) + If Not _pgDriverOn Then + _pgDriverOn = True + TabControl1.TabPages.Insert(1, _pgDriver) End If Else - If pgDriverON Then - pgDriverON = False - TabControl1.Controls.Remove(pgDriver) + If _pgDriverOn Then + _pgDriverOn = False + TabControl1.Controls.Remove(_pgDriver) End If End If End Sub @@ -417,7 +419,7 @@ Public Class VectoJobForm lv0.SubItems(0).Text = AuxEntryKV.Key lv0.SubItems.Add(AuxEntryKV.Value.Type) If Cfg.DeclMode Then - lv0.SubItems.Add(AuxEntryKV.Value.TechStr) + lv0.SubItems.Add(String.Join(", ", AuxEntryKV.Value.TechnologyList)) Else lv0.SubItems.Add(AuxEntryKV.Value.Path.OriginalPath) End If @@ -464,12 +466,12 @@ Public Class VectoJobForm VECTOfile = file - Dim x As Short = Len(file) + Dim x As Integer = Len(file) While Mid(file, x, 1) <> "\" And x > 0 x = x - 1 End While Text = Mid(file, x + 1, Len(file) - x) - Changed = False + _changed = False ToolStripStatusLabelGEN.Text = "" 'file & " opened." UpdatePic() @@ -522,9 +524,9 @@ Public Class VectoJobForm 'Start/Stop vec0.StartStop = ChBStartStop.Checked - vec0.StStV = CSng(fTextboxToNumString(TbSSspeed.Text)) - vec0.StStT = CSng(fTextboxToNumString(TbSStime.Text)) - vec0.StartStopDelay = CInt(fTextboxToNumString(TbSSdelay.Text)) + vec0.StStV = TbSSspeed.Text.ToDouble() + vec0.StStT = TbSStime.Text.ToDouble() + vec0.StartStopDelay = TbSSdelay.Text.ToDouble() 'a_DesMax vec0.DesMaxFile = TbDesMaxFile.Text @@ -538,7 +540,8 @@ Public Class VectoJobForm Dim auxEntry = New VectoJob.AuxEntry If Cfg.DeclMode Then - auxEntry.TechStr = lv0.SubItems(2).Text + auxEntry.TechnologyList.Clear() + auxEntry.TechnologyList.Add(lv0.SubItems(2).Text) Else auxEntry.Path.Init(GetPath(file), lv0.SubItems(2).Text) End If @@ -551,16 +554,16 @@ Public Class VectoJobForm vec0.EcoRollOn = RdEcoRoll.Checked vec0.OverSpeedOn = RdOverspeed.Checked - vec0.OverSpeed = CSng(fTextboxToNumString(TbOverspeed.Text)) - vec0.UnderSpeed = CSng(fTextboxToNumString(TbUnderSpeed.Text)) - vec0.VMin = CSng(fTextboxToNumString(TbVmin.Text)) + vec0.OverSpeed = TbOverspeed.Text.ToDouble() + vec0.UnderSpeed = TbUnderSpeed.Text.ToDouble() + vec0.VMin = TbVmin.Text.ToDouble() vec0.LookAheadOn = CbLookAhead.Checked 'vec0.ALookahead = CSng(fTextboxToNumString(TbAlookahead.Text)) 'vec0.VMinLa = CSng(fTextboxToNumString(TbVminLA.Text)) - vec0.LacPreviewFactor = CSng(fTextboxToNumString(tbLacPreviewFactor.Text)) - vec0.LacDfOffset = CSng(fTextboxToNumString(tbDfCoastingOffset.Text)) - vec0.LacDfScale = CSng(fTextboxToNumString(tbDfCoastingScale.Text)) + vec0.LacPreviewFactor = tbLacPreviewFactor.Text.ToDouble() + vec0.LacDfOffset = tbDfCoastingOffset.Text.ToDouble() + vec0.LacDfScale = tbDfCoastingScale.Text.ToDouble() vec0.LacDfTargetSpeedFile = tbLacDfTargetSpeedFile.Text vec0.LacDfVelocityDropFile = tbLacDfVelocityDropFile.Text '------------------------------------------------------------ @@ -580,7 +583,7 @@ Public Class VectoJobForm MainForm.AddToJobListView(VECTOfile) - Changed = False + _changed = False Return True End Function @@ -590,8 +593,8 @@ Public Class VectoJobForm If ChangeCheckCancel() Then Exit Sub - n_idle = -1 - FLDfile = "" + EngineIdleSpeed = -1 + EngineFullLoadFile = "" 'Files TbVEH.Text = "" @@ -631,7 +634,7 @@ Public Class VectoJobForm VECTOfile = "" Text = "Job Editor" ToolStripStatusLabelGEN.Text = "" - Changed = False + _changed = False UpdatePic() End Sub @@ -694,16 +697,16 @@ Public Class VectoJobForm #End Region Private Sub Change() - If Not Changed Then + If Not _changed Then ToolStripStatusLabelGEN.Text = "Unsaved changes in current file" - Changed = True + _changed = True End If End Sub ' "Save changes? "... Returns True if User aborts Private Function ChangeCheckCancel() As Boolean - If Changed Then + If _changed Then Select Case MsgBox("Save changes ?", MsgBoxStyle.YesNoCancel) Case MsgBoxResult.Yes @@ -711,7 +714,7 @@ Public Class VectoJobForm Case MsgBoxResult.Cancel Return True Case Else 'MsgBoxResult.No - Changed = False + _changed = False Return False End Select @@ -729,31 +732,31 @@ Public Class VectoJobForm Private Sub ButAuxAdd_Click(sender As Object, e As EventArgs) Handles ButAuxAdd.Click Dim ID As String - AuxDlog.VehPath = GetPath(VECTOfile) - AuxDlog.TbPath.Text = "" - AuxDlog.CbType.SelectedIndex = -1 - AuxDlog.CbType.Text = "" - AuxDlog.TbID.Text = "" '!!! Set Type before ID, because changing the type will overwrite the id !!! + _auxDialog.VehPath = GetPath(VECTOfile) + _auxDialog.TbPath.Text = "" + _auxDialog.CbType.SelectedIndex = -1 + _auxDialog.CbType.Text = "" + _auxDialog.TbID.Text = "" '!!! Set Type before ID, because changing the type will overwrite the id !!! lbDlog: - If AuxDlog.ShowDialog = DialogResult.OK Then + If _auxDialog.ShowDialog = DialogResult.OK Then - ID = UCase(Trim(AuxDlog.TbID.Text)) + ID = UCase(Trim(_auxDialog.TbID.Text)) Dim lv0 As ListViewItem For Each lv0 In LvAux.Items If lv0.SubItems(0).Text = ID Then MsgBox("ID '" & ID & "' already defined!", MsgBoxStyle.Critical) - AuxDlog.TbID.SelectAll() - AuxDlog.TbID.Focus() + _auxDialog.TbID.SelectAll() + _auxDialog.TbID.Focus() GoTo lbDlog End If Next lv0 = New ListViewItem - lv0.SubItems(0).Text = UCase(Trim(AuxDlog.TbID.Text)) - lv0.SubItems.Add(Trim(AuxDlog.CbType.Text)) - lv0.SubItems.Add(Trim(AuxDlog.TbPath.Text)) + lv0.SubItems(0).Text = UCase(Trim(_auxDialog.TbID.Text)) + lv0.SubItems.Add(Trim(_auxDialog.CbType.Text)) + lv0.SubItems.Add(Trim(_auxDialog.TbPath.Text)) LvAux.Items.Add(lv0) Change() End If @@ -783,27 +786,27 @@ lbDlog: Dim selItem = LvAux.SelectedItems(0) - AuxDlog.VehPath = GetPath(VECTOfile) - AuxDlog.CbType.SelectedIndex = -1 - AuxDlog.CbType.Text = selItem.SubItems(1).Text - AuxDlog.TbID.Text = selItem.SubItems(0).Text 'After Type-set! + _auxDialog.VehPath = GetPath(VECTOfile) + _auxDialog.CbType.SelectedIndex = -1 + _auxDialog.CbType.Text = selItem.SubItems(1).Text + _auxDialog.TbID.Text = selItem.SubItems(0).Text 'After Type-set! If Cfg.DeclMode Then - AuxDlog.CbTech.Text = selItem.SubItems(2).Text - AuxDlog.TbPath.Text = "" + _auxDialog.CbTech.Text = selItem.SubItems(2).Text + _auxDialog.TbPath.Text = "" Else - AuxDlog.CbTech.SelectedIndex = -1 - AuxDlog.TbPath.Text = selItem.SubItems(2).Text + _auxDialog.CbTech.SelectedIndex = -1 + _auxDialog.TbPath.Text = selItem.SubItems(2).Text End If - If AuxDlog.ShowDialog = DialogResult.OK Then - selItem.SubItems(0).Text = UCase(Trim(AuxDlog.TbID.Text)) - selItem.SubItems(1).Text = Trim(AuxDlog.CbType.Text) + If _auxDialog.ShowDialog = DialogResult.OK Then + selItem.SubItems(0).Text = UCase(Trim(_auxDialog.TbID.Text)) + selItem.SubItems(1).Text = Trim(_auxDialog.CbType.Text) If Cfg.DeclMode Then - selItem.SubItems(2).Text = Trim(AuxDlog.CbTech.Text) + selItem.SubItems(2).Text = Trim(_auxDialog.CbTech.Text) Else - selItem.SubItems(2).Text = Trim(AuxDlog.TbPath.Text) + selItem.SubItems(2).Text = Trim(_auxDialog.TbPath.Text) End If Change() @@ -977,7 +980,7 @@ lbDlog: Public Sub UpdatePic() Dim VEH0 As New Vehicle Dim i As Integer - Dim pmax As Single + Dim pmax As Double Dim f As CsvFile Dim lM As List(Of Single) @@ -991,7 +994,7 @@ lbDlog: Dim s As Series Dim a As ChartArea - Dim img As Image + Dim img As Bitmap Dim EngOK = False @@ -1007,7 +1010,7 @@ lbDlog: VEH0.FilePath = fFileRepl(TbVEH.Text, GetPath(VECTOfile)) If VEH0.ReadFile(False) Then - Dim maxMass = (VEH0.MassMax * 1000).SI(Of Kilogram)() 'CSng(fTextboxToNumString(TbMassMass.Text)) + Dim maxMass = (VEH0.MassMax * 1000).SI(Of Kilogram)() 'CSng(fTextboxToNumString(TbMassMass.Text)) Dim s0 As Segment = Nothing Try @@ -1028,7 +1031,7 @@ lbDlog: HDVclass = "-" End If - PicVehicle.Image = ConvPicPath(HDVclass, False) 'Image.FromFile(cDeclaration.ConvPicPath(HDVclass, False)) + PicVehicle.Image = ConvPicPath(HDVclass.ToInt(), False) 'Image.FromFile(cDeclaration.ConvPicPath(HDVclass, False)) TbHVCclass.Text = "HDV Class " & HDVclass TbVehCat.Text = VEH0.VehicleCategory.GetCategoryName() 'ConvVehCat(VEH0.VehCat, True) @@ -1054,8 +1057,8 @@ lbDlog: If ENG0.ReadFile(False) Then - n_idle = ENG0.IdleSpeed - FLDfile = ENG0.PathFLD + EngineIdleSpeed = ENG0.IdleSpeed + EngineFullLoadFile = ENG0.PathFLD EngOK = True FLD0.FilePath = ENG0.PathFLD @@ -1321,7 +1324,7 @@ lbDlog: End If Dim aauxFileValidated As Boolean = False - Dim fbAux As New FileBrowser(True, False) + Dim fbAux As New FileBrowser("aaux", True, False) Dim message As String = String.Empty Dim absoluteAuxPath As String Dim assembly As AdvancedAuxiliary @@ -1353,7 +1356,8 @@ lbDlog: While needToFindOrCreateFile 'Find / Create file and configure. - If fbAux.CustomDialog(absoluteAuxPath, False, False, tFbExtMode.ForceExt, False, String.Empty) Then + If fbAux.CustomDialog(absoluteAuxPath, False, False, FileBrowserFileExtensionMode.ForceExt, False, String.Empty) _ + Then txtAdvancedAuxiliaryFile.Text = GetFilenameWithoutDirectory(fbAux.Files(0), GetPath(VECTOfile)) assembly = DirectCast(cboAdvancedAuxiliaries.SelectedItem, AdvancedAuxiliary) diff --git a/VECTO/GUI/VehicleAuxiliariesDialog.vb b/VECTO/GUI/VehicleAuxiliariesDialog.vb index 831bc43416..aaa378ed30 100644 --- a/VECTO/GUI/VehicleAuxiliariesDialog.vb +++ b/VECTO/GUI/VehicleAuxiliariesDialog.vb @@ -40,15 +40,15 @@ Public Class VehicleAuxiliariesDialog Private Sub DeclInit() CbTech.Items.Clear() Select Case TbID.Text - Case sKey.AUX.Fan + Case Constants.AuxiliaryKey.Fan CbTech.Items.AddRange(DeclarationData.Fan.GetTechnologies()) - Case sKey.AUX.SteerPump + Case Constants.AuxiliaryKey.SteerPump CbTech.Items.AddRange(DeclarationData.SteeringPump.GetTechnologies()) - Case sKey.AUX.HVAC + Case Constants.AuxiliaryKey.HVAC CbTech.Items.AddRange(DeclarationData.HeatingVentilationAirConditioning.GetTechnologies()) - Case sKey.AUX.ElecSys + Case Constants.AuxiliaryKey.ElecSys CbTech.Items.AddRange(DeclarationData.ElectricSystem.GetTechnologies()) - Case sKey.AUX.PneumSys + Case Constants.AuxiliaryKey.PneumSys CbTech.Items.AddRange(DeclarationData.PneumaticSystem.GetTechnologies()) End Select If CbTech.Items.Count > 0 Then @@ -94,7 +94,8 @@ Public Class VehicleAuxiliariesDialog 'Browse for .vaux files Private Sub BtBrowse_Click(sender As Object, e As EventArgs) Handles BtBrowse.Click - If AuxFileBrowser.OpenDialog(fFileRepl(TbPath.Text, VehPath)) Then TbPath.Text = GetFilenameWithoutDirectory(AuxFileBrowser.Files(0), VehPath) + If AuxFileBrowser.OpenDialog(fFileRepl(TbPath.Text, VehPath)) Then _ + TbPath.Text = GetFilenameWithoutDirectory(AuxFileBrowser.Files(0), VehPath) End Sub 'Update ID when Aux Type was changed @@ -106,12 +107,12 @@ Public Class VehicleAuxiliariesDialog If Cfg.DeclMode Then Select Case CbType.SelectedIndex Case 0 - TbID.Text = sKey.AUX.Fan + TbID.Text = Constants.AuxiliaryKey.Fan Case 1 - TbID.Text = sKey.AUX.SteerPump + TbID.Text = Constants.AuxiliaryKey.SteerPump Case Else '2 - TbID.Text = sKey.AUX.HVAC + TbID.Text = Constants.AuxiliaryKey.HVAC End Select Else diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb index 28d309b014..417ec287cb 100644 --- a/VECTO/GUI/VehicleForm.vb +++ b/VECTO/GUI/VehicleForm.vb @@ -21,6 +21,16 @@ Imports TUGraz.VectoCore.Models.Declaration ''' Vehicle Editor. ''' </summary> Public Class VehicleForm + Private Enum AxleTbl + AxleNumber = 0 + RelativeLoad = 1 + TwinTyres = 2 + RRC = 3 + FzISO = 4 + WheelsDimension = 5 + Inertia = 6 + End Enum + Private _axlDlog As VehicleAxleDialog Private _hdVclass As String Private _vehFile As String @@ -94,8 +104,8 @@ Public Class VehicleForm TbHDVclass.Text = "-" Exit Sub End If - Dim vehC As VehicleCategory = CbCat.SelectedValue - Dim axlC As AxleConfiguration = CbAxleConfig.SelectedValue + Dim vehC As VehicleCategory = CType(CbCat.SelectedValue, VehicleCategory) + Dim axlC As AxleConfiguration = CType(CbAxleConfig.SelectedValue, AxleConfiguration) Dim maxMass As Kilogram = (TbMassMass.Text.ToDouble() * 1000).SI(Of Kilogram)() _hdVclass = "-" @@ -107,12 +117,12 @@ Public Class VehicleForm ' no segment found - ignore End Try If Not s0 Is Nothing Then - _hdVclass = s0.VehicleClass + _hdVclass = s0.VehicleClass.GetClassNumber() End If TbHDVclass.Text = _hdVclass - PicVehicle.Image = ConvPicPath(_hdVclass, False) + PicVehicle.Image = ConvPicPath(_hdVclass.ToInt(), False) End Sub @@ -124,9 +134,9 @@ Public Class VehicleForm TbHDVclass.Text = "-" Exit Sub End If - Dim vehC = CbCat.SelectedValue - Dim axlC = CbAxleConfig.SelectedValue - Dim maxMass = (TbMassMass.Text.ToDouble() * 1000).SI(Of Kilogram)() + Dim vehC As VehicleCategory = CType(CbCat.SelectedValue, VehicleCategory) + Dim axlC As AxleConfiguration = CType(CbAxleConfig.SelectedValue, AxleConfiguration) + Dim maxMass As Kilogram = (TbMassMass.Text.ToDouble() * 1000).SI(Of Kilogram)() Dim s0 As Segment = Nothing Try @@ -135,21 +145,13 @@ Public Class VehicleForm ' no segment found - ignore End Try If Not s0 Is Nothing Then - _hdVclass = s0.VehicleClass - Dim axleCount As Short = s0.Missions(0).AxleWeightDistribution.Count() + _hdVclass = s0.VehicleClass.GetClassNumber() + Dim axleCount As Integer = s0.Missions(0).AxleWeightDistribution.Count() Dim i0 = LvRRC.Items.Count If axleCount > i0 Then For i = 1 To axleCount - LvRRC.Items.Count - Dim lvi = New ListViewItem - lvi.SubItems(0).Text = (i + i0).ToString - lvi.SubItems.Add("-") - lvi.SubItems.Add("no") - lvi.SubItems.Add("") - lvi.SubItems.Add("") - lvi.SubItems.Add("-") - lvi.SubItems.Add("-") - LvRRC.Items.Add(lvi) + LvRRC.Items.Add(CreateListViewItem(i + i0, Double.NaN, False, Double.NaN, Double.NaN, "", Double.NaN)) Next ElseIf axleCount < LvRRC.Items.Count Then @@ -170,13 +172,13 @@ Public Class VehicleForm CbCdMode.SelectedValue = CrossWindCorrectionMode.DeclarationModeCorrection TbCdFile.Text = "" - Dim rdyn As Single + Dim rdyn As Double rdyn = -1 If rdyn < 0 Then TBrdyn.Text = "-" Else - TBrdyn.Text = rdyn + TBrdyn.Text = rdyn.ToGUIFormat() End If End Sub @@ -305,7 +307,7 @@ Public Class VehicleForm 'Open VEH Sub OpenVehicle(file As String) - Dim inertia As Single + Dim inertia As Double If ChangeCheckCancel() Then Exit Sub @@ -328,20 +330,20 @@ Public Class VehicleForm End Select End If - TbMass.Text = veh.Mass - TbMassExtra.Text = veh.MassExtra - TbLoad.Text = veh.Loading - TBrdyn.Text = veh.DynamicTyreRadius + TbMass.Text = veh.Mass.ToGUIFormat() + TbMassExtra.Text = veh.MassExtra.ToGUIFormat() + TbLoad.Text = veh.Loading.ToGUIFormat() + TBrdyn.Text = veh.DynamicTyreRadius.ToGUIFormat() CbCdMode.SelectedValue = veh.CrossWindCorrectionMode TbCdFile.Text = veh.CrossWindCorrectionFile.OriginalPath CbRtType.SelectedValue = veh.RetarderType - TbRtRatio.Text = veh.RetarderRatio + TbRtRatio.Text = veh.RetarderRatio.ToGUIFormat() TbRtPath.Text = veh.RetarderLossMapFile.OriginalPath cbAngularGearType.SelectedValue = veh.AngularGearType - tbAngularGearRatio.Text = veh.AngularGearRatio + tbAngularGearRatio.Text = veh.AngularGearRatio.ToGUIFormat() tbAngularGearLossMapPath.Text = veh.AngularGearLossMapFile.OriginalPath CbCat.SelectedValue = veh.VehicleCategory @@ -351,44 +353,24 @@ Public Class VehicleForm Dim i = 0 For Each a0 In veh.Axles i += 1 - Dim lvi = New ListViewItem - lvi.SubItems(0).Text = i.ToString - If Cfg.DeclMode Then - lvi.SubItems.Add("-") - Else - lvi.SubItems.Add(a0.Share) - End If - - If a0.TwinTire Then - lvi.SubItems.Add("yes") - Else - lvi.SubItems.Add("no") - End If - lvi.SubItems.Add(a0.RRC) - lvi.SubItems.Add(a0.FzISO) - lvi.SubItems.Add(a0.Wheels) If Cfg.DeclMode Then inertia = DeclarationData.Wheels.Lookup(a0.Wheels).Inertia.Value() - If inertia < 0 Then - lvi.SubItems.Add("-") - Else - lvi.SubItems.Add(inertia) - End If + LvRRC.Items.Add(CreateListViewItem(i, Double.NaN, a0.TwinTire, a0.RRC, a0.FzISO, a0.Wheels, inertia)) Else - lvi.SubItems.Add(a0.Inertia) + LvRRC.Items.Add(CreateListViewItem(i, a0.Share, a0.TwinTire, a0.RRC, a0.FzISO, a0.Wheels, a0.Inertia)) + End If - LvRRC.Items.Add(lvi) Next - TbMassMass.Text = veh.MassMax - TbMassExtra.Text = veh.MassExtra + TbMassMass.Text = veh.MassMax.ToGUIFormat() + TbMassExtra.Text = veh.MassExtra.ToGUIFormat() CbAxleConfig.SelectedValue = veh.AxleConfiguration - TBcdA.Text = veh.CdA0 + TBcdA.Text = veh.CdA0.ToGUIFormat() cbPTOType.SelectedValue = veh.PTOType tbPTOLossMap.Text = veh.PTOLossMap.OriginalPath @@ -405,45 +387,67 @@ Public Class VehicleForm _changed = False End Sub + Private Function CreateListViewItem(axleNumber As Integer, share As Double, twinTire As Boolean, rrc As Double, + fzIso As Double, wheels As String, inertia As Double) As ListViewItem + Dim retVal As New ListViewItem + retVal.SubItems(0).Text = axleNumber.ToGUIFormat() + FillDoubleValue(retVal, share, "-") + retVal.SubItems.Add(If(twinTire, "yes", "no")) + FillDoubleValue(retVal, rrc) + FillDoubleValue(retVal, fzIso) + retVal.SubItems.Add(wheels) + FillDoubleValue(retVal, inertia) + Return retVal + End Function + + Private Sub FillDoubleValue(listViewItem As ListViewItem, share As Double, Optional defaultValue As String = "") + + If Double.IsNaN(share) Then + listViewItem.SubItems.Add(defaultValue) + Else + listViewItem.SubItems.Add(share.ToGUIFormat()) + End If + End Sub + 'Save VEH Private Function SaveVehicle(file As String) As Boolean Dim veh = New Vehicle veh.FilePath = file - veh.Mass = CSng(fTextboxToNumString(TbMass.Text)) - veh.MassExtra = CSng(fTextboxToNumString(TbMassExtra.Text)) - veh.Loading = CSng(fTextboxToNumString(TbLoad.Text)) + veh.Mass = TbMass.Text.ToDouble() + veh.MassExtra = TbMassExtra.Text.ToDouble() + veh.Loading = TbLoad.Text.ToDouble() - veh.CdA0 = CSng(fTextboxToNumString(TBcdA.Text)) + veh.CdA0 = TBcdA.Text.ToDouble() - veh.DynamicTyreRadius = CSng(fTextboxToNumString(TBrdyn.Text)) - veh.CrossWindCorrectionMode = CbCdMode.SelectedValue + veh.DynamicTyreRadius = TBrdyn.Text.ToDouble() + veh.CrossWindCorrectionMode = CType(CbCdMode.SelectedValue, CrossWindCorrectionMode) veh.CrossWindCorrectionFile.Init(GetPath(file), TbCdFile.Text) - veh.RetarderType = CbRtType.SelectedValue - veh.RetarderRatio = CSng(fTextboxToNumString(TbRtRatio.Text)) + veh.RetarderType = CType(CbRtType.SelectedValue, RetarderType) + veh.RetarderRatio = TbRtRatio.Text.ToDouble() veh.RetarderLossMapFile.Init(GetPath(file), TbRtPath.Text) - veh.AngularGearType = cbAngularGearType.SelectedValue - veh.AngularGearRatio = CSng(fTextboxToNumString(tbAngularGearRatio.Text)) + veh.AngularGearType = CType(cbAngularGearType.SelectedValue, AngularGearType) + veh.AngularGearRatio = tbAngularGearRatio.Text.ToDouble() veh.AngularGearLossMapFile.Init(GetPath(file), tbAngularGearLossMapPath.Text) - veh.VehicleCategory = CbCat.SelectedValue 'CType(CbCat.SelectedIndex, tVehCat) + veh.VehicleCategory = CType(CbCat.SelectedValue, VehicleCategory) 'CType(CbCat.SelectedIndex, tVehCat) Dim axleShareCheck As Double - For Each LV0 In LvRRC.Items + For Each entry As ListViewItem In LvRRC.Items Dim a0 = New Vehicle.Axle - a0.Share = fTextboxToNumString(LV0.SubItems(1).Text) + a0.Share = entry.SubItems(AxleTbl.RelativeLoad).Text.ToDouble() axleShareCheck += a0.Share - a0.TwinTire = (LV0.SubItems(2).Text = "yes") - a0.RRC = fTextboxToNumString(LV0.SubItems(3).Text) - a0.FzISO = fTextboxToNumString(LV0.SubItems(4).Text) - a0.Wheels = LV0.SubItems(5).Text - a0.Inertia = fTextboxToNumString(LV0.SubItems(6).Text) + a0.TwinTire = (entry.SubItems(AxleTbl.TwinTyres).Text = "yes") + a0.RRC = entry.SubItems(AxleTbl.RRC).Text.ToDouble() + a0.FzISO = entry.SubItems(AxleTbl.FzISO).Text.ToDouble() + a0.Wheels = entry.SubItems(AxleTbl.WheelsDimension).Text + a0.Inertia = entry.SubItems(AxleTbl.Inertia).Text.ToDouble() veh.Axles.Add(a0) Next - veh.PTOType = cbPTOType.SelectedValue + veh.PTOType = CType(cbPTOType.SelectedValue, String) veh.PTOLossMap.Init(GetPath(file), tbPTOLossMap.Text) veh.PTOCycle.Init(GetPath(file), tbPTOCycle.Text) @@ -452,9 +456,9 @@ Public Class VehicleForm Return False End If - veh.MassMax = CSng(fTextboxToNumString(TbMassMass.Text)) - veh.MassExtra = CSng(fTextboxToNumString(TbMassExtra.Text)) - veh.AxleConfiguration = CbAxleConfig.SelectedValue + veh.MassMax = TbMassMass.Text.ToDouble() + veh.MassExtra = TbMassExtra.Text.ToDouble() + veh.AxleConfiguration = CType(CbAxleConfig.SelectedValue, AxleConfiguration) '--------------------------------------------------------------------------------- @@ -647,27 +651,11 @@ Public Class VehicleForm #Region "Axle Configuration" Private Sub ButAxlAdd_Click(sender As Object, e As EventArgs) Handles ButAxlAdd.Click - Dim lv0 As ListViewItem - _axlDlog.Clear() - If _axlDlog.ShowDialog = DialogResult.OK Then - lv0 = New ListViewItem - - lv0.SubItems(0).Text = LvRRC.Items.Count + 1 - lv0.SubItems.Add(Trim(_axlDlog.TbAxleShare.Text)) - If _axlDlog.CbTwinT.Checked Then - lv0.SubItems.Add("yes") - Else - lv0.SubItems.Add("no") - End If - lv0.SubItems.Add(Trim(_axlDlog.TbRRC.Text)) - lv0.SubItems.Add(Trim(_axlDlog.TbFzISO.Text)) - lv0.SubItems.Add(Trim(_axlDlog.CbWheels.Text)) - lv0.SubItems.Add(Trim(_axlDlog.TbI_wheels.Text)) - - LvRRC.Items.Add(lv0) - + LvRRC.Items.Add(CreateListViewItem(LvRRC.Items.Count + 1, _axlDlog.TbAxleShare.Text.ToDouble(), + _axlDlog.CbTwinT.Checked, _axlDlog.TbRRC.Text.ToDouble(), _axlDlog.TbFzISO.Text.ToDouble(), + _axlDlog.CbWheels.Text, _axlDlog.TbI_wheels.Text.ToDouble())) Change() DeclInit() @@ -710,7 +698,7 @@ Public Class VehicleForm i = 0 For Each lv0 In LvRRC.Items i += 1 - lv0.SubItems(0).Text = i.ToString + lv0.SubItems(AxleTbl.AxleNumber).Text = i.ToString Next LvRRC.Items(LvRRC.Items.Count - 1).Selected = True @@ -725,24 +713,24 @@ Public Class VehicleForm Dim lv0 = LvRRC.SelectedItems(0) - _axlDlog.TbAxleShare.Text = lv0.SubItems(1).Text - _axlDlog.CbTwinT.Checked = (lv0.SubItems(2).Text = "yes") - _axlDlog.TbRRC.Text = lv0.SubItems(3).Text - _axlDlog.TbFzISO.Text = lv0.SubItems(4).Text - _axlDlog.TbI_wheels.Text = lv0.SubItems(6).Text - _axlDlog.CbWheels.Text = lv0.SubItems(5).Text + _axlDlog.TbAxleShare.Text = lv0.SubItems(AxleTbl.RelativeLoad).Text + _axlDlog.CbTwinT.Checked = (lv0.SubItems(AxleTbl.TwinTyres).Text = "yes") + _axlDlog.TbRRC.Text = lv0.SubItems(AxleTbl.RRC).Text + _axlDlog.TbFzISO.Text = lv0.SubItems(AxleTbl.FzISO).Text + _axlDlog.TbI_wheels.Text = lv0.SubItems(AxleTbl.Inertia).Text + _axlDlog.CbWheels.Text = lv0.SubItems(AxleTbl.WheelsDimension).Text If _axlDlog.ShowDialog = DialogResult.OK Then - lv0.SubItems(1).Text = _axlDlog.TbAxleShare.Text + lv0.SubItems(AxleTbl.RelativeLoad).Text = _axlDlog.TbAxleShare.Text If _axlDlog.CbTwinT.Checked Then - lv0.SubItems(2).Text = "yes" + lv0.SubItems(AxleTbl.TwinTyres).Text = "yes" Else - lv0.SubItems(2).Text = "no" + lv0.SubItems(AxleTbl.TwinTyres).Text = "no" End If - lv0.SubItems(3).Text = _axlDlog.TbRRC.Text - lv0.SubItems(4).Text = _axlDlog.TbFzISO.Text - lv0.SubItems(5).Text = _axlDlog.CbWheels.Text - lv0.SubItems(6).Text = _axlDlog.TbI_wheels.Text + lv0.SubItems(AxleTbl.RRC).Text = _axlDlog.TbRRC.Text + lv0.SubItems(AxleTbl.FzISO).Text = _axlDlog.TbFzISO.Text + lv0.SubItems(AxleTbl.WheelsDimension).Text = _axlDlog.CbWheels.Text + lv0.SubItems(AxleTbl.Inertia).Text = _axlDlog.TbI_wheels.Text Change() DeclInit() diff --git a/VECTO/Input Files/Engine.vb b/VECTO/Input Files/Engine.vb index 464e0898b9..9c50cfc05d 100644 --- a/VECTO/Input Files/Engine.vb +++ b/VECTO/Input Files/Engine.vb @@ -10,7 +10,9 @@ ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Collections.Generic Imports System.IO +Imports Newtonsoft.Json.Linq Imports TUGraz.VECTO.Input_Files +Imports TUGraz.VectoCore.InputData.FileIO.JSON ''' <summary> ''' Engine input file @@ -27,7 +29,7 @@ Public Class Engine ''' Format version of input file. Defined in ReadFile. ''' </summary> ''' <remarks></remarks> - Private _fileVersion As Short + Private _fileVersion As Integer ''' <summary> ''' Engine description (model, type, etc.). Saved in input file. @@ -39,19 +41,19 @@ Public Class Engine ''' Engine displacement [ccm]. Saved in input file. ''' </summary> ''' <remarks></remarks> - Public Displacement As Single + Public Displacement As Double ''' <summary> ''' Idling speed [1/min]. Saved in input file. ''' </summary> ''' <remarks></remarks> - Public IdleSpeed As Single + Public IdleSpeed As Double ''' <summary> ''' Rotational inertia including flywheel [kgm²]. Saved in input file. Overwritten by generic value in Declaration mode. ''' </summary> ''' <remarks></remarks> - Public EngineInertia As Single + Public EngineInertia As Double ''' <summary> ''' List of full load/motoring curve files (.vfld) @@ -82,19 +84,19 @@ Public Class Engine ''' WHTC Urban test results. Saved in input file. ''' </summary> ''' <remarks></remarks> - Public WHTCurban As Single + Public WHTCurban As Double ''' <summary> ''' WHTC Rural test results. Saved in input file. ''' </summary> ''' <remarks></remarks> - Public WHTCrural As Single + Public WHTCrural As Double ''' <summary> ''' WHTC Motorway test results. Saved in input file. ''' </summary> ''' <remarks></remarks> - Public WHTCmw As Single + Public WHTCmw As Double Public SavedInDeclMode As Boolean @@ -148,7 +150,7 @@ Public Class Engine dic.Add("Date", Now.ToUniversalTime().ToString("o")) dic.Add("AppVersion", VECTOvers) dic.Add("FileVersion", FormatVersion) - JSON.Content.Add("Header", dic) + JSON.Content.Add("Header", JToken.FromObject(dic)) 'Body dic = New Dictionary(Of String, Object) @@ -171,7 +173,7 @@ Public Class Engine dic.Add("WHTC-Motorway", WHTCmw) - JSON.Content.Add("Body", dic) + JSON.Content.Add("Body", JToken.FromObject(dic)) Return JSON.WriteFile(_filePath) @@ -182,49 +184,50 @@ Public Class Engine ''' </summary> ''' <returns>True if successful.</returns> ''' <remarks></remarks> - Public Function ReadFile(Optional ByVal ShowMsg As Boolean = True) As Boolean - Dim MsgSrc As String - Dim JSON As New JSONParser + Public Function ReadFile(Optional ByVal showMsg As Boolean = True) As Boolean + Dim msgSrc As String + Dim json As New JSONParser - MsgSrc = "ENG/ReadFile" + msgSrc = "ENG/ReadFile" SetDefault() - If Not JSON.ReadFile(_filePath) Then Return False + If Not json.ReadFile(_filePath) Then Return False Try - _fileVersion = JSON.Content("Header")("FileVersion") + _fileVersion = json.Content.GetEx("Header").GetEx(Of Integer)("FileVersion") + Dim body As JToken = json.Content.GetEx("Body") If _fileVersion > 1 Then - SavedInDeclMode = JSON.Content("Body")("SavedInDeclMode") + SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") Else SavedInDeclMode = Cfg.DeclMode End If - ModelName = JSON.Content("Body")("ModelName") + ModelName = body.GetEx(Of String)("ModelName") - Displacement = JSON.Content("Body")("Displacement") - IdleSpeed = JSON.Content("Body")("IdlingSpeed") - EngineInertia = JSON.Content("Body")("Inertia") + Displacement = body.GetEx(Of Double)("Displacement") + IdleSpeed = body.GetEx(Of Double)("IdlingSpeed") + EngineInertia = body.GetEx(Of Double)("Inertia") If _fileVersion < 3 Then - _fullLoadCurvePath.Init(_myPath, JSON.Content("Body")("FullLoadCurves")(0)("Path")) + _fullLoadCurvePath.Init(_myPath, body.GetEx("FullLoadCurves").First.GetEx(Of String)("Path")) Else - _fullLoadCurvePath.Init(_myPath, JSON.Content("Body")("FullLoadCurve")) + _fullLoadCurvePath.Init(_myPath, body.GetEx(Of String)("FullLoadCurve")) End If - _fuelConsumptionMapPath.Init(_myPath, JSON.Content("Body")("FuelMap")) + _fuelConsumptionMapPath.Init(_myPath, body.GetEx(Of String)("FuelMap")) - If _fileVersion > 2 AndAlso Not JSON.Content("Body")("WHTC-Urban") Is Nothing Then - WHTCurban = CSng(JSON.Content("Body")("WHTC-Urban")) - WHTCrural = CSng(JSON.Content("Body")("WHTC-Rural")) - WHTCmw = CSng(JSON.Content("Body")("WHTC-Motorway")) + If _fileVersion > 2 AndAlso Not body("WHTC-Urban") Is Nothing Then + WHTCurban = (body.GetEx(Of Double)("WHTC-Urban")) + WHTCrural = (body.GetEx(Of Double)("WHTC-Rural")) + WHTCmw = (body.GetEx(Of Double)("WHTC-Motorway")) End If Catch ex As Exception - If ShowMsg Then WorkerMsg(MessageType.Err, "Failed to read VECTO file! " & ex.Message, MsgSrc) + If showMsg Then WorkerMsg(MessageType.Err, "Failed to read VECTO file! " & ex.Message, msgSrc) Return False End Try @@ -286,3 +289,4 @@ Public Class Engine End Set End Property End Class + diff --git a/VECTO/Input Files/EngineFullLoadCurve.vb b/VECTO/Input Files/EngineFullLoadCurve.vb index da6b43cd41..846d686378 100644 --- a/VECTO/Input Files/EngineFullLoadCurve.vb +++ b/VECTO/Input Files/EngineFullLoadCurve.vb @@ -20,25 +20,25 @@ Public Class EngineFullLoadCurve ''' List of full load torque values [Nm] ''' </summary> ''' <remarks></remarks> - Public MaxTorqueList As List(Of Single) + Public MaxTorqueList As List(Of Double) ''' <summary> ''' List of motoring torque values [Nm] ''' </summary> ''' <remarks></remarks> - Public DragTorqueList As List(Of Single) + Public DragTorqueList As List(Of Double) ''' <summary> ''' List of engine speed values [1/min] ''' </summary> ''' <remarks></remarks> - Public EngineSpeedList As List(Of Single) + Public EngineSpeedList As List(Of Double) ''' <summary> ''' List of PT1 values [s] ''' </summary> ''' <remarks></remarks> - Private _pt1List As List(Of Single) + Private _pt1List As List(Of Double) ''' <summary> ''' Read file. FilePath must be set before calling. @@ -75,10 +75,10 @@ Public Class EngineFullLoadCurve file.ReadLine() 'Initialize Lists - MaxTorqueList = New List(Of Single) - DragTorqueList = New List(Of Single) - EngineSpeedList = New List(Of Single) - _pt1List = New List(Of Single) + MaxTorqueList = New List(Of Double) + DragTorqueList = New List(Of Double) + EngineSpeedList = New List(Of Double) + _pt1List = New List(Of Double) Dim firstLine As Boolean = True Try @@ -148,7 +148,7 @@ lbEr: ''' <param name="nU">engine speed [1/min]</param> ''' <returns>stationary full load power [kW]</returns> ''' <remarks></remarks> - Public Function Pfull(nU As Single) As Single + Public Function Pfull(nU As Double) As Double Dim i As Int32 'Extrapolation for x < x(1) @@ -170,8 +170,7 @@ lbEr: lbInt: 'Interpolation - Return _ - nMtoPe(nU, + Return nMtoPe(nU, (nU - EngineSpeedList(i - 1)) * (MaxTorqueList(i) - MaxTorqueList(i - 1)) / (EngineSpeedList(i) - EngineSpeedList(i - 1)) + MaxTorqueList(i - 1)) End Function @@ -182,7 +181,7 @@ lbInt: ''' <param name="nU">engine speed [1/min]</param> ''' <returns>stationary full load torque [Nm]</returns> ''' <remarks></remarks> - Private Function Torque(ByVal nU As Single) As Single + Private Function Torque(nU As Double) As Double Dim i As Int32 'Extrapolation for x < x(1) @@ -310,16 +309,16 @@ lbInt: ''' </summary> ''' <returns>engine speed at maximum power [1/min]</returns> ''' <remarks></remarks> - Public Function EngineRatedSpeed() As Single + Public Function EngineRatedSpeed() As Double Dim stepSize As Single = 1 - Dim maxPower As Single = 0 - Dim rpm As Single = EngineSpeedList(0) - Dim maxSpeed As Single = EngineSpeedList.Last() - Dim ratedSpeed As Single = rpm + Dim maxPower As Double = 0 + Dim rpm As Double = EngineSpeedList(0) + Dim maxSpeed As Double = EngineSpeedList.Last() + Dim ratedSpeed As Double = rpm Do - Dim power As Single = nMtoPe(rpm, Torque(rpm)) + Dim power As Double = nMtoPe(rpm, Torque(rpm)) If power > maxPower Then maxPower = power ratedSpeed = rpm diff --git a/VECTO/Input Files/FuelconsumptionMap.vb b/VECTO/Input Files/FuelconsumptionMap.vb index 2989b09df6..8b98ce8344 100644 --- a/VECTO/Input Files/FuelconsumptionMap.vb +++ b/VECTO/Input Files/FuelconsumptionMap.vb @@ -9,13 +9,14 @@ ' ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Collections.Generic +Imports TUGraz.VectoCommon.Utils Public Class FuelconsumptionMap 'Implements IFuelConsumptionMap - Private _angularSpeedList As List(Of Single) - Private _torqueList As List(Of Single) - Private _fuelconsumptionList As List(Of Single) + Private _angularSpeedList As List(Of Double) + Private _torqueList As List(Of Double) + Private _fuelconsumptionList As List(Of Double) Private _filePath As String @@ -50,9 +51,9 @@ Public Class FuelconsumptionMap file.ReadLine() 'Initi Lists (before version check so ReadOldFormat works) - _fuelconsumptionList = New List(Of Single) - _torqueList = New List(Of Single) - _angularSpeedList = New List(Of Single) + _fuelconsumptionList = New List(Of Double) + _torqueList = New List(Of Double) + _angularSpeedList = New List(Of Double) Dim lineCount As Integer = -1 @@ -66,12 +67,12 @@ Public Class FuelconsumptionMap lineCount += 1 'Revolutions - Dim rpm As Double = CDbl(line(0)) + Dim rpm As Double = line(0).ToDouble() _angularSpeedList.Add(rpm) 'Power - _torqueList.Add(line(1)) + _torqueList.Add(line(1).ToDouble()) 'FC 'Check sign @@ -81,7 +82,7 @@ Public Class FuelconsumptionMap Return False End If - _fuelconsumptionList.Add(CSng(line(2))) + _fuelconsumptionList.Add(line(2).ToDouble()) Loop @@ -121,13 +122,13 @@ lbEr: End Set End Property - Public ReadOnly Property Tq As List(Of Single) + Public ReadOnly Property Tq As List(Of Double) Get Return _torqueList End Get End Property - Public ReadOnly Property nU As List(Of Single) + Public ReadOnly Property nU As List(Of Double) Get Return _angularSpeedList End Get diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb index bb60b420ba..46f44f4bf1 100644 --- a/VECTO/Input Files/Gearbox.vb +++ b/VECTO/Input Files/Gearbox.vb @@ -10,22 +10,24 @@ ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Collections.Generic Imports System.IO +Imports Newtonsoft.Json.Linq Imports TUGraz.VECTO.Input_Files Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCommon.Utils +Imports TUGraz.VectoCore.InputData.FileIO.JSON Public Class Gearbox Private Const FormatVersion As Short = 6 - Private _fileVersion As Short + Private _fileVersion As Integer Private _myPath As String Private _filePath As String Public ModelName As String - Public GbxInertia As Single - Public TracIntrSi As Single + Public GbxInertia As Double + Public TracIntrSi As Double - Public GearRatios As List(Of Single) + Public GearRatios As List(Of Double) Public GearLossmaps As List(Of SubPath) 'Gear shift polygons @@ -33,28 +35,28 @@ Public Class Gearbox Public MaxTorque As List(Of String) - Public TorqueResv As Single + Public TorqueResv As Double Public SkipGears As Boolean - Public ShiftTime As Integer - Public TorqueResvStart As Single - Public StartSpeed As Single - Public StartAcc As Single + Public ShiftTime As Double + Public TorqueResvStart As Double + Public StartSpeed As Double + Public StartAcc As Double Public ShiftInside As Boolean Public Type As GearboxType 'Torque Converter Input Public TorqueConverterEnabled As Boolean - Public TorqueConverterReferenceRpm As Single + Public TorqueConverterReferenceRpm As Double Private ReadOnly _torqueConverterFile As New SubPath - Public TorqueConverterInertia As Single + Public TorqueConverterInertia As Double Public TorqueConverterShiftPolygonFile As String Public SavedInDeclMode As Boolean - Public UpshiftMinAcceleration As Single - Public DownshiftAfterUpshift As Single - Public UpshiftAfterDownshift As Single + Public UpshiftMinAcceleration As Double + Public DownshiftAfterUpshift As Double + Public UpshiftAfterDownshift As Double Public Sub New() @@ -69,7 +71,7 @@ Public Class Gearbox GbxInertia = 0 TracIntrSi = 0 - GearRatios = New List(Of Single) + GearRatios = New List(Of Double) GearLossmaps = New List(Of SubPath) GearshiftFiles = New List(Of SubPath) MaxTorque = New List(Of String) @@ -95,7 +97,7 @@ Public Class Gearbox Public Function SaveFile() As Boolean Dim i As Integer - Dim writer As New JSONParser + Dim json As New JSONParser Dim content As Dictionary(Of String, Object) 'Header @@ -104,7 +106,7 @@ Public Class Gearbox content.Add("Date", Now.ToUniversalTime().ToString("o")) content.Add("AppVersion", VECTOvers) content.Add("FileVersion", FormatVersion) - writer.Content.Add("Header", content) + json.Content.Add("Header", JToken.FromObject(content)) 'Body content = New Dictionary(Of String, Object) @@ -159,103 +161,105 @@ Public Class Gearbox content.Add("UpshiftAfterDownshiftDelay", UpshiftAfterDownshift) content.Add("UpshiftMinAcceleration", UpshiftMinAcceleration) - writer.Content.Add("Body", content) + json.Content.Add("Body", JToken.FromObject(content)) - Return writer.WriteFile(_filePath) + Return json.WriteFile(_filePath) End Function Public Function ReadFile(Optional ByVal showMsg As Boolean = True) As Boolean Dim i As Integer - Dim parser As New JSONParser - Dim dic As Object + Dim json As New JSONParser + Dim dic As JToken Const msgSrc As String = "GBX/ReadFile" SetDefault() - If Not parser.ReadFile(_filePath) Then Return False + If Not json.ReadFile(_filePath) Then Return False Try - _fileVersion = parser.Content("Header")("FileVersion") + _fileVersion = json.Content.GetEx("Header").GetEx(Of Integer)("FileVersion") + Dim body As JToken = json.Content.GetEx("Body") If _fileVersion > 3 Then - SavedInDeclMode = parser.Content("Body")("SavedInDeclMode") + SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") Else SavedInDeclMode = Cfg.DeclMode End If - ModelName = parser.Content("Body")("ModelName") - GbxInertia = parser.Content("Body")("Inertia") - TracIntrSi = parser.Content("Body")("TracInt") + ModelName = body.GetEx(Of String)("ModelName") + GbxInertia = body.GetEx(Of Double)("Inertia") + TracIntrSi = body.GetEx(Of Double)("TracInt") i = -1 - For Each dic In parser.Content("Body")("Gears") + For Each dic In body.GetEx("Gears") i += 1 - GearRatios.Add(dic("Ratio")) + GearRatios.Add(dic.GetEx(Of Double)("Ratio")) GearLossmaps.Add(New SubPath) If dic("Efficiency") Is Nothing Then - GearLossmaps(i).Init(_myPath, dic("LossMap")) + GearLossmaps(i).Init(_myPath, dic.GetEx(Of String)("LossMap")) Else - GearLossmaps(i).Init(_myPath, dic("Efficiency")) + GearLossmaps(i).Init(_myPath, dic.GetEx(Of Double)("Efficiency")) End If - MaxTorque.Add(dic("MaxTorque")) + MaxTorque.Add(dic.GetEx(Of String)("MaxTorque")) GearshiftFiles.Add(New SubPath) If i = 0 Then - GearshiftFiles(i).Init(_myPath, sKey.NoFile) + GearshiftFiles(i).Init(_myPath, Constants.NoFile) Else If _fileVersion < 2 Then - GearshiftFiles(i).Init(_myPath, parser.Content("Body")("ShiftPolygons")) + GearshiftFiles(i).Init(_myPath, body.GetEx(Of String)("ShiftPolygons")) Else - GearshiftFiles(i).Init(_myPath, dic("ShiftPolygon")) + GearshiftFiles(i).Init(_myPath, dic.GetEx(Of String)("ShiftPolygon")) End If End If Next - TorqueResv = parser.Content("Body")("TqReserve") - SkipGears = parser.Content("Body")("SkipGears") - ShiftTime = parser.Content("Body")("ShiftTime") - TorqueResvStart = parser.Content("Body")("StartTqReserve") - StartSpeed = parser.Content("Body")("StartSpeed") - StartAcc = parser.Content("Body")("StartAcc") - ShiftInside = parser.Content("Body")("EaryShiftUp") + 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 = parser.Content("Body")("GearboxType").ToString.ParseEnum(Of GearboxType)() + Type = json.Content("Body")("GearboxType").ToString.ParseEnum(Of GearboxType)() - If parser.Content("Body")("UpshiftMinAcceleration") Is Nothing Then + If body("UpshiftMinAcceleration") Is Nothing Then UpshiftMinAcceleration = 0.1 Else - UpshiftMinAcceleration = parser.Content("Body")("UpshiftMinAcceleration") + UpshiftMinAcceleration = body.GetEx(Of Double)("UpshiftMinAcceleration") End If - If parser.Content("Body")("DownshiftAferUpshiftDelay") Is Nothing Then + If body("DownshiftAferUpshiftDelay") Is Nothing Then DownshiftAfterUpshift = 10 Else - DownshiftAfterUpshift = parser.Content("Body")("DownshiftAferUpshiftDelay") + DownshiftAfterUpshift = body.GetEx(Of Double)("DownshiftAferUpshiftDelay") End If - If parser.Content("Body")("UpshiftAfterDownshiftDelay") Is Nothing Then + If body("UpshiftAfterDownshiftDelay") Is Nothing Then UpshiftAfterDownshift = 10 Else - UpshiftAfterDownshift = parser.Content("Body")("UpshiftAfterDownshiftDelay") + UpshiftAfterDownshift = body.GetEx(Of Double)("UpshiftAfterDownshiftDelay") End If - If parser.Content("Body")("TorqueConverter") Is Nothing Then + If json.Content("Body")("TorqueConverter") Is Nothing Then TorqueConverterEnabled = False Else - TorqueConverterEnabled = parser.Content("Body")("TorqueConverter")("Enabled") - _torqueConverterFile.Init(_myPath, parser.Content("Body")("TorqueConverter")("File")) - TorqueConverterReferenceRpm = parser.Content("Body")("TorqueConverter")("RefRPM") + 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 = parser.Content("Body")("TorqueConverter")("Inertia") + TorqueConverterInertia = torqueConverter.GetEx(Of Double)("Inertia") End If If _fileVersion > 5 Then - TorqueConverterShiftPolygonFile = parser.Content("Body")("TorqueConverter")("ShiftPolygon") + TorqueConverterShiftPolygonFile = torqueConverter.GetEx(Of String)("ShiftPolygon") End If End If Catch ex As Exception @@ -286,9 +290,9 @@ Public Class Gearbox End Set End Property - Public Property GearLossMap(ByVal gearNr As Short, Optional ByVal original As Boolean = False) As String + Public Property GearLossMap(ByVal gearNr As Integer, Optional ByVal original As Boolean = False) As String Get - If Original Then + If original Then Return GearLossmaps(gearNr).OriginalPath Else Return GearLossmaps(gearNr).FullPath @@ -299,7 +303,7 @@ Public Class Gearbox End Set End Property - Public Property ShiftPolygonFile(ByVal gearNr As Short, Optional ByVal original As Boolean = False) As String + Public Property ShiftPolygonFile(ByVal gearNr As Integer, Optional ByVal original As Boolean = False) As String Get If original Then Return GearshiftFiles(gearNr).OriginalPath @@ -314,7 +318,7 @@ Public Class Gearbox Public Property TorqueConverterFile(Optional ByVal original As Boolean = False) As String Get - If Original Then + If original Then Return _torqueConverterFile.OriginalPath Else Return _torqueConverterFile.FullPath diff --git a/VECTO/Input Files/SubPath.vb b/VECTO/Input Files/SubPath.vb index 011151ed16..20d196187a 100644 --- a/VECTO/Input Files/SubPath.vb +++ b/VECTO/Input Files/SubPath.vb @@ -29,7 +29,7 @@ Namespace Input_Files End Sub Private Function CheckFilenameGiven(f As String) As String - If Trim(UCase(f)) = sKey.NoFile Then + If Trim(UCase(f)) = Constants.NoFile Then Return "" Else Return f @@ -66,7 +66,7 @@ Namespace Input_Files If _valid Then Return _originalPath Else - Return sKey.NoFile + Return Constants.NoFile End If End Get End Property diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb index d67674d414..aa63f4e73c 100644 --- a/VECTO/Input Files/VectoJob.vb +++ b/VECTO/Input Files/VectoJob.vb @@ -16,6 +16,7 @@ Imports System.IO Imports System.Linq Imports Newtonsoft.Json.Linq Imports TUGraz.VECTO.Input_Files +Imports TUGraz.VectoCore.InputData.FileIO.JSON Public Class VectoJob Private Const FormatVersion As Short = 3 @@ -35,9 +36,9 @@ Public Class VectoJob Private ReadOnly _gearboxFile As SubPath Private _startStop As Boolean - Private _startStopMaxSpeed As Single - Private _startStopMinTime As Single - Public StartStopDelay As Integer + Private _startStopMaxSpeed As Double + Private _startStopMinTime As Double + Public StartStopDelay As Double Private ReadOnly _driverAccelerationFile As SubPath @@ -48,11 +49,11 @@ Public Class VectoJob Public EngineOnly As Boolean - Public VMin As Single + Public VMin As Double Public LookAheadOn As Boolean Public OverSpeedOn As Boolean - Public OverSpeed As Single - Public UnderSpeed As Single + Public OverSpeed As Double + Public UnderSpeed As Double Public EcoRollOn As Boolean Public SavedInDeclMode As Boolean @@ -60,10 +61,11 @@ Public Class VectoJob Public Class AuxEntry Public Type As String Public ReadOnly Path As SubPath - Public TechStr As String = "" + Public TechnologyList As List(Of String) Public Sub New() Path = New SubPath + TechnologyList = New List(Of String)() End Sub End Class @@ -87,11 +89,11 @@ Public Class VectoJob 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}}) + json.Content.Add("Header", JToken.FromObject(New Dictionary(Of String, Object) From { + {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, + {"Date", Now.ToUniversalTime().ToString("o")}, + {"AppVersion", VECTOvers}, + {"FileVersion", FormatVersion}})) 'Body Dim dic0 = New Dictionary(Of String, Object) @@ -120,7 +122,7 @@ Public Class VectoJob {"ID", Trim(UCase(kv.Key))}, {"Type", kv.Value.Type}, {"Path", kv.Value.Path.PathOrDummy}, - {"Technology", IIf(kv.Value.TechStr = "", New List(Of String), New List(Of String) From {kv.Value.TechStr})} + {"Technology", kv.Value.TechnologyList} })) End If @@ -153,7 +155,7 @@ Public Class VectoJob overspeedDic.Add("UnderSpeed", UnderSpeed) dic0.Add("OverSpeedEcoRoll", overspeedDic) - json.Content.Add("Body", dic0) + json.Content.Add("Body", JToken.FromObject(dic0)) Return json.WriteFile(_sFilePath) End Function @@ -166,28 +168,29 @@ Public Class VectoJob If Not json.ReadFile(_sFilePath) Then Return False Try - Dim fileVersion = json.Content("Header")("FileVersion") - Dim body As JObject = json.Content("Body") + Dim fileVersion As Integer = json.Content.GetEx("Header").GetEx(Of Integer)("FileVersion") + + Dim body As JToken = json.Content.GetEx("Body") If fileVersion > 1 Then - SavedInDeclMode = body("SavedInDeclMode") + SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") Else SavedInDeclMode = Cfg.DeclMode End If If Not body("VehicleFile") Is Nothing Then _ - _vehicleFile.Init(_myPath, body("VehicleFile")) + _vehicleFile.Init(_myPath, body.GetEx(Of String)("VehicleFile")) - _engineFile.Init(_myPath, body("EngineFile")) + _engineFile.Init(_myPath, body.GetEx(Of String)("EngineFile")) If Not body("GearboxFile") Is Nothing Then _ - _gearboxFile.Init(_myPath, body("GearboxFile")) + _gearboxFile.Init(_myPath, body.GetEx(Of String)("GearboxFile")) If Not body("Cycles") Is Nothing Then - For Each str As String In body("Cycles") + For Each entry As JToken In body.GetEx("Cycles") Dim subPath = New SubPath - subPath.Init(_myPath, str) + subPath.Init(_myPath, entry.Value(Of String)) CycleFiles.Add(subPath) Next End If @@ -207,9 +210,9 @@ Public Class VectoJob If Not body("Aux") Is Nothing Then - For Each dic In body("Aux") + For Each dic As JToken In body.GetEx("Aux") - Dim auxId As String = UCase(Trim(dic("ID").ToString)) + Dim auxId As String = UCase(Trim(dic.GetEx(Of String)("ID"))) If AuxPaths.ContainsKey(auxId) Then WorkerMsg(MessageType.Err, "Multiple definitions of the same auxiliary type (" & auxId & ")!", msgSrc) @@ -218,27 +221,27 @@ Public Class VectoJob Dim auxEntry = New AuxEntry - auxEntry.Type = dic("Type") - auxEntry.Path.Init(_myPath, dic("Path")) + auxEntry.Type = dic.GetEx(Of String)("Type") + auxEntry.Path.Init(_myPath, dic.GetEx(Of String)("Path")) If Not dic("Technology") Is Nothing Then If fileVersion = 2 Then - auxEntry.TechStr = dic("Technology") + auxEntry.TechnologyList.Add(dic.GetEx(Of String)("Technology")) End If If fileVersion = 3 Then - auxEntry.TechStr = dic("Technology").FirstOrDefault() + auxEntry.TechnologyList = dic.GetEx("Technology").ToObject(Of List(Of String))() '.FirstOrDefault() End If End If - If (auxId = sKey.AUX.HVAC) Then - If Not String.IsNullOrWhiteSpace(auxEntry.TechStr) Then - auxEntry.TechStr = "" + If (auxId = Constants.AuxiliaryKey.HVAC) Then + If auxEntry.TechnologyList.Count > 0 Then ' Not String.IsNullOrWhiteSpace(auxEntry.TechStr) Then + auxEntry.TechnologyList.Clear() WorkerMsg(MessageType.Normal, "Aux: Automatically Upgraded HVAC to new format.", msgSrc) End If End If - If auxId = sKey.AUX.ElecSys Then - If auxEntry.TechStr = "Custom Technology List" OrElse String.IsNullOrWhiteSpace(auxEntry.TechStr) Then + If auxId = Constants.AuxiliaryKey.ElecSys Then + If auxEntry.TechnologyList.Contains("Custom Technology List") OrElse auxEntry.TechnologyList.Count > 0 Then Dim hasTech = False If Not dic("TechList") Is Nothing Then @@ -247,41 +250,45 @@ Public Class VectoJob Next End If + auxEntry.TechnologyList.Clear() If Not hasTech Then - auxEntry.TechStr = "Standard technology" + auxEntry.TechnologyList.Add("Standard technology") Else - auxEntry.TechStr = "Standard technology - LED headlights, all" + auxEntry.TechnologyList.Add("Standard technology - LED headlights, all") End If WorkerMsg(MessageType.Normal, - "Aux: Automatically Upgraded Electric System to new format: '" + auxEntry.TechStr + "'", + "Aux: Automatically Upgraded Electric System to new format: '" + auxEntry.TechnologyList.FirstOrDefault() + "'", msgSrc) End If End If - If auxId = sKey.AUX.SteerPump Then - Select Case auxEntry.TechStr - Case "Variable displacement" - WorkerMsg(MessageType.Warn, "Aux: Steering Pump Technology not automatically convertible. Please set new value.", - msgSrc) - Case "Hydraulic supported by electric" - WorkerMsg(MessageType.Warn, "Aux: Steering Pump Technology not automatically convertible. Please set new value.", - msgSrc) - End Select + If auxId = Constants.AuxiliaryKey.SteerPump Then + If _ + auxEntry.TechnologyList.Contains("Variable displacement") OrElse + auxEntry.TechnologyList.Contains("Hydraulic supported by electric") Then + auxEntry.TechnologyList.Clear() + WorkerMsg(MessageType.Warn, "Aux: Steering Pump Technology not automatically convertible. Please set new value.", + msgSrc) + End If End If - If auxId = sKey.AUX.Fan Then - Select Case auxEntry.TechStr - Case "Crankshaft mounted - Electronically controlled visco clutch (Default)" - auxEntry.TechStr = "Crankshaft mounted - Electronically controlled visco clutch" - Case "Crankshaft mounted - On/Off clutch" - auxEntry.TechStr = "Crankshaft mounted - On/off clutch" - Case "Belt driven or driven via transm. - On/Off clutch" - auxEntry.TechStr = "Belt driven or driven via transm. - On/off clutch" - End Select + If auxId = Constants.AuxiliaryKey.Fan Then + If auxEntry.TechnologyList.Contains("Crankshaft mounted - Electronically controlled visco clutch (Default)") Then + auxEntry.TechnologyList.Clear() + auxEntry.TechnologyList.Add("Crankshaft mounted - Electronically controlled visco clutch") + End If + If auxEntry.TechnologyList.Contains("Crankshaft mounted - On/Off clutch") Then + auxEntry.TechnologyList.Clear() + auxEntry.TechnologyList.Add("Crankshaft mounted - On/off clutch") + End If + If auxEntry.TechnologyList.Contains("Belt driven or driven via transm. - On/Off clutch") Then + auxEntry.TechnologyList.Clear() + auxEntry.TechnologyList.Add("Belt driven or driven via transm. - On/off clutch") + End If End If - If fileVersion = 2 AndAlso auxId = sKey.AUX.PneumSys Then - auxEntry.TechStr = "" + If fileVersion = 2 AndAlso auxId = Constants.AuxiliaryKey.PneumSys Then + auxEntry.TechnologyList.Clear() WorkerMsg(MessageType.Warn, "Aux: Pneumatic System must be updated. Please set new value.", msgSrc) End If @@ -292,29 +299,31 @@ Public Class VectoJob End If If Not body("VACC") Is Nothing Then - _driverAccelerationFile.Init(_myPath, body("VACC")) + _driverAccelerationFile.Init(_myPath, body.GetEx(Of String)("VACC")) End If - EngineOnly = body("EngineOnlyMode") + EngineOnly = body.GetEx(Of Boolean)("EngineOnlyMode") If Not body("StartStop") Is Nothing Then - Dim dic = body("StartStop") - _startStop = dic("Enabled") - _startStopMaxSpeed = dic("MaxSpeed") - _startStopMinTime = dic("MinTime") - StartStopDelay = dic("Delay") + Dim startStop As JToken = body.GetEx("StartStop") + _startStop = startStop.GetEx(Of Boolean)("Enabled") + _startStopMaxSpeed = startStop.GetEx(Of Double)("MaxSpeed") + _startStopMinTime = startStop.GetEx(Of Double)("MinTime") + StartStopDelay = startStop.GetEx(Of Double)("Delay") Else _startStop = False End If If Not body("LAC") Is Nothing Then - Dim dic = body("LAC") - LookAheadOn = dic("Enabled") - LacPreviewFactor = If(dic("PreviewDistanceFactor") Is Nothing, 10, dic("PreviewDistanceFactor")) - LacDfOffset = If(dic("DF_offset") Is Nothing, 2.5, dic("DF_offset")) - LacDfScale = If(dic("DF_scaling") Is Nothing, 1.5, dic("DF_scaling")) - LacDfTargetSpeedFile = If(Not dic("DF_targetSpeedLookup") Is Nothing, dic("DF_targetSpeedLookup"), "") - LacDfVelocityDropFile = If(Not dic("Df_velocityDropLookup") Is Nothing, dic("Df_velocityDropLookup"), "") + Dim lac = body.GetEx("LAC") + LookAheadOn = lac.GetEx(Of Boolean)("Enabled") + LacPreviewFactor = If(lac("PreviewDistanceFactor") Is Nothing, 10, lac.GetEx(Of Double)("PreviewDistanceFactor")) + LacDfOffset = If(lac("DF_offset") Is Nothing, 2.5, lac.GetEx(Of Double)("DF_offset")) + LacDfScale = If(lac("DF_scaling") Is Nothing, 1.5, lac.GetEx(Of Double)("DF_scaling")) + LacDfTargetSpeedFile = + If(Not lac("DF_targetSpeedLookup") Is Nothing, lac.GetEx(Of String)("DF_targetSpeedLookup"), "") + LacDfVelocityDropFile = + If(Not lac("Df_velocityDropLookup") Is Nothing, lac.GetEx(Of String)("Df_velocityDropLookup"), "") Else LookAheadOn = False End If @@ -341,9 +350,9 @@ Public Class VectoJob Return False End Select - VMin = dic("MinSpeed") - OverSpeed = dic("OverSpeed") - If Not dic("UnderSpeed") Is Nothing Then UnderSpeed = dic("UnderSpeed") + VMin = dic.GetEx(Of Double)("MinSpeed") + OverSpeed = dic.GetEx(Of Double)("OverSpeed") + If Not dic("UnderSpeed") Is Nothing Then UnderSpeed = dic.GetEx(Of Double)("UnderSpeed") Else OverSpeedOn = False @@ -462,20 +471,20 @@ Public Class VectoJob End Set End Property - Public Property StStV As Single + Public Property StStV As Double Get Return _startStopMaxSpeed End Get - Set(value As Single) + Set(value As Double) _startStopMaxSpeed = value End Set End Property - Public Property StStT As Single + Public Property StStT As Double Get Return _startStopMinTime End Get - Set(value As Single) + Set(value As Double) _startStopMinTime = value End Set End Property @@ -493,9 +502,9 @@ Public Class VectoJob End Set End Property - Public Property LacPreviewFactor As Single - Public Property LacDfOffset As Single - Public Property LacDfScale As Single + Public Property LacPreviewFactor As Double + Public Property LacDfOffset As Double + Public Property LacDfScale As Double Public Property LacDfTargetSpeedFile As String Public Property LacDfVelocityDropFile As String diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb index e8eccb79de..4d68c985ff 100644 --- a/VECTO/Input Files/Vehicle.vb +++ b/VECTO/Input Files/Vehicle.vb @@ -13,57 +13,59 @@ Option Infer On Imports System.Collections.Generic Imports System.IO Imports System.Linq +Imports Newtonsoft.Json.Linq Imports TUGraz.VECTO.Input_Files Imports TUGraz.VectoCommon.Models Imports TUGraz.VectoCommon.Utils +Imports TUGraz.VectoCore.InputData.FileIO.JSON Imports TUGraz.VectoCore.Models.Declaration Public Class Vehicle 'V2 MassMax is now saved in [t] instead of [kg] Private Const FormatVersion As Short = 7 - Private _fileVersion As Short + Private _fileVersion As Integer Private _filePath As String Private _path As String - Public Mass As Single - Public Loading As Single + Public Mass As Double + Public Loading As Double - Public CdA0 As Single + Public CdA0 As Double Public CrossWindCorrectionMode As CrossWindCorrectionMode Public ReadOnly CrossWindCorrectionFile As SubPath Public RetarderType As RetarderType - Public RetarderRatio As Single = 0 + Public RetarderRatio As Double = 0 Public ReadOnly RetarderLossMapFile As SubPath - Public DynamicTyreRadius As Single + Public DynamicTyreRadius As Double Public ReadOnly Axles As List(Of Axle) Public VehicleCategory As VehicleCategory - Public MassExtra As Single - Public MassMax As Single + Public MassExtra As Double + Public MassMax As Double Public AxleConfiguration As AxleConfiguration Public SavedInDeclMode As Boolean Public AngularGearType As AngularGearType - Public AngularGearRatio As Single + Public AngularGearRatio As Double Public ReadOnly AngularGearLossMapFile As SubPath Public PTOType As String - Public PTOLossMap As SubPath - Public PTOCycle As SubPath + Public ReadOnly PTOLossMap As SubPath + Public ReadOnly PTOCycle As SubPath Public Class Axle - Public RRC As Single - Public Share As Single + Public RRC As Double + Public Share As Double Public TwinTire As Boolean - Public FzISO As Single + Public FzISO As Double Public Wheels As String - Public Inertia As Single + Public Inertia As Double End Class @@ -122,51 +124,52 @@ Public Class Vehicle If Not json.ReadFile(_filePath) Then Return False Try - Dim header = json.Content("Header") - Dim body = json.Content("Body") + Dim header As jtoken = json.Content.GetEx("Header") + Dim body As JToken = json.Content.GetEx("Body") - _fileVersion = header("FileVersion") + _fileVersion = header.GetEx(Of Integer)("FileVersion") If _fileVersion > 4 Then - SavedInDeclMode = body("SavedInDeclMode") + SavedInDeclMode = body.GetEx(Of Boolean)("SavedInDeclMode") Else SavedInDeclMode = Cfg.DeclMode End If - Mass = body("CurbWeight") - MassExtra = body("CurbWeightExtra") - Loading = body("Loading") + Mass = body.GetEx(Of Double)("CurbWeight") + MassExtra = body.GetEx(Of Double)("CurbWeightExtra") + Loading = body.GetEx(Of Double)("Loading") VehicleCategory = body("VehCat").ToString.ParseEnum(Of VehicleCategory)() 'ConvVehCat(body("VehCat").ToString) AxleConfiguration = AxleConfigurationHelper.Parse(body("AxleConfig")("Type").ToString) If _fileVersion < 2 Then 'convert kg to ton MassMax /= 1000 Else - MassMax = body("MassMax") + MassMax = body.GetEx(Of Double)("MassMax") End If If _fileVersion < 7 Then 'calc CdA from Cd and area value - CdA0 = CSng(body("Cd")) * CSng(body("CrossSecArea")) + CdA0 = (body.GetEx(Of Double)("Cd")) * (body.GetEx(Of Double)("CrossSecArea")) Else - CdA0 = body("CdA") + CdA0 = body.GetEx(Of Double)("CdA") End If 'CdA02 = CdA0 CrossWindCorrectionMode = CrossWindCorrectionModeHelper.Parse(body("CdCorrMode").ToString) If Not body("CdCorrFile") Is Nothing Then - CrossWindCorrectionFile.Init(_path, body("CdCorrFile")) + CrossWindCorrectionFile.Init(_path, body.GetEx(Of String)("CdCorrFile")) End If If body("Retarder") Is Nothing Then RetarderType = RetarderType.None Else RetarderType = RetarderTypeHelper.Parse(body("Retarder")("Type").ToString) - If Not body("Retarder")("Ratio") Is Nothing Then - RetarderRatio = body("Retarder")("Ratio") + Dim retarder As JToken = body.GetEx("Retarder") + If Not retarder("Ratio") Is Nothing Then + RetarderRatio = retarder.GetEx(Of Double)("Ratio") End If - If Not body("Retarder")("File") Is Nothing Then - RetarderLossMapFile.Init(_path, body("Retarder")("File")) + If Not retarder("File") Is Nothing Then + RetarderLossMapFile.Init(_path, retarder.GetEx(Of String)("File")) End If End If @@ -174,62 +177,67 @@ Public Class Vehicle AngularGearType = AngularGearType.None Else AngularGearType = body("AngularGear")("Type").ToString.ParseEnum(Of AngularGearType)() - If Not body("AngularGear")("Ratio") Is Nothing Then - AngularGearRatio = body("AngularGear")("Ratio") + Dim angleDrive As JToken = body("AngularGear") + If Not angleDrive("Ratio") Is Nothing Then + AngularGearRatio = angleDrive.GetEx(Of Double)("Ratio") End If If Not body("AngularGear")("LossMap") Is Nothing Then - AngularGearLossMapFile.Init(_path, body("AngularGear")("LossMap")) + AngularGearLossMapFile.Init(_path, angleDrive.GetEx(Of String)("LossMap")) End If End If - Dim inertiaTemp As Single + Dim inertiaTemp As Double If _fileVersion < 3 Then - inertiaTemp = body("WheelsInertia") - DynamicTyreRadius = 1000 * body("WheelsDiaEff") / 2 + inertiaTemp = body.GetEx(Of Double)("WheelsInertia") + DynamicTyreRadius = 1000 * body.GetEx(Of Double)("WheelsDiaEff") / 2 Else - DynamicTyreRadius = body("rdyn") + DynamicTyreRadius = body.GetEx(Of Double)("rdyn") End If - Dim axleCount = body("AxleConfig")("Axles").Count() - For Each axleEntry In body("AxleConfig")("Axles") + Dim axleCount As Integer = body("AxleConfig")("Axles").Count() + For Each axleEntry In body.GetEx("AxleConfig").GetEx("Axles") Dim axle = New Axle With { - .Share = CSng(axleEntry("AxleWeightShare")), - .TwinTire = CBool(axleEntry("TwinTyres")), - .RRC = CSng(axleEntry("RRCISO")), - .FzISO = CSng(axleEntry("FzISO"))} + .Share = (axleEntry.GetEx(Of Double)("AxleWeightShare")), + .TwinTire = (axleEntry.GetEx(Of Boolean)("TwinTyres")), + .RRC = (axleEntry.GetEx(Of Double)("RRCISO")), + .FzISO = (axleEntry.GetEx(Of Double)("FzISO"))} If _fileVersion < 3 Then axle.Wheels = "-" - axle.Inertia = inertiaTemp / (IIf(axle.TwinTire, 4, 2) * axleCount) + Dim numWheels As Integer = 2 + If axle.TwinTire Then numWheels = 4 + axle.Inertia = inertiaTemp / (numWheels * axleCount) Else - axle.Wheels = CStr(axleEntry("Wheels")).Replace("R ", "R") - axle.Inertia = CSng(axleEntry("Inertia")) + axle.Wheels = (axleEntry.GetEx(Of String)("Wheels")).Replace("R ", "R") + axle.Inertia = (axleEntry.GetEx(Of Double)("Inertia")) End If Axles.Add(axle) Next PTOType = PTOTransmission.NoPTO If Not body("PTO") Is Nothing Then - Dim ptoStr = body("PTO")("Type") + Dim ptoTypeToken = body.GetEx("PTO")("Type") - If String.IsNullOrWhiteSpace(ptoStr) Then + If String.IsNullOrWhiteSpace(ptoTypeToken.Value(Of String)) Then PTOType = PTOTransmission.NoPTO - WorkerMsg(MessageType.Normal, "PTO automatically updated to '" + PTOType + "'", msgSrc) + WorkerMsg(MessageType.Normal, "PTO automatically updated to '" + ptoTypeToken.Value(Of String)() + "'", msgSrc) Else Try - DeclarationData.PTOTransmission.Lookup(ptoStr) - PTOType = ptoStr + DeclarationData.PTOTransmission.Lookup(ptoTypeToken.Value(Of String)) + PTOType = ptoTypeToken.Value(Of String)() Catch ex As Exception + WorkerMsg(MessageType.Normal, + "PTO '" + ptoTypeToken.Value(Of String)() + "' not found, automatically updated to '" + PTOTransmission.NoPTO + + "'", msgSrc) PTOType = PTOTransmission.NoPTO - WorkerMsg(MessageType.Normal, "PTO '" + ptoStr + "' not found, automatically updated to '" + PTOType + "'", msgSrc) End Try End If End If If Not PTOType.Equals(PTOTransmission.NoPTO) Then - PTOLossMap.Init(_path, body("PTO")("LossMap")) - PTOCycle.Init(_path, body("PTO")("Cycle")) + PTOLossMap.Init(_path, body.GetEx("PTO").GetEx(Of String)("LossMap")) + PTOCycle.Init(_path, body.GetEx("PTO").GetEx(Of String)("Cycle")) End If Catch ex As Exception @@ -245,11 +253,11 @@ Public Class Vehicle 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}}) + json.Content.Add("Header", JToken.FromObject(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) @@ -287,7 +295,7 @@ Public Class Vehicle {"FzISO", axle.FzISO}})}}} } - json.Content.Add("Body", dic) + json.Content.Add("Body", JToken.FromObject(dic)) Return json.WriteFile(_filePath) End Function diff --git a/VECTO/JSONparser.vb b/VECTO/JSONparser.vb index 8a4cbcf797..95689356a2 100644 --- a/VECTO/JSONparser.vb +++ b/VECTO/JSONparser.vb @@ -12,57 +12,68 @@ Imports System.Collections.Generic Imports System.IO Imports Microsoft.VisualBasic.FileIO Imports Newtonsoft.Json +Imports Newtonsoft.Json.Linq ''' <summary> ''' uses JSON.NET http://json.codeplex.com/ ''' </summary> ''' <remarks></remarks> Public Class JSONParser - Public Content As Dictionary(Of String, Object) + Public Content As JObject 'Dictionary(Of String, Object) Public Sub New() - Content = New Dictionary(Of String, Object) + 'Content = New Dictionary(Of String, Object) End Sub + Public Function ReadFile(path As String) As Boolean + If (Not File.Exists(path)) Then + Return False + End If + Using reader As TextReader = File.OpenText(path) + JToken.ReadFrom(New JsonTextReader(reader)) + End Using + Return True + End Function + ''' <summary> ''' Reads a JSON File into the Content variable. ''' </summary> ''' <param name="path"></param> ''' <returns></returns> ''' <remarks></remarks> - Public Function ReadFile(path As String) As Boolean - Dim file As TextFieldParser - Dim str As String + 'Public Function ReadFile(path As String) As Boolean + ' Dim file As TextFieldParser + ' Dim str As String - Content.Clear() + ' Content.Clear() - If Not IO.File.Exists(path) Then - Return False - End If + ' If Not IO.File.Exists(path) Then + ' Return False + ' End If - Try - file = New TextFieldParser(path) - Catch ex As Exception - Return False - End Try + ' Try + ' file = New TextFieldParser(path) + ' Catch ex As Exception + ' Return False + ' End Try - If file.EndOfData Then - file.Close() - Return False - End If + ' If file.EndOfData Then + ' file.Close() + ' Return False + ' End If - str = file.ReadToEnd + ' str = file.ReadToEnd - file.Close() + ' file.Close() - Try - Content = JsonConvert.DeserializeObject(str, Content.GetType) - Catch ex As Exception - Return False - End Try + ' Try + ' Content = JsonConvert.DeserializeObject(str, Content.GetType) + ' Catch ex As Exception + ' Return False + ' End Try - Return True - End Function + ' Return True + 'End Function ''' <summary> ''' Writes the Content variable into a JSON file. diff --git a/VECTO/MainModule.vb b/VECTO/MainModule.vb index 8796e12985..b068a602c4 100644 --- a/VECTO/MainModule.vb +++ b/VECTO/MainModule.vb @@ -20,7 +20,7 @@ Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Engine Module MainModule Public JobFileList As List(Of String) - Public Function ConvertToEngineData(fld As EngineFullLoadCurve, nIdle As Single) As CombustionEngineData + Public Function ConvertToEngineData(fld As EngineFullLoadCurve, nIdle As Double) As CombustionEngineData Dim retVal As CombustionEngineData = New CombustionEngineData() retVal.FullLoadCurve = New TUGraz.VectoCore.Models.SimulationComponent.Data.Engine.EngineFullLoadCurve() @@ -28,16 +28,16 @@ Module MainModule For i As Integer = 0 To fld.EngineSpeedList.Count - 1 retVal.FullLoadCurve.FullLoadEntries.Add( New FullLoadCurve.FullLoadCurveEntry() _ - With {.EngineSpeed = CType(fld.EngineSpeedList(i), Double).RPMtoRad(), - .TorqueFullLoad = CType(fld.MaxTorqueList(i), Double).SI(Of NewtonMeter)(), - .TorqueDrag = CType(fld.DragTorqueList(i), Double).SI(Of NewtonMeter)()}) + With {.EngineSpeed = fld.EngineSpeedList(i).RPMtoRad(), + .TorqueFullLoad = fld.MaxTorqueList(i).SI(Of NewtonMeter)(), + .TorqueDrag = fld.DragTorqueList(i).SI(Of NewtonMeter)()}) Next retVal.IdleSpeed = CType(nIdle, Double).RPMtoRad() Return retVal End Function - Public Function ConvPicPath(hdVclass As String, isLongHaul As Boolean) As Bitmap + Public Function ConvPicPath(hdVclass As Integer, isLongHaul As Boolean) As Bitmap Dim longHaulFlag As String = "" If isLongHaul Then longHaulFlag = "t" @@ -61,5 +61,4 @@ Module MainModule Return My.Resources.Undef ' resourcePath & "Undef.png" End Select End Function - End Module diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj index db7fea4f09..06c726c5d9 100644 --- a/VECTO/VECTO.vbproj +++ b/VECTO/VECTO.vbproj @@ -47,11 +47,13 @@ <DefineTrace>false</DefineTrace> <OutputPath>bin\Debug\</OutputPath> <DocumentationFile>VECTO.xml</DocumentationFile> - <NoWarn>41999,42016,42017,42018,42019,42032,42036</NoWarn> + <NoWarn> + </NoWarn> <Prefer32Bit>false</Prefer32Bit> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <WarningLevel>1</WarningLevel> <UseVSHostingProcess>true</UseVSHostingProcess> + <WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>None</DebugType> @@ -60,11 +62,13 @@ <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DocumentationFile>VECTO.xml</DocumentationFile> - <NoWarn>41999,42016,42017,42018,42019,42032,42036</NoWarn> + <NoWarn> + </NoWarn> <RemoveIntegerChecks>false</RemoveIntegerChecks> <PlatformTarget>AnyCPU</PlatformTarget> <Prefer32Bit>false</Prefer32Bit> <WarningLevel>1</WarningLevel> + <WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors> </PropertyGroup> <PropertyGroup> <ApplicationManifest>My Project\app.manifest</ApplicationManifest> @@ -75,7 +79,8 @@ <DefineTrace>true</DefineTrace> <OutputPath>bin\x86\Debug\</OutputPath> <DocumentationFile>VECTO.xml</DocumentationFile> - <NoWarn>41999,42016,42017,42018,42019,42032,42036</NoWarn> + <NoWarn> + </NoWarn> <DebugType>full</DebugType> <PlatformTarget>x86</PlatformTarget> <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets> @@ -83,12 +88,14 @@ <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> <Prefer32Bit>false</Prefer32Bit> <WarningLevel>1</WarningLevel> + <WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> <DefineTrace>true</DefineTrace> <OutputPath>bin\x86\Release\</OutputPath> <DocumentationFile>VECTO.xml</DocumentationFile> - <NoWarn>41999,42016,42017,42018,42019,42032,42036</NoWarn> + <NoWarn> + </NoWarn> <DebugType>None</DebugType> <PlatformTarget>x86</PlatformTarget> <CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets> @@ -96,6 +103,7 @@ <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules> <Prefer32Bit>false</Prefer32Bit> <WarningLevel>1</WarningLevel> + <WarningsAsErrors>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036</WarningsAsErrors> </PropertyGroup> <PropertyGroup> <ManifestCertificateThumbprint>B392FDC8053AEBCC6B0860DD32DEC702EB46BD4A</ManifestCertificateThumbprint> @@ -115,6 +123,9 @@ <PropertyGroup> <SignAssembly>false</SignAssembly> </PropertyGroup> + <PropertyGroup> + <OptionStrict>On</OptionStrict> + </PropertyGroup> <ItemGroup> <Reference Include="itextsharp, Version=5.5.9.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> diff --git a/VECTO/VECTO_Global.vb b/VECTO/VECTO_Global.vb index 06fd0798aa..9fd843c88b 100644 --- a/VECTO/VECTO_Global.vb +++ b/VECTO/VECTO_Global.vb @@ -30,7 +30,7 @@ Public Module VECTO_Global Public Cfg As Configuration - Public sKey As csKey + 'Public sKey As csKey Public ReadOnly FileFormat As Encoding = Encoding.UTF8 @@ -156,9 +156,9 @@ Public Module VECTO_Global If file = "" Then Return "" 'Replace sKeys - file = Replace(file, sKey.DefVehPath & "\", MyAppPath & "Default Vehicles\", 1, -1, + file = Replace(file, Constants.DefVehPath & "\", MyAppPath & "Default Vehicles\", 1, -1, CompareMethod.Text) - file = Replace(file, sKey.HomePath & "\", MyAppPath, 1, -1, CompareMethod.Text) + file = Replace(file, Constants.HomePath & "\", MyAppPath, 1, -1, CompareMethod.Text) 'Replace - Determine folder If MainDir = "" Then @@ -186,11 +186,11 @@ Public Module VECTO_Global 'Path one-level-up "C:\temp\ordner1\" >> "C:\temp\" Private Function fPathUp(Pfad As String) As String - Dim x As Int16 + Dim x As Integer Pfad = Pfad.Substring(0, Pfad.Length - 1) - x = Pfad.LastIndexOf("\") + x = Pfad.LastIndexOf("\", StringComparison.Ordinal) If x = -1 Then Return "" @@ -200,7 +200,7 @@ Public Module VECTO_Global 'File name without the path "C:\temp\TEST.txt" >> "TEST.txt" oder "TEST" Public Function GetFilenameWithoutPath(file As String, includeFileExtension As Boolean) As String _ 'GetFilenameWithoutPath - Dim x As Int16 + Dim x As Integer x = file.LastIndexOf("\", StringComparison.Ordinal) + 1 file = Right(file, Len(file) - x) If Not includeFileExtension Then @@ -239,7 +239,7 @@ Public Module VECTO_Global 'Extension alone "C:\temp\TEST.txt" >> ".txt" Public Function GetExtension(file As String) As String 'GetExtension - Dim x As Int16 + Dim x As Integer x = file.LastIndexOf(".", StringComparison.Ordinal) If x = -1 Then Return "" @@ -253,26 +253,27 @@ Public Module VECTO_Global End Module -Public Class csKey - Public ReadOnly AUX As csKeyAux +Module Constants + 'Public ReadOnly AUX As AuxiliaryKey - Public HomePath As String = "<HOME>" - Public DefVehPath As String = "<VEHDIR>" - Public NoFile As String = "<NOFILE>" + Public Const HomePath As String = "<HOME>" + Public Const DefVehPath As String = "<VEHDIR>" + Public Const NoFile As String = "<NOFILE>" - Public Sub New() + 'Public Sub New() - AUX = New csKeyAux - End Sub + ' AUX = New AuxiliaryKey + 'End Sub - Public Class csKeyAux - Public Fan As String = "FAN" - Public SteerPump As String = "STP" - Public HVAC As String = "AC" - Public ElecSys As String = "ES" - Public PneumSys As String = "PS" + ' ReSharper disable once ClassNeverInstantiated.Global + Public Class AuxiliaryKey + Public Const Fan As String = "FAN" + Public Const SteerPump As String = "STP" + Public Const HVAC As String = "AC" + Public Const ElecSys As String = "ES" + Public Const PneumSys As String = "PS" End Class -End Class +End Module diff --git a/VECTO/VECTO_Types.vb b/VECTO/VECTO_Types.vb index f3bddb403e..d95e991782 100644 --- a/VECTO/VECTO_Types.vb +++ b/VECTO/VECTO_Types.vb @@ -17,13 +17,13 @@ Imports System.Linq ''' Determines how file extensions are set in the File Browser ''' </summary> ''' <remarks></remarks> -Public Enum tFbExtMode As Integer +Public Enum FileBrowserFileExtensionMode As Integer ForceExt = 0 MultiExt = 1 SingleExt = 2 End Enum -Public Enum tWorkMsgType +Public Enum WorkerMessageType StatusBar StatusListBox ProgBars -- GitLab