Merge branch 'splitIntoTwoModules' of eng-git.canterbury.ac.nz:seng302-2017/team-7 into splitIntoTwoModules

main
fjc40 9 years ago
commit ecebace9f1

@ -6,6 +6,7 @@ import seng302.Model.BoatInRace;
/**
* Constants that are used throughout the program
* Created by Erika on 19-Mar-17.
* @deprecated please use XML for constant data
*/
public class Constants {

@ -114,7 +114,6 @@ public class RaceController extends Controller {
raceMap.widthProperty().bind(canvasBase.widthProperty());
raceMap.heightProperty().bind(canvasBase.heightProperty());
//raceMap.setBoats(newRace.getStartingBoats());
raceMap.setRaceBoundaries(raceData.getBoundary());
raceMap.drawRaceMap();
raceMap.setVisible(true);

@ -3,6 +3,7 @@ package seng302.Mock;
import seng302.GPSCoordinate;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
@ -59,12 +60,14 @@ public class StreamedCourse implements RaceDataSource {
return streamedCourseXMLReader.getLegs();
}
public List<Marker> getMarkers() { return streamedCourseXMLReader.getMarkers(); }
public List<GPSCoordinate> getBoundary() {
return streamedCourseXMLReader.getBoundary();
}
public ZonedDateTime getZonedDateTime() {
return RaceClock.getCurrentZonedDateTime(regattaXMLReader.getRegatta().getGPSCoordinate());
return streamedCourseXMLReader.getRaceStartTime();
}
public GPSCoordinate getMapTopLeft() {

@ -1,5 +1,6 @@
package seng302.Mock;
import org.joda.time.DateTime;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@ -15,30 +16,32 @@ import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourseXMLReader extends XMLReader {
private static double COORDINATEPADDING = 0.0005;
Date creationTimeDate;
Date raceStartTime;
int raceID;
String raceType;
boolean postpone;
private static double COORDINATEPADDING = 0.000;
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer, Element> marks = new HashMap<>();
private Map<Integer,Element> compoundMarks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
private List<Marker> markers = new ArrayList<>();
ZonedDateTime creationTimeDate;
ZonedDateTime raceStartTime;
int raceID;
String raceType;
boolean postpone;
/**
* Constructor for Streamed Race XML
*
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
*/
public StreamedCourseXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
@ -47,11 +50,10 @@ public class StreamedCourseXMLReader extends XMLReader {
/**
* Constructor for Streamed Race XML
*
* @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 StreamedCourseXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
@ -68,14 +70,14 @@ public class StreamedCourseXMLReader extends XMLReader {
}
private void readRace() throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
raceType = getTextValueOfNode(settings, "RaceType");
creationTimeDate = dateFormat.parse(getTextValueOfNode(settings, "CreationTimeDate"));
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
raceStartTime = dateFormat.parse(raceTimeTag.getNamedItem("Time").getTextContent());
raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
}
@ -100,40 +102,37 @@ public class StreamedCourseXMLReader extends XMLReader {
}
/**
* Indexes CompoundMark elements by their ID for use in generating the course.
* Indexes CompoundMark elements by their ID for use in generating the course, and populates list of Markers.
* @see seng302.Model.Marker
*/
private void readCompoundMarks() {
private void readCompoundMarks() throws StreamedCourseXMLException {
Element nCourse = (Element) doc.getElementsByTagName("Course").item(0);
for (int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
Node compoundMark = nCourse.getChildNodes().item(i);
if (compoundMark.getNodeName().equals("CompoundMark")) {
marks.put(getCompoundMarkID((Element) compoundMark), (Element) compoundMark);
if(compoundMark.getNodeName().equals("CompoundMark")) {
int compoundMarkID = getCompoundMarkID((Element) compoundMark);
compoundMarks.put(compoundMarkID, (Element)compoundMark);
markers.add(getMarker(compoundMarkID));
}
}
}
/**
* Generates a Marker from the CompoundMark element with given ID.
*
* @param compoundMarkID index of required CompoundMark element
* @return generated Marker
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of marks
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of compoundMarks
* @see seng302.Model.Marker
*/
private Marker getMarker(int compoundMarkID) throws StreamedCourseXMLException {
Element compoundMark = marks.get(compoundMarkID);
Element compoundMark = compoundMarks.get(compoundMarkID);
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
Marker marker;
switch (nMarks.getLength()) {
case 1:
marker = new Marker(getCoordinate((Element) nMarks.item(0)));
break;
case 2:
marker = new Marker(getCoordinate((Element) nMarks.item(0)), getCoordinate((Element) nMarks.item(1)));
break;
default:
throw new StreamedCourseXMLException();
switch(nMarks.getLength()) {
case 1: marker = new Marker(getCoordinate((Element)nMarks.item(0))); break;
case 2: marker = new Marker(getCoordinate((Element)nMarks.item(0)), getCoordinate((Element)nMarks.item(1))); break;
default: throw new StreamedCourseXMLException();
}
return marker;
@ -142,12 +141,11 @@ public class StreamedCourseXMLReader extends XMLReader {
private GPSCoordinate getCoordinate(Element mark) {
double lat = Double.parseDouble(mark.getAttribute("TargetLat"));
double lon = Double.parseDouble(mark.getAttribute("TargetLng"));
return new GPSCoordinate(lat, lon);
return new GPSCoordinate(lat,lon);
}
/**
* Reads "compoundMarkID" attribute of CompoundMark or Corner element
*
* @param element with "compoundMarkID" attribute
* @return value of "compoundMarkID" attribute
*/
@ -157,28 +155,26 @@ public class StreamedCourseXMLReader extends XMLReader {
/**
* Reads "name" attribute of CompoundMark element with corresponding CompoundMarkID
*
* @param compoundMarkID unique ID for CompoundMark element
* @return value of "name" attribute
*/
private String getCompoundMarkName(int compoundMarkID) {
return marks.get(compoundMarkID).getAttribute("Name");
return compoundMarks.get(compoundMarkID).getAttribute("Name");
}
/**
* Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements.
*
* @throws StreamedCourseXMLException if markers cannot be resolved from CompoundMark
*/
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
Marker lastMarker = getMarker(getCompoundMarkID((Element) nCorners.item(0)));
String legName = getCompoundMarkName(getCompoundMarkID((Element) nCorners.item(0)));
for (int i = 1; i < nCorners.getLength(); i++) {
Element markXML = (Element) nCorners.item(i);
Marker lastMarker = getMarker(getCompoundMarkID((Element)nCorners.item(0)));
String legName = getCompoundMarkName(getCompoundMarkID((Element)nCorners.item(0)));
for(int i = 1; i < nCorners.getLength(); i++) {
Element markXML = (Element)nCorners.item(i);
Marker currentMarker = getMarker(getCompoundMarkID(markXML));
legs.add(new Leg(legName, lastMarker, currentMarker, i - 1));
legs.add(new Leg(legName, lastMarker, currentMarker, i-1));
lastMarker = currentMarker;
legName = getCompoundMarkName(getCompoundMarkID(markXML));
}
@ -186,7 +182,7 @@ public class StreamedCourseXMLReader extends XMLReader {
private void readCourseLimit() {
Element nCourseLimit = (Element) doc.getElementsByTagName("CourseLimit").item(0);
for (int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {
for(int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {
Node limit = nCourseLimit.getChildNodes().item(i);
if (limit.getNodeName().equals("Limit")) {
double lat = Double.parseDouble(limit.getAttributes().getNamedItem("Lat").getTextContent());
@ -195,6 +191,7 @@ public class StreamedCourseXMLReader extends XMLReader {
}
}
double maxLatitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
double maxLongitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING;
double minLatitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
@ -220,15 +217,17 @@ public class StreamedCourseXMLReader extends XMLReader {
return legs;
}
public List<Marker> getMarkers() { return markers; }
public Double getPadding() {
return COORDINATEPADDING;
}
public Date getCreationTimeDate() {
public ZonedDateTime getCreationTimeDate() {
return creationTimeDate;
}
public Date getRaceStartTime() {
public ZonedDateTime getRaceStartTime() {
return raceStartTime;
}

@ -37,6 +37,14 @@ public class Marker {
return mark2;
}
/**
* Returns true if mark consists of two points, e.g. it is a gate.
* @return boolean
*/
public boolean isCompoundMark() {
return mark1 != mark2;
}
public GPSCoordinate getAverageGPSCoordinate() {
return averageGPSCoordinate;
}

@ -43,7 +43,7 @@ public class RaceClock {
*/
public void setTime(ZonedDateTime time) {
this.time = time;
this.timeString.set(DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z").format(time));
this.timeString.set(DateTimeFormatter.ofPattern("HH:mm:ss dd/MM/YYYY Z").format(time));
this.lastTime = System.currentTimeMillis();
}

@ -7,8 +7,10 @@ import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.transform.Rotate;
import seng302.*;
import seng302.Controllers.RaceController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@ -17,7 +19,6 @@ import java.util.List;
* Created by fwy13 on 17/03/17.
*/
public class ResizableRaceCanvas extends Canvas {
double[] xpoints = {}, ypoints = {};
private GraphicsContext gc;
private RaceMap map;
private List<BoatInRace> boats;
@ -26,7 +27,9 @@ public class ResizableRaceCanvas extends Canvas {
private boolean annoAbbrev = true;
private boolean annoSpeed = true;
private boolean annoPath = true;
private ArrayList<GPSCoordinate> raceBoundaries;
private List<GPSCoordinate> raceBoundaries;
private List<Marker> markers;
double[] xpoints = {}, ypoints = {};
public ResizableRaceCanvas(RaceDataSource raceData) {
gc = this.getGraphicsContext2D();
@ -38,7 +41,11 @@ public class ResizableRaceCanvas extends Canvas {
double long1 = raceData.getMapTopLeft().getLongitude();
double lat2 = raceData.getMapBottomRight().getLatitude();
double long2 = raceData.getMapBottomRight().getLongitude();
setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight()));
this.raceBoundaries = raceData.getBoundary();
this.markers = raceData.getMarkers();
}
/**
@ -161,15 +168,15 @@ public class ResizableRaceCanvas extends Canvas {
private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) {
String text = "";
//Check name toggle value
if (annoName) {
if (annoName){
text += String.format("%s ", name);
}
//Check abbreviation toggle value
if (annoAbbrev) {
if (annoAbbrev){
text += String.format("%s ", abbrev);
}
//Check speed toggle value
if (annoSpeed) {
if (annoSpeed){
text += String.format("%.2fkn", speed);
}
//String text = String.format("%s, %2$.2fkn", name, speed);
@ -204,6 +211,22 @@ public class ResizableRaceCanvas extends Canvas {
gc.fillPolygon(xpoints, ypoints, xpoints.length);
}
/**
* Draw race markers
*/
public void drawMarkers() {
for(Marker marker: markers) {
GraphCoordinate mark1 = this.map.convertGPS(marker.getMark1());
if(marker.isCompoundMark()) {
GraphCoordinate mark2 = this.map.convertGPS(marker.getMark2());
// TODO - improve colour coding of markers
displayLine(mark1, mark2, Color.GREEN);
} else {
displayPoint(mark1, Color.GREEN);
}
}
}
/**
* Draws the Race Map
*/
@ -220,26 +243,9 @@ public class ResizableRaceCanvas extends Canvas {
this.map.setHeight((int) height);
this.map.setWidth((int) width);
//finish line
gc.setLineWidth(2);
drawBoundaries();
GraphCoordinate finishLineCoord1 = this.map.convertGPS(Constants.finishLineMarker1);
GraphCoordinate finishLineCoord2 = this.map.convertGPS(Constants.finishLineMarker2);
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
//marks
GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1);
GraphCoordinate windwardGate1 = this.map.convertGPS(Constants.windwardGate1);
GraphCoordinate windwardGate2 = this.map.convertGPS(Constants.windwardGate2);
GraphCoordinate leewardGate1 = this.map.convertGPS(Constants.leewardGate1);
GraphCoordinate leewardGate2 = this.map.convertGPS(Constants.leewardGate2);
displayMark(markCoord, Color.GOLD);
displayLine(windwardGate1, windwardGate2, Color.DARKCYAN);
displayLine(leewardGate1, leewardGate2, Color.DARKVIOLET);
//start line
GraphCoordinate startline1 = this.map.convertGPS(Constants.startLineMarker1);
GraphCoordinate startline2 = this.map.convertGPS(Constants.startLineMarker2);
displayLine(startline1, startline2, Color.GREEN);
drawMarkers();
updateBoats();
@ -336,14 +342,13 @@ public class ResizableRaceCanvas extends Canvas {
if (raceAnno)
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
if (boat.isTrackVisible()) drawTrack(boat);
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
*/

@ -2,6 +2,7 @@ package seng302;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
import java.time.ZonedDateTime;
import java.util.List;
@ -11,14 +12,11 @@ import java.util.List;
*/
public interface RaceDataSource {
List<BoatInRace> getBoats();
List<Leg> getLegs();
List<Marker> getMarkers();
List<GPSCoordinate> getBoundary();
ZonedDateTime getZonedDateTime();
GPSCoordinate getMapTopLeft();
GPSCoordinate getMapBottomRight();
}

@ -17,6 +17,7 @@ import java.util.List;
/**
* Created by fwy13 on 26/03/2017.
* @deprecated use {@link seng302.Mock.StreamedCourseXMLReader}
*/
public class RaceXMLReader extends XMLReader implements RaceDataSource {
private static double COORDINATEPADDING = 0.0005;
@ -275,6 +276,11 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
return new GPSCoordinate(startLat, startLong);
}
@Override
public List<Marker> getMarkers() {
return null;
}
public List<BoatInRace> getBoats() {
return boats;
}

@ -1,13 +1,17 @@
package seng302.Mock;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import seng302.GPSCoordinate;
import seng302.Model.Leg;
import seng302.Model.Marker;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Tests only work on the current version of mockXML/raceXML/raceTest.xml
@ -72,6 +76,23 @@ public class StreamedRaceTest {
"M2",
"Gate"
};
for (int i = 0; i < legs.size(); i++) assertEquals(expectedNames[i], legs.get(i).getName());
for(int i = 0; i < legs.size(); i++) assertEquals(expectedNames[i], legs.get(i).getName());
}
/**
* raceTest.xml is not compliant with this test. Markers are positioned far out of bounds.
*/
@Test
public void markersWithinRaceBoundaries() {
GPSCoordinate topLeft = streamedCourseXMLReader.getMapTopLeft();
GPSCoordinate bottomRight = streamedCourseXMLReader.getMapBottomRight();
for(Marker marker: streamedCourseXMLReader.getMarkers()) {
GPSCoordinate centre = marker.getAverageGPSCoordinate();
assertTrue(centre.getLatitude() < bottomRight.getLatitude());
assertTrue(centre.getLatitude() > topLeft.getLatitude());
assertTrue(centre.getLongitude() > bottomRight.getLongitude());
assertTrue(centre.getLongitude() < topLeft.getLongitude());
}
}
}

Loading…
Cancel
Save