Commit 91956092 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add check for scenario attributes and move ScenarioChecker indicator to top

parent a00d5101
......@@ -330,6 +330,8 @@ ScenarioChecker.overlap.obstacle.target.warn=Target contains an obstacle. This s
ScenarioChecker.overlap.obstacle.source=Obstacle overlaps with a source. This setup will spawn pedestrians within the obstacle.
ScenarioChecker.overlap.obstacle.obstacle=Two obstacles overlap / is enclosed completely. Delete one for better performance.
ScenarioChecker.simAttr.simTimeStepWrong=simTimeStep parameter outside of allowed range.
ScenarioChecker.msg.ok=Scenario ok.
ScenarioChecker.msg.warn=Scenario contains warnings.
ScenarioChecker.msg.err=Scenario contains errors.
......
......@@ -321,6 +321,8 @@ ScenarioChecker.overlap.obstacle.target.warn=Ziel hat ein Hinderniss in sich. Di
ScenarioChecker.overlap.obstacle.source=Hinderniss \u00fcberdeckt Quelle. Die f\u00fchrt dazu, dass Pedestrians im Hinderniss erzeugt werden.
ScenarioChecker.overlap.obstacle.obstacle=Zwei identische bzw. eingeschlossene Obstacles gefunden. L\u00f6sche eins f\u00fcr bessere Performance
ScenarioChecker.simAttr.simTimeStepWrong=simTimeStep Parameter au\u00dferhalb des Definitionsbereichs.
ScenarioChecker.msg.ok=Scenario ok.
ScenarioChecker.msg.warn=Scenario hat Warnungen.
ScenarioChecker.msg.err=Scenario ist Fehlerhaft.
......
......@@ -7,6 +7,7 @@ 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;
import org.vadere.gui.projectview.view.ScenarioNamePanel;
import org.vadere.gui.projectview.view.ScenarioPanel;
import org.vadere.gui.projectview.view.VDialogManager;
import org.vadere.gui.projectview.view.VTable;
......@@ -42,7 +43,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 ScenarioNamePanel scenarioNamePanel; // to add or remove the "*" to indicate unsaved changes
private boolean showSimulationResultDialog;
public ProjectViewModel() {
......@@ -269,12 +270,12 @@ public class ProjectViewModel {
projectChangeListeners.add(listener);
}
public void setScenarioNameLabel(JLabel scenarioName) {
this.scenarioNameLabel = scenarioName;
public void setScenarioNamePanel(ScenarioNamePanel scenarioNamePanel) {
this.scenarioNamePanel = scenarioNamePanel;
}
public void setScenarioNameLabel(final String name) {
this.scenarioNameLabel.setText(name);
public void setScenarioNameLabelString(final String name) {
this.scenarioNamePanel.setScenarioName(name);
}
private class OutputRefresher implements Runnable {
......@@ -404,7 +405,7 @@ public class ProjectViewModel {
public void refreshScenarioNames() {
if (scenarioTable.getRowCount() > 0) {
scenarioTable.repaint();
scenarioNameLabel.setText(currentScenario.getDisplayName());
scenarioNamePanel.setScenarioName(currentScenario.getDisplayName());
}
}
......
......@@ -100,6 +100,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
private JMenu mntmRecentProjects;
private ProgressPanel progressPanel = new ProgressPanel();
private ScenarioPanel scenarioJPanel;
private ScenarioNamePanel scenarioNamePanel;
private boolean scenariosRunning = false;
private Set<Action> projectSpecificActions = new HashSet<>(); // actions that should only be enabled, when a project is loaded
private ProjectRunResultDialog projectRunResultDialog;
......@@ -137,7 +138,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
@Override
public void preScenarioRun(final Scenario scenario, final int scenariosLeft) {
EventQueue.invokeLater(() -> {
model.setScenarioNameLabel(scenario.getName());
model.setScenarioNameLabelString(scenario.getName());
repaint();
});
}
......@@ -676,15 +677,11 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
rightSidePanel.setLayout(new BorderLayout(0, 0));
contentPane.add(rightSidePanel, BorderLayout.CENTER);
JPanel ScenarioNamePanel = new JPanel();
rightSidePanel.add(ScenarioNamePanel, BorderLayout.NORTH);
scenarioNamePanel = new ScenarioNamePanel();
rightSidePanel.add(scenarioNamePanel, BorderLayout.NORTH);
JLabel scenarioName = new JLabel();
ScenarioNamePanel.add(scenarioName);
scenarioName.setHorizontalAlignment(SwingConstants.CENTER);
scenarioJPanel = new ScenarioPanel(scenarioName, model);
model.setScenarioNameLabel(scenarioName); // TODO [priority=low] [task=refactoring] breaking mvc pattern (?) - but I need access to refresh the scenarioName
scenarioJPanel = new ScenarioPanel(scenarioNamePanel, model);
model.setScenarioNamePanel(scenarioNamePanel); // TODO [priority=low] [task=refactoring] breaking mvc pattern (?) - but I need access to refresh the scenarioName
model.addProjectChangeListener(scenarioJPanel);
rightSidePanel.add(scenarioJPanel, BorderLayout.CENTER);
}
......
package org.vadere.gui.projectview.view;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.topographycreator.control.ActionScenarioChecker;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
......@@ -10,78 +9,68 @@ import java.awt.*;
import javax.swing.*;
public class ScenarioCheckerPanel extends JPanel {
public class ScenarioNamePanel extends JPanel {
private final static ImageIcon iconRed = new ImageIcon(Resources.class.getResource("/icons/light_red1.png"));
private final static ImageIcon iconYellow = new ImageIcon(Resources.class.getResource("/icons/light_yellow1.png"));
private final static ImageIcon iconGreen = new ImageIcon(Resources.class.getResource("/icons/light_green1.png"));
private JLabel lblmsg;
private JButton btnChecker;
private JLabel lblScenarioName;
private JButton btnScenarioChecker;
private ActionScenarioChecker action;
public ScenarioCheckerPanel(){
setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0));
lblmsg = new JLabel();
add(lblmsg);
btnChecker = new JButton(iconGreen);
btnChecker.setText("");
add(btnChecker);
public ScenarioNamePanel(){
btnScenarioChecker = new JButton(iconGreen);
btnScenarioChecker.setBorderPainted(false);
btnScenarioChecker.setBorder(null);
btnScenarioChecker.setMargin(new Insets(0, 0, 0, 0));
btnScenarioChecker.setContentAreaFilled(false);
btnScenarioChecker.addActionListener(e-> System.out.println("ddd"));
btnScenarioChecker.setRolloverIcon(iconRed);
action = new ActionScenarioChecker("ScenarioChecker", this);
add(btnScenarioChecker);
btnChecker.addActionListener(action);
setRed();
setMsgErr();
}
public void check(final Scenario scenario){
action.check(scenario);
lblScenarioName = new JLabel();
lblScenarioName.setHorizontalAlignment(SwingConstants.CENTER);
add(lblScenarioName);
}
public void setRed(){
btnChecker.setIcon(iconRed);
}
public void setYellow(){
btnChecker.setIcon(iconYellow);
public void setScenarioNameLabel(JLabel label){
removeAll();
lblScenarioName = label;
add(btnScenarioChecker);
add(lblScenarioName);
}
public void setGreen(){
btnChecker.setIcon(iconGreen);
public void setScenarioName(String scenarioName){
lblScenarioName.setText(scenarioName);
lblScenarioName.setHorizontalAlignment(SwingConstants.CENTER);
}
public void setMsgOK(){
lblmsg.setText(Messages.getString("ScenarioChecker.msg.ok"));
public void observerIDrawPanelModel(IDrawPanelModel model){
action.observerModel(model);
}
public void setMsgWarn(){
lblmsg.setText(Messages.getString("ScenarioChecker.msg.warn"));
public void check(final Scenario scenario){
action.check(scenario);
}
public void setMsgErr(){
lblmsg.setText(Messages.getString("ScenarioChecker.msg.err"));
public void stopObserver(){
btnScenarioChecker.removeActionListener(action);
action = new ActionScenarioChecker("ScenarioChecker", this);
btnScenarioChecker.addActionListener(action);
}
public void observerIDrawPanelModel(IDrawPanelModel model){
action.observerModel(model);
public void setRed(){
btnScenarioChecker.setIcon(iconRed);
}
public void stopObserver(){
btnChecker.removeActionListener(action);
action = new ActionScenarioChecker("ScenarioChecker", this);
btnChecker.addActionListener(action);
public void setYellow(){
btnScenarioChecker.setIcon(iconYellow);
}
private JButton addActionToToolbar(final JToolBar toolbar, final Action action,
final String toolTipProperty) {
JButton button = toolbar.add(action);
button.setBorderPainted(false);
button.setToolTipText(Messages.getString(toolTipProperty));
return button;
public void setGreen(){
btnScenarioChecker.setIcon(iconGreen);
}
}
......@@ -33,7 +33,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
private static final long serialVersionUID = 0L;
private JTabbedPane tabbedPane;
private final JLabel scenarioName;
private final ScenarioNamePanel scenarioNamePanel;
// tabs
private List<JMenu> menusInTabs = new ArrayList<>();
......@@ -43,7 +43,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
private DataProcessingView dataProcessingGUIview; // DataProcessing
private TopographyWindow topographyCreatorView; // Topography creator tab... OR:
private final PostvisualizationWindow postVisualizationView; // Post-Visualization tab, replaces Topography tab if output is selected
private ScenarioCheckerPanel scenarioCheckerPanel;
// during simulation-run, only this is shown instead of the tabs above:
private final OnlineVisualization onlineVisualization;
......@@ -59,8 +58,8 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
private static JEditorPane activeTopographyErrorMsg = null;
ScenarioPanel(JLabel scenarioName, ProjectViewModel model) {
this.scenarioName = scenarioName;
ScenarioPanel(ScenarioNamePanel scenarioNamePanel, ProjectViewModel model) {
this.scenarioNamePanel = scenarioNamePanel;
this.onlineVisualization = new OnlineVisualization(true);
this.postVisualizationView = new PostvisualizationWindow(model.getCurrentProjectPath());
this.model = model;
......@@ -83,14 +82,12 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
tabbedPane = new JTabbedPane(SwingConstants.TOP);
editCard.add(tabbedPane, BorderLayout.CENTER);
scenarioCheckerPanel = new ScenarioCheckerPanel();
editCard.add(scenarioCheckerPanel, BorderLayout.SOUTH);
tabbedPane.addChangeListener(e -> {
// remove ScenarioChecker listener if exists
scenarioCheckerPanel.stopObserver();
scenarioNamePanel.stopObserver();
int index = tabbedPane.getSelectedIndex();
if (index >= 0 && topographyFileView != null
......@@ -101,11 +98,11 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
&& index == tabbedPane.indexOfTab(Messages.getString("Tab.TopographyCreator.title"))
&& scenario != null) {
setTopography(scenario.getTopography());
scenarioCheckerPanel.observerIDrawPanelModel(topographyCreatorView.getPanelModel());
scenarioNamePanel.observerIDrawPanelModel(topographyCreatorView.getPanelModel());
return;
}
scenarioCheckerPanel.check(scenario);
scenarioNamePanel.check(scenario);
});
attributesSimulationView =
new TextView("/attributes", "default_directory_attributes", AttributeType.SIMULATION);
......@@ -231,7 +228,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
*/
public void setScenario(Scenario scenario, boolean isEditable) {
this.scenario = scenario;
this.scenarioName.setText(scenario.getDisplayName());
this.scenarioNamePanel.setScenarioName(scenario.getDisplayName());
if (!initialized) {
initialize();
......@@ -300,7 +297,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
}
public void clearScenarioView() {
scenarioName.setText("");
scenarioNamePanel.setScenarioName("");
initialized = false;
removeAll();
......
package org.vadere.gui.topographycreator.control;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.view.ScenarioCheckerPanel;
import org.vadere.gui.projectview.view.ScenarioNamePanel;
import org.vadere.gui.projectview.view.ScenarioPanel;
import org.vadere.gui.projectview.view.VDialogManager;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
......@@ -26,10 +26,10 @@ public class ActionScenarioChecker extends AbstractAction implements Observer {
private MsgDocument msgDocument;
private IDrawPanelModel model;
private ScenarioCheckerPanel view;
private ScenarioNamePanel view;
public
ActionScenarioChecker(String name, ScenarioCheckerPanel view) {
ActionScenarioChecker(String name, ScenarioNamePanel view) {
super(name);
this.errorMsg = new PriorityQueue<>();
this.warnMsg = new PriorityQueue<>();
......@@ -76,16 +76,13 @@ public class ActionScenarioChecker extends AbstractAction implements Observer {
addMsg(checker.checkBuildingStep());
view.setGreen();
view.setMsgOK();
if (warnMsg.size() > 0) {
view.setYellow();
view.setMsgWarn();
}
if (errorMsg.size() > 0) {
view.setRed();
view.setMsgErr();
}
}
......@@ -117,13 +114,16 @@ public class ActionScenarioChecker extends AbstractAction implements Observer {
private void msgToDocString(StringBuilder sb, ScenarioCheckerMessage msg, MsgDocument doc) {
sb.append("[");
msg.getMsgTarget().getTargets().forEach(t -> {
doc.makeLink(t, sb);
sb.append(", ");
});
sb.setLength(sb.length()-2);
sb.append("] ");
if (msg.hasTarget()){
sb.append("[");
msg.getMsgTarget().getTargets().forEach(t -> {
doc.makeLink(t, sb);
sb.append(", ");
});
sb.setLength(sb.length()-2);
sb.append("] ");
}
sb.append("Reason: ").append(Messages.getString(msg.getReason().getLocalMessageId()));
if (!msg.getReasonModifier().isEmpty()) {
......
......@@ -3,6 +3,7 @@ package org.vadere.simulator.util;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.checks.ScenarioCheckerTest;
import org.vadere.simulator.util.checks.simulation.SimulationTimeStepLengthCheck;
import org.vadere.simulator.util.checks.topography.PedestrianSpeedSetupCheck;
import org.vadere.simulator.util.checks.topography.StairTreadSanityCheck;
import org.vadere.simulator.util.checks.topography.TopographyOverlapCheck;
......@@ -55,6 +56,13 @@ public class ScenarioChecker {
ret.addAll(checkStairTreadSanity());
ret.addAll(checkPedestrianSpeedSetup());
ret.addAll(checkOverlap());
ret.addAll(checkSimulationAttribues());
return ret;
}
public PriorityQueue<ScenarioCheckerMessage> checkSimulationAttribues(){
PriorityQueue<ScenarioCheckerMessage> ret = new PriorityQueue<>();
ret.addAll(runCheck(new SimulationTimeStepLengthCheck()));
return ret;
}
......
......@@ -57,7 +57,15 @@ public class ScenarioCheckerMessage implements Comparable<ScenarioCheckerMessage
}
public boolean isMessageForAllElements(Integer... ids){
return msgTarget.affectsAllTargets(ids);
if (hasTarget()){
return msgTarget.affectsAllTargets(ids);
} else {
return false;
}
}
public boolean hasTarget(){
return msgTarget != null;
}
private Comparator<ScenarioCheckerMessage> sortByType() {
......
......@@ -8,6 +8,7 @@ package org.vadere.simulator.util;
*/
public enum ScenarioCheckerReason {
// Topography reasons
SOURCE_TARGET_ID_NOT_FOUND("ScenarioChecker.source.targetIdNotFound"),
SOURCE_NO_TARGET_ID_SET("ScenarioChecker.source.noTargetIdSet"),
SOURCE_NO_TARGET_ID_NO_SPAWN("ScenarioChecker.source.noTargetIdAndNoSpawn"),
......@@ -32,7 +33,10 @@ public enum ScenarioCheckerReason {
TARGET_OVERLAP("ScenarioChecker.target.overlap"),
PEDESTRIAN_SPEED_SETUP("ScenarioChecker.pedestrian.speedsetup"),
PEDESTRIAN_SPEED_NOT_LOGICAL("ScenarioChecker.pedestrian.speedNotLogical"),
PEDESTRIAN_SPEED_NEGATIVE("ScenarioChecker.pedestrian.speedIsNegative");
PEDESTRIAN_SPEED_NEGATIVE("ScenarioChecker.pedestrian.speedIsNegative"),
// Simulation attribute reasons
SIM_TIME_STEP_WRONG("ScenarioChecker.simAttr.simTimeStepWrong");
private String msgId;
......
......@@ -2,16 +2,29 @@ package org.vadere.simulator.util.checks.simulation;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.state.attributes.AttributesSimulation;
import java.util.PriorityQueue;
public class SimulationTimeStepLengthCheck extends AbstractScenarioCheck {
private final static double LOW_BOUND = 0.1;
private final static double HIGH_BOUND = 1.0;
@Override
public PriorityQueue<ScenarioCheckerMessage> runScenarioCheckerTest(Scenario scenario) {
PriorityQueue<ScenarioCheckerMessage> ret = new PriorityQueue<>();
AttributesSimulation simAttr = scenario.getAttributesSimulation();
//todo....
return null;
double simTimeStep = simAttr.getSimTimeStepLength();
if(simTimeStep < LOW_BOUND || simTimeStep > HIGH_BOUND){
ret.add(msgBuilder.simulationAttrError()
.reason(ScenarioCheckerReason.SIM_TIME_STEP_WRONG, String.format("[%3.1f - %3.1f]", LOW_BOUND, HIGH_BOUND))
.build());
}
return ret;
}
}
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