Commit 6d17b580 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Added segment handling

parent 7fc458be
......@@ -185,7 +185,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
*/
trajectory = new RouteImpl(comp.getRealPosition(),
destination, pointList,
routeSensor.getSegmentListeners(),
routeSensor.getSegmentListeners(), routeSensor,
calculateSegments(pointList));
} else {
trajectory = new RouteImpl(comp.getRealPosition(),
......
......@@ -32,6 +32,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor.RouteSegmentListener;
/**
......@@ -50,6 +51,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.route.RouteSensor.R
*/
public class RouteImpl implements Route {
private final RouteSensor sensor;
private PositionVector start;
private PositionVector destination;
......@@ -82,8 +85,9 @@ public class RouteImpl implements Route {
*/
public RouteImpl(PositionVector start,
PositionVector destination, PointList pointList,
Set<RouteSegmentListener> segmentListeners,
Set<RouteSegmentListener> segmentListeners, RouteSensor sensor,
List<RouteSegmentImpl> routeSegments) {
this.sensor = sensor;
this.start = start;
this.destination = destination;
this.pointList = pointList;
......@@ -108,7 +112,7 @@ public class RouteImpl implements Route {
*/
public RouteImpl(PositionVector start,
PositionVector destination, PointList pointList) {
this(start, destination, pointList, Collections.emptySet(),
this(start, destination, pointList, Collections.emptySet(), null,
Collections.emptyList());
}
......@@ -181,8 +185,22 @@ public class RouteImpl implements Route {
}
/*
* TODO Segment handling (also inform listeners!)
* Segment handling (also inform listeners!)
*/
if (routeSegmentsLength > 0
&& routeSegmentsLength > currentSegmentIndex) {
List<RouteSegmentImpl> segmentSublist = routeSegments
.subList(currentSegmentIndex + 1, routeSegmentsLength);
for (RouteSegmentImpl candidate : segmentSublist) {
if (candidate.getFromRouteIndex() >= currentIndex) {
break;
}
currentSegmentIndex++;
segmentListeners.forEach(l -> l.onChangedRouteSegment(sensor,
this, routeSegments.get(currentSegmentIndex - 1),
candidate));
}
}
/*
* Reached target flag
......
......@@ -205,6 +205,9 @@ public class ModularMovementModelViz extends JComponent
public void drawTrajectory(Graphics2D g2) {
Route rt = routeSensor.getRoute();
if (!rt.hasSegmentInformation()) {
return;
}
for (RouteSegment segment : rt.getSegmentsAhead()) {
Location lastLoc = null;
for (Location loc : segment.getSegmentLocations()) {
......
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