From 9e6a9e7e0799ad6bf59b9a8a5e8e7f5e8f2f1360 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Thu, 1 Sep 2016 18:10:24 +0200
Subject: [PATCH] extending auxiliaries classes to provide list of available
 auxiliaries (for GUI)

---
 .../Models/Declaration/ElectricSystem.cs      | 14 ++++++--
 VectoCore/VectoCore/Models/Declaration/Fan.cs | 12 +++++--
 .../VectoCore/Models/Declaration/HVAC.cs      |  9 ++++-
 .../Models/Declaration/PneumaticSystem.cs     |  8 ++++-
 .../Models/Declaration/SteeringPump.cs        | 35 +++++++++++++------
 .../VectoCore/Models/Declaration/Wheels.cs    |  9 +++++
 6 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs b/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs
index b68718cc1f..bdc17fea45 100644
--- a/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs
+++ b/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs
@@ -31,12 +31,13 @@
 
 using System;
 using System.Data;
+using System.Linq;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Utils;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
-	public sealed class ElectricSystem : LookupData<MissionType, string, Watt>
+	public sealed class ElectricSystem : LookupData<MissionType, string, Watt>, IDeclarationAuxiliaryTable
 	{
 		private readonly Alternator _alternator = new Alternator();
 
@@ -68,8 +69,9 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		public override Watt Lookup(MissionType missionType, string technology = null)
 		{
-			if (string.IsNullOrWhiteSpace(technology))
+			if (string.IsNullOrWhiteSpace(technology)) {
 				technology = "Standard technology";
+			}
 			var value = base.Lookup(missionType, technology);
 			return value / _alternator.Lookup(missionType);
 		}
@@ -103,10 +105,16 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			public override double Lookup(MissionType missionType, string technology = null)
 			{
-				if (string.IsNullOrWhiteSpace(technology))
+				if (string.IsNullOrWhiteSpace(technology)) {
 					technology = "Standard alternator efficiency";
+				}
 				return base.Lookup(missionType, technology);
 			}
 		}
+
+		public string[] GetTechnologies()
+		{
+			return Data.Keys.Select(x => x.Item2).Distinct().ToArray();
+		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Declaration/Fan.cs b/VectoCore/VectoCore/Models/Declaration/Fan.cs
index b1940483d8..54673dff50 100644
--- a/VectoCore/VectoCore/Models/Declaration/Fan.cs
+++ b/VectoCore/VectoCore/Models/Declaration/Fan.cs
@@ -31,12 +31,13 @@
 
 using System;
 using System.Data;
+using System.Linq;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Utils;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
-	public sealed class Fan : LookupData<MissionType, string, Watt>
+	public sealed class Fan : LookupData<MissionType, string, Watt>, IDeclarationAuxiliaryTable
 	{
 		protected override string ResourceId
 		{
@@ -55,6 +56,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			foreach (DataRow row in table.Rows) {
 				var name = row.Field<string>("technology");
+
 				foreach (DataColumn col in table.Columns) {
 					if (col.Caption != "technology") {
 						Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), name)] = row.ParseDouble(col).SI<Watt>();
@@ -65,9 +67,15 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		public override Watt Lookup(MissionType mission, string technology = null)
 		{
-			if (string.IsNullOrWhiteSpace(technology))
+			if (string.IsNullOrWhiteSpace(technology)) {
 				technology = "Crankshaft mounted - Electronically controlled visco clutch";
+			}
 			return base.Lookup(mission, technology);
 		}
+
+		public string[] GetTechnologies()
+		{
+			return Data.Keys.Select(x => x.Item2).Distinct().ToArray();
+		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Declaration/HVAC.cs b/VectoCore/VectoCore/Models/Declaration/HVAC.cs
index 2dbdaa7618..2e4f31833b 100644
--- a/VectoCore/VectoCore/Models/Declaration/HVAC.cs
+++ b/VectoCore/VectoCore/Models/Declaration/HVAC.cs
@@ -31,12 +31,14 @@
 
 using System;
 using System.Data;
+using Org.BouncyCastle.Asn1;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Utils;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
-	public sealed class HeatingVentilationAirConditioning : LookupData<MissionType, VehicleClass, Watt>
+	public sealed class HeatingVentilationAirConditioning : LookupData<MissionType, VehicleClass, Watt>,
+		IDeclarationAuxiliaryTable
 	{
 		protected override string ResourceId
 		{
@@ -63,5 +65,10 @@ namespace TUGraz.VectoCore.Models.Declaration
 				}
 			}
 		}
+
+		public string[] GetTechnologies()
+		{
+			return new[] { "Default" };
+		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs b/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs
index c0d2bbc799..37d965f8d2 100644
--- a/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs
+++ b/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs
@@ -31,12 +31,13 @@
 
 using System;
 using System.Data;
+using System.Linq;
 using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.Utils;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
-	public sealed class PneumaticSystem : LookupData<MissionType, string, Watt>
+	public sealed class PneumaticSystem : LookupData<MissionType, string, Watt>, IDeclarationAuxiliaryTable
 	{
 		protected override string ResourceId
 		{
@@ -62,5 +63,10 @@ namespace TUGraz.VectoCore.Models.Declaration
 				}
 			}
 		}
+
+		public string[] GetTechnologies()
+		{
+			return Data.Keys.Select(x => x.Item2).Distinct().ToArray();
+		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs b/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs
index dc2965fc58..1feac2e11b 100644
--- a/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs
+++ b/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs
@@ -38,26 +38,26 @@ using TUGraz.VectoCore.Utils;
 
 namespace TUGraz.VectoCore.Models.Declaration
 {
-	public sealed class SteeringPump
+	public sealed class SteeringPump : IDeclarationAuxiliaryTable
 	{
+		private readonly SteeringPumpBaseLine _baseLookup = new SteeringPumpBaseLine();
+		private readonly SteeringPumpAxles _axleLookup = new SteeringPumpAxles();
+		private readonly SteeringPumpTechnologies _techLookup = new SteeringPumpTechnologies();
+
 		public Watt Lookup(MissionType mission, VehicleClass hdvClass, IEnumerable<string> technologies)
 		{
-			var baseLookup = new SteeringPumpBaseLine();
-			var axleLookup = new SteeringPumpAxles();
-			var techLookup = new SteeringPumpTechnologies();
-
-			var baseLine = baseLookup.Lookup(mission, hdvClass);
+			var baseLine = _baseLookup.Lookup(mission, hdvClass);
 			var power = new SteeringPumpValues<Watt>(0.SI<Watt>(), 0.SI<Watt>(), 0.SI<Watt>());
 			var factors = new SteeringPumpValues<double>(0, 0, 0);
 			var i = 0;
 			foreach (var technology in technologies) {
 				i++;
-				var axles = axleLookup.Lookup(mission, i);
+				var axles = _axleLookup.Lookup(mission, i);
 				power.UnloadedFriction += baseLine.UnloadedFriction * axles.UnloadedFriction;
 				power.Banking += baseLine.Banking * axles.Banking;
 				power.Steering += baseLine.Steering * axles.Steering;
 
-				var f = techLookup.Lookup(technology, mission);
+				var f = _techLookup.Lookup(technology, mission);
 				factors.UnloadedFriction += f.UnloadedFriction;
 				factors.Banking += f.Banking;
 				factors.Steering += f.Steering;
@@ -90,8 +90,9 @@ namespace TUGraz.VectoCore.Models.Declaration
 				foreach (DataRow row in table.Rows) {
 					var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass"));
 					foreach (DataColumn col in table.Columns) {
-						if (col.Caption == "hdvclass" || string.IsNullOrWhiteSpace(row.Field<string>(col.Caption)))
+						if (col.Caption == "hdvclass" || string.IsNullOrWhiteSpace(row.Field<string>(col.Caption))) {
 							continue;
+						}
 						var values = row.Field<string>(col.Caption).Split('/')
 							.Select(v => v.ToDouble() / 100.0).Concat(0.0.Repeat(3)).SI<Watt>().ToList();
 						Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), hdvClass)] = new SteeringPumpValues<Watt>(values[0],
@@ -144,6 +145,11 @@ namespace TUGraz.VectoCore.Models.Declaration
 				}
 				return values;
 			}
+
+			public string[] GetTechnologies()
+			{
+				return Data.Keys.Distinct().ToArray();
+			}
 		}
 
 		private sealed class SteeringPumpAxles : LookupData<MissionType, int, SteeringPumpValues<double>>
@@ -166,11 +172,13 @@ namespace TUGraz.VectoCore.Models.Declaration
 				foreach (DataRow row in table.Rows) {
 					var axleNumber = int.Parse(row.Field<string>("steeredaxles"));
 					foreach (DataColumn col in table.Columns) {
-						if (col.Caption == "steeredaxles")
+						if (col.Caption == "steeredaxles") {
 							continue;
+						}
 						var field = row.Field<string>(col.Caption);
-						if (string.IsNullOrWhiteSpace(field))
+						if (string.IsNullOrWhiteSpace(field)) {
 							continue;
+						}
 						var values = field.Split('/').ToDouble().Concat(0.0.Repeat(3)).ToList();
 						Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), axleNumber)] = new SteeringPumpValues<double>(values[0],
 							values[1], values[2]);
@@ -192,5 +200,10 @@ namespace TUGraz.VectoCore.Models.Declaration
 				Steering = steering;
 			}
 		}
+
+		public string[] GetTechnologies()
+		{
+			return _techLookup.GetTechnologies();
+		}
 	}
 }
\ No newline at end of file
diff --git a/VectoCore/VectoCore/Models/Declaration/Wheels.cs b/VectoCore/VectoCore/Models/Declaration/Wheels.cs
index 8d70ab77e9..eed2c80c39 100644
--- a/VectoCore/VectoCore/Models/Declaration/Wheels.cs
+++ b/VectoCore/VectoCore/Models/Declaration/Wheels.cs
@@ -29,6 +29,7 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
+using System.Collections.Generic;
 using System.Data;
 using System.Linq;
 using TUGraz.VectoCommon.Utils;
@@ -38,6 +39,8 @@ namespace TUGraz.VectoCore.Models.Declaration
 {
 	public sealed class Wheels : LookupData<string, Wheels.Entry>
 	{
+		private string[] _dimensions;
+
 		protected override string ResourceId
 		{
 			get { return "TUGraz.VectoCore.Resources.Declaration.Wheels.csv"; }
@@ -62,6 +65,7 @@ namespace TUGraz.VectoCore.Models.Declaration
 					DynamicTyreRadius = row.ParseDouble("d").SI().Milli.Meter.Cast<Meter>(),
 					CircumferenceFactor = row.ParseDouble("f")
 				}).ToDictionary(e => e.WheelType);
+			_dimensions = table.Rows.Cast<DataRow>().Select(row => row.Field<string>(0)).ToArray();
 		}
 
 		public class Entry
@@ -71,5 +75,10 @@ namespace TUGraz.VectoCore.Models.Declaration
 			public Meter DynamicTyreRadius;
 			public double CircumferenceFactor;
 		}
+
+		public string[] GetWheelsDimensions()
+		{
+			return _dimensions;
+		}
 	}
 }
\ No newline at end of file
-- 
GitLab