Cleanup, SimulatorService using redefined API which takes WindPatternDisplay as a parameter.

This commit is contained in:
Nidhi Sawhney committed 2012-05-25 12:54:29 +02:00
1 parent c3e0a29cff
commit fca30ed74f
5 files changed
+37 -106

No files matched your search

@@ -21,12 +21,10 @@ public interface SimulatorService extends RemoteService {
public PositionDTO[] getRaceLocations();
public WindLatticeDTO getWindLatice(WindLatticeGenParamsDTO params);
public WindFieldDTO getWindField(WindFieldGenParamsDTO params);
public WindFieldDTO getWindField(WindFieldGenParamsDTO params, WindPatternDisplay pattern);
public PathDTO[] getPaths(WindFieldGenParamsDTO params);
public PathDTO[] getPaths(WindFieldGenParamsDTO params, WindPatternDisplay pattern);
public List<WindPatternDTO> getWindPatterns();
@@ -18,12 +18,10 @@ public interface SimulatorServiceAsync {
void getRaceLocations(AsyncCallback<PositionDTO[]> callback);
void getWindLatice(WindLatticeGenParamsDTO params, AsyncCallback<WindLatticeDTO> callback);
void getWindField(WindFieldGenParamsDTO params, AsyncCallback<WindFieldDTO> callback);
void getWindField(WindFieldGenParamsDTO params, WindPatternDisplay display, AsyncCallback<WindFieldDTO> callback);
void getPaths(WindFieldGenParamsDTO params, AsyncCallback<PathDTO[]> callback);
void getPaths(WindFieldGenParamsDTO params, WindPatternDisplay display, AsyncCallback<PathDTO[]> callback);
void getWindPatterns(AsyncCallback<List<WindPatternDTO>> callback);
@@ -53,6 +53,8 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
private static Logger logger = Logger.getLogger("com.sap.sailing");
private WindControlParameters controlParameters = new WindControlParameters(0,0);
@Override
public PositionDTO[] getRaceLocations() {
PositionDTO lakeGarda = new PositionDTO();
@@ -129,69 +131,7 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
return wl;
}
public WindFieldDTO getWindField(WindFieldGenParamsDTO params) {
Position nw = new DegreePosition(params.getNorthWest().latDeg, params.getNorthWest().lngDeg);
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
List<Position> course = new ArrayList<Position>();
course.add(nw);
course.add(se);
Distance dist = nw.getDistance(se);
Speed requiredSpeed10 = dist.inTime(600000);
logger.info(requiredSpeed10.getKilometersPerHour() + "km/h," + requiredSpeed10.getKnots() + "kn,"
+ requiredSpeed10.getMetersPerSecond() + "m/s");
RectangularBoundary bd = new RectangularBoundary(nw, se);
List<Position> lattice = bd.extractLattice(5, 5);
// TODO remove this, only placed so that we can display some points
if (lattice == null) {
lattice = new LinkedList<Position>();
lattice.add(nw);
lattice.add(se);
}
// WindField wf = new WindFieldImpl(bd, params.getWindSpeed(), params.getWindBearing());
// I am creating the WindField such as the course goes mainly against the wind (as it should)
// and the speed of the wind would go over the course in 10 minutes (for the sake of the running time)
//WindField wf = new WindFieldImpl(bd, requiredSpeed10.getKilometersPerHour(), bd.getSouth().getDegrees());
KnotSpeedImpl knotSpeedImpl = new KnotSpeedImpl(params.getWindSpeed());
WindField wf = new WindFieldImpl(bd, knotSpeedImpl.getKilometersPerHour(), bd.getSouth().getDegrees());
List<WindDTO> wList = new ArrayList<WindDTO>();
if (lattice != null) {
for (Position p : lattice) {
Wind localWind = wf.getWind(new TimedPositionWithSpeedSimple(p));
logger.fine(localWind.toString());
WindDTO w = createWindDTO(localWind);
wList.add(w);
}
}
WindFieldDTO wfDTO = new WindFieldDTO();
wfDTO.setMatrix(wList);
return wfDTO;
}
@Override
public WindFieldDTO getWindField(WindFieldGenParamsDTO params, WindPatternDisplay pattern) {
Position nw = new DegreePosition(params.getNorthWest().latDeg, params.getNorthWest().lngDeg);
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
List<Position> course = new ArrayList<Position>();
course.add(nw);
course.add(se);
Distance dist = nw.getDistance(se);
Speed requiredSpeed10 = dist.inTime(600000);
logger.info(requiredSpeed10.getKilometersPerHour() + "km/h," + requiredSpeed10.getKnots() + "kn,"
+ requiredSpeed10.getMetersPerSecond() + "m/s");
RectangularBoundary bd = new RectangularBoundary(nw, se);
List<Position> lattice = bd.extractLattice(5, 5);
WindControlParameters controlParameters = new WindControlParameters(0,0);
private void retreiveWindControlParameters(WindPatternDisplay pattern) {
for(WindPatternSetting<?> s : pattern.getSettings()) {
Field f;
try {
@@ -217,6 +157,21 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
}
}
}
@Override
public WindFieldDTO getWindField(WindFieldGenParamsDTO params, WindPatternDisplay pattern) {
Position nw = new DegreePosition(params.getNorthWest().latDeg, params.getNorthWest().lngDeg);
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
List<Position> course = new ArrayList<Position>();
course.add(nw);
course.add(se);
RectangularBoundary bd = new RectangularBoundary(nw, se);
List<Position> lattice = bd.extractLattice(params.getxRes(), params.getyRes());
retreiveWindControlParameters(pattern);
KnotSpeedImpl knotSpeedImpl = new KnotSpeedImpl(controlParameters.speed);
WindField wf = new WindFieldImpl(bd, knotSpeedImpl.getKilometersPerHour(), bd.getSouth().getDegrees());
@@ -241,26 +196,23 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
* Currently the path is a list of WindDTO objects at the path points and only a single optimal path is returned
*
* */
public PathDTO[] getPaths(WindFieldGenParamsDTO params) {
public PathDTO[] getPaths(WindFieldGenParamsDTO params, WindPatternDisplay pattern) {
Position nw = new DegreePosition(params.getNorthWest().latDeg, params.getNorthWest().lngDeg);
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
List<Position> course = new ArrayList<Position>();
course.add(nw);
course.add(se);
Distance dist = nw.getDistance(se);
Speed requiredSpeed10 = dist.inTime(600000);
RectangularBoundary bd = new RectangularBoundary(nw, se);
// WindField wf = new WindFieldImpl(bd, params.getWindSpeed(), params.getWindBearing());
// I am creating the WindField such as the course goes mainly against the wind (as it should)
// and the speed of the wind would go over the course in 10 minutes (for the sake of the running time)
KnotSpeedImpl knotSpeedImpl = new KnotSpeedImpl(params.getWindSpeed());
RectangularBoundary bd = new RectangularBoundary(nw, se);
retreiveWindControlParameters(pattern);
KnotSpeedImpl knotSpeedImpl = new KnotSpeedImpl(controlParameters.speed);
WindField wf = new WindFieldImpl(bd, knotSpeedImpl.getKilometersPerHour(), bd.getSouth().getDegrees());
PathDTO[] pathDTO = new PathDTO[1];
//TODO Get all the paths that need to be displayed
List<WindDTO> path = getOptimumPath(course, wf);
PathDTO[] pathDTO = new PathDTO[1];
pathDTO[0] = new PathDTO("Path 1");
pathDTO[0].setMatrix(path);
return pathDTO;
@@ -8,11 +8,9 @@ public class WindFieldGenParamsDTO implements IsSerializable {
private PositionDTO northWest;
private PositionDTO southEast;
private double xRes;
private double yRes;
private int xRes;
private int yRes;
private double windSpeedInKnots;
private double windBearing;
public PositionDTO getNorthWest() {
return northWest;
@@ -26,29 +24,17 @@ public class WindFieldGenParamsDTO implements IsSerializable {
public void setSouthEast(PositionDTO southEast) {
this.southEast = southEast;
}
public double getxRes() {
public int getxRes() {
return xRes;
}
public void setxRes(double xRes) {
public void setxRes(int xRes) {
this.xRes = xRes;
}
public double getyRes() {
public int getyRes() {
return yRes;
}
public void setyRes(double yRes) {
public void setyRes(int yRes) {
this.yRes = yRes;
}
public double getWindSpeed() {
return windSpeedInKnots;
}
public void setWindSpeed(double windSpeed) {
this.windSpeedInKnots = windSpeed;
}
public double getWindBearing() {
return windBearing;
}
public void setWindBearing(double windBearing) {
this.windBearing = windBearing;
}
}
@@ -127,8 +127,6 @@ public class SimulatorMap extends AbsolutePanel implements RequiresDataInitializ
windParams.setSouthEast(endPointDTO);
windParams.setxRes(xRes);
windParams.setyRes(yRes);
windParams.setWindBearing(wControls.windBearing);
windParams.setWindSpeed(wControls.windSpeedInKnots);
simulatorSvc.getWindField(windParams, windPatternDisplay, new AsyncCallback<WindFieldDTO>() {
@Override
@@ -150,7 +148,7 @@ public class SimulatorMap extends AbsolutePanel implements RequiresDataInitializ
windFieldCanvasOverlay.redraw(true);
}
private void generatePath(final WindControlParameters wControls, final boolean display) {
private void generatePath(final WindControlParameters wControls, WindPatternDisplay windPatternDisplay, final boolean display) {
logger.info("In generatePath");
PositionDTO startPointDTO = new PositionDTO(raceCourseCanvasOverlay.startPoint.getLatitude(),
@@ -162,10 +160,9 @@ public class SimulatorMap extends AbsolutePanel implements RequiresDataInitializ
windParams.setSouthEast(endPointDTO);
windParams.setxRes(xRes);
windParams.setyRes(yRes);
windParams.setWindBearing(wControls.windBearing);
windParams.setWindSpeed(wControls.windSpeedInKnots);
simulatorSvc.getPaths(windParams, new AsyncCallback<PathDTO[]>() {
simulatorSvc.getPaths(windParams, windPatternDisplay, new AsyncCallback<PathDTO[]>() {
@Override
public void onFailure(Throwable message) {
errorReporter.reportError("Failed servlet call to SimulatorService\n" + message.getMessage());
@@ -211,7 +208,7 @@ public class SimulatorMap extends AbsolutePanel implements RequiresDataInitializ
mapw.removeOverlay(replayPathCanvasOverlay);
pathCanvasOverlay.displayWindAlongPath = true;
mapw.addOverlay(pathCanvasOverlay);
generatePath(wControls, true);
generatePath(wControls, windPatternDisplay, true);
// pathCanvasOverlay.redraw(true);
}
@@ -221,7 +218,7 @@ public class SimulatorMap extends AbsolutePanel implements RequiresDataInitializ
replayPathCanvasOverlay.displayWindAlongPath = false;
mapw.addOverlay(replayPathCanvasOverlay);
generateWindField(wControls, windPatternDisplay);
generatePath(wControls, false);
generatePath(wControls, windPatternDisplay, false);
}
private void refreshWindDisplayView(WindControlParameters wControls, WindPatternDisplay windPatternDisplay) {