Merge branch 'master' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into story28
This commit is contained in:
@@ -35,6 +35,9 @@ public class RaceController extends Controller {
|
|||||||
SplitPane race;
|
SplitPane race;
|
||||||
@FXML
|
@FXML
|
||||||
CheckBox showFPS;
|
CheckBox showFPS;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
CheckBox showBoatPath;
|
||||||
@FXML
|
@FXML
|
||||||
CheckBox showAnnotations;
|
CheckBox showAnnotations;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -235,6 +238,15 @@ public class RaceController extends Controller {
|
|||||||
raceMap.update();
|
raceMap.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//listener for show abbreviation for annotation
|
||||||
|
showBoatPath.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
|
Boolean old_val, Boolean new_val) {
|
||||||
|
raceMap.toggleBoatPath();
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
//listener to show speed for annotation
|
//listener to show speed for annotation
|
||||||
showSpeed.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
showSpeed.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
public void changed(ObservableValue<? extends Boolean> ov,
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
@@ -251,6 +263,7 @@ public class RaceController extends Controller {
|
|||||||
presetAnno.add(showName.isSelected());
|
presetAnno.add(showName.isSelected());
|
||||||
presetAnno.add(showAbbrev.isSelected());
|
presetAnno.add(showAbbrev.isSelected());
|
||||||
presetAnno.add(showSpeed.isSelected());
|
presetAnno.add(showSpeed.isSelected());
|
||||||
|
presetAnno.add(showBoatPath.isSelected());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//listener to show saved annotation
|
//listener to show saved annotation
|
||||||
@@ -261,9 +274,10 @@ public class RaceController extends Controller {
|
|||||||
showName.setSelected(presetAnno.get(0));
|
showName.setSelected(presetAnno.get(0));
|
||||||
showAbbrev.setSelected(presetAnno.get(1));
|
showAbbrev.setSelected(presetAnno.get(1));
|
||||||
showSpeed.setSelected(presetAnno.get(2));
|
showSpeed.setSelected(presetAnno.get(2));
|
||||||
|
showBoatPath.setSelected(presetAnno.get(3));
|
||||||
raceMap.update();
|
raceMap.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
import javafx.beans.property.IntegerProperty;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -9,6 +8,8 @@ import seng302.Constants;
|
|||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boat in the Race extends Boat.
|
* Boat in the Race extends Boat.
|
||||||
@@ -27,6 +28,14 @@ public class BoatInRace extends Boat {
|
|||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private StringProperty position;
|
private StringProperty position;
|
||||||
|
|
||||||
|
private Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
||||||
|
private long nextValidTime = 0;
|
||||||
|
|
||||||
|
private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
|
||||||
|
private static float trackPointTimeInterval = 5000; // every 1 seconds
|
||||||
|
private final int TRACK_POINT_LIMIT = 10;
|
||||||
|
private boolean trackVisible = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
*
|
*
|
||||||
@@ -251,4 +260,53 @@ public class BoatInRace extends Boat {
|
|||||||
public void setPosition(String position) {
|
public void setPosition(String position) {
|
||||||
this.position.set(position);
|
this.position.set(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new point to boat's track.
|
||||||
|
* @param coordinate of point on track
|
||||||
|
* @return whether add is successful
|
||||||
|
* @see seng302.Model.TrackPoint
|
||||||
|
*/
|
||||||
|
public boolean addTrackPoint(GPSCoordinate coordinate) {
|
||||||
|
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
if (added && this.started) {
|
||||||
|
nextValidTime = currentTime + (long) trackPointTimeInterval;
|
||||||
|
track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval));
|
||||||
|
}
|
||||||
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the boat's sampled track between start of race and current time.
|
||||||
|
* @return queue of track points
|
||||||
|
* @see seng302.Model.TrackPoint
|
||||||
|
*/
|
||||||
|
public Queue<TrackPoint> getTrack() {
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether track is visible
|
||||||
|
* @return true if visible
|
||||||
|
*/
|
||||||
|
public boolean isTrackVisible() {
|
||||||
|
return trackVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets track visibility.
|
||||||
|
* @param trackVisible visible if true.
|
||||||
|
*/
|
||||||
|
public void setTrackVisible(boolean trackVisible) {
|
||||||
|
this.trackVisible = trackVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getBaseTrackPointTimeInterval() {
|
||||||
|
return BASE_TRACK_POINT_TIME_INTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setTrackPointTimeInterval(float value) {
|
||||||
|
trackPointTimeInterval = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public abstract class Race implements Runnable {
|
|||||||
String name = officialStart.getName();
|
String name = officialStart.getName();
|
||||||
Marker endMarker = officialStart.getEndMarker();
|
Marker endMarker = officialStart.getEndMarker();
|
||||||
|
|
||||||
|
BoatInRace.setTrackPointTimeInterval(BoatInRace.getBaseTrackPointTimeInterval() / scaleFactor);
|
||||||
|
|
||||||
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
@@ -214,20 +215,23 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
if (boat != null && !boat.isFinished()) {
|
if (boat != null && !boat.isFinished()) {
|
||||||
|
boat.addTrackPoint(boat.getCurrentPosition());
|
||||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||||
checkPosition(boat, totalTimeElapsed);
|
checkPosition(boat, totalTimeElapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller != null) controller.updateMap(startingBoats);
|
// if (controller != null) controller.updateMap(startingBoats);
|
||||||
if (timerEnabled)
|
if (timerEnabled)
|
||||||
updateTime(calcTimer());
|
updateTime(calcTimer());
|
||||||
} else {
|
|
||||||
//Exit animation timer
|
|
||||||
updateTime(calcTimer());
|
|
||||||
updateFPS(0); //race ended so fps = 0
|
|
||||||
stop(); //exit animation timer
|
|
||||||
}
|
}
|
||||||
|
controller.updateMap(startingBoats);
|
||||||
|
// } else {
|
||||||
|
// //Exit animation timer
|
||||||
|
// updateTime(calcTimer());
|
||||||
|
// updateFPS(0); //race ended so fps = 0
|
||||||
|
// stop(); //exit animation timer
|
||||||
|
// }
|
||||||
fps++;
|
fps++;
|
||||||
if ((System.currentTimeMillis() - timeCurrent) > 1000) {
|
if ((System.currentTimeMillis() - timeCurrent) > 1000) {
|
||||||
updateFPS(fps);
|
updateFPS(fps);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
private boolean annoName = true;
|
private boolean annoName = true;
|
||||||
private boolean annoAbbrev = true;
|
private boolean annoAbbrev = true;
|
||||||
private boolean annoSpeed = true;
|
private boolean annoSpeed = true;
|
||||||
|
private boolean annoPath = true;
|
||||||
private ArrayList<GPSCoordinate> raceBoundaries;
|
private ArrayList<GPSCoordinate> raceBoundaries;
|
||||||
double[] xpoints = {}, ypoints = {};
|
double[] xpoints = {}, ypoints = {};
|
||||||
|
|
||||||
@@ -39,6 +40,9 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
*/
|
*/
|
||||||
public void setBoats(BoatInRace[] boats) {
|
public void setBoats(BoatInRace[] boats) {
|
||||||
this.boats = boats;
|
this.boats = boats;
|
||||||
|
for (BoatInRace boat : boats) {
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResizableRaceCanvas(RaceMap map) {
|
public ResizableRaceCanvas(RaceMap map) {
|
||||||
@@ -295,6 +299,14 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleBoatPath() {
|
||||||
|
if (annoPath) {
|
||||||
|
annoPath = false;
|
||||||
|
} else {
|
||||||
|
annoPath = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle abbreviation display in annotation
|
* Toggle abbreviation display in annotation
|
||||||
*/
|
*/
|
||||||
@@ -338,6 +350,24 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
if (raceAnno)
|
if (raceAnno)
|
||||||
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||||
|
|
||||||
|
if(boat.isTrackVisible()) drawTrack(boat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws all track points for a given boat. Colour is set by boat, opacity by track point.
|
||||||
|
* @param boat whose track is displayed
|
||||||
|
* @see seng302.Model.TrackPoint
|
||||||
|
*/
|
||||||
|
private void drawTrack(BoatInRace boat) {
|
||||||
|
if (annoPath) {
|
||||||
|
for (TrackPoint point : boat.getTrack()) {
|
||||||
|
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
|
||||||
|
Color boatColour = boat.getColour();
|
||||||
|
gc.setFill(new Color(boatColour.getRed(), boatColour.getGreen(), boatColour.getBlue(), point.getAlpha()));
|
||||||
|
gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package seng302.Model;
|
||||||
|
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by cbt24 on 7/04/17.
|
||||||
|
*/
|
||||||
|
public class TrackPoint {
|
||||||
|
private GPSCoordinate coordinate;
|
||||||
|
private long timeAdded;
|
||||||
|
private long expiry;
|
||||||
|
private double minAlpha;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new track point with fixed GPS coordinates and time, to reach minimum opacity on expiry.
|
||||||
|
* @param coordinate position of point on physical race map
|
||||||
|
* @param timeAdded system clock at time of addition
|
||||||
|
* @param expiry time to minimum opacity after added
|
||||||
|
*/
|
||||||
|
public TrackPoint(GPSCoordinate coordinate, long timeAdded, long expiry) {
|
||||||
|
this.coordinate = coordinate;
|
||||||
|
this.timeAdded = timeAdded;
|
||||||
|
this.expiry = expiry;
|
||||||
|
this.minAlpha = 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the position of the point on physical race map.
|
||||||
|
* @return GPS coordinate of point
|
||||||
|
*/
|
||||||
|
public GPSCoordinate getCoordinate() {
|
||||||
|
return coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets opacity of point scaled by age in proportion to expiry, between 1 and minimum opacity inclusive.
|
||||||
|
* @return greater of minimum opacity and scaled opacity
|
||||||
|
*/
|
||||||
|
public double getAlpha() {
|
||||||
|
return Double.max(minAlpha,1.0 - (double)(System.currentTimeMillis() - timeAdded) / expiry);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets time point was added to track.
|
||||||
|
* @return system clock at time of addition
|
||||||
|
*/
|
||||||
|
public long getTimeAdded() {
|
||||||
|
return timeAdded;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,14 +23,15 @@
|
|||||||
<panes>
|
<panes>
|
||||||
<TitledPane animated="false" text="Annotation Control">
|
<TitledPane animated="false" text="Annotation Control">
|
||||||
<content>
|
<content>
|
||||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="240.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
|
<CheckBox fx:id="showBoatPath" mnemonicParsing="false" selected="true" text="Show Boat Paths" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="104.0" />
|
||||||
<CheckBox fx:id="showAnnotations" layoutX="-2.0" layoutY="14.0" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<CheckBox fx:id="showAnnotations" layoutX="-2.0" layoutY="14.0" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||||
<CheckBox fx:id="showName" layoutY="39.0" mnemonicParsing="false" selected="true" text="Show Boat Name" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="26.0" />
|
<CheckBox fx:id="showName" layoutY="39.0" mnemonicParsing="false" selected="true" text="Show Boat Name" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="26.0" />
|
||||||
<CheckBox fx:id="showAbbrev" layoutY="61.0" mnemonicParsing="false" selected="true" text="Show Boat Abbreviation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="52.0" />
|
<CheckBox fx:id="showAbbrev" layoutY="61.0" mnemonicParsing="false" selected="true" text="Show Boat Abbreviation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="52.0" />
|
||||||
<CheckBox fx:id="showSpeed" layoutY="90.0" mnemonicParsing="false" selected="true" text="Show Boat Speed" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="78.0" />
|
<CheckBox fx:id="showSpeed" layoutY="90.0" mnemonicParsing="false" selected="true" text="Show Boat Speed" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="78.0" />
|
||||||
<Button fx:id="saveAnno" layoutX="11.0" layoutY="106.0" maxWidth="154.0" mnemonicParsing="false" prefWidth="154.0" text="Save Annotation" AnchorPane.topAnchor="104.0" />
|
<Button fx:id="saveAnno" layoutX="11.0" layoutY="106.0" maxWidth="154.0" mnemonicParsing="false" prefWidth="154.0" text="Save Annotation" AnchorPane.topAnchor="130.0" />
|
||||||
<Button fx:id="showSetAnno" layoutX="11.0" layoutY="139.0" mnemonicParsing="false" text="Show Set Annotation" AnchorPane.topAnchor="139.0" />
|
<Button fx:id="showSetAnno" layoutX="11.0" layoutY="139.0" mnemonicParsing="false" text="Show Set Annotation" AnchorPane.topAnchor="160.0" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
Reference in New Issue
Block a user