Commit 241dc003 authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

First working version of monitoring

parent 85482a86
...@@ -44,7 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.core.TimeComponent; ...@@ -44,7 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.core.TimeComponent;
* @author Sebastian Kaune * @author Sebastian Kaune
*/ */
public class Scheduler implements EventHandler, public class Scheduler implements EventHandler,
SchedulerComponent, TimeComponent { SchedulerComponent, TimeComponent {
// Flag to allow the compiler to remove the unneeded debug code // Flag to allow the compiler to remove the unneeded debug code
private static final boolean DEBUG_CODE = false; private static final boolean DEBUG_CODE = false;
...@@ -449,6 +449,7 @@ public class Scheduler implements EventHandler, ...@@ -449,6 +449,7 @@ public class Scheduler implements EventHandler,
* *
* @return current scheduler time * @return current scheduler time
*/ */
@Override
public long getCurrentTime() { public long getCurrentTime() {
return currentTime; return currentTime;
} }
...@@ -518,6 +519,7 @@ public class Scheduler implements EventHandler, ...@@ -518,6 +519,7 @@ public class Scheduler implements EventHandler,
return simTime; return simTime;
} }
@Override
public int compareTo(SchedulerEvent o) { public int compareTo(SchedulerEvent o) {
int comp = Double.compare(this.simTime, o.simTime); int comp = Double.compare(this.simTime, o.simTime);
return comp == 0 ? Double.compare(this.globalOrderIdx, o.globalOrderIdx) : comp; return comp == 0 ? Double.compare(this.globalOrderIdx, o.globalOrderIdx) : comp;
...@@ -567,6 +569,10 @@ public class Scheduler implements EventHandler, ...@@ -567,6 +569,10 @@ public class Scheduler implements EventHandler,
} }
} }
public double getTimeSkew() {
return timeSkew;
}
/** /**
* Sets the simulation speed lock, changes in setRealTime or setTimeSkew * Sets the simulation speed lock, changes in setRealTime or setTimeSkew
* will not apply while the lock is set. * will not apply while the lock is set.
......
...@@ -826,12 +826,10 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -826,12 +826,10 @@ public class TraciSimulationController implements VehicleController, SimulationS
List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes(); List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes();
if (lanes.size() > 0) { if (lanes.size() > 0) {
List<Location> laneShape = getLaneShape(lanes.get(0).getLaneID()); List<Location> laneShape = getLaneShape(lanes.get(0).getLaneID());
for (Location location : laneShape) { if (laneShape.size() > 1) {
if (0 <= location.getLongitude() && location.getLongitude() <= _endX - _startX && 0 <= location.getLatitude() && location.getLatitude() <= _endY - _startY) {
return true; return true;
} }
} }
}
return false; return false;
} }
return true; return true;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.impl.topology.views.visualization.ui; package de.tud.kom.p2psim.impl.topology.views.visualization.ui;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
...@@ -28,12 +29,16 @@ import javax.swing.AbstractAction; ...@@ -28,12 +29,16 @@ import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem; import javax.swing.JCheckBoxMenuItem;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
...@@ -44,6 +49,9 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager; ...@@ -44,6 +49,9 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisualizationListener; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisualizationListener;
import de.tud.kom.p2psim.impl.util.guirunner.Config; import de.tud.kom.p2psim.impl.util.guirunner.Config;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
/** /**
* Menu-Bar containing means to alter the simulation speed, pause and un-pause * Menu-Bar containing means to alter the simulation speed, pause and un-pause
...@@ -70,6 +78,8 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL ...@@ -70,6 +78,8 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
private ComponentVisManager visManager; private ComponentVisManager visManager;
private JPanel runUntil;
public SimControlPanel(ComponentVisManager visManager) { public SimControlPanel(ComponentVisManager visManager) {
// super("Control"); // super("Control");
this.visManager = visManager; this.visManager = visManager;
...@@ -86,6 +96,8 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL ...@@ -86,6 +96,8 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
this.add(getSpeedLabel()); this.add(getSpeedLabel());
this.add(Box.createHorizontalStrut(10)); this.add(Box.createHorizontalStrut(10));
this.add(getPlayPauseButton()); this.add(getPlayPauseButton());
this.add(Box.createHorizontalStrut(10));
this.add(getRunUntil());
this.add(Box.createHorizontalGlue()); this.add(Box.createHorizontalGlue());
} }
...@@ -162,6 +174,53 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL ...@@ -162,6 +174,53 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
return speedslider; return speedslider;
} }
protected JPanel getRunUntil() {
if (runUntil == null) {
runUntil = new JPanel();
runUntil.setBackground(new Color(0, 0, 0, 0));
JButton button = new JButton("Run until");
runUntil.add(button);
JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, Simulator.getEndTime() / Time.MINUTE, 1));
runUntil.add(spinner);
runUntil.add(new JLabel("min"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent pE) {
int value = (int)((double) spinner.getValue());
boolean wasPaused = isSimulatorPaused;
if (Time.getCurrentTime() < value * Time.MINUTE) {
if (wasPaused) {
unpauseSimulation();
}
double timeSkew = Simulator.getScheduler().getTimeSkew();
Simulator.getScheduler().setTimeSkew(0);
Event.scheduleWithDelay(value * Time.MINUTE - Time.getCurrentTime(), new EventHandler() {
@Override
public void eventOccurred(Object pContent, int pType) {
if (Simulator.getScheduler().getTimeSkew() == 0) {
Simulator.getScheduler().setTimeSkew(timeSkew);
}
if (wasPaused) {
pauseSimulation();
}
}
}, null, 0);
}
}
});
}
return runUntil;
}
protected JLabel getSpeedLabel() { protected JLabel getSpeedLabel() {
if (speedlabel == null) { if (speedlabel == null) {
speedlabel = new JLabel("max"); speedlabel = new JLabel("max");
......
...@@ -27,6 +27,7 @@ import java.awt.Graphics; ...@@ -27,6 +27,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -112,7 +113,7 @@ implements VisualizationComponent { ...@@ -112,7 +113,7 @@ implements VisualizationComponent {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
boolean first = true; boolean first = true;
for (NodeVis vis : nodes) { for (NodeVis vis : new ArrayList<>(nodes)) {
vis.draw(g2); vis.draw(g2);
if (first) { if (first) {
first = false; first = false;
...@@ -238,7 +239,7 @@ implements VisualizationComponent { ...@@ -238,7 +239,7 @@ implements VisualizationComponent {
g2.setStroke(new BasicStroke(3)); g2.setStroke(new BasicStroke(3));
for (int color = 0; color < segments; color++) { for (int color = 0; color < segments; color++) {
if (!activeLayers[color]) { if (activeLayers.length <= color || !activeLayers[color]) {
continue; continue;
} }
g2.setColor(Color.DARK_GRAY); g2.setColor(Color.DARK_GRAY);
......
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