Commit 381c709f authored by Jakob Schöttl's avatar Jakob Schöttl

Bugfixes and refactoring

parent d0b20bab
......@@ -37,9 +37,6 @@ public class Scenario {
private DataProcessingJsonManager dataProcessingJsonManager;
private ScenarioFinishedListener finishedListener;
private boolean simpleOutputProcessorName = false;
private String savedStateSerialized;
private String currentStateSerialized;
......@@ -144,10 +141,6 @@ public class Scenario {
scenarioStore.topography = topography;
}
public void setScenarioFinishedListener(ScenarioFinishedListener finishedListener) {
this.finishedListener = finishedListener;
}
@Override
public Scenario clone() {
Scenario clonedScenario = null;
......@@ -164,10 +157,6 @@ public class Scenario {
return getName();
}
public void setSimpleOutputProcessorName(boolean simpleOutputProcessorName) {
this.simpleOutputProcessorName = simpleOutputProcessorName;
}
public String getDisplayName() {
return scenarioStore.name + (hasUnsavedChanges() ? "*" : "");
}
......@@ -178,8 +167,6 @@ public class Scenario {
// not all necessary! only the ones that could have changed
scenarioStore = srm.scenarioStore;
dataProcessingJsonManager = srm.dataProcessingJsonManager;
finishedListener = srm.finishedListener;
simpleOutputProcessorName = srm.simpleOutputProcessorName;
} catch (IOException | VadereClassNotFoundException e) {
e.printStackTrace();
}
......
......@@ -36,18 +36,17 @@ public class ScenarioRun implements Runnable {
private static Logger logger = LogManager.getLogger(ScenarioRun.class);
private ScenarioStore scenarioStore;
private Path outputPath;
private final List<PassiveCallback> passiveCallbacks = new LinkedList<>();
private DataProcessingJsonManager dataProcessingJsonManager;
private ProcessorManager processorManager;
private final DataProcessingJsonManager dataProcessingJsonManager;
private ScenarioFinishedListener finishedListener;
private Simulation simulation;
private final Scenario scenario;
private final ScenarioStore scenarioStore; // contained in scenario, but here for convenience
public ScenarioRun(final Scenario scenario) {
this.scenario = scenario;
......@@ -78,13 +77,13 @@ public class ScenarioRun implements Runnable {
final Random random = modelBuilder.getRandom();
// prepare processors and simulation data writer
processorManager = dataProcessingJsonManager.createProcessorManager(mainModel);
final ProcessorManager processorManager = dataProcessingJsonManager.createProcessorManager(mainModel);
createAndSetOutputDirectory();
createAndSetOutputDirectory(processorManager);
scenario.saveToOutputPath(outputPath);
sealAllAttributes();
sealAllAttributes(processorManager);
// Run simulation main loop from start time = 0 seconds
simulation = new Simulation(mainModel, 0, scenarioStore.name, scenarioStore, passiveCallbacks, random, processorManager);
......@@ -183,22 +182,21 @@ public class ScenarioRun implements Runnable {
this.finishedListener = finishedListener;
}
public boolean pause() {
if (simulation != null) {
public void pause() {
if (simulation != null) { // TODO throw an illegal state exception if simulation is not running
simulation.pause();
return true;
}
return false;
}
public void resume() {
if (simulation != null)
if (simulation != null) { // TODO throw an illegal state exception if simulation is not running
simulation.resume();
}
}
// Output stuff...
private void createAndSetOutputDirectory() {
private void createAndSetOutputDirectory(final ProcessorManager processorManager) {
try {
// Create output directory
Files.createDirectories(outputPath);
......@@ -228,18 +226,10 @@ public class ScenarioRun implements Runnable {
return null;
}
public ProcessorManager getProcessorManager() {
return processorManager;
}
public DataProcessingJsonManager getDataProcessingJsonManager() {
return dataProcessingJsonManager;
}
public void setDataProcessingJsonManager(final DataProcessingJsonManager manager) {
this.dataProcessingJsonManager = manager;
}
public Path getOutputPath() {
return outputPath;
}
......@@ -248,7 +238,7 @@ public class ScenarioRun implements Runnable {
return scenario;
}
public void sealAllAttributes() {
public void sealAllAttributes(final ProcessorManager processorManager) {
scenarioStore.sealAllAttributes();
processorManager.sealAllAttributes();
}
......
......@@ -146,8 +146,7 @@ public class VadereProject implements ScenarioFinishedListener {
}
private ScenarioRun prepareNextScenario() {
final Scenario nextScenario = scenariosLeft.remove().clone();
nextScenario.setScenarioFinishedListener(this);
final Scenario nextScenario = scenariosLeft.remove().clone(); // TODO why clone? scenario should not be changed during a simulation run
notifySingleScenarioFinishListener(nextScenario);
......@@ -156,6 +155,7 @@ public class VadereProject implements ScenarioFinishedListener {
if (visualization != null) {
scenarioRun.addPassiveCallback(visualization);
}
scenarioRun.setScenarioFinishedListener(this);
return scenarioRun;
}
......@@ -170,10 +170,9 @@ public class VadereProject implements ScenarioFinishedListener {
}
public void pauseRunnningScenario() {
if (currentScenarioRun.pause()) {
for (SingleScenarioFinishedListener listener : singleScenarioFinishedListener) {
listener.scenarioPaused(currentScenarioRun.getScenario(), scenariosLeft.size() + 1);
}
currentScenarioRun.pause();
for (SingleScenarioFinishedListener listener : singleScenarioFinishedListener) {
listener.scenarioPaused(currentScenarioRun.getScenario(), scenariosLeft.size() + 1);
}
}
......
Markdown is supported
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