diff --git a/VECTO/GUI/IHPCForm.vb b/VECTO/GUI/IHPCForm.vb index 609eccbad3e410866abf42ac921f2ca45d6a0bcc..98b7c26d4840e85da03bdfd5a3bc55b66a6f01a8 100644 --- a/VECTO/GUI/IHPCForm.vb +++ b/VECTO/GUI/IHPCForm.vb @@ -17,13 +17,7 @@ Public Class IHPCForm #Region "Set JSON Data" Public Sub ReadIHPCFile(file As String) - - Dim inputProvider = New JSONComponentInputData(file, Nothing) - Dim ihpcData = inputProvider.ElectricMachines.Entries.First().ElectricMachine - - If IsNothing(ihpcData) Then - Return - End If + Dim ihpcData = JSONInputDataFactory.ReadIHPCEngineeringInputData(file, True) tbModel.Text = ihpcData.Model tbInertia.Text = ihpcData.Inertia.ToGUIFormat() diff --git a/VECTO/GUI/VehicleForm.vb b/VECTO/GUI/VehicleForm.vb index c60562055b9045665b72316dd9a58e28ec4c7d66..90795dab3ad5db4101f9021bfaa607b5797cec0c 100644 --- a/VECTO/GUI/VehicleForm.vb +++ b/VECTO/GUI/VehicleForm.vb @@ -570,9 +570,9 @@ Public Class VehicleForm tcVehicleComponents.TabPages.Remove(tpIEPC) 'IHPC - tcVehicleComponents.TabPages.Remove(tbIHPC) + tcVehicleComponents.TabPages.Remove(tbIHPC) - Case VectoSimulationJobType.ParallelHybridVehicle + Case VectoSimulationJobType.ParallelHybridVehicle lblTitle.Text = "Parallel Hybrid Vehicle" 'Powertrain --------------------------------------------------------------- @@ -597,11 +597,11 @@ Public Class VehicleForm pnEcoRoll.Visible = False cbEcoRoll.SelectedIndex = 0 - 'IEPC - tcVehicleComponents.TabPages.Remove(tpIEPC) + 'IEPC + tcVehicleComponents.TabPages.Remove(tpIEPC) - 'IHPC - tcVehicleComponents.TabPages.Remove(tbIHPC) + 'IHPC + tcVehicleComponents.TabPages.Remove(tbIHPC) Case VectoSimulationJobType.SerialHybridVehicle lblTitle.Text = "Serial Hybrid Vehicle" @@ -629,11 +629,11 @@ Public Class VehicleForm pnEcoRoll.Visible = False cbEcoRoll.SelectedIndex = 0 - 'IEPC - tcVehicleComponents.TabPages.Remove(tpIEPC) + 'IEPC + tcVehicleComponents.TabPages.Remove(tpIEPC) - 'IHPC - tcVehicleComponents.TabPages.Remove(tbIHPC) + 'IHPC + tcVehicleComponents.TabPages.Remove(tbIHPC) Case VectoSimulationJobType.BatteryElectricVehicle lblTitle.Text = "Battery Electric Vehicle" @@ -661,32 +661,30 @@ Public Class VehicleForm pnEcoRoll.Visible = False cbEcoRoll.SelectedIndex = 0 - 'IEPC - tcVehicleComponents.TabPages.Remove(tpIEPC) + 'IEPC + tcVehicleComponents.TabPages.Remove(tpIEPC) - 'IHPC - tcVehicleComponents.TabPages.Remove(tbIHPC) + 'IHPC + tcVehicleComponents.TabPages.Remove(tbIHPC) Case VectoSimulationJobType.IEPC_E lblTitle.Text = "IEPC-E Vehicle" - tcVehicleComponents.TabPages.Remove(tpElectricMachine) - tcVehicleComponents.TabPages.Remove(tpGensetComponents) + tcVehicleComponents.TabPages.Remove(tpElectricMachine) + tcVehicleComponents.TabPages.Remove(tpGensetComponents) tcVehicleComponents.TabPages.Remove(tbIHPC) - Case VectoSimulationJobType.IEPC_S - lblTitle.Text = "IEPC-S Vehicle" + Case VectoSimulationJobType.IEPC_S + lblTitle.Text = "IEPC-S Vehicle" tcVehicleComponents.TabPages.Remove(tpElectricMachine) - tcVehicleComponents.TabPages.Remove(tbIHPC) + tcVehicleComponents.TabPages.Remove(tbIHPC) - Case VectoSimulationJobType.IHPC - lblTitle.Text = "IHPC Vehicle" - - tcVehicleComponents.TabPages.Remove(tpElectricMachine) - tcVehicleComponents.TabPages.Remove(tpGensetComponents) + Case VectoSimulationJobType.IHPC + lblTitle.Text = "IHPC Vehicle" - 'IEPC - tcVehicleComponents.TabPages.Remove(tpIEPC) + tcVehicleComponents.TabPages.Remove(tpElectricMachine) + tcVehicleComponents.TabPages.Remove(tpGensetComponents) + tcVehicleComponents.TabPages.Remove(tpIEPC) Case Else If Not tcVehicleComponents.TabPages.Contains(tpElectricMachine) Then @@ -1538,9 +1536,17 @@ Public Class VehicleForm Dim f = FileRepl(tbIEPCFilePath.Text, GetPath(_vehFile)) IEPCForm.JobDir = GetPath(_vehFile) - If Not IEPCForm.Visible Then + + If Not Trim(f) = "" Then + If Not File.Exists(f) Then + MsgBox("File not found!") + Exit Sub + End If + End If + + If Not IEPCForm.Visible Then IEPCForm.NewIEPC() - IEPCForm.Show() + IEPCForm.Show() Else If IEPCForm.WindowState = FormWindowState.Minimized Then IEPCForm.WindowState = FormWindowState.Normal IEPCForm.BringToFront() @@ -1556,29 +1562,36 @@ Public Class VehicleForm End Sub Private Sub btIHPCFile_Click(sender As Object, e As EventArgs) Handles btIHPCFile.Click - If IHPCFileBrowser.OpenDialog(FileRepl(tbIHPCFilePath.Text, GetPath(_vehFile))) Then - tbIHPCFilePath.Text = GetFilenameWithoutDirectory(IHPCFileBrowser.Files(0), GetPath(_vehFile)) - End If - End Sub + If IHPCFileBrowser.OpenDialog(FileRepl(tbIHPCFilePath.Text, GetPath(_vehFile))) Then + tbIHPCFilePath.Text = GetFilenameWithoutDirectory(IHPCFileBrowser.Files(0), GetPath(_vehFile)) + End If + End Sub - Private Sub btIHPC_Click(sender As Object, e As EventArgs) Handles btIHPC.Click + Private Sub btIHPC_Click(sender As Object, e As EventArgs) Handles btIHPC.Click Dim f = FileRepl(tbIHPCFilePath.Text, GetPath(_vehFile)) IHPCForm.JobDir = GetPath(_vehFile) - If Not IHPCForm.Visible Then - IHPCForm.ClearIHPC() - IHPCForm.Show() - Else - If IHPCForm.WindowState = FormWindowState.Minimized Then IHPCForm.WindowState = FormWindowState.Normal - IHPCForm.BringToFront() - End If - - If Not Trim(f) = "" Then - Try - IHPCForm.ReadIHPCFile(f) - Catch ex As Exception - MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading IHPC File") - End Try - End If - End Sub + If Not Trim(f) = "" Then + If Not File.Exists(f) Then + MsgBox("File not found!") + Exit Sub + End If + End If + + If Not IHPCForm.Visible Then + IHPCForm.ClearIHPC() + IHPCForm.Show() + Else + If IHPCForm.WindowState = FormWindowState.Minimized Then IHPCForm.WindowState = FormWindowState.Normal + IHPCForm.BringToFront() + End If + + If Not Trim(f) = "" Then + Try + IHPCForm.ReadIHPCFile(f) + Catch ex As Exception + MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading IHPC File") + End Try + End If + End Sub End Class \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index 83816ced3a487e074ae8ba31cd7c65d3641fdc8e..950eb28af3d32daa64c3e718325d869e968974de 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -258,5 +258,19 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON throw new VectoException("Engineering IEPC: Unsupported FileVersion. Got {0}", version); } } + + public static IElectricMotorEngineeringInputData ReadIHPCEngineeringInputData(string filename, + bool tolerateMissing = false) + { + var json = ReadFile(filename); + var version = ReadVersion(json); + switch (version) + { + case 5: + return ReadElectricMotorData(filename, tolerateMissing); + default: + throw new VectoException("Engineering IHPC: Unsupported FileVersion. Got {0}", version); + } + } } }