From 38b3bea23d5e378cb41fb6ab6ed7c66a781730de Mon Sep 17 00:00:00 2001
From: marvin <marvin@marvin-TERRA-MOBILE-1529H>
Date: Thu, 19 Dec 2019 01:29:05 +0100
Subject: [PATCH] Case-based input selection

---
 Varianten/AdapterFIDEROS/src/Adapter.java | 52 ++++++++++++++++++-----
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/Varianten/AdapterFIDEROS/src/Adapter.java b/Varianten/AdapterFIDEROS/src/Adapter.java
index 78d0733..a3fce3a 100644
--- a/Varianten/AdapterFIDEROS/src/Adapter.java
+++ b/Varianten/AdapterFIDEROS/src/Adapter.java
@@ -94,20 +94,50 @@ public class Adapter {
 	 */
 	public static void main(String[] args) {
 		try {
-			Document FeatureModel = readXml("resources/input/featuremodel.xml");
-			Document GazeboModel = readXml("resources/input/turtlebot3-master/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro");
+			Document featureModel = readXml("resources/input/featuremodel.xml");
+			Document sensorConfig = readXml("resources/input/sensorconfig.xml");
+			Document gazeboModel = null;
 			
 			//TODO
 			//######### Operate on featuremodel.xml #########
-			Element fmRoot = FeatureModel.getRootElement();
-			List<Element> modules = fmRoot.getChildren("module");
+			//CustomBot not supported for now
+			List<Attribute> botList = xQueryAttributes(featureModel, "//module[@types='TurtleBot']/@name");
+			
+			String botName = "";
+			switch(botList.size()) {
+				case 0:
+					System.out.println("Invalid input: No bot selected\n");
+					System.exit(-1);
+					break;
+				case 1:
+					botName = botList.get(0).getValue();
+					break;
+				default:
+					System.out.println("Invalid input: multiple bots selected\n");
+					System.exit(-1);
+					
+			}
+			switch(botName) {
+				case "Burger":
+					gazeboModel = readXml("resources/input/turtlebot3-master/turtlebot3_description/urdf/turtlebot3_burger.gazebo.xacro");
+					break;
+				case "Waffle":
+					gazeboModel = readXml("resources/input/turtlebot3-master/turtlebot3_description/urdf/turtlebot3_waffle.gazebo.xacro");
+					break;
+				case "WafflePi":
+					gazeboModel = readXml("resources/input/turtlebot3-master/turtlebot3_description/urdf/turtlebot3_waffle_pi.gazebo.xacro");
+					break;
+				default:
+					System.out.println("Cannot handle \'"+botName+"\': No input file known.\n");
+					System.exit(-1);
+			}
 			
 			//###############################################
 			
 			
 			//TODO
 			//######### Operate on .gazebo.xacro ############
-			Element gmRoot = GazeboModel.getRootElement();
+			Element gmRoot = gazeboModel.getRootElement();
 
 			//###############################################
 			
@@ -117,7 +147,7 @@ public class Adapter {
 			
 			//TODO
 			//######### Output result #######################
-			xmlOutput.output(GazeboModel, dest);
+			xmlOutput.output(gazeboModel, dest);
 
 			//###############################################
 			
@@ -125,11 +155,11 @@ public class Adapter {
 			//XPathExamples
 			XPathFactory xFactory = XPathFactory.instance();
 			XPathExpression<Element> xExpr = xFactory.compile("robot/gazebo/sensor/ray/range/min", Filters.element());
-			Element test = xExpr.evaluateFirst(GazeboModel);
-			List<Element> test2 = searchAllElements(GazeboModel, "min");
-			List<Element> test3 = searchAllElements(GazeboModel, "max");
-			Element test4 = searchFirstElement(GazeboModel, "plugin");
-			List<Attribute> test5 = xQueryAttributes(GazeboModel, "(//plugin)[1]/@*");
+			Element test = xExpr.evaluateFirst(gazeboModel);
+			List<Element> test2 = searchAllElements(gazeboModel, "min");
+			List<Element> test3 = searchAllElements(gazeboModel, "max");
+			Element test4 = searchFirstElement(gazeboModel, "plugin");
+			List<Attribute> test5 = xQueryAttributes(gazeboModel, "(//plugin)[1]/@*");
 			
 			if(test != null) xmlOutput.output(test, System.out);
 			System.out.println("\n");
-- 
GitLab