Commit b86cc079 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Added new scenario element "TargetChanger" ("TargetChangerController" and...

Added new scenario element "TargetChanger" ("TargetChangerController" and "SettingsDialog" must be still adapted)
parent c2f57685
......@@ -237,6 +237,7 @@ SettingsDialog.chbUseRandomColors.text=Random Coloring
SettingsDialog.chbHideVoronoiDiagram.text=Hide VoronoiDiagram
SettingsDialog.chbShowObstacles.text=Show Obstacles
SettingsDialog.chbShowTargets.text=Show Targets
SettingsDialog.chbShowTargetChangers.text=Show Target Changers
SettingsDialog.chbShowSources.text=Show Sources
SettingsDialog.chbShowAbsorbingAreas.text=Show Absorbing Areas
SettingsDialog.chbShowStairs.text=Show Stairs
......@@ -283,6 +284,7 @@ SettingsDialog.lblCellWidth.text=Cell Width
SettingsDialog.btnClose.text=Close
SettingsDialog.lblDensityColor.text=Density
SettingsDialog.lblAbsorbingAreaColor.text=Absorbing Area
SettingsDialog.lblTargetChanger.text=Target Changer
SettingsDialog.lblStair.text=Stair
SettingsDialog.lblPedestrianNoTarget.text=Without Target (-1)
ProjectView.menuOpenFloorFieldFile.title=Add Floor Field File...
......@@ -322,6 +324,7 @@ TopographyCreator.btnTranslation.tooltip=Translate Topography
TopographyCreator.btnElementTranslation.tooltip=Translate Topography Elements
TopographyCreator.btnInsertObstacle.tooltip=Obstacle
TopographyCreator.btnInsertTarget.tooltip=Target
TopographyCreator.btnInsertTargetChanger.tooltip=Target Changer
TopographyCreator.btnInsertAbsorbingArea.tooltip=Absorbing Area
TopographyCreator.btnInsertSource.tooltip=Source
TopographyCreator.btnInsertStairs.tooltip=Stairs
......
......@@ -233,6 +233,7 @@ SettingsDialog.chbUseRandomColors.text=Zuf\u00E4llige Farben
SettingsDialog.chbHideVoronoiDiagram.text=Voronoi-Diagramm nicht anzeigen
SettingsDialog.chbShowObstacles.text=Hindernisse anzeigen
SettingsDialog.chbShowTargets.text=Ziele anzeigen
SettingsDialog.chbShowTargetChangers.text=Ziel\u00E4nderungen anzeigen
SettingsDialog.chbShowSources.text=Quellen anzeigen
SettingsDialog.chbShowAbsorbingAreas.text=Absorbierende Bereiche anzeigen
SettingsDialog.chbShowMeasurementAreas.text=Messbereich anzeigen
......@@ -278,6 +279,7 @@ SettingsDialog.lblCellWidth.text=Zellbreite
SettingsDialog.btnClose.text=Schlie\u00dfen
SettingsDialog.lblDensityColor.text=Dichte
SettingsDialog.lblAbsorbingAreaColor.text=Absorbierender Bereich
SettingsDialog.lblTargetChanger.text=Ziel\u00e4nderung
SettingsDialog.lblStair.text=Treppe
SettingsDialog.lblPedestrianNoTarget.text=Ohne Ziel (-1)
SettingsDialog.menuOpenFloorFieldFile.title=Floor Field-Datei hinzuf\u00fcgen...
......@@ -312,6 +314,7 @@ TopographyCreator.btnCutTopography.tooltip=Szenario ausschneiden
TopographyCreator.btnInsertPedestrian.tooltip=Fu\u00dfg\u00e4nger
TopographyCreator.btnInsertObstacle.tooltip=Hindernis
TopographyCreator.btnInsertTarget.tooltip=Ziel
TopographyCreator.btnInsertTargetChanger.tooltip=Zielanpassung
TopographyCreator.btnInsertAbsorbingArea.tooltip=Absorbierender Bereich
TopographyCreator.btnTopographyBound.tooltip=Topographie Grenze
TopographyCreator.btnMergeWithConvexHull.tooltip=Verbinde mit Convex H\u00fclle
......
package org.vadere.gui.components.control.simulation;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import javax.swing.*;
import java.awt.*;
public class ActionSetTargetChangerColor extends ActionSetColor {
public ActionSetTargetChangerColor(String name, SimulationModel<? extends DefaultSimulationConfig> model, JPanel coloredPanel) {
super(name, model, coloredPanel);
}
@Override
protected void saveColor(Color color) {
model.config.setTargetChangerColor(color);
}
}
......@@ -6,6 +6,7 @@ public class DefaultConfig {
private Color obstacleColor = new Color(0.7f,0.7f,0.7f);
private Color sourceColor = new Color(0.3333333333333333f, 0.6588235294117647f, 0.40784313725490196f);
private Color targetColor = new Color(0.8666666666666667f, 0.51764705882352946f, 0.32156862745098042f);
private Color targetChangerColor = new Color(1.00f, 0.60f, 0.00f);
private Color absorbingAreaColor = new Color(0.76863f,0.30588f, 0.32157f);
private Color densityColor = Color.RED;
private Color stairColor = new Color(0.5058823529411764f, 0.4470588235294118f, 0.6980392156862745f);
......@@ -19,6 +20,7 @@ public class DefaultConfig {
public DefaultConfig(final DefaultConfig config) {
this.sourceColor = config.sourceColor;
this.targetColor = config.targetColor;
this.targetChangerColor = config.targetChangerColor;
this.absorbingAreaColor = config.absorbingAreaColor;
this.densityColor = config.densityColor;
this.obstacleColor = config.obstacleColor;
......@@ -84,6 +86,15 @@ public class DefaultConfig {
setChanged();
}
public Color getTargetChangerColor() {
return targetChangerColor;
}
public void setTargetChangerColor(final Color targetChangerColor) {
this.targetChangerColor = targetChangerColor;
setChanged();
}
public Color getAbsorbingAreaColor() {
return absorbingAreaColor;
}
......
......@@ -103,6 +103,9 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
case TARGET:
c = getConfig().getTargetColor();
break;
case TARGET_CHANGER:
c = getConfig().getTargetChangerColor();
break;
case ABSORBING_AREA:
c = getConfig().getAbsorbingAreaColor();
break;
......
......@@ -23,6 +23,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean useRandomPedestrianColors = false;
private boolean showPedestrianIds = false;
private boolean showTargets = true;
private boolean showTargetChangers = true;
private boolean showAbsorbingAreas = true;
private boolean showSources = true;
private boolean showObstacles = true;
......@@ -117,6 +118,8 @@ public class DefaultSimulationConfig extends DefaultConfig {
return showTargets;
}
public boolean isShowTargetChangers() { return showTargetChangers; }
public boolean isShowAbsorbingAreas() {
return showAbsorbingAreas;
}
......@@ -139,6 +142,11 @@ public class DefaultSimulationConfig extends DefaultConfig {
setChanged();
}
public void setShowTargetChangers(boolean showTargetChangers) {
this.showTargetChangers = showTargetChangers;
setChanged();
}
public boolean isShowSources() {
return showSources;
}
......
......@@ -83,14 +83,17 @@ public class SettingsDialog extends JDialog {
// ######################################################################################
// Layout definition for sub panels
// FIXME: Describe what "5dlu" and the other cryptic things like "prefs" mean,
// or better rewrite this code because it is hard to read.
FormLayout additionalLayout = new FormLayout("5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu", // col
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
FormLayout colorLayout = new FormLayout("5dlu, pref, 2dlu, pref:grow, 2dlu, pref, 2dlu, pref, 5dlu", // col
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
"5dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5dlu"); // rows
colorLayeredPane.setLayout(colorLayout);
additionalLayeredPane.setLayout(additionalLayout);
// Integer[] colorIds = new Integer[CONFIG.("SettingsDialog.maxNumberOfTargets")];
Integer[] colorIds = (Integer[])CONFIG.getArray(Integer.class, "SettingsDialog.maxNumberOfTargets");
for (int index = 1; index <= colorIds.length; index++) {
colorIds[index - 1] = index;
......@@ -103,6 +106,7 @@ public class SettingsDialog extends JDialog {
JCheckBox chShowObstacles = new JCheckBox((Messages.getString("SettingsDialog.chbShowObstacles.text")));
JCheckBox chShowTargets = new JCheckBox((Messages.getString("SettingsDialog.chbShowTargets.text")));
JCheckBox chShowTargetChangers = new JCheckBox((Messages.getString("SettingsDialog.chbShowTargetChangers.text")));
JCheckBox chShowSources = new JCheckBox((Messages.getString("SettingsDialog.chbShowSources.text")));
JCheckBox chShowAbsorbingAreas = new JCheckBox((Messages.getString("SettingsDialog.chbShowAbsorbingAreas.text")));
JCheckBox chShowMeasurementAreas = new JCheckBox((Messages.getString("SettingsDialog.chbShowMeasurementAreas.text")));
......@@ -134,6 +138,12 @@ public class SettingsDialog extends JDialog {
model.notifyObservers();
});
chShowTargetChangers.setSelected(model.config.isShowTargetChangers());
chShowTargetChangers.addItemListener(e -> {
model.config.setShowTargetChangers(!model.config.isShowTargetChangers());
model.notifyObservers();
});
chShowSources.setSelected(model.config.isShowSources());
chShowSources.addItemListener(e -> {
model.config.setShowSources(!model.config.isShowSources());
......@@ -183,6 +193,7 @@ public class SettingsDialog extends JDialog {
colorLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblStair.text") + ":"), cc.xy(2, 8));
colorLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblDensityColor.text") + ":"), cc.xy(2, 10));
colorLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblAbsorbingAreaColor.text") + ":"), cc.xy(2, 12));
colorLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblTargetChanger.text") + ":"), cc.xy(2, 14));
colorLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblPedestrianNoTarget.text") + ":"),
cc.xy(2, 20));
......@@ -234,12 +245,20 @@ public class SettingsDialog extends JDialog {
colorLayeredPane.add(pAbsorbingAreaColor, cc.xy(4, 12));
colorLayeredPane.add(bAbsorbingAreaColor, cc.xy(6, 12));
colorLayeredPane.add(new JSeparator(), cc.xyw(1, 14, 9));
final JButton bTargetChangerColor = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pTargetChangerColor = new JPanel();
pTargetChangerColor.setBackground(model.config.getTargetChangerColor());
pTargetChangerColor.setPreferredSize(new Dimension(130, 20));
bTargetChangerColor.addActionListener(new ActionSetTargetChangerColor("Set Target Changer Color", model, pTargetChangerColor));
colorLayeredPane.add(pTargetChangerColor, cc.xy(4, 14));
colorLayeredPane.add(bTargetChangerColor, cc.xy(6, 14));
colorLayeredPane.add(new JSeparator(), cc.xyw(1, 16, 9));
colorLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblPedTrajColor.text") + ":"),
cc.xyw(2, 16, 5));
colorLayeredPane.add(jComoboTargetIds, cc.xy(2, 18));
colorLayeredPane.add(pPedestrian, cc.xy(4, 18));
colorLayeredPane.add(bChange, cc.xy(6, 18));
cc.xyw(2, 18, 5));
colorLayeredPane.add(jComoboTargetIds, cc.xy(2, 20));
colorLayeredPane.add(pPedestrian, cc.xy(4, 20));
colorLayeredPane.add(bChange, cc.xy(6, 20));
final JButton bPedestrianNoTarget = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pPedestrianNoTarget = new JPanel();
......@@ -248,10 +267,8 @@ public class SettingsDialog extends JDialog {
pPedestrianNoTarget.setPreferredSize(new Dimension(130, 20));
bPedestrianNoTarget.addActionListener(new ActionSetPedestrianWithoutTargetColor(
"Set Pedestrian without Target Color", model, pPedestrianNoTarget));
colorLayeredPane.add(pPedestrianNoTarget, cc.xy(4, 20));
colorLayeredPane.add(bPedestrianNoTarget, cc.xy(6, 20));
// 20 is free
colorLayeredPane.add(pPedestrianNoTarget, cc.xy(4, 22));
colorLayeredPane.add(bPedestrianNoTarget, cc.xy(6, 22));
JCheckBox chRandomColors = new JCheckBox(Messages.getString("SettingsDialog.chbUseRandomColors.text"));
chRandomColors.setSelected(model.config.isUseRandomPedestrianColors());
......@@ -265,11 +282,12 @@ public class SettingsDialog extends JDialog {
additionalLayeredPane.add(chHideVoronoiDiagram, cc.xyw(2, 2, 5));
additionalLayeredPane.add(chShowObstacles, cc.xyw(2, 4, 5));
additionalLayeredPane.add(chShowTargets, cc.xyw(2, 6, 5));
additionalLayeredPane.add(chShowSources, cc.xyw(2, 8, 5));
additionalLayeredPane.add(chShowStairs, cc.xyw(2, 10, 5));
additionalLayeredPane.add(chShowAbsorbingAreas, cc.xyw(2, 12, 5));
additionalLayeredPane.add(chShowMeasurementAreas, cc.xyw(2, 14, 5));
additionalLayeredPane.add(chShowPedIds, cc.xyw(2, 16, 5));
additionalLayeredPane.add(chShowTargetChangers, cc.xyw(2, 8, 5));
additionalLayeredPane.add(chShowSources, cc.xyw(2, 10, 5));
additionalLayeredPane.add(chShowStairs, cc.xyw(2, 12, 5));
additionalLayeredPane.add(chShowAbsorbingAreas, cc.xyw(2, 14, 5));
additionalLayeredPane.add(chShowMeasurementAreas, cc.xyw(2, 16, 5));
additionalLayeredPane.add(chShowPedIds, cc.xyw(2, 18, 5));
JCheckBox chChowLogo = new JCheckBox(Messages.getString("SettingsDialog.chbLogo.text"));
chChowLogo.setSelected(model.config.isShowLogo());
......@@ -277,7 +295,7 @@ public class SettingsDialog extends JDialog {
model.config.setShowLogo(!model.config.isShowLogo());
model.notifyObservers();
});
additionalLayeredPane.add(chChowLogo, cc.xyw(2, 18, 5));
additionalLayeredPane.add(chChowLogo, cc.xyw(2, 20, 5));
additionalLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblSnapshotDir.text") + ":"),
cc.xy(2, 20));
......@@ -287,10 +305,10 @@ public class SettingsDialog extends JDialog {
JTextField tSnapshotDir = new JTextField(VadereConfig.getConfig().getString("SettingsDialog.snapshotDirectory.path", "."));
tSnapshotDir.setEditable(false);
tSnapshotDir.setPreferredSize(new Dimension(130, 20));
additionalLayeredPane.add(tSnapshotDir, cc.xy(4, 20));
additionalLayeredPane.add(tSnapshotDir, cc.xy(4, 22));
final JButton bSnapshotDir = new JButton(Messages.getString("SettingsDialog.btnEditSnapshot.text"));
bSnapshotDir.addActionListener(new ActionSetSnapshotDirectory("Set Snapshot Directory", model, tSnapshotDir));
additionalLayeredPane.add(bSnapshotDir, cc.xy(6, 22));
additionalLayeredPane.add(bSnapshotDir, cc.xy(6, 24));
final JSpinner spinnerCellWidth = new JSpinner();
final SpinnerNumberModel sModelCellWidth = new SpinnerNumberModel(model.config.getGridWidth(),
......@@ -304,7 +322,7 @@ public class SettingsDialog extends JDialog {
additionalLayeredPane.add(new JLabel(Messages.getString("SettingsDialog.lblCellWidth.text") + ":"),
cc.xy(2, 22));
additionalLayeredPane.add(spinnerCellWidth, cc.xy(4, 22));
additionalLayeredPane.add(spinnerCellWidth, cc.xy(4, 26));
mainPanel.add(getAdditionalOptionPanel(), cc.xy(2, 6));
......
......@@ -138,6 +138,9 @@ public class TikzGenerator {
Color targetColor = model.getConfig().getTargetColor();
colorDefinitions += String.format(Locale.US, colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
Color targetChangerColor = model.getConfig().getTargetChangerColor();
colorDefinitions += String.format(Locale.US, colorTextPattern, "TargetChangerColor", targetChangerColor.getRed(), targetChangerColor.getGreen(), targetChangerColor.getBlue());
Color absorbingAreaColor = model.getConfig().getAbsorbingAreaColor();
colorDefinitions += String.format(Locale.US, colorTextPattern, "AbsorbingAreaColor", absorbingAreaColor.getRed(), absorbingAreaColor.getGreen(), absorbingAreaColor.getBlue());
......@@ -225,6 +228,17 @@ public class TikzGenerator {
generatedCode += "% Targets (not enabled in config)\n";
}
if (config.isShowTargetChangers()) {
generatedCode += "% Target Changers\n";
for (TargetChanger targetChanger : topography.getTargetChangers()) {
VPoint centroid = targetChanger.getShape().getCentroid();
generatedCode += String.format(Locale.US, "\\coordinate (target_changer_%d) at (%f,%f); %%centroid coordinate for target changer %d\n", targetChanger.getId(), centroid.x, centroid.y, targetChanger.getId());
generatedCode += String.format(Locale.US, "\\fill[TargetChangerColor] %s;\n", generatePathForScenarioElement(targetChanger));
}
} else {
generatedCode += "% Target Changers (not enabled in config)\n";
}
if (config.isShowAbsorbingAreas()) {
generatedCode += "% Absorbing Areas\n";
for (AbsorbingArea absorbingArea : topography.getAbsorbingAreas()) {
......
......@@ -5,16 +5,7 @@ import org.vadere.gui.topographycreator.control.AttributeModifier;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesCar;
import org.vadere.state.attributes.scenario.AttributesTopography;
import org.vadere.state.scenario.AbsorbingArea;
import org.vadere.state.scenario.MeasurementArea;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Stairs;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Teleporter;
import org.vadere.state.scenario.Topography;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
......@@ -44,6 +35,7 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
private LinkedList<Stairs> stairs;
private LinkedList<Source> sources;
private LinkedList<Target> targets;
private LinkedList<TargetChanger> targetChangers;
private LinkedList<AbsorbingArea> absorbingAreas;
private LinkedList<MeasurementArea> measurementAreas;
private Teleporter teleporter;
......@@ -62,6 +54,7 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
stairs = new LinkedList<>();
sources = new LinkedList<>();
targets = new LinkedList<>();
targetChangers = new LinkedList<>();
absorbingAreas = new LinkedList<>();
topographyElements = new LinkedList<>();
attributes = new AttributesTopography();
......@@ -83,6 +76,7 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
}
sources = new LinkedList<>(topography.getSources());
targets = new LinkedList<>(topography.getTargets());
targetChangers = new LinkedList<>(topography.getTargetChangers());
absorbingAreas = new LinkedList<>(topography.getAbsorbingAreas());
teleporter = topography.getTeleporter();
measurementAreas = new LinkedList<>(topography.getMeasurementAreas());
......@@ -98,6 +92,7 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
topographyElements.addAll(pedestrians);
topographyElements.addAll(sources);
topographyElements.addAll(targets);
topographyElements.addAll(targetChangers);
topographyElements.addAll(measurementAreas);
topographyElements.addAll(absorbingAreas);
}
......@@ -143,6 +138,9 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
for (Target target : targets)
topography.addTarget(target);
for (TargetChanger targetChanger : targetChangers)
topography.addTargetChanger(targetChanger);
for (AbsorbingArea absorbingArea : absorbingAreas)
topography.addAbsorbingArea(absorbingArea);
......@@ -187,6 +185,8 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
return pedestrians.remove(element);
case TARGET:
return targets.remove(element);
case TARGET_CHANGER:
return targetChangers.remove(element);
case ABSORBING_AREA:
return absorbingAreas.remove(element);
case SOURCE:
......@@ -251,6 +251,11 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
this.targets.add(target);
}
public void addTargetChanger(final TargetChanger targetChanger) {
this.topographyElements.add(targetChanger);
this.targetChangers.add(targetChanger);
}
public void addAbsorbingArea(final AbsorbingArea absorbingArea) {
this.topographyElements.add(absorbingArea);
this.absorbingAreas.add(absorbingArea);
......@@ -262,6 +267,12 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
return target;
}
public TargetChanger removeLastTargetChanger() {
TargetChanger targetChanger = targetChangers.removeLast();
topographyElements.remove(targetChanger);
return targetChanger;
}
public AbsorbingArea removeLastAbsorbingArea() {
AbsorbingArea absorbingArea = absorbingAreas.removeLast();
topographyElements.remove(absorbingArea);
......@@ -322,6 +333,10 @@ public class TopographyBuilder implements Iterable<ScenarioElement> {
return targets.iterator();
}
public Iterator<TargetChanger> getTargetChangerIterator() {
return targetChangers.iterator();
}
public Iterator<AbsorbingArea> getAbsorbingAreaIterator() {
return absorbingAreas.iterator();
}
......
......@@ -197,6 +197,9 @@ public class TopographyCreatorModel extends DefaultModel implements IDrawPanelMo
case TARGET:
element = topographyBuilder.removeLastTarget();
break;
case TARGET_CHANGER:
element = topographyBuilder.removeLastTargetChanger();
break;
case ABSORBING_AREA:
element = topographyBuilder.removeLastAbsorbingArea();
break;
......@@ -298,6 +301,9 @@ public class TopographyCreatorModel extends DefaultModel implements IDrawPanelMo
case TARGET:
topographyBuilder.addTarget((org.vadere.state.scenario.Target) shape);
break;
case TARGET_CHANGER:
topographyBuilder.addTargetChanger((org.vadere.state.scenario.TargetChanger) shape);
break;
case ABSORBING_AREA:
topographyBuilder.addAbsorbingArea((org.vadere.state.scenario.AbsorbingArea) shape);
break;
......
......@@ -32,6 +32,8 @@ public class TopographyElementFactory {
return new org.vadere.state.scenario.Source(new AttributesSource(-1, shape));
case TARGET:
return new org.vadere.state.scenario.Target(new AttributesTarget(shape));
case TARGET_CHANGER:
return new org.vadere.state.scenario.TargetChanger(new AttributesTargetChanger(shape));
case ABSORBING_AREA:
return new org.vadere.state.scenario.AbsorbingArea(new AttributesAbsorbingArea(shape));
case PEDESTRIAN:
......@@ -52,6 +54,8 @@ public class TopographyElementFactory {
return new org.vadere.state.scenario.Source((AttributesSource) attributes);
} else if (attributes instanceof AttributesTarget) {
return new org.vadere.state.scenario.Target((AttributesTarget) attributes);
} else if (attributes instanceof AttributesTargetChanger) {
return new org.vadere.state.scenario.TargetChanger((AttributesTargetChanger) attributes);
} else if (attributes instanceof AttributesMeasurementArea) {
return new org.vadere.state.scenario.MeasurementArea((AttributesMeasurementArea) attributes);
} else if (attributes instanceof AttributesAbsorbingArea) {
......
......@@ -37,6 +37,7 @@ public class TopographyCreatorRenderer extends DefaultRenderer {
renderers[ScenarioElementType.PEDESTRIAN.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.SOURCE.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.TARGET.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.TARGET_CHANGER.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.ABSORBING_AREA.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.STAIRS.ordinal()] = this::renderStair;
renderers[ScenarioElementType.TELEPORTER.ordinal()] = this::renderFilledShape;
......
......@@ -240,6 +240,10 @@ public class TopographyWindow extends JPanel {
TopographyAction switchToTargetAction = new ActionSwitchCategory("switch to targets", panelModel,
ScenarioElementType.TARGET, selectRectangleAction);
/* switch category to target changer action */
TopographyAction switchToTargetChangerAction = new ActionSwitchCategory("switch to target changer", panelModel,
ScenarioElementType.TARGET_CHANGER, selectRectangleAction);
/* switch category to absorbing areas action */
TopographyAction switchToAbsorbingAreaAction = new ActionSwitchCategory("switch to absorbing areas", panelModel,
ScenarioElementType.ABSORBING_AREA, selectRectangleAction);
......@@ -313,6 +317,11 @@ public class TopographyWindow extends JPanel {
.getResource("/icons/target_icon.png")), panelModel, switchToTargetAction, targetButton,
obstacleAndTargetDrawModes);
JButton targetChangerButton = new JButton();
TopographyAction openTargetChangerDialog = new ActionOpenDrawOptionMenu("TargetChanger", new ImageIcon(Resources.class
.getResource("/icons/target_changer_icon.png")), panelModel, switchToTargetChangerAction, targetChangerButton,
obstacleAndTargetDrawModes);
/* open absorbing area paint method dialog action */
JButton absorbingAreaButton = new JButton();
TopographyAction openAbsorbingAreaDialog = new ActionOpenDrawOptionMenu("AbsorbingArea", new ImageIcon(Resources.class
......@@ -398,6 +407,8 @@ public class TopographyWindow extends JPanel {
addActionToToolbar(toolbar, openTargetDialog, "TopographyCreator.btnInsertTarget.tooltip",
targetButton);
toolbar.addSeparator(new Dimension(5, 50));
addActionToToolbar(toolbar, openTargetChangerDialog, "TopographyCreator.btnInsertTargetChanger.tooltip",
targetChangerButton);
addActionToToolbar(toolbar, openObstacleDialog, "TopographyCreator.btnInsertObstacle.tooltip",
obsButton);
addActionToToolbar(toolbar, openAbsorbingAreaDialog, "TopographyCreator.btnInsertAbsorbingArea.tooltip",
......
......@@ -38,6 +38,7 @@ public class Simulation {
private final Collection<SourceController> sourceControllers;
private final Collection<TargetController> targetControllers;
private final Collection<TargetChangerController> targetChangerControllers;
private final Collection<AbsorbingAreaController> absorbingAreaControllers;
private TeleporterController teleporterController;
private TopographyController topographyController;
......@@ -96,6 +97,7 @@ public class Simulation {
this.attributesAgent = scenarioStore.getTopography().getAttributesPedestrian();
this.sourceControllers = new LinkedList<>();
this.targetControllers = new LinkedList<>();
this.targetChangerControllers = new LinkedList<>();
this.absorbingAreaControllers = new LinkedList<>();
this.topography = scenarioStore.getTopography();
this.runTimeInSec = attributesSimulation.getFinishTime();
......@@ -168,6 +170,10 @@ public class Simulation {
targetControllers.add(new TargetController(topography, target));
}
for (TargetChanger targetChanger : topography.getTargetChangers()) {
targetChangerControllers.add(new TargetChangerController(topography, targetChanger));
}
for (AbsorbingArea absorbingArea : topography.getAbsorbingAreas()) {
absorbingAreaControllers.add(new AbsorbingAreaController(topography, absorbingArea));
}
......@@ -365,6 +371,10 @@ public class Simulation {
targetController.update(simTimeInSec);
}
for (TargetChangerController targetChangerController : this.targetChangerControllers) {
targetChangerController.update(simTimeInSec);
}
for (AbsorbingAreaController absorbingAreaController : this.absorbingAreaControllers) {
absorbingAreaController.update(simTimeInSec);
}
......@@ -512,4 +522,4 @@ public class Simulation {
this.startTimeInSec = startTimeInSec;
}
}
}
\ No newline at end of file
package org.vadere.simulator.control;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.logging.Logger;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
/**
* Change target id of an agent which enters the given {@link TargetChanger} area.
*
* TargetChanger's attributes contain two important parameters to control the change behavior:
* - changeTargetProbability
* - nextTargetIsPedestrian
*
* "changeTargetProbability" defines how many percent of the agents, who enter the area,
* should change its target. If "nextTargetIsPedestrian == false", assign a new
* static target. Otherwise, randomly choose a pedestrian (with given target id) to follow.
*/
public class TargetChangerController {
// Variables
private static final Logger log = Logger.getLogger(TargetChangerController.class);
public final TargetChanger targetChanger;
private Topography topography;
// Constructors
public TargetChangerController(Topography topography, TargetChanger targetChanger) {
this.targetChanger = targetChanger;
this.topography = topography;
}
// Other Methods
public void update(double simTimeInSec) {
for (DynamicElement element : getDynamicElementsNearTargetChangerArea()) {