diff --git a/doc/design_decisions.md b/doc/design_decisions.md deleted file mode 100644 index e9421fa2..00000000 --- a/doc/design_decisions.md +++ /dev/null @@ -1,2 +0,0 @@ -# Design Decisions - diff --git a/doc/examples/examples.md b/doc/examples/examples.md deleted file mode 100644 index 994f4e89..00000000 --- a/doc/examples/examples.md +++ /dev/null @@ -1,7 +0,0 @@ -# Examples - -You should also include example data files for your application that demonstrate the -features of your application. These should contain adequate amounts of data that -would be expected from actual use of your application. - -This file should provide a basic overview of the example files available. diff --git a/doc/user_manual.md b/doc/user_manual.md deleted file mode 100644 index 7c571c01..00000000 --- a/doc/user_manual.md +++ /dev/null @@ -1 +0,0 @@ -# User Manual \ No newline at end of file diff --git a/pom.xml b/pom.xml index b22f7658..cd0a669d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,151 +3,15 @@ 4.0.0 seng302 team-7 - jar - 0.0 + pom + 1.0-SNAPSHOT team-7 - https://eng-git.canterbury.ac.nz/SENG302-2016/team-7 - - - - junit - junit - 4.12 - test - - - - org.geotools - gt-referencing - 9.0 - - - - - org.mockito - mockito-all - 1.9.5 - - - - com.github.bfsmith - geotimezone - 1.0.3 - - - org.testng - testng - 6.11 - test - + + mock + visualiser + - - - - - - maven2-repository.dev.java.net - Java.net repository - http://download.java.net/maven/2 - - - osgeo - Open Source Geospatial Foundation Repository - http://download.osgeo.org/webdav/geotools/ - - - - true - - opengeo - OpenGeo Maven Repository - http://repo.opengeo.org - - - - - 1.8 - 1.8 - + https://eng-git.canterbury.ac.nz/SENG302-2016/team-7 - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - - org.apache.maven.plugins - maven-shade-plugin - 2.4.3 - - - - - seng302.App - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - package - - shade - - - - - - - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.5 - - - org.apache.maven.plugins - maven-pmd-plugin - 3.6 - - true - ${maven.compiler.target} - - /rulesets/java/basic.xml - /rulesets/java/imports.xml - /rulesets/java/codesize.xml - /rulesets/java/design.xml - /rulesets/java/empty.xml - /rulesets/java/junit.xml - /rulesets/java/unusedcode.xml - - true - utf-8 - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.19.1 - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.8.1 - - - diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java deleted file mode 100644 index cf9d3ed2..00000000 --- a/src/main/java/seng302/App.java +++ /dev/null @@ -1,82 +0,0 @@ -package seng302; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; - -public class App extends Application { - Stage primaryStage; - BorderPane mainContainer; - Scene mainScene; - - /** - * Entry point for running the programme - * - * @param args for starting the programme - */ - public static void main(String[] args) { - launch(args); - } - - public void start(Stage stage) throws Exception { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/scenes/main.fxml")); - Parent root = loader.load(); - Scene scene = new Scene(root, 1200, 800); - stage.setScene(scene); - stage.show(); - } - -// /** -// * Loads and sets up the GUI elements -// * -// * @param primaryStage Base for all scenes -// * @throws Exception Error in initialising programme -// */ -// @Override -// public void start(Stage primaryStage) throws Exception { -// this.primaryStage = primaryStage; -// primaryStage.minHeightProperty().setValue(600); -// primaryStage.minWidthProperty().setValue(780); -// //load the first container -// try { -// FXMLLoader loader = new FXMLLoader(); -// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/main.fxml"); -// mainContainer = (BorderPane) loader.load(in); -// mainScene = new Scene(mainContainer, 1200, 800); -// primaryStage.setScene(mainScene); -// primaryStage.sizeToScene(); -// MainController mainController = (MainController) loader.getController(); -// mainController.setParent(this); -// in.close(); -// //add the center -// loadPane("race.fxml"); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// primaryStage.show(); -// } -// -// /** -// * Loads panes for use in the GUI -// * -// * @param fxmlName name of resource fxml file -// * @throws Exception critical error in loading file -// */ -// public void loadPane(String fxmlName) throws Exception { -// FXMLLoader loader = new FXMLLoader(); -// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/" + fxmlName); -// Parent page; -// try { -// page = (Parent) loader.load(in); -// } finally { -// in.close(); -// } -// mainContainer.getChildren().remove(mainContainer.getCenter()); -// mainContainer.setCenter(page); -// Controller controller = (Controller) loader.getController(); -// controller.setParent(this); -// } -} diff --git a/src/main/java/seng302/Constants.java b/src/main/java/seng302/Constants.java deleted file mode 100644 index b2d96fcb..00000000 --- a/src/main/java/seng302/Constants.java +++ /dev/null @@ -1,33 +0,0 @@ -package seng302; - -import javafx.scene.paint.Color; -import seng302.Model.BoatInRace; - -/** - * Constants that are used throughout the program - * Created by Erika on 19-Mar-17. - */ -public class Constants { - - public static final int NMToMetersConversion = 1852; // 1 nautical mile = 1852 meters - - public static final GPSCoordinate startLineMarker1 = new GPSCoordinate(32.296577, -64.854304); - public static final GPSCoordinate startLineMarker2 = new GPSCoordinate(32.293771, -64.855242); - public static final GPSCoordinate mark1 = new GPSCoordinate(32.293039, -64.843983); - public static final GPSCoordinate windwardGate1 = new GPSCoordinate(32.284680, -64.850045); - public static final GPSCoordinate windwardGate2 = new GPSCoordinate(32.280164, -64.847591); - public static final GPSCoordinate leewardGate1 = new GPSCoordinate(32.309693, -64.835249); - public static final GPSCoordinate leewardGate2 = new GPSCoordinate(32.308046, -64.831785); - public static final GPSCoordinate finishLineMarker1 = new GPSCoordinate(32.317379, -64.839291); - public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260); - - public static final double wakeScale = 10; - - public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[] - {new BoatInRace("Oracle Team USA", 30.0, Color.BLUEVIOLET, "Oracle"), - new BoatInRace("Land Rover BAR", 23.0, Color.BLACK, "BGR"), - new BoatInRace("SoftBank Team Japan", 27.0, Color.RED, "JPN"), - new BoatInRace("Groupama Team France", 25.0, Color.ORANGE, "FRA"), - new BoatInRace("Artemis Racing", 22.5, Color.DARKOLIVEGREEN, "SWE"), - new BoatInRace("Emirates Team New Zealand", 62, Color.LIMEGREEN, "ETNZ")}; -} diff --git a/src/main/java/seng302/Controllers/Controller.java b/src/main/java/seng302/Controllers/Controller.java deleted file mode 100644 index c5d160e7..00000000 --- a/src/main/java/seng302/Controllers/Controller.java +++ /dev/null @@ -1,33 +0,0 @@ -package seng302.Controllers; - -import javafx.fxml.Initializable; -import seng302.App; - -import java.net.URL; -import java.util.ResourceBundle; - -/** - * Controller parent for app controllers. - * Created by fwy13 on 15/03/2017. - */ -public abstract class Controller implements Initializable { - protected MainController parent; - - /** - * Sets the parent of the application - * - * @param parent controller - */ - public void setParent(MainController parent) { - this.parent = parent; - } - - /** - * Initialisation class that is run on start up. - * - * @param location resources location - * @param resources resources bundle - */ - @Override - public abstract void initialize(URL location, ResourceBundle resources); -} diff --git a/src/main/java/seng302/Controllers/MainController.java b/src/main/java/seng302/Controllers/MainController.java deleted file mode 100644 index 796c47b4..00000000 --- a/src/main/java/seng302/Controllers/MainController.java +++ /dev/null @@ -1,42 +0,0 @@ -package seng302.Controllers; - -import javafx.fxml.FXML; -import javafx.scene.control.SplitPane; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.GridPane; -import seng302.RaceDataSource; -import seng302.RaceXMLReader; - -import java.net.URL; -import java.util.ResourceBundle; - -/** - * Created by fwy13 on 15/03/2017. - */ -public class MainController extends Controller { - @FXML StartController startController; - @FXML RaceController raceController; - - public void beginRace(int scaleFactor, RaceDataSource raceData) { - raceController.startRace(scaleFactor, raceData); - } - - - - - /** - * Main Controller for the applications will house the menu and the displayed pane. - * - * @param location of resources - * @param resources bundle - */ - @Override - public void initialize(URL location, ResourceBundle resources) { - startController.setParent(this); - raceController.setParent(this); - AnchorPane.setTopAnchor(startController.startWrapper(), 0.0); - AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0); - AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0); - AnchorPane.setRightAnchor(startController.startWrapper(), 0.0); - } -} diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java deleted file mode 100644 index 6d4bdf8e..00000000 --- a/src/main/java/seng302/Controllers/RaceController.java +++ /dev/null @@ -1,227 +0,0 @@ -package seng302.Controllers; - - -import javafx.beans.property.ReadOnlyObjectWrapper; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.ObservableList; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.scene.layout.GridPane; -import org.xml.sax.SAXException; -import seng302.Model.*; -import seng302.RaceDataSource; -import seng302.RaceXMLReader; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.ResourceBundle; - -/** - * Created by fwy13 on 15/03/2017. - */ -public class RaceController extends Controller { - @FXML - GridPane canvasBase; - - //user saved data for annotation display - private ArrayList presetAnno; - - ResizableRaceCanvas raceMap; - @FXML - SplitPane race; - @FXML - CheckBox showFPS; - - @FXML - CheckBox showBoatPath; - @FXML - CheckBox showAnnotations; - @FXML - Label timer; - @FXML - Label FPS; - @FXML - Label timeZone; - - @FXML - CheckBox showName; - @FXML - CheckBox showAbbrev; - @FXML - CheckBox showSpeed; - @FXML - Button saveAnno; - @FXML - Button showSetAnno; - - @FXML - TableView boatInfoTable; - @FXML - TableColumn boatPlacingColumn; - @FXML - TableColumn boatTeamColumn; - @FXML - TableColumn boatMarkColumn; - @FXML - TableColumn boatSpeedColumn; - - /** - * Updates the ResizableRaceCanvas (raceMap) with most recent data - * - * @param boats boats that are to be displayed in the race - * @see ResizableRaceCanvas - */ - public void updateMap(ObservableList boats) { - raceMap.setBoats(boats); - raceMap.update(); - } - - /** - * Updates the array listened by the TableView (boatInfoTable) that displays the boat information. - * - * @param race Race to listen to. - */ - public void setInfoTable(Race race) { - //boatInfoTable.getItems().clear(); - boatInfoTable.setItems(race.getStartingBoats()); - - boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); - boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp()); - boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName()); - boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty()); - } - - - @Override - public void initialize(URL location, ResourceBundle resources) { - //listener for fps - showFPS.selectedProperty().addListener((ov, old_val, new_val) -> { - if (showFPS.isSelected()) { - FPS.setVisible(true); - } else { - FPS.setVisible(false); - } - }); - } - - /** - * Initializes and runs the race, based on the user's chosen scale factor - * Currently uses an example racecourse - * - * @param scaleFactor scale value of race - */ - public void startRace(int scaleFactor, RaceDataSource raceData) { - ConstantVelocityRace newRace = new ConstantVelocityRace(raceData, this, scaleFactor); - newRace.initialiseBoats(); - - raceMap = new ResizableRaceCanvas(raceData); - raceMap.setMouseTransparent(true); - raceMap.widthProperty().bind(canvasBase.widthProperty()); - raceMap.heightProperty().bind(canvasBase.heightProperty()); - raceMap.setBoats(newRace.getStartingBoats()); - raceMap.setRaceBoundaries(raceData.getBoundary()); - raceMap.drawRaceMap(); - raceMap.setVisible(true); - - canvasBase.getChildren().add(raceMap); - race.setVisible(true); - - //Initialize save annotation array, fps listener, and annotation listeners - //timezone - RaceClock raceClock = new RaceClock(raceData.getMark()); - timeZone.setText(raceClock.getTimeZone()); - initializeFPS(); - initializeAnnotations(); - - new Thread((newRace)).start(); - } - - - /** - * Set the value for the race clock label - * - * @param time time that the label will be updated to - */ - public void setTimer(String time) { - timer.setText(time); - } - - /** - * Set the value for the fps label - * - * @param fps fps that the label will be updated to - */ - public void setFrames(String fps) { - FPS.setText((fps)); - } - - /** - * Set up FPS display at bottom of screen - */ - private void initializeFPS() { - showFPS.setVisible(true); - showFPS.selectedProperty().addListener((ov, old_val, new_val) -> { - if (showFPS.isSelected()) { - FPS.setVisible(true); - } else { - FPS.setVisible(false); - } - }); - } - - /** - * Set up boat annotations - */ - private void initializeAnnotations() { - presetAnno = new ArrayList<>(); - //listener for annotation - showAnnotations.selectedProperty().addListener((ov, old_val, new_val) -> { - raceMap.toggleAnnotations(); - raceMap.update(); - }); - //listener for show name in annotation - showName.selectedProperty().addListener((ov, old_val, new_val) -> { - raceMap.toggleAnnoName(); - raceMap.update(); - }); - //listener for show abbreviation for annotation - showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> { - raceMap.toggleAnnoAbbrev(); - raceMap.update(); - }); - - //listener for show boat path for annotation - showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> { - raceMap.toggleBoatPath(); - raceMap.update(); - }); - //listener to show speed for annotation - showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> { - raceMap.toggleAnnoSpeed(); - raceMap.update(); - }); - //listener to save currently selected annotation - saveAnno.setOnAction(event -> { - presetAnno.clear(); - presetAnno.add(showName.isSelected()); - presetAnno.add(showAbbrev.isSelected()); - presetAnno.add(showSpeed.isSelected()); - presetAnno.add(showBoatPath.isSelected()); - }); - //listener to show saved annotation - showSetAnno.setOnAction(event -> { - if (presetAnno.size() > 0) { - showName.setSelected(presetAnno.get(0)); - showAbbrev.setSelected(presetAnno.get(1)); - showSpeed.setSelected(presetAnno.get(2)); - showBoatPath.setSelected(presetAnno.get(3)); - raceMap.update(); - } - }); - } -} \ No newline at end of file diff --git a/src/main/java/seng302/Controllers/StartController.java b/src/main/java/seng302/Controllers/StartController.java deleted file mode 100644 index f62fb6ea..00000000 --- a/src/main/java/seng302/Controllers/StartController.java +++ /dev/null @@ -1,159 +0,0 @@ -package seng302.Controllers; - -import javafx.animation.AnimationTimer; -import javafx.application.Platform; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.GridPane; -import org.xml.sax.SAXException; -import seng302.Model.BoatInRace; -import seng302.Model.RaceClock; -import seng302.RaceDataSource; -import seng302.RaceXMLReader; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.net.URL; -import java.util.List; -import java.util.ResourceBundle; - -/** - * Created by esa46 on 6/04/17. - */ -public class StartController extends Controller { - - @FXML private GridPane start; - @FXML private AnchorPane startWrapper; - - @FXML private TableView boatNameTable; - @FXML private TableColumn boatNameColumn; - @FXML private TableColumn boatCodeColumn; - @FXML private Label timeZoneTime; - @FXML private Label timer; - @FXML private int PRERACE_TIME = 15000; - - @FXML Button oneMinButton; - @FXML Button fiveMinButton; - @FXML Button fifteenMinButton; - - private RaceClock raceClock; - - private RaceDataSource raceData; - - /** - * Begins the race with a scale factor of 15 - */ - public void startRace1Min() { - startRace(15); - } - - /** - * Begins the race with a scale factor of 3 - */ - public void startRace5Min() { - startRace(3); - } - - /** - * Begins the race with a scale factor of 1 - */ - public void startRaceNoScaling() { - startRace(1); - } - - private void startRace(int raceScale){ - - oneMinButton.setDisable(true); - fiveMinButton.setDisable(true); - fifteenMinButton.setDisable(true); - countdownTimer(raceScale); - } - - @Override - public void initialize(URL location, ResourceBundle resources){ - raceData = null; - try { - raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml"); - } catch (IOException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } - initialiseTables(); - } - - public AnchorPane startWrapper(){ - return startWrapper; - } - - private void initialiseTables() { - List boats = raceData.getBoats(); - ObservableList observableBoats = FXCollections.observableArrayList(boats); - - boatNameTable.setItems(observableBoats); - boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); - boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev")); - //timezone - raceClock = new RaceClock(raceData.getMark()); - timeZoneTime.textProperty().bind(raceClock.timeProperty()); - } - - - /** - * Updates the calculated time to the timer label - * - * @param time The calculated time from calcTimer() method - */ - protected void updateTime(String time) { - Platform.runLater(() -> { - timer.setText(time); - }); - } - - /** - * Countdown timer until race starts. Use PRERACE_TIME to set countdown duration. - */ - protected void countdownTimer(int scaleFactor) { - new AnimationTimer() { - long currentTime = System.currentTimeMillis(); - long startTime = currentTime + (PRERACE_TIME/scaleFactor); - long minutes; - long currentTimeInSeconds; - long remainingSeconds; - long hours; - long timeLeft; - - @Override - public void handle(long arg0) { - timeLeft = startTime - currentTime; - if (timeLeft <= 0) { - updateTime("Race is starting..."); - stop(); - parent.beginRace(scaleFactor, raceData); - startWrapper.setVisible(false); - - } else { - currentTimeInSeconds = (timeLeft*scaleFactor) / 1000; - minutes = currentTimeInSeconds / 60; - remainingSeconds = currentTimeInSeconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - updateTime(String.format("Race Clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds)); - raceClock.updateTime(); - - } - currentTime = System.currentTimeMillis(); - } - }.start(); - } - -} diff --git a/src/main/java/seng302/GPSCoordinate.java b/src/main/java/seng302/GPSCoordinate.java deleted file mode 100644 index 9ece540f..00000000 --- a/src/main/java/seng302/GPSCoordinate.java +++ /dev/null @@ -1,72 +0,0 @@ -package seng302; - -/** - * GPS Coordinate for the world map. - * Created by esa46 on 15/03/17. - */ -public class GPSCoordinate { - - private double latitude; - private double longitude; - - /** - * Constructor Method - * - * @param latitude latitude the coordinate is located at. - * @param longitude Longitude that the coordinate is located at. - */ - public GPSCoordinate(double latitude, double longitude) { - this.latitude = latitude; - this.longitude = longitude; - } - - /** - * Gets the Latitude that the Coordinate is at. - * - * @return Returns the latitude of the Coordinate. - */ - public double getLatitude() { - return latitude; - } - - /** - * Gets the Longitude that the Coordinate is at. - * - * @return Returns the longitude of the Coordinate. - */ - public double getLongitude() { - return longitude; - } - - /** - * To String method of the Coordinate in the form Latitude: $f, Longitude: $f. - * - * @return A String representation of the GPSCoordinate Class. - */ - public String toString() { - return String.format("Latitude: %f, Longitude: %f", latitude, longitude); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - GPSCoordinate that = (GPSCoordinate) o; - - if (Math.abs(this.latitude - latitude) > 1e-6) return false; - return (Math.abs(this.longitude - longitude) < 1e-6); - } - - @Override - public int hashCode() { - int result; - long temp; - temp = Double.doubleToLongBits(latitude); - result = (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(longitude); - result = 31 * result + (int) (temp ^ (temp >>> 32)); - return result; - } -} - diff --git a/src/main/java/seng302/GraphCoordinate.java b/src/main/java/seng302/GraphCoordinate.java deleted file mode 100644 index 050931c2..00000000 --- a/src/main/java/seng302/GraphCoordinate.java +++ /dev/null @@ -1,40 +0,0 @@ -package seng302; - -/** - * Graph Coordinate that is to be displayed on the Canvas - * Created by cbt24 on 15/03/17. - */ -public class GraphCoordinate { - private int x; - private int y; - - /** - * Constructor method. - * - * @param x X coordinate. - * @param y Y coordinate. - */ - public GraphCoordinate(int x, int y) { - this.x = x; - this.y = y; - } - - /** - * Returns the X coordinate. - * - * @return x axis Coordinate. - */ - public int getX() { - return x; - } - - /** - * Returns the Y coordinate. - * - * @return y axis Coordinate. - */ - public int getY() { - return y; - } - -} diff --git a/src/main/java/seng302/Mock/Regatta.java b/src/main/java/seng302/Mock/Regatta.java deleted file mode 100644 index 3b749256..00000000 --- a/src/main/java/seng302/Mock/Regatta.java +++ /dev/null @@ -1,99 +0,0 @@ -package seng302.Mock; - -/** - * Created by jjg64 on 19/04/17. - */ -public class Regatta { - int regattaID; - String RegattaName; - int raceID = 0; - String courseName; - double centralLatitude; - double centralLongitude; - double centralAltitude; - float utcOffset; - float magneticVariation; - - public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) { - this.regattaID = regattaID; - this.RegattaName = regattaName; - this.courseName = courseName; - this.centralLatitude = centralLatitude; - this.centralLongitude = centralLongitude; - this.centralAltitude = centralAltitude; - this.utcOffset = utcOffset; - this.magneticVariation = magneticVariation; - } - - public int getRegattaID() { - return regattaID; - } - - public void setRegattaID(int ID) { - this.regattaID = ID; - } - - public String getRegattaName() { - return RegattaName; - } - - public void setRegattaName(String regattaName) { - RegattaName = regattaName; - } - - public int getRaceID() { - return raceID; - } - - public void setRaceID(int raceID) { - this.raceID = raceID; - } - - public String getCourseName() { - return courseName; - } - - public void setCourseName(String courseName) { - this.courseName = courseName; - } - - public double getCentralLatitude() { - return centralLatitude; - } - - public void setCentralLatitude(double centralLatitude) { - this.centralLatitude = centralLatitude; - } - - public double getCentralLongitude() { - return centralLongitude; - } - - public void setCentralLongitude(double centralLongitude) { - this.centralLongitude = centralLongitude; - } - - public double getCentralAltitude() { - return centralAltitude; - } - - public void setCentralAltitude(double centralAltitude) { - this.centralAltitude = centralAltitude; - } - - public float getUtcOffset() { - return utcOffset; - } - - public void setUtcOffset(float utcOffset) { - this.utcOffset = utcOffset; - } - - public float getMagneticVariation() { - return magneticVariation; - } - - public void setMagneticVariation(float magneticVariation) { - this.magneticVariation = magneticVariation; - } -} diff --git a/src/main/java/seng302/Mock/RegattaXMLReader.java b/src/main/java/seng302/Mock/RegattaXMLReader.java deleted file mode 100644 index 6291825f..00000000 --- a/src/main/java/seng302/Mock/RegattaXMLReader.java +++ /dev/null @@ -1,68 +0,0 @@ -package seng302.Mock; - -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import seng302.XMLReader; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; - -/** - * Created by jjg64 on 19/04/17. - */ -public class RegattaXMLReader extends XMLReader { - private Regatta regatta; - - /** - * Constructor for Regatta XML - * @param filePath path of the file - * @throws IOException error - * @throws SAXException error - * @throws ParserConfigurationException error - */ - public RegattaXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException { - this(filePath, true); - } - - /** - * Constructor for Regatta 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 - * @throws ParserConfigurationException error - */ - public RegattaXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException { - super(filePath); - if (read) { - read(); - } - } - - /** - * Read the XML - */ - private void read() { - NodeList attributeConfig = doc.getElementsByTagName("RegattaConfig"); - Element attributes = (Element) attributeConfig.item(0); - makeRegatta(attributes); - } - - private void makeRegatta(Element attributes) { - int regattaID = Integer.parseInt(getTextValueOfNode(attributes, "RegattaID")); - String regattaName = getTextValueOfNode(attributes, "RegattaName"); - String courseName = getTextValueOfNode(attributes, "CourseName"); - double centralLatitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralLatitude")); - double centralLongitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralLongitude")); - double centralAltitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralAltitude")); - float utcOffset = Float.parseFloat(getTextValueOfNode(attributes, "UtcOffset")); - float magneticVariation = Float.parseFloat(getTextValueOfNode(attributes, "MagneticVariation")); - - regatta = new Regatta(regattaID, regattaName, courseName, centralLatitude, centralLongitude, centralAltitude, utcOffset, magneticVariation); - } - - public Regatta getRegatta() { - return regatta; - } -} diff --git a/src/main/java/seng302/Model/Boat.java b/src/main/java/seng302/Model/Boat.java deleted file mode 100644 index 49b5a0f9..00000000 --- a/src/main/java/seng302/Model/Boat.java +++ /dev/null @@ -1,86 +0,0 @@ -package seng302.Model; - -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -/** - * Created by fwy13 on 3/03/17. - */ -public class Boat { - - private StringProperty name; - private double velocity; - private StringProperty velocityProp; - private String abbrev; - - /** - * Boat initialiser which keeps all of the information of the boat. - * - * @param name Name of the Boat. - * @param velocity Speed in m/s that the boat travels at. - * @param abbrev nam abbreviation - */ - public Boat(String name, double velocity, String abbrev) { - this.velocity = velocity; - this.velocityProp = new SimpleStringProperty(String.valueOf(Math.round(velocity))); - this.abbrev = abbrev; - this.name = new SimpleStringProperty(name); - } - - /** - * @return Name of the boat - */ - public StringProperty getName() { - return name; - } - - /** - * Sets the boat name - * - * @param name of boat - */ - public void setName(String name) { - this.name.setValue(name); - } - - /** - * @return Speed of the boat. - */ - public double getVelocity() { - return velocity; - } - - /** - * Sets the speed of the boat in knots. - * - * @param velocity speed in knots - */ - public void setVelocity(double velocity) { - this.velocity = velocity; - this.velocityProp.setValue(String.valueOf(Math.round(velocity))); - } - - /** - * Print method prints the name of the boat - * - * @return Name of the boat. - */ - public String toString() { - return getName().getValue(); - } - - /** - * @return Velocity String Property of the boat - */ - public StringProperty getVelocityProp() { - return velocityProp; - } - - /** - * @return Abbreviation of the boat - */ - public String getAbbrev() { - return abbrev; - } - -} diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java deleted file mode 100644 index 520e7b06..00000000 --- a/src/main/java/seng302/Model/BoatInRace.java +++ /dev/null @@ -1,329 +0,0 @@ -package seng302.Model; - -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.scene.paint.Color; -import org.geotools.referencing.GeodeticCalculator; -import seng302.Constants; -import seng302.GPSCoordinate; - -import java.awt.geom.Point2D; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * Boat in the Race extends Boat. - * Created by esa46 on 15/03/17. - */ -public class BoatInRace extends Boat { - - private Leg currentLeg; - private double scaledVelocity; - private double distanceTravelledInLeg; - private GPSCoordinate currentPosition; - private long timeFinished; - private Color colour; - private boolean finished = false; - private StringProperty currentLegName; - private boolean started = false; - private StringProperty position; - private double heading; - - private Queue 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. - * - * @param name Name of the boat. - * @param velocity Speed that the boat travels. - * @param colour Colour the boat will be displayed as on the map - * @param abbrev of boat - */ - public BoatInRace(String name, double velocity, Color colour, String abbrev) { - super(name, velocity, abbrev); - setColour(colour); - currentLegName = new SimpleStringProperty(""); - position = new SimpleStringProperty("-"); - } - - /** - * Calculates the azimuth of the travel via map coordinates of the raceMarkers - * - * @return the direction that the boat is heading towards in degrees (-180 to 180). - */ - public double calculateAzimuth() { - - GeodeticCalculator calc = new GeodeticCalculator(); - GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate(); - GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate(); - - calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude()); - calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude()); - - return calc.getAzimuth(); - } - - /** - * Converts an azimuth to a bearing - * - * @param azimuth azimuth value to be converted - * @return the bearings in degrees (0 to 360). - */ - public static double calculateHeading(double azimuth) { - if (azimuth >= 0) { - return azimuth; - } else { - return azimuth + 360; - } - } - - public double getHeading() { - return heading; - } - - public void setHeading(double heading) { - this.heading = heading; - } - - /** - * Calculates the bearing of the travel via map coordinates of the raceMarkers - * - * @return the direction that the boat is heading towards in degrees (0 to 360). - */ - public double calculateHeading() { - double azimuth = this.calculateAzimuth(); - return calculateHeading(azimuth); - } - - /** - * Returns the position of the end of the boat's wake, which is 180 degrees - * from the boat's heading, and whose length is proportional to the boat's - * speed. - * - * @return GPSCoordinate of wake endpoint. - */ - public GPSCoordinate getWake() { - double reverseHeading = getHeading() - 180; - double distance = Constants.wakeScale * getVelocity(); - - GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint( - new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude()) - ); - calc.setDirection(reverseHeading, distance); - Point2D endpoint = calc.getDestinationGeographicPoint(); - return new GPSCoordinate(endpoint.getY(), endpoint.getX()); - } - - /** - * @return Scaled velocity of the boat - */ - public double getScaledVelocity() { - return scaledVelocity; - } - - /** - * Sets the boat's scaled velocity - * - * @param velocity of boat - */ - public void setScaledVelocity(double velocity) { - this.scaledVelocity = velocity; - } - - /** - * @return Returns the current position of the boat in a GPSCoordinate Class. - * @see GPSCoordinate - */ - public GPSCoordinate getCurrentPosition() { - return currentPosition; - } - - /** - * Sets the current position on the GPS that the boat. - * - * @param position GPSCoordinate of the position that the boat is currently on. - * @see GPSCoordinate - */ - public void setCurrentPosition(GPSCoordinate position) { - this.currentPosition = position; - } - - /** - * @return Returns the time that the boat finished the race. - */ - public long getTimeFinished() { - return timeFinished; - } - - /** - * Sets the time that the boat finished the race. - * - * @param timeFinished Time the boat finished the race. - */ - public void setTimeFinished(long timeFinished) { - this.timeFinished = timeFinished; - } - - /** - * @return Returns the colour of the boat. - */ - public Color getColour() { - return colour; - } - - /** - * Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas. - * - * @param colour Colour that the boat is to be set to. - * @see ResizableRaceCanvas - */ - public void setColour(Color colour) { - this.colour = colour; - } - - /** - * Gets the current leg that the boat is on. - * - * @return returns the leg the boat is on in a Leg class - * @see Leg - */ - public Leg getCurrentLeg() { - return currentLeg; - } - - /** - * Sets the boat's current leg. - * - * @param currentLeg Leg class that the boat is currently on. - * @see Leg - */ - public void setCurrentLeg(Leg currentLeg) { - this.currentLeg = currentLeg; - this.currentLegName.setValue(currentLeg.getName()); - } - - /** - * @return Name of boat's current leg - */ - public StringProperty getCurrentLegName() { - return currentLegName; - } - - /** - * Gets the distance travelled by the boat in the leg. - * - * @return Returns the value in nautical miles (1.852km) that the boat has traversed. - */ - public double getDistanceTravelledInLeg() { - return distanceTravelledInLeg; - } - - /** - * Sets the distance travelled by the boat in the leg in nautical miles (1.852km) - * - * @param distanceTravelledInLeg Distance travelled by the boat in nautical miles. - */ - public void setDistanceTravelledInLeg(double distanceTravelledInLeg) { - this.distanceTravelledInLeg = distanceTravelledInLeg; - } - - /** - * @return true if boat has finished, false if not - */ - public boolean isFinished() { - return this.finished; - } - - /** - * Sets whether boat is finished or not - * - * @param bool is finished value - */ - public void setFinished(boolean bool) { - this.finished = bool; - } - - public boolean isStarted() { - return started; - } - - public void setStarted(boolean started) { - this.started = started; - } - - public String getPosition() { - return position.get(); - } - - public StringProperty positionProperty() { - return position; - } - - public void setPosition(String 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 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; - } - - /** - * Get base track point time interval - * @return base track point time interval - */ - public static float getBaseTrackPointTimeInterval() { - return BASE_TRACK_POINT_TIME_INTERVAL; - } - - /** - * Set track point time interval - * @param value track point time interval value - */ - public static void setTrackPointTimeInterval(float value) { - trackPointTimeInterval = value; - } -} diff --git a/src/main/java/seng302/Model/ConstantVelocityRace.java b/src/main/java/seng302/Model/ConstantVelocityRace.java deleted file mode 100644 index 84fdab19..00000000 --- a/src/main/java/seng302/Model/ConstantVelocityRace.java +++ /dev/null @@ -1,208 +0,0 @@ -package seng302.Model; - -import org.geotools.referencing.GeodeticCalculator; -import seng302.Constants; -import seng302.Controllers.RaceController; -import seng302.GPSCoordinate; -import seng302.RaceDataSource; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; - -/** - * Created by cbt24 on 6/03/17. - * - * @deprecated - */ -public class ConstantVelocityRace extends Race { - - private int dnfChance = 0; //%percentage chance a boat fails at each checkpoint - - /** - * Initialiser for a constant velocity race without standard data source - * - * @param startingBoats in race - * @param legs in race - * @param controller for graphics - * @param scaleFactor of timer - */ - public ConstantVelocityRace(List startingBoats, List legs, RaceController controller, int scaleFactor) { - super(startingBoats, legs, controller, scaleFactor); - } - - /** - * Initialiser for legacy tests - * - * @param startingBoats in race - * @param legs in race - * @param controller for graphics - * @param scaleFactor of timer - * - * @deprecated Please use {@link #ConstantVelocityRace(List, List, RaceController, int) } for future tests. - */ - public ConstantVelocityRace(BoatInRace[] startingBoats, List legs, RaceController controller, int scaleFactor) { - super(Arrays.asList(startingBoats), legs, controller, scaleFactor); - } - - /** - * Initialiser for constant velocity race with standard data source - * @param raceData for race - * @param controller for graphics - * @param scaleFactor of timer - */ - public ConstantVelocityRace(RaceDataSource raceData, RaceController controller, int scaleFactor) { - super(raceData, controller, scaleFactor); - } - - public void initialiseBoats() { - Leg officialStart = legs.get(0); - String name = officialStart.getName(); - Marker endMarker = officialStart.getEndMarker(); - - BoatInRace.setTrackPointTimeInterval(BoatInRace.getBaseTrackPointTimeInterval() / scaleFactor); - - ArrayList startMarkers = getSpreadStartingPositions(); - for (int i = 0; i < startingBoats.size(); i++) { - BoatInRace boat = startingBoats.get(i); - if (boat != null) { - boat.setScaledVelocity(boat.getVelocity() * scaleFactor); - Leg startLeg = new Leg(name, 0); - boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate()); - startLeg.setStartMarker(startMarkers.get(i)); - startLeg.setEndMarker(endMarker); - startLeg.calculateDistance(); - boat.setCurrentLeg(startLeg); - boat.setHeading(boat.calculateHeading()); - } - } - } - - /** - * Creates a list of starting positions for the different boats, so they do not appear cramped at the start line - * - * @return list of starting positions - */ - public ArrayList getSpreadStartingPositions() { - - int nBoats = startingBoats.size(); - Marker marker = legs.get(0).getStartMarker(); - - GeodeticCalculator initialCalc = new GeodeticCalculator(); - initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude()); - initialCalc.setDestinationGeographicPoint(marker.getMark2().getLongitude(), marker.getMark2().getLatitude()); - - double azimuth = initialCalc.getAzimuth(); - double distanceBetweenMarkers = initialCalc.getOrthodromicDistance(); - double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1); - - GeodeticCalculator positionCalc = new GeodeticCalculator(); - positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude()); - ArrayList positions = new ArrayList<>(); - - for (int i = 0; i < nBoats; i++) { - positionCalc.setDirection(azimuth, distanceBetweenBoats); - Point2D position = positionCalc.getDestinationGeographicPoint(); - positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX()))); - - positionCalc = new GeodeticCalculator(); - positionCalc.setStartingGeographicPoint(position); - } - return positions; - } - - /** - * Sets the chance each boat has of failing at a gate or marker - * @param chance percentage chance a boat has of failing per checkpoint. - */ - protected void setDnfChance(int chance) { - if (chance >= 0 && chance <= 100) { - dnfChance = chance; - } - } - - protected boolean doNotFinish() { - Random rand = new Random(); - return rand.nextInt(100) < dnfChance; - } - - /** - * Calculates the distance a boat has travelled and updates its current position according to this value. - * - * @param boat to be updated - * @param millisecondsElapsed since last update - */ - protected void updatePosition(BoatInRace boat, int millisecondsElapsed) { - - //distanceTravelled = velocity (nm p hr) * time taken to update loop - double distanceTravelled = (boat.getScaledVelocity() * millisecondsElapsed) / 3600000; - - double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg(); - - boolean finish = boat.getCurrentLeg().getName().equals("Finish"); - if (!finish) { - boat.setHeading(boat.calculateHeading()); - //update boat's distance travelled - boat.setDistanceTravelledInLeg(totalDistanceTravelled); - //Calculate boat's new position by adding the distance travelled onto the start point of the leg - boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(), - totalDistanceTravelled, boat.calculateAzimuth())); - } - } - - protected void checkPosition(BoatInRace boat, long timeElapsed) { - if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) { - //boat has passed onto new leg - if (boat.getCurrentLeg().getName().equals("Finish")) { - //boat has finished - boatsFinished++; - boat.setFinished(true); - boat.setTimeFinished(timeElapsed); - } else if (doNotFinish()) { - boatsFinished++; - boat.setFinished(true); - boat.setCurrentLeg(new Leg("DNF", -1)); - boat.setVelocity(0); - boat.setScaledVelocity(0); - } else { - //Calculate how much the boat overshot the marker by - boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance()); - //Move boat on to next leg - Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1); - - boat.setCurrentLeg(nextLeg); - //Add overshoot distance into the distance travelled for the next leg - boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg()); - } - //Update the boat display table in the GUI to reflect the leg change - updatePositions(); - } - } - - /** - * Calculates the boats next GPS position based on its distance travelled and heading - * - * @param oldCoordinates GPS coordinates of the boat's starting position - * @param distanceTravelled distance in nautical miles - * @param azimuth boat's current direction. Value between -180 and 180 - * @return The boat's new coordinate - */ - public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) { - - //Find new coordinate using current heading and distance - - GeodeticCalculator geodeticCalculator = new GeodeticCalculator(); - //Load start point into calculator - Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude()); - geodeticCalculator.setStartingGeographicPoint(startPoint); - //load direction and distance tranvelled into calculator - geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion); - //get new point - Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint(); - - return new GPSCoordinate(endPoint.getY(), endPoint.getX()); - } - -} \ No newline at end of file diff --git a/src/main/java/seng302/Model/Leg.java b/src/main/java/seng302/Model/Leg.java deleted file mode 100644 index 2cd45249..00000000 --- a/src/main/java/seng302/Model/Leg.java +++ /dev/null @@ -1,106 +0,0 @@ -package seng302.Model; - -import org.geotools.referencing.GeodeticCalculator; -import seng302.Constants; -import seng302.GPSCoordinate; - -/** - * Created by cbt24 on 6/03/17. - */ -public class Leg { - private String name; //nautical miles - private double distance; - private Marker startMarker; - private Marker endMarker; - private int legNumber; - - /** - * Leg Initialiser - * - * @param name Name of the Leg - * @param start marker - * @param end marker - * @param number Leg's position in race - */ - public Leg(String name, Marker start, Marker end, int number) { - this.name = name; - this.startMarker = start; - this.endMarker = end; - this.legNumber = number; - calculateDistance(); - } - - /** - * Construction Method - * - * @param name Name of the Leg - * @param number leg number - */ - public Leg(String name, int number) { - this.name = name; - this.legNumber = number; - } - - /** - * Returns the name of the Leg - * - * @return Returns the name of the Leg - */ - public String getName() { - return name; - } - - /** - * Get the distance in nautical miles - * - * @return Returns the total distance of the leg. - */ - public double getDistance() { - return distance; - } - - /** - * Returns the leg number that the leg exists in the Race - * - * @return Returns the Leg - * @see Race - */ - public int getLegNumber() { - return legNumber; - } - - - public Marker getStartMarker() { - return startMarker; - } - - - public Marker getEndMarker() { - return endMarker; - } - - - public void setStartMarker(Marker startMarker) { - this.startMarker = startMarker; - } - - public void setEndMarker(Marker endMarker) { - this.endMarker = endMarker; - } - - /** - * Calculates the distance that the legs are in nautical miles (1.852 km). - */ - public void calculateDistance() { - - GeodeticCalculator calc = new GeodeticCalculator(); - //Load start and end of leg - GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate(); - GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate(); - calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude()); - calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude()); - this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion; - } - - -} diff --git a/src/main/java/seng302/Model/Marker.java b/src/main/java/seng302/Model/Marker.java deleted file mode 100644 index 2b7cafbe..00000000 --- a/src/main/java/seng302/Model/Marker.java +++ /dev/null @@ -1,62 +0,0 @@ -package seng302.Model; - -import org.geotools.referencing.GeodeticCalculator; -import seng302.GPSCoordinate; - -import java.awt.geom.Point2D; - -/** - * Created by esa46 on 29/03/17. - */ -public class Marker { - - private GPSCoordinate averageGPSCoordinate; - private GPSCoordinate mark1; - private GPSCoordinate mark2; - - public Marker(GPSCoordinate mark1) { - - this.mark1 = mark1; - this.mark2 = mark1; - this.averageGPSCoordinate = calculateAverage(); - - } - - public Marker(GPSCoordinate mark1, GPSCoordinate mark2) { - - this.mark1 = mark1; - this.mark2 = mark2; - this.averageGPSCoordinate = calculateAverage(); - - } - - public GPSCoordinate getMark1() { - return mark1; - } - - public GPSCoordinate getMark2() { - return mark2; - } - - public GPSCoordinate getAverageGPSCoordinate() { - return averageGPSCoordinate; - } - - - private GPSCoordinate calculateAverage() { - - GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude()); - calc.setDestinationGeographicPoint(mark2.getLongitude(), mark2.getLatitude()); - double azimuth = calc.getAzimuth(); - double distance = calc.getOrthodromicDistance(); - - GeodeticCalculator middleCalc = new GeodeticCalculator(); - middleCalc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude()); - middleCalc.setDirection(azimuth, distance / 2); - Point2D middlePoint = middleCalc.getDestinationGeographicPoint(); - return new GPSCoordinate(middlePoint.getY(), middlePoint.getX()); - - } - -} diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java deleted file mode 100644 index bfc1d518..00000000 --- a/src/main/java/seng302/Model/Race.java +++ /dev/null @@ -1,263 +0,0 @@ -package seng302.Model; - - -import javafx.animation.AnimationTimer; -import javafx.application.Platform; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import org.geotools.referencing.GeodeticCalculator; -import seng302.Controllers.RaceController; -import seng302.GPSCoordinate; -import seng302.RaceDataSource; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; - -/** - * Parent class for races - * Created by fwy13 on 3/03/17. - */ -public abstract class Race implements Runnable { - //protected BoatInRace[] startingBoats; - protected ObservableList startingBoats; - protected List legs; - protected RaceController controller; - protected int boatsFinished = 0; - protected long totalTimeElapsed; - private int lastFPS = 20; - - protected int scaleFactor; - - protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race - private boolean timerEnabled = true; //boolean to determine if timer is ran - - /** - * Initailiser for Race - * - * @param boats Takes in an array of boats that are participating in the race. - * @param legs Number of marks in order that the boats pass in order to complete the race. - * @param controller race controller - * @param scaleFactor for race - */ - public Race(List boats, List legs, RaceController controller, int scaleFactor) { - - this.startingBoats = FXCollections.observableArrayList(boats); - this.legs = legs; - this.legs.add(new Leg("Finish", this.legs.size())); - this.controller = controller; - this.scaleFactor = scaleFactor; - if (startingBoats != null && startingBoats.size() > 0) { - initialiseBoats(); - } - } - - public Race(BoatInRace[] startingBoats, List legs, RaceController controller, int scaleFactor) { - this(Arrays.asList(startingBoats), legs, controller, scaleFactor); - } - - public Race(RaceDataSource raceData, RaceController controller, int scaleFactor) { - this(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor); - } - - public abstract void initialiseBoats(); - - /** - * Randomly generate number to see if boat fails - * @return True if number lower than dnfChance else false - */ - protected abstract boolean doNotFinish(); - - /** - * Checks the position of the boat, this updates the boats current position. - * - * @param boat Boat that the postion is to be updated for. - * @param timeElapsed Time that has elapse since the start of the the race. - * @see BoatInRace - */ - protected abstract void checkPosition(BoatInRace boat, long timeElapsed); - - /** - * Updates the boat's gps coordinates depending on time elapsed - * - * @param boat to be updated - * @param millisecondsElapsed time since last update - */ - protected abstract void updatePosition(BoatInRace boat, int millisecondsElapsed); - - /** - * Runnable for the thread. - */ - public void run() { - setControllerListeners(); - initialiseBoats(); - if (timerEnabled) countdownTimer(); - //simulateRace(); - } - - /** - * Disable the timer - */ - public void disableTimer() { - timerEnabled = false; - } - - - /** - * Countdown timer until race starts. Use PRERACE_TIME to set countdown duration. - */ - protected void countdownTimer() { - new AnimationTimer() { - long currentTime = System.currentTimeMillis(); - long startTime = currentTime + (PRERACE_TIME/scaleFactor); - long minutes; - long currentTimeInSeconds; - long remainingSeconds; - long hours; - long timeLeft; - - @Override - public void handle(long arg0) { - timeLeft = startTime - currentTime; - if (timeLeft <= 0 && controller != null) { - updateTime("Race is starting..."); - stop(); - simulateRace(); - } else { - currentTimeInSeconds = (timeLeft*scaleFactor) / 1000; - minutes = currentTimeInSeconds / 60; - remainingSeconds = currentTimeInSeconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - if (controller != null) { - updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds)); - } - } - currentTime = System.currentTimeMillis(); - } - }.start(); - } - - /** - * Takes total time elapsed and format to hour:minute:second - * - * @return Formatted time as string - */ - protected String calcTimer() { - long minutes; - long currentTimeInSeconds; - long remainingSeconds; - long hours; - - currentTimeInSeconds = (totalTimeElapsed * scaleFactor) / 1000; - minutes = currentTimeInSeconds / 60; - remainingSeconds = currentTimeInSeconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds); - } - - /** - * Updates the calculated time to the timer label - * - * @param time The calculated time from calcTimer() method - */ - protected void updateTime(String time) { - Platform.runLater(() -> { - controller.setTimer(time); - }); - } - - /** - * Update the calculated fps to the fps label - * - * @param fps The new calculated fps value - */ - private void updateFPS(int fps) { - Platform.runLater(() -> { - controller.setFrames("FPS: " + fps); - }); - } - - /** - * Starts the Race Simulation, playing the race start to finish with the timescale. - * This prints the boats participating, the order that the events occur in time order, and the respective information of the events. - */ - private void simulateRace() { - - System.setProperty("javafx.animation.fullspeed", "true"); - - for (BoatInRace boat : startingBoats) { - boat.setStarted(true); - } - - new AnimationTimer() { - - long timeRaceStarted = System.currentTimeMillis(); //start time of loop - int fps = 0; //init fps value - long timeCurrent = System.currentTimeMillis(); //current time - - @Override - public void handle(long arg0) { - - if (boatsFinished < startingBoats.size()) { - totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted; - - for (BoatInRace boat : startingBoats) { - if (boat != null && !boat.isFinished()) { - boat.addTrackPoint(boat.getCurrentPosition()); - updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS)); - checkPosition(boat, totalTimeElapsed); - } - } - if (timerEnabled) - updateTime(calcTimer()); - } - controller.updateMap(startingBoats); - fps++; - if ((System.currentTimeMillis() - timeCurrent) > 1000) { - updateFPS(fps); - lastFPS = fps; - fps = 0; - timeCurrent = System.currentTimeMillis(); - } - - } - - }.start(); - } - - /** - * Update position of boats in race, no position if on starting leg or DNF. - */ - protected void updatePositions() { - FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber()); - for(BoatInRace boat: startingBoats) { - if(boat != null) { - boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1)); - if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0) - boat.setPosition("-"); - } - } - } - - /** - * Update call for the controller. - */ - protected void setControllerListeners() { - if (controller != null) controller.setInfoTable(this); - } - - /** - * Returns the boats that have started the race. - * - * @return ObservableList of BoatInRace class that participated in the race. - * @see ObservableList - * @see BoatInRace - */ - public ObservableList getStartingBoats() { - return startingBoats; - } -} diff --git a/src/main/java/seng302/Model/RaceClock.java b/src/main/java/seng302/Model/RaceClock.java deleted file mode 100644 index 6ea62bd3..00000000 --- a/src/main/java/seng302/Model/RaceClock.java +++ /dev/null @@ -1,53 +0,0 @@ -package seng302.Model; - -import com.github.bfsmith.geotimezone.TimeZoneLookup; -import com.github.bfsmith.geotimezone.TimeZoneResult; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import seng302.GPSCoordinate; - -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; - -/** - * Created by Gondr on 19/04/2017. - */ -public class RaceClock { - private StringProperty time; - private DateTimeFormatter dateTimeFormatter; - private String timeZone; - private ZoneId zoneId; - - public RaceClock(GPSCoordinate gpsCoordinate){ - TimeZoneLookup timeZoneLookup = new TimeZoneLookup(); - TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude()); - zoneId = ZoneId.of(timeZoneResult.getResult()); - LocalDateTime localDateTime = LocalDateTime.now(zoneId); - ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); - dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z"); - // System.out.println(dateTimeFormatter.format(zonedDateTime)); - time = new SimpleStringProperty(dateTimeFormatter.format(zonedDateTime)); - DateTimeFormatter timeZoneFormatter = DateTimeFormatter.ofPattern("z"); - timeZone = timeZoneFormatter.format(zonedDateTime); - } - - public void updateTime(){ - LocalDateTime localDateTime = LocalDateTime.now(zoneId); - ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); - time.setValue(dateTimeFormatter.format(zonedDateTime)); - } - - public String getTime() { - return time.get(); - } - - public StringProperty timeProperty() { - return time; - } - - public String getTimeZone() { - return timeZone; - } -} diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java deleted file mode 100644 index da83b5f1..00000000 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ /dev/null @@ -1,410 +0,0 @@ -package seng302.Model; - - -import javafx.scene.canvas.Canvas; -import javafx.scene.canvas.GraphicsContext; -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; - -/** - * This creates a JavaFX Canvas that is fills it's parent. - * Cannot be downsized. - * Created by fwy13 on 17/03/17. - */ -public class ResizableRaceCanvas extends Canvas { - private GraphicsContext gc; - private RaceMap map; - private List boats; - private boolean raceAnno = true; - private boolean annoName = true; - private boolean annoAbbrev = true; - private boolean annoSpeed = true; - private boolean annoPath = true; - private ArrayList raceBoundaries; - double[] xpoints = {}, ypoints = {}; - - public ResizableRaceCanvas(RaceDataSource raceData) { - gc = this.getGraphicsContext2D(); - // Redraw canvas when size changes. - widthProperty().addListener(evt -> drawRaceMap()); - heightProperty().addListener(evt -> drawRaceMap()); - - double lat1 = raceData.getMapTopLeft().getLatitude(); - 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())); - } - - /** - * Sets the boats that are to be displayed in this race. - * - * @param boats in race - */ - public void setBoats(List boats) { - this.boats = boats; - } - - /** - * Sets the RaceMap that the RaceCanvas is to be displaying for. - * - * @param map race map - */ - public void setMap(RaceMap map) { - this.map = map; - } - - /** - * Displays the mark of a race as a circle. - * - * @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as. - * @param paint Colour the mark is to be coloured. - * @see GraphCoordinate - * @see Color - * @see Paint - */ - public void displayMark(GraphCoordinate graphCoordinate, Paint paint) { - double d = 25; - gc.setFill(paint); - gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d); - } - - public void displayBoat(BoatInRace boat, double angle) { - GraphCoordinate pos = this.map.convertGPS(boat.getCurrentPosition()); - Paint paint = boat.getColour(); - - double[] x = {pos.getX() - 6, pos.getX(), pos.getX() + 6}; - double[] y = {pos.getY() + 12, pos.getY() - 12, pos.getY() + 12}; - gc.setFill(paint); - - gc.save(); - rotate(angle, pos.getX(), pos.getY()); - gc.fillPolygon(x, y, 3); - gc.restore(); - } - - /** - * Displays a line on the map with rectangles on the starting and ending point of the line. - * - * @param graphCoordinateA Starting Point of the line in GraphCoordinate. - * @param graphCoordinateB End Point of the line in GraphCoordinate. - * @param paint Colour the line is to coloured. - * @see GraphCoordinate - * @see Color - * @see Paint - */ - private void displayLine(GraphCoordinate graphCoordinateA, GraphCoordinate graphCoordinateB, Paint paint) { - gc.setStroke(paint); - gc.setFill(paint); - gc.fillOval(graphCoordinateA.getX() - 3, graphCoordinateA.getY() - 3, 6, 6); - gc.fillOval(graphCoordinateB.getX() - 3, graphCoordinateB.getY() - 3, 6, 6); - gc.strokeLine(graphCoordinateA.getX(), graphCoordinateA.getY(), graphCoordinateB.getX(), graphCoordinateB.getY()); - } - - /** - * Display a point on the Canvas - * - * @param graphCoordinate Coordinate that the point is to be displayed at. - * @param paint Colour that the boat is to be coloured. - * @see GraphCoordinate - * @see Paint - * @see Color - */ - private void displayPoint(GraphCoordinate graphCoordinate, Paint paint) { - gc.setFill(paint); - gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10); - } - - - /** - * Displays an arrow on the Canvas - * - * @param coordinate Coordinate that the arrow is to be displayed at. - * @param angle Angle that the arrow is to be facing in degrees 0 degrees = North (Up). - * @see GraphCoordinate - */ - private void displayArrow(GraphCoordinate coordinate, int angle) { - gc.save(); - rotate(angle, coordinate.getX(), coordinate.getY()); - gc.setFill(Color.BLACK); - gc.fillPolygon(new double[]{coordinate.getX() - 12, coordinate.getX() - 6, coordinate.getX(), coordinate.getX() - 4, coordinate.getX() - 4, coordinate.getX() - 8, coordinate.getX() - 8}, - new double[]{coordinate.getY() - 5, coordinate.getY() - 20, coordinate.getY() - 5, coordinate.getY() - 5, coordinate.getY() + 20, coordinate.getY() + 20, coordinate.getY() - 5}, - 7); - gc.restore(); - } - - /** - * Rotates things on the canvas Note: this must be called in between gc.save() and gc.restore() else they will rotate everything - * - * @param angle Bearing angle to rotate at in degrees - * @param px Pivot point x of rotation. - * @param py Pivot point y of rotation. - */ - private void rotate(double angle, double px, double py) { - Rotate r = new Rotate(angle, px, py); - gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy()); - } - - /** - * Display given name and speed of boat at a graph coordinate - * - * @param name name of the boat - * @param abbrev abbreviation of the boat name - * @param speed speed of the boat - * @param coordinate coordinate the text appears - */ - private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) { - String text = ""; - //Check name toggle value - if (annoName){ - text += String.format("%s ", name); - } - //Check abbreviation toggle value - if (annoAbbrev){ - text += String.format("%s ", abbrev); - } - //Check speed toggle value - if (annoSpeed){ - text += String.format("%.2fkn", speed); - } - //String text = String.format("%s, %2$.2fkn", name, speed); - long xCoord = coordinate.getX() + 20; - long yCoord = coordinate.getY(); - if (xCoord + (text.length() * 7) >= getWidth()) { - xCoord -= text.length() * 7; - } - if (yCoord - (text.length() * 2) <= 0) { - yCoord += 30; - } - gc.fillText(text, xCoord, yCoord); - } - - /** - * Draws race map with up to date data. - */ - public void update() { - this.drawRaceMap(); - this.updateBoats(); - } - - /** - * Draw boundary of the race. - */ - public void drawBoundaries() { - if (this.raceBoundaries == null) { - return; - } - gc.setFill(Color.AQUA); - setRaceBoundCoordinates(); - gc.fillPolygon(xpoints, ypoints, xpoints.length); - } - - /** - * Draws the Race Map - */ - public void drawRaceMap() { - - double width = getWidth(); - double height = getHeight(); - - gc.clearRect(0, 0, width, height); - - if (map == null) { - return;//TODO this should return a exception in the future - } - 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); - - updateBoats(); - - //display wind direction arrow - specify origin point and angle - angle now set to random angle - displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150); - } - - /** - * Draws a boat at a certain GPSCoordinate - * - * @param colour Colour to colour boat. - * @param gpsCoordinates GPScoordinate that the boat is to be drawn at. - * @see GPSCoordinate - * @see Color - */ - public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) { - GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates); - displayPoint(graphCoordinate, colour); - } - - /** - * Toggle the raceAnno value - */ - public void toggleAnnotations() { - if (raceAnno) { - raceAnno = false; - } else { - raceAnno = true; - } - } - - /** - * Toggle name display in annotation - */ - public void toggleAnnoName() { - if (annoName) { - annoName = false; - } else { - annoName = true; - } - } - - public void toggleBoatPath() { - if (annoPath) { - annoPath = false; - } else { - annoPath = true; - } - } - - /** - * Toggle abbreviation display in annotation - */ - public void toggleAnnoAbbrev() { - if (annoAbbrev) { - annoAbbrev = false; - } else { - annoAbbrev = true; - } - } - - /** - * Toggle speed display in annotation - */ - public void toggleAnnoSpeed() { - if (annoSpeed) { - annoSpeed = false; - } else { - annoSpeed = true; - } - } - - /** - * Draws boats while race in progress, when leg heading is set. - */ - public void updateBoats() { - if (boats != null) { - for (BoatInRace boat : boats) { - boolean finished = boat.getCurrentLeg().getName().equals("Finish") || boat.getCurrentLeg().getName().equals("DNF"); - boolean isStart = boat.isStarted(); - if (!finished && isStart) { - displayBoat(boat, boat.getHeading()); - GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition()); - GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake()); - displayLine(wakeFrom, wakeTo, boat.getColour()); - } else if (!isStart) { - displayBoat(boat, boat.getHeading()); - } else { - displayBoat(boat, 0); - } - - if (raceAnno) - 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 && raceAnno) { - 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); - } - } - } - - public void setRaceBoundaries(List boundaries) { - this.raceBoundaries = new ArrayList<>(); - for (GPSCoordinate bound : boundaries) { - raceBoundaries.add(bound); - } - setRaceBoundCoordinates(); - } - - public void setRaceBoundCoordinates() { - xpoints = new double[this.raceBoundaries.size()]; - ypoints = new double[this.raceBoundaries.size()]; - for (int i = 0; i < raceBoundaries.size(); i++) { - GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i)); - xpoints[i] = coord.getX(); - ypoints[i] = coord.getY(); - } - } - - /** - * Set the Canvas to resizable. - * - * @return That the Canvas is resizable. - */ - @Override - public boolean isResizable() { - return true; - } - - /** - * Returns the preferred width of the Canvas - * - * @param width of canvas - * @return Returns the width of the Canvas - */ - @Override - public double prefWidth(double width) { - return getWidth(); - } - - /** - * Returns the preferred height of the Canvas - * - * @param height of canvas - * @return Returns the height of the Canvas - */ - @Override - public double prefHeight(double height) { - return getHeight(); - } - -} diff --git a/src/main/java/seng302/Model/TrackPoint.java b/src/main/java/seng302/Model/TrackPoint.java deleted file mode 100644 index a2c30aa0..00000000 --- a/src/main/java/seng302/Model/TrackPoint.java +++ /dev/null @@ -1,50 +0,0 @@ -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; - } -} diff --git a/src/main/java/seng302/RaceDataSource.java b/src/main/java/seng302/RaceDataSource.java deleted file mode 100644 index 2f562766..00000000 --- a/src/main/java/seng302/RaceDataSource.java +++ /dev/null @@ -1,19 +0,0 @@ -package seng302; - -import seng302.Model.BoatInRace; -import seng302.Model.Leg; - -import java.util.List; - -/** - * Created by connortaylorbrown on 19/04/17. - */ -public interface RaceDataSource { - List getBoats(); - List getLegs(); - List getBoundary(); - - GPSCoordinate getMark(); - GPSCoordinate getMapTopLeft(); - GPSCoordinate getMapBottomRight(); -} diff --git a/src/main/java/seng302/RaceMap.java b/src/main/java/seng302/RaceMap.java deleted file mode 100644 index 0ccf9a6d..00000000 --- a/src/main/java/seng302/RaceMap.java +++ /dev/null @@ -1,69 +0,0 @@ -package seng302; - -/** - * Created by cbt24 on 15/03/17. - */ -public class RaceMap { - private double x1, x2, y1, y2; - private int width, height; - - /** - * Constructor Method. - * - * @param x1 Longitude of the top left point. - * @param y1 Latitude of the top left point. - * @param x2 Longitude of the top right point. - * @param y2 Latitude of the top right point. - * @param width width that the Canvas the race is to be drawn on is. - * @param height height that the Canvas the race is to be drawn on is. - */ - public RaceMap(double y1, double x1, double y2, double x2, int height, int width) { - this.x1 = x1; - this.x2 = x2; - this.y1 = y1; - this.y2 = y2; - this.width = width; - this.height = height; - } - - /** - * Converts GPS coordinates to coordinates for container - * - * @param lat GPS latitude - * @param lon GPS longitude - * @return GraphCoordinate (pair of doubles) - * @see GraphCoordinate - */ - public GraphCoordinate convertGPS(double lat, double lon) { - int difference = Math.abs(width - height); - int size = width; - if (width > height) { - size = height; - return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference / 2), (int) (size - (size * (lat - y1) / (y2 - y1)))); - } else { - return new GraphCoordinate((int) (size * (lon - x1) / (x2 - x1)), (int) ((size - (size * (lat - y1) / (y2 - y1))) + difference / 2)); - } - - //return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1)))); - } - - /** - * Converts the GPS Coordinate to GraphCoordinates - * - * @param coordinate GPSCoordinate representation of Latitude and Longitude. - * @return GraphCoordinate that the GPS is coordinates are to be displayed on the map. - * @see GraphCoordinate - * @see GPSCoordinate - */ - public GraphCoordinate convertGPS(GPSCoordinate coordinate) { - return convertGPS(coordinate.getLatitude(), coordinate.getLongitude()); - } - - public void setWidth(int width) { - this.width = width; - } - - public void setHeight(int height) { - this.height = height; - } -} diff --git a/src/main/java/seng302/RaceXMLReader.java b/src/main/java/seng302/RaceXMLReader.java deleted file mode 100644 index f10da6ef..00000000 --- a/src/main/java/seng302/RaceXMLReader.java +++ /dev/null @@ -1,322 +0,0 @@ -package seng302; - -import javafx.scene.paint.Color; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import seng302.Model.BoatInRace; -import seng302.Model.Leg; -import seng302.Model.Marker; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by fwy13 on 26/03/2017. - */ -public class RaceXMLReader extends XMLReader implements RaceDataSource { - private List boats = new ArrayList<>(); - private Color[] colors = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN};//TODO make this established in xml or come up with a better system. - private List legs = new ArrayList<>(); - private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2; - private GPSCoordinate mapTopLeft, mapBottomRight; - private List boundary = new ArrayList<>(); - private static double COORDINATEPADDING = 0.0005; - - /** - * Constractor for Race XML - * @param filePath path of the file - * @throws IOException error - * @throws SAXException error - * @throws ParserConfigurationException error - */ - public RaceXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException { - this(filePath, true); - } - - /** - * COnstructor for 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 - * @throws ParserConfigurationException error - */ - public RaceXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException { - super(filePath); - if (read) { - read(); - } - } - - /** - * Read the files - */ - private void read() { - readCourse(); - readLegs(); - readBoats(); - } - - /** - * Read all the boats in the XML file - */ - public void readBoats() { - //get all boats - NodeList nBoats = doc.getElementsByTagName("boat"); - - for (int i = 0; i < nBoats.getLength(); i++) { - String name = getTextValueOfNode((Element) nBoats.item(i), "name"); - String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr"); - double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed")); - BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev); - boat.setCurrentPosition(startPt1); - if (legs.size() > 0) { - boat.setCurrentLeg(legs.get(0)); - } - boats.add(boat); - } - } - - /** - * Read all the legs in the XML file - */ - public void readLegs() { - //get all legs - NodeList nLegs = doc.getElementsByTagName("leg"); - - for (int i = 0; i < nLegs.getLength(); i++) { - String label = getTextValueOfNode((Element) nLegs.item(i), "name"); - NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start"); - Marker startMarker = getMarker(start); - NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish"); - Marker finishMarker = getMarker(finish); - legs.add(new Leg(label, startMarker, finishMarker, i)); - } - } - - /** - * Read courses in XML file - */ - public void readCourse() { - NodeList nCourse = doc.getElementsByTagName("course"); - - NodeList nBounds = ((Element) nCourse.item(0)).getElementsByTagName("boundaries"); - nBounds = ((Element) nBounds.item(0)).getElementsByTagName("coordinate"); - int maxLatitudeIndex = 0; - double maxLatitude = -Double.MIN_VALUE; - int maxLongitudeIndex = 0; - double maxLongitude = -180; - int minLatitudeIndex = 0; - double minLatitude = Double.MAX_VALUE; - int minLongitudeIndex = 0; - double minLongitude = Double.MAX_VALUE; - for (int i = 0; i < nBounds.getLength(); i++) { - boundary.add(getCoordinates((Element) nBounds.item(i))); - if (boundary.get(i).getLatitude() > maxLatitude) { - maxLatitudeIndex = i; - maxLatitude = boundary.get(i).getLatitude(); - } - if (boundary.get(i).getLatitude() < minLatitude) { - minLatitudeIndex = i; - minLatitude = boundary.get(i).getLatitude(); - } - if (boundary.get(i).getLongitude() > maxLongitude) { - maxLongitudeIndex = i; - maxLongitude = boundary.get(i).getLongitude(); - } - if (boundary.get(i).getLongitude() < minLongitude) { - minLongitudeIndex = i; - minLongitude = boundary.get(i).getLongitude(); - } - } - - double difference = 0;//this will hold the largest difference so we can make the map square. - double latitudeDiff = Math.abs(Math.abs(boundary.get(maxLatitudeIndex).getLatitude()) - Math.abs(boundary.get(minLatitudeIndex).getLatitude())); - double longitudeDiff = Math.abs(Math.abs(boundary.get(maxLongitudeIndex).getLongitude()) - Math.abs(boundary.get(minLongitudeIndex).getLongitude())); - if (latitudeDiff >= longitudeDiff) { - difference = latitudeDiff - longitudeDiff; - maxLongitude += difference / 2; - minLongitude -= difference / 2; - } else { - difference = longitudeDiff - latitudeDiff; - maxLatitude += difference / 2; - minLatitude -= difference / 2; - } - maxLatitude += COORDINATEPADDING; - minLatitude -= COORDINATEPADDING; - maxLongitude += COORDINATEPADDING; - minLongitude -= COORDINATEPADDING; - //now create map boundaries - //top left canvas point is min logitude, max latitude - //bottom right of canvas point is min longitude, max latitude. - mapTopLeft = new GPSCoordinate(minLatitude, minLongitude); - mapBottomRight = new GPSCoordinate(maxLatitude, maxLongitude); - - NodeList nMarks = ((Element) nCourse.item(0)).getElementsByTagName("marker"); - startPt1 = getCoordinates(nMarks, 0); - startPt2 = getCoordinates(nMarks, 0, 1); - mark = getCoordinates(nMarks, 1); - windwardPt1 = getCoordinates(nMarks, 2); - windwardPt2 = getCoordinates(nMarks, 2, 1); - leewardPt1 = getCoordinates(nMarks, 3); - leewardPt2 = getCoordinates(nMarks, 3, 1); - finishPt1 = getCoordinates(nMarks, 4); - finishPt2 = getCoordinates(nMarks, 4, 1); - } - - /** - * gets a marker from the XML file - * @param start base nodelist this should be the tag that contains - * @return - */ - private Marker getMarker(NodeList start) { - return getMarker(start, 0); - } - - /** - * gets a marker from the XML file - * @param start base nodelist this should be the tag that contains - * @param startIndex index in the node that has the coordinate tag - * @return - */ - private Marker getMarker(NodeList start, int startIndex) { - return getMarker(start, startIndex, 0); - } - - /** - * gets a marker from the XML file - * @param start base nodelist this should be the tag that contains - * @param startIndex index in the node that has the coordinate tag - * @param nodeIndex coordinate index - * @return - */ - private Marker getMarker(NodeList start, int startIndex, int nodeIndex) { - NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker"); - Element marker = (Element) nodeList.item(nodeIndex); - return getMarker(marker); - } - - /** - * gets a changes a marker to GPS coordinates into a marker - * @param markerNode marker to turn into coordinates - * @return - */ - private Marker getMarker(Element markerNode) { - - NodeList nCoordinates = markerNode.getElementsByTagName("coordinate"); - - GPSCoordinate side1 = getCoordinates((Element) nCoordinates.item(0)); - GPSCoordinate side2; - if (nCoordinates.getLength() > 1) { - side2 = getCoordinates((Element) nCoordinates.item(1)); - } else { - side2 = side1; - } - return new Marker(side1, side2); - - } - - /** - * gets a coordinates from the XML file - * @param start base nodelist this should be the tag that contains - * @return - */ - private GPSCoordinate getCoordinates(NodeList start) { - return getCoordinates(start, 0); - } - - /** - * gets a coordinates from the XML file - * @param start base nodelist this should be the tag that contains - * @param startIndex the index the tag containing the coordinate should be in - * @return - */ - private GPSCoordinate getCoordinates(NodeList start, int startIndex) { - return getCoordinates(start, startIndex, 0); - } - - /** - * gets a coordinates from the XML file - * @param start base nodelist this should be the tag that contains - * @param startIndex the index the tag containing the coordinate should be in - * @param nodeIndex The coordinate index - * @return - */ - private GPSCoordinate getCoordinates(NodeList start, int startIndex, int nodeIndex) { - NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("coordinate"); - Element coord = (Element) nodeList.item(nodeIndex); - return getCoordinates(coord); - } - - /** - * Returns the coordinate TODO raise exception that runs when the XML is formatted wrongly. - * - * @param coordNode - * @return - */ - private GPSCoordinate getCoordinates(Element coordNode) { - - double startLat = Double.parseDouble(getTextValueOfNode(coordNode, "latitude")); - double startLong = Double.parseDouble(getTextValueOfNode(coordNode, "longitude")); - return new GPSCoordinate(startLat, startLong); - } - - public List getBoats() { - return boats; - } - - public List getLegs() { - return legs; - } - - public GPSCoordinate getMark() { - return mark; - } - - public GPSCoordinate getStartPt1() { - return startPt1; - } - - public GPSCoordinate getStartPt2() { - return startPt2; - } - - public GPSCoordinate getFinishPt1() { - return finishPt1; - } - - public GPSCoordinate getFinishPt2() { - return finishPt2; - } - - public GPSCoordinate getLeewardPt1() { - return leewardPt1; - } - - public GPSCoordinate getLeewardPt2() { - return leewardPt2; - } - - public GPSCoordinate getWindwardPt1() { - return windwardPt1; - } - - public GPSCoordinate getWindwardPt2() { - return windwardPt2; - } - - public List getBoundary() { - return boundary; - } - - public GPSCoordinate getMapTopLeft() { - return mapTopLeft; - } - - public GPSCoordinate getMapBottomRight() { - return mapBottomRight; - } -} diff --git a/src/main/java/seng302/XMLReader.java b/src/main/java/seng302/XMLReader.java deleted file mode 100644 index 810096d3..00000000 --- a/src/main/java/seng302/XMLReader.java +++ /dev/null @@ -1,40 +0,0 @@ -package seng302; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.InputStream; - -/** - * Created by fwy13 on 26/03/2017. - */ -public abstract class XMLReader { - - protected Document doc; - - public XMLReader(String filePath) throws ParserConfigurationException, IOException, SAXException { - InputStream fXmlFile = getClass().getClassLoader().getResourceAsStream(filePath); - DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); - doc = dBuilder.parse(fXmlFile); - doc.getDocumentElement().normalize(); - } - - public Document getDocument() { - return doc; - } - - public String getTextValueOfNode(Element n, String tagName) { - return n.getElementsByTagName(tagName).item(0).getTextContent(); - } - - public String getAttribute(Element n, String attr) { - return n.getAttribute(attr); - } - -} diff --git a/src/main/resources/raceXML/bermuda_AC35.xml b/src/main/resources/raceXML/bermuda_AC35.xml deleted file mode 100644 index 716f274b..00000000 --- a/src/main/resources/raceXML/bermuda_AC35.xml +++ /dev/null @@ -1,268 +0,0 @@ - - - - ORACLE TEAM USA - 20 - USA - BLUEVIOLET - - - Land Rover BAR - 30 - GBR - BLACK - - - SoftBank Team Japan - 25 - JPN - RED - - - Groupama Team France - 20 - FRA - ORANGE - - - Artemis Racing - 29 - SWE - DARKOLIVEGREEN - - - Emirates Team New Zealand - 62 - NZL - LIMEGREEN - - - - - Start to Mark 1 - - - - 32.296577 - -64.854304 - - - 32.293771 - -64.855242 - - - - - - - 32.293039 - -64.843983 - - - - - - Mark 1 to Leeward Gate - - - - 32.293039 - -64.843983 - - - - - - - 32.309693 - -64.835249 - - - 32.308046 - -64.831785 - - - - - - Leeward Gate to Windward Gate - - - - 32.309693 - -64.835249 - - - 32.308046 - -64.831785 - - - - - - - 32.284680 - -64.850045 - - - 32.280164 - -64.847591 - - - - - - Windward Gate to Leeward Gate - - - - 32.284680 - -64.850045 - - - 32.280164 - -64.847591 - - - - - - - 32.309693 - -64.835249 - - - 32.308046 - -64.831785 - - - - - - Leeward Gate to Finish - - - - 32.309693 - -64.835249 - - - 32.308046 - -64.831785 - - - - - - - 32.317379 - -64.839291 - - - 32.317257 - -64.836260 - - - - - - - - - 32.313922 - -64.837168 - - - 32.317379 - -64.839291 - - - 32.317911 - -64.836996 - - - 32.317257 - -64.836260 - - - 32.304273 - -64.822834 - - - 32.279097 - -64.841545 - - - 32.279604 - -64.849871 - - - 32.289545 - -64.854162 - - - 32.290198 - -64.858711 - - - 32.297164 - -64.856394 - - - 32.296148 - -64.849184 - - - - Start Line - - 32.296577 - -64.854304 - - - 32.293771 - -64.855242 - - - - Mark - - 32.293039 - -64.843983 - - - - Windward Gate - - 32.284680 - -64.850045 - - - 32.280164 - -64.847591 - - - - Leeward Gate - - 32.309693 - -64.835249 - - - 32.308046 - -64.831785 - - - - Finish Line - - 32.317379 - -64.839291 - - - 32.317257 - -64.836260 - - - - diff --git a/src/main/resources/scenes/main.fxml b/src/main/resources/scenes/main.fxml deleted file mode 100644 index d94c8b59..00000000 --- a/src/main/resources/scenes/main.fxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/scenes/race.fxml b/src/main/resources/scenes/race.fxml deleted file mode 100644 index 56aed929..00000000 --- a/src/main/resources/scenes/race.fxml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -