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

Exposed TComp movement model and attraction points for REST-demo

parent 99f01b63
......@@ -202,6 +202,14 @@ public class DefaultTopologyComponent implements TopologyComponent {
public Topology getTopology() {
return topology;
}
/**
* Access to the movement model
* @return
*/
public MovementModel getMovementModel() {
return movementModel;
}
@Override
public double getMinMovementSpeed() {
......
......@@ -31,6 +31,8 @@ import java.util.Vector;
import javax.swing.JComponent;
import org.w3c.dom.Attr;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
......@@ -53,6 +55,7 @@ import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationActuator;
/**
* Modular Movement Model uses different models/strategies to create a movement
......@@ -178,9 +181,19 @@ public class ModularMovementModel implements MovementModel, EventHandler {
public void changeTargetLocation(SimLocationActuator actuator,
double longitude, double latitude) {
/*
* Set a new target AP for the current actuator
* Set a new target AP for the current actuator (or assign to an AP close by)
*/
transition.updateTargetAttractionPoint(actuator, new AttractionPoint((int) longitude, (int) latitude, ""));
AttractionPoint apFound = null;
for (AttractionPoint ap : transition.getAllAttractionPoints()) {
if (ap.getRealPosition().distanceTo(new PositionVector(longitude, latitude)) < 1) {
apFound = ap;
break;
}
}
if (apFound == null) {
apFound = new AttractionPoint((int) longitude, (int) latitude, "");
}
transition.updateTargetAttractionPoint(actuator, apFound);
}
private void checkConfiguration() {
......@@ -305,8 +318,16 @@ public class ModularMovementModel implements MovementModel, EventHandler {
*
* @return
*/
protected List<AttractionPoint> getAttractionPoints() {
return new Vector<AttractionPoint>(
attractionGenerator.getAttractionPoints());
public List<AttractionPoint> getAttractionPoints() {
return new Vector<AttractionPoint>(transition.getAllAttractionPoints());
}
/**
* Only for visualization
* @param actuator
* @return
*/
public AttractionPoint getCurrentAttractionPoint(LocationActuator actuator) {
return transition.getAssignments().get(actuator);
}
}
......@@ -65,6 +65,11 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
public void setAttractionPoints(List<AttractionPoint> attractionPoints) {
aPoints.addAll(attractionPoints);
}
@Override
public List<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
@Override
public void addComponent(SimLocationActuator ms) {
......
......@@ -47,6 +47,12 @@ public interface ITransitionStrategy {
* @param attractionPoints
*/
public void setAttractionPoints(List<AttractionPoint> attractionPoints);
/**
* Return a list of all attraction points
* @return
*/
public List<AttractionPoint> getAllAttractionPoints();
/**
* Add the object and assign the MS to an {@link AttractionPoint}.
......
......@@ -160,6 +160,11 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
init();
aPoints.addAll(attractionPoints);
}
@Override
public List<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
@Override
public void addComponent(SimLocationActuator ms) {
......
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