Commit 7b1da6cf authored by Marion Goedel's avatar Marion Goedel
Browse files

Changes in VadereConsole to allow for option -suq as preparation for the SUQ controller.

parent dac9c25c
...@@ -5,6 +5,7 @@ import org.vadere.simulator.projects.io.IOVadere; ...@@ -5,6 +5,7 @@ import org.vadere.simulator.projects.io.IOVadere;
import org.vadere.util.io.IOUtils; import org.vadere.util.io.IOUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
public class ScenarioFactory { public class ScenarioFactory {
...@@ -31,4 +32,22 @@ public class ScenarioFactory { ...@@ -31,4 +32,22 @@ public class ScenarioFactory {
return scenario; return scenario;
} }
public static Scenario createScenarioWithScenarioFilePath(
final Path scenarioPath) throws IOException {
String json = IOUtils.readTextFile(scenarioPath);
Scenario scenario = IOVadere.fromJson(json);
return scenario;
}
public static Scenario createScenarioWithScenarioJson(
final String scenarioJson) throws IOException {
Scenario scenario = IOVadere.fromJson(scenarioJson);
return scenario;
}
} }
...@@ -40,9 +40,18 @@ public class VadereConsole { ...@@ -40,9 +40,18 @@ public class VadereConsole {
System.exit(1); System.exit(1);
} }
System.out.println(System.getProperty("user.dir"));
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
String pathToScenarioFile = ns.getString("scenario-file"); String pathToScenarioFile = ns.getString("scenario-file");
String outputDir = ns.get("output-dir"); String outputDir = ns.get("output-dir");
if (ns.getBoolean("suq")){
if (outputDir == null){
throw new IllegalArgumentException("If the option -suq is activated, an output directory (output-dir) has to be specified!");
}
}
if (pathToScenarioFile == null) { if (pathToScenarioFile == null) {
System.err.println("Too few arguments. Exiting."); System.err.println("Too few arguments. Exiting.");
...@@ -61,12 +70,26 @@ public class VadereConsole { ...@@ -61,12 +70,26 @@ public class VadereConsole {
logger.info(String.format("Running VADERE on %s...", scenarioFilePath)); logger.info(String.format("Running VADERE on %s...", scenarioFilePath));
try { try {
Scenario scenario = ScenarioFactory.createVadereWithProjectDirectory(projectDirectory,scenarioFile); Scenario scenario;
if (ns.getBoolean("suq")) {
scenario = ScenarioFactory.createScenarioWithScenarioFilePath(Paths.get(scenarioFile));
}else{
scenario = ScenarioFactory.createVadereWithProjectDirectory(scenarioFile, projectDirectory);
}
if(outputDir != null) { if(outputDir != null) {
new ScenarioRun(scenario, outputDir,null).run(); if (ns.getBoolean("suq")){
new ScenarioRun(scenario, outputDir, null,true).run();
}else {
new ScenarioRun(scenario, outputDir, null).run();
}
} }
else { else {
new ScenarioRun(scenario, null).run(); if (ns.getBoolean("suq")){
new ScenarioRun(scenario, null, null,true).run();
}else {
new ScenarioRun(scenario, null).run();
}
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -83,6 +106,9 @@ public class VadereConsole { ...@@ -83,6 +106,9 @@ public class VadereConsole {
.help("Path to the scenario file."); .help("Path to the scenario file.");
parser.addArgument("output-dir").required(false) parser.addArgument("output-dir").required(false)
.help("Path to the directory of the output. By default this is ./output of the directory of the executable."); .help("Path to the directory of the output. By default this is ./output of the directory of the executable.");
parser.addArgument("-suq").required(false)
.help("Indicates that the folder structure for input and output is fully controlled by the user. Only a single scenario is run, no project or project structure is necessary. Intended for the SUQ-Controller. Outputpath has to be specified!")
.action(Arguments.storeTrue());
return parser; return parser;
} }
......
...@@ -53,11 +53,16 @@ public class ScenarioRun implements Runnable { ...@@ -53,11 +53,16 @@ public class ScenarioRun implements Runnable {
this(scenario, IOUtils.OUTPUT_DIR, scenarioFinishedListener); this(scenario, IOUtils.OUTPUT_DIR, scenarioFinishedListener);
} }
public ScenarioRun(final Scenario scenario, final String outputDir, final RunnableFinishedListener scenarioFinishedListener) { public ScenarioRun(final Scenario scenario, final String outputDir, final RunnableFinishedListener scenarioFinishedListener) {
this(scenario, outputDir, scenarioFinishedListener, false);
}
public ScenarioRun(final Scenario scenario, final String outputDir, final RunnableFinishedListener scenarioFinishedListener, boolean suq) {
this.scenario = scenario; this.scenario = scenario;
this.scenarioStore = scenario.getScenarioStore(); this.scenarioStore = scenario.getScenarioStore();
this.dataProcessingJsonManager = scenario.getDataProcessingJsonManager(); this.dataProcessingJsonManager = scenario.getDataProcessingJsonManager();
this.setOutputPaths(Paths.get(outputDir)); // TODO [priority=high] [task=bugfix] [Error?] this is a relative path. If you start the application via eclipse this will be VadereParent/output this.setOutputPaths(Paths.get(outputDir), suq); // TODO [priority=high] [task=bugfix] [Error?] this is a relative path. If you start the application via eclipse this will be VadereParent/outputs
this.finishedListener = scenarioFinishedListener; this.finishedListener = scenarioFinishedListener;
} }
...@@ -138,6 +143,15 @@ public class ScenarioRun implements Runnable { ...@@ -138,6 +143,15 @@ public class ScenarioRun implements Runnable {
} }
} }
public void setOutputPaths(final Path outputPath, boolean suq) {
if (suq == false){
setOutputPaths(outputPath);
}else{
this.outputPath = Paths.get(outputPath.toString());
System.out.println(this.outputPath);
}
}
public void pause() { public void pause() {
if (simulation != null) { // TODO throw an illegal state exception if simulation is not running if (simulation != null) { // TODO throw an illegal state exception if simulation is not running
simulation.pause(); simulation.pause();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment