diff --git a/VECTO/GUI/IEPCForm.vb b/VECTO/GUI/IEPCForm.vb index 80d298c251fb4ada08bc74259a82813d8f17d718..0199933db9b52c096e0b7fb0a8b94648127f8ff5 100644 --- a/VECTO/GUI/IEPCForm.vb +++ b/VECTO/GUI/IEPCForm.vb @@ -390,11 +390,11 @@ Public Class IEPCForm iepc.SetDragCurveEntries(lvDragCurve) - 'If Not iepc.SaveFile(file) Then - ' MsgBox("Cannot save to " & file, MsgBoxStyle.Critical) - ' Return False - 'End If - + If Not iepc.SaveFile(file) Then + MsgBox("Cannot save to " & file, MsgBoxStyle.Critical) + Return False + End If + _changed = False LbStatus.Text = "" diff --git a/VECTO/Input Files/IEPCInputData.vb b/VECTO/Input Files/IEPCInputData.vb index 5eb2cebe272657aa2aa50dba1912916223a3e6b3..0b48b59bb934eb14d12a35e1b8654fa3720d5eb8 100644 --- a/VECTO/Input Files/IEPCInputData.vb +++ b/VECTO/Input Files/IEPCInputData.vb @@ -29,13 +29,13 @@ Public Class IEPCInputData Public Function SaveFile(filePath As String) As Boolean _filePath = filePath - 'Try - ' Dim writer = New JSONFileWriter() - ' writer.SaveIEPC(Me, filePath, Cfg.DeclMode) - 'Catch ex As Exception - ' MsgBox("Failed to write IEPC file: " + ex.Message) - ' Return False - 'End Try + Try + Dim writer = New JSONFileWriter() + writer.SaveIEPC(Me, filePath, Cfg.DeclMode) + Catch ex As Exception + MsgBox("Failed to write IEPC file: " + ex.Message) + Return False + End Try Return True End Function diff --git a/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs b/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs index d3d1e1f2871e74d26b87b45f9eba681b29515ed4..118fdc8d35ecc40b72f4a7eb13bffbb9757d0566 100644 --- a/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs +++ b/VectoCore/VectoCore/OutputData/FileIO/JSONFileWriter.cs @@ -38,6 +38,8 @@ public class JSONFileWriter : IOutputFileWriter private const int ElectricMotorFormatVersion = 5; + + private const int IEPCFormatVersion = 1; private const int REESSFormatVersion = 1; @@ -101,6 +103,69 @@ public class JSONFileWriter : IOutputFileWriter WriteFile(header, body, filename); } + public void SaveIEPC(IIEPCEngineeringInputData iepc, string filename, bool declMode) + { + var header = GetHeader(IEPCFormatVersion); + + var body = new Dictionary<string, object> + { + {JsonKeys.SavedInDeclMode, declMode}, + {JsonKeys.Component_Model, iepc.Model}, + {JsonKeys.IEPC_Inertia, iepc.Inertia.Value()}, + {JsonKeys.IEPC_DifferentialIncluded, iepc.DifferentialIncluded}, + {JsonKeys.IEPC_DesignTypeWheelMotor, iepc.DesignTypeWheelMotor}, + {JsonKeys.IEPC_NrOfDesignTypeWheelMotorMeasured, iepc.NrOfDesignTypeWheelMotorMeasured}, + {JsonKeys.IEPC_ThermalOverloadRecoveryFactor, iepc.OverloadRecoveryFactor} + }; + + var gears = new List<Dictionary<string, object>>(); + + foreach (var gear in iepc.Gears) { + var currentGear = new Dictionary<string, object> { + { JsonKeys.Gearbox_Gear_Ratio, gear.Ratio } + }; + if(gear.MaxOutputShaftSpeed != null) + currentGear.Add(JsonKeys.Gearbox_Gear_MaxOutShaftTorque, gear.MaxOutputShaftTorque.Value()); + if(gear.MaxOutputShaftSpeed != null) + currentGear.Add(JsonKeys.Gearbox_Gear_MaxOutShaftSpeed, gear.MaxOutputShaftSpeed.Value()); + gears.Add(currentGear); + } + + var voltageLevels = new List<Dictionary<string, object>>(); + foreach (var voltageLevel in iepc.VoltageLevels) { + var currentLevel = new Dictionary<string, object> + { + {JsonKeys.IEPC_Voltage, voltageLevel.VoltageLevel.Value()}, + {JsonKeys.IEPC_ContinuousTorque, voltageLevel.ContinuousTorque.Value()}, + {JsonKeys.IEPC_ContinuousTorqueSpeed, Convert.ToDouble(voltageLevel.ContinuousTorqueSpeed.AsRPM.ToString())}, + {JsonKeys.IEPC_OverloadTorque, voltageLevel.OverloadTorque.Value()}, + {JsonKeys.IEPC_OverloadTorqueSpeed,Convert.ToDouble(voltageLevel.OverloadTestSpeed.AsRPM.ToString())}, + {JsonKeys.IEPC_OverloadTime, voltageLevel.OverloadTime.Value()}, + {JsonKeys.IEPC_FullLoadCurve, GetRelativePath(voltageLevel.FullLoadCurve.Source, Path.GetDirectoryName(filename))}, + + }; + var powerMaps = new Dictionary<string, object>(); + foreach (var pMap in voltageLevel.PowerMap) + { + powerMaps.Add(pMap.Gear.ToString(), GetRelativePath(pMap.PowerMap.Source, Path.GetDirectoryName(filename))); + } + currentLevel.Add(JsonKeys.IEPC_PowerMaps, powerMaps); //PowerMap + voltageLevels.Add(currentLevel); + } + + var dragCurves = new Dictionary<string, object>(); + foreach (var dragCurveEntry in iepc.DragCurves) { + dragCurves.Add(dragCurveEntry.Gear.ToString(), + GetRelativePath(dragCurveEntry.DragCurve.Source, Path.GetDirectoryName(filename))); + } + + body.Add(JsonKeys.Gearbox_Gears, gears); + body.Add(JsonKeys.IEPC_VoltageLevels, voltageLevels); + body.Add(JsonKeys.IEPC_DragCurves, dragCurves); + + WriteFile(header, body, filename); + } + public void SaveBattery(IBatteryPackEngineeringInputData battery, string filename, bool declMode) { var header = GetHeader(REESSFormatVersion);