Commit d113b8f1 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add simulation result dialog and checkbox to turn it on/off

parent c9fafceb
......@@ -74,6 +74,7 @@ ProjectView.btnNewButton.text=New button
ProjectView.btnRunAllTests.text=Run all scenarios
ProjectView.mntmRunSelectetTests.text=Run selected scenario
ProjectView.mntmRunSelectedTests.text=Run selected scenarios
ProjectView.mntmSimulationResult.text=Show Simulation Result Dialog
ProjectView.btnPauseRunningTests.text=Pause running scenarios
ProjectView.btnRunSelectedTest.text=Run selected scenario
ProjectView.btnRunSelectedTest.toolTipText=Run selected scenario
......
......@@ -75,6 +75,7 @@ ProjectView.btnNewButton.text=Neuer Button
ProjectView.btnRunAllTests.text=Alle Szenarios ausf\u00FChren
ProjectView.mntmRunSelectetTests.text=Ausgew\u00E4hlte Szenarios ausf\u00FChren
ProjectView.mntmRunSelectedTests.text=Ausgew\u00E4hlte Szenarios ausf\u00FChren
ProjectView.mntmSimulationResult.text=Ergebnis Dialog anzeigen
ProjectView.btnPauseRunningTests.text=Laufende Szenarios pausieren
ProjectView.btnRunSelectedTest.text=Ausgew\u00E4hltes Szenario ausf\u00FChren
ProjectView.btnRunSelectedTest.toolTipText=Ausgew\u00E4hlten Szenario ausf\u00FChren
......
package org.vadere.gui.projectview.control;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.model.ProjectViewModel;
import java.awt.event.ActionEvent;
import java.util.prefs.Preferences;
import javax.swing.*;
public class ShowResultDialogAction extends AbstractAction {
ProjectViewModel model;
JCheckBoxMenuItem item;
public ShowResultDialogAction(final String name, final ProjectViewModel model, JCheckBoxMenuItem item) {
super(name);
this.model = model;
this.item = item;
}
@Override
public void actionPerformed(ActionEvent e) {
model.setShowSimulationResultDialog(item.getState());
Preferences.userNodeForPackage(VadereApplication.class).putBoolean("Project.simulationResult.show", item.getState());
}
}
......@@ -3,6 +3,7 @@ package org.vadere.gui.projectview.model;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.control.IOutputFileRefreshListener;
import org.vadere.gui.projectview.control.IProjectChangeListener;
import org.vadere.gui.projectview.view.ProjectView;
......@@ -21,6 +22,7 @@ import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
public class ProjectViewModel {
......@@ -42,6 +44,7 @@ public class ProjectViewModel {
private final Collection<IOutputFileRefreshListener> outputRefreshListeners;
private final Collection<IProjectChangeListener> projectChangeListeners;
private JLabel scenarioNameLabel; // to add or remove the "*" to indicate unsaved changes
private boolean showSimulationResultDialog;
public ProjectViewModel() {
this.outputTableModel = new OutputFileTableModel();
......@@ -50,6 +53,8 @@ public class ProjectViewModel {
this.projectChangeListeners = new LinkedList<>();
this.project = null;
this.refreshOutputExecutor = Executors.newSingleThreadExecutor();
this.showSimulationResultDialog = Preferences.userNodeForPackage(VadereApplication.class)
.getBoolean("Project.simulationResult.show", true);
}
public void deleteOutputFiles(final int[] rows) throws IOException {
......@@ -403,4 +408,11 @@ public class ProjectViewModel {
return currentScenario;
}
public boolean isShowSimulationResultDialog() {
return showSimulationResultDialog;
}
public void setShowSimulationResultDialog(boolean showSimulationResultDialog) {
this.showSimulationResultDialog = showSimulationResultDialog;
}
}
package org.vadere.gui.projectview.view;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.VadereProject;
......@@ -9,7 +12,15 @@ import java.util.LinkedList;
import javax.swing.*;
public class ProjectRunResultDialog implements ProjectFinishedListener {
private static Logger logger = LogManager.getLogger(ProjectRunResultDialog.class);
private final ProjectView projectView;
private final ProjectViewModel projectViewModel;
public ProjectRunResultDialog(ProjectView projectView, ProjectViewModel projectViewModel) {
this.projectView = projectView;
this.projectViewModel = projectViewModel;
}
@Override
public void preProjectRun(VadereProject project) {
......@@ -19,9 +30,24 @@ public class ProjectRunResultDialog implements ProjectFinishedListener {
@Override
public void postProjectRun(VadereProject project) {
LinkedList<SimulationResult> simulationResultList = project.getSimulationResults();
String title = "Simulation Result: " + simulationResultList.getFirst().getScenarioName();
String infoMessage = "TotalOverlap: " + simulationResultList.getFirst().getTotalOverlaps();
// todo parentComponten to ProjectView?????
JOptionPane.showMessageDialog(null, infoMessage, title, JOptionPane.INFORMATION_MESSAGE);
StringBuilder sb = new StringBuilder();
for (SimulationResult res : simulationResultList) {
sb.append(res.getScenarioName()).append(":\n")
.append(" Runtime: ").append(res.getRunTimeAsString()).append("\n")
.append(" Overlaps: ").append(res.getTotalOverlaps()).append("\n")
.append(" State: ").append(res.getState()).append("\n\n");
}
String title = simulationResultList.size() > 1 ? "Simulation Results" : "Simulation Result";
String infoMessage = sb.toString();
if (projectViewModel.isShowSimulationResultDialog()){
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(projectView, infoMessage, title, JOptionPane.INFORMATION_MESSAGE);
});
} else {
logger.info(sb.toString());
}
}
}
package org.vadere.gui.projectview.view;
import org.apache.commons.codec.language.bm.Lang;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Language;
......@@ -32,6 +31,7 @@ import org.vadere.gui.projectview.control.ActionSeeDiscardChanges;
import org.vadere.gui.projectview.control.ActionShowAboutDialog;
import org.vadere.gui.projectview.control.IOutputFileRefreshListener;
import org.vadere.gui.projectview.control.IProjectChangeListener;
import org.vadere.gui.projectview.control.ShowResultDialogAction;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.model.ProjectViewModel.OutputBundle;
import org.vadere.gui.projectview.model.ProjectViewModel.ScenarioBundle;
......@@ -42,7 +42,6 @@ import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.SingleScenarioFinishedListener;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.io.IOOutput;
import org.vadere.util.io.IOUtils;
import java.awt.*;
......@@ -103,7 +102,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
private ScenarioPanel scenarioJPanel;
private boolean scenariosRunning = false;
private Set<Action> projectSpecificActions = new HashSet<>(); // actions that should only be enabled, when a project is loaded
private ProjectRunResultDialog projectRunResultDialog = new ProjectRunResultDialog();
private ProjectRunResultDialog projectRunResultDialog;
// ####################### Part of the control this should also be part of another class
// ##################
......@@ -304,6 +303,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
model.addOutputFileRefreshListener(this);
model.addProjectChangeListener(this);
this.model = model;
projectRunResultDialog = new ProjectRunResultDialog(this, model);
setTitle("Vadere GUI");
setBounds(100, 100, 1000, 600);
......@@ -385,6 +385,15 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
addToProjectSpecificActions(saveProjectAsAction);
mnFile.add(mntmSaveAs);
// Checkbox menu item to turn off result dialog of project run.
mnFile.addSeparator();
boolean showDialogDefault = Preferences.userNodeForPackage(VadereApplication.class)
.getBoolean("Project.simulationResult.show", false);
JCheckBoxMenuItem showResultDialogMenu = new JCheckBoxMenuItem(Messages.getString("ProjectView.mntmSimulationResult.text"), null, showDialogDefault);
Action showResultDialogMenuAction = new ShowResultDialogAction(Messages.getString("ProjectView.mntmSimulationResult.text"), model, showResultDialogMenu);
showResultDialogMenu.setAction(showResultDialogMenuAction);
mnFile.add(showResultDialogMenu);
JMenuItem mntmExit = new JMenuItem(closeApplicationAction);
mnFile.addSeparator();
mnFile.add(mntmExit);
......
......@@ -7,6 +7,14 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "density.txt",
"processors" : [ 1 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out.txt",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "out1.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianDensityCountingProcessor",
......@@ -19,6 +27,20 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 4
}
} ],
"isTimestamped" : true
},
......
......@@ -11,6 +11,10 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.PedestrianIdOutputFile",
"filename" : "waitingTimes.txt",
"processors" : [ 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out.txt",
"processors" : [ 3 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -28,6 +32,20 @@
"type" : "RECTANGLE"
}
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
} ],
"isTimestamped" : true
},
......
......@@ -2,7 +2,6 @@
"name" : "rimea_11_exit_selection",
"description" : "",
"release" : "0.4",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ ],
"processors" : [ ],
......
......@@ -2,7 +2,6 @@
"name" : "rimea_14_select_route",
"description" : "",
"release" : "0.4",
"commithash" : "warning: no commit hash",
"processWriters" : {
"files" : [ ],
"processors" : [ ],
......
......@@ -11,6 +11,7 @@ import org.vadere.simulator.models.potential.PotentialFieldModel;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesAgent;
......@@ -65,9 +66,10 @@ public class Simulation {
private final Topography topography;
private final ProcessorManager processorManager;
private final SourceControllerFactory sourceControllerFactory;
private SimulationResult simulationResult;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager) {
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager, SimulationResult simulationResult) {
this.name = name;
this.mainModel = mainModel;
this.scenarioStore = scenarioStore;
......@@ -79,6 +81,7 @@ public class Simulation {
this.runTimeInSec = attributesSimulation.getFinishTime();
this.startTimeInSec = startTimeInSec;
this.simTimeInSec = startTimeInSec;
this.simulationResult = simulationResult;
this.models = mainModel.getSubmodels();
this.sourceControllerFactory = mainModel.getSourceControllerFactory();
......@@ -229,6 +232,7 @@ public class Simulation {
if (Thread.interrupted()) {
runSimulation = false;
simulationResult.setState("Simulation interrupted");
logger.info("Simulation interrupted.");
}
}
......
......@@ -114,9 +114,10 @@ public class ScenarioRun implements Runnable {
sealAllAttributes();
// Run simulation main loop from start time = 0 seconds
simulation = new Simulation(mainModel, 0, scenarioStore.getName(), scenarioStore, passiveCallbacks, random, processorManager);
simulation = new Simulation(mainModel, 0, scenarioStore.getName(), scenarioStore, passiveCallbacks, random, processorManager, simulationResult);
}
simulation.run();
simulationResult.setState("SimulationRun completed");
} catch (Exception e) {
throw new RuntimeException("Simulation failed.", e);
......
......@@ -26,7 +26,7 @@ public class SimulationResult {
startTime = Instant.now();
}
public void stopTime(){
runTime = Duration.between(Instant.now(), startTime);
runTime = Duration.between(startTime, Instant.now());
}
......@@ -62,4 +62,14 @@ public class SimulationResult {
public void setState(String state) {
this.state = state;
}
@Override
public String toString() {
return "SimulationResult{" +
"scenarioName='" + scenarioName + '\'' +
", runTime=" + runTime +
", totalOverlaps=" + totalOverlaps +
", state='" + state + '\'' +
'}';
}
}
......@@ -282,9 +282,11 @@ public class VadereProject {
simulationResults.add(currentScenarioRun.getSimulationResult());
if (scenariosLeft.isEmpty()) {
simulationResults.stream().forEach(res -> logger.info(res.toString()));
for (ProjectFinishedListener listener : projectFinishedListener) {
listener.postProjectRun(VadereProject.this);
}
resetState();
} else {
prepareAndStartScenarioRunThread();
}
......@@ -298,4 +300,8 @@ public class VadereProject {
public void setProjectOutput(ProjectOutput projectOutput) {
this.projectOutput = projectOutput;
}
public void resetState() {
simulationResults = new LinkedList<>();
}
}
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