diff --git a/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index fbec2083e3b67768d6fcb6c2ae5b330331ebfd9f..fe36741ec061ce919f8b2cd796d2e741974e461d 100644 --- a/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -173,8 +173,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON /// } /// } /// </code> - public class JSONInputDataV2 : JSONFile, IEngineeringInputDataProvider, IEngineeringJobInputData, IDriverInputData, - IAuxiliariesEngineeringInputData + public class JSONInputDataV2 : JSONFile, IEngineeringInputDataProvider, IDeclarationInputDataProvider, + IEngineeringJobInputData, IDriverEngineeringInputData, IAuxiliariesEngineeringInputData { protected IGearboxEngineeringInputData Gearbox; @@ -304,6 +304,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON return this; } + IDriverEngineeringInputData IEngineeringInputDataProvider.DriverInputData + { + get { return this; } + } + IAuxiliariesDeclarationInputData IDeclarationInputDataProvider.AuxiliaryInputData() { return AuxiliaryInputData(); @@ -320,7 +325,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } - public virtual IDriverInputData DriverInputData + public virtual IDriverDeclarationInputData DriverInputData { get { return this; } } @@ -383,7 +388,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON #region DriverInputData - public virtual IStartStopInputData StartStop + public virtual IStartStopEngineeringInputData StartStop { get { @@ -397,6 +402,17 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } + IOverSpeedEcoRollDeclarationInputData IDriverDeclarationInputData.OverSpeedEcoRoll + { + get + { + var overspeed = Body.GetEx(JsonKeys.DriverData_OverspeedEcoRoll); + return new OverSpeedEcoRollInputData() { + Mode = DriverData.ParseDriverMode(overspeed.GetEx<string>(JsonKeys.DriverData_OverspeedEcoRoll_Mode)) + }; + } + } + public virtual ILookaheadCoastingInputData Lookahead { get @@ -410,7 +426,12 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } - public virtual IOverSpeedEcoRollInputData OverSpeedEcoRoll + IStartStopDeclarationInputData IDriverDeclarationInputData.StartStop + { + get { return StartStop; } + } + + public virtual IOverSpeedEcoRollEngineeringInputData OverSpeedEcoRoll { get { diff --git a/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index 4084181d9c41f2f52904ebd8c50d2181e91f292f..7769d99591c38ce27dd60baadc426857c69921f0 100644 --- a/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -35,7 +35,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON } } - public static IEngineeringInputDataProvider ReadJsonJob(string filename) + public static IInputDataProvider ReadJsonJob(string filename) { var json = ReadFile(filename); var version = ReadVersion(json); diff --git a/VectoCore/InputData/IInputDataProvider.cs b/VectoCore/InputData/IInputDataProvider.cs index 788082e59d95c173da848ad50c53e51e3ad0596a..aa0ce19f2602232cb46c1883d61bad4f940a8e7f 100644 --- a/VectoCore/InputData/IInputDataProvider.cs +++ b/VectoCore/InputData/IInputDataProvider.cs @@ -39,26 +39,26 @@ namespace TUGraz.VectoCore.InputData IRetarderInputData RetarderInputData { get; } - IDriverInputData DriverInputData { get; } + IDriverDeclarationInputData DriverInputData { get; } } - public interface IEngineeringInputDataProvider : IDeclarationInputDataProvider + public interface IEngineeringInputDataProvider : IInputDataProvider { - new IEngineeringJobInputData JobInputData(); + IEngineeringJobInputData JobInputData(); - new IVehicleEngineeringInputData VehicleInputData { get; } + IVehicleEngineeringInputData VehicleInputData { get; } - new IGearboxEngineeringInputData GearboxInputData { get; } + IGearboxEngineeringInputData GearboxInputData { get; } - //IAxleGearInputData AxleGearInputData { get; } + IAxleGearInputData AxleGearInputData { get; } - new IEngineEngineeringInputData EngineInputData { get; } + IEngineEngineeringInputData EngineInputData { get; } - new IAuxiliariesEngineeringInputData AuxiliaryInputData(); + IAuxiliariesEngineeringInputData AuxiliaryInputData(); - //IRetarderInputData RetarderInputData { get; } + IRetarderInputData RetarderInputData { get; } - //IDriverInputData DriverInputData { get; } + IDriverEngineeringInputData DriverInputData { get; } } } \ No newline at end of file diff --git a/VectoCore/InputData/Impl/InputData.cs b/VectoCore/InputData/Impl/InputData.cs index 7ed9cee7c4dcb3218d41375f42b4070a8b336af7..b6c4681ed997a3cd7a13fcbf0f2201fed7431c2d 100644 --- a/VectoCore/InputData/Impl/InputData.cs +++ b/VectoCore/InputData/Impl/InputData.cs @@ -32,7 +32,7 @@ namespace TUGraz.VectoCore.InputData.Impl public DataTable CycleData { get; internal set; } } - public class StartStopInputData : IStartStopInputData + public class StartStopInputData : IStartStopEngineeringInputData { public bool Enabled { get; internal set; } @@ -52,7 +52,7 @@ namespace TUGraz.VectoCore.InputData.Impl public MeterPerSecond MinSpeed { get; internal set; } } - public class OverSpeedEcoRollInputData : IOverSpeedEcoRollInputData + public class OverSpeedEcoRollInputData : IOverSpeedEcoRollEngineeringInputData { public DriverData.DriverMode Mode { get; internal set; } diff --git a/VectoCore/InputData/InputData.cs b/VectoCore/InputData/InputData.cs index dca192a5770eec29067cbb714fdaff26c07c115e..f10c940f0d37a4146f08e041cd9d4067c7c02d5f 100644 --- a/VectoCore/InputData/InputData.cs +++ b/VectoCore/InputData/InputData.cs @@ -472,29 +472,41 @@ namespace TUGraz.VectoCore.InputData DataTable CycleData { get; } } - public interface IDriverInputData + public interface IDriverDeclarationInputData { bool SavedInDeclarationMode { get; } - IStartStopInputData StartStop { get; } - ILookaheadCoastingInputData Lookahead { get; } - IOverSpeedEcoRollInputData OverSpeedEcoRoll { get; } + IStartStopDeclarationInputData StartStop { get; } + + IOverSpeedEcoRollDeclarationInputData OverSpeedEcoRoll { get; } + } + + public interface IDriverEngineeringInputData : IDriverDeclarationInputData + { + new IStartStopEngineeringInputData StartStop { get; } + + new IOverSpeedEcoRollEngineeringInputData OverSpeedEcoRoll { get; } /// <summary> /// P009; P033, P034, P035 /// cf. VECTO Input Parameters.xlsx /// </summary> DataTable AccelerationCurve { get; } + + ILookaheadCoastingInputData Lookahead { get; } } - public interface IOverSpeedEcoRollInputData + public interface IOverSpeedEcoRollDeclarationInputData { /// <summary> /// P015 /// cf. VECTO Input Parameters.xlsx /// </summary> DriverData.DriverMode Mode { get; } + } + public interface IOverSpeedEcoRollEngineeringInputData : IOverSpeedEcoRollDeclarationInputData + { /// <summary> /// P016 /// cf. VECTO Input Parameters.xlsx @@ -535,14 +547,17 @@ namespace TUGraz.VectoCore.InputData MeterPerSecond MinSpeed { get; } } - public interface IStartStopInputData + public interface IStartStopDeclarationInputData { /// <summary> /// P010 StartStop - enabled /// cf. VECTO Input Parameters.xlsx /// </summary> bool Enabled { get; } + } + public interface IStartStopEngineeringInputData : IStartStopDeclarationInputData + { /// <summary> /// P011 StartStop - Max speed /// cf. VECTO Input Parameters.xlsx diff --git a/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs b/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs index af7ce93c2877e6c909d7870887ae2a0529a1f4da..96bf97d7d688a13589a79723355f26011d273f2c 100644 --- a/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs +++ b/VectoCore/InputData/Reader/DataObjectAdaper/DeclarationDataAdapter.cs @@ -33,7 +33,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper { public class DeclarationDataAdapter : AbstractSimulationDataAdapter { - public DriverData CreateDriverData(IDriverInputData data) + public DriverData CreateDriverData(IDriverDeclarationInputData data) { if (!data.SavedInDeclarationMode) { WarnDeclarationMode("DriverData"); diff --git a/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs b/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs index 8fabe6f85d3e013e3402215f6422500f44ce7361..2f52ae3e261462f9e6323df1e21c8a66fc11dc89 100644 --- a/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs +++ b/VectoCore/InputData/Reader/DataObjectAdaper/EngineeringDataAdapter.cs @@ -159,7 +159,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdaper }).Concat(new VectoRunData.AuxData { ID = "", DemandType = AuxiliaryDemandType.Direct }.ToEnumerable()).ToList(); } - internal DriverData CreateDriverData(IDriverInputData driver) + internal DriverData CreateDriverData(IDriverEngineeringInputData driver) { if (driver.SavedInDeclarationMode) { WarnEngineeringMode("DriverData"); diff --git a/VectoCoreTest/FileIO/JsonTest.cs b/VectoCoreTest/FileIO/JsonTest.cs index da9fe1977e0c36f5bdb657caf197d08f29c196f6..9599df293fac020ed42c47a6285720c2d1c84185 100644 --- a/VectoCoreTest/FileIO/JsonTest.cs +++ b/VectoCoreTest/FileIO/JsonTest.cs @@ -77,9 +77,8 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); ((JObject)json["Body"]).Property("Cycles").Remove(); - AssertHelper.Exception<InvalidFileFormatException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).Cycles; - }, "Key Cycles not found"); + AssertHelper.Exception<InvalidFileFormatException>( + () => { var tmp = new JSONInputDataV2(json, TestJobFile).Cycles; }, "Key Cycles not found"); } [TestMethod] @@ -100,7 +99,8 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("VACC").Remove(); AssertHelper.Exception<VectoException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.AccelerationCurve; + IEngineeringInputDataProvider input = new JSONInputDataV2(json, TestJobFile); + var tmp = input.DriverInputData.AccelerationCurve; }, "AccelerationCurve (VACC) required"); } @@ -111,7 +111,8 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); json["Body"]["VACC"] = "Truck"; - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.AccelerationCurve; + IEngineeringInputDataProvider input = new JSONInputDataV2(json, TestJobFile); + var tmp = input.DriverInputData.AccelerationCurve; Assert.IsNotNull(tmp); } @@ -121,9 +122,11 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); ((JObject)json["Body"]).Property("LAC").Remove(); - AssertHelper.Exception<VectoException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.Lookahead; - }, "Key LAC not found"); + AssertHelper.Exception<VectoException>( + () => { + IEngineeringInputDataProvider input = new JSONInputDataV2(json, TestJobFile); + var tmp = input.DriverInputData.Lookahead; + }, "Key LAC not found"); } [TestMethod] @@ -132,9 +135,9 @@ namespace TUGraz.VectoCore.Tests.FileIO var json = (JObject)JToken.ReadFrom(new JsonTextReader(File.OpenText(TestJobFile))); ((JObject)json["Body"]).Property("OverSpeedEcoRoll").Remove(); - AssertHelper.Exception<VectoException>(() => { - var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.OverSpeedEcoRoll; - }, "Key OverSpeedEcoRoll not found"); + AssertHelper.Exception<VectoException>( + () => { var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.OverSpeedEcoRoll; }, + "Key OverSpeedEcoRoll not found"); } } diff --git a/VectoCoreTest/FileIO/SimulationDataReaderTest.cs b/VectoCoreTest/FileIO/SimulationDataReaderTest.cs index cc666e65bf5e06552983def4e0d11682ade7d9b1..db0bf413982f8ee8e296724a62143ed89e3a1054 100644 --- a/VectoCoreTest/FileIO/SimulationDataReaderTest.cs +++ b/VectoCoreTest/FileIO/SimulationDataReaderTest.cs @@ -19,6 +19,8 @@ using System.IO; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.InputData; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Declaration; @@ -37,7 +39,11 @@ namespace TUGraz.VectoCore.Tests.FileIO public void ReadDeclarationJobFile() { var dataProvider = JSONInputDataFactory.ReadJsonJob(DeclarationJob); - var reader = new DeclarationModeVectoRunDataFactory(dataProvider, null); + var declarationProvider = dataProvider as IDeclarationInputDataProvider; + if (declarationProvider == null) { + throw new VectoException("Failed to cas to Engineering InputDataProvider"); + } + var reader = new DeclarationModeVectoRunDataFactory(declarationProvider, null); //reader.SetJobFile(DeclarationJob); var runData = reader.NextRun().First(); diff --git a/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs b/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs index 426cf4eb889e35f68ead341467eacb14823ad58c..b2f7c59b5ba920ac4b6410aeb93408bd26ab90d3 100644 --- a/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs +++ b/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs @@ -18,6 +18,8 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Exceptions; +using TUGraz.VectoCore.InputData; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Connector.Ports; @@ -37,7 +39,11 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation public void BuildFullPowerTrainTest() { var dataProvider = JSONInputDataFactory.ReadJsonJob(JobFile); - var reader = new EngineeringModeVectoRunDataFactory(dataProvider); + var engineeringProvider = dataProvider as IEngineeringInputDataProvider; + if (engineeringProvider == null) { + throw new VectoException("Failed to cas to Engineering InputDataProvider"); + } + var reader = new EngineeringModeVectoRunDataFactory(engineeringProvider); var runData = reader.NextRun().First(); var writer = new MockModalDataContainer(); diff --git a/VectoCoreTest/Utils/MockSimulationDataFactory.cs b/VectoCoreTest/Utils/MockSimulationDataFactory.cs index 9210f39639950f2fe264e17c0a0965f8e26514bc..e258cc2c5fe061deb3fa8218ad90eaf1a01b06cf 100644 --- a/VectoCoreTest/Utils/MockSimulationDataFactory.cs +++ b/VectoCoreTest/Utils/MockSimulationDataFactory.cs @@ -16,6 +16,7 @@ * limitations under the Licence. */ +using TUGraz.VectoCore.Exceptions; using TUGraz.VectoCore.InputData; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.DataObjectAdaper; @@ -71,8 +72,12 @@ namespace TUGraz.VectoCore.Tests.Utils public static DriverData CreateDriverDataFromFile(string driverDataFile) { var jobInput = JSONInputDataFactory.ReadJsonJob(driverDataFile); + var engineeringJob = jobInput as IEngineeringInputDataProvider; + if (engineeringJob == null) { + throw new VectoException("Failed to cas to Engineering InputDataProvider"); + } var dao = new EngineeringDataAdapter(); - return dao.CreateDriverData(jobInput.DriverInputData); + return dao.CreateDriverData(engineeringJob.DriverInputData); } } } \ No newline at end of file