From ef098e63d7394bb82b9e6cdb02a3dc7416a9dc5f Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 12:51:03 +1300 Subject: [PATCH 01/12] Added finishing events #implement and rotated the map by 180 degrees#fix --- src/main/java/seng302/App.java | 2 +- .../seng302/controllers/CanvasController.java | 117 +++++++++++++----- .../java/seng302/controllers/Controller.java | 18 --- .../controllers/MasterViewController.java | 38 ++++++ .../seng302/controllers/RaceController.java | 4 +- .../controllers/RaceResultController.java | 27 ++++ src/main/java/seng302/models/Event.java | 3 +- src/main/java/seng302/models/Race.java | 7 +- src/main/resources/FinishView.fxml | 9 +- src/main/resources/MainView.fxml | 4 +- src/main/resources/RaceView.fxml | 2 +- 11 files changed, 168 insertions(+), 63 deletions(-) delete mode 100644 src/main/java/seng302/controllers/Controller.java create mode 100644 src/main/java/seng302/controllers/MasterViewController.java create mode 100644 src/main/java/seng302/controllers/RaceResultController.java diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index db1e823e..b2dd4250 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -10,7 +10,7 @@ public class App extends Application { @Override public void start(Stage primaryStage) throws Exception { - Parent root = FXMLLoader.load(getClass().getResource("/RaceView.fxml")); + Parent root = FXMLLoader.load(getClass().getResource("/MainView.fxml")); primaryStage.setTitle("RaceVision"); primaryStage.setScene(new Scene(root)); diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 19784df8..936f4be0 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -7,8 +7,11 @@ import javafx.animation.Timeline; import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.util.Duration; import seng302.models.Boat; @@ -20,6 +23,7 @@ import seng302.models.mark.Mark; import seng302.models.mark.MarkType; import seng302.models.mark.SingleMark; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -35,12 +39,31 @@ public class CanvasController { private Race race; private GraphicsContext gc; private HashMap timelineInfos; + @FXML private Canvas canvas; + @FXML + private AnchorPane contentAnchorPane; + + @FXML + private RaceResultController raceResultController; + + private void setContentPane(String jfxUrl) { + try { + contentAnchorPane.getChildren().removeAll(); + contentAnchorPane.getChildren().clear(); + contentAnchorPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); + } catch (javafx.fxml.LoadException e) { + System.err.println(e.getCause()); + } catch (IOException e) { + System.err.println(e); + } + } + public void initialize() { gc = canvas.getGraphicsContext2D(); - gc.scale(22, 22); + gc.scale(15, 15); RaceController raceController = new RaceController(); raceController.initializeRace(); race = raceController.getRace(); @@ -53,7 +76,6 @@ public class CanvasController { gc.clearRect(0, 0, 760, 360); drawCourse(); drawBoats(); - } }; @@ -61,9 +83,27 @@ public class CanvasController { // starts the timer and reads events from each boat's time line timer.start(); + + int i = 0; + for (TimelineInfo timelineInfo : timelineInfos.values()) { + Timeline timeline = timelineInfo.getTimeline(); + + if (i == timelineInfos.values().size() - 1) { + timeline.setOnFinished(event -> { + setContentPane("/FinishView.fxml"); + + for (Boat boat : race.getFinishedBoats()) { + System.out.println(boat.getTeamName()); + } + + }); + } + timeline.play(); + + i++; } } @@ -82,12 +122,22 @@ public class CanvasController { List events = boat_events.get(boat); // iterates all events and convert each event to keyFrame, then add them into a list for (Event event : events) { - keyFrames.add( - new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), - new KeyValue(x, event.getThisMark().getLatitude()), - new KeyValue(y, event.getThisMark().getLongitude()) - ) - ); + if (event.getIsFinishingEvent()) { + keyFrames.add( + new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), + event1 -> race.setBoatFinished(boat), + new KeyValue(x, event.getThisMark().getLatitude()), + new KeyValue(y, event.getThisMark().getLongitude()) + ) + ); + } else { + keyFrames.add( + new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), + new KeyValue(x, event.getThisMark().getLatitude()), + new KeyValue(y, event.getThisMark().getLongitude()) + ) + ); + } } // uses the lists generated above to create a Timeline for the boat. @@ -105,36 +155,25 @@ public class CanvasController { } } - /** - * @return the distance between the two marks - */ - public double getDistanceBetweenMarks(Mark mark1, Mark mark2) { - double earth_radius = 6378.137; - double dLat = mark2.getLatitude() * Math.PI / 180 - mark1.getLatitude() * Math.PI / 180; - double dLon = mark2.getLongitude() * Math.PI / 180 - mark1.getLongitude() * Math.PI / 180; - - double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(mark1.getLatitude() * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2); - - double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - double d = earth_radius * c; - - return d * 1000; - } - /** * Draws a boat with given (x, y) position in the given color * - * @param x - * @param y + * @param lat + * @param lon * @param color */ private void drawBoat(double lat, double lon, Color color) { // Latitude //Double x = (MAP_WIDTH / 360.0) * (180 + lon); //Double y = (MAP_HEIGHT / 180.0) * (80 - lat); + double yLat = lon; + double yLon = lat; - double x = abs(lat - 32.283808) * 1000; // to prevent negative longitude - double y = abs(lon + 64.854401) * 1000; // to prevent negative latitude + //double x = abs(yLat - 32.283808) * 1000; // to prevent negative longitude + //double y = abs(yLon + 64.854401) * 1000; // to prevent negative latitude + + double y = abs(yLat + 64.854401) * 1000; // to prevent negative longitude + double x = abs(yLon - 32.283808) * 1000; // to prevent negative latitude double diameter = 0.5; gc.setFill(color); @@ -160,8 +199,24 @@ public class CanvasController { * @param singleMark */ private void drawSingleMark(SingleMark singleMark) { - double x = abs(singleMark.getLatitude() - 32.283808) * 1000; // to prevent negative longitude - double y = abs(singleMark.getLongitude() + 64.854401) * 1000; // to prevent negative latitude + double yLat = singleMark.getLongitude(); + double yLon = singleMark.getLatitude(); + + //double yLat = singleMark.getLatitude(); + //double yLon = singleMark.getLongitude(); + + System.out.println(yLat); + System.out.println(yLon); + + //double x = abs(yLat - 32.283808) * 1000; // to prevent negative longitude + //double y = abs(yLon + 64.854401) * 1000; // to prevent negative latitude + + double x = abs(yLon - 32.283808) * 1000; // to prevent negative longitude + double y = abs(yLat + 64.854401) * 1000; // to prevent negative latitude + + System.out.println(x); + System.out.println(y); + System.out.println(); gc.setFill(Color.BLACK); gc.fillOval(x, y, 0.5, 0.5); @@ -176,4 +231,4 @@ public class CanvasController { drawSingleMark(gateMark.getSingleMark1()); drawSingleMark(gateMark.getSingleMark2()); } -} +} \ No newline at end of file diff --git a/src/main/java/seng302/controllers/Controller.java b/src/main/java/seng302/controllers/Controller.java deleted file mode 100644 index 41fb6dc2..00000000 --- a/src/main/java/seng302/controllers/Controller.java +++ /dev/null @@ -1,18 +0,0 @@ -package seng302.controllers; - -import javafx.fxml.FXML; -import javafx.scene.Parent; -import javafx.scene.layout.AnchorPane; - -/** - * Created by ptg19 on 20/03/17. - */ -public class Controller { - @FXML private AnchorPane window; - @FXML private Parent raceView; - @FXML private RaceController raceViewController; - - //^ this is automatic fxml linking based off http://blog.buildpath.de/fxml-composition-how-to-get-the-controller-of-an-included-fxml-view-nested-controllers/ - // From googling it's probably better to just add a child however you did that in your 301 michael, it kinda depends on how we are going to - // make an event for changing the screen. -} diff --git a/src/main/java/seng302/controllers/MasterViewController.java b/src/main/java/seng302/controllers/MasterViewController.java new file mode 100644 index 00000000..72de0419 --- /dev/null +++ b/src/main/java/seng302/controllers/MasterViewController.java @@ -0,0 +1,38 @@ +package seng302.controllers; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Pane; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +/** + * Created by michaelrausch on 21/03/17. + */ +public class MasterViewController implements Initializable { + @FXML + private AnchorPane contentPane; + + private void setContentPane(String jfxUrl){ + try{ + contentPane.getChildren().removeAll(); + contentPane.getChildren().clear(); + contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); + } + catch(javafx.fxml.LoadException e){ + System.err.println(e.getCause()); + } + catch(IOException e){ + System.err.println(e); + } + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + setContentPane("/RaceView.fxml"); + } +} diff --git a/src/main/java/seng302/controllers/RaceController.java b/src/main/java/seng302/controllers/RaceController.java index 11f3a318..fa5d89f0 100644 --- a/src/main/java/seng302/controllers/RaceController.java +++ b/src/main/java/seng302/controllers/RaceController.java @@ -2,9 +2,8 @@ package seng302.controllers; import seng302.models.Boat; import seng302.models.OldFileParser; -import seng302.models.parsers.*; -import seng302.models.mark.*; import seng302.models.Race; +import seng302.models.parsers.CourseParser; import java.io.FileNotFoundException; import java.lang.reflect.Array; @@ -20,6 +19,7 @@ import java.util.Random; */ public class RaceController { Race race = null; + public void initializeRace() { String raceConfigFile; raceConfigFile = "doc/examples/config.json"; diff --git a/src/main/java/seng302/controllers/RaceResultController.java b/src/main/java/seng302/controllers/RaceResultController.java new file mode 100644 index 00000000..ce0fc868 --- /dev/null +++ b/src/main/java/seng302/controllers/RaceResultController.java @@ -0,0 +1,27 @@ +package seng302.controllers; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.layout.AnchorPane; + +import java.net.URL; +import java.util.ResourceBundle; + +/** + * Created by ptg19 on 20/03/17. + */ +public class RaceResultController implements Initializable{ + @FXML private AnchorPane window; + @FXML private Parent raceView; + @FXML private RaceController raceViewController; + + public void setResults(){ + System.out.println("HI MOM"); + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + + } +} diff --git a/src/main/java/seng302/models/Event.java b/src/main/java/seng302/models/Event.java index 51eb814c..00a2b8bd 100644 --- a/src/main/java/seng302/models/Event.java +++ b/src/main/java/seng302/models/Event.java @@ -1,7 +1,6 @@ package seng302.models; import seng302.models.mark.Mark; -import seng302.models.mark.SingleMark; import java.text.SimpleDateFormat; import java.util.Date; @@ -40,7 +39,7 @@ public class Event { * @param eventTime, what time the event happens * @param eventBoat, the boat that the event belongs to */ - public Event(Double eventTime, Boat eventBoat, SingleMark mark1) { + public Event(Double eventTime, Boat eventBoat, Mark mark1) { this.time = eventTime; this.boat = eventBoat; this.mark1 = mark1; diff --git a/src/main/java/seng302/models/Race.java b/src/main/java/seng302/models/Race.java index ab036664..8ac21386 100644 --- a/src/main/java/seng302/models/Race.java +++ b/src/main/java/seng302/models/Race.java @@ -104,8 +104,9 @@ public class Race { // There are no more marks after this event else{ - Event event = new Event(time, boat, course.get(i), course.get(i)); + Event event = new Event(time, boat, course.get(i)); events.get(boat).add(event); + } } } @@ -132,4 +133,8 @@ public class Race { public HashMap getEvents() { return events; } + + public void setBoatFinished(Boat boat){ + this.finishingOrder.add(boat); + } } \ No newline at end of file diff --git a/src/main/resources/FinishView.fxml b/src/main/resources/FinishView.fxml index bdf28013..ba9e3d51 100644 --- a/src/main/resources/FinishView.fxml +++ b/src/main/resources/FinishView.fxml @@ -5,8 +5,7 @@ - - + @@ -22,13 +21,13 @@ - + - - + + diff --git a/src/main/resources/MainView.fxml b/src/main/resources/MainView.fxml index cc35fba2..1b4784a5 100644 --- a/src/main/resources/MainView.fxml +++ b/src/main/resources/MainView.fxml @@ -5,8 +5,8 @@ - + - + diff --git a/src/main/resources/RaceView.fxml b/src/main/resources/RaceView.fxml index e7538f07..002963fd 100644 --- a/src/main/resources/RaceView.fxml +++ b/src/main/resources/RaceView.fxml @@ -6,7 +6,7 @@ - + From a526b0d65a32b8733b71f5858b3194a5613a8774 Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 12:52:43 +1300 Subject: [PATCH 02/12] Rotated map by 180 degrees #fix --- src/main/java/seng302/controllers/CanvasController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 936f4be0..6e850aca 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -58,7 +58,7 @@ public class CanvasController { System.err.println(e.getCause()); } catch (IOException e) { System.err.println(e); - } + } public void initialize() { From c12760b70a5091697aee536f06445dd2065278d4 Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 12:53:42 +1300 Subject: [PATCH 03/12] Inserted missing } #fix --- src/main/java/seng302/controllers/CanvasController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 6e850aca..936f4be0 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -58,7 +58,7 @@ public class CanvasController { System.err.println(e.getCause()); } catch (IOException e) { System.err.println(e); - + } } public void initialize() { From 7591a7932339356301f837301fe3d56244530c2c Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 14:05:55 +1300 Subject: [PATCH 04/12] Fixed course rotation #fix --- doc/examples/course.xml | 36 +++++++------- .../seng302/controllers/CanvasController.java | 48 +++++++------------ 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/doc/examples/course.xml b/doc/examples/course.xml index 49e17923..f8bfa00e 100644 --- a/doc/examples/course.xml +++ b/doc/examples/course.xml @@ -6,57 +6,57 @@ Start Start1 - 32.296038 - -64.854401 + 32.296577 + -64.854304 Start2 - 32.293834 - -64.855195 + 32.293771 + -64.855242 Mid Mark - 32.292881 - -64.843231 + 32.293039 + -64.843983 Leeward Gate Leeward Gate1 - 32.283808 - -64.850012 + 32.284680 + -64.850045 Leeward Gate2 - 32.283216 - -64.847686 + 32.280164 + -64.847591 Windward Gate Windward Gate1 - 32.309908 - -64.833665 + 32.309693 + -64.835249 Windward Gate2 - 32.309158 - -64.830834 + 32.308046 + -64.831785 Finish Finish1 - 32.318439 - -64.837367 + 32.317379 + -64.839291 Finish2 - 32.318303 - -64.834974 + 32.317257 + -64.836260 diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 936f4be0..b50594f3 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -28,8 +28,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import static java.lang.Math.abs; - /** * Created by ptg19 on 15/03/17. * Modified by Haoming Yin (hyi25) on 20/3/2017. @@ -40,6 +38,9 @@ public class CanvasController { private GraphicsContext gc; private HashMap timelineInfos; + private final double ORIGIN_LAT = 32.320504; + private final double ORIGIN_LON = -64.857063; + @FXML private Canvas canvas; @@ -85,10 +86,16 @@ public class CanvasController { timer.start(); int i = 0; + Double maxDuration = 0.0; for (TimelineInfo timelineInfo : timelineInfos.values()) { Timeline timeline = timelineInfo.getTimeline(); + System.out.println(); + + if (/*timeline.getTotalDuration().greaterThanOrEqualTo(maxDuration)*/ true){ + + } if (i == timelineInfos.values().size() - 1) { timeline.setOnFinished(event -> { @@ -99,6 +106,10 @@ public class CanvasController { } }); + System.out.println("B"); + } + else{ + System.out.println("A"); } timeline.play(); @@ -164,18 +175,11 @@ public class CanvasController { */ private void drawBoat(double lat, double lon, Color color) { // Latitude - //Double x = (MAP_WIDTH / 360.0) * (180 + lon); - //Double y = (MAP_HEIGHT / 180.0) * (80 - lat); - double yLat = lon; - double yLon = lat; - - //double x = abs(yLat - 32.283808) * 1000; // to prevent negative longitude - //double y = abs(yLon + 64.854401) * 1000; // to prevent negative latitude - - double y = abs(yLat + 64.854401) * 1000; // to prevent negative longitude - double x = abs(yLon - 32.283808) * 1000; // to prevent negative latitude + double x = (lon - ORIGIN_LON) * 1000; + double y = (ORIGIN_LAT - lat) * 1000; double diameter = 0.5; + gc.setFill(color); gc.fillOval(x, y, diameter, diameter); } @@ -199,24 +203,8 @@ public class CanvasController { * @param singleMark */ private void drawSingleMark(SingleMark singleMark) { - double yLat = singleMark.getLongitude(); - double yLon = singleMark.getLatitude(); - - //double yLat = singleMark.getLatitude(); - //double yLon = singleMark.getLongitude(); - - System.out.println(yLat); - System.out.println(yLon); - - //double x = abs(yLat - 32.283808) * 1000; // to prevent negative longitude - //double y = abs(yLon + 64.854401) * 1000; // to prevent negative latitude - - double x = abs(yLon - 32.283808) * 1000; // to prevent negative longitude - double y = abs(yLat + 64.854401) * 1000; // to prevent negative latitude - - System.out.println(x); - System.out.println(y); - System.out.println(); + double x = (singleMark.getLongitude() - ORIGIN_LON) * 1000; + double y = (ORIGIN_LAT - singleMark.getLatitude()) * 1000; gc.setFill(Color.BLACK); gc.fillOval(x, y, 0.5, 0.5); From f6ea2953e999266e48b1838f93cd2e2e3bbd83ae Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 14:28:51 +1300 Subject: [PATCH 05/12] Changed lat/long for gates to midpoint and added colours for the marks Tags: #fix #implement #story[10,11] --- .../seng302/controllers/CanvasController.java | 31 ++++++++++++++++--- .../java/seng302/models/mark/GateMark.java | 8 +++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index b50594f3..5ffa2a3c 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -190,7 +190,7 @@ public class CanvasController { private void drawCourse() { for (Mark mark : race.getCourse()) { if (mark.getMarkType() == MarkType.SINGLE_MARK) { - drawSingleMark((SingleMark) mark); + drawSingleMark((SingleMark) mark, Color.BLACK); } else if (mark.getMarkType() == MarkType.GATE_MARK) { drawGateMark((GateMark) mark); } @@ -202,11 +202,11 @@ public class CanvasController { * * @param singleMark */ - private void drawSingleMark(SingleMark singleMark) { + private void drawSingleMark(SingleMark singleMark, Color color) { double x = (singleMark.getLongitude() - ORIGIN_LON) * 1000; double y = (ORIGIN_LAT - singleMark.getLatitude()) * 1000; - gc.setFill(Color.BLACK); + gc.setFill(color); gc.fillOval(x, y, 0.5, 0.5); } @@ -216,7 +216,28 @@ public class CanvasController { * @param gateMark */ private void drawGateMark(GateMark gateMark) { - drawSingleMark(gateMark.getSingleMark1()); - drawSingleMark(gateMark.getSingleMark2()); + Color color = Color.BLUE; + + if (gateMark.getName().equals("Start") || gateMark.getName().equals("Finish")){ + color = Color.RED; + } + + drawSingleMark(gateMark.getSingleMark1(), color); + drawSingleMark(gateMark.getSingleMark2(), color); + + GraphicsContext gc = canvas.getGraphicsContext2D(); + + gc.setStroke(color); + + //@todo Put this in Mark class + double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * 1000; + double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * 1000; + + double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * 1000; + double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * 1000; + + gc.setLineWidth(0.1); + + gc.strokeLine(x1, y1, x2, y2); } } \ No newline at end of file diff --git a/src/main/java/seng302/models/mark/GateMark.java b/src/main/java/seng302/models/mark/GateMark.java index 208d2416..edf4f4ec 100644 --- a/src/main/java/seng302/models/mark/GateMark.java +++ b/src/main/java/seng302/models/mark/GateMark.java @@ -37,4 +37,12 @@ public class GateMark extends Mark { public void setSingleMark2(SingleMark singleMark2) { this.singleMark2 = singleMark2; } + + public double getLatitude(){ + return (this.getSingleMark1().getLatitude() + this.getSingleMark2().getLatitude()) / 2; + } + + public double getLongitude(){ + return (this.getSingleMark1().getLongitude() + this.getSingleMark2().getLongitude()) / 2; + } } From 039e61def6780744dc557b2986a0787aac235cfe Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 14:50:28 +1300 Subject: [PATCH 06/12] Fixed broken JavaFX file #fix --- src/main/resources/RaceView.fxml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/resources/RaceView.fxml b/src/main/resources/RaceView.fxml index 46120626..d14c7c88 100644 --- a/src/main/resources/RaceView.fxml +++ b/src/main/resources/RaceView.fxml @@ -7,9 +7,6 @@ -<<<<<<< HEAD - -======= @@ -20,7 +17,6 @@ ->>>>>>> 29a0b236703d61e4553cda97e470d1125587cfde From a41f2e4bdefae9d3db0db9b81309700a460de037 Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 15:10:57 +1300 Subject: [PATCH 07/12] Changed marks from circles to squares #fix --- src/main/java/seng302/controllers/CanvasController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 2beee4ff..0c8f749d 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -209,7 +209,8 @@ public class CanvasController { double y = (ORIGIN_LAT - singleMark.getLatitude()) * 1000; gc.setFill(color); - gc.fillOval(x, y, 0.5, 0.5); + gc.fillRect(x,y,0.5,0.5); + //gc.fillOval(x, y, 0.5, 0.5); } /** From 9e22eac4d85656fedc74912ea842cc201ba2d9ec Mon Sep 17 00:00:00 2001 From: Michael Rausch Date: Wed, 22 Mar 2017 22:30:49 +1300 Subject: [PATCH 08/12] Added the race results to the RaceResultController. Also fixed some bugs - Fixed a bug where the race results would be out of order. - Changed the colour of the start and finish gates - Added the race results to the RaceResultController and updated view Tags: #fix #implement #story[13, 10, 11] --- doc/examples/config.json | 4 +- doc/examples/config.xml | 2 +- .../seng302/controllers/CanvasController.java | 56 ++++++++----------- .../seng302/controllers/RaceController.java | 12 ++-- .../controllers/RaceResultController.java | 20 +++++-- src/main/java/seng302/models/Race.java | 1 + src/main/resources/FinishView.fxml | 35 +++++++++--- src/main/resources/RaceView.fxml | 2 +- 8 files changed, 76 insertions(+), 56 deletions(-) diff --git a/doc/examples/config.json b/doc/examples/config.json index 8a3f3ac2..80c3b3e4 100644 --- a/doc/examples/config.json +++ b/doc/examples/config.json @@ -9,7 +9,7 @@ }, { "team-name": "Artemis Racing", - "velocity": 10.3 + "velocity": 59.3 }, { "team-name": "Emirates Team New Zealand", @@ -17,7 +17,7 @@ }, { "team-name": "Groupama Team France", - "velocity": 9.9 + "velocity": 29.9 }, { "team-name": "Land Rover BAR", diff --git a/doc/examples/config.xml b/doc/examples/config.xml index 05c20921..34e008cc 100644 --- a/doc/examples/config.xml +++ b/doc/examples/config.xml @@ -3,6 +3,6 @@ AC35 6 - 2.0 + 1.0 diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 0c8f749d..033598ec 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -40,23 +40,23 @@ public class CanvasController { private GraphicsContext gc; private HashMap timelineInfos; + private AnchorPane raceResults; + private final double ORIGIN_LAT = 32.320504; private final double ORIGIN_LON = -64.857063; - private final double VIEW_CORNER_LAT = 32.280808; - private final double VIEW_CORNER_LON = -64.858401; - @FXML private AnchorPane contentAnchorPane; - @FXML - private RaceResultController raceResultController; + private void loadRaceResultView() { + FXMLLoader loader = new FXMLLoader(getClass().getResource("/FinishView.fxml")); + loader.setController(new RaceResultController(race)); - private void setContentPane(String jfxUrl) { try { contentAnchorPane.getChildren().removeAll(); contentAnchorPane.getChildren().clear(); - contentAnchorPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); + contentAnchorPane.getChildren().addAll((Pane) loader.load()); + } catch (javafx.fxml.LoadException e) { System.err.println(e.getCause()); } catch (IOException e) { @@ -87,37 +87,23 @@ public class CanvasController { // starts the timer and reads events from each boat's time line timer.start(); - int i = 0; Double maxDuration = 0.0; + Timeline maxTimeline = null; for (TimelineInfo timelineInfo : timelineInfos.values()) { Timeline timeline = timelineInfo.getTimeline(); System.out.println(); - if (/*timeline.getTotalDuration().greaterThanOrEqualTo(maxDuration)*/ true){ - - } - - if (i == timelineInfos.values().size() - 1) { - timeline.setOnFinished(event -> { - setContentPane("/FinishView.fxml"); - - for (Boat boat : race.getFinishedBoats()) { - System.out.println(boat.getTeamName()); - } - - }); - System.out.println("B"); - } - else{ - System.out.println("A"); + if (timeline.getTotalDuration().toMillis() >= maxDuration) { + maxDuration = timeline.getTotalDuration().toMillis(); + maxTimeline = timeline; } timeline.play(); - - i++; } + + maxTimeline.setOnFinished(event -> loadRaceResultView()); } /** @@ -210,7 +196,6 @@ public class CanvasController { gc.setFill(color); gc.fillRect(x,y,0.5,0.5); - //gc.fillOval(x, y, 0.5, 0.5); } /** @@ -221,10 +206,14 @@ public class CanvasController { private void drawGateMark(GateMark gateMark) { Color color = Color.BLUE; - if (gateMark.getName().equals("Start") || gateMark.getName().equals("Finish")){ + if (gateMark.getName().equals("Start")){ color = Color.RED; } + if (gateMark.getName().equals("Finish")){ + color = Color.GREEN; + } + drawSingleMark(gateMark.getSingleMark1(), color); drawSingleMark(gateMark.getSingleMark2(), color); @@ -232,15 +221,18 @@ public class CanvasController { gc.setStroke(color); - //@todo Put this in Mark class + // Convert lat/lon to x,y double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * 1000; double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * 1000; double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * 1000; double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * 1000; - gc.setLineWidth(0.1); - + gc.setLineWidth(0.07); gc.strokeLine(x1, y1, x2, y2); } + + public Race getRace(){ + return this.race; + } } \ No newline at end of file diff --git a/src/main/java/seng302/controllers/RaceController.java b/src/main/java/seng302/controllers/RaceController.java index fa5d89f0..e8471426 100644 --- a/src/main/java/seng302/controllers/RaceController.java +++ b/src/main/java/seng302/controllers/RaceController.java @@ -55,13 +55,18 @@ public class RaceController { //get race size int numberOfBoats = (int) fp.getRaceSize(); + int boatsAdded = 0; //get time scale double timeScale = fp.getTimeScale(); race.setTimeScale(timeScale); for (Map team : teams) { - boatNames.add((String) team.get("team-name")); + if (boatsAdded < numberOfBoats){ + boatNames.add((String) team.get("team-name")); + race.addBoat(new Boat(team.get("team-name").toString(), (Double) (team.get("velocity")))); + } + boatsAdded++; } // Shuffle team names @@ -72,11 +77,6 @@ public class RaceController { return null; } - // Add boats to the race - for (int i = 0; i < numberOfBoats; i++) { - race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity")))); - } - CourseParser cp = new CourseParser("doc/examples/course.xml"); race.addCourse(cp.getCourse()); diff --git a/src/main/java/seng302/controllers/RaceResultController.java b/src/main/java/seng302/controllers/RaceResultController.java index ce0fc868..7378fa68 100644 --- a/src/main/java/seng302/controllers/RaceResultController.java +++ b/src/main/java/seng302/controllers/RaceResultController.java @@ -2,8 +2,10 @@ package seng302.controllers; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.Parent; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; +import seng302.models.Race; import java.net.URL; import java.util.ResourceBundle; @@ -13,15 +15,23 @@ import java.util.ResourceBundle; */ public class RaceResultController implements Initializable{ @FXML private AnchorPane window; - @FXML private Parent raceView; - @FXML private RaceController raceViewController; + @FXML private VBox resultsVBox; + private Race race; - public void setResults(){ - System.out.println("HI MOM"); + RaceResultController(Race race){ + this.race = race; } @Override public void initialize(URL location, ResourceBundle resources) { + int boatPosition = this.race.getFinishedBoats().length; + + for (int i = this.race.getFinishedBoats().length - 1; i >= 0; i--){ + resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getTeamName())); + boatPosition--; + } + + } } diff --git a/src/main/java/seng302/models/Race.java b/src/main/java/seng302/models/Race.java index 8ac21386..7361ebec 100644 --- a/src/main/java/seng302/models/Race.java +++ b/src/main/java/seng302/models/Race.java @@ -135,6 +135,7 @@ public class Race { } public void setBoatFinished(Boat boat){ + System.out.println(boat.getTeamName() + " finished"); this.finishingOrder.add(boat); } } \ No newline at end of file diff --git a/src/main/resources/FinishView.fxml b/src/main/resources/FinishView.fxml index ba9e3d51..debdea26 100644 --- a/src/main/resources/FinishView.fxml +++ b/src/main/resources/FinishView.fxml @@ -1,36 +1,53 @@ + - + - - + + - - - + + + + - + + + + - - + + + + + + + + + + + + + + diff --git a/src/main/resources/RaceView.fxml b/src/main/resources/RaceView.fxml index d14c7c88..e658a8bf 100644 --- a/src/main/resources/RaceView.fxml +++ b/src/main/resources/RaceView.fxml @@ -18,7 +18,7 @@ - + From a2d06909c99318f89504064745162f2ef276b99e Mon Sep 17 00:00:00 2001 From: Haoming Yin Date: Thu, 23 Mar 2017 00:21:18 +1300 Subject: [PATCH 09/12] Finished config parser to read race info from external xml file - created config parser unit test. - modified config.xml file - write unit test for config parser #story[422] --- doc/examples/config.xml | 1 + .../seng302/models/parsers/ConfigParser.java | 80 +++++++++++++++++++ .../models/parsers/ConfigParserTest.java | 42 ++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/main/java/seng302/models/parsers/ConfigParser.java create mode 100644 src/test/java/seng302/models/parsers/ConfigParserTest.java diff --git a/doc/examples/config.xml b/doc/examples/config.xml index 34e008cc..4a1b0770 100644 --- a/doc/examples/config.xml +++ b/doc/examples/config.xml @@ -4,5 +4,6 @@ AC35 6 1.0 + 135 diff --git a/src/main/java/seng302/models/parsers/ConfigParser.java b/src/main/java/seng302/models/parsers/ConfigParser.java new file mode 100644 index 00000000..74d0986a --- /dev/null +++ b/src/main/java/seng302/models/parsers/ConfigParser.java @@ -0,0 +1,80 @@ +package seng302.models.parsers; + + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import java.util.DoubleSummaryStatistics; + +public class ConfigParser extends FileParser { + + private Document doc; + + public ConfigParser(String path) { + super(path); + this.doc = this.parseFile(); + } + + /** + * Gets wind direction from config file. + * + * @return a double type degree, or 0 if no value or invalid value is found + */ + public double getWindDirection() { + return getDoubleByTagName("wind-direction", 0.0); + } + + /** + * Gets a non negative time scale for the race + * + * @return a double type scale, or 0 if no scale or invalid scale is found + */ + public double getTimeScale() { + return getDoubleByTagName("time-scale", 1.0); + } + + /** + * Gets a double type number by given tag name found in xml file + * + * @param tagName a string of tag name + * @param defaultVal value returned if no value or invalid value is found + * @return value found + */ + public double getDoubleByTagName(String tagName, double defaultVal) { + double val = defaultVal; + try { + Node node = this.doc.getElementsByTagName(tagName).item(0); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + val = Double.valueOf(element.getTextContent()); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + return val; + } + } + + /** + * Gets a string by given tag name found in xml file + * + * @param tagName a string of tag name + * @param defaultVal a string returned if no value or invalid value is found + * @return string found + */ + public String getStringByTagName(String tagName, String defaultVal) { + String string = defaultVal; + try { + Node node = this.doc.getElementsByTagName(tagName).item(0); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + string = element.getTextContent(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + return string; + } + } +} diff --git a/src/test/java/seng302/models/parsers/ConfigParserTest.java b/src/test/java/seng302/models/parsers/ConfigParserTest.java new file mode 100644 index 00000000..26387220 --- /dev/null +++ b/src/test/java/seng302/models/parsers/ConfigParserTest.java @@ -0,0 +1,42 @@ +package seng302.models.parsers; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by Haoming on 23/03/17. + */ +public class ConfigParserTest { + + private ConfigParser cp; + + @Before + public void initializeParser() throws Exception { + cp = new ConfigParser("doc/examples/config.xml"); + } + + @Test + public void getWindDirection() throws Exception { + assertEquals(135, cp.getWindDirection(), 1e-10); + } + + @Test + public void getTimeScale() throws Exception { + assertEquals(1.0, cp.getTimeScale(), 1e-10); + } + + @Test + public void getDoubleByTagName() throws Exception { + assertEquals(6, cp.getDoubleByTagName("race-size", 0), 1e-10); + assertEquals(100, cp.getDoubleByTagName("noTag", 100), 1e-10); + } + + @Test + public void getStringByTagName() throws Exception { + assertEquals("AC35", cp.getStringByTagName("race-name", "11")); + assertEquals("oops", cp.getStringByTagName("noTag", "oops")); + } + +} \ No newline at end of file From 42ffd1b1f894fb676fcc0164a70234b8689e629f Mon Sep 17 00:00:00 2001 From: Haoming Yin Date: Thu, 23 Mar 2017 01:10:07 +1300 Subject: [PATCH 10/12] Add rotated wind direction arrow to race view. #story[422] --- .../seng302/controllers/CanvasController.java | 10 ++++++++++ src/main/resources/RaceView.fxml | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java index 033598ec..2e00b8f1 100644 --- a/src/main/java/seng302/controllers/CanvasController.java +++ b/src/main/java/seng302/controllers/CanvasController.java @@ -13,6 +13,7 @@ import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; +import javafx.scene.text.Text; import javafx.util.Duration; import seng302.models.Boat; import seng302.models.Event; @@ -22,6 +23,8 @@ import seng302.models.mark.GateMark; import seng302.models.mark.Mark; import seng302.models.mark.MarkType; import seng302.models.mark.SingleMark; +import seng302.models.parsers.ConfigParser; +import seng302.models.parsers.CourseParser; import java.io.IOException; import java.util.ArrayList; @@ -47,6 +50,8 @@ public class CanvasController { @FXML private AnchorPane contentAnchorPane; + @FXML + private Text windArrowText, windDirectionText; private void loadRaceResultView() { FXMLLoader loader = new FXMLLoader(getClass().getResource("/FinishView.fxml")); @@ -104,6 +109,11 @@ public class CanvasController { } maxTimeline.setOnFinished(event -> loadRaceResultView()); + + //set wind direction!!!!!!! can't find another place to put my code --haoming + double windDirection = new ConfigParser("doc/examples/config.xml").getWindDirection(); + windDirectionText.setText(String.format("%.1f°", windDirection)); + windArrowText.setRotate(windDirection); } /** diff --git a/src/main/resources/RaceView.fxml b/src/main/resources/RaceView.fxml index e658a8bf..4a726873 100644 --- a/src/main/resources/RaceView.fxml +++ b/src/main/resources/RaceView.fxml @@ -1,5 +1,7 @@ + + @@ -18,7 +20,7 @@ - + @@ -33,6 +35,17 @@