Commit 9f043451 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

UltimateBug fix (try) by making sure that only the GUI-Thread changes the...

UltimateBug fix (try) by making sure that only the GUI-Thread changes the ScenarioStore object if the GUI is used and no mix between GUI thread and another thread.
parent 9b9a44da
Pipeline #59484 passed with stage
in 47 seconds
...@@ -106,12 +106,14 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen ...@@ -106,12 +106,14 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
} }
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e)
{
updateModel(); updateModel();
} }
@Override @Override
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
updateModel(); updateModel();
} }
}; };
...@@ -126,7 +128,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen ...@@ -126,7 +128,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
ScenarioElement element = panelModel.getSelectedElement(); ScenarioElement element = panelModel.getSelectedElement();
if (element != null) { if (element != null) {
String json = txtrTextfiletextarea.getText(); String json = txtrTextfiletextarea.getText();
//logger.info(json);
if (json.length() == 0) if (json.length() == 0)
return; return;
......
...@@ -6,6 +6,7 @@ import org.vadere.gui.projectview.view.ProjectView; ...@@ -6,6 +6,7 @@ import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.state.attributes.models.AttributesBHM; import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.util.io.IOUtils; import org.vadere.util.io.IOUtils;
import java.awt.*;
import java.io.IOException; import java.io.IOException;
import java.util.prefs.BackingStoreException; import java.util.prefs.BackingStoreException;
import java.util.prefs.InvalidPreferencesFormatException; import java.util.prefs.InvalidPreferencesFormatException;
......
...@@ -109,12 +109,14 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing ...@@ -109,12 +109,14 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
// ################## // ##################
@Override @Override
public void postProjectRun(final VadereProject scenario) { public void postProjectRun(final VadereProject scenario) {
scenariosRunning = false; EventQueue.invokeLater(() -> {
model.refreshOutputTable(); scenariosRunning = false;
setScenariosRunning(false); model.refreshOutputTable();
progressPanel.setData(Messages.getString("ProgressPanelDone.text"), 100); setScenariosRunning(false);
scenarioJPanel.showEditScenario(); progressPanel.setData(Messages.getString("ProgressPanelDone.text"), 100);
selectCurrentScenarioRunManager(); scenarioJPanel.showEditScenario();
selectCurrentScenarioRunManager();
});
} }
private void selectCurrentScenarioRunManager() { private void selectCurrentScenarioRunManager() {
...@@ -127,58 +129,71 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing ...@@ -127,58 +129,71 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
@Override @Override
public void preProjectRun(final VadereProject project) { public void preProjectRun(final VadereProject project) {
setScenariosRunning(true); EventQueue.invokeLater(() -> {
progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 0); setScenariosRunning(true);
progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 0);
});
} }
@Override @Override
public void preScenarioRun(final Scenario scenario, final int scenariosLeft) { public void preScenarioRun(final Scenario scenario, final int scenariosLeft) {
model.setScenarioNameLabel(scenario.getName()); EventQueue.invokeLater(() -> {
repaint(); model.setScenarioNameLabel(scenario.getName());
repaint();
});
} }
@Override @Override
public void postScenarioRun(final Scenario cloneScenario, final int scenarioLeft) { public void postScenarioRun(final Scenario cloneScenario, final int scenarioLeft) {
// take the original! EventQueue.invokeLater(() -> {
replace(cloneScenario, VadereState.INITIALIZED); replace(cloneScenario, VadereState.INITIALIZED);
// model.refreshOutputTable(); // model.refreshOutputTable();
// find index of scenario // find index of scenario
int totalScenariosCount = model.getProject().getScenarios().size(); int totalScenariosCount = model.getProject().getScenarios().size();
int doneScenariosCount = totalScenariosCount - scenarioLeft; int doneScenariosCount = totalScenariosCount - scenarioLeft;
progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 100 * doneScenariosCount progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 100 * doneScenariosCount
/ totalScenariosCount); / totalScenariosCount);
logger.info(String.format("scenario %s finished", cloneScenario.getName())); logger.info(String.format("scenario %s finished", cloneScenario.getName()));
});
} }
@Override @Override
public void scenarioStarted(final Scenario cloneScenario, final int scenariosLeft) { public void scenarioStarted(final Scenario cloneScenario, final int scenariosLeft) {
// take the original! // take the original!
replace(cloneScenario, VadereState.RUNNING); EventQueue.invokeLater(() -> {
replace(cloneScenario, VadereState.RUNNING);
});
} }
@Override @Override
public void scenarioPaused(final Scenario cloneScenario, final int scenariosLeft) { public void scenarioPaused(final Scenario cloneScenario, final int scenariosLeft) {
// take the original! // take the original!
replace(cloneScenario, VadereState.PAUSED); EventQueue.invokeLater(() -> {
replace(cloneScenario, VadereState.PAUSED);
});
} }
@Override @Override
public void scenarioInterrupted(final Scenario scenario, final int scenariosLeft) { public void scenarioInterrupted(final Scenario scenario, final int scenariosLeft) {
replace(scenario, VadereState.INTERRUPTED); EventQueue.invokeLater(() -> {
setScenariosRunning(false); replace(scenario, VadereState.INTERRUPTED);
selectCurrentScenarioRunManager(); setScenariosRunning(false);
logger.info(String.format("all running scenarios interrupted")); selectCurrentScenarioRunManager();
logger.info(String.format("all running scenarios interrupted"));
});
} }
@Override @Override
public void error(final Scenario scenario, final int scenarioLefts, final Throwable throwable) { public void error(final Scenario scenario, final int scenarioLefts, final Throwable throwable) {
replace(scenario, VadereState.INTERRUPTED); EventQueue.invokeLater(() -> {
new Thread( replace(scenario, VadereState.INTERRUPTED);
() -> { new Thread(
IOUtils.errorBox(Messages.getString("ProjectView.simulationRunErrorDialog.text") + " " + scenario () -> {
+ ": " + throwable, Messages.getString("ProjectView.simulationRunErrorDialog.title")); IOUtils.errorBox(Messages.getString("ProjectView.simulationRunErrorDialog.text") + " " + scenario
}).start(); + ": " + throwable, Messages.getString("ProjectView.simulationRunErrorDialog.title"));
}).start();
});
} }
private void replace(final Scenario scenarioRM, final VadereState state) { private void replace(final Scenario scenarioRM, final VadereState state) {
...@@ -190,21 +205,27 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing ...@@ -190,21 +205,27 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
@Override @Override
public void preRefresh() { public void preRefresh() {
outputTable.setEnabled(false); EventQueue.invokeLater(() -> {
outputTable.setEnabled(false);
});
} }
@Override @Override
public void postRefresh() { public void postRefresh() {
if (!scenariosRunning) EventQueue.invokeLater(() -> {
outputTable.setEnabled(true); if (!scenariosRunning)
outputTable.setEnabled(true);
});
} }
@Override @Override
public void projectChanged(final VadereProject project) { public void projectChanged(final VadereProject project) {
setTitle(); EventQueue.invokeLater(() -> {
model.getProject().addProjectFinishedListener(this); setTitle();
model.getProject().addSingleScenarioFinishedListener(this); model.getProject().addProjectFinishedListener(this);
model.getProject().addProjectFinishedListener(scenarioJPanel); model.getProject().addSingleScenarioFinishedListener(this);
model.getProject().addProjectFinishedListener(scenarioJPanel);
});
} }
@Override @Override
...@@ -217,21 +238,23 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing ...@@ -217,21 +238,23 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
* Launch the application. * Launch the application.
*/ */
public static void start() { public static void start() {
try { EventQueue.invokeLater(() -> {
// Set Java L&F from system try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // Set Java L&F from system
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
| IllegalAccessException e) { } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException
IOUtils.errorBox("The system look and feel could not be loaded.", "Error setLookAndFeel"); | IllegalAccessException e) {
} IOUtils.errorBox("The system look and feel could not be loaded.", "Error setLookAndFeel");
// show GUI }
ProjectViewModel model = new ProjectViewModel(); // show GUI
ProjectView frame = new ProjectView(model); ProjectViewModel model = new ProjectViewModel();
frame.setProjectSpecificActionsEnabled(false); ProjectView frame = new ProjectView(model);
frame.setVisible(true); frame.setProjectSpecificActionsEnabled(false);
frame.setSize(1200, 800); frame.setVisible(true);
frame.setSize(1200, 800);
frame.openLastUsedProject(model);
frame.openLastUsedProject(model);
});
} }
private void openLastUsedProject(final ProjectViewModel model) { private void openLastUsedProject(final ProjectViewModel model) {
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
"finishTime" : 70.0, "finishTime" : 70.0,
"simTimeStepLength" : 0.4, "simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.1, "realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : true, "writeSimulationData" : false,
"visualizationEnabled" : true, "visualizationEnabled" : true,
"printFPS" : false, "printFPS" : false,
"needsBoundary" : false, "needsBoundary" : false,
......
...@@ -76,10 +76,10 @@ public class Simulation { ...@@ -76,10 +76,10 @@ public class Simulation {
this.mainModel = mainModel; this.mainModel = mainModel;
this.scenarioStore = scenarioStore; this.scenarioStore = scenarioStore;
this.attributesSimulation = scenarioStore.attributesSimulation; this.attributesSimulation = scenarioStore.attributesSimulation;
this.attributesAgent = scenarioStore.topography.getAttributesPedestrian(); this.attributesAgent = scenarioStore.getTopography().getAttributesPedestrian();
this.sourceControllers = new LinkedList<>(); this.sourceControllers = new LinkedList<>();
this.targetControllers = new LinkedList<>(); this.targetControllers = new LinkedList<>();
this.topography = scenarioStore.topography; this.topography = scenarioStore.getTopography();
this.runTimeInSec = attributesSimulation.getFinishTime(); this.runTimeInSec = attributesSimulation.getFinishTime();
this.startTimeInSec = startTimeInSec; this.startTimeInSec = startTimeInSec;
this.simTimeInSec = startTimeInSec; this.simTimeInSec = startTimeInSec;
......
...@@ -66,20 +66,20 @@ public class ScenarioBuilder { ...@@ -66,20 +66,20 @@ public class ScenarioBuilder {
store.attributesSimulation = (AttributesSimulation) builder.build(); store.attributesSimulation = (AttributesSimulation) builder.build();
} }
else if(AttributesAgent.class == clazz){ else if(AttributesAgent.class == clazz){
builder = new AttributesBuilder<>((E)store.topography.getAttributesPedestrian()); builder = new AttributesBuilder<>((E)store.getTopography().getAttributesPedestrian());
builder.setField(fieldName, value); builder.setField(fieldName, value);
setAttributesAgent((AttributesAgent) builder.build()); setAttributesAgent((AttributesAgent) builder.build());
} }
else if(AttributesCar.class == clazz){ else if(AttributesCar.class == clazz){
builder = new AttributesBuilder<>((E)store.topography.getAttributesCar()); builder = new AttributesBuilder<>((E)store.getTopography().getAttributesCar());
builder.setField(fieldName, value); builder.setField(fieldName, value);
setAttributesCar((AttributesCar) builder.build()); setAttributesCar((AttributesCar) builder.build());
} }
else if(AttributesTopography.class == clazz){ else if(AttributesTopography.class == clazz){
builder = new AttributesBuilder<>((E)store.topography.getAttributes()); builder = new AttributesBuilder<>((E)store.getTopography().getAttributes());
builder.setField(fieldName, value); builder.setField(fieldName, value);
ReflectionAttributeModifier reflectionAttributeModifier = new ReflectionAttributeModifier(); ReflectionAttributeModifier reflectionAttributeModifier = new ReflectionAttributeModifier();
reflectionAttributeModifier.setAttributes(store.topography, builder.build()); reflectionAttributeModifier.setAttributes(store.getTopography(), builder.build());
} }
else { else {
builder = new AttributesBuilder<>(store.getAttributes(clazz)); builder = new AttributesBuilder<>(store.getAttributes(clazz));
...@@ -92,9 +92,9 @@ public class ScenarioBuilder { ...@@ -92,9 +92,9 @@ public class ScenarioBuilder {
private void setAttributesCar(@NotNull final AttributesCar attributesCar) { private void setAttributesCar(@NotNull final AttributesCar attributesCar) {
Field field; Field field;
try { try {
field = store.topography.getClass().getDeclaredField("attributesCar"); field = store.getTopography().getClass().getDeclaredField("attributesCar");
field.setAccessible(true); field.setAccessible(true);
field.set(store.topography, attributesCar); field.set(store.getTopography(), attributesCar);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
logger.error(e); logger.error(e);
...@@ -104,9 +104,9 @@ public class ScenarioBuilder { ...@@ -104,9 +104,9 @@ public class ScenarioBuilder {
private void setAttributesAgent(@NotNull final AttributesAgent attributesAgent) { private void setAttributesAgent(@NotNull final AttributesAgent attributesAgent) {
Field field; Field field;
try { try {
field = store.topography.getClass().getDeclaredField("attributesPedestrian"); field = store.getTopography().getClass().getDeclaredField("attributesPedestrian");
field.setAccessible(true); field.setAccessible(true);
field.set(store.topography, attributesAgent); field.set(store.getTopography(), attributesAgent);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
logger.error(e); logger.error(e);
......
...@@ -48,8 +48,8 @@ public class MainModelBuilder { ...@@ -48,8 +48,8 @@ public class MainModelBuilder {
String mainModelName = scenarioStore.mainModel; String mainModelName = scenarioStore.mainModel;
DynamicClassInstantiator<MainModel> instantiator = new DynamicClassInstantiator<>(); DynamicClassInstantiator<MainModel> instantiator = new DynamicClassInstantiator<>();
MainModel mainModel = instantiator.createObject(mainModelName); MainModel mainModel = instantiator.createObject(mainModelName);
mainModel.initialize(scenarioStore.attributesList, scenarioStore.topography, mainModel.initialize(scenarioStore.attributesList, scenarioStore.getTopography(),
scenarioStore.topography.getAttributesPedestrian(), random); scenarioStore.getTopography().getAttributesPedestrian(), random);
return mainModel; return mainModel;
} }
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
package org.vadere.simulator.models.osm.stairOptimization; package org.vadere.simulator.models.osm.stairOptimization;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.simulator.models.osm.PedestrianOSM; import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer; import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.scenario.Stairs; import org.vadere.state.scenario.Stairs;
import org.vadere.state.scenario.Stairs.Tread; import org.vadere.state.scenario.Stairs.Tread;
import org.vadere.util.geometry.Vector2D; import org.vadere.util.geometry.Vector2D;
...@@ -27,6 +29,8 @@ public class StairStepOptimizer implements StepCircleOptimizer { ...@@ -27,6 +29,8 @@ public class StairStepOptimizer implements StepCircleOptimizer {
private Stairs stairs; private Stairs stairs;
private Logger logger = LogManager.getLogger(StairStepOptimizer.class);
private final double tol_equal_values = 1E-4; private final double tol_equal_values = 1E-4;
public StairStepOptimizer(Stairs s) { public StairStepOptimizer(Stairs s) {
...@@ -35,7 +39,7 @@ public class StairStepOptimizer implements StepCircleOptimizer { ...@@ -35,7 +39,7 @@ public class StairStepOptimizer implements StepCircleOptimizer {
@Override @Override
public VPoint getNextPosition(PedestrianOSM pedestrian, Shape reachableArea) { public VPoint getNextPosition(PedestrianOSM pedestrian, Shape reachableArea) {
//logger.info(stairs.getAttributes().getUpwardDirection());
if (!isOnActualStairs(pedestrian)) { if (!isOnActualStairs(pedestrian)) {
Logger.getLogger(this.getClass()) Logger.getLogger(this.getClass())
.error("Only pedestrians should get in here that are on actual Stairs -> Bug in code."); .error("Only pedestrians should get in here that are on actual Stairs -> Bug in code.");
......
...@@ -100,7 +100,7 @@ public class Scenario { ...@@ -100,7 +100,7 @@ public class Scenario {
} }
public AttributesAgent getAttributesPedestrian() { public AttributesAgent getAttributesPedestrian() {
return scenarioStore.topography.getAttributesPedestrian(); return scenarioStore.getTopography().getAttributesPedestrian();
} }
public AttributesSimulation getAttributesSimulation() { public AttributesSimulation getAttributesSimulation() {
...@@ -108,7 +108,7 @@ public class Scenario { ...@@ -108,7 +108,7 @@ public class Scenario {
} }
public Topography getTopography() { public Topography getTopography() {
return scenarioStore.topography; return scenarioStore.getTopography();
} }
public void setName(String name) { public void setName(String name) {
...@@ -124,7 +124,7 @@ public class Scenario { ...@@ -124,7 +124,7 @@ public class Scenario {
} }
public void setTopography(final Topography topography) { public void setTopography(final Topography topography) {
scenarioStore.topography = topography; scenarioStore.setTopography(topography);
} }
@Override @Override
......
...@@ -69,8 +69,7 @@ public class ScenarioRun implements Runnable { ...@@ -69,8 +69,7 @@ public class ScenarioRun implements Runnable {
public void run() { public void run() {
try { try {
logger.info(String.format("Initializing scenario. Start of scenario '%s'...", scenario.getName())); logger.info(String.format("Initializing scenario. Start of scenario '%s'...", scenario.getName()));
scenarioStore.getTopography().reset();
scenarioStore.topography.reset();
MainModelBuilder modelBuilder = new MainModelBuilder(scenarioStore); MainModelBuilder modelBuilder = new MainModelBuilder(scenarioStore);
modelBuilder.createModelAndRandom(); modelBuilder.createModelAndRandom();
......
...@@ -5,6 +5,8 @@ import java.util.ArrayList; ...@@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.io.JsonConverter; import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.Attributes;
...@@ -25,12 +27,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; ...@@ -25,12 +27,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
*/ */
public class ScenarioStore { public class ScenarioStore {
private static Logger logger = LogManager.getLogger(ScenarioStore.class);
public String name; public String name;
public String description; public String description;
public String mainModel; public String mainModel;
public List<Attributes> attributesList; public List<Attributes> attributesList;
public AttributesSimulation attributesSimulation; public AttributesSimulation attributesSimulation;
public Topography topography; private Topography topography;
public ScenarioStore(final String name, final String description, final String mainModel, final List<Attributes> attributesModel, public ScenarioStore(final String name, final String description, final String mainModel, final List<Attributes> attributesModel,
final AttributesSimulation attributesSimulation, final Topography topography) { final AttributesSimulation attributesSimulation, final Topography topography) {
...@@ -42,6 +45,15 @@ public class ScenarioStore { ...@@ -42,6 +45,15 @@ public class ScenarioStore {
this.topography = topography; this.topography = topography;
} }
public synchronized Topography getTopography() {
return topography;
}
public synchronized void setTopography(final Topography topography) {
//logger.info("setTopography:" + topography + ", thread:" + Thread.currentThread());
this.topography = topography;
}
public ScenarioStore(final String name) { public ScenarioStore(final String name) {
this(name, "", null, new ArrayList<>(), new AttributesSimulation(), new Topography()); this(name, "", null, new ArrayList<>(), new AttributesSimulation(), new Topography());
} }
......
...@@ -107,7 +107,7 @@ public class JsonConverter { ...@@ -107,7 +107,7 @@ public class JsonConverter {
vadereNode.set("attributesSimulation", StateJsonConverter.convertValue(scenarioStore.attributesSimulation, JsonNode.class)); vadereNode.set("attributesSimulation", StateJsonConverter.convertValue(scenarioStore.attributesSimulation, JsonNode.class));
// vadere > topography // vadere > topography
ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.