diff --git a/VadereGui/src/org/vadere/gui/components/view/ScenarioElementView.java b/VadereGui/src/org/vadere/gui/components/view/ScenarioElementView.java index bd2268a6e0e69b3be73f044f29ffa8b869a7d882..83419168ebddbd5fcd0ed6e02b42696287d151df 100644 --- a/VadereGui/src/org/vadere/gui/components/view/ScenarioElementView.java +++ b/VadereGui/src/org/vadere/gui/components/view/ScenarioElementView.java @@ -106,12 +106,14 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen } @Override - public void removeUpdate(DocumentEvent e) { + public void removeUpdate(DocumentEvent e) + { updateModel(); } @Override public void changedUpdate(DocumentEvent e) { + updateModel(); } }; @@ -126,7 +128,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen ScenarioElement element = panelModel.getSelectedElement(); if (element != null) { String json = txtrTextfiletextarea.getText(); - + //logger.info(json); if (json.length() == 0) return; diff --git a/VadereGui/src/org/vadere/gui/projectview/VadereApplication.java b/VadereGui/src/org/vadere/gui/projectview/VadereApplication.java index 51221a1b4c96e254f3c3f860ec6d60b9e5e0760e..498b2261de6603bbd583544e1493000ab104f61e 100644 --- a/VadereGui/src/org/vadere/gui/projectview/VadereApplication.java +++ b/VadereGui/src/org/vadere/gui/projectview/VadereApplication.java @@ -6,6 +6,7 @@ import org.vadere.gui.projectview.view.ProjectView; import org.vadere.state.attributes.models.AttributesBHM; import org.vadere.util.io.IOUtils; +import java.awt.*; import java.io.IOException; import java.util.prefs.BackingStoreException; import java.util.prefs.InvalidPreferencesFormatException; diff --git a/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java b/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java index f9fb12c595de17464ea5712d841eb561b15235fc..c2cb0d0d414b5652365359d241e613dbb2e0ce24 100644 --- a/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java +++ b/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java @@ -109,12 +109,14 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing // ################## @Override public void postProjectRun(final VadereProject scenario) { - scenariosRunning = false; - model.refreshOutputTable(); - setScenariosRunning(false); - progressPanel.setData(Messages.getString("ProgressPanelDone.text"), 100); - scenarioJPanel.showEditScenario(); - selectCurrentScenarioRunManager(); + EventQueue.invokeLater(() -> { + scenariosRunning = false; + model.refreshOutputTable(); + setScenariosRunning(false); + progressPanel.setData(Messages.getString("ProgressPanelDone.text"), 100); + scenarioJPanel.showEditScenario(); + selectCurrentScenarioRunManager(); + }); } private void selectCurrentScenarioRunManager() { @@ -127,58 +129,71 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing @Override public void preProjectRun(final VadereProject project) { - setScenariosRunning(true); - progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 0); + EventQueue.invokeLater(() -> { + setScenariosRunning(true); + progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 0); + }); } @Override public void preScenarioRun(final Scenario scenario, final int scenariosLeft) { - model.setScenarioNameLabel(scenario.getName()); - repaint(); + EventQueue.invokeLater(() -> { + model.setScenarioNameLabel(scenario.getName()); + repaint(); + }); } @Override public void postScenarioRun(final Scenario cloneScenario, final int scenarioLeft) { - // take the original! - replace(cloneScenario, VadereState.INITIALIZED); - - // model.refreshOutputTable(); - // find index of scenario - int totalScenariosCount = model.getProject().getScenarios().size(); - int doneScenariosCount = totalScenariosCount - scenarioLeft; - progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 100 * doneScenariosCount - / totalScenariosCount); - logger.info(String.format("scenario %s finished", cloneScenario.getName())); + EventQueue.invokeLater(() -> { + replace(cloneScenario, VadereState.INITIALIZED); + + // model.refreshOutputTable(); + // find index of scenario + int totalScenariosCount = model.getProject().getScenarios().size(); + int doneScenariosCount = totalScenariosCount - scenarioLeft; + progressPanel.setData(Messages.getString("ProgressPanelWorking.text"), 100 * doneScenariosCount + / totalScenariosCount); + logger.info(String.format("scenario %s finished", cloneScenario.getName())); + }); } @Override public void scenarioStarted(final Scenario cloneScenario, final int scenariosLeft) { // take the original! - replace(cloneScenario, VadereState.RUNNING); + EventQueue.invokeLater(() -> { + replace(cloneScenario, VadereState.RUNNING); + }); } @Override public void scenarioPaused(final Scenario cloneScenario, final int scenariosLeft) { // take the original! - replace(cloneScenario, VadereState.PAUSED); + EventQueue.invokeLater(() -> { + replace(cloneScenario, VadereState.PAUSED); + }); } @Override public void scenarioInterrupted(final Scenario scenario, final int scenariosLeft) { - replace(scenario, VadereState.INTERRUPTED); - setScenariosRunning(false); - selectCurrentScenarioRunManager(); - logger.info(String.format("all running scenarios interrupted")); + EventQueue.invokeLater(() -> { + replace(scenario, VadereState.INTERRUPTED); + setScenariosRunning(false); + selectCurrentScenarioRunManager(); + logger.info(String.format("all running scenarios interrupted")); + }); } @Override public void error(final Scenario scenario, final int scenarioLefts, final Throwable throwable) { - replace(scenario, VadereState.INTERRUPTED); - new Thread( - () -> { - IOUtils.errorBox(Messages.getString("ProjectView.simulationRunErrorDialog.text") + " " + scenario - + ": " + throwable, Messages.getString("ProjectView.simulationRunErrorDialog.title")); - }).start(); + EventQueue.invokeLater(() -> { + replace(scenario, VadereState.INTERRUPTED); + new Thread( + () -> { + IOUtils.errorBox(Messages.getString("ProjectView.simulationRunErrorDialog.text") + " " + scenario + + ": " + throwable, Messages.getString("ProjectView.simulationRunErrorDialog.title")); + }).start(); + }); } private void replace(final Scenario scenarioRM, final VadereState state) { @@ -190,21 +205,27 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing @Override public void preRefresh() { - outputTable.setEnabled(false); + EventQueue.invokeLater(() -> { + outputTable.setEnabled(false); + }); } @Override public void postRefresh() { - if (!scenariosRunning) - outputTable.setEnabled(true); + EventQueue.invokeLater(() -> { + if (!scenariosRunning) + outputTable.setEnabled(true); + }); } @Override public void projectChanged(final VadereProject project) { - setTitle(); - model.getProject().addProjectFinishedListener(this); - model.getProject().addSingleScenarioFinishedListener(this); - model.getProject().addProjectFinishedListener(scenarioJPanel); + EventQueue.invokeLater(() -> { + setTitle(); + model.getProject().addProjectFinishedListener(this); + model.getProject().addSingleScenarioFinishedListener(this); + model.getProject().addProjectFinishedListener(scenarioJPanel); + }); } @Override @@ -217,21 +238,23 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing * Launch the application. */ public static void start() { - try { - // Set Java L&F from system - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException - | IllegalAccessException e) { - IOUtils.errorBox("The system look and feel could not be loaded.", "Error setLookAndFeel"); - } - // show GUI - ProjectViewModel model = new ProjectViewModel(); - ProjectView frame = new ProjectView(model); - frame.setProjectSpecificActionsEnabled(false); - frame.setVisible(true); - frame.setSize(1200, 800); - - frame.openLastUsedProject(model); + EventQueue.invokeLater(() -> { + try { + // Set Java L&F from system + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException + | IllegalAccessException e) { + IOUtils.errorBox("The system look and feel could not be loaded.", "Error setLookAndFeel"); + } + // show GUI + ProjectViewModel model = new ProjectViewModel(); + ProjectView frame = new ProjectView(model); + frame.setProjectSpecificActionsEnabled(false); + frame.setVisible(true); + frame.setSize(1200, 800); + + frame.openLastUsedProject(model); + }); } private void openLastUsedProject(final ProjectViewModel model) { diff --git a/VadereModelTests/TestStairs/scenarios/stairs_diagonal_1_+1.scenario b/VadereModelTests/TestStairs/scenarios/stairs_diagonal_1_+1.scenario index 5862f0abbf15d820660e4e1d2885a67ec7266e03..caf474d0bd8d2efd449106572283c77351277020 100644 --- a/VadereModelTests/TestStairs/scenarios/stairs_diagonal_1_+1.scenario +++ b/VadereModelTests/TestStairs/scenarios/stairs_diagonal_1_+1.scenario @@ -71,7 +71,7 @@ "finishTime" : 70.0, "simTimeStepLength" : 0.4, "realTimeSimTimeRatio" : 0.1, - "writeSimulationData" : true, + "writeSimulationData" : false, "visualizationEnabled" : true, "printFPS" : false, "needsBoundary" : false, diff --git a/VadereSimulator/src/org/vadere/simulator/control/Simulation.java b/VadereSimulator/src/org/vadere/simulator/control/Simulation.java index d008896bc9d82a33145a5bc70363d2284596e8ed..20d554c318d7acaf9d917487c5a964283ddb0f54 100644 --- a/VadereSimulator/src/org/vadere/simulator/control/Simulation.java +++ b/VadereSimulator/src/org/vadere/simulator/control/Simulation.java @@ -76,10 +76,10 @@ public class Simulation { this.mainModel = mainModel; this.scenarioStore = scenarioStore; this.attributesSimulation = scenarioStore.attributesSimulation; - this.attributesAgent = scenarioStore.topography.getAttributesPedestrian(); + this.attributesAgent = scenarioStore.getTopography().getAttributesPedestrian(); this.sourceControllers = new LinkedList<>(); this.targetControllers = new LinkedList<>(); - this.topography = scenarioStore.topography; + this.topography = scenarioStore.getTopography(); this.runTimeInSec = attributesSimulation.getFinishTime(); this.startTimeInSec = startTimeInSec; this.simTimeInSec = startTimeInSec; diff --git a/VadereSimulator/src/org/vadere/simulator/entrypoints/ScenarioBuilder.java b/VadereSimulator/src/org/vadere/simulator/entrypoints/ScenarioBuilder.java index 16c1be2735f82d4942161587a4eb90685b0d14df..e1a74f50486a8852077db33c8e8611c7bb0ac956 100644 --- a/VadereSimulator/src/org/vadere/simulator/entrypoints/ScenarioBuilder.java +++ b/VadereSimulator/src/org/vadere/simulator/entrypoints/ScenarioBuilder.java @@ -66,20 +66,20 @@ public class ScenarioBuilder { store.attributesSimulation = (AttributesSimulation) builder.build(); } else if(AttributesAgent.class == clazz){ - builder = new AttributesBuilder<>((E)store.topography.getAttributesPedestrian()); + builder = new AttributesBuilder<>((E)store.getTopography().getAttributesPedestrian()); builder.setField(fieldName, value); setAttributesAgent((AttributesAgent) builder.build()); } else if(AttributesCar.class == clazz){ - builder = new AttributesBuilder<>((E)store.topography.getAttributesCar()); + builder = new AttributesBuilder<>((E)store.getTopography().getAttributesCar()); builder.setField(fieldName, value); setAttributesCar((AttributesCar) builder.build()); } else if(AttributesTopography.class == clazz){ - builder = new AttributesBuilder<>((E)store.topography.getAttributes()); + builder = new AttributesBuilder<>((E)store.getTopography().getAttributes()); builder.setField(fieldName, value); ReflectionAttributeModifier reflectionAttributeModifier = new ReflectionAttributeModifier(); - reflectionAttributeModifier.setAttributes(store.topography, builder.build()); + reflectionAttributeModifier.setAttributes(store.getTopography(), builder.build()); } else { builder = new AttributesBuilder<>(store.getAttributes(clazz)); @@ -92,9 +92,9 @@ public class ScenarioBuilder { private void setAttributesCar(@NotNull final AttributesCar attributesCar) { Field field; try { - field = store.topography.getClass().getDeclaredField("attributesCar"); + field = store.getTopography().getClass().getDeclaredField("attributesCar"); field.setAccessible(true); - field.set(store.topography, attributesCar); + field.set(store.getTopography(), attributesCar); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); logger.error(e); @@ -104,9 +104,9 @@ public class ScenarioBuilder { private void setAttributesAgent(@NotNull final AttributesAgent attributesAgent) { Field field; try { - field = store.topography.getClass().getDeclaredField("attributesPedestrian"); + field = store.getTopography().getClass().getDeclaredField("attributesPedestrian"); field.setAccessible(true); - field.set(store.topography, attributesAgent); + field.set(store.getTopography(), attributesAgent); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); logger.error(e); diff --git a/VadereSimulator/src/org/vadere/simulator/models/MainModelBuilder.java b/VadereSimulator/src/org/vadere/simulator/models/MainModelBuilder.java index 59d260a2f678268e3c49c45f97ac366cd202983a..98e4af9e3633fb4da6bc9108c8108bd915d2171b 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/MainModelBuilder.java +++ b/VadereSimulator/src/org/vadere/simulator/models/MainModelBuilder.java @@ -48,8 +48,8 @@ public class MainModelBuilder { String mainModelName = scenarioStore.mainModel; DynamicClassInstantiator instantiator = new DynamicClassInstantiator<>(); MainModel mainModel = instantiator.createObject(mainModelName); - mainModel.initialize(scenarioStore.attributesList, scenarioStore.topography, - scenarioStore.topography.getAttributesPedestrian(), random); + mainModel.initialize(scenarioStore.attributesList, scenarioStore.getTopography(), + scenarioStore.getTopography().getAttributesPedestrian(), random); return mainModel; } diff --git a/VadereSimulator/src/org/vadere/simulator/models/osm/stairOptimization/StairStepOptimizer.java b/VadereSimulator/src/org/vadere/simulator/models/osm/stairOptimization/StairStepOptimizer.java index ab196cb0d1cfe4745230a44587e6f4834c3335c3..63c3508a620b43e465e471ce1b6883054714ae0f 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/osm/stairOptimization/StairStepOptimizer.java +++ b/VadereSimulator/src/org/vadere/simulator/models/osm/stairOptimization/StairStepOptimizer.java @@ -4,9 +4,11 @@ package org.vadere.simulator.models.osm.stairOptimization; +import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.vadere.simulator.models.osm.PedestrianOSM; 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.Tread; import org.vadere.util.geometry.Vector2D; @@ -27,6 +29,8 @@ public class StairStepOptimizer implements StepCircleOptimizer { private Stairs stairs; + private Logger logger = LogManager.getLogger(StairStepOptimizer.class); + private final double tol_equal_values = 1E-4; public StairStepOptimizer(Stairs s) { @@ -35,7 +39,7 @@ public class StairStepOptimizer implements StepCircleOptimizer { @Override public VPoint getNextPosition(PedestrianOSM pedestrian, Shape reachableArea) { - + //logger.info(stairs.getAttributes().getUpwardDirection()); if (!isOnActualStairs(pedestrian)) { Logger.getLogger(this.getClass()) .error("Only pedestrians should get in here that are on actual Stairs -> Bug in code."); diff --git a/VadereSimulator/src/org/vadere/simulator/projects/Scenario.java b/VadereSimulator/src/org/vadere/simulator/projects/Scenario.java index 732078671a805020aa186263b389e72f6668880c..c6a35fd6d34b148e8ac0fe8d3e316fe27c29a114 100644 --- a/VadereSimulator/src/org/vadere/simulator/projects/Scenario.java +++ b/VadereSimulator/src/org/vadere/simulator/projects/Scenario.java @@ -100,7 +100,7 @@ public class Scenario { } public AttributesAgent getAttributesPedestrian() { - return scenarioStore.topography.getAttributesPedestrian(); + return scenarioStore.getTopography().getAttributesPedestrian(); } public AttributesSimulation getAttributesSimulation() { @@ -108,7 +108,7 @@ public class Scenario { } public Topography getTopography() { - return scenarioStore.topography; + return scenarioStore.getTopography(); } public void setName(String name) { @@ -124,7 +124,7 @@ public class Scenario { } public void setTopography(final Topography topography) { - scenarioStore.topography = topography; + scenarioStore.setTopography(topography); } @Override diff --git a/VadereSimulator/src/org/vadere/simulator/projects/ScenarioRun.java b/VadereSimulator/src/org/vadere/simulator/projects/ScenarioRun.java index d12e7c33d69eabe638606313b89e92d56d603db4..4b811609fe4ea54c2a31bf397af8f1c5a263ce86 100644 --- a/VadereSimulator/src/org/vadere/simulator/projects/ScenarioRun.java +++ b/VadereSimulator/src/org/vadere/simulator/projects/ScenarioRun.java @@ -69,8 +69,7 @@ public class ScenarioRun implements Runnable { public void run() { try { logger.info(String.format("Initializing scenario. Start of scenario '%s'...", scenario.getName())); - - scenarioStore.topography.reset(); + scenarioStore.getTopography().reset(); MainModelBuilder modelBuilder = new MainModelBuilder(scenarioStore); modelBuilder.createModelAndRandom(); diff --git a/VadereSimulator/src/org/vadere/simulator/projects/ScenarioStore.java b/VadereSimulator/src/org/vadere/simulator/projects/ScenarioStore.java index 774991a6a7f7470b66783373d9d51c9b1bf0bc72..55bb5ea207b079f49582dc2bf5c706fe50605e6d 100644 --- a/VadereSimulator/src/org/vadere/simulator/projects/ScenarioStore.java +++ b/VadereSimulator/src/org/vadere/simulator/projects/ScenarioStore.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.vadere.simulator.projects.io.JsonConverter; import org.vadere.state.attributes.Attributes; @@ -25,12 +27,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; */ public class ScenarioStore { + private static Logger logger = LogManager.getLogger(ScenarioStore.class); public String name; public String description; public String mainModel; public List attributesList; public AttributesSimulation attributesSimulation; - public Topography topography; + private Topography topography; public ScenarioStore(final String name, final String description, final String mainModel, final List attributesModel, final AttributesSimulation attributesSimulation, final Topography topography) { @@ -42,6 +45,15 @@ public class ScenarioStore { 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) { this(name, "", null, new ArrayList<>(), new AttributesSimulation(), new Topography()); } diff --git a/VadereSimulator/src/org/vadere/simulator/projects/io/JsonConverter.java b/VadereSimulator/src/org/vadere/simulator/projects/io/JsonConverter.java index ae910470731fdd6b8c609de5130087d9157bae1a..2a0262396e74fda47b925c8e9fe56989c3a9dcb6 100644 --- a/VadereSimulator/src/org/vadere/simulator/projects/io/JsonConverter.java +++ b/VadereSimulator/src/org/vadere/simulator/projects/io/JsonConverter.java @@ -107,7 +107,7 @@ public class JsonConverter { vadereNode.set("attributesSimulation", StateJsonConverter.convertValue(scenarioStore.attributesSimulation, JsonNode.class)); // vadere > topography - ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.topography); + ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.getTopography()); vadereNode.set("topography", topographyNode); return vadereNode; @@ -121,7 +121,7 @@ public class JsonConverter { public static ScenarioStore cloneScenarioStore(ScenarioStore scenarioStore) throws IOException { JsonNode attributesSimulationNode = StateJsonConverter.convertValue(scenarioStore.attributesSimulation, JsonNode.class); ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.attributesList); - ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.topography); + ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.getTopography()); return new ScenarioStore(scenarioStore.name, scenarioStore.description, scenarioStore.mainModel, StateJsonConverter.deserializeAttributesListFromNode(attributesModelNode), StateJsonConverter.deserializeAttributesSimulationFromNode(attributesSimulationNode), diff --git a/VadereState/src/org/vadere/state/scenario/Stairs.java b/VadereState/src/org/vadere/state/scenario/Stairs.java index 5c5a988f6fcff699e53674834c1ca9cf04e138f8..639c90a3550e1e603272b0baa508131a42d20821 100644 --- a/VadereState/src/org/vadere/state/scenario/Stairs.java +++ b/VadereState/src/org/vadere/state/scenario/Stairs.java @@ -5,6 +5,8 @@ import java.awt.geom.Path2D; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; import org.vadere.state.attributes.scenario.AttributesStairs; import org.vadere.state.types.ScenarioElementType; import org.vadere.util.geometry.shapes.VLine; @@ -14,6 +16,7 @@ import org.vadere.util.geometry.shapes.VShape; public class Stairs extends ScenarioElement { + private static Logger logger = LogManager.getLogger(Stairs.class); public static class Tread { public final VLine treadline;