Merge branch 'visualiserAndDataLink' into splitIntoTwoModules

# Conflicts:
#	visualiser/src/main/java/seng302/Controllers/RaceController.java
#	visualiser/src/main/java/seng302/Controllers/StartController.java
#	visualiser/src/main/java/seng302/Mock/BoatXMLReader.java
#	visualiser/src/main/java/seng302/Mock/StreamedBoat.java
#	visualiser/src/main/java/seng302/Mock/StreamedCourse.java
#	visualiser/src/main/java/seng302/Mock/StreamedRace.java
#	visualiser/src/main/java/seng302/Model/BoatInRace.java
#	visualiser/src/main/java/seng302/Model/ConstantVelocityRace.java
#	visualiser/src/main/java/seng302/Model/Race.java
#	visualiser/src/main/java/seng302/RaceXMLReader.java
#	visualiser/src/test/java/seng302/Model/ConstantVelocityRaceTest.java
This commit is contained in:
Joseph Gardner
2017-04-28 13:26:12 +12:00
16 changed files with 758 additions and 607 deletions
@@ -3,11 +3,14 @@ package seng302.Mock;
import javafx.scene.paint.Color;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import seng302.Model.Boat;
import seng302.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.text.ParseException;
import java.util.*;
@@ -15,36 +18,30 @@ import java.util.*;
* Created by Joseph on 24/04/2017.
*/
public class BoatXMLReader extends XMLReader {
private static int currentColourIndex = 0;
Map<Integer, StreamedBoat> streamedBoatMap = new HashMap<>();
Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Color> colours;
/**
* Constructor for Boat XML Reader
*
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException {
this(filePath, false);
makeColours();
}
/**
* Constructor for Boat XML Reader
*
* @param filePath file path to read
* @param read whether or not to read and store the files straight away.
* @throws IOException error
* @throws SAXException error
* @param read whether or not to read and store the files straight away.
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException {
super(filePath);
makeColours();
if (read) {
read();
}
@@ -81,7 +78,6 @@ public class BoatXMLReader extends XMLReader {
Node boat = nBoats.getChildNodes().item(i);
if (boat.getNodeName().equals("Boat")) {
readSingleBoat(boat);
currentColourIndex = (currentColourIndex + 1) % colours.size();
}
}
}
@@ -98,8 +94,7 @@ public class BoatXMLReader extends XMLReader {
String shortName = null;
String country = null;
if (exists(boat, "Type")) type = boat.getAttributes().getNamedItem("Type").getTextContent();
if (exists(boat, "SourceID"))
sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
if (exists(boat, "SourceID")) sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
if (exists(boat, "BoatName")) boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent();
if (exists(boat, "ShortName")) shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent();
if (exists(boat, "Country")) country = boat.getAttributes().getNamedItem("Country").getTextContent();
@@ -109,9 +104,9 @@ public class BoatXMLReader extends XMLReader {
if (!streamedBoatMap.containsKey(sourceID)) {
if (country != null) {
streamedBoat = new StreamedBoat(sourceID, boatName, colours.get(currentColourIndex), country);
streamedBoat = new StreamedBoat(sourceID, boatName, country);
} else {
streamedBoat = new StreamedBoat(sourceID, boatName, colours.get(currentColourIndex), shortName);
streamedBoat = new StreamedBoat(sourceID, boatName, shortName);
}
streamedBoatMap.put(sourceID, streamedBoat);
// Override boat with new boat
@@ -133,20 +128,6 @@ public class BoatXMLReader extends XMLReader {
// TODO Get relative point before implementing. (GPSposition is based off a relative point).
}
private void makeColours() {
colours = new ArrayList<Color>(Arrays.asList(
Color.BLUEVIOLET,
Color.BLACK,
Color.RED,
Color.ORANGE,
Color.DARKOLIVEGREEN,
Color.LIMEGREEN,
Color.PURPLE,
Color.DARKGRAY,
Color.YELLOW
));
}
public void setParticipants(Map<Integer, StreamedBoat> participants) {
this.participants = participants;
}
@@ -154,4 +135,8 @@ public class BoatXMLReader extends XMLReader {
public Map<Integer, StreamedBoat> getStreamedBoatMap() {
return streamedBoatMap;
}
public List<Boat> getBoats() {
return new ArrayList<>(streamedBoatMap.values());
}
}
@@ -1,44 +1,48 @@
package seng302.Mock;
import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
import seng302.Model.Boat;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
/**
* Created by Joseph on 24/04/2017.
*/
public class StreamedBoat extends BoatInRace {
public class StreamedBoat extends Boat {
private int sourceID;
private boolean complete;
private boolean dnf = false;
public StreamedBoat(int sourceID, String name, Color colour, String abbrev) {
super(name, colour, abbrev);
private void init() {
this.velocity = 0;
}
public StreamedBoat(int sourceID, String name, String abbrev) {
super(name, abbrev);
this.sourceID = sourceID;
this.complete = true;
this.init();
}
public StreamedBoat(int sourceID) {
super("None", Color.BLACK, "None");
super("None", "None");
this.sourceID = sourceID;
this.complete = false;
}
/**
* Overridden to ignore this function
*
* @return 0
* @deprecated
*/
public double getScaledVelocity() {
return 0;
this.init();
}
/**
* Overridden to ignore this function
* Calculates the azimuth of the travel via heading of the boat
*
* @param velocity of boat
* @deprecated
* @return the direction that the boat is heading towards in degrees (-180 to 180).
*/
public void setScaledVelocity(double velocity) {
public double calculateAzimuth() {
double azimuth;
if (heading <= 180) {
azimuth = heading;
} else {
azimuth = -heading + 180;
}
return azimuth;
}
}
@@ -1,15 +1,11 @@
package seng302.Mock;
import seng302.GPSCoordinate;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
import seng302.Model.RaceClock;
import seng302.Model.*;
import seng302.RaceDataSource;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
@@ -44,16 +40,16 @@ public class StreamedCourse implements RaceDataSource {
}
}
public RegattaXMLReader getRegattaXMLReader() {
return regattaXMLReader;
}
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
this.regattaXMLReader = regattaXMLReader;
}
public List<BoatInRace> getBoats() {
return new ArrayList<>(boatXMLReader.getStreamedBoatMap().values());
public RegattaXMLReader getRegattaXMLReader() {
return regattaXMLReader;
}
public List<Boat> getBoats() {
return boatXMLReader.getBoats();
}
public List<Leg> getLegs() {
@@ -1,10 +1,16 @@
package seng302.Mock;
import javafx.collections.FXCollections;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
import seng302.Controllers.RaceController;
import seng302.Model.BoatInRace;
import seng302.Model.Race;
import seng302.GPSCoordinate;
import seng302.Model.*;
import seng302.RaceDataSource;
import java.awt.geom.Point2D;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
*/
@@ -14,18 +20,30 @@ public class StreamedRace extends Race {
public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
super(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
this.raceData = raceData;
this.scaleFactor = 1; // There will be no scaling in a live streamed race
}
public void initialiseBoats() {
Leg officialStart = legs.get(0);
String name = officialStart.getName();
Marker endMarker = officialStart.getEndMarker();
for (int i = 0; i < startingBoats.size(); i++) {
Boat boat = startingBoats.get(i);
if (boat != null) {
Leg startLeg = new Leg(name, 0);
startLeg.setEndMarker(endMarker);
boat.setCurrentLeg(startLeg);
}
}
}
/**
* Checks if the boat cannot finish the race
*
* @return True if boat cannot finish the race
*/
protected boolean doNotFinish() {
// DNF is no longer random and is now determined by a dnf packet
return false;
}
@@ -36,18 +54,30 @@ public class StreamedRace extends Race {
* @param timeElapsed Time that has elapse since the start of the the race.
* @see BoatInRace
*/
protected void checkPosition(BoatInRace boat, long timeElapsed) {
protected void checkPosition(Boat boat, long timeElapsed) {
if (boat.getCurrentLeg().getName().toLowerCase().contains("finish")) {
//boat has finished
boatsFinished++;
boat.setFinished(true);
boat.setTimeFinished(timeElapsed);
}
//Update the boat display table in the GUI to reflect the leg change
updatePositions();
}
/**
* Updates the boat's gps coordinates
*
* @param boat to be updated
* @param boat to be updated
* @param millisecondsElapsed time since last update
*/
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
protected void updatePosition(Boat boat, int millisecondsElapsed) {
//TODO Grab info from network
// setPostiion(boat, coordinate);
}
protected void setPostion(Boat boat, GPSCoordinate coordinate) {
boat.setCurrentPosition(coordinate);
}
}