Compare commits

..

341 Commits

Author SHA1 Message Date
Kusal Ekanayake e0854bc68c Merge remote-tracking branch 'origin/master' 2017-05-25 14:55:35 +12:00
Kusal Ekanayake cec7014856 Set axis ons parkline style 2017-05-25 14:54:34 +12:00
Kusal Ekanayake f1a9da83fc Quick fixes before merge 2017-05-25 14:22:01 +12:00
Kusal Ekanayake 6e903bfbed Merge branch 'develop' into 38b_LayLines
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/models/Yacht.java
#	src/main/java/seng302/models/stream/StreamParser.java
2017-05-25 14:16:55 +12:00
Michael Rausch 23d62f552e Merged develop onto this branch
Tidied code, removed print statements

#story[956] #pair[wmu16, mra106]
2017-05-25 14:06:33 +12:00
Kusal Ekanayake 53f6a6b8c5 Implimented a new way to determine positions
#story[952]
2017-05-25 14:06:33 +12:00
Michael Rausch af81bf5891 Merge remote-tracking branch 'origin/develop' into 38b_LayLines
# Conflicts:
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/Event.java
#	src/main/java/seng302/models/mark/Mark.java
#	src/main/java/seng302/models/stream/StreamParser.java
2017-05-25 13:56:08 +12:00
Michael Rausch e72ac1def8 Laylines are now togglable. Still not completely fool proof
Laylines appear only for the selected boat. The dissapear if the boat is not seleccted. Laylines are the colour of the boat

Laylines do not yet automatically update for a selected boat when it passes a mark

There is still a polling interval of a second in which if you select a boat after it has just passed a mark it still thinks the next mark is that mark and laylines are displayed incorrectly

#story[956] #pair[wmu16, mra106]
2017-05-25 13:48:48 +12:00
Calum adbb9ffe3b Removed completed TODO request. 2017-05-25 10:31:37 +12:00
Calum a6d9c66fc9 Removed unused import statements and class variables. Removed non error print statements. 2017-05-25 10:20:39 +12:00
William Muir 99588c7ff8 Laylines now working upon selecting a boat. Still need to make their visibility togglable
Currently just paints upon clicking

tags: #story[956]
2017-05-25 09:54:00 +12:00
William Muir 68c3e3e999 Merged develop onto this branchk
tags: #story[956]
2017-05-25 09:21:47 +12:00
William Muir 67b5650288 Merge branch 'develop' into 38b_LayLines
# Conflicts:
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/Yacht.java
2017-05-25 09:19:42 +12:00
William Muir ffe70a8313 Trying to get laylines to display on proper respective sides of the gate
Having a great time here, Not quite working. There was an issue where the laylines are crossed and I think its tied to the fact that sometimes the two seperate points of the gate mark appear to have the same x y coordinate so the line function doesnt work? idk

tags: #story[956] #pair[wmu16]
2017-05-25 00:22:15 +12:00
Haoming Yin 331e0fc6ab Merge branch 'Story34_Sparklines' into 'develop'
Story34 sparklines



See merge request !38
2017-05-24 22:24:50 +12:00
Kusal Ekanayake b3fd735f5c Merge branch 'develop' into Story34_Sparklines
# Conflicts:
#	src/main/java/seng302/controllers/CanvasController.java
2017-05-24 21:50:15 +12:00
William Muir 3cbbdb070f Basic implementation for mapping windspeed to draw a polar on a gate complete
Created functionality to grab the closest windspeed value to map to VMG values based off the current wind speed in the Polar Table

Created new RaceXML mark object which contains ALL marks for purposes of sequencing

Displaying correct (?) polars for one point only on a gate

Created functionality to receive leg data for each boat and then map that to the next gate. This may only work for the current race due to a slight fudge factor

Created functionality to receive wind speed

tags: #story[956] #pair[wmu16, mra106]
2017-05-24 20:31:07 +12:00
Haoming Yin d2e55bf964 Removed the FPS background, and lowered the update frequency so it doesn't flip too fast.
#story[923]
2017-05-24 19:33:24 +12:00
Kusal Ekanayake 05cdadac79 Merge remote-tracking branch 'origin/Story34_Sparklines' into Story34_Sparklines 2017-05-24 18:57:09 +12:00
Kusal Ekanayake e6aed88188 Merge with develop.
#story[952]
2017-05-24 18:56:56 +12:00
Kusal Ekanayake d032314ddb Merge branch 'develop' into Story34_Sparklines
# Conflicts:
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/Yacht.java
2017-05-24 18:56:04 +12:00
Peter Galloway 6301fd2fb7 Merge branch 'issue#5_fix_pre-race_boats_on_leaderboard' into 'develop'
Issue#5 fix pre race boats on leaderboard

Updated leaderboard so it only shows competing boats and pre-race no longer shows only one boat

See merge request !36
2017-05-24 18:52:37 +12:00
Kusal Ekanayake 34c3899ec4 Removed unused css for charts 2017-05-24 18:51:52 +12:00
Kusal Ekanayake 46f5fc5172 Merge with develop.
#story[952]
2017-05-24 18:47:27 +12:00
Kusal Ekanayake 81c021b59a Merge branch 'develop' into Story34_Sparklines
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/resources/views/RaceView.fxml
2017-05-24 18:45:01 +12:00
Kusal Ekanayake 8ab57e4e61 Cleaned up code for review.
#story[952]
2017-05-24 18:43:50 +12:00
Zhi You Tan 13ff179840 Merge remote-tracking branch 'origin/develop' into issue#5_fix_pre-race_boats_on_leaderboard 2017-05-24 16:18:33 +12:00
Michael Rausch 76c0d34760 Merge branch '37-display_map_on_canvas' into 'develop'
37 display map on canvas

Merge request for story #928

See merge request !37
2017-05-24 15:05:39 +12:00
Michael Rausch 71637d7286 Removed dead code from canvas controller and canvas map
Tags: #story[928]
2017-05-24 15:04:12 +12:00
William Muir 1cac7cc189 Calculation of upwind downwind leg given a boat, wind and next mark now works. created GeometryUtils class
Can accurately calculate if a boat is going upwind or downward using a line function for the wind vector from the gate and the boat position from the gate.

Requires knowledge of the next mark which requires the boat to have passed a mark. This could be fixed by extracting the leg number from the race status packet and mapping these to gates in an initalisation step

tags: #story[956]
2017-05-24 14:57:22 +12:00
Haoming Yin c42942430f Fixed bug that grid panel pushes annotation panel up out of window.
#story[928]
2017-05-24 14:57:06 +12:00
Kusal Ekanayake 7abb36c362 The axis is labeled correctly and is scaled accordingly.
The sparkline should work from the start of a race now also. We now have the boat in first place listed at the top along with the axis labeling and marking matching the position (eg, 1st at top. 6th at bottom). Boats picked up on the visualiser park way through the race are able to added and drawn onto the sparkline.

#story[952]
2017-05-24 14:42:41 +12:00
Haoming Yin 3fd0c0a2dd Merge remote-tracking branch 'origin/37-display_map_on_canvas' into 37-display_map_on_canvas
# Conflicts:
#	src/main/java/seng302/App.java
2017-05-24 13:55:42 +12:00
Haoming Yin 397f7d003a Fixed the size of race canvas and race view so that canvas won't be stretched
- canvas view is set to 1280 * 960

#story[928]
2017-05-24 13:54:05 +12:00
Haoming Yin f85d3bf5fe Plugged Canvas map to canvas view controller to display map
- rebase on the latest develop status
- optimised the scaling factor the map to fit the canvas view
- a new image containing map image is displayed under race canvas

#story[928]
2017-05-24 13:52:49 +12:00
Haoming Yin 8f93956ff1 Added methods to calculate optimal map size given a geo boundary.
- From zoom level 20 to 1, once find a size that contains the whole boundary, then the size will be used to retrieve map image from google

#story[928]
2017-05-24 00:49:03 +12:00
Haoming Yin 4fe4ac1079 Added get map size (width and height) method in canvasMap with given boundary
#story[928]
2017-05-24 00:49:03 +12:00
Haoming Yin 8a2f0a9f45 Added unit tests for Mercator projection class.
- changed its methods to static
- add some documentation for its methods

#story[928]
2017-05-24 00:49:03 +12:00
Haoming Yin 5cc865f0af Created Mercator projection to convert between Geo location and planar projection point.
- MapGeo and MapPoint encapsulate geo location and planar projection point into classes.

#story[928]
2017-05-24 00:49:03 +12:00
Haoming Yin 189ba93e64 Created a canvas map class to fetch map image from google
- also added Bound class to encapsulate map boundary.
- created TestMapView and its controller just for testing.

#story[928]
2017-05-24 00:49:03 +12:00
William Muir 89464e033e Initial work on calculating when a gate is upwind or downwind
Need to know if a gate is upwind or downwind to use the appropriate polar table

Currently calculate the angle between the next mark and the vector of the current mark to the wind, if this angle is less than 90 degrees than the next mark should be down wind

Pretty poor implementation currently, just prototype

Doesn't appear to be working as intended currently. Just a prototype for how we could implement further

tags: #story[956]
2017-05-24 00:08:55 +12:00
Zhi You Tan 6d7c36e31f Updated code to check if boat is in the race before displaying in the leaderboard
#story[923]
2017-05-23 20:00:23 +12:00
Michael Rausch ca8ea03870 Added method in mark group to draw lay lines, also added next mark to Yacht class.
#story[956]
2017-05-23 18:54:42 +12:00
Kusal Ekanayake 3f57adb9cf Merge branch 'develop' into Story34_Sparklines
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/resources/views/RaceView.fxml
2017-05-23 14:06:24 +12:00
Zhi You Tan 2686dac62e Fixed Yacht position initialise. TO-DO: check if the boat is participating before showing up on leaderboard. 2017-05-23 11:53:23 +12:00
Zhi You Tan ffd40fef6d Merge remote-tracking branch 'origin/develop' into issue#5_fix_pre-race_boats_on_leaderboard
# Conflicts:
#	src/main/java/seng302/controllers/RaceController.java
#	src/main/java/seng302/controllers/StartScreenController.java
2017-05-23 11:31:18 +12:00
William Muir e1b8e19966 Initial work on finding next marks for boats as from mark rounding messages
Marks were very difficult to extend, need large refactor

Marks now have a compound ID as well as their sourceID. They need this compound ID to be identifiable by the
mark rounding messages.

tags: #story[956]  #pair[wmu16, mra106]
2017-05-22 18:54:07 +12:00
William Muir dec742cf54 Merge remote-tracking branch 'origin/develop' into 38b_LayLines 2017-05-22 18:15:58 +12:00
Zhi You Tan 6f1b0b06c3 Fixed est time to next mark and time from last mark annotation update after commit e0750f53 in BoatGroup.java
#story[924] #story[927]
2017-05-22 16:17:52 +12:00
Michael Rausch 408d70c420 Merge branch 'issue#10_unifying_marks' into 'develop'
Issue#10 unifying marks

Marks work properly, reading boat position packets and moving.

First and last marks are colored green and red respectively.

See merge request !35
2017-05-22 16:07:50 +12:00
Alistair McIntyre e51c966969 Made sure only boats in participant list are replaced. Also removed mark coloring as it wasn't as accurate as was necessary.
#story[923]
2017-05-22 16:05:24 +12:00
William Muir 08eacacfd4 Polar table is now parsed form the stored file in resources on startup in main
story[956]
2017-05-22 15:45:16 +12:00
William Muir 87150b3c72 Merge remote-tracking branch 'origin/develop' into 38b_LayLines 2017-05-22 15:40:11 +12:00
William Muir e385ac5c09 Initial work on static parser class for polar files
story[956]
2017-05-22 15:39:53 +12:00
Alistair McIntyre c30629542b Merged develop into issue10 branch. Fixed merge issues and completed manual testing before merge request.
#story[923]
2017-05-22 15:27:23 +12:00
Alistair McIntyre 3f9fa24c69 Merge branch 'develop' into issue#10_unifying_marks
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/controllers/CanvasController.java
2017-05-22 15:13:48 +12:00
Alistair McIntyre 78573fa837 Made start/finish lines a different color.
#story[923]
2017-05-22 15:10:05 +12:00
Michael Rausch d4837cacda Merge branch 'Issue#4_boat_movement' into 'develop'
Issue#4 boat movement

This merge will break several things:
1 boat wakes and trails will be the most effective and will have to be manually re-implemented in the re-engineered boatgroup
2 boat annotations in Raceviewcontroller have been effected
3 boat selection (on click) in Raceviewcontroller has been effected

See merge request !34
2017-05-22 15:03:11 +12:00
Peter Galloway 0367805f0f fixed bug from merge where est time to next mark was null on some boats #story[923] 2017-05-22 15:01:04 +12:00
Peter Galloway e0750f5341 Merge branch 'develop' into Issue#4_boat_movement
# Conflicts:
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/Race.java
2017-05-22 14:56:08 +12:00
Calum 80528c9c42 fixed bug in canvas controller
#bug
2017-05-22 14:30:31 +12:00
alistairjmcintyre be633c0e60 Marks display correctly on the canvas, no double ups or anything like that left.
#[issue10]
2017-05-22 13:22:55 +12:00
cir27 97f1ccb6c1 Fixed a bug where an error was caused when attempting to flip the race around the prime meridian.
All x values are now flipped horizontally if the difference between the smallest lon, e.g. -179.5 and the largest e.g. 179.5 is greater than 180.

#story[923] #bug
2017-05-22 05:41:57 +12:00
cir27 68a243725b Fixed a bug where an error was caused when attempting to flip the race around the prime meridian.
All x values are now flipped horizontally if the difference between the smallest lon, e.g. -179.5 and the largest e.g. 179.5 is greater than 180.

#story[923] #bug
2017-05-22 05:39:36 +12:00
Kusal Ekanayake 8f81060a18 Managed to make the sparklines coordinate with their colour.
However the symbols had to be removed. The sparkline can also be intialised at any time now but this might need to be tested further to ensure that it works.

#story[952]
2017-05-21 19:49:11 +12:00
Kusal Ekanayake 07c76f12e1 Merge branch 'develop' into Story34_Sparklines 2017-05-21 17:37:41 +12:00
cir27 c6ab96a86f Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop 2017-05-21 16:05:37 +12:00
Kusal Ekanayake 059c0de1fa Quickfix for null pointer in boatObject
#pair[ptg19,kre39]
2017-05-21 15:58:17 +12:00
Kusal Ekanayake 8e147bd1bd Making the boat sparkline initialise after the race screen is shown.
#story[952]
2017-05-21 14:56:05 +12:00
Michael Rausch 4d3cfe71f7 Merge branch 'develop' into Issue#4_boat_movement
Conflicts:
	src/main/java/seng302/models/BoatGroup.java
	src/main/java/seng302/models/Wake.java
2017-05-19 21:40:16 +12:00
Michael Rausch 5adb7c3762 Fixed failing ColorsTest
#story[923]
2017-05-19 20:57:40 +12:00
Michael Rausch 937b309b07 Added boat trails to the boat group, fixed annotations
- Set colours for the annotations
- Added boat trails back into the boat group
- Re-added time until next mark and time since last mark rounding

#story[923]
2017-05-19 20:55:02 +12:00
Kusal Ekanayake 48d58ea660 Sparklines now update when a boat passes a mark.
There are issue of initialising the sparkline before the race starts and when the race is being viewed when it starts. It works great though when you join a race halfway.
#story[952]
2017-05-19 18:08:26 +12:00
Michael Rausch aaf2e6a3f0 Added boat wakes back to the visualiser
#story[923]
2017-05-19 16:57:29 +12:00
Kusal Ekanayake 422dcd4501 Sparklines now update with boat position change.
Need to make it work for any amount of boats in the race and to work when the race first starts as it currently only shows one boat.
#story[952]
2017-05-19 15:15:05 +12:00
Kusal Ekanayake 951a726309 The line chart now has series which display on it.
Need to get the right data to display on the linechart when it updates.

#story[952]
2017-05-18 20:56:42 +12:00
Alistair McIntyre b692ddcbe6 Marks and gates correctly displaying from XML messages and mark(boat) position packets. Will need a little polishing but marks and gates are moving around.
#story[923] #pair[ajm412, ptg19]
2017-05-18 18:39:23 +12:00
Alistair McIntyre 5d6b356602 all marks displaying except currently gate marks are displaying as a single dot
#story[923] #pair[ajm412, ptg19]
2017-05-18 18:02:25 +12:00
Alistair McIntyre 08057edb28 Merge branch 'Issue#4_boat_movement' into issue#10_unifying_marks
# Conflicts:
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/mark/MarkGroup.java
2017-05-18 17:04:00 +12:00
Kusal Ekanayake 390aabc78f Adding race yacht series to the sparkline.
Next step is to make the series of the boats update when new position information is received.

#story[952]
2017-05-18 14:44:10 +12:00
William Muir a2123df0c5 Fixed Boat selection and lost annotations (Estimated and Leg Time)
Trails and Wakes, however,  are still not re implemented yet.

story[923]
2017-05-18 14:41:08 +12:00
Kusal Ekanayake b87008f590 Merge branch 'develop' into Story34_Sparklines 2017-05-18 13:22:51 +12:00
Kusal Ekanayake ecc0e722b5 Started sparkline prototype
#story[952]
2017-05-18 13:19:59 +12:00
Zhi You Tan 6f9a8e5581 Merge remote-tracking branch 'origin/develop' into issue#5_fix_pre-race_boats_on_leaderboard 2017-05-18 12:20:02 +12:00
Zhi You Tan b17bba3629 Fixed leaderboard on start screen and race view to show all boats correctly during pre-race.
#story[923]
2017-05-18 12:18:51 +12:00
Michael Rausch cf4d7e03f5 Merge branch 'issue#1_wakes_3.0' into 'develop'
Issue#1 wakes 3.0

Changed methods in the wake class to fix issues caused by unexpected velocities making the wakes go crazy.
Improved performance.
Made wakes look different.

See merge request !33
2017-05-18 11:45:28 +12:00
Michael Rausch 73eeeb0ef9 Removed extra print stmt and changed default server back to official 2017-05-18 11:45:06 +12:00
Peter Galloway 0f79353936 fixes from merge #story[923] 2017-05-17 20:15:47 +12:00
Peter Galloway 38b44fa92b Merge branch 'develop' into Issue#4_boat_movement
# Conflicts:
#	src/main/java/seng302/controllers/Controller.java
#	src/main/java/seng302/controllers/RaceController.java
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/mark/MarkGroup.java
#	src/main/java/seng302/models/stream/StreamParser.java
#	src/test/java/seng302/models/stream/StreamReceiverTest.java
2017-05-17 20:05:40 +12:00
alistairjmcintyre 3fd13ddc0a Adjusted XMLParser to use model Mark objects rather than the simple datatype that existed in the XMLParser previously. Began attempting to implement them into the canvas controller but have issues
#[issue10]
2017-05-17 19:46:05 +12:00
Peter Galloway 2e375978bd cleaned up code for merging back to develop #story[923] 2017-05-17 19:18:31 +12:00
Calum 45db731a60 Fixed a merge issue.
#story[923] #bug #refactor
2017-05-17 18:06:36 +12:00
Peter Galloway 95e353c14e fixed initialization bug #story[923] 2017-05-17 17:55:21 +12:00
Calum 8a3a41294a Fixed error causing build failure.
#story[923] #bug #refactor
2017-05-17 17:41:45 +12:00
Calum f41858e2c7 Tidied variable names. 2017-05-17 17:35:59 +12:00
Peter Galloway aaa3dc93f1 boat movement working reliably now, still need to fix one bug at initialization #story[923] 2017-05-17 17:34:47 +12:00
Calum e5eab0a6c8 Merge remote-tracking branch 'origin/develop' into issue#1_wakes_3.0
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/models/BoatGroup.java
2017-05-17 17:27:34 +12:00
Calum 7c39368126 Removed unnecessary constant 2017-05-17 17:23:10 +12:00
Calum ade926e2f2 StreamParser class now only shares thread safe classes.
#story[923] #bug
2017-05-17 16:44:05 +12:00
Calum c63c8e4d73 Stripped out excess code in Wake class. 2017-05-17 16:33:45 +12:00
Michael Rausch 3c418b2aa4 Changed boat location message to milliseconds 2017-05-17 14:57:31 +12:00
Michael Rausch d34a158c34 Merge branch '38a_Select_Boats' into 'develop'
38a select boats

Selection of boats now possible by selecting a boat from a drop down menu to focus that boat singularly or clicking a boat on the canvas to toggle that boats annotations.

Changed the annotations slider to remove the low annotation option. Only now includes None, Important and All. I think this makes much more sense.

Refactor of the race view controller class to combine all timelines for polling the Stream Parser to update race view data such as tables into one timeline for polling. In the future this should be improved further from polling to an observer model.

See merge request !31
2017-05-17 14:38:23 +12:00
Michael Rausch 6e3d037021 Merge branch 'develop' into 38a_Select_Boats 2017-05-17 14:34:10 +12:00
Zhi You Tan 7d160eaf54 Removed unused imports from controller.java 2017-05-17 13:16:00 +12:00
Peter Galloway 4fc99edbd6 Merge branch 'issue#14_split_start_screen_view&controller' into 'develop'
Split Start Screen out from Main View view and controller.

The start screen has its own view and controller now. Returned main view to its original function.

(This solves issue#14)

See merge request !32
2017-05-17 13:07:48 +12:00
Zhi You Tan 4da8c1645e Split Start Screen out from Main View view and controller.
#story[923]
2017-05-17 12:56:13 +12:00
William Muir 1c01aab1e7 Merge on to develop
story[955]
2017-05-17 10:34:00 +12:00
William Muir 6a85b0800f Merge on to develop
story[955]
2017-05-17 10:06:50 +12:00
William Muir 1acb0fbac4 Merge on to develop
story[955]
2017-05-17 10:04:28 +12:00
William Muir 2b294702a9 Merge remote-tracking branch 'origin/develop' into 38a_Select_Boats
# Conflicts:
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/BoatGroup.java
2017-05-17 09:53:18 +12:00
William Muir afd97d6e05 Reformating of code to google style.
#story[955]
2017-05-17 00:34:36 +12:00
William Muir 2d5a7a8a49 Large tidying of RaceViewController class. Fixing updating for combo boxes
#story[955]
2017-05-16 15:06:01 +12:00
Peter Galloway 9e3036e134 Stripped down the boatgroup to the basic movement components and then tried to adjust how position updates are being dealt with to make everything more logically understandable. I made some progress in terms of understanding but the position update is still not as reliable as I would like. I will be explaining to other team members how this part of the code is working so the time I have spent is not completely wasted #story[923] 2017-05-15 23:17:36 +12:00
Haoming Yin 8dec458ba9 Added methods to calculate optimal map size given a geo boundary.
- From zoom level 20 to 1, once find a size that contains the whole boundary, then the size will be used to retrieve map image from google

#story[928]
2017-05-15 19:57:23 +12:00
Michael Rausch da07d885da Merge branch 'Story47CourseLimits' into 'develop'
Story47 course limits

The idea was to have the course canvas update whenever we receive a new xml packet for the race data. Specifically for a few seconds after the race where the course boundaries change, going from a boundary which contains the start line to cutting off the start line as soon as the boats start.

See merge request !30
2017-05-15 18:43:49 +12:00
Michael Rausch a9de005e1a Removed a extraneous print stmt 2017-05-15 18:41:44 +12:00
Michael Rausch e03e121da4 Merge branch 'develop' into Story47CourseLimits
Conflicts:
	src/main/java/seng302/App.java
2017-05-15 18:37:31 +12:00
Peter Galloway fc3ca70e5d Merge branch 'issue#10_unifying_marks' into Issue#4_boat_movement
# Conflicts:
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/controllers/Controller.java
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/stream/StreamPacket.java
#	src/main/java/seng302/models/stream/StreamParser.java
2017-05-15 18:09:47 +12:00
Kusal Ekanayake 9c7144c918 Removed dud print statement
#story[889]
2017-05-15 17:55:06 +12:00
Peter Galloway ed8d70c3b3 commented out buffered code and cleaned up some other areas to try and make the boatgroup clear enough to modify #story[923] 2017-05-15 17:53:11 +12:00
Kusal Ekanayake fa501460cb Cleaned up code for merge.
#story[889]
2017-05-15 17:21:56 +12:00
Kusal Ekanayake 110143ae6e Added a dynamically updating course limits file to the model.
This will make manual testing of the course limits easier. When the race starts, the limits encapsulate the start line but soon after the race starts the course limits close off around the start line (this is for the model). This means the model acts in a very similar way to the actual live stream.

#story[889]
2017-05-15 17:09:12 +12:00
Haoming Yin eda3d76077 Added get map size (width and height) method in canvasMap with given boundary
#story[928]
2017-05-15 17:06:28 +12:00
William Muir 51f090324a CSS on annotation selection and minor bug fixes. Changed annotation slider to only have None, important and All
#story[955]
2017-05-15 16:44:28 +12:00
Michael Rausch 335540ff4a Merge branch 'story36_elapsed_time' into 'develop'
Story36 elapsed time

Implemented time elapsed since last mark on annotation

See merge request !29
2017-05-15 16:33:21 +12:00
Zhi You Tan 5fa47ff65b Implemented elapsed time since last mark on annotation.
#story[927]
2017-05-15 16:31:04 +12:00
Zhi You Tan 3a1c1a5e43 Merge remote-tracking branch 'origin/develop' into story36_elapsed_time
# Conflicts:
#	src/main/java/seng302/models/BoatGroup.java
2017-05-15 15:54:44 +12:00
Michael Rausch 4c7f530458 Merge branch 'story33_add_estimated_time_annotation' into 'develop'
Story33 add estimated time annotation

Added estimated time to next mark to annotation

See merge request !28
2017-05-15 15:50:46 +12:00
Zhi You Tan 2e914a7704 Fixed estimate time to next mark to match acceptance criteria which is countdown in minutes and seconds.
#story[924]
2017-05-15 15:49:21 +12:00
Calum 8fbb9d6d4e Added/improved documentation
#chore
2017-05-15 15:36:18 +12:00
Calum 23bc643c91 Removed some unused functions and imports caused by code refactor.
#chore
2017-05-15 15:20:21 +12:00
Calum c4fe116267 MarkGroups refactored to be independent of BoatGroups as their functionality has diverged.
#issue[10] #refactor
2017-05-15 15:17:54 +12:00
Kusal Ekanayake 081d7e3dcb Fixed the parsing of bytes being off by one byte in the stream parser fr the race status packet.
#story[924] #pair[kre39,zyt10]
2017-05-15 14:52:57 +12:00
William Muir 764ae37ce4 Gave the boatgroups a selection attribute, allowing them to be highlighted upon clicking
Boats can be clicked on canvas or from selection drop down on the side

#story[955]
2017-05-15 14:09:09 +12:00
Zhi You Tan e62a609b6b Prepared StreamParser.java, BoatGroup.java, Yacht.java for leg timer annotation (story 36)
#story[927]
2017-05-15 13:47:30 +12:00
Haoming Yin 4b1a4aae87 Added unit tests for Mercator projection class.
- changed its methods to static
- add some documentation for its methods

#story[928]
2017-05-15 13:23:04 +12:00
Peter Galloway ccda5f2a2e changing branch name #story[923] 2017-05-15 12:40:11 +12:00
Haoming Yin 3fd8b1b855 Created Mercator projection to convert between Geo location and planar projection point.
- MapGeo and MapPoint encapsulate geo location and planar projection point into classes.

#story[928]
2017-05-15 12:24:36 +12:00
Kusal Ekanayake 94d1982670 Shifted the canvas to the back of the window when updated.
This is to preserve the way the boats are still shown on the front when the course i reloaded.
As the main live stream has been down, this still needs to be tested.
2017-05-15 10:46:28 +12:00
Zhi You Tan 39efafc75f Fixed Annotation.java, ImportantAnnotationController.java, RaceViewController.java to include estimate time to next mark after merge
#story[924]
2017-05-15 10:36:20 +12:00
Kusal Ekanayake afe0c9f1a6 Merge branch 'develop' into Story47CourseLimits
# Conflicts:
#	src/main/resources/views/RaceView.fxml
2017-05-15 10:33:22 +12:00
Zhi You Tan 04b105d74b Merge branch 'develop' into story33_add_estimated_time_annotation
# Conflicts:
#	src/main/java/seng302/controllers/RaceViewController.java
2017-05-15 10:19:58 +12:00
Zhi You Tan 1ab6351d48 Fixed estimated time to next mark (annotation) to update correctly
#story[924]
2017-05-15 10:11:19 +12:00
Michael Rausch 9c348df5a5 Merge branch 'merge_request_test' into 'master'
Added .codeclimate.yml for static code analysis



See merge request !26
2017-05-15 01:28:57 +12:00
Peter Galloway 256ec046fc adjusted givePointsXY to try and use the marks from the XML parser, stopped partway as the marks from the XML parser and the standard marks need to be merged before this can be fixed properly #story[923] 2017-05-14 22:12:16 +12:00
Peter Galloway 85d4d63287 Merge branch 'story35_create_annotation_view' into 'develop'
Story35 create annotation view

## Addresses issue #9 and story 35

# Change Log
* Styled application using CSS (Issue #9)
* User can select to only show important annotations using the annotation slider
* Added view to select important annotations
* Important annotations are updated in real-time

# Testing
* Unit tests in test/java/seng302/visualizer/annotations/*
* Controllers have been tested manually

# Acceptance Criteria

* There is a mechanism to chose the ‘important’ annotations while viewing a race.

* Any number of annotations (from zero to the number of annotations) can be chosen.

* If the partial annotations toggle is active, choosing an annotation makes that annotation immediately visible for all boats, and deselecting an annotation should likewise remove it from all boats.

* When the partial annotations toggle becomes active, all annotations chosen as ‘important’, and only those annotations, should be shown.

See merge request !27
2017-05-14 22:00:02 +12:00
Michael Rausch 213d36ed56 Merge remote-tracking branch 'origin/develop' into story35_create_annotation_view 2017-05-14 21:05:48 +12:00
Michael Rausch ff6bfc9516 Important annotations are displayed correctly when updated.
- Important annotations can be selected, the live view updates in real time
- Change local time text colour to white
- Split the important annotations state into a separate class

Tags: #story[926]
2017-05-14 20:27:25 +12:00
Peter Galloway ae5678482b changed package "parsers" to be called "stream" #story[923] 2017-05-14 20:26:49 +12:00
Peter Galloway 63514cfafb deleted duplicated packet type class #story[923] 2017-05-14 20:20:14 +12:00
Peter Galloway 03ca60f2e1 deleted a whole bunch of legacy code, primarily the old controllers and old parsers #story[923] 2017-05-14 20:12:35 +12:00
Calum 89ef6e5277 Wake calculation now changed to be based off of the separation between wakes.
This allows wakes to auto correct their position better and stops the system reliance on "realistic data".
Wakes have several options for behaviour until the ideal settings are decided upon.
Note that MarkGroup position updating is currently disabled.

#implement #refactor #issue[1] #story[923]
2017-05-14 17:24:15 +12:00
Zhi You Tan 47880d09bc Implemented estimated time to next mark. Added checkbox for estimated time to next mark. To be fix: change from long to human readable time, update time every second
#story[923]
2017-05-12 20:04:09 +12:00
Zhi You Tan 5472765b95 Removed unused methods in RaceViewController.java
#story[923]
2017-05-12 18:24:28 +12:00
Zhi You Tan 14d975dce4 Fixed a bug where clicking "watch race" before race starts will cause boats to travel in unexpected ways.
#story[923]
2017-05-12 17:41:47 +12:00
Michael Rausch a23bdd0c53 Added functionality to select important annotations and ui changes
- Added CSS for the race view & welcome screen
- Added view to select important annotations
- Annotations are enabled/disabled when the user changes the important annotations

Tags: #story[926]
2017-05-11 21:44:56 +12:00
cir27 b0d8c3db0a Merge remote-tracking branch 'origin/develop' into develop 2017-05-11 16:40:50 +12:00
Kusal Ekanayake 4a75c062ce Making the course limits change when a new xml packet is received..
#story[889]
2017-05-11 15:49:49 +12:00
Michael Rausch fe90a3bf13 Merge branch 'master' into story35_create_annotation_view 2017-05-11 13:43:02 +12:00
Michael Rausch 711f6f4c45 Merge branch 'master' into develop 2017-05-11 13:29:51 +12:00
Haoming Yin 8fa7829a3c Created a canvas map class to fetch map image from google
- also added Bound class to encapsulate map boundary.
- created TestMapView and its controller just for testing.

#story[928]
2017-05-10 20:52:46 +12:00
Peter Galloway 6d7697a0eb commented out the problematic buffering functionality #story[923] 2017-05-10 13:58:10 +12:00
Michael Rausch cdd80af27b Added .codeclimate.yml for static code analysis 2017-05-10 11:56:18 +12:00
Zhi You Tan 2cb09b81f8 Updated .mailmap for everyone 2017-05-04 16:53:16 +12:00
Peter Galloway b529d621e9 changed course size to 720x720 2017-05-04 16:42:23 +12:00
William Muir 24667991f1 Merge on to master
Final Push
2017-05-04 14:39:29 +12:00
Zhi You Tan ac3f3bfd55 Added a check if race started, then start screen switches to race view automatically.
#story[572]
2017-05-04 14:32:06 +12:00
William Muir f2c4929656 Merge remote-tracking branch 'origin/master' 2017-05-04 14:22:49 +12:00
William Muir 4c038a823a Merge branch 'master' into develop
# Conflicts:
#	.mailmap
2017-05-04 14:22:20 +12:00
Alistair McIntyre 3080c1bf27 Merge remote-tracking branch 'origin/Story28_GetCorrectTimeZone' into develop
# Conflicts:
#	src/main/java/seng302/controllers/Controller.java
2017-05-04 14:15:05 +12:00
Alistair McIntyre 59809c39ea Began figuring out how to implement XML data in place of mock data.
#story[820] #pair[ajm412, wmu16]
2017-05-04 14:13:03 +12:00
Calum 9b063190ce Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop
# Conflicts:
#	src/test/java/seng302/models/MarkGroupTest.java
2017-05-04 14:04:52 +12:00
Calum 49f2398669 Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop 2017-05-04 14:01:32 +12:00
Calum d7a4d20ceb Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop
# Conflicts:
#	src/test/java/seng302/models/MarkGroupTest.java
2017-05-04 14:01:19 +12:00
Michael Rausch 0855e268c8 Removed another test that was causing failing due CI not having disply 2017-05-04 14:01:06 +12:00
Calum 49b8d75aea Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop
# Conflicts:
#	src/test/java/seng302/models/BoatGroupTest.java
2017-05-04 14:00:44 +12:00
Calum b1a9a7845b Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop
# Conflicts:
#	src/test/java/seng302/models/BoatGroupTest.java
2017-05-04 14:00:24 +12:00
Michael Rausch b1e749bafb Removed test that was failing due to CI not having a display 2017-05-04 13:59:44 +12:00
Michael Rausch f6fc6c0693 Merge remote-tracking branch 'origin/develop' into develop 2017-05-04 13:53:49 +12:00
Calum ad1371bce0 Commented out tests that were causing build failures.
Issue is related to tests failing to get the source code from our project needed to build. They run
fine when run from the IDE.
2017-05-04 13:52:47 +12:00
Michael Rausch e77df0a5dd Changed port number and added standalone flag
- can use -standalone to just run the server
- Changed port number as to not conflict with some web servers
2017-05-04 13:52:36 +12:00
Zhi You Tan 6935bd514e Reimplemented race position in the race view. Removed Boat class and Yacht class is replaced completely. Race position "-" shows properly on start screen. Removed BoatTest and TeamsParserTest. Fixed estimated time till finish on server.
#story[818]
2017-05-04 13:50:06 +12:00
Kusal Ekanayake a4cc5f222c Refactored course boundary to be a shade rather than a line and made the stream parser and stream receiver exit gracefully before the app closes.
#story[820]
2017-05-04 13:29:53 +12:00
Calum a0bb7b85b4 potential fix for build failures 2017-05-04 13:26:29 +12:00
Calum fd8ed92f88 Fix for wakes on internal data
#bug
2017-05-04 13:20:50 +12:00
Calum c7b6261602 Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop 2017-05-04 12:46:07 +12:00
Calum 3aefb14faf Added testing. 2017-05-04 12:46:01 +12:00
Michael Rausch 8521b68855 Server thread stops when window has been closed 2017-05-04 12:35:36 +12:00
Michael Rausch e37b244f45 Fixed a bug where boat statuses were being sent incorrectly
- Boats now have an estimated time until finish
- Boat packets are being sent correctly

Tags: #story[829]
2017-05-04 12:27:59 +12:00
Calum 7f40fb6283 Fixed bug left in last commit 2017-05-04 11:00:57 +12:00
Calum 83316f7a17 Merge branch 'develop' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into develop
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/controllers/Controller.java
2017-05-04 10:48:06 +12:00
Calum a56e55ae70 Fix for some movement on racestart issues
#bug
2017-05-04 10:38:04 +12:00
Zhi You Tan 07234ee33a Updated start screen team list to show position in race. Created Yacht class to replace Boat class. Removed Boat class from XMLParser. Removed unused BoatParser.java.
#story[572]
2017-05-04 04:16:16 +12:00
Michael Rausch 145d59df45 Removed unused imports 2017-05-04 01:18:41 +12:00
Michael Rausch 7e8c3af9ce Removed extra 'minutes' labels 2017-05-04 01:08:18 +12:00
Michael Rausch aa6ef72670 Merge remote-tracking branch 'origin/develop' into develop 2017-05-03 23:27:35 +12:00
Haoming Yin ed8781b382 Added method to check if a boat is finished the race or not.
- updated server if all boats finish the race, then start sending race finished message.
- race simulator will terminate if all boats finish the race, and prints log.

#story[715]
2017-05-03 22:44:25 +12:00
Michael Rausch 7a5f4e8f8c Removed minutes label from timestamp
Tags: #story[820]
2017-05-03 22:16:03 +12:00
Michael Rausch d992422efd Various bug fixes
- Made canvas fill entire screen
- Made window scale to screens that aren't 1920x1080
- Changed boat speeds in mock so they aren't too fast
- Added command line options to switch server

Tags: #story[829]
2017-05-03 21:56:51 +12:00
Haoming Yin f0d6312fa5 Fix bugs that server doesn't send boat location before and after the race.
- server will sends boat location not only during the race, but also before the race and after all boats have finished the race.
- refactored simulator so that it runs at the begining to send boat location, and if its "isStarted" set to true, then it starts moving the boats.

#story[715]
2017-05-02 22:51:35 +12:00
Zhi You Tan 772ece25a0 Implemented real time race clock on the start screen using data from stream.
#story[594]
2017-05-02 22:39:33 +12:00
Zhi You Tan d063a41ad4 Merge remote-tracking branch 'origin/wake_remake' into develop
# Conflicts:
#	src/main/java/seng302/App.java
2017-05-02 22:09:03 +12:00
William Muir 6d02f05f05 Quick change to stop adding course markers as they are dynamic and add them in the previous way 2017-05-02 21:51:04 +12:00
cir27 3a72409fb8 Merge remote-tracking branch 'origin/develop' into develop 2017-05-02 21:50:30 +12:00
William Muir b3a89279d6 Quick change to stop adding course markers as they are dynamic and add them in the previous way 2017-05-02 21:31:38 +12:00
William Muir 4432ba26e5 Merge remote-tracking branch 'origin/develop' into develop 2017-05-02 21:12:22 +12:00
William Muir fe824a8f71 Finished implementing drawing of border from XML
Border is drawn onto canvas, it is static.

#story[469]
2017-05-02 21:05:53 +12:00
Zhi You Tan 8233b75e05 Fixed the start screen team list after merging. Team list shows boats competing in event again.
#story[572]
2017-05-02 18:52:31 +12:00
Zhi You Tan 3af15b2b95 Updated wind direction on race view controller so it responds to the stream.
#story[818]
2017-05-02 18:02:44 +12:00
cir27 fd092bb7e1 Merge remote-tracking branch 'origin/develop' into develop
# Conflicts:
#	src/main/java/seng302/App.java
2017-05-02 16:41:49 +12:00
cir27 9c60521d00 Merge branch 'develop' of C:\Users\CJIRWIN\Documents\team-13 with conflicts. 2017-05-02 16:41:40 +12:00
Haoming Yin a4dfcca302 Fixed a boat bearing bug.
- server should send LastPastCorner's heading bearing, instead of headingCorner's bearing

#story[715]
2017-05-02 14:51:44 +12:00
Kusal Ekanayake 04ce6f6103 Removed white behind fps counter 2017-05-02 14:18:40 +12:00
Kusal Ekanayake 178af141f0 Refactoring and documentation
#story[820]
2017-05-02 14:08:25 +12:00
William Muir c5c2d4375d Changed the canvas controller to read marks from the XML as received from the server (PROTOTYPE)
Gates appear to draw in the correct places although a bit jittery for some reason

Boundary marks are a bit sporadic and still need lines drawn in between

Large refactor of canvas controller and XMLParser still required if these two are going to work together well. Currently canvas controller is a bit of a mess.

#story[469]
2017-05-01 23:10:15 +12:00
William Muir 3aa183042f Merge remote-tracking branch 'origin/wake_remake' into wake_remake 2017-05-01 22:00:15 +12:00
William Muir 944755fde1 Merge branch 'wake_remake' of /home/cosc/student/wmu16/Documents/300/SENG302/team-13 with conflicts. 2017-05-01 22:00:12 +12:00
Peter cd78c35bf6 Merge remote-tracking branch 'origin/wake_remake' into wake_remake 2017-05-01 20:37:58 +12:00
Peter Galloway f8d003002b fixing error from merge #story[820] 2017-05-01 20:37:46 +12:00
Peter Galloway 56fab768f3 fixing error from merge #story[820] 2017-05-01 20:37:26 +12:00
Peter Galloway c92744f21c Merge branch 'wake_remake' into develop 2017-05-01 20:35:15 +12:00
Peter Galloway 1f71fd1967 Merge branch 'wake_remake' into Story30b_correcting_boat_movement
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/RaceObject.java
#	src/main/java/seng302/models/mark/MarkGroup.java
#	src/main/java/seng302/models/parsers/StreamParser.java
2017-05-01 20:33:09 +12:00
Peter Galloway 33ae7beeb4 merging with wake remake #story[820] 2017-05-01 20:09:51 +12:00
Peter Galloway 130efa3a51 Merge branch 'wake_remake' into Story30b_correcting_boat_movement
# Conflicts:
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/parsers/StreamParser.java
2017-05-01 19:09:09 +12:00
Peter Galloway 7df55fc1a3 problems appear to be fixed and the boats are updating properly from the timeValid field of the boat location. #story[820] 2017-05-01 18:55:21 +12:00
Zhi You Tan 3adadcc1e1 Updated the timer to show two decimals for the seconds.
#story[572]
2017-05-01 18:49:58 +12:00
Kusal Ekanayake 5b027a29d8 Merge remote-tracking branch 'origin/wake_remake' into wake_remake 2017-05-01 18:35:56 +12:00
Kusal Ekanayake 2a9d0fb82c Removed 2 bad import statements that halted the build form building. 2017-05-01 18:35:48 +12:00
Zhi You Tan ee6a543f8d Fixed timer separator instead of dot to semicolon, and fixed the timer position in race canvas, and updated the start screen so it does not grow vertically
#story[572]
2017-05-01 18:35:17 +12:00
Kusal Ekanayake d927531354 Removed broken time extracting method and replaced it with currently existing long extractor. Added speed to the setDestination method for the raceObject abstract class.
#story[820]
2017-05-01 18:22:08 +12:00
Haoming Yin 1d47df09eb Merge branch 'merge_branch_front' into wake_remake
# Conflicts:
#	src/main/java/seng302/App.java
2017-05-01 17:46:16 +12:00
Haoming Yin a9709c4f84 Merged the mock server to visualisation.
#story[715] #story[716]
2017-05-01 17:42:07 +12:00
Alistair McIntyre a06806c42d Merge remote-tracking branch 'origin/wake_remake' into wake_remake 2017-05-01 17:35:51 +12:00
Alistair McIntyre 57de058582 Began figuring out how to implement XML data in place of mock data.
#story[820] #pair[ajm412, wmu16]
2017-05-01 17:35:39 +12:00
Haoming Yin 978493853d Merge branch 'Story29' into merge_branch_front
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/controllers/Controller.java
#	src/main/java/seng302/controllers/RaceViewController.java
#	src/main/java/seng302/models/Boat.java
#	src/main/java/seng302/models/Colors.java
#	src/main/java/seng302/models/Event.java
#	src/main/java/seng302/models/Race.java
#	src/main/java/seng302/models/mark/GateMark.java
#	src/main/java/seng302/models/mark/Mark.java
#	src/main/java/seng302/models/mark/MarkType.java
#	src/main/java/seng302/models/mark/SingleMark.java
#	src/main/java/seng302/models/parsers/CourseParser.java
#	src/main/java/seng302/models/parsers/TeamsParser.java
#	src/main/resources/views/MainView.fxml
#	src/main/resources/views/RaceView.fxml
#	src/test/java/seng302/BoatTest.java
#	src/test/java/seng302/ColorsTest.java
#	src/test/java/seng302/EventTest.java
#	src/test/java/seng302/models/mark/MarkTest.java
#	src/test/java/seng302/models/parsers/CourseParserTest.java
2017-05-01 17:06:17 +12:00
Peter Galloway a5ca9218da Discovered the time valid timestamp in the boat location packet is quite inconsistent and either the stream or my implementation is making the display really buggy. Because the way it was before I changed things is more reliable at the moment, I have decided to wait until our mock stream is merged before continuing this development. #story[820] 2017-05-01 16:56:53 +12:00
Kusal Ekanayake 5fe330bfbb Boat trials and wakes now work with both fast and slow data sets.
Instead of fixed, hard coded thresholds and scale factors dynamically changing values
that scale with the onscreen movement are used to determine how graphical objects
are drawn.

#implement #story[816]
2017-05-01 16:41:58 +12:00
Zhi You Tan c80cff87f7 Updated import statements after merge 2017-05-01 16:02:09 +12:00
Zhi You Tan 9a864cc2bd Merge remote-tracking branch 'origin/Mark_to_MarkGroup' into wake_remake
# Conflicts:
#	src/main/java/seng302/App.java
#	src/main/java/seng302/controllers/Controller.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/Wake.java
#	src/main/java/seng302/models/parsers/StreamParser.java
#	src/main/resources/views/MainView.fxml
2017-05-01 15:59:14 +12:00
Alistair McIntyre c07f13180f Merged Story 30b branch into 30c branch
#story[820]
2017-05-01 15:32:23 +12:00
Alistair McIntyre f672eafd6d Merge remote-tracking branch 'origin/Story30A_InputStreamCheckingHead' into wake_remake
# Conflicts:
#	src/main/java/seng302/models/parsers/StreamPacket.java
#	src/main/java/seng302/models/parsers/StreamParser.java
#	src/main/java/seng302/models/parsers/StreamReceiver.java
2017-05-01 15:27:51 +12:00
Calum 6a361c0d4b Documented some RaceObject classes.
#documentation
2017-05-01 14:30:41 +12:00
alistairjmcintyre b597f010dc Added some missing fields. Added missing getters.
#story[820]
2017-05-01 00:36:10 +12:00
Michael Rausch a670f677e9 Added other email to .mailmap 2017-05-01 00:10:07 +12:00
Michael Rausch a77423b937 Added other email to .mailmap 2017-05-01 00:07:56 +12:00
Michael Rausch 50083a9297 Added tests for reverse and intToBytes
#story[829]
2017-04-30 23:54:32 +12:00
Michael Rausch d5aa430d4a Fixed a method that was converting the timestamp bytes incorrectly
- If an argument is passed to the application, it will use the internal mock server
Tags: #story[820]
2017-04-30 23:41:21 +12:00
Michael Rausch e7f9954970 Removed unneeded files, also fixed heading calculation
Tags #story[829]
2017-04-30 23:29:15 +12:00
William Muir ec57851de2 Created annotation slider to display different levels of annotations
Removed toggleAnnotations method as abstract from race object and made only for boat group as it didnt make sense for markgroup, at least not currently as they have no annotations to show

#story[558]
2017-04-30 23:24:24 +12:00
Calum 0eb767b615 Finished tweaking wakes. Made marker movement smooth.
#implement #story[818]
2017-04-30 22:34:49 +12:00
Calum 45b77c05d4 Improvements to wake 2017-04-30 19:32:29 +12:00
Calum b9900925b8 Fixing wakes, bug caused by attempting to fix a issue with jittery boats actually caused by parser.
#bug
2017-04-30 19:00:07 +12:00
cir27 d94290c58d Merge branch 'Mark_to_MarkGroup' of https://eng-git.canterbury.ac.nz/seng302-2017/team-13 into Mark_to_MarkGroup 2017-04-30 18:15:24 +12:00
cir27 f50aabff7b Documentation added to graphics classes.
#document
2017-04-30 18:15:16 +12:00
Michael Rausch d07c660eb9 Merge remote-tracking branch 'origin/Story29' into Story29 2017-04-30 17:47:05 +12:00
Michael Rausch 6491efec4c Fixed race status sent in race status messages
#story[829]
2017-04-30 17:46:56 +12:00
Zhi You Tan 25038da2a1 Created BoatsParser.java to parse boats from server boat.xml and created a table on the start screen to display all the teams from server
#story[572]
2017-04-30 17:17:47 +12:00
William Muir 85f461c88c Fixed bug so XML messages are located and sent properly on the server
Imported appache commons to read inputstream to a bytearray

#story[829]
2017-04-30 17:08:06 +12:00
Michael Rausch 1cf55f3e96 Fixed an issue where buffers aren't being sent properly
Tags #Story[829]
2017-04-30 16:16:44 +12:00
Michael Rausch 9a995ddcc1 Boat status changes to finished when a boat finishes the race
Tags: #story[829]
2017-04-30 01:55:49 +12:00
alistairjmcintyre 0b2ef3de00 XML data types are done. Easily navigated for future use. Some documentation has been done, tests aren't yet completed just yet.
#story[820]
2017-04-30 00:52:18 +12:00
Peter 99e50aa7ac Merge remote-tracking branch 'origin/Story30b_correcting_boat_movement' into Story30b_correcting_boat_movement 2017-04-29 20:21:49 +12:00
Peter Galloway a898290c0b partway through fixing boat movement to be updated from the data valid timestamp rather than the data sent timestamp #pair[kre39, ptg19] #story[820] 2017-04-29 20:21:26 +12:00
Kusal Ekanayake 6cbff1097b Fixed error'd tests which were based off old xml data. 2017-04-29 20:16:14 +12:00
Peter Galloway 246083460e partway through fixing boat movement to be updated from the data valid timestamp rather than the data sent timestamp #story[820] 2017-04-29 20:13:34 +12:00
Kusal Ekanayake 1d28334346 Removed the parser from queing packets incorrectly. Used the marker boat location packets to get the live updates of the marker positions and implemented the markers being updated much like the boats currently are. This means the course more closely resembles the actual intended course design.
#story[820]
2017-04-29 20:10:39 +12:00
Michael Rausch 3e97f016d5 Getting boat locations from race simulator & bug fixes
- Boat locations that are generated by the simulator are sent to the client as they happen
- Fixed heading and lat/lon encoding
- Fixed a bug where the header wasn't included in the sent byte stream
- Fixed the format of data as it's sent to the client.
- Data is now sent using a channel
- Removed tests that don't work with channels

Tags: #story[829]
2017-04-29 19:38:21 +12:00
Alistair McIntyre ab0d4634d6 Moved XML parsing to non static class to create objects. Changed the abstraction as using generics in maps lead to more headaches than anything. Still not quite completed. Needs documentation and validation for tags too.
#story[820]
2017-04-29 19:02:30 +12:00
Peter Galloway 1e1e482b79 Added a delay for reading packets from the packet buffer so packets that are recieved out of order have time to order by timestamp in the priority queue #story[820] 2017-04-29 18:56:41 +12:00
cir27 a0624cfef6 Merge branch 'wake_remake' into Mark_to_MarkGroup
# Conflicts:
#	src/main/java/seng302/controllers/CanvasController.java
#	src/main/java/seng302/models/BoatGroup.java
#	src/main/java/seng302/models/Wake.java
#	src/main/java/seng302/models/parsers/StreamParser.java
#	src/main/resources/views/RaceView.fxml
2017-04-29 14:29:12 +12:00
cir27 02a35b4c02 Reduced the cost of updating wakes. Improved the logic for controlling indices.
#implement #story[820]
2017-04-29 14:20:52 +12:00
cir27 80409c08a6 Removed a graphical object added for testing. 2017-04-29 02:17:55 +12:00
cir27 6149f7be60 Wakes no longer become out of sync with boats after extended periods of time. Added in
a limit to the length of boat trails.

#implement
2017-04-29 02:14:55 +12:00
Calum 474f0ee427 Further work on new wake system. Wakes turn correctly but need to scale with velocity and
eventually desync with the boats. Needs to reset to the boats position on straights.
2017-04-28 23:25:49 +12:00
Zhi You Tan f3ee618900 Fixed broken race timer and timer now using stream timer data.
#story[818]
2017-04-28 21:44:23 +12:00
Zhi You Tan b939086e10 Updated welcome screen to show if race is finished or starting
#story[572]
2017-04-28 21:28:34 +12:00
Zhi You Tan ffdfc24e65 Created a start screen with a timer which shows the race progress
#story[572]
2017-04-28 20:09:17 +12:00
Peter Galloway 07bbd7e06d Added reasonable testing for StreamReciever, further testing would probably need StreamReciever to be rewritten #story[817] 2017-04-28 18:29:35 +12:00
Calum 765f27f987 Starting new wake implementation. 2017-04-28 17:08:08 +12:00
Kusal Ekanayake d204bee55d Started documentation on the stream parser.
#story[820]
2017-04-28 17:01:28 +12:00
Kusal Ekanayake 0f4ad48de0 Fixed and enables the old wakes. Enabled the fps counter by implementing the team-27s fps counter from their code, fixed trails from starting at the start of the startline no matter at what point in the race the stream is connected to (this is means the map starts a lot cleaner). Added live tracked speeds which are taken from the boat location packet. Linked the speeds coming in to their specified boats and allowed the onscreen speed tracker to keep up with the speeds. Linked the current speeds to the wakes so the wakes are redrawn for each change in speed and size to match the speed. Also added the toggle functionality back to the fps counter so they can be toggled on an off.
#story[818]
2017-04-28 16:41:35 +12:00
Alistair McIntyre fe480d5cb6 Finished parsing the Race XML data. Began making some optimizations to hopefully make parsing the Boat Data a quicker and simpler task.
#story[820]
2017-04-28 15:41:12 +12:00
Haoming Yin 8a04a0e5b7 Added documents for Boat, RaceParser and Simulator classes.
#story[828]
2017-04-28 14:53:26 +12:00
Haoming Yin 705a0a2eaf Added document and unit tests for GeoUtility class.
- three methods in GeoUtility have been tested and passed.

#story[828]
2017-04-28 14:34:24 +12:00
Kusal Ekanayake d1289b0de1 Fixed boats moving in the correct heading as according to the stream and attempted to fix the wakes direction.
#story[818]
2017-04-27 18:52:37 +12:00
Alistair McIntyre e1de5e0989 Parsed more course data from XML messages
#story[820]
2017-04-27 18:31:13 +12:00
Alistair McIntyre f5b9160304 Started parsing the different types of XML messages to Map objects so that we can extract the relevant data for the visualizer.
#story[820]
2017-04-27 17:22:46 +12:00
Kusal Ekanayake 0a22812165 Got the live ac35 data working in paralell with the parse and the app. Boats move and the live data works correctly. We need to fix the markers now
#story[818]
2017-04-27 16:18:33 +12:00
Kusal Ekanayake 104fd86179 Got the live ac35 data working in paralell with the parse and the app.
#story[820]
2017-04-27 14:40:26 +12:00
Calum 67a702ffcd Wakes still broken. Implemented dashed lines that track the progress of individual boats.
#implement #story[483]
2017-04-27 13:57:19 +12:00
Calum 65c0e6f77d Fixed markergroup bugs. Improved wakes. Still WIP 2017-04-27 11:58:50 +12:00
cir27 245bd184b4 Mark drawing moved to MarkGroup class. RaceObject and it's sub classes now describe
all functionality required for a on screen object. Improved wakes. Branch currently
untested.

#story[812, 820] #refactor #implement.
2017-04-27 02:44:25 +12:00
Haoming Yin 8c8f253233 Created simulator to generate mock data.
- simulator runs as a background thread and sleep for a given time lapse.
- simulator extends observable, so it can notify all its observers when boats positions have been updated

#story[828]
2017-04-26 22:58:13 +12:00
Haoming Yin 8b8422de3a Renamed course parser to race parser
- because in AC35 spec. race xml file contain course set up and all other general race settings

#story[828]
2017-04-26 22:52:18 +12:00
Haoming Yin 7bf2d4c40e Added Position class to better use GeoUtility.
- mark now inherit from Position

#story[828]
2017-04-26 22:52:18 +12:00
Haoming Yin 2a67f04d15 Create GeoUtility to process all geo calculations.
- calculate distance between two geo positions
- calculate the bearing from one geo position to another
- calculate the new geo position by passing original position, bearing and
distance

#story[828]
2017-04-26 22:52:18 +12:00
Haoming Yin b2ea8196d5 Fixed a bug of getCourse method as it didn't parse xml correctly.
- a typo 'CompoundmarkID'(should be 'CompoundMarkID') which caused parser failed to parse file.
- add typeOf method in RoundingType to convert strings to types

#story[828]
2017-04-26 22:52:18 +12:00
Haoming Yin 7f38191d03 Rewrote course parser to parse race xml file specified in AC35 spec.
#story[828]
2017-04-26 22:52:18 +12:00
Haoming Yin f6b7a3042f Rewrote all kind of marks to fit marks specified in AC35 spec.
- added compound mark
- added corner
- rewrote mark as a single mark
- added rounding type enum

#story[828]
2017-04-26 22:52:18 +12:00
Haoming Yin 3bdc6ce5cc Created a new course parser to parse race xml file specified in AC35 spec.
#story[828]
2017-04-26 22:52:18 +12:00
Michael Rausch bc31987f96 Added Boat location messages to the mock streaming data interface
- Added static methods to convert between binary packed lat/longs and floating point numbers

Tags: #story[829]
2017-04-26 22:38:39 +12:00
cir27 eaff4c5aac Added abstract class for all javafx object that a displayed during race. Began refactoring of mark implementation to be a subclass of the aforementioned abstract class. 2017-04-26 21:16:22 +12:00
Calum 95bafdc0d1 Fixed bug which caused boats to all travel to the same position. 2017-04-26 19:19:03 +12:00
Kusal Ekanayake c776d22941 Linking up course stream with visualiser. Boats moving, and course drawing. Boats however are not moving as intended. Needs to be fixed/looked into.
#story[820] #pair[kre39,cir27]
2017-04-26 18:45:58 +12:00
Calum 749c6b7fef Fixed bugs caused by horizontally scaling maps 2017-04-26 17:18:33 +12:00
Kusal Ekanayake 912c081606 Added marks with the test data coords to the xml
#story[820]
2017-04-26 15:55:51 +12:00
Kusal Ekanayake c73bf7dd3e Started merging received packets from the sample stream and reading lats and lons to move boats from them.
#story[820]
2017-04-26 15:51:15 +12:00
Kusal Ekanayake a3ae015be8 Merge remote-tracking branch 'origin/30b/30c_boat_animation' into StreamReceiverMergeWithVisualiser 2017-04-26 15:06:55 +12:00
Michael Rausch 1f8f1f0f86 Added boat location, and race start messages to the mock data interface
- Added proper support for signed and unsigned types. This includes automatic conversion to the correct data type (long to int, short, or byte).

- Moved code related to adding values into the byte buffer into the abstract Message class

Tags: #story[29]
2017-04-25 21:49:51 +12:00
Kusal Ekanayake 5eebab2748 Completed data extractors for: heartbeat, racestatus, display text msg, race start status, yacht event code, yacht action acode, chatter text, boat location, mark rounding, course wind and average wind. Some of the methods need to be validated but others have been tested. Will now need to link the parses with the model.
#story[820]
2017-04-25 17:57:22 +12:00
Alistair McIntyre 8cbd1cc4aa Added support to import XML packet to XML Document object.
#story[820]
2017-04-25 17:38:26 +12:00
Kusal Ekanayake 00c1a89f58 Fixed error in the switch (missing breaks)
#story[820]
2017-04-25 15:39:28 +12:00
Kusal Ekanayake d51825ffb7 Created separate streams for each different data type to be parsed into so the exact needed data would be able to be extracted.
#story[820]
2017-04-25 15:32:04 +12:00
cir27 42569e6ad7 Changed BoatPolygon is now a group instead of a polygon and is called BoatGroup.
BoatPolygon's functionality was more maintainable and scalable by having it extend Group.

 #story30c
2017-04-25 04:30:44 +12:00
cir27 ef874b4245 Added a transition time to rotational movement.
The aim is to make animations smoother when the boat turns. Unsure if current
 implementation will look good without testing on a datastream.

 #story30c
2017-04-25 03:12:30 +12:00
Calum 46037b5aea Refactored Boat class to better fit the MVC model by moving all GUI parts to BoatPolygon. Changed the way animation works so that it will work with a constantly updated set of lats and lons.
TODO - Change Mark class to no longer store XY pixel data.
TODO - Add in a timer force updates boat position if a packet has not been recieved for a while.

#story30b #story30c #implement #refactor
2017-04-24 23:06:30 +12:00
Michael Rausch 6874f288ee Added Race Status messages to the mock streaming data interface
Tags: #story[29]
2017-04-24 21:53:42 +12:00
Zhi You Tan b6fd90e9d7 Updated .mailmap for Zhi You Tan's information 2017-04-24 18:33:06 +12:00
Peter Galloway f078c34bf9 the stream receiver can now be passed a threadsafe priorityQueue that it will add the packets to as they are received (note the priority queue passed should be initialized with a comparitor for "StreamPacket"s) #story[817] 2017-04-24 18:29:50 +12:00
Peter Galloway c1e4a6156c re-engineered stream receiver to make it cleaner and ready to be used with the rest of the program. #story[817] 2017-04-24 17:38:29 +12:00
Kusal Ekanayake 71e14259f6 Started looking into boat location packets, am able to extract the lats an lons but needs validations. Can also see the device type, timestamp, and sequence number. Code needs to be cleaned up and will need to start looking into the set up packets, specifically the packets containing xml data so the course can be created.
#story[820]
2017-04-24 16:47:41 +12:00
Kusal Ekanayake 403dc480c4 Created packet enum to class packets and started progress on how the packets are read and parsed according to the type of packet.
#story[820]
2017-04-24 15:50:21 +12:00
Kusal Ekanayake 3dc1a7f9c0 StreamPacket class created so that we can store all packets generically. The timestamp has also been extracted and stored with the packet so that in the future we may turn the current ArrayList into a priority que.
#story[817]
2017-04-23 20:14:41 +12:00
Peter Galloway 672194adb4 changed Peter Galloway's name to specified format 2017-04-23 19:04:45 +12:00
Haoming Yin fdb84b6675 Update .mailmap for Haoming Yin's information. 2017-04-23 18:51:36 +12:00
Peter ba352183bf added functionality to check the CRC for the packet. I ran into a lot of trouble with this regarding everything in java being signed by twos compliment #story[817] 2017-04-23 16:53:35 +12:00
Kusal Ekanayake dd480080c9 Updated .mailmap to have the correct username for Kusal Ekanayake. 2017-04-23 14:57:26 +12:00
kre39 4047978ea2 Renamed file to match its functionality more accurately .
#story[30a]
2017-04-23 14:43:18 +12:00
kre39 a649b11bbf Reading relevant information (boats and race related info) from the stream so it can be moved to a parse and turned into objects for the actual race.
#story[30a]
2017-04-23 14:42:10 +12:00
Peter 247560ee43 converted prototype to be reading the stream byte by byte rather than by lines and characters which was very confusing and unreliable. currently extracting message type and payload length. #story[817] 2017-04-22 16:39:03 +12:00
Kusal Ekanayake 50e7ece477 Checking for the header of each packet as the stream parser checks for each byte to see if it matches with the desired header sequence. 2017-04-20 19:17:12 +12:00
Calum b5129c5c80 Moved the canvas drawing implementation from team27's codebase to team13's.
#story30b
2017-04-20 19:06:32 +12:00
Alistair McIntyre 6a27dedd74 Simple test to get stream data 2017-04-20 15:08:50 +12:00
Michael Rausch edc306da22 Created AC35 Streaming server
- Sends heartbeat messages every 5 seconds
- Sends XML at beginning

Tags: #story[29]
2017-04-19 19:05:19 +12:00
Kusal Ekanayake 15ded667fe Started to implement the group over the canvas in the code. Removed basic boat redrawing and timeline and replaced with boats being placed into a group and given coordinates. 2017-04-11 17:46:02 +12:00
William Muir 34872a822b Stripped back codebase to make to create basic model for streaming data
Removed many classes involved with visualisation such as controllers and multiple fxmls. Now there is just one for debugging

Merged in Boat updating pattern from team 27

#story[828]
2017-04-08 17:49:50 +12:00
Michael Rausch 9817fc9093 Fixed JavaDoc errors by adding missing @params 2017-04-04 19:29:05 +12:00
Michael Rausch dde4b2fcba gitlab ci test (passing) 2017-04-04 19:15:41 +12:00
Michael Rausch 623600a8a9 gitlab ci test (failing) 2017-04-04 19:15:01 +12:00
Michael Rausch bff4986242 Gitlab CI Build Test 2017-04-04 19:10:01 +12:00
Michael Rausch c689530068 Gitlab CI Build Test 2017-04-04 19:03:45 +12:00
115 changed files with 8569 additions and 1780 deletions
+17
View File
@@ -0,0 +1,17 @@
engines:
pmd:
enabled: true
channel: "beta"
fixme:
enabled: true
config:
strings:
- FIXME
- TODO
- BUG
- FIX
ratings:
paths:
- "**.java"
+8
View File
@@ -17,3 +17,11 @@
# http://stacktoheap.com/blog/2013/01/06/using-mailmap-to-fix-authors-list-in-git/ # http://stacktoheap.com/blog/2013/01/06/using-mailmap-to-fix-authors-list-in-git/
Michael Rausch <mra106@uclive.ac.nz> <me@michaelrausch.nz> Michael Rausch <mra106@uclive.ac.nz> <me@michaelrausch.nz>
Michael Rausch <mra106@uclive.ac.nz> <michael@michaelrausch.net>
Kusal Ekanayake <kre39@uclive.ac.nz> kre39 <kre39@uclive.ac.nz>
Haoming Yin <hyi25@uclive.ac.nz> <haoming.y@icloud.com>
Peter Galloway <ptg19@uclive.ac.nz> Peter <ptg19@uclive.ac.nz>
Zhi You Tan <zyt10@uclive.ac.nz> zyt10 <zyt10@uclive.ac.nz>
Zhi You Tan <zyt10@uclive.ac.nz> Ryan Tan <ryan_zhiyou@hotmail.com>
Alistair McIntyre <ajm412@uclive.ac.nz> alistairjmcintyre <alistairjmcintyre@gmail.com>
Calum <cir27@uclive.ac.nz> cir27 <cir27@uclive.ac.nz>
+5
View File
@@ -20,6 +20,11 @@
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency> <dependency>
<groupId>com.googlecode.json-simple</groupId> <groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
+64 -3
View File
@@ -5,20 +5,81 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import seng302.models.PolarTable;
import seng302.models.stream.StreamParser;
import seng302.models.stream.StreamReceiver;
import seng302.server.ServerThread;
public class App extends Application {
public class App extends Application
{
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
PolarTable.parsePolarFile(getClass().getResource("/config/acc_polars.csv").getFile());
Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml")); Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml"));
primaryStage.setTitle("RaceVision"); primaryStage.setTitle("RaceVision");
primaryStage.setScene(new Scene(root)); primaryStage.setScene(new Scene(root, 1530, 960));
primaryStage.setMaxWidth(1530);
primaryStage.setMaxHeight(960);
// primaryStage.setMaximized(true);
primaryStage.show(); primaryStage.show();
primaryStage.setOnCloseRequest(e -> {
StreamParser.appClose();
StreamReceiver.noMoreBytes();
System.exit(0);
});
} }
public static void main(String[] args) { public static void main(String[] args) {
StreamReceiver sr = null;
new ServerThread("Racevision Test Server");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (args.length == 1 && args[0].equals("-standalone")) {
return;
}
if (args.length == 3 && args[0].equals("-server")) {
sr = new StreamReceiver(args[1], Integer.valueOf(args[2]), "RaceStream");
} else if (args.length == 2 && args[0].equals("-server")) {
switch (args[1]) {
case "internal":
sr = new StreamReceiver("localhost", 4949, "RaceStream");
break;
case "staffserver":
sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
break;
case "official":
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
break;
}
}
//Change the StreamReceiver in this else block to change the default data source.
else{
// sr = new StreamReceiver("localhost", 4949, "RaceStream");
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4942, "RaceStream");
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
}
sr.start();
StreamParser streamParser = new StreamParser("StreamParser");
streamParser.start();
launch(args); launch(args);
} }
} }
+63
View File
@@ -0,0 +1,63 @@
package seng302;
import javafx.geometry.Point2D;
/**
* A Class for performing geometric calculations on the canvas
* Created by wmu16 on 24/05/17.
*/
public final class GeometryUtils {
/**
* Performs the line function on two points of a line and a test point to test which side of the line that point is
* on. If the return value is
* return 1, then the point is on one side of the line,
* return -1 then the point is on the other side of the line
* return 0 then the point is exactly on the line.
* @param linePoint1 One point of the line
* @param linePoint2 Second point of the line
* @param testPoint The point to test with this line
* @return A return value indicating which side of the line the point is on
*/
public static Integer lineFunction(Point2D linePoint1, Point2D linePoint2, Point2D testPoint) {
Double x = testPoint.getX();
Double y = testPoint.getY();
Double x1 = linePoint1.getX();
Double y1 = linePoint1.getY();
Double x2 = linePoint2.getX();
Double y2 = linePoint2.getY();
Double result = (x - x1)*(y2 - y1) - (y - y1)*(x2 - x1); //Line function
if (result > 0) {
return 1;
}
else if (result < 0) {
return -1;
}
else {
return 0;
}
}
/**
* Given a point and a vector (angle and vector length) Will create a new point, that vector away from the origin
* point
* @param originPoint The point with which to use as the base for our vector addition
* @param angleInDeg (DEGREES) The angle at which our new point is being created (in degrees!)
* @param vectorLength The length out on this angle from the origin point to create the new point
* @return a Point2D
*/
public static Point2D makeArbitraryVectorPoint(Point2D originPoint, Double angleInDeg, Double vectorLength) {
Double endPointX = originPoint.getX() + vectorLength * Math.cos(Math.toRadians(angleInDeg));
Double endPointY = originPoint.getY() + vectorLength * Math.sin(Math.toRadians(angleInDeg));
return new Point2D(endPointX, endPointY);
}
}
@@ -1,20 +1,35 @@
package seng302.controllers; package seng302.controllers;
import javafx.animation.*; import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import seng302.models.Boat; import seng302.models.BoatGroup;
import seng302.models.TimelineInfo; import seng302.models.Colors;
import seng302.models.mark.GateMark; import seng302.models.Yacht;
import seng302.models.mark.Mark; import seng302.models.map.Boundary;
import seng302.models.mark.MarkType; import seng302.models.map.CanvasMap;
import seng302.models.mark.SingleMark; import seng302.models.mark.*;
import seng302.models.stream.StreamParser;
import seng302.models.stream.XMLParser;
import seng302.models.stream.XMLParser.RaceXMLObject.Limit;
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
import seng302.models.stream.packets.BoatPositionPacket;
import seng302.server.simulator.GeoUtility;
import seng302.server.simulator.mark.Position;
import java.util.*; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue;
/** /**
* Created by ptg19 on 15/03/17. * Created by ptg19 on 15/03/17.
@@ -27,66 +42,278 @@ public class CanvasController {
private RaceViewController raceViewController; private RaceViewController raceViewController;
private ResizableCanvas canvas; private ResizableCanvas canvas;
private Group group;
private GraphicsContext gc; private GraphicsContext gc;
private ImageView mapImage;
private final double ORIGIN_LAT = 32.321504; private final int BUFFER_SIZE = 50;
private final double ORIGIN_LON = -64.857063; private final int PANEL_WIDTH = 1260; // it should be 1280 but, minors 40 to cancel the bias.
private final int SCALE = 16000; private final int PANEL_HEIGHT = 960;
private final int CANVAS_WIDTH = 720;
private final int CANVAS_HEIGHT = 720;
private boolean horizontalInversion = false;
private double distanceScaleFactor;
private ScaleDirection scaleDirection;
private Mark minLatPoint;
private Mark minLonPoint;
private Mark maxLatPoint;
private Mark maxLonPoint;
private double referencePointX;
private double referencePointY;
private double metersPerPixelX;
private double metersPerPixelY;
private List<MarkGroup> markGroups = new ArrayList<>();
private List<BoatGroup> boatGroups = new ArrayList<>();
//FRAME RATE
private Double frameRate = 60.0;
private final long[] frameTimes = new long[30];
private int frameTimeIndex = 0;
private boolean arrayFilled = false;
public AnimationTimer timer;
private enum ScaleDirection {
HORIZONTAL,
VERTICAL
}
public void setup(RaceViewController raceViewController){ public void setup(RaceViewController raceViewController){
this.raceViewController = raceViewController; this.raceViewController = raceViewController;
} }
public void initialize() { public void initialize() {
raceViewController = new RaceViewController();
canvas = new ResizableCanvas(); canvas = new ResizableCanvas();
group = new Group();
// create image view for map, bind panel size to image
mapImage = new ImageView();
canvasPane.getChildren().add(mapImage);
mapImage.fitWidthProperty().bind(canvasPane.widthProperty());
mapImage.fitHeightProperty().bind(canvasPane.heightProperty());
canvasPane.getChildren().add(canvas); canvasPane.getChildren().add(canvas);
canvasPane.getChildren().add(group);
// Bind canvas size to stack pane size. // Bind canvas size to stack pane size.
canvas.widthProperty().bind(canvasPane.widthProperty()); canvas.widthProperty().bind(new SimpleDoubleProperty(CANVAS_WIDTH));
canvas.heightProperty().bind(canvasPane.heightProperty()); canvas.heightProperty().bind(new SimpleDoubleProperty(CANVAS_HEIGHT));
}
public void initializeCanvas (){
gc = canvas.getGraphicsContext2D(); gc = canvas.getGraphicsContext2D();
gc.setGlobalAlpha(0.5);
fitMarksToCanvas();
drawGoogleMap();
// TODO: 1/05/17 wmu16 - Change this call to now draw the marks as from the xml
initializeBoats();
initializeMarks();
timer = new AnimationTimer() {
private int UPDATE_FPM_PERIOD = 50; // update FPM label every 50 frames
// overriding the handle so that it can clean canvas and redraw boats and course marks private int updateFPMCounter = 100;
AnimationTimer timer = new AnimationTimer() {
private long lastUpdate = 0;
private long lastFpsUpdate = 0;
private int lastFpsCount = 0;
private int fpsCount = 0;
@Override @Override
public void handle(long now) { public void handle(long now) {
if (true){ //if statement for limiting refresh rate if needed
gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
gc.setFill(Color.SKYBLUE);
gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
drawCourse();
drawBoats();
drawFps(lastFpsCount);
// If race has started, draw the boats and play the timeline //fps stuff
if (raceViewController.getRace().getRaceTime() > 1){ long oldFrameTime = frameTimes[frameTimeIndex] ;
raceViewController.playTimelines(); frameTimes[frameTimeIndex] = now ;
frameTimeIndex = (frameTimeIndex + 1) % frameTimes.length ;
if (frameTimeIndex == 0) {
arrayFilled = true ;
} }
// Race has not started, pause the timelines long elapsedNanos;
else { if (arrayFilled) {
raceViewController.pauseTimelines(); elapsedNanos = now - oldFrameTime ;
long elapsedNanosPerFrame = elapsedNanos / frameTimes.length ;
frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ;
if (updateFPMCounter++ > UPDATE_FPM_PERIOD) {
updateFPMCounter = 0;
drawFps(frameRate.intValue());
} }
lastUpdate = now; raceViewController.updateSparkLine();
fpsCount ++;
if (now - lastFpsUpdate >= 1000000000){
lastFpsCount = fpsCount;
fpsCount = 0;
lastFpsUpdate = now;
} }
updateGroups();
if (StreamParser.isRaceFinished()) {
this.stop();
} }
} }
}; };
timer.start(); }
/**
* First find the top right and bottom left points' geo locations, then retrieve
* map from google to display on image view. - Haoming 22/5/2017
*/
private void drawGoogleMap() {
findMetersPerPixel();
Point2D topLeftPoint = findScaledXY(maxLatPoint.getLatitude(), minLonPoint.getLongitude());
// distance from top left extreme to panel origin (top left corner)
double distanceFromTopLeftToOrigin = Math.sqrt(Math.pow(topLeftPoint.getX() * metersPerPixelX, 2) + Math.pow(topLeftPoint.getY() * metersPerPixelY, 2));
// angle from top left extreme to panel origin
double bearingFromTopLeftToOrigin = Math.toDegrees(Math.atan2(-topLeftPoint.getX(), topLeftPoint.getY()));
// the top left extreme
Position topLeftPos = new Position(maxLatPoint.getLatitude(), minLonPoint.getLongitude());
Position originPos = GeoUtility.getGeoCoordinate(topLeftPos, bearingFromTopLeftToOrigin, distanceFromTopLeftToOrigin);
// distance from origin corner to bottom right corner of the panel
double distanceFromOriginToBottomRight = Math.sqrt(Math.pow(PANEL_HEIGHT* metersPerPixelY, 2) + Math.pow(PANEL_WIDTH * metersPerPixelX, 2));
double bearingFromOriginToBottomRight = Math.toDegrees(Math.atan2(PANEL_WIDTH, -PANEL_HEIGHT));
Position bottomRightPos = GeoUtility.getGeoCoordinate(originPos, bearingFromOriginToBottomRight, distanceFromOriginToBottomRight);
Boundary boundary = new Boundary(originPos.getLat(), bottomRightPos.getLng(), bottomRightPos.getLat(), originPos.getLng());
CanvasMap canvasMap = new CanvasMap(boundary);
mapImage.setImage(canvasMap.getMapImage());
}
/**
* Adds border marks to the canvas, taken from the XML file
*
* NOTE: This is quite confusing as objects are grabbed from the XMLParser such as Mark and CompoundMark which are
* named the same as those in the model package but are, however not the same, so they do not have things such as
* a type and must be derived from the number of marks in a compound mark etc..
*/
private void addRaceBorder() {
XMLParser.RaceXMLObject raceXMLObject = StreamParser.getXmlObject().getRaceXML();
ArrayList<Limit> courseLimits = raceXMLObject.getCourseLimit();
gc.setStroke(Color.DARKBLUE);
gc.setLineWidth(3);
double[] xBoundaryPoints = new double[courseLimits.size()];
double[] yBoundaryPoints = new double[courseLimits.size()];
for (int i = 0; i < courseLimits.size() - 1; i++) {
Limit thisPoint1 = courseLimits.get(i);
SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(), thisPoint1.getSeqID(), thisPoint1.getSeqID());
Limit thisPoint2 = courseLimits.get(i+1);
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(), thisPoint2.getSeqID(), thisPoint2.getSeqID());
Point2D borderPoint1 = findScaledXY(thisMark1);
Point2D borderPoint2 = findScaledXY(thisMark2);
gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(),
borderPoint2.getX(), borderPoint2.getY());
xBoundaryPoints[i] = borderPoint1.getX();
yBoundaryPoints[i] = borderPoint1.getY();
}
Limit thisPoint1 = courseLimits.get(courseLimits.size()-1);
SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(), thisPoint1.getSeqID(), thisPoint1.getSeqID());
Limit thisPoint2 = courseLimits.get(0);
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(), thisPoint2.getSeqID(), thisPoint2.getSeqID());
Point2D borderPoint1 = findScaledXY(thisMark1);
Point2D borderPoint2 = findScaledXY(thisMark2);
gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(),
borderPoint2.getX(), borderPoint2.getY());
xBoundaryPoints[courseLimits.size()-1] = borderPoint1.getX();
yBoundaryPoints[courseLimits.size()-1] = borderPoint1.getY();
// gc.setFill(Color.LIGHTBLUE);
// gc.fillPolygon(xBoundaryPoints,yBoundaryPoints,yBoundaryPoints.length);
}
private void updateGroups(){
for (BoatGroup boatGroup : boatGroups) {
// some raceObjects will have multiple ID's (for instance gate marks)
//checking if the current "ID" has any updates associated with it
if (StreamParser.boatLocations.containsKey(boatGroup.getRaceId())) {
if (boatGroup.isStopped()) {
updateBoatGroup(boatGroup);
}
}
boatGroup.move();
}
for (MarkGroup markGroup : markGroups) {
for (Long id : markGroup.getRaceIds()) {
if (StreamParser.markLocations.containsKey(id)) {
updateMarkGroup(id, markGroup);
}
}
}
checkForCourseChanges();
}
private void checkForCourseChanges() {
if (StreamParser.isNewRaceXmlReceived()){
gc.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
drawGoogleMap();
addRaceBorder();
}
}
private void updateBoatGroup(BoatGroup boatGroup) {
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatLocations.get(boatGroup.getRaceId());
// giving the movementQueue a 5 packet buffer to account for slightly out of order packets
if (movementQueue.size() > 0){
try {
BoatPositionPacket positionPacket = movementQueue.take();
Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon());
double heading = 360.0 / 0xffff * positionPacket.getHeading();
boatGroup.setDestination(p2d.getX(), p2d.getY(), heading, positionPacket.getGroundSpeed(), positionPacket.getTimeValid(), frameRate, boatGroup.getRaceId());
} catch (InterruptedException e){
e.printStackTrace();
}
// }
}
}
void updateMarkGroup (long raceId, MarkGroup markGroup) {
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.markLocations.get(raceId);
if (movementQueue.size() > 0){
try {
BoatPositionPacket positionPacket = movementQueue.take();
Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon());
markGroup.moveMarkTo(p2d.getX(), p2d.getY(), raceId);
} catch (InterruptedException e){
e.printStackTrace();
}
}
}
/**
* Draws all the boats.
*/
private void initializeBoats() {
Map<Integer, Yacht> boats = StreamParser.getBoats();
Group boatAnnotations = new Group();
ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML().getParticipants();
ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) {
participantIDs.add(p.getsourceID());
}
for (Yacht boat : boats.values()) {
if (participantIDs.contains(boat.getSourceID())) {
boat.setColour(Colors.getColor());
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
boatGroups.add(boatGroup);
boatAnnotations.getChildren().add(boatGroup.getLowPriorityAnnotations());
}
}
group.getChildren().add(boatAnnotations);
group.getChildren().addAll(boatGroups);
}
private void initializeMarks() {
List<Mark> allMarks = StreamParser.getXmlObject().getRaceXML().getNonDupCompoundMarks();
for (Mark mark : allMarks) {
if (mark.getMarkType() == MarkType.SINGLE_MARK) {
SingleMark sMark = (SingleMark) mark;
MarkGroup markGroup = new MarkGroup(sMark, findScaledXY(sMark));
markGroups.add(markGroup);
} else {
GateMark gMark = (GateMark) mark;
MarkGroup markGroup = new MarkGroup(gMark, findScaledXY(gMark.getSingleMark1()), findScaledXY(gMark.getSingleMark2())); //should be 2 objects in the list.
markGroups.add(markGroup);
}
}
group.getChildren().addAll(markGroups);
} }
class ResizableCanvas extends Canvas { class ResizableCanvas extends Canvas {
public ResizableCanvas() { ResizableCanvas() {
// Redraw canvas when size changes. // Redraw canvas when size changes.
widthProperty().addListener(evt -> draw()); widthProperty().addListener(evt -> draw());
heightProperty().addListener(evt -> draw()); heightProperty().addListener(evt -> draw());
@@ -109,175 +336,188 @@ public class CanvasController {
public double prefWidth(double height) { public double prefWidth(double height) {
return getWidth(); return getWidth();
} }
@Override @Override
public double prefHeight(double width) { public double prefHeight(double width) {
return getHeight(); return getHeight();
} }
} }
private void drawFps(int fps){ private void drawFps(int fps){
if (raceViewController.isDisplayFps()){ if (raceViewController.isDisplayFps()){
gc.setFill(Color.BLACK); gc.clearRect(5, 5, 60, 30);
gc.setFont(new Font(14)); gc.setFont(new Font(16));
gc.setLineWidth(3); gc.setLineWidth(4);
gc.setGlobalAlpha(0.75);
gc.fillText(fps + " FPS", 5, 20); gc.fillText(fps + " FPS", 5, 20);
gc.setGlobalAlpha(0.5);
} else {
gc.clearRect(5,5,60,30);
} }
} }
/** /**
* Draws all the boats. * Calculates x and y location for every marker that fits it to the canvas the race will be drawn on.
*/ */
private void drawBoats() { private void fitMarksToCanvas() {
Map<Boat, TimelineInfo> timelineInfos = raceViewController.getTimelineInfos(); //Check is called once to avoid unnecessarily change the course limits once the race is running
for (Boat boat : timelineInfos.keySet()) { StreamParser.isNewRaceXmlReceived();
TimelineInfo timelineInfo = timelineInfos.get(boat); findMinMaxPoint();
double minLonToMaxLon = scaleRaceExtremities();
boat.setLocation(timelineInfo.getY().doubleValue(), timelineInfo.getX().doubleValue()); calculateReferencePointLocation(minLonToMaxLon);
//givePointsXY();
drawBoat(boat.getLongitude(), boat.getLatitude(), boat.getColor(), boat.getShortName(), boat.getSpeedInKnots(), boat.getHeading()); addRaceBorder();
}
} }
/** /**
* Draw the wake line behind a boat * Sets the class variables minLatPoint, maxLatPoint, minLonPoint, maxLonPoint to the marker with the leftmost
* @param gc The graphics context used for drawing the wake * marker, rightmost marker, southern most marker and northern most marker respectively.
* @param x the x position of the boat
* @param y the y position of the boat
* @param speed the speed of the boat
* @param color the color of the wake line
* @param heading the heading of the boat
*/ */
private void drawWake(GraphicsContext gc, double x, double y, double speed, Color color, double heading){ private void findMinMaxPoint() {
double angle = Math.toRadians(heading); List<Limit> sortedPoints = new ArrayList<>();
speed = speed * 2; for (Limit limit : StreamParser.getXmlObject().getRaceXML().getCourseLimit()) {
Point newP = new Point(0, speed); sortedPoints.add(limit);
newP.rotate(angle); }
sortedPoints.sort(Comparator.comparingDouble(Limit::getLat));
Limit minLatMark = sortedPoints.get(0);
Limit maxLatMark = sortedPoints.get(sortedPoints.size()-1);
minLatPoint = new SingleMark(minLatMark.toString(), minLatMark.getLat(), minLatMark.getLng(), minLatMark.getSeqID(), minLatMark.getSeqID());
maxLatPoint = new SingleMark(maxLatMark.toString(), maxLatMark.getLat(), maxLatMark.getLng(), maxLatMark.getSeqID(), minLatMark.getSeqID());
gc.setStroke(color); sortedPoints.sort(Comparator.comparingDouble(Limit::getLng));
gc.setLineWidth(1.0); //If the course is on a point on the earth where longitudes wrap around.
gc.strokeLine(x, y, newP.x + x, newP.y + y); Limit minLonMark = sortedPoints.get(0);
Limit maxLonMark = sortedPoints.get(sortedPoints.size()-1);
minLonPoint = new SingleMark(minLonMark.toString(), minLonMark.getLat(), minLonMark.getLng(), minLonMark.getSeqID(), minLonMark.getSeqID());
maxLonPoint = new SingleMark(maxLonMark.toString(), maxLonMark.getLat(), maxLonMark.getLng(), maxLonMark.getSeqID(), minLonMark.getSeqID());
if (maxLonPoint.getLongitude() - minLonPoint.getLongitude() > 180) {
horizontalInversion = true;
}
} }
/** /**
* Draws a boat with given (x, y) position in the given color * Calculates the location of a reference point, this is always the point with minimum latitude, in relation to the
* canvas.
* *
* @param lat * @param minLonToMaxLon The horizontal distance between the point of minimum longitude to maximum longitude.
* @param lon
* @param color
* @param name
* @param speed
*/ */
private void drawBoat(double lat, double lon, Color color, String name, double speed, double heading) { private void calculateReferencePointLocation (double minLonToMaxLon) {
// Latitude Mark referencePoint = minLatPoint;
double x = (lon - ORIGIN_LON) * SCALE; double referenceAngle;
double y = (ORIGIN_LAT - lat) * SCALE;
gc.setFill(color); if (scaleDirection == ScaleDirection.HORIZONTAL) {
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint));
referencePointX = BUFFER_SIZE + distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint);
if (raceViewController.isDisplayAnnotations()) { referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, maxLatPoint));
// Set boat text referencePointY = CANVAS_HEIGHT - (BUFFER_SIZE + BUFFER_SIZE);
gc.setFont(new Font(14)); referencePointY -= distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint);
gc.setLineWidth(3); referencePointY = referencePointY / 2;
gc.fillText(name + ", " + speed + " knots", x + 15, y + 15); referencePointY += BUFFER_SIZE;
referencePointY += distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint);
} else {
referencePointY = CANVAS_HEIGHT - BUFFER_SIZE;
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint));
referencePointX = BUFFER_SIZE;
referencePointX += distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint);
referencePointX += ((CANVAS_WIDTH - (BUFFER_SIZE + BUFFER_SIZE)) - (minLonToMaxLon * distanceScaleFactor)) / 2;
} }
// double diameter = 9; if(horizontalInversion) {
// gc.fillOval(x, y, diameter, diameter); referencePointX = CANVAS_WIDTH - BUFFER_SIZE - (referencePointX - BUFFER_SIZE);
double angle = Math.toRadians(heading);
Point p1 = new Point(0, -15); // apex point
Point p2 = new Point(7, 4); // base point
Point p3 = new Point(-7, 4); // base point
p1.rotate(angle);
p2.rotate(angle);
p3.rotate(angle);
double[] xx = new double[] {p1.x + x, p2.x + x, x, p3.x + x};
double[] yy = new double[] {p1.y + y, p2.y + y, y, p3.y + y};
gc.fillPolygon(xx, yy, 4);
if (raceViewController.isDisplayAnnotations()){
drawWake(gc, x, y, speed, color, heading);
} }
} }
/**
* Finds the scale factor necessary to fit all race markers within the onscreen map and assigns it to distanceScaleFactor
* Returns the max horizontal distance of the map.
*/
private double scaleRaceExtremities () {
double vertAngle = Math.abs(Mark.calculateHeadingRad(minLatPoint, maxLatPoint));
double vertDistance = Math.cos(vertAngle) * Mark.calculateDistance(minLatPoint, maxLatPoint);
double horiAngle = Mark.calculateHeadingRad(minLonPoint, maxLonPoint);
if (horiAngle <= (Math.PI / 2))
horiAngle = (Math.PI / 2) - horiAngle;
else
horiAngle = horiAngle - (Math.PI / 2);
double horiDistance = Math.cos(horiAngle) * Mark.calculateDistance(minLonPoint, maxLonPoint);
double vertScale = (CANVAS_HEIGHT - (BUFFER_SIZE + BUFFER_SIZE)) / vertDistance;
if ((horiDistance * vertScale) > (CANVAS_WIDTH - (BUFFER_SIZE + BUFFER_SIZE))) {
distanceScaleFactor = (CANVAS_WIDTH - (BUFFER_SIZE + BUFFER_SIZE)) / horiDistance;
scaleDirection = ScaleDirection.HORIZONTAL;
} else {
distanceScaleFactor = vertScale;
scaleDirection = ScaleDirection.VERTICAL;
}
return horiDistance;
}
private Point2D findScaledXY (Mark unscaled) {
return findScaledXY (unscaled.getLatitude(), unscaled.getLongitude());
}
public Point2D findScaledXY (double unscaledLat, double unscaledLon) {
double distanceFromReference;
double angleFromReference;
int xAxisLocation = (int) referencePointX;
int yAxisLocation = (int) referencePointY;
angleFromReference = Mark.calculateHeadingRad(minLatPoint.getLatitude(), minLatPoint.getLongitude(), unscaledLat, unscaledLon);
distanceFromReference = Mark.calculateDistance(minLatPoint.getLatitude(), minLatPoint.getLongitude(), unscaledLat, unscaledLon);
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
xAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
} else if (angleFromReference >= 0) {
angleFromReference = angleFromReference - Math.PI / 2;
xAxisLocation += (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
yAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
} else if (angleFromReference < 0 && angleFromReference >= -Math.PI / 2) {
angleFromReference = Math.abs(angleFromReference);
xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
} else {
angleFromReference = Math.abs(angleFromReference) - Math.PI / 2;
xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
yAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
}
if(horizontalInversion) {
xAxisLocation = CANVAS_WIDTH - BUFFER_SIZE - (xAxisLocation - BUFFER_SIZE);
}
return new Point2D(xAxisLocation, yAxisLocation);
}
/** /**
* Inner class for creating point so that you can rotate it around origin point. * Find the number of meters per pixel.
*/ */
class Point { private void findMetersPerPixel () {
Point2D p1, p2;
double x, y; Mark m1, m2;
double theta, distance, dx, dy, dHorizontal, dVertical;
Point (double x, double y) { m1 = new SingleMark("m1", maxLatPoint.getLatitude(), minLonPoint.getLongitude(), 1, 0);
this.x = x; m2 = new SingleMark("m2", minLatPoint.getLatitude(), maxLonPoint.getLongitude(), 2, 0);
this.y = y; p1 = findScaledXY(m1);
p2 = findScaledXY(m2);
theta = Mark.calculateHeadingRad(m1, m2);
distance = Mark.calculateDistance(m1, m2);
dHorizontal = Math.abs(Math.sin(theta) * distance);
dVertical = Math.abs(Math.cos(theta) * distance);
dx = Math.abs(p1.getX() - p2.getX());
dy = Math.abs(p1.getY() - p2.getY());
metersPerPixelX = dHorizontal / dx;
metersPerPixelY = dVertical / dy;
} }
void rotate(double angle) { List<BoatGroup> getBoatGroups() {
double oldX = x; return boatGroups;
double oldY = y;
this.x = oldX * Math.cos(angle) - oldY * Math.sin(angle);
this.y = oldX * Math.sin(angle) + oldY * Math.cos(angle);
}
} }
/** List<MarkGroup> getMarkGroups() {
* Draws the course. return markGroups;
*/
private void drawCourse() {
for (Mark mark : raceViewController.getRace().getCourse()) {
if (mark.getMarkType() == MarkType.SINGLE_MARK) {
drawSingleMark((SingleMark) mark, Color.BLACK);
} else if (mark.getMarkType() == MarkType.GATE_MARK) {
drawGateMark((GateMark) mark);
}
}
}
/**
* Draw a given mark on canvas
*
* @param singleMark
*/
private void drawSingleMark(SingleMark singleMark, Color color) {
double x = (singleMark.getLongitude() - ORIGIN_LON) * SCALE;
double y = (ORIGIN_LAT - singleMark.getLatitude()) * SCALE;
gc.setFill(color);
gc.fillRect(x,y,5.5,5.5);
}
/**
* Draw a gate mark which contains two single marks
*
* @param gateMark
*/
private void drawGateMark(GateMark gateMark) {
Color color = Color.BLUE;
if (gateMark.getName().equals("Start")){
color = Color.RED;
}
if (gateMark.getName().equals("Finish")){
color = Color.GREEN;
}
drawSingleMark(gateMark.getSingleMark1(), color);
drawSingleMark(gateMark.getSingleMark2(), color);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setStroke(color);
// Convert lat/lon to x,y
double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * SCALE;
double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * SCALE;
double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * SCALE;
double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * SCALE;
gc.setLineWidth(1);
gc.strokeLine(x1, y1, x2, y2);
} }
} }
@@ -9,30 +9,31 @@ import javafx.scene.layout.Pane;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import seng302.models.stream.StreamParser;
/**
* Created by michaelrausch on 21/03/17.
*/
public class Controller implements Initializable { public class Controller implements Initializable {
@FXML @FXML
private AnchorPane contentPane; private AnchorPane contentPane;
private void setContentPane(String jfxUrl){ private void setContentPane(String jfxUrl) {
try{ try {
contentPane.getChildren().removeAll(); contentPane.getChildren().removeAll();
contentPane.getChildren().clear(); contentPane.getChildren().clear();
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
} contentPane.getChildren()
catch(javafx.fxml.LoadException e){ .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
} catch (javafx.fxml.LoadException e) {
System.err.println(e.getCause()); System.err.println(e.getCause());
} } catch (IOException e) {
catch(IOException e){
System.err.println(e); System.err.println(e);
} }
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
setContentPane("/views/RaceView.fxml"); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
setContentPane("/views/StartScreenView.fxml");
StreamParser.boatLocations.clear();
} }
} }
@@ -1,80 +0,0 @@
package seng302.controllers;
import seng302.models.Boat;
import seng302.models.Race;
import seng302.models.parsers.ConfigParser;
import seng302.models.parsers.CourseParser;
import seng302.models.parsers.TeamsParser;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
/**
* Created by zyt10 on 17/03/17.
* run before CanvasController to initialize race events
* the CanvasController then uses the event data to make the animations
*/
public class RaceController {
Race race = null;
public void initializeRace() {
String raceConfigFile = "/config/config.xml";
String teamsConfigFile = "/config/teams.xml";
try {
race = createRace(raceConfigFile, teamsConfigFile);
} catch (Exception e) {
System.out.println("There was an error creating the race.");
}
if (race != null) {
race.startRace();
} else {
System.out.println("There was an error creating the race. Exiting.");
}
}
public Race createRace(String configFile, String teamsConfigFile) throws Exception {
Race race = new Race();
// Read team names from file
TeamsParser tp = new TeamsParser(teamsConfigFile);
// Read course from file
ConfigParser config = new ConfigParser(configFile);
ArrayList<String> boatNames = new ArrayList<>();
ArrayList<Boat> teams = tp.getBoats();
//get race size
int numberOfBoats = teams.size();
//get time scale
double timeScale = config.getTimeScale();
race.setTimeScale(timeScale);
for (Boat boat : teams) {
boatNames.add(boat.getTeamName());
race.addBoat(boat);
}
// Shuffle team names
long seed = System.nanoTime();
Collections.shuffle(boatNames, new Random(seed));
if (numberOfBoats > Array.getLength(boatNames.toArray())) {
return null;
}
CourseParser course = new CourseParser("/config/course.xml");
race.addCourse(course.getCourse());
return race;
}
public Race getRace() {
return race;
}
}
@@ -1,37 +0,0 @@
package seng302.controllers;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
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;
/**
* Created by ptg19 on 20/03/17.
*/
public class RaceResultController implements Initializable{
@FXML private AnchorPane window;
@FXML private VBox resultsVBox;
private Race race;
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--;
}
}
}
@@ -1,38 +1,64 @@
package seng302.controllers; package seng302.controllers;
import javafx.animation.Animation;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty; import javafx.collections.FXCollections;
import javafx.beans.property.SimpleDoubleProperty; import javafx.collections.ObservableList;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Point2D;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Line;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration; import javafx.util.Duration;
import seng302.models.Boat; import javafx.util.StringConverter;
import seng302.models.Event; import seng302.GeometryUtils;
import seng302.models.Race; import seng302.controllers.annotations.Annotation;
import seng302.models.TimelineInfo; import seng302.controllers.annotations.ImportantAnnotationController;
import seng302.models.parsers.ConfigParser; import seng302.controllers.annotations.ImportantAnnotationDelegate;
import seng302.controllers.annotations.ImportantAnnotationsState;
import seng302.models.*;
import seng302.models.mark.GateMark;
import seng302.models.mark.Mark;
import seng302.models.mark.MarkGroup;
import seng302.models.mark.SingleMark;
import seng302.models.stream.StreamParser;
import seng302.models.stream.XMLParser;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
import java.util.stream.Collectors;
/** /**
* Created by ptg19 on 29/03/17. * Created by ptg19 on 29/03/17.
*/ */
public class RaceViewController { public class RaceViewController extends Thread implements ImportantAnnotationDelegate {
@FXML
private LineChart raceSparkLine;
@FXML
private NumberAxis sparklineYAxis;
@FXML @FXML
private VBox positionVbox; private VBox positionVbox;
@FXML @FXML
private CheckBox toggleAnnotation, toggleFps; private CheckBox toggleFps;
@FXML @FXML
private Text timerLabel; private Text timerLabel;
@FXML @FXML
@@ -40,68 +66,225 @@ public class RaceViewController {
@FXML @FXML
private Text windArrowText, windDirectionText; private Text windArrowText, windDirectionText;
@FXML @FXML
private Slider annotationSlider;
@FXML
private Button selectAnnotationBtn;
@FXML
private ComboBox boatSelectionComboBox;
@FXML
private CanvasController includedCanvasController; private CanvasController includedCanvasController;
private boolean displayAnnotations; private static ArrayList<Yacht> startingBoats = new ArrayList<>();
private boolean displayFps; private boolean displayFps;
private Timeline timerTimeline; private Timeline timerTimeline;
private Map<Boat, TimelineInfo> timelineInfos = new HashMap<>(); private Stage stage;
private ArrayList<Boat> boatOrder = new ArrayList<>(); private static HashMap<Integer, Series<String, Double>> sparkLineData = new HashMap<>();
private Race race; private static ArrayList<Yacht> racingBoats = new ArrayList<>();
private ImportantAnnotationsState importantAnnotations;
private Yacht selectedBoat;
public void initialize() { public void initialize() {
includedCanvasController.setup(this); // Load a default important annotation state
RaceController raceController = new RaceController(); importantAnnotations = new ImportantAnnotationsState();
raceController.initializeRace();
race = raceController.getRace();
initializeTimer(); //Formatting the y axis of the sparkline
initializeSettings(); raceSparkLine.getYAxis().setRotate(180);
try{ raceSparkLine.getYAxis().setTickLabelRotation(180);
initializeTimelines(); raceSparkLine.getYAxis().setTranslateX(-5);
raceSparkLine.getYAxis().setAutoRanging(false);
sparklineYAxis.setTickMarkVisible(false);
startingBoats = new ArrayList<>(StreamParser.getBoats().values());
includedCanvasController.setup(this);
includedCanvasController.initializeCanvas();
initializeUpdateTimer();
initialiseFPSCheckBox();
initialiseAnnotationSlider();
initialiseBoatSelectionComboBox();
includedCanvasController.timer.start();
selectAnnotationBtn.setOnAction(event -> loadSelectAnnotationView());
} }
catch (Exception e){
/**
* The important annotations have been changed, update this view
*
* @param importantAnnotationsState The current state of the selected annotations
*/
public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState) {
this.importantAnnotations = importantAnnotationsState;
setAnnotations((int) annotationSlider.getValue()); // Refresh the displayed annotations
}
/**
* Loads the "select annotations" view in a new window
*/
private void loadSelectAnnotationView() {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
Stage stage = new Stage();
// Set controller
ImportantAnnotationController controller = new ImportantAnnotationController(this,
stage);
fxmlLoader.setController(controller);
// Load FXML and set CSS
fxmlLoader
.setLocation(getClass().getResource("/views/importantAnnotationSelectView.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 469, 298);
scene.getStylesheets().add(getClass().getResource("/css/master.css").toString());
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
stage.show();
controller.loadState(importantAnnotations);
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
//set wind direction!!!!!!! can't find another place to put my code --haoming
double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
windDirectionText.setText(String.format("%.1f°", windDirection));
windArrowText.setRotate(windDirection);
} }
private void initializeSettings(){
displayAnnotations = true; private void initialiseFPSCheckBox() {
displayFps = true; displayFps = true;
toggleFps.selectedProperty().addListener(
(observable, oldValue, newValue) -> displayFps = !displayFps);
}
toggleAnnotation.selectedProperty().addListener(new ChangeListener<Boolean>() { private void initialiseAnnotationSlider() {
annotationSlider.setLabelFormatter(new StringConverter<Double>() {
@Override @Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { public String toString(Double n) {
displayAnnotations = !displayAnnotations; if (n == 0) {
return "None";
}
if (n == 1) {
return "Important";
}
if (n == 2) {
return "All";
}
return "All";
}
@Override
public Double fromString(String s) {
switch (s) {
case "None":
return 0d;
case "Important":
return 1d;
case "All":
return 2d;
default:
return 2d;
}
} }
}); });
toggleFps.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override annotationSlider.valueProperty().addListener((obs, oldval, newVal) ->
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { setAnnotations((int) annotationSlider.getValue()));
displayFps = !displayFps;
annotationSlider.setValue(2);
} }
/**
* Used to add any new boats into the race that may have started late or not have had data received yet
*/
void updateSparkLine(){
// Collect the racing boats that aren't already in the chart
ArrayList<Yacht> sparkLineCandidates = startingBoats.stream().filter(yacht -> !sparkLineData.containsKey(yacht.getSourceID())
&& yacht.getPosition() != null & yacht.getPosition() != "-").collect(Collectors.toCollection(ArrayList::new));
// Obtain the qualifying boats to set the max on the Y axis
racingBoats = startingBoats.stream().filter(yacht ->
yacht.getPosition() != null & yacht.getPosition() != "-").collect(Collectors.toCollection(ArrayList::new));
sparklineYAxis.setUpperBound(racingBoats.size() + 1);
// Create a new data series for new boats
sparkLineCandidates.stream().filter(yacht -> yacht.getPosition() != null).forEach(yacht -> {
Series<String, Double> yachtData = new Series<>();
yachtData.setName(yacht.getBoatName());
yachtData.getData().add(new XYChart.Data<>(Integer.toString(yacht.getLegNumber()), 1 + racingBoats.size() - Double.parseDouble(yacht.getPosition())));
sparkLineData.put(yacht.getSourceID(), yachtData);
});
// Lambda function to sort the series in order of leg (later legs shown more to the right)
List<XYChart.Series<String, Double>> positions = new ArrayList<>(sparkLineData.values());
Collections.sort(positions, (o1, o2) -> {
Integer leg1 = Integer.parseInt(o1.getData().get(o1.getData().size()-1).getXValue());
Integer leg2 = Integer.parseInt(o2.getData().get(o2.getData().size()-1).getXValue());
if (leg2 < leg1){
return 1;
} else {
return -1;
}
});
// Adds the new data series to the sparkline (and set the colour of the series)
raceSparkLine.setCreateSymbols(false);
positions.stream().filter(spark -> !raceSparkLine.getData().contains(spark)).forEach(spark -> {
raceSparkLine.getData().add(spark);
spark.getNode().lookup(".chart-series-line").setStyle("-fx-stroke:" + getBoatColorAsRGB(spark.getName()));
}); });
} }
private void initializeTimer(){
/**
* Updates the yachts sparkline of the desired boat and using the new leg number
* @param yacht The yacht to be updated on the sparkline
* @param legNumber the leg number that the position will be assigned to
*/
public static void updateYachtPositionSparkline(Yacht yacht, Integer legNumber){
XYChart.Series<String, Double> positionData = sparkLineData.get(yacht.getSourceID());
positionData.getData().add(new XYChart.Data<>(Integer.toString(legNumber), 1 + racingBoats.size() - Double.parseDouble(yacht.getPosition())));
}
/**
* gets the rgb string of the boats colour to use for the chart via css
* @param boatName boat passed in to get the boats colour
* @return the colour as an rgb string
*/
private String getBoatColorAsRGB(String boatName){
Color color = Color.WHITE;
for (Yacht yacht: startingBoats){
if (Objects.equals(yacht.getBoatName(), boatName)){
color = yacht.getColour();
}
}
if (color == null){
return String.format( "#%02X%02X%02X",255,255,255);
}
return String.format( "#%02X%02X%02X",
(int)( color.getRed() * 255 ),
(int)( color.getGreen() * 255 ),
(int)( color.getBlue() * 255 ) );
}
/**
* Initalises a timer which updates elements of the RaceView such as wind direction, boat
* orderings etc.. which are dependent on the info from the stream parser constantly.
* Updates of each of these attributes are called ONCE EACH SECOND
*/
private void initializeUpdateTimer() {
timerTimeline = new Timeline(); timerTimeline = new Timeline();
timerTimeline.setCycleCount(Timeline.INDEFINITE); timerTimeline.setCycleCount(Timeline.INDEFINITE);
// Run timer update every second // Run timer update every second
timerTimeline.getKeyFrames().add( timerTimeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(1), new KeyFrame(Duration.seconds(1),
event -> { event -> {
// Stop timer if race is finished updateRaceTime();
if (this.race.isRaceFinished()) { updateWindDirection();
this.timerTimeline.stop(); updateOrder();
} else { updateBoatSelectionComboBox();
timerLabel.setText(convertTimeToMinutesSeconds(race.getRaceTime()));
this.race.incrementRaceTime();
}
}) })
); );
@@ -109,103 +292,233 @@ public class RaceViewController {
timerTimeline.playFromStart(); timerTimeline.playFromStart();
} }
/** /**
* Generates time line for each boat, and stores time time into timelineInfos hash map * Iterates over all corners until ones SeqID matches with the boats current leg number.
* Then it gets the compoundMarkID of that corner and uses it to fetch the appropriate mark
* Returns null if no next mark found.
* @param bg The BoatGroup to find the next mark of
* @return The next Mark or null if none found
*/ */
private void initializeTimelines() { private Mark getNextMark(BoatGroup bg) {
HashMap<Boat, List> boat_events = race.getEvents(); Integer legNumber = bg.getBoat().getLegNumber();
for (Boat boat : boat_events.keySet()) { List<XMLParser.RaceXMLObject.Corner> markSequence = StreamParser.getXmlObject().getRaceXML().getCompoundMarkSequence();
// x, y are the real time coordinates
DoubleProperty x = new SimpleDoubleProperty();
DoubleProperty y = new SimpleDoubleProperty();
List<KeyFrame> keyFrames = new ArrayList<>(); if (legNumber == 0) {
List<Event> events = boat_events.get(boat); return null;
} else if (legNumber == markSequence.size() - 1) {
return null;
}
// iterates all events and convert each event to keyFrame, then add them into a list for (XMLParser.RaceXMLObject.Corner corner : markSequence) {
for (Event event : events) { if (legNumber + 2 == corner.getSeqID()) {
if (event.getIsFinishingEvent()) { Integer thisCompoundMarkID = corner.getCompoundMarkID();
keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime()), for (Mark mark : StreamParser.getXmlObject().getRaceXML().getAllCompoundMarks()) {
onFinished -> {race.setBoatFinished(boat); handleEvent(event);}, if (mark.getCompoundMarkID() == thisCompoundMarkID) {
new KeyValue(x, event.getThisMark().getLatitude()), return mark;
new KeyValue(y, event.getThisMark().getLongitude()) }
) }
); }
}
return null;
}
/**
* Updates the wind direction arrow and text as from info from the StreamParser
*/
private void updateWindDirection() {
windDirectionText.setText(String.format("%.1f°", StreamParser.getWindDirection()));
windArrowText.setRotate(StreamParser.getWindDirection());
}
/**
* Updates the clock for the race
*/
private void updateRaceTime() {
if (StreamParser.isRaceFinished()) {
timerLabel.setFill(Color.RED);
timerLabel.setText("Race Finished!");
} else { } else {
keyFrames.add( timerLabel.setText(getTimeSinceStartOfRace());
new KeyFrame(Duration.seconds(event.getTime()),
onFinished ->{
handleEvent(event);
boat.setHeading(event.getBoatHeading());
},
new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude())
)
);
} }
} }
timelineInfos.put(boat, new TimelineInfo(new Timeline(keyFrames.toArray(new KeyFrame[keyFrames.size()])), x, y));
}
setRaceDuration();
}
private void setRaceDuration(){
Double maxDuration = 0.0;
Timeline maxTimeline = null;
for (TimelineInfo timelineInfo : timelineInfos.values()) { /**
* Grabs the boats currently in the race as from the StreamParser and sets them to be selectable
Timeline timeline = timelineInfo.getTimeline(); * in the boat selection combo box
if (timeline.getTotalDuration().toMillis() >= maxDuration) { */
maxDuration = timeline.getTotalDuration().toMillis(); private void updateBoatSelectionComboBox() {
maxTimeline = timeline; ObservableList<Yacht> observableBoats = FXCollections
.observableArrayList(StreamParser.getBoatsPos().values());
boatSelectionComboBox.setItems(observableBoats);
} }
// Timelines are paused by default
timeline.play(); /**
timeline.pause(); * Updates the order of the boats as from the StreamParser and sets them in the boat order
* section
*/
private void updateOrder() {
positionVbox.getChildren().clear();
positionVbox.getChildren().removeAll();
positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
// list of racing boat id
ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML()
.getParticipants();
ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) {
participantIDs.add(p.getsourceID());
} }
maxTimeline.setOnFinished(event -> { if (StreamParser.isRaceStarted()) {
race.setRaceFinished(); for (Yacht boat : StreamParser.getBoatsPos().values()) {
loadRaceResultView(); if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing
if (boat.getBoatStatus() == 3) { // 3 is finish status
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " (Finished)");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
positionVbox.getChildren().add(textToAdd);
} else {
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
positionVbox.getChildren().add(textToAdd);
}
}
}
} else {
for (Yacht boat : StreamParser.getBoats().values()) {
if (participantIDs.contains(boat.getSourceID())) { // check if the boat is racing
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
positionVbox.getChildren().add(textToAdd);
}
}
}
}
private void updateLaylines(BoatGroup bg) {
Mark nextMark = getNextMark(bg);
Boolean isUpwind = null;
// Can only calc leg direction if there is a next mark and it is a gate mark
if (nextMark != null) {
if (nextMark instanceof GateMark) {
if (bg.isUpwindLeg(includedCanvasController, nextMark)) {
isUpwind = true;
} else {
isUpwind = false;
}
for(MarkGroup mg : includedCanvasController.getMarkGroups()) {
mg.removeLaylines();
if (mg.getMainMark().getId() == nextMark.getId()) {
SingleMark singleMark1 = ((GateMark) nextMark).getSingleMark1();
SingleMark singleMark2 = ((GateMark) nextMark).getSingleMark2();
Point2D markPoint1 = includedCanvasController.findScaledXY(singleMark1.getLatitude(), singleMark1.getLongitude());
Point2D markPoint2 = includedCanvasController.findScaledXY(singleMark2.getLatitude(), singleMark2.getLongitude());
HashMap<Double, Double> angleAndSpeed;
if (isUpwind) {
angleAndSpeed = PolarTable.getOptimalUpwindVMG(StreamParser.getWindSpeed());
} else {
angleAndSpeed = PolarTable.getOptimalDownwindVMG(StreamParser.getWindSpeed());
}
Double resultingAngle = angleAndSpeed.keySet().iterator().next();
Point2D boatCurrentPos = new Point2D(bg.getBoatLayoutX(), bg.getBoatLayoutY());
Point2D gateMidPoint = markPoint1.midpoint(markPoint2);
Integer lineFuncResult = GeometryUtils.lineFunction(boatCurrentPos, gateMidPoint, markPoint2);
Line rightLayline = new Line();
Line leftLayline = new Line();
if (lineFuncResult == 1) {
rightLayline = makeRightLayline(markPoint2, 180 - resultingAngle, StreamParser.getWindDirection());
leftLayline = makeLeftLayline(markPoint1, 180 - resultingAngle, StreamParser.getWindDirection());
} else if (lineFuncResult == -1) {
rightLayline = makeRightLayline(markPoint1, 180 - resultingAngle, StreamParser.getWindDirection());
leftLayline = makeLeftLayline(markPoint2, 180 - resultingAngle, StreamParser.getWindDirection());
}
leftLayline.setStrokeWidth(0.5);
leftLayline.setStroke(bg.getBoat().getColour());
rightLayline.setStrokeWidth(0.5);
rightLayline.setStroke(bg.getBoat().getColour());
bg.setLaylines(leftLayline, rightLayline);
mg.addLaylines(leftLayline, rightLayline);
}
}
}
}
}
private Point2D getPointRotation(Point2D ref, Double distance, Double angle){
Double newX = ref.getX() + (ref.getX() + distance -ref.getX())*Math.cos(angle) - (ref.getY() + distance -ref.getY())*Math.sin(angle);
Double newY = ref.getY() + (ref.getX() + distance -ref.getX())*Math.sin(angle) + (ref.getY() + distance -ref.getY())*Math.cos(angle);
return new Point2D(newX, newY);
}
public Line makeLeftLayline(Point2D startPoint, Double layLineAngle, Double baseAngle) {
Point2D ep = getPointRotation(startPoint, 50.0, baseAngle + layLineAngle);
Line line = new Line(startPoint.getX(), startPoint.getY(), ep.getX(), ep.getY());
return line;
}
public Line makeRightLayline(Point2D startPoint, Double layLineAngle, Double baseAngle) {
Point2D ep = getPointRotation(startPoint, 50.0, baseAngle - layLineAngle);
Line line = new Line(startPoint.getX(), startPoint.getY(), ep.getX(), ep.getY());
return line;
}
/**
* Initialised the combo box with any boats currently in the race and adds the required listener
* for the combobox to take action upon selection
*/
private void initialiseBoatSelectionComboBox() {
updateBoatSelectionComboBox();
boatSelectionComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
//This listener is fired whenever the combo box changes. This means when the values are updated
//We dont want to set the selected value if the values are updated but nothing clicked (null)
if (newValue != null && newValue != selectedBoat) {
Yacht thisYacht = (Yacht) newValue;
setSelectedBoat(thisYacht);
}
}); });
} }
/**
* Play each boats timerTimeline
*/
public void playTimelines(){
for (TimelineInfo timelineInfo : timelineInfos.values()){
Timeline timeline = timelineInfo.getTimeline();
if (timeline.getStatus() == Animation.Status.PAUSED){
timeline.play();
}
}
}
/**
* Pause each boats timerTimeline
*/
public void pauseTimelines(){
for (TimelineInfo timelineInfo : timelineInfos.values()){
Timeline timeline = timelineInfo.getTimeline();
if (timeline.getStatus() == Animation.Status.RUNNING){
timeline.pause();
}
}
}
/** /**
* Display the list of boats in the order they finished the race * Display the list of boats in the order they finished the race
*/ */
private void loadRaceResultView() { private void loadRaceResultView() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/FinishView.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/FinishView.fxml"));
loader.setController(new RaceResultController(race));
try { try {
contentAnchorPane.getChildren().removeAll(); contentAnchorPane.getChildren().removeAll();
@@ -219,28 +532,6 @@ public class RaceViewController {
} }
} }
public void handleEvent(Event event) {
Boat boat = event.getBoat();
boatOrder.remove(boat);
boat.setMarkLastPast(event.getMarkPosInRace());
boatOrder.add(boat);
boatOrder.sort(new Comparator<Boat>() {
@Override
public int compare(Boat b1, Boat b2) {
return b2.getMarkLastPast() - b1.getMarkLastPast();
}
});
showOrder();
}
private void showOrder() {
positionVbox.getChildren().clear();
positionVbox.getChildren().removeAll();
for (Boat boat : boatOrder) {
positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
}
}
/** /**
* Convert seconds to a string of the format mm:ss * Convert seconds to a string of the format mm:ss
@@ -255,26 +546,140 @@ public class RaceViewController {
return String.format("%02d:%02d", time / 60, time % 60); return String.format("%02d:%02d", time / 60, time % 60);
} }
public void stopTimer() { private String getTimeSinceStartOfRace() {
timerTimeline.stop(); String timerString = "0:00";
if (StreamParser.getTimeSinceStart() > 0) {
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long.toString(StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
} }
public void startTimer() { timerString = "-" + timerMinute + ":" + timerSecond;
timerTimeline.play(); } else {
String timerMinute = Long.toString(-1 * StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long.toString(-1 * StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
timerString = timerMinute + ":" + timerSecond;
}
return timerString;
} }
public boolean isDisplayFps() {
boolean isDisplayFps() {
return displayFps; return displayFps;
} }
public boolean isDisplayAnnotations() { /**
return displayAnnotations; * Display the important annotations for a specific BoatGroup
* @param bg The boat group to set the annotations for
*/
private void setBoatGroupImportantAnnotations(BoatGroup bg) {
if (importantAnnotations.getAnnotationState(Annotation.NAME)) {
bg.setTeamNameObjectVisible(true);
} else {
bg.setTeamNameObjectVisible(false);
} }
public Race getRace() { if (importantAnnotations.getAnnotationState(Annotation.SPEED)) {
return race; bg.setVelocityObjectVisible(true);
} else {
bg.setVelocityObjectVisible(false);
} }
public Map<Boat, TimelineInfo> getTimelineInfos() { if (importantAnnotations.getAnnotationState(Annotation.TRACK)) {
return timelineInfos; bg.setLineGroupVisible(true);
} else {
bg.setLineGroupVisible(false);
}
if (importantAnnotations.getAnnotationState(Annotation.WAKE)) {
bg.setWakeVisible(true);
} else {
bg.setWakeVisible(false);
}
//TODO fix boat annotations with new boatgroup
if (importantAnnotations.getAnnotationState(Annotation.ESTTIMETONEXTMARK)) {
bg.setEstTimeToNextMarkObjectVisible(true);
} else {
bg.setEstTimeToNextMarkObjectVisible(false);
}
if (importantAnnotations.getAnnotationState(Annotation.LEGTIME)) {
bg.setLegTimeObjectVisible(true);
} else {
bg.setLegTimeObjectVisible(false);
}
}
private void setAnnotations(Integer annotationLevel) {
switch (annotationLevel) {
// No Annotations
case 0:
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
bg.setTeamNameObjectVisible(false);
bg.setVelocityObjectVisible(false);
bg.setEstTimeToNextMarkObjectVisible(false);
bg.setLegTimeObjectVisible(false);
bg.setLineGroupVisible(false);
bg.setWakeVisible(false);
}
break;
// Important Annotations
case 1:
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
setBoatGroupImportantAnnotations(bg);
}
break;
// All Annotations
case 2:
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
bg.setTeamNameObjectVisible(true);
bg.setVelocityObjectVisible(true);
bg.setEstTimeToNextMarkObjectVisible(true);
bg.setLegTimeObjectVisible(true);
bg.setLineGroupVisible(true);
bg.setWakeVisible(true);
}
break;
}
}
/**
* Sets all the annotations of the selected boat to be visible and all others to be hidden
*
* @param yacht The yacht for which we want to view all annotations
*/
private void setSelectedBoat(Yacht yacht) {
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
//We need to iterate over all race groups to get the matching boat group belonging to this boat if we
//are to toggle its annotations, there is no other backwards knowledge of a yacht to its boatgroup.
if (bg.getBoat().getHullID().equals(yacht.getHullID())) {
updateLaylines(bg);
bg.setIsSelected(true);
selectedBoat = yacht;
} else {
bg.setIsSelected(false);
}
}
}
void setStage(Stage stage) {
this.stage = stage;
}
Stage getStage() {
return stage;
}
/**
* Used for when the boat attempts to add data to the sparkline (first checks if the sparkline contains info on it)
* @param yachtId
* @return
*/
public static boolean sparkLineStatus(Integer yachtId) {
return sparkLineData.containsKey(yachtId);
} }
} }
@@ -0,0 +1,188 @@
package seng302.controllers;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
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 javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import seng302.models.Yacht;
import seng302.models.stream.StreamParser;
import seng302.models.stream.XMLParser.RaceXMLObject.Participant;
public class StartScreenController implements Initializable {
@FXML
private GridPane gridPane;
@FXML
private Label timeTillLive;
@FXML
private Button streamButton;
@FXML
private Button switchToRaceViewButton;
@FXML
private TableView<Yacht> teamList;
@FXML
private TableColumn<Yacht, String> boatNameCol;
@FXML
private TableColumn<Yacht, String> shortNameCol;
@FXML
private TableColumn<Yacht, String> countryCol;
@FXML
private TableColumn<Yacht, String> posCol;
@FXML
private Label realTime;
private boolean switchedToRaceView = false;
private void setContentPane(String jfxUrl) {
try {
// get the main controller anchor pane (MainView.fxml)
AnchorPane contentPane = (AnchorPane) gridPane.getParent();
contentPane.getChildren().removeAll();
contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren()
.addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
} catch (javafx.fxml.LoadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
gridPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
teamList.getStylesheets().add(getClass().getResource("/css/master.css").toString());
}
/**
* Running a timer to update the livestream status on welcome screen. Update interval is 1
* second.
*/
public void startStream() {
if (StreamParser.isStreamStatus()) {
streamButton.setVisible(false);
realTime.setVisible(true);
timeTillLive.setVisible(true);
timeTillLive.setTextFill(Color.GREEN);
timeTillLive.setText("Connecting...");
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> {
if (StreamParser.isRaceStarted()) {
if (!switchedToRaceView) {
switchToRaceView();
}
timer.cancel();
}
if (StreamParser.isRaceFinished()) {
realTime.setText(StreamParser.getCurrentTimeString());
timeTillLive.setTextFill(Color.RED);
timeTillLive.setText("Race finished! Waiting for new race...");
switchToRaceViewButton.setDisable(true);
} else if (StreamParser.getTimeSinceStart() > 0) {
realTime.setText(StreamParser.getCurrentTimeString());
updateTeamList();
timeTillLive.setTextFill(Color.RED);
switchToRaceViewButton.setDisable(false);
String timerMinute = Long
.toString(StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long
.toString(StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
String timerString = "-" + timerMinute + ":" + timerSecond;
timeTillLive.setText(timerString);
} else {
realTime.setText(StreamParser.getCurrentTimeString());
updateTeamList();
timeTillLive.setTextFill(Color.BLACK);
switchToRaceViewButton.setDisable(false);
String timerMinute = Long
.toString(-1 * StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long
.toString(-1 * StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
String timerString = timerMinute + ":" + timerSecond;
timeTillLive.setText(timerString);
}
});
}
}, 0, 1000);
} else {
timeTillLive.setText("Stream not available.");
timeTillLive.setTextFill(Color.RED);
}
}
public void switchToRaceView() {
StreamParser.boatLocations.clear();
switchedToRaceView = true;
setContentPane("/views/RaceView.fxml");
}
private void updateTeamList() {
ObservableList<Yacht> data = FXCollections.observableArrayList();
teamList.setItems(data);
boatNameCol.setCellValueFactory(
new PropertyValueFactory<>("boatName")
);
shortNameCol.setCellValueFactory(
new PropertyValueFactory<>("shortName")
);
countryCol.setCellValueFactory(
new PropertyValueFactory<>("country")
);
posCol.setCellValueFactory(
new PropertyValueFactory<>("position")
);
// check if the boat is racing
ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML()
.getParticipants();
ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) {
participantIDs.add(p.getsourceID());
}
// add boats to the start screen list
if (StreamParser.isRaceStarted()) { // if race is started, use StreamParser.getBoatsPos()
for (Yacht boat : StreamParser.getBoatsPos().values()) {
if (participantIDs.contains(boat.getSourceID())) {
data.add(boat);
}
}
} else { // else use StreamParser.getBoats()
for (Yacht boat : StreamParser.getBoats().values()) {
if (participantIDs.contains(boat.getSourceID())) {
data.add(boat);
}
}
}
teamList.refresh();
}
}
@@ -0,0 +1,13 @@
package seng302.controllers.annotations;
/**
* Annotations the user can select as important
*/
public enum Annotation {
SPEED,
WAKE,
TRACK,
NAME,
ESTTIMETONEXTMARK,
LEGTIME
}
@@ -0,0 +1,145 @@
package seng302.controllers.annotations;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import seng302.controllers.RaceViewController;
import seng302.controllers.annotations.Annotation;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
public class ImportantAnnotationController implements Initializable {
/*
* JavaFX Outlets
*/
@FXML
private CheckBox boatWakeSelect;
@FXML
private CheckBox boatSpeedSelect;
@FXML
private CheckBox boatTrackSelect;
@FXML
private CheckBox boatNameSelect;
@FXML
private CheckBox boatEstTimeToNextMarkSelect;
@FXML
private CheckBox boatElapsedTimeSelect;
@FXML
private AnchorPane annotationSelectWindow;
@FXML
private Button closeButton;
private ImportantAnnotationDelegate delegate;
private ImportantAnnotationsState importantAnnotationsState;
private Stage stage;
public ImportantAnnotationController(ImportantAnnotationDelegate delegate, Stage stage) {
this.delegate = delegate;
importantAnnotationsState = new ImportantAnnotationsState();
this.stage = stage;
}
/**
* Sets whether or not an annotation is considered important, then
* sends an update to the delegate
*
* @param annotation The annotation
* @param isSet True if annotation is important
*/
private void setAnnotation(Annotation annotation, Boolean isSet) {
importantAnnotationsState.setAnnotationState(annotation, isSet);
sendUpdate();
}
/**
* Sends an update to the delegate when the important
* annotations have changed
*/
private void sendUpdate() {
this.delegate.importantAnnotationsChanged(importantAnnotationsState);
}
/**
* Load the current state of the 'important annotations'
*
* @param currentState hashmap containing the states of each annotation
*/
public void loadState(ImportantAnnotationsState currentState) {
this.importantAnnotationsState = currentState;
// Initialise checkboxes
for (Annotation annotation : importantAnnotationsState.getAnnotations()) {
switch (annotation) {
case WAKE:
boatWakeSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case SPEED:
boatSpeedSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case TRACK:
boatTrackSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case NAME:
boatNameSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case ESTTIMETONEXTMARK:
boatEstTimeToNextMarkSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case LEGTIME:
boatElapsedTimeSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
default:
break;
}
}
}
/**
* View did load
*
* @param location .
* @param resources .
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
boatWakeSelect
.setOnAction(event -> setAnnotation(Annotation.WAKE, boatWakeSelect.isSelected()));
boatSpeedSelect
.setOnAction(event -> setAnnotation(Annotation.SPEED, boatSpeedSelect.isSelected()));
boatTrackSelect
.setOnAction(event -> setAnnotation(Annotation.TRACK, boatTrackSelect.isSelected()));
boatNameSelect
.setOnAction(event -> setAnnotation(Annotation.NAME, boatNameSelect.isSelected()));
boatEstTimeToNextMarkSelect.setOnAction(event -> setAnnotation(Annotation.ESTTIMETONEXTMARK,
boatEstTimeToNextMarkSelect.isSelected()));
boatElapsedTimeSelect.setOnAction(
event -> setAnnotation(Annotation.LEGTIME, boatElapsedTimeSelect.isSelected()));
closeButton.setOnAction(event -> stage.close());
}
}
@@ -0,0 +1,16 @@
package seng302.controllers.annotations;
/**
* An ImportantAnnotationDelegate handles updating the important annotations
* displayed to the user on behalf of the ImportantAnnotationController
*/
public interface ImportantAnnotationDelegate {
/**
* The important annotations have been changed, update the
* annotations displayed to the user
* @param importantAnnotationsState The current state of the selected annotations
*/
void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState);
}
@@ -0,0 +1,52 @@
package seng302.controllers.annotations;
import java.util.HashMap;
import java.util.Map;
public class ImportantAnnotationsState {
public static final Boolean DEFAULT_ANNOTATION_STATE = true;
private Map<Annotation, Boolean> currentState;
/**
* Stores the users preference for the annotations
* they consider to be important
*/
public ImportantAnnotationsState(){
this.currentState = new HashMap<>();
initialiseState();
}
/**
* Set each annotation to the default annotation state
*/
private void initialiseState(){
for (Annotation annotation : getAnnotations()){
currentState.put(annotation, DEFAULT_ANNOTATION_STATE);
}
}
/**
* Sets the state (visibility) of an annotation
* @param annotation The annotation to set
* @param visible Whether or not the annotation should be visible
*/
public void setAnnotationState(Annotation annotation, Boolean visible){
this.currentState.put(annotation, visible);
}
/**
* Returns the state (visibility) of a specific annotation
* @param annotation The annotation to check
* @return True if visible, else false
*/
public Boolean getAnnotationState(Annotation annotation){
return this.currentState.containsKey(annotation) && this.currentState.get(annotation);
}
/**
* @return Return an array containing all defined annotations
*/
public Annotation[] getAnnotations(){
return Annotation.class.getEnumConstants();
}
}
-130
View File
@@ -1,130 +0,0 @@
package seng302.models;
import javafx.scene.paint.Color;
/**
* Represents a boat in the race.
*/
public class Boat {
private String teamName; // The name of the team, this is also the name of the boat
private double velocity; // In meters/second
private double lat; // Boats position
private double lon; // -
private double distanceToNextMark;
private Color color;
private int markLastPast;
private double heading;
private String shortName;
public Boat(String teamName) {
this.teamName = teamName;
this.velocity = 10; // Default velocity
this.lat = 0.0;
this.lon = 0.0;
this.distanceToNextMark = 0.0;
this.shortName = "";
}
/**
* Represents a boat in the race.
*
* @param teamName The name of the team sailing the boat
* @param boatVelocity The speed of the boat in meters/second
* @param shortName A shorter version of the teams name
*/
public Boat(String teamName, double boatVelocity, String shortName) {
this.teamName = teamName;
this.velocity = boatVelocity;
this.distanceToNextMark = 0.0;
this.color = Colors.getColor();
this.shortName = shortName;
}
/**
* Returns the name of the team sailing the boat
*
* @return The name of the team
*/
public String getTeamName() {
return this.teamName;
}
/**
* Sets the name of the team sailing the boat
*
* @param teamName The name of the team
*/
public void setTeamName(String teamName) {
this.teamName = teamName;
}
/**
* Gets velocity of the boat
*
* @return a float number of the boat velocity
*/
public double getVelocity() {
return this.velocity;
}
/**
* Sets velocity of the boat
*
* @param velocity The velocity of boat
*/
public void setVelocity(double velocity) {
this.velocity = velocity;
}
/**
* Sets the boats location
*
* @param lat, the boats latitude
* @param lon, the boats longitude
*/
public void setLocation(double lat, double lon) {
this.lat = lat;
this.lon = lon;
}
public void setDistanceToNextMark(double distance){
this.distanceToNextMark = distance;
}
public double getLatitude(){
return this.lat;
}
public double getLongitude(){
return this.lon;
}
public Color getColor() {
return color;
}
public double getSpeedInKnots(){
return Math.round((this.velocity * 1.94384) * 100d) / 100d;
}
public void setMarkLastPast(int markLastPast) {
this.markLastPast = markLastPast;
}
public int getMarkLastPast() {
return markLastPast;
}
public void setHeading(double heading){
this.heading = heading;
}
public double getHeading(){
return this.heading;
}
public String getShortName(){
return this.shortName;
}
}
+509
View File
@@ -0,0 +1,509 @@
package seng302.models;
import java.util.ArrayList;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.CacheHint;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.text.Text;
import javafx.scene.transform.Rotate;
import seng302.GeometryUtils;
import seng302.controllers.CanvasController;
import seng302.models.mark.GateMark;
import seng302.models.mark.Mark;
import seng302.models.mark.SingleMark;
import seng302.models.stream.StreamParser;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
* dimensional boat. It contains a single polygon for the boat, a group of lines to show it's path,
* a wake object and two text labels to annotate the boat teams name and the boats velocity. The
* boat will update it's position onscreen everytime UpdatePosition is called unless the window is
* minimized in which case it attempts to store animations and apply them when the window is
* maximised.
*/
public class BoatGroup extends Group {
//Constants for drawing
private static final double TEAMNAME_X_OFFSET = 10d;
private static final double TEAMNAME_Y_OFFSET = -29d;
private static final double VELOCITY_X_OFFSET = 10d;
private static final double VELOCITY_Y_OFFSET = -17d;
private static final double ESTTIMETONEXTMARK_X_OFFSET = 10d;
private static final double ESTTIMETONEXTMARK_Y_OFFSET = -5d;
private static final double LEGTIME_X_OFFSET = 10d;
private static final double LEGTIME_Y_OFFSET = 7d;
private static final double BOAT_HEIGHT = 15d;
private static final double BOAT_WIDTH = 10d;
//Variables for boat logic.
private boolean isStopped = true;
private double xIncrement;
private double yIncrement;
private long lastTimeValid = 0;
private Double lastRotation = 0.0;
private long framesToMove;
//Graphical objects
private Yacht boat;
private Group lineGroup = new Group();
private Polygon boatPoly;
private Text teamNameObject;
private Text velocityObject;
private Text estTimeToNextMarkObject;
private Text legTimeObject;
private Wake wake;
private Line leftLayLine;
private Line rightLayline;
private Double distanceTravelled = 0.0;
private Point2D lastPoint;
private boolean destinationSet;
private Color textColor = Color.RED;
private Boolean isSelected = true; //All boats are initalised as selected
/**
* Creates a BoatGroup with the default triangular boat polygon.
*
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used
* to tell which BoatGroup to update.
* @param color The colour of the boat polygon and the trailing line.
*/
public BoatGroup(Yacht boat, Color color) {
this.boat = boat;
initChildren(color);
this.textColor = color;
}
/**
* Creates a BoatGroup with the boat being the default polygon. The head of the boat should be
* at point (0,0).
*
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used
* to tell which BoatGroup to update.
* @param color The colour of the boat polygon and the trailing line.
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat
* polygon.
*/
public BoatGroup(Yacht boat, Color color, double... points) {
this.boat = boat;
initChildren(color, points);
}
/**
* Return a text object with caching and a color applied
*
* @param defaultText The default text to display
* @param fill The text fill color
* @return The text object
*/
private Text getTextObject(String defaultText, Color fill) {
Text text = new Text(defaultText);
text.setFill(fill);
text.setCacheHint(CacheHint.SPEED);
text.setCache(true);
return text;
}
/**
* Creates the javafx objects that will be the in the group by default.
*
* @param color The colour of the boat polygon and the trailing line.
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat
* polygon.
*/
private void initChildren(Color color, double... points) {
textColor = color;
destinationSet = false;
boatPoly = new Polygon(points);
boatPoly.setFill(color);
boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
boatPoly.setOnMouseExited(event -> boatPoly.setFill(color));
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED);
teamNameObject = getTextObject(boat.getShortName(), textColor);
velocityObject = getTextObject(boat.getVelocity().toString(), textColor);
teamNameObject.setX(TEAMNAME_X_OFFSET);
teamNameObject.setY(TEAMNAME_Y_OFFSET);
teamNameObject.relocate(teamNameObject.getX(), teamNameObject.getY());
velocityObject.setX(VELOCITY_X_OFFSET);
velocityObject.setY(VELOCITY_Y_OFFSET);
velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
updateLastMarkRoundingTime();
updateTimeTillNextMark();
if (estTimeToNextMarkObject != null) {
estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET);
estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET);
estTimeToNextMarkObject
.relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY());
}
if (legTimeObject != null) {
legTimeObject.setX(LEGTIME_X_OFFSET);
legTimeObject.setY(LEGTIME_Y_OFFSET);
legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY());
}
leftLayLine = new Line();
rightLayline = new Line();
wake = new Wake(0, -BOAT_HEIGHT);
super.getChildren()
.addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject,
legTimeObject, leftLayLine, rightLayline);
}
/**
* Creates the javafx objects that will be the in the group by default.
*
* @param color The colour of the boat polygon and the trailing line.
*/
private void initChildren(Color color) {
initChildren(color,
-BOAT_WIDTH / 2, BOAT_HEIGHT / 2,
0.0, -BOAT_HEIGHT / 2,
BOAT_WIDTH / 2, BOAT_HEIGHT / 2);
}
/**
* Moves the boat and its children annotations from its current coordinates by specified
* amounts.
*
* @param dx The amount to move the X coordinate by
* @param dy The amount to move the Y coordinate by
*/
private void moveGroupBy(double dx, double dy) {
boatPoly.setLayoutX(boatPoly.getLayoutX() + dx);
boatPoly.setLayoutY(boatPoly.getLayoutY() + dy);
teamNameObject.setLayoutX(teamNameObject.getLayoutX() + dx);
teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy);
velocityObject.setLayoutX(velocityObject.getLayoutX() + dx);
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
estTimeToNextMarkObject.setLayoutX(estTimeToNextMarkObject.getLayoutX() + dx);
estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy);
legTimeObject.setLayoutX(legTimeObject.getLayoutX() + dx);
legTimeObject.setLayoutY(legTimeObject.getLayoutY() + dy);
wake.setLayoutX(wake.getLayoutX() + dx);
wake.setLayoutY(wake.getLayoutY() + dy);
}
/**
* Moves the boat and its children annotations to coordinates specified
*
* @param x The X coordinate to move the boat to
* @param y The Y coordinate to move the boat to
*/
private void moveTo(double x, double y, double rotation) {
rotateTo(rotation);
boatPoly.setLayoutX(x);
boatPoly.setLayoutY(y);
teamNameObject.setLayoutX(x);
teamNameObject.setLayoutY(y);
velocityObject.setLayoutX(x);
velocityObject.setLayoutY(y);
estTimeToNextMarkObject.setLayoutX(x);
estTimeToNextMarkObject.setLayoutY(y);
legTimeObject.setLayoutX(x);
legTimeObject.setLayoutY(y);
wake.setLayoutX(x);
wake.setLayoutY(y);
wake.rotate(rotation);
}
private void rotateTo(double rotation) {
boatPoly.getTransforms().setAll(new Rotate(rotation));
}
/**
* Updates the time until next mark label, will create a label if one doesn't exist
*/
private void updateTimeTillNextMark() {
if (estTimeToNextMarkObject == null) {
estTimeToNextMarkObject = getTextObject("Next mark: -", textColor);
}
if (boat.getEstimateTimeAtNextMark() != null) {
DateFormat format = new SimpleDateFormat("mm:ss");
String timeToNextMark = format
.format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
} else {
estTimeToNextMarkObject.setText("Next mark: -");
}
}
/**
* Updates the time since last mark rounding, will create a label if one doesn't exist
*/
private void updateLastMarkRoundingTime() {
if (legTimeObject == null) {
legTimeObject = getTextObject("Last mark: -", textColor);
}
if (boat.getMarkRoundingTime() != null) {
DateFormat format = new SimpleDateFormat("mm:ss");
String elapsedTime = format
.format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundingTime());
legTimeObject.setText("Last mark: " + elapsedTime);
} else {
legTimeObject.setText("Last mark: -");
}
}
public void move() {
double dx = xIncrement * framesToMove;
double dy = yIncrement * framesToMove;
distanceTravelled += Math.abs(dx) + Math.abs(dy);
moveGroupBy(xIncrement, yIncrement);
framesToMove = framesToMove - 1;
if (framesToMove <= 0) {
isStopped = true;
}
if (distanceTravelled > 70) {
distanceTravelled = 0d;
if (lastPoint != null) {
Line l = new Line(
lastPoint.getX(),
lastPoint.getY(),
boatPoly.getLayoutX(),
boatPoly.getLayoutY()
);
l.getStrokeDashArray().setAll(3d, 7d);
l.setStroke(boat.getColour());
l.setCache(true);
l.setCacheHint(CacheHint.SPEED);
lineGroup.getChildren().add(l);
}
if (destinationSet) {
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
}
}
wake.updatePosition(1000 / 60);
}
/**
* Calculates the rotational velocity required to reach the rotationalGoal from the
* currentRotation.
*/
protected Double calculateRotationalVelocity(Double rotationalGoal) {
Double rotationalVelocity = 0.0;
if (Math.abs(rotationalGoal - lastRotation) > 180) {
if (rotationalGoal - lastRotation >= 0.0) {
rotationalVelocity = ((rotationalGoal - lastRotation) - 360) / 200;
} else {
rotationalVelocity = (360 + (rotationalGoal - lastRotation)) / 200;
}
} else {
rotationalVelocity = (rotationalGoal - lastRotation) / 200;
}
//Sometimes the rotation is too large to be realistic. In that case just do it instantly.
if (Math.abs(rotationalVelocity) > 1) {
rotationalVelocity = 0.0;
}
return rotationalVelocity;
}
/**
* Sets the destination of the boat and the headng it should have once it reaches
*
* @param newXValue The X co-ordinate the boat needs to move to.
* @param newYValue The Y co-ordinate the boat needs to move to.
* @param rotation Rotation to move graphics to.
* @param timeValid the time the position values are valid for
*/
public void setDestination(double newXValue, double newYValue, double rotation,
double groundSpeed, long timeValid, double frameRate, long id) {
if (lastTimeValid == 0) {
lastTimeValid = timeValid - 200;
moveTo(newXValue, newYValue, rotation);
}
framesToMove = Math.round((frameRate / (1000.0f / (timeValid - lastTimeValid))));
double dx = newXValue - boatPoly.getLayoutX();
double dy = newYValue - boatPoly.getLayoutY();
xIncrement = dx / framesToMove;
yIncrement = dy / framesToMove;
destinationSet = true;
Double rotationalVelocity = calculateRotationalVelocity(rotation);
updateTimeTillNextMark();
updateLastMarkRoundingTime();
if (Math.abs(rotationalVelocity) > 0.075) {
rotationalVelocity = 0.0;
wake.rotate(rotation);
}
rotateTo(rotation);
wake.setRotationalVelocity(rotationalVelocity, groundSpeed);
velocityObject.setText(String.format("%.2f m/s", groundSpeed));
lastTimeValid = timeValid;
isStopped = false;
lastRotation = rotation;
}
/**
* This function works out if a boat is going upwind or down wind. It looks at the boats current position, the next
* gates position and the current wind
* If bot the wind vector from the next gate and the boat from the next gate lay on the same side, then the boat is
* going up wind, if they are on different sides of the gate, then the boat is going downwind
* @param canvasController
*/
public Boolean isUpwindLeg(CanvasController canvasController, Mark nextMark) {
Double windAngle = StreamParser.getWindDirection();
GateMark thisGateMark = (GateMark) nextMark;
SingleMark nextMark1 = thisGateMark.getSingleMark1();
SingleMark nextMark2 = thisGateMark.getSingleMark2();
Point2D nextMarkPoint1 = canvasController.findScaledXY(nextMark1.getLatitude(), nextMark1.getLongitude());
Point2D nextMarkPoint2 = canvasController.findScaledXY(nextMark2.getLatitude(), nextMark2.getLongitude());
Point2D boatCurrentPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
Point2D windTestPoint = GeometryUtils.makeArbitraryVectorPoint(nextMarkPoint1, windAngle, 10d);
Integer boatLineFuncResult = GeometryUtils.lineFunction(nextMarkPoint1, nextMarkPoint2, boatCurrentPoint);
Integer windLineFuncResult = GeometryUtils.lineFunction(nextMarkPoint1, nextMarkPoint2, windTestPoint);
/*
If both the wind vector from the gate and the boat from the gate are on the same side of that gate, then the
boat is travelling into the wind. thus upwind. Otherwise if they are on different sides, then the boat is going
with the wind.
*/
if (boatLineFuncResult == windLineFuncResult) {
return true;
} else {
return false;
}
}
public void setIsSelected(Boolean isSelected) {
this.isSelected = isSelected;
setTeamNameObjectVisible(isSelected);
setVelocityObjectVisible(isSelected);
setLineGroupVisible(isSelected);
setWakeVisible(isSelected);
setEstTimeToNextMarkObjectVisible(isSelected);
setLegTimeObjectVisible(isSelected);
setLayLinesVisible(isSelected);
}
public void setTeamNameObjectVisible(Boolean visible) {
teamNameObject.setVisible(visible);
}
public void setVelocityObjectVisible(Boolean visible) {
velocityObject.setVisible(visible);
}
public void setEstTimeToNextMarkObjectVisible(Boolean visible) {
estTimeToNextMarkObject.setVisible(visible);
}
public void setLegTimeObjectVisible(Boolean visible) {
legTimeObject.setVisible(visible);
}
public void setLineGroupVisible(Boolean visible) {
lineGroup.setVisible(visible);
}
public void setWakeVisible(Boolean visible) {
wake.setVisible(visible);
}
public void setLayLinesVisible(Boolean visible) {
leftLayLine.setVisible(visible);
rightLayline.setVisible(visible);
}
public void setLaylines(Line line1, Line line2) {
this.leftLayLine = line1;
this.rightLayline = line2;
}
public ArrayList<Line> getLaylines() {
ArrayList<Line> laylines = new ArrayList<>();
laylines.add(leftLayLine);
laylines.add(rightLayline);
return laylines;
}
public Yacht getBoat() {
return boat;
}
/**
* Returns all raceIds associated with this group. For BoatGroups the ID's are for the boat.
*
* @return An array containing all ID's associated with this RaceObject.
*/
public long getRaceId() {
return boat.getSourceID();
}
/**
* Due to javaFX limitations annotations associated with a boat that you want to appear below
* all boats in the Z-axis need to be pulled out of the BoatGroup and added to the parent group
* of the BoatGroups. This function returns these annotations as a group.
*
* @return A group containing low priority annotations.
*/
public Group getLowPriorityAnnotations() {
Group group = new Group();
group.getChildren().addAll(wake, lineGroup);
return group;
}
public Double getBoatLayoutX() {
return boatPoly.getLayoutX();
}
public Double getBoatLayoutY() {
return boatPoly.getLayoutY();
}
public boolean isStopped() {
return isStopped;
}
@Override
public String toString() {
return boat.toString();
}
}
+5 -6
View File
@@ -3,18 +3,17 @@ package seng302.models;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
/** /**
* Created by ryan_ on 16/03/2017. * Enum for randomly generating colours.
*/ */
public enum Colors { public enum Colors {
RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE; RED, PERU, SEAGREEN, GREEN, BLUE, PURPLE;
static Integer index = 0; static Integer index = 0;
public static Color getColor() { public static Color getColor() {
index++; if (index == 6) {
if (index > 6) { index = 0;
index = 1;
} }
return Color.valueOf(values()[index-1].toString()); return Color.valueOf(values()[index++].toString());
} }
} }
-148
View File
@@ -1,148 +0,0 @@
package seng302.models;
import seng302.models.mark.Mark;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Event class containing the time of specific event, related team/boat, and
* event location such as leg.
*/
public class Event {
private Double time; // Time the event occurs
private Boat boat;
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
private Mark mark1; // This mark
private Mark mark2; // Next mark
private int markPosInRace; // the position of the current mark in the race course
private final double ORIGIN_LAT = 32.320504;
private final double ORIGIN_LON = -64.857063;
private final double SCALE = 16000;
/**
* Event class containing the time of specific event, related team/boat, and
* event location such as leg.
*
* @param eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to
*/
public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2, int markPosInRace) {
this.time = eventTime;
this.boat = eventBoat;
this.mark1 = mark1;
this.mark2 = mark2;
this.markPosInRace = markPosInRace;
}
/**
* Event class containing the time of specific event, related team/boat, and
* event location such as leg.
*
* @param eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to
*/
public Event(Double eventTime, Boat eventBoat, Mark mark1, int markPosInRace) {
this.time = eventTime;
this.boat = eventBoat;
this.mark1 = mark1;
this.markPosInRace = markPosInRace;
this.isFinishingEvent = true;
}
public double getTime() {
return this.time;
}
public void setTime(double eventTime) {
this.time = eventTime;
}
/**
* Gets the time in a formatted string
*
* @return the string of time
*/
public String getTimeString() {
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue()));
}
public Boat getBoat() {
return this.boat;
}
public void setBoat(Boat eventBoat) {
this.boat = eventBoat;
}
public boolean getIsFinishingEvent() {
return this.isFinishingEvent;
}
/**
* Get a string that contains the timestamp and course information for this event
*
* @return A string that details what happened in this event
*/
public String getEventString() {
// This event is a boat finishing the race
if (this.isFinishingEvent) {
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
}
System.out.println(this.getDistanceBetweenMarks());
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°");
}
/**
* @return the distance between the two marks
*/
public double getDistanceBetweenMarks() {
double earth_radius = 6378.137;
double dLat = this.mark2.getLatitude() * Math.PI / 180 - this.mark1.getLatitude() * Math.PI / 180;
double dLon = this.mark2.getLongitude() * Math.PI / 180 - this.mark1.getLongitude() * Math.PI / 180;
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.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;
}
/**
* Calculates current boat heading direction.
* @return the boats heading as degree. vertical upward is 0 degree, and degree goes up clockwise.
*/
public double getBoatHeading() {
if (mark2 == null){
return 0.0;
}
double x1 = (mark1.getLongitude() - ORIGIN_LON) * SCALE;
double y1 = (ORIGIN_LAT - mark1.getLatitude()) * SCALE;
double x2 = (mark2.getLongitude() - ORIGIN_LON) * SCALE;
double y2 = (ORIGIN_LAT - mark2.getLatitude()) * SCALE;
double headingRadians = Math.atan2(y2-y1, x2-x1);
if (headingRadians < 0){
headingRadians += 2 * Math.PI;
}
// Convert back to degrees, and flip 180 degrees
// return ((headingRadians) * 180) / Math.PI;
return (Math.toDegrees(headingRadians) + 90) % 360;
}
public Mark getThisMark() {
return this.mark1;
}
public int getMarkPosInRace() {
return markPosInRace;
}
}
-109
View File
@@ -1,109 +0,0 @@
package seng302.models;
import seng302.models.mark.SingleMark;
/**
* Represents the leg of a race.
*/
public class Leg {
private int heading;
private int distance;
private boolean isFinishingLeg;
private SingleMark startingSingleMark;
/**
* Create a new leg
*
* @param heading, the magnetic heading of this leg
* @param distance, the total distance of this leg in meters
* @param singleMark, the singleMark this leg starts on
*/
public Leg(int heading, int distance, SingleMark singleMark) {
this.heading = heading;
this.distance = distance;
this.startingSingleMark = singleMark;
this.isFinishingLeg = false;
}
/**
* Create a new leg
*
* @param heading, the magnetic heading of this leg
* @param distance, the total distance of this leg in meters
* @param markerName, the name of the marker this leg starts on
*/
public Leg(int heading, int distance, String markerName) {
this.heading = heading;
this.distance = distance;
this.startingSingleMark = new SingleMark(markerName);
this.isFinishingLeg = false;
}
/**
* Get the heading of this leg
*/
public int getHeading() {
return this.heading;
}
/**
* Set the heading for this leg
*/
public void setHeading(int heading) {
this.heading = heading;
}
/**
* Get the total distance of this leg in meters
*/
public int getDistance() {
return this.distance;
}
/**
* Set the distance of this leg in meters
*/
public void setDistance(int distance) {
this.distance = distance;
}
/**
* Returns the marker this leg started on
*/
public SingleMark getMarker() {
return this.startingSingleMark;
}
/**
* Set the singleMark this leg starts on
*/
public void setMarker(SingleMark singleMark) {
this.startingSingleMark = singleMark;
}
/**
* Returns the name of the marker this leg started on
*/
public String getMarkerLabel() {
return this.startingSingleMark.getName();
}
/**
* Specify whether or not the race finishes on this leg
*
* @param isFinishingLeg whether or not the race finishes on this leg
*/
public void setFinishingLeg(boolean isFinishingLeg) {
this.isFinishingLeg = isFinishingLeg;
}
/**
* Returns whether or not the race finishes after this leg
* @return true if this the race finishes after this leg
*/
public boolean getIsFinishingLeg() {
return this.isFinishingLeg;
}
}
@@ -0,0 +1,163 @@
package seng302.models;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
/**
* A static class for parsing and storing the polars. Will parse the whole polar table and also store the optimised
* upwind and downwind in separate tables here as well
* Created by wmu16 on 22/05/17.
*/
public final class PolarTable {
//A Polar table will consist of a wind speed key to a hashmap value of pairs of wind angles and boat speeds
private static HashMap<Double, HashMap<Double, Double>> polarTable;
private static HashMap<Double, HashMap<Double, Double>> upwindOptimal;
private static HashMap<Double, HashMap<Double, Double>> downwindOptimal;
private static int upTwaIndex;
private static int dnTwaIndex;
/**
* Iterates through each row of the polar table, in pairs, to extract the row into a hashmap of angle to boat speed.
* These angle boatspeed hashmaps are then added to an outer hashmap at the end of wind speed key to each row hashmap
* as a value
* @param file containing the polar csv information
*/
public static void parsePolarFile(String file) {
polarTable = new HashMap<>();
upwindOptimal = new HashMap<>();
downwindOptimal = new HashMap<>();
String line;
Boolean isHeaderLine = true;
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
while ((line = br.readLine()) != null) {
String[] thisLine = line.split(",");
//Initial line in file
if (isHeaderLine) {
deduceHeaders(thisLine);
isHeaderLine = false;
} else {
HashMap<Double, Double> thisPolar = new HashMap<>();
HashMap<Double, Double> thisUpWindPolar = new HashMap<>();
HashMap<Double, Double> thisDnWindPolar = new HashMap<>();
Double thisWindSpeed = Double.parseDouble(thisLine[0]);
// -3 <== -1 for length -1, and a further -2 as we iterate in pairs of 2 so finish before final 2
for (int i = 1; i < thisLine.length; i += 2) {
Double thisWindAngle = Double.parseDouble(thisLine[i]);
Double thisBoatSpeed = Double.parseDouble(thisLine[i + 1]);
thisPolar.put(thisWindAngle, thisBoatSpeed);
if (i == upTwaIndex) {
thisUpWindPolar.put(thisWindAngle, thisBoatSpeed);
} else if (i == dnTwaIndex) {
thisDnWindPolar.put(thisWindAngle, thisBoatSpeed);
}
}
polarTable.put(thisWindSpeed, thisPolar);
upwindOptimal.put(thisWindSpeed, thisUpWindPolar);
downwindOptimal.put(thisWindSpeed, thisDnWindPolar);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Parses the header line of a polar file
* @param thisLine The line which is the header of a polar file
*/
private static void deduceHeaders(String[] thisLine) {
for (int i = 0; i < thisLine.length; i++) {
String thisItem = thisLine[i];
if (thisItem.toLowerCase().startsWith("uptwa")) {
upTwaIndex = i;
}
else if (thisItem.toLowerCase().startsWith("dntwa")) {
dnTwaIndex = i;
}
}
}
/**
* @return The entire polar table
*/
public static HashMap<Double, HashMap<Double, Double>> getPolarTable() {
return polarTable;
}
/**
* @return The polar table just containing the optimal upwind values
*/
public static HashMap<Double, HashMap<Double, Double>> getUpwindOptimal() {
return upwindOptimal;
}
/**
* @return The polar table just containing the optimal downwind values
*/
public static HashMap<Double, HashMap<Double, Double>> getDownwindOptimal() {
return downwindOptimal;
}
/**
* Will raise an exception if a polar table has just one row of data
* @param thisWindSpeed The current wind speed
* @return HashMap containing just the optimal upwind angle and resulting boat speed
*/
public static HashMap<Double, Double> getOptimalUpwindVMG(Double thisWindSpeed) {
Double polarWindSpeed = getClosestMatch(thisWindSpeed);
return upwindOptimal.get(polarWindSpeed);
}
/**
* Will raise an exception if a polar table has just one row of data
* @param thisWindSpeed The current wind speed
* @return HashMap containing just the optimal downwind angle and resulting boat speed
*/
public static HashMap<Double, Double> getOptimalDownwindVMG(Double thisWindSpeed) {
Double polarWindSpeed = getClosestMatch(thisWindSpeed);
return downwindOptimal.get(polarWindSpeed);
}
private static Double getClosestMatch(Double thisWindSpeed) {
ArrayList<Double> windValues = new ArrayList<>(polarTable.keySet());
Double lowerVal = windValues.get(0);
Double upperVal = windValues.get(1);
for(int i = 0; i < windValues.size() - 1; i++) {
lowerVal = windValues.get(i);
upperVal = windValues.get(i+1);
if (thisWindSpeed <= upperVal) {
break;
}
}
Double lowerDiff = Math.abs(lowerVal - thisWindSpeed);
Double upperDiff = Math.abs(upperVal - thisWindSpeed);
return (lowerDiff <= upperDiff) ? lowerVal : upperVal;
}
}
-197
View File
@@ -1,197 +0,0 @@
package seng302.models;
import seng302.models.mark.Mark;
import java.util.*;
/**
* Race class containing the boats and legs in the race
* Created by mra106 on 8/3/2017.
*/
public class Race {
private ArrayList<Boat> boats; // The boats in the race
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race
private HashMap<Boat, List> events = new HashMap<>(); // The events that occur in the race
private List<Mark> course; // Marks in the race
private long startTime = 0;
private double timeScale = 1;
private boolean raceFinished = false; // Race is finished
private int raceTime = -2; // Current time in the race
/**
* Race class containing the boats and legs in the race
*/
public Race() {
this.boats = new ArrayList<>();
this.finishingOrder = new ArrayList<>();
this.course = new ArrayList<>();
}
/**
* Add a boat to the race
*
* @param boat, the boat to add
*/
public void addBoat(Boat boat) {
boats.add(boat);
}
/**
* Returns a list of boats in a random order
*
* @returns a list of boats
*/
public Boat[] getShuffledBoats() {
// Shuffle the list of boats
long seed = System.nanoTime();
Collections.shuffle(this.boats, new Random(seed));
return boats.toArray(new Boat[boats.size()]);
}
/**
* Returns a list of boats in the order that they
* finished the race (position 0 is first place)
*
* @returns a list of boats
*/
public Boat[] getFinishedBoats() {
return this.finishingOrder.toArray(new Boat[this.finishingOrder.size()]);
}
/**
* Returns a list of boats in the race
*
* @return a list of the boats competing in the race
*/
public Boat[] getBoats() {
return boats.toArray(new Boat[boats.size()]);
}
/**
* Sets time scale
*
* @param timeScale
*/
public void setTimeScale(double timeScale) {
this.timeScale = timeScale;
}
/**
* Generate all events that will happen during the race.
*/
private void generateEvents() {
for (Boat boat : this.boats) {
double totalDistance = 0;
int numberOfMarks = this.course.size();
for (int i = 0; i < numberOfMarks; i++) {
Double time = (totalDistance / boat.getVelocity() / timeScale);
// If there are singleMarks after this event
if (i < numberOfMarks - 1) {
Event event = new Event(time, boat, course.get(i), course.get(i + 1), i);
try {
events.get(boat).add(event);
} catch (NullPointerException e) {
events.put(boat, new ArrayList<>(Arrays.asList(event)));
}
totalDistance += event.getDistanceBetweenMarks();
System.out.println(totalDistance);
System.out.println(boat.getVelocity());
}
// There are no more marks after this event
else{
Event event = new Event(time, boat, course.get(i), i);
events.get(boat).add(event);
}
}
}
}
/**
* Starts a race and generates all events for the race.
*/
public void startRace() {
// record start time.
this.startTime = System.currentTimeMillis();
generateEvents();
}
/**
* Set the race course
* @param course a list of marks in the course
*/
public void addCourse(List<Mark> course) {
this.course = course;
}
/**
* Get a list of marks in the course
* @return
*/
public List<Mark> getCourse() {
return course;
}
/**
* Get a map of the events in the race
* @return
*/
public HashMap<Boat, List> getEvents() {
return events;
}
/**
* Set a boat as finished
* @param boat The boat that has finished the race
*/
public void setBoatFinished(Boat boat){
this.finishingOrder.add(boat);
}
/**
* Set the race as finished
*/
public void setRaceFinished(){
this.raceFinished = true;
}
/**
* Return whether or not the race is finished
* @return true if the race is finished
*/
public boolean isRaceFinished(){
return this.raceFinished;
}
/**
* Set the race time
* @param raceTime the race time in seconds
*/
public void setRaceTime(int raceTime){
this.raceTime = raceTime;
}
/**
* Return the race time
* @return the race time in seconds
*/
public int getRaceTime(){
return this.raceTime;
}
/**
* Increment the race time by one second
*/
public void incrementRaceTime(){
this.raceTime += this.timeScale;
}
}
@@ -1,31 +0,0 @@
package seng302.models;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
/**
* Created by zyt10 on 17/03/17.
* this class is literally just to associate a timeline with a DoubleProperty x and y
*/
public class TimelineInfo {
private Timeline timeline;
private DoubleProperty x;
private DoubleProperty y;
public TimelineInfo(Timeline timeline, DoubleProperty x, DoubleProperty y) {
this.timeline = timeline;
this.x = x;
this.y = y;
}
public Timeline getTimeline() {
return timeline;
}
public DoubleProperty getX() {
return x;
}
public DoubleProperty getY() {
return y;
}
}
+114
View File
@@ -0,0 +1,114 @@
package seng302.models;
import javafx.scene.CacheHint;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.transform.Rotate;
/**
* A group containing objects used to represent wakes onscreen. Contains functionality for their animation.
*/
class Wake extends Group {
//The number of wakes
private int numWakes = 8;
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
private final double MAX_DIFF = 75;
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
private final int UNIFICATION_SPEED = 750;
private Arc[] arcs = new Arc[numWakes];
private double[] rotationalVelocities = new double[numWakes];
private double[] rotations = new double[numWakes];
private double baseRad;
/**
* Create a wake at the given location.
*
* @param startingX x location where the tip of wake arcs will be.
* @param startingY y location where the tip of wake arcs will be.
*/
Wake(double startingX, double startingY) {
super.setLayoutX(startingX);
super.setLayoutY(startingY);
Arc arc;
for (int i = 0; i < numWakes; i++) {
//Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg.
arc = new Arc(0, 0, 0, 0, -110, 40);
arc.setCache(true);
arc.setCacheHint(CacheHint.SPEED);
arc.setType(ArcType.OPEN);
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
arc.setStrokeWidth(3.0);
arc.setStrokeLineCap(StrokeLineCap.ROUND);
arc.setFill(new Color(0.0, 0.0, 0.0, 0.0));
baseRad = (20 / numWakes);
arcs[i] = arc;
}
super.getChildren().addAll(arcs);
}
/**
* Sets the rotationalVelocity of each arc.
*
* @param rotationalVelocity The rotationalVelocity the wake should move at.
* @param velocity The real world velocity of the boat in m/s.
*/
void setRotationalVelocity(double rotationalVelocity, double velocity) {
rotationalVelocities[0] = rotationalVelocity;
for (int i = 1; i < numWakes; i++) {
double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
double shortestDistance = Math.atan2(
Math.sin(wakeSeparationRad),
Math.cos(wakeSeparationRad)
);
double distDeg = Math.toDegrees(shortestDistance);
if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
} else {
if (distDeg < (MAX_DIFF / numWakes))
rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
else
rotationalVelocities[i] = rotationalVelocities[i - 1];
}
}
double rad = baseRad + velocity;
for (Arc arc : arcs) {
arc.setRadiusX(rad);
arc.setRadiusY(rad);
rad += (20 / numWakes) + (velocity / 2);
}
}
/**
* Arcs rotate based on the distance they would have travelled over the supplied time interval.
*
* @param timeInterval the time interval, in microseconds, that the wake should move.
*/
void updatePosition(long timeInterval) {
for (int i = 0; i < numWakes; i++) {
rotations[i] = rotations[i] + rotationalVelocities[i] * timeInterval;
arcs[i].getTransforms().setAll(new Rotate(rotations[i]));
}
}
/**
* Rotate all wakes to the given rotation.
*
* @param rotation the from north angle in degrees to rotate to.
*/
void rotate(double rotation) {
for (int i = 0; i < arcs.length; i++) {
rotations[i] = rotation;
rotationalVelocities[i] = 0;
arcs[i].getTransforms().setAll(new Rotate(rotation));
}
}
}
+208
View File
@@ -0,0 +1,208 @@
package seng302.models;
import javafx.scene.paint.Color;
import seng302.models.mark.Mark;
import seng302.controllers.RaceViewController;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import seng302.models.stream.StreamParser;
import seng302.models.stream.XMLParser.RaceXMLObject.Corner;
/**
* Yacht class for the racing boat.
*
* Class created to store more variables (eg. boat statuses) compared to the XMLParser boat class,
* also done outside Boat class because some old variables are not used anymore.
*/
public class Yacht {
// Used in boat group
private Color colour;
private double velocity;
private String boatType;
private Integer sourceID;
private String hullID; //matches HullNum in the XML spec.
private String shortName;
private String boatName;
private String country;
// Boat status
private Integer boatStatus;
private Integer legNumber;
private Integer penaltiesAwarded;
private Integer penaltiesServed;
private Long estimateTimeAtNextMark;
private Long estimateTimeAtFinish;
private String position;
// Mark rounding
private Long markRoundingTime;
private Mark lastMarkRounded;
private Mark nextMark;
/**
* Used in EventTest and RaceTest.
*
* @param boatName Create a yacht object with name.
*/
public Yacht(String boatName) {
this.boatName = boatName;
}
/**
* Used in BoatGroupTest.
*
* @param boatName The name of the team sailing the boat
* @param boatVelocity The speed of the boat in meters/second
* @param shortName A shorter version of the teams name
*/
public Yacht(String boatName, double boatVelocity, String shortName, int id) {
this.boatName = boatName;
this.velocity = boatVelocity;
this.shortName = shortName;
this.sourceID = id;
}
public Yacht(String boatType, Integer sourceID, String hullID, String shortName,
String boatName, String country) {
this.boatType = boatType;
this.sourceID = sourceID;
this.hullID = hullID;
this.shortName = shortName;
this.boatName = boatName;
this.country = country;
this.position = "-";
}
public String getBoatType() {
return boatType;
}
public Integer getSourceID() {
return sourceID;
}
public String getHullID() {
return hullID;
}
public String getShortName() {
return shortName;
}
public String getBoatName() {
return boatName;
}
public String getCountry() {
return country;
}
public Integer getBoatStatus() {
return boatStatus;
}
public void setBoatStatus(Integer boatStatus) {
this.boatStatus = boatStatus;
}
public Integer getLegNumber() {
return legNumber;
}
public void setLegNumber(Integer legNumber) {
if (colour != null && position != "-" && legNumber != this.legNumber&& RaceViewController.sparkLineStatus(sourceID)) {
RaceViewController.updateYachtPositionSparkline(this, legNumber);
}
this.legNumber = legNumber;
}
public Integer getPenaltiesAwarded() {
return penaltiesAwarded;
}
public void setPenaltiesAwarded(Integer penaltiesAwarded) {
this.penaltiesAwarded = penaltiesAwarded;
}
public Integer getPenaltiesServed() {
return penaltiesServed;
}
public void setPenaltiesServed(Integer penaltiesServed) {
this.penaltiesServed = penaltiesServed;
}
public Long getEstimateTimeAtNextMark() {
// DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
// return format.format(estimateTimeAtNextMark);
return estimateTimeAtNextMark;
}
public void setEstimateTimeAtNextMark(Long estimateTimeAtNextMark) {
this.estimateTimeAtNextMark = estimateTimeAtNextMark;
}
public String getEstimateTimeAtFinish() {
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return format.format(estimateTimeAtFinish);
}
public void setEstimateTimeAtFinish(Long estimateTimeAtFinish) {
this.estimateTimeAtFinish = estimateTimeAtFinish;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public Color getColour() {
return colour;
}
public void setColour(Color colour) {
this.colour = colour;
}
public Double getVelocity() {
return velocity;
}
public void setVelocity(double velocity) {
this.velocity = velocity;
}
public Long getMarkRoundingTime() {
return markRoundingTime;
}
public void setMarkRoundingTime(Long markRoundingTime) {
this.markRoundingTime = markRoundingTime;
}
public Mark getLastMarkRounded() {
return lastMarkRounded;
}
public void setLastMarkRounded(Mark lastMarkRounded) {
this.lastMarkRounded = lastMarkRounded;
}
@Override
public String toString() {
return boatName;
}
public void setNextMark(Mark nextMark) {
this.nextMark = nextMark;
}
public Mark getNextMark(){
return nextMark;
}
}
@@ -0,0 +1,44 @@
package seng302.models.map;
/**
* The Boundary class represents a rectangle territorial boundary on a map. It
* contains four extremity double values(N, E, S, W). N and S are represented as
* latitudes in radians. E and W are represented as longitudes in radians.
*
* Created by Haoming on 10/5/17
*/
public class Boundary {
private double northLat, eastLng, southLat, westLng;
public Boundary(double northLat, double eastLng, double southLat, double westLng) {
this.northLat = northLat;
this.eastLng = eastLng;
this.southLat = southLat;
this.westLng = westLng;
}
double getCentreLat() {
return (northLat + southLat) / 2;
}
double getCentreLng() {
return (eastLng + westLng) / 2;
}
double getNorthLat() {
return northLat;
}
double getEastLng() {
return eastLng;
}
double getSouthLat() {
return southLat;
}
double getWestLng() {
return westLng;
}
}
@@ -0,0 +1,104 @@
package seng302.models.map;
import javafx.scene.image.Image;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
import java.lang.Math;
/**
* CanvasMap retrieves a map image with given geo boundary from Google Map server.
* By passing a rectangle like geo boundary, it returns a map image with the
* highest resolution. However, due to free quote account usage limit, the maximum
* resolution is only 1280 * 1280.
*
* Created by Haoming on 15/5/2017
*/
public class CanvasMap {
private Boundary boundary;
private long width, height; // desired image size
private int zoom;
private String KEY = "AIzaSyC-5oOShMCY5Oy_9L7guYMPUPFHDMr37wE";
public CanvasMap(Boundary boundary) {
this.boundary = boundary;
calculateOptimalMapSize();
}
public Image getMapImage() {
try {
URL url = new URL(getRequest());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
return new Image(connection.getInputStream());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private String getRequest() {
StringBuilder sb = new StringBuilder();
sb.append("https://maps.googleapis.com/maps/api/staticmap?");
sb.append(String.format("center=%f,%f", boundary.getCentreLat(), boundary.getCentreLng()));
sb.append(String.format("&zoom=%d", zoom));
sb.append(String.format("&size=%dx%d&scale=2", width, height));
sb.append("&style=feature:all|element:labels|visibility:off"); // hide all labels on map
// sb.append(String.format("&markers=%f,%f", boundary.getSouthLat(), boundary.getWestLng()));
// sb.append(String.format("&key=%s", KEY));
return sb.toString();
}
private void calculateOptimalMapSize() {
for (int z = 20; z > 0; z--) {
MapSize mapSize = getMapSize(z, boundary);
zoom = z;
width = mapSize.width;
height = mapSize.height;
// if map size is valid, exit the loop as we have the highest resolution
if (mapSize.isValid()) break;
}
}
private MapSize getMapSize(int zoom, Boundary boundary) {
double scale = Math.pow(2, zoom);
MapGeo geoSW = new MapGeo(boundary.getSouthLat(), boundary.getWestLng());
MapGeo geoNE = new MapGeo(boundary.getNorthLat(), boundary.getEastLng());
MapPoint pointSW = MercatorProjection.toMapPoint(geoSW);
MapPoint pointNE = MercatorProjection.toMapPoint(geoNE);
return new MapSize(Math.abs(pointNE.getX() - pointSW.getX()) * scale,
Math.abs(pointNE.getY() - pointSW.getY()) * scale);
}
class MapSize {
long width, height;
MapSize(double width, double height) {
this.width = Math.round(width);
this.height = Math.round(height);
}
/**
* Map size is valid when width and height are both less than 640 pixels
* @return true if both dimensions are less than 640px
*/
boolean isValid() {
return Math.max(width, height) <= 640;
}
}
public long getWidth() {
return width;
}
public long getHeight() {
return height;
}
public int getZoom() {
return zoom;
}
}
@@ -0,0 +1,31 @@
package seng302.models.map;
/**
* A class represent Geo location (latitude, longitude).
* Created by Haoming on 15/5/2017
*/
class MapGeo {
private double lat, lng;
MapGeo(double lat, double lng) {
this.lat = lat;
this.lng = lng;
}
double getLat() {
return lat;
}
void setLat(double lat) {
this.lat = lat;
}
double getLng() {
return lng;
}
void setLng(double lng) {
this.lng = lng;
}
}
@@ -0,0 +1,31 @@
package seng302.models.map;
/**
* A class represent euclidean planar point (x, y)
* Created by Haoming on 15/5/2017
*/
class MapPoint {
private double x, y;
MapPoint(double x, double y) {
this.x = x;
this.y = y;
}
double getX() {
return x;
}
void setX(double x) {
this.x = x;
}
double getY() {
return y;
}
void setY(double y) {
this.y = y;
}
}
@@ -0,0 +1,52 @@
package seng302.models.map;
/**
* An utility class useful to convert between Geo locations and Mercator projection
* planar coordinates.
* Created by Haoming on 15/5/2017
*/
public class MercatorProjection {
private static final double MERCATOR_RANGE = 256;
private static final double pixelsPerLngDegree = MERCATOR_RANGE / 360.0;
private static final double pixelsPerLngRadian = MERCATOR_RANGE / (2 * Math.PI);
/**
* A help function keeps the value in bound between -0.9999 and 0.9999.
* @param value in bound value
* @return the value in bound
*/
private static double bound(double value) {
return Math.min(Math.max(value, -0.9999), 0.9999);
}
/**
* Projects a Geo Location (lat, lng) on a planar
* @param geo MapGeo (lat, lng) location to be projected
* @return the projection GeoPoint (x, y) on planar
*/
public static MapPoint toMapPoint(MapGeo geo) {
MapPoint point = new MapPoint(0, 0);
MapPoint origin = new MapPoint(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
point.setX(origin.getX() + geo.getLng() * pixelsPerLngDegree);
// NOTE(appleton): Truncating to 0.9999 effectively limits latitude to
// 89.189. This is about a third of a tile past the edge of the world tile.
double sinY = bound(Math.sin(Math.toRadians(geo.getLat())));
point.setY(origin.getY() + 0.5 * Math.log((1 + sinY) / (1 - sinY)) * (-pixelsPerLngRadian));
return point;
}
/**
* Converts the planar projection (x, y) back to Geo Location (lat, lng)
* @param point MapPoint (x, y) to be converted back
* @return the original Geo location converted from the given projection point
*/
public static MapGeo toMapGeo(MapPoint point) {
MapPoint origin = new MapPoint(MERCATOR_RANGE / 2.0, MERCATOR_RANGE / 2.0);
double lng = (point.getX() - origin.getX()) / pixelsPerLngDegree;
double latRadians = (point.getY() - origin.getY()) / (-pixelsPerLngRadian);
double lat = Math.toDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2.0);
return new MapGeo(lat, lng);
}
}
@@ -0,0 +1,23 @@
package seng302.models.map;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import java.net.URL;
import java.util.ResourceBundle;
public class TestMapController implements Initializable{
@FXML
private Canvas mapCanvas;
@Override
public void initialize(URL location, ResourceBundle resources) {
GraphicsContext gc = mapCanvas.getGraphicsContext2D();
Boundary bound = new Boundary(57.662943, 11.848501, 57.673945, 11.824966);
CanvasMap canvasMap = new CanvasMap(bound);
gc.drawImage(canvasMap.getMapImage(), 0, 0, canvasMap.getWidth(), canvasMap.getHeight());
}
}
@@ -16,8 +16,8 @@ public class GateMark extends Mark {
* @param singleMark1 one single mark inside of the gate mark * @param singleMark1 one single mark inside of the gate mark
* @param singleMark2 the second mark inside of the gate mark * @param singleMark2 the second mark inside of the gate mark
*/ */
public GateMark(String name, SingleMark singleMark1, SingleMark singleMark2, double latitude, double longitude) { public GateMark(String name, MarkType type, SingleMark singleMark1, SingleMark singleMark2, double latitude, double longitude, int compoundMarkID) {
super(name, MarkType.GATE_MARK, latitude, longitude); super(name, type, latitude, longitude, compoundMarkID);
this.singleMark1 = singleMark1; this.singleMark1 = singleMark1;
this.singleMark2 = singleMark2; this.singleMark2 = singleMark2;
} }
@@ -39,12 +39,11 @@ public class GateMark extends Mark {
} }
public double getLatitude(){ public double getLatitude(){
//return (this.getSingleMark1().getLatitude() + this.getSingleMark2().getLatitude()) / 2;
return (this.getSingleMark1().getLatitude()); return (this.getSingleMark1().getLatitude());
} }
public double getLongitude(){ public double getLongitude(){
//return (this.getSingleMark1().getLongitude() + this.getSingleMark2().getLongitude()) / 2;
return (this.getSingleMark1().getLongitude()); return (this.getSingleMark1().getLongitude());
} }
} }
+96 -2
View File
@@ -10,22 +10,104 @@ public abstract class Mark {
private MarkType markType; private MarkType markType;
private double latitude; private double latitude;
private double longitude; private double longitude;
private long id;
private int compoundMarkID;
/** /**
* Create a mark instance by passing its name and type * Create a mark instance by passing its name and type
* @param name the name of the mark * @param name the name of the mark
* @param markType the type of mark. either GATE_MARK or SINGLE_MARK. * @param markType the type of mark. either GATE_MARK or SINGLE_MARK.
*/ */
public Mark (String name, MarkType markType) { public Mark (String name, MarkType markType, int sourceID, int compoundMarkID) {
this.name = name; this.name = name;
this.markType = markType; this.markType = markType;
this.id = sourceID;
this.compoundMarkID = compoundMarkID;
} }
public Mark(String name, MarkType markType, double latitude, double longitude) { public Mark(String name, MarkType markType, double latitude, double longitude, int compoundMarkID) {
this.name = name; this.name = name;
this.markType = markType; this.markType = markType;
this.latitude = latitude; this.latitude = latitude;
this.longitude = longitude; this.longitude = longitude;
this.id = 0;
this.compoundMarkID = compoundMarkID;
}
/**
* Calculated the heading in radians from first Mark to the second Mark.
*
* @param pointOne First Mark
* @param pointTwo Second Mark
* @return Heading in radians
*/
public static Double calculateHeadingRad(Mark pointOne, Mark pointTwo) {
Double longitude1 = pointOne.getLongitude();
Double longitude2 = pointTwo.getLongitude();
Double latitude1 = pointOne.getLatitude();
Double latitude2 = pointTwo.getLatitude();
return calculateHeadingRad(latitude1, longitude1, latitude2, longitude2);
}
/**
* Calculate the heading in radians from geographical location with latitude1, longitude 1 to
* geographical latitude2, longitude 2
*
* @param longitude1 Longitude of first point in degrees
* @param longitude2 Longitude of second point in degrees
* @param latitude1 Latitude of first point in degrees
* @param latitude2 Latitude of first point in degrees
* @return Heading in radians
*/
public static double calculateHeadingRad(Double latitude1, Double longitude1, Double latitude2,
Double longitude2) {
latitude1 = Math.toRadians(latitude1);
latitude2 = Math.toRadians(latitude2);
Double longDiff = Math.toRadians(longitude2 - longitude1);
Double y = Math.sin(longDiff) * Math.cos(latitude2);
Double x =
Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2)
* Math.cos(longDiff);
return Math.atan2(y, x);
}
/**
* Calculates the distance in meters from the first Mark to a second Mark
*
* @param pointOne First Mark
* @param pointTwo Second Mark
* @return Distance in meters
*/
public static Double calculateDistance(Mark pointOne, Mark pointTwo) {
Double longitude1 = pointOne.getLongitude();
Double longitude2 = pointTwo.getLongitude();
Double latitude1 = pointOne.getLatitude();
Double latitude2 = pointTwo.getLatitude();
return calculateDistance(latitude1, longitude1, latitude2, longitude2);
}
/**
* Calculate the distance in meters from geographical location with latitude1, longitude 1 to
* geographical latitude2, longitude 2
*
* @param longitude1 Longitude of first point in degrees
* @param longitude2 Longitude of second point in degrees
* @param latitude1 Latitude of first point in degrees
* @param latitude2 Latitude of first point in degrees
* @return Distance in meters
*/
public static Double calculateDistance(Double latitude1, Double longitude1, Double latitude2,
Double longitude2) {
Double theta = longitude1 - longitude2;
Double dist = Math.sin(Math.toRadians(latitude1)) * Math.sin(Math.toRadians(latitude2)) +
Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) *
Math.cos(Math.toRadians(theta));
dist = Math.acos(dist);
dist = Math.toDegrees(dist);
dist = dist * 60
* 1.1508; //nautical mile (distance between two degrees) * (degrees in a minute)
dist = dist * 1609.344; //ratio of miles to metres
return dist;
} }
public String getName() { public String getName() {
@@ -51,4 +133,16 @@ public abstract class Mark {
public double getLongitude() { public double getLongitude() {
return longitude; return longitude;
} }
public long getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getCompoundMarkID() {
return compoundMarkID;
}
} }
@@ -0,0 +1,163 @@
package seng302.models.mark;
import java.util.ArrayList;
import java.util.List;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import seng302.GeometryUtils;
/**
* Grouping of javaFX objects needed to represent a Mark on screen.
*/
public class MarkGroup extends Group {
private static int MARK_RADIUS = 5;
private static int LINE_THICKNESS = 2;
private static double DASHED_GAP_LEN = 2d;
private static double DASHED_LINE_LEN = 5d;
private List<Mark> marks = new ArrayList<>();
private Mark mainMark;
/**
* Constructor for singleMark groups
* @param mark
* @param points
*/
public MarkGroup (SingleMark mark, Point2D points) {
marks.add(mark);
mainMark = mark;
Color color = Color.BLACK;
if (mark.getName().equals("Start")){
color = Color.GREEN;
} else if (mark.getName().equals("Finish")){
color = Color.RED;
}
Circle markCircle;
markCircle = new Circle(
points.getX(),
points.getY(),
MARK_RADIUS,
color
);
super.getChildren().add(markCircle);
}
public void addLaylines(Line line1, Line line2) {
super.getChildren().addAll(line1, line2);
}
public void removeLaylines() {
ArrayList<Node> toRemove = new ArrayList<>();
for(Node node : super.getChildren()) {
if (node instanceof Line) {
Line layLine = (Line) node;
/***
* OOHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHhhh
*/
if (layLine.getStrokeWidth() == 0.5){
toRemove.add(layLine);
}
}
}
super.getChildren().removeAll(toRemove);
}
public MarkGroup(GateMark mark, Point2D points1, Point2D points2) {
marks.add(mark.getSingleMark1());
marks.add(mark.getSingleMark2());
mainMark = mark;
Color color = Color.BLACK;
if (mark.getName().equals("Start")){
color = Color.GREEN;
} else if (mark.getName().equals("Finish")){
color = Color.RED;
}
Circle markCircle;
markCircle = new Circle(
points1.getX(),
points1.getY(),
MARK_RADIUS,
color
);
super.getChildren().add(markCircle);
markCircle = new Circle(
points2.getX(),
points2.getY(),
MARK_RADIUS,
color
);
super.getChildren().add(markCircle);
Line line = new Line(
points1.getX(),
points1.getY(),
points2.getX(),
points2.getY()
);
line.setStrokeWidth(LINE_THICKNESS);
line.setStroke(color);
if (mark.getMarkType() == MarkType.OPEN_GATE) {
line.getStrokeDashArray().addAll(DASHED_GAP_LEN, DASHED_LINE_LEN);
}
super.getChildren().add(line);
//Laylines
// if (mark.)
// addLayLine(points1, 12.0, 90.0);
// addLayLine(points2, 12.0, 90.0);
}
public void moveMarkTo (double x, double y, long raceId)
{
if (mainMark.getMarkType() == MarkType.SINGLE_MARK) {
Circle markCircle = (Circle) super.getChildren().get(0);
markCircle.setCenterX(x);
markCircle.setCenterY(y);
} else {
Circle markCircle1 = (Circle) super.getChildren().get(0);
Circle markCircle2 = (Circle) super.getChildren().get(1);
Line connectingLine = (Line) super.getChildren().get(2);
if (marks.get(0).getId() == raceId) {
markCircle1.setCenterX(x);
markCircle1.setCenterY(y);
connectingLine.setStartX(markCircle1.getCenterX());
connectingLine.setStartY(markCircle1.getCenterY());
} else if (marks.get(1).getId() == raceId) {
markCircle2.setCenterX(x);
markCircle2.setCenterY(y);
connectingLine.setEndX(markCircle2.getCenterX());
connectingLine.setEndY(markCircle2.getCenterY());
}
}
}
public boolean hasRaceId (int... raceIds) {
for (int id : raceIds)
for (Mark mark : marks)
if (id == mark.getId())
return true;
return false;
}
public long[] getRaceIds () {
long[] idArray = new long[marks.size()];
int i = 0;
for (Mark mark : marks)
idArray[i++] = mark.getId();
return idArray;
}
public Mark getMainMark() {
return mainMark;
}
}
@@ -5,5 +5,5 @@ package seng302.models.mark;
* Created by Haoming Yin (hyi25) on 17/3/17. * Created by Haoming Yin (hyi25) on 17/3/17.
*/ */
public enum MarkType { public enum MarkType {
SINGLE_MARK, GATE_MARK SINGLE_MARK, OPEN_GATE
} }
@@ -10,7 +10,6 @@ public class SingleMark extends Mark {
private double lon; private double lon;
private String name; private String name;
/** /**
* Represents a marker * Represents a marker
* *
@@ -18,22 +17,12 @@ public class SingleMark extends Mark {
* @param lat, the latitude of the marker * @param lat, the latitude of the marker
* @param lon, the longitude of the marker * @param lon, the longitude of the marker
*/ */
public SingleMark(String name, double lat, double lon) { public SingleMark(String name, double lat, double lon, int sourceID, int compoundMarkID) {
super(name, MarkType.SINGLE_MARK); super(name, MarkType.SINGLE_MARK, sourceID, compoundMarkID);
this.lat = lat; this.lat = lat;
this.lon = lon; this.lon = lon;
} }
/**
* Represents the marker at the beginning of a leg
*
* @param name, the name of the marker
*/
public SingleMark(String name) {
super(name, MarkType.SINGLE_MARK);
this.lat = 0;
this.lon = 0;
}
public double getLatitude() { public double getLatitude() {
return this.lat; return this.lat;
@@ -1,78 +0,0 @@
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) {
} 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) {
} finally {
return string;
}
}
}
@@ -1,140 +0,0 @@
package seng302.models.parsers;
import org.w3c.dom.*;
import seng302.models.mark.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
/**
* parse a course xml file
* Created by Haoming Yin (hyi25) on 16/3/2017
*/
public class CourseParser extends FileParser {
private Document doc;
private HashMap<String, Mark> marks = new HashMap<>();
public CourseParser(String path) {
super(path);
this.doc = this.parseFile();
}
/**
* create a mark by given node
*
* @param node
* @return a mark, or null if fails to create a mark
*/
private SingleMark generateSingleMark(Node node) {
try {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String name = element.getElementsByTagName("name").item(0).getTextContent();
double lat = Double.valueOf(element.getElementsByTagName("latitude").item(0).getTextContent());
double lon = Double.valueOf(element.getElementsByTagName("longitude").item(0).getTextContent());
SingleMark singleMark = new SingleMark(name, lat, lon);
return singleMark;
} else {
throw new NoSuchElementException("Cannot generate a mark by given node.");
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* generate an arrayList of gates
*
* @return an arrayList of gates, or null if no gate has been found.
*/
private void generateGateMarks() {
ArrayList<GateMark> gateMarks = new ArrayList<>();
try {
NodeList nodes = doc.getElementsByTagName("gate");
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String name = element.getElementsByTagName("name").item(0).getTextContent();
SingleMark mark1 = generateSingleMark(element.getElementsByTagName("mark").item(0));
SingleMark mark2 = generateSingleMark(element.getElementsByTagName("mark").item(1));
GateMark gateMark = new GateMark(name, mark1, mark2, mark1.getLatitude(), mark1.getLongitude());
marks.put(name, gateMark);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* generate an arrayList of marks
*
* @return an arrayList of marks, or null if no gate has been found.
*/
private void generateSingleMarks() {
ArrayList<SingleMark> singleMarks = new ArrayList<>();
try {
// find the "marks" tag
Node node = doc.getElementsByTagName("marks").item(0);
// iterate all "marks"'s children
for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) {
// if node's tag name is "mark"
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) n;
if (element.getNodeName() == "mark") {
Mark mark = generateSingleMark(n);
marks.put(mark.getName(), mark);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* return the order of all the marks along a course
*
* @return an arrayList of the names of ordered course marks
*/
private ArrayList<String> getOrder() {
ArrayList<String> markOrder = new ArrayList<>();
try {
Node orderNode = doc.getElementsByTagName("order").item(0);
for (Node node = orderNode.getFirstChild(); node != null; node = node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String name = element.getTextContent();
markOrder.add(name);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return markOrder;
}
public ArrayList<Mark> getCourse() {
generateSingleMarks();
generateGateMarks();
ArrayList<Mark> course = new ArrayList<>();
try {
for (String mark : getOrder()) {
course.add(marks.get(mark));
}
} catch (Exception e) {
e.printStackTrace();
}
return course;
}
}
@@ -1,63 +0,0 @@
package seng302.models.parsers;
import org.w3c.dom.*;
import seng302.models.Boat;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class TeamsParser extends FileParser {
private Document doc;
public TeamsParser(String path) {
super(path);
this.doc = this.parseFile();
}
/**
* Create a boat instance by a given team node
* @param node a boat node containing name, alias and velocity
* @return an instance of Boat
*/
private Boat parseBoat(Node node) {
try {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String name = element.getElementsByTagName("name").item(0).getTextContent();
String alias = element.getElementsByTagName("alias").item(0).getTextContent();
double velocity = Double.valueOf(element.getElementsByTagName("velocity").item(0).getTextContent());
Boat boat = new Boat(name, velocity, alias);
return boat;
} else {
throw new NoSuchElementException("Cannot generate a boat by given node");
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Create an arraylist of boats instance.
* @return an arraylist of boats in teams file
*/
public ArrayList<Boat> getBoats() {
ArrayList<Boat> boats = new ArrayList<>();
try {
NodeList nodes = this.doc.getElementsByTagName("team");
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
boats.add(parseBoat(node));
}
return boats;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
@@ -0,0 +1,668 @@
package seng302.models.stream;
import java.io.IOException;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.PriorityBlockingQueue;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import seng302.models.Yacht;
import seng302.models.mark.Mark;
import seng302.models.stream.packets.BoatPositionPacket;
import seng302.models.stream.packets.StreamPacket;
/**
* The purpose of this class is to take in the stream of divided packets so they can be read
* and parsed in by turning the byte arrays into useful data. There are two public static hashmaps
* that are threadsafe so the visualiser can always access the latest speed and position available
* Created by kre39 on 23/04/17.
*/
public class StreamParser extends Thread {
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> markLocations = new ConcurrentHashMap<>();
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatLocations = new ConcurrentHashMap<>();
private String threadName;
private Thread t;
private static boolean newRaceXmlReceived = false;
private static boolean raceStarted = false;
private static XMLParser xmlObject;
private static boolean raceFinished = false;
private static boolean streamStatus = false;
private static long timeSinceStart = -1;
private static Map<Integer, Yacht> boats = new ConcurrentHashMap<>();
private static Map<Integer, Yacht> boatsPos = new ConcurrentSkipListMap<>();
private static double windDirection = 0;
private static Double windSpeed = 0d;
private static Long currentTimeLong;
private static String currentTimeString;
private static boolean appRunning;
//CONVERSION CONSTANTS
private static final Double MS_TO_KNOTS = 1.94384;
/**
* Used to initialise the thread name and stream parser object so a thread can be executed
*
* @param threadName name of the thread
*/
public StreamParser(String threadName) {
this.threadName = threadName;
}
/**
* Used to within threading so when the stream parser thread runs, it will keep looking for a
* packet to process until it is unable to find anymore packets
*/
public void run() {
appRunning = true;
try {
streamStatus = true;
xmlObject = new XMLParser();
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
Thread.sleep(1);
}
while (appRunning) {
StreamPacket packet = StreamReceiver.packetBuffer.take();
parsePacket(packet);
Thread.sleep(1);
while (StreamReceiver.packetBuffer.peek() == null) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Used to start the stream parser thread when multithreading
*/
public void start() {
if (t == null) {
t = new Thread(this, threadName);
t.start();
}
}
/**
* Looks at the type of the packet then sends it to the appropriate parser to extract the
* specific data associated with that packet type
*
* @param packet the packet to be looked at and processed
*/
private static void parsePacket(StreamPacket packet) {
try {
switch (packet.getType()) {
case HEARTBEAT:
extractHeartBeat(packet);
break;
case RACE_STATUS:
extractRaceStatus(packet);
break;
case DISPLAY_TEXT_MESSAGE:
extractDisplayMessage(packet);
break;
case XML_MESSAGE:
newRaceXmlReceived = true;
extractXmlMessage(packet);
break;
case RACE_START_STATUS:
extractRaceStartStatus(packet);
break;
case YACHT_EVENT_CODE:
extractYachtEventCode(packet);
break;
case YACHT_ACTION_CODE:
extractYachtActionCode(packet);
break;
case CHATTER_TEXT:
extractChatterText(packet);
break;
case BOAT_LOCATION:
extractBoatLocation(packet);
break;
case MARK_ROUNDING:
extractMarkRounding(packet);
break;
case COURSE_WIND:
extractCourseWind(packet);
break;
case AVG_WIND:
extractAvgWind(packet);
break;
default:
break;
}
} catch (NullPointerException e) {
System.out.println("Error parsing packet");
e.printStackTrace();
}
}
/**
* Extracts the seq num used in the heartbeat packet
*
* @param packet Packet parsed in to use the payload
*/
private static void extractHeartBeat(StreamPacket packet) {
long heartbeat = bytesToLong(packet.getPayload());
}
private static String getTimeZoneString() {
Integer offset = xmlObject.getRegattaXML().getUtcOffset();
StringBuilder utcOffset = new StringBuilder();
utcOffset.append("GMT");
if (offset > 0) {
utcOffset.append("+");
utcOffset.append(offset);
} else if (offset < 0) {
utcOffset.append("-");
utcOffset.append(offset);
}
return utcOffset.toString();
}
/**
* Extracts the useful race status data from race status type packets. This method will also
* print to the console the current state of the race (if it has started/finished or is about to
* start), along side this it'll also display the amount of time since the race has started or
* time till it starts
*
* @param packet Packet parsed in to use the payload
*/
private static void extractRaceStatus(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
long currentTime = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long raceId = bytesToLong(Arrays.copyOfRange(payload, 7, 11));
int raceStatus = payload[11];
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
long rawWindSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
currentTimeLong = currentTime;
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
if (xmlObject.getRegattaXML() != null) {
format.setTimeZone(TimeZone.getTimeZone(getTimeZoneString()));
currentTimeString = format.format((new Date(currentTime)).getTime());
}
long timeTillStart =
((new Date(expectedStartTime)).getTime() - (new Date(currentTime)).getTime()) / 1000;
if (timeTillStart > 0) {
timeSinceStart = timeTillStart;
} else {
if (raceStatus == 4 || raceStatus == 8) {
raceFinished = true;
raceStarted = false;
} else if (!raceStarted) {
raceStarted = true;
raceFinished = false;
}
timeSinceStart = timeTillStart;
}
double windDirFactor = 0x4000 / 90; //0x4000 is 90 degrees, 0x8000 is 180 degrees, etc...
windDirection = windDir / windDirFactor;
windSpeed = rawWindSpeed / 1000 * MS_TO_KNOTS;
int noBoats = payload[22];
int raceType = payload[23];
for (int i = 0; i < noBoats; i++) {
long boatStatusSourceID = bytesToLong(
Arrays.copyOfRange(payload, 24 + (i * 20), 28 + (i * 20)));
Yacht boat = boats.get((int) boatStatusSourceID);
boat.setBoatStatus((int) payload[28 + (i * 20)]);
setBoatLegPosition(boat, (int) payload[29 + (i * 20)]);
boat.setPenaltiesAwarded((int) payload[30 + (i * 20)]);
boat.setPenaltiesServed((int) payload[31 + (i * 20)]);
Long estTimeAtNextMark = bytesToLong(
Arrays.copyOfRange(payload, 32 + (i * 20), 38 + (i * 20)));
boat.setEstimateTimeAtNextMark(estTimeAtNextMark);
Long estTimeAtFinish = bytesToLong(
Arrays.copyOfRange(payload, 38 + (i * 20), 44 + (i * 20)));
boat.setEstimateTimeAtFinish(estTimeAtFinish);
// boatsPos.put(estTimeAtFinish, boat);
// String boatStatus = "SourceID: " + boatStatusSourceID;
// boatStatus += "\nBoat Status: " + (int)payload[28 + (i * 20)];
// boatStatus += "\nLegNumber: " + (int)payload[29 + (i * 20)];
// boatStatus += "\nPenaltiesAwarded: " + (int)payload[29 + (i * 20)];
// boatStatus += "\nPenaltiesServed: " + (int)payload[30 + (i * 20)];
// boatStatus += "\nEstTimeAtNextMark: " + bytesToLong(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20)));
// boatStatus += "\nEstTimeAtFinish: " + bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)));
// boatStatuses.add(boatStatus);
}
// if (isRaceStarted()) {
// int pos = 1;
// for (Yacht yacht : boatsPos.values()) {
// yacht.setPosition(String.valueOf(pos));
// pos++;
// }
// } else {
// for (Yacht yacht : boatsPos.values()) {
// yacht.setPosition("-");
// }
// }
}
private static void setBoatLegPosition(Yacht updatingBoat, Integer leg){
Integer placing = 1;
if (leg != updatingBoat.getLegNumber() && (raceStarted || raceFinished)) {
for (Yacht boat : boats.values()) {
if (boat.getLegNumber() != null && leg <= boat.getLegNumber()){
placing += 1;
}
}
updatingBoat.setPosition(placing.toString());
updatingBoat.setLegNumber(leg);
boatsPos.putIfAbsent(placing, updatingBoat);
boatsPos.replace(placing, updatingBoat);
} else if(updatingBoat.getLegNumber() == null){
updatingBoat.setPosition("1");
updatingBoat.setLegNumber(leg);
}
}
/**
* Used to extract the messages passed through with the display message packet
*
* @param packet Packet parsed in to use the payload
*/
private static void extractDisplayMessage(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
int numOfLines = payload[3];
int totalLen = 0;
for (int i = 0; i < numOfLines; i++) {
int lineNum = payload[4 + totalLen];
int textLength = payload[5 + totalLen];
byte[] messageTextBytes = Arrays
.copyOfRange(payload, 6 + totalLen, 6 + textLength + totalLen);
String messageText = new String(messageTextBytes);
totalLen += 2 + textLength;
}
}
/**
* Used to read in the xml data. Will call the specific methods to create the course and boats
*
* @param packet Packet parsed in to use the payload
*/
private static void extractXmlMessage(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageType = payload[9];
long messageLength = bytesToLong(Arrays.copyOfRange(payload, 12, 14));
String xmlMessage = new String(
(Arrays.copyOfRange(payload, 14, (int) (14 + messageLength)))).trim();
//Create XML document Object
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
Document doc = null;
try {
db = dbf.newDocumentBuilder();
doc = db.parse(new InputSource(new StringReader(xmlMessage)));
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
}
xmlObject.constructXML(doc, messageType);
if (messageType == 7) { //7 is the boat XML
boats = xmlObject.getBoatXML().getCompetingBoats();
}
if (messageType == 6) { //6 is race info xml
newRaceXmlReceived = true;
}
}
/**
* Extracts the race start status from the packet, currently is unused within the app but
* is here for potential future use
*
* @param packet Packet parsed in to use the payload
*/
private static void extractRaceStartStatus(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
long timeStamp = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long raceStartTime = bytesToLong(Arrays.copyOfRange(payload, 9, 15));
long raceId = bytesToLong(Arrays.copyOfRange(payload, 15, 19));
int notificationType = payload[19];
}
/**
* When a yacht event occurs this will parse the byte array to retrieve the necessary info,
* currently unused
*
* @param packet Packet parsed in to use the payload
*/
private static void extractYachtEventCode(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
long timeStamp = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long raceId = bytesToLong(Arrays.copyOfRange(payload, 9, 13));
long subjectId = bytesToLong(Arrays.copyOfRange(payload, 13, 17));
long incidentId = bytesToLong(Arrays.copyOfRange(payload, 17, 21));
int eventId = payload[21];
}
/**
* When a yacht action occurs this will parse the parse the byte array to retrieve the necessary
* info, currently unused
*
* @param packet Packet parsed in to use the payload
*/
private static void extractYachtActionCode(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
long timeStamp = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long subjectId = bytesToLong(Arrays.copyOfRange(payload, 9, 13));
long incidentId = bytesToLong(Arrays.copyOfRange(payload, 13, 17));
int eventId = payload[17];
}
/**
* Strips the message from the chatter text type packets, currently the message is unused
*
* @param packet Packet parsed in to use the payload
*/
private static void extractChatterText(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
int messageType = payload[1];
int length = payload[2];
String message = new String(Arrays.copyOfRange(payload, 3, 3 + length));
}
/**
* Used to breakdown the boatlocation packets so the boat coordinates, id and groundspeed are
* all used All the other extra data is still being read and translated however is unused.
*
* @param packet Packet parsed in to use the payload
*/
private static void extractBoatLocation(StreamPacket packet) {
byte[] payload = packet.getPayload();
int deviceType = (int) payload[15];
long timeValid = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long seq = bytesToLong(Arrays.copyOfRange(payload, 11, 15));
long boatId = bytesToLong(Arrays.copyOfRange(payload, 7, 11));
long rawLat = bytesToLong(Arrays.copyOfRange(payload, 16, 20));
long rawLon = bytesToLong(Arrays.copyOfRange(payload, 20, 24));
//Converts the double to a usable lat/lon
double lat = ((180d * (double) rawLat) / Math.pow(2, 31));
double lon = ((180d * (double) rawLon) / Math.pow(2, 31));
long heading = bytesToLong(Arrays.copyOfRange(payload, 28, 30));
double groundSpeed = bytesToLong(Arrays.copyOfRange(payload, 38, 40)) / 1000.0;
//type 1 is a racing yacht and type 3 is a mark, needed for updating positions of the mark and boat
if (deviceType == 1) {
BoatPositionPacket boatPacket = new BoatPositionPacket(boatId, timeValid, lat, lon,
heading, groundSpeed);
//add a new priority que to the boatLocations HashMap
if (!boatLocations.containsKey(boatId)) {
boatLocations.put(boatId,
new PriorityBlockingQueue<>(256, new Comparator<BoatPositionPacket>() {
@Override
public int compare(BoatPositionPacket p1, BoatPositionPacket p2) {
return (int) (p1.getTimeValid() - p2.getTimeValid());
}
}));
}
boatLocations.get(boatId).put(boatPacket);
} else if (deviceType == 3) {
BoatPositionPacket markPacket = new BoatPositionPacket(boatId, timeValid, lat, lon,
heading, groundSpeed);
//add a new priority que to the boatLocations HashMap
if (!markLocations.containsKey(boatId)) {
markLocations.put(boatId,
new PriorityBlockingQueue<>(256, new Comparator<BoatPositionPacket>() {
@Override
public int compare(BoatPositionPacket p1, BoatPositionPacket p2) {
return (int) (p1.getTimeValid() - p2.getTimeValid());
}
}));
}
markLocations.get(boatId).put(markPacket);
}
}
/**
* This packet type is received when a mark or gate is rounded by a boat
*
* @param packet The packet containing the payload
*/
private static void extractMarkRounding(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
long timeStamp = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long raceId = bytesToLong(Arrays.copyOfRange(payload, 9, 13));
long subjectId = bytesToLong(Arrays.copyOfRange(payload, 13, 17));
int boatStatus = payload[17];
int roundingSide = payload[18];
int markType = payload[19];
int markId = payload[20];
// assign mark rounding time to boat
boats.get((int)subjectId).setMarkRoundingTime(timeStamp);
for (Mark mark : xmlObject.getRaceXML().getAllCompoundMarks()) {
if (mark.getCompoundMarkID() == markId) {
boats.get((int)subjectId).setLastMarkRounded(mark);
}
}
}
/**
* This packet type contains periodic data on the state of the wind
*
* @param packet The packet containing the payload
*/
private static void extractCourseWind(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
int selectedWindId = payload[1];
int loopCount = payload[2];
ArrayList<String> windInfo = new ArrayList<>();
for (int i = 0; i < loopCount; i++) {
String wind = "WindId: " + payload[3 + (20 * i)];
wind +=
"\nTime: " + bytesToLong(Arrays.copyOfRange(payload, 4 + (20 * i), 10 + (20 * i)));
wind += "\nRaceId: " + bytesToLong(
Arrays.copyOfRange(payload, 10 + (20 * i), 14 + (20 * i)));
wind += "\nWindDirection: " + bytesToLong(
Arrays.copyOfRange(payload, 14 + (20 * i), 16 + (20 * i)));
wind += "\nWindSpeed: " + bytesToLong(
Arrays.copyOfRange(payload, 16 + (20 * i), 18 + (20 * i)));
wind += "\nBestUpWindAngle: " + bytesToLong(
Arrays.copyOfRange(payload, 18 + (20 * i), 20 + (20 * i)));
wind += "\nBestDownWindAngle: " + bytesToLong(
Arrays.copyOfRange(payload, 20 + (20 * i), 22 + (20 * i)));
wind += "\nFlags: " + String
.format("%8s", Integer.toBinaryString(payload[22 + (20 * i)] & 0xFF))
.replace(' ', '0');
windInfo.add(wind);
}
}
/**
* This packet conatins the average wind to ground speed
*
* @param packet The packet containing the paylaod
*/
private static void extractAvgWind(StreamPacket packet) {
byte[] payload = packet.getPayload();
int messageVersionNo = payload[0];
long timeStamp = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
long rawPeriod = bytesToLong(Arrays.copyOfRange(payload, 7, 9));
long rawSamplePeriod = bytesToLong(Arrays.copyOfRange(payload, 9, 11));
long period2 = bytesToLong(Arrays.copyOfRange(payload, 11, 13));
long speed2 = bytesToLong(Arrays.copyOfRange(payload, 13, 15));
long period3 = bytesToLong(Arrays.copyOfRange(payload, 15, 17));
long speed3 = bytesToLong(Arrays.copyOfRange(payload, 17, 19));
long period4 = bytesToLong(Arrays.copyOfRange(payload, 19, 21));
long speed4 = bytesToLong(Arrays.copyOfRange(payload, 21, 23));
}
/**
* takes an array of up to 7 bytes and returns a positive
* long constructed from the input bytes
*
* @return a positive long if there is less than 7 bytes -1 otherwise
*/
private static long bytesToLong(byte[] bytes) {
long partialLong = 0;
int index = 0;
for (byte b : bytes) {
if (index > 6) {
return -1;
}
partialLong = partialLong | (b & 0xFFL) << (index * 8);
index++;
}
return partialLong;
}
/**
* returns false if race not started, true otherwise
*
* @return race started status
*/
public static boolean isRaceStarted() {
return raceStarted;
}
/**
* returns false if stream not connected, true otherwise
*
* @return stream started status
*/
public static boolean isStreamStatus() {
return streamStatus;
}
/**
* returns race timer
*
* @return race timer in long
*/
public static long getTimeSinceStart() {
return timeSinceStart;
}
/**
* return false if race not finished, true otherwise
*
* @return race finished status
*/
public static boolean isRaceFinished() {
return raceFinished;
}
/**
* return a map of boats with sourceID and the boat
*
* @return map of boats
*/
public static Map<Integer, Yacht> getBoats() {
return boats;
}
/**
* returns the latest updated object from xml parser
*
* @return the latest xml object
*/
public static XMLParser getXmlObject() {
return xmlObject;
}
/**
* returns the wind direction in degrees
*
* @return a double wind direction value
*/
public static double getWindDirection() {
return windDirection;
}
/**
* Returns the wind speed in knots
* @return A double indicating the wind speed in knots
*/
public static Double getWindSpeed() {
return windSpeed;
}
/**
* returns stream time in formatted string format
*
* @return String of stream time
*/
public static String getCurrentTimeString() {
return currentTimeString;
}
/**
* used in boat position since tree map can sort position efficiently.
*
* @return a map of time to finish and boat.
*/
public static Map<Integer, Yacht> getBoatsPos() {
return boatsPos;
}
/**
* returns current time in stream in long
*
* @return a long value of current time
*/
public static Long getCurrentTimeLong() {
return currentTimeLong;
}
public static void appClose() {
appRunning = false;
}
/**
* Used to check if a new un-processed xml has been found, if so will return true before
* toggling off so that the next check will return false.
*
* @return the status of if new xml has been received
*/
public static boolean isNewRaceXmlReceived() {
if (newRaceXmlReceived) {
newRaceXmlReceived = false;
return true;
} else {
return false;
}
}
}
@@ -0,0 +1,158 @@
package seng302.models.stream;
import seng302.models.stream.packets.StreamPacket;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
public class StreamReceiver extends Thread {
private InputStream stream;
private Socket host;
private ByteArrayOutputStream crcBuffer;
private Thread t;
private String threadName;
public static PriorityBlockingQueue<StreamPacket> packetBuffer;
private static boolean moreBytes;
public StreamReceiver(String hostAddress, int hostPort, String threadName) {
this.threadName = threadName;
this.setDaemon(true);
try {
host = new Socket(hostAddress, hostPort);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
public void run(){
PriorityBlockingQueue<StreamPacket> pq = new PriorityBlockingQueue<>(256, new Comparator<StreamPacket>() {
@Override
public int compare(StreamPacket s1, StreamPacket s2) {
return (int) (s1.getTimeStamp() - s2.getTimeStamp());
}
});
packetBuffer = pq;
connect();
}
public void start () {
if (t == null) {
t = new Thread (this, threadName);
t.start ();
}
}
public StreamReceiver(Socket host, PriorityBlockingQueue packetBuffer){
this.host=host;
this.packetBuffer = packetBuffer;
}
public void connect(){
try {
stream = host.getInputStream();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
int sync1;
int sync2;
moreBytes = true;
while(moreBytes) {
try {
crcBuffer = new ByteArrayOutputStream();
sync1 = readByte();
sync2 = readByte();
//checking if it is the start of the packet
if(sync1 == 0x47 && sync2 == 0x83) {
int type = readByte();
//No. of milliseconds since Jan 1st 1970
long timeStamp = bytesToLong(getBytes(6));
skipBytes(4);
long payloadLength = bytesToLong(getBytes(2));
byte[] payload = getBytes((int) payloadLength);
Checksum checksum = new CRC32();
checksum.update(crcBuffer.toByteArray(), 0, crcBuffer.size());
long computedCrc = checksum.getValue();
long packetCrc = bytesToLong(getBytes(4));
if (computedCrc == packetCrc) {
packetBuffer.add(new StreamPacket(type, payloadLength, timeStamp, payload));
} else {
System.err.println("Packet has been dropped");
}
}
} catch (Exception e) {
moreBytes = false;
}
}
}
private int readByte() throws Exception {
int currentByte = -1;
try {
currentByte = stream.read();
crcBuffer.write(currentByte);
} catch (IOException e) {
e.printStackTrace();
}
if (currentByte == -1){
throw new Exception();
}
return currentByte;
}
private byte[] getBytes(int n) throws Exception{
byte[] bytes = new byte[n];
for (int i = 0; i < n; i++){
bytes[i] = (byte) readByte();
}
return bytes;
}
private void skipBytes(long n) throws Exception{
for (int i=0; i < n; i++){
readByte();
}
}
/**
* takes an array of up to 7 bytes in little endian format and
* returns a positive long constructed from the input bytes
*
* @return a positive long if there is less than 8 bytes -1 otherwise
*/
private long bytesToLong(byte[] bytes){
long partialLong = 0;
int index = 0;
for (byte b: bytes){
if (index > 6){
return -1;
}
partialLong = partialLong | (b & 0xFFL) << (index * 8);
index++;
}
return partialLong;
}
public static void main(String[] args) {
StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1");
//StreamReceiver sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread2");
sr.start();
}
public static void noMoreBytes(){
moreBytes = false;
}
}
@@ -0,0 +1,610 @@
package seng302.models.stream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import seng302.models.Yacht;
import seng302.models.mark.GateMark;
import seng302.models.mark.Mark;
import seng302.models.mark.MarkType;
import seng302.models.mark.SingleMark;
/**
* Class to create an XML object from the XML Packet Messages.
*
* Example usage:
*
* Document doc; // some xml document
* Integer xmlMessageType; // an Integer of value 5, 6, 7
*
* xmlP = new XMLParser(doc, xmlMessageType);
* RegattaXMLObject rXmlObj = xmlP.createRegattaXML(); // creates a regattaXML object.
*/
public class XMLParser {
private Document xmlDoc;
private RaceXMLObject raceXML;
private RegattaXMLObject regattaXML;
private BoatXMLObject boatXML;
public XMLParser() {
}
/**
* Constructor for XMLParser
*
* @param doc Document to create XML object.
* @param messageType Defines if a message is a RegattaXML(5), RaceXML(6), BoatXML(7).
*/
public void constructXML(Document doc, Integer messageType) {
this.xmlDoc = doc;
switch (messageType) {
case 5:
regattaXML = new RegattaXMLObject(this.xmlDoc);
break;
case 6:
raceXML = new RaceXMLObject(this.xmlDoc);
break;
case 7:
boatXML = new BoatXMLObject(this.xmlDoc);
break;
}
}
public RaceXMLObject getRaceXML() {
return raceXML;
}
public RegattaXMLObject getRegattaXML() {
return regattaXML;
}
public BoatXMLObject getBoatXML() {
return boatXML;
}
/**
* Returns the text content of a given child element tag, assuming it exists, as an Integer.
*
* @param ele Document Element with child elements.
* @param tag Tag to find in document elements child elements.
* @return Text content from tag if found, null otherwise.
*/
private static Integer getElementInt(Element ele, String tag) {
NodeList tagList = ele.getElementsByTagName(tag);
if (tagList.getLength() > 0) {
return Integer.parseInt(tagList.item(0).getTextContent());
} else {
return null;
}
}
/**
* Returns the text content of a given child element tag, assuming it exists, as an String.
*
* @param ele Document Element with child elements.
* @param tag Tag to find in document elements child elements.
* @return Text content from tag if found, null otherwise.
*/
private static String getElementString(Element ele, String tag) {
NodeList tagList = ele.getElementsByTagName(tag);
if (tagList.getLength() > 0) {
return tagList.item(0).getTextContent();
} else {
return null;
}
}
/**
* Returns the text content of a given child element tag, assuming it exists, as a Double.
*
* @param ele Document Element with child elements.
* @param tag Tag to find in document elements child elements.
* @return Text content from tag if found, null otherwise.
*/
private static Double getElementDouble(Element ele, String tag) {
NodeList tagList = ele.getElementsByTagName(tag);
if (tagList.getLength() > 0) {
return Double.parseDouble(tagList.item(0).getTextContent());
} else {
return null;
}
}
/**
* Returns the text content of an attribute of a given Node, assuming it exists, as a String.
*
* @param n A node object that should have some attributes
* @param attr The attribute you want to get from the given node.
* @return The String representation of the text content of an attribute in the given node, else
* returns null.
*/
private static String getNodeAttributeString(Node n, String attr) {
Node attrItem = n.getAttributes().getNamedItem(attr);
if (attrItem != null) {
return attrItem.getTextContent();
} else {
return null;
}
}
/**
* Returns the text content of an attribute of a given Node, assuming it exists, as an Integer.
*
* @param n A node object that should have some attributes
* @param attr The attribute you want to get from the given node.
* @return The Integer representation of the text content of an attribute in the given node,
* else returns null.
*/
private static Integer getNodeAttributeInt(Node n, String attr) {
Node attrItem = n.getAttributes().getNamedItem(attr);
if (attrItem != null) {
return Integer.parseInt(attrItem.getTextContent());
} else {
return null;
}
}
/**
* Returns the text content of an attribute of a given Node, assuming it exists, as a Double.
*
* @param n A node object that should have some attributes
* @param attr The attribute you want to get from the given node.
* @return The Double representation of the text content of an attribute in the given node, else
* returns null.
*/
private static Double getNodeAttributeDouble(Node n, String attr) {
Node attrItem = n.getAttributes().getNamedItem(attr);
if (attrItem != null) {
return Double.parseDouble(attrItem.getTextContent());
} else {
return null;
}
}
public class RegattaXMLObject {
//Regatta Info
private Integer regattaID;
private String regattaName;
private String courseName;
private Double centralLat;
private Double centralLng;
private Integer utcOffset;
/**
* Constructor for a RegattaXMLObject.
* Takes the information from a Document object and creates a more usable format.
*
* @param doc XML Document Object
*/
RegattaXMLObject(Document doc) {
Element docEle = doc.getDocumentElement();
this.regattaID = getElementInt(docEle, "RegattaID");
this.regattaName = getElementString(docEle, "RegattaName");
this.courseName = getElementString(docEle, "CourseName");
this.centralLat = getElementDouble(docEle, "CentralLatitude");
this.centralLng = getElementDouble(docEle, "CentralLongitude");
this.utcOffset = getElementInt(docEle, "UtcOffset");
}
public Integer getRegattaID() {
return regattaID;
}
public String getRegattaName() {
return regattaName;
}
public String getCourseName() {
return courseName;
}
public Double getCentralLat() {
return centralLat;
}
public Double getCentralLng() {
return centralLng;
}
public Integer getUtcOffset() {
return utcOffset;
}
}
public class RaceXMLObject {
// Race Info
private Integer raceID;
private String raceType;
private String creationTimeDate; // XML Creation Time
//Race Start Details
private String raceStartTime;
private Boolean postponeStatus;
//Non atomic race attributes
private ArrayList<Participant> participants;
private ArrayList<Mark> allMarks;
private ArrayList<Mark> nonDuplicateMarks;
private ArrayList<Corner> compoundMarkSequence;
private ArrayList<Limit> courseLimit;
// ensures there's no duplicate marks.
private List<Long> seenSourceIDs = new ArrayList<Long>();
/**
* Constructor for a RaceXMLObject.
* Takes the information from a Document object and creates a more usable format.
*
* @param doc XML Document Object
*/
RaceXMLObject(Document doc) {
Element docEle = doc.getDocumentElement();
//Atomic and Semi-Atomic Elements
this.raceID = getElementInt(docEle, "RaceID");
this.raceType = getElementString(docEle, "RaceType");
this.creationTimeDate = getElementString(docEle, "CreationTimeDate");
Node raceStart = docEle.getElementsByTagName("RaceStartTime").item(0);
this.raceStartTime = getNodeAttributeString(raceStart, "Start");
this.postponeStatus = Boolean
.parseBoolean(getNodeAttributeString(raceStart, "Postpone"));
//Participants
participants = new ArrayList<>();
NodeList pList = docEle.getElementsByTagName("Participants").item(0).getChildNodes();
for (int i = 0; i < pList.getLength(); i++) {
Node pNode = pList.item(i);
String entry;
if (pNode.getNodeName().equals("Yacht")) {
Integer sourceID = getNodeAttributeInt(pNode, "SourceID");
if (pNode.getAttributes().getLength() == 2) {
entry = getNodeAttributeString(pNode, "Entry");
} else {
entry = null;
}
Participant pa = new Participant(sourceID, entry);
participants.add(pa);
}
}
//Course
allMarks = new ArrayList<>();
nonDuplicateMarks = new ArrayList<>();
createCompoundMarks(docEle);
//Course Mark Sequence
compoundMarkSequence = new ArrayList<>();
NodeList cornerList = docEle.getElementsByTagName("CompoundMarkSequence").item(0)
.getChildNodes();
for (int i = 0; i < cornerList.getLength(); i++) {
Node cornerNode = cornerList.item(i);
if (cornerNode.getNodeName().equals("Corner")) {
Corner corner = new Corner(cornerNode);
compoundMarkSequence.add(corner);
}
}
//Course Limits
courseLimit = new ArrayList<>();
NodeList limitList = docEle.getElementsByTagName("CourseLimit").item(0).getChildNodes();
for (int i = 0; i < limitList.getLength(); i++) {
Node limitNode = limitList.item(i);
if (limitNode.getNodeName().equals("Limit")) {
Limit limit = new Limit(limitNode);
courseLimit.add(limit);
}
}
}
private void createCompoundMarks(Element docEle) {
NodeList cMarkList = docEle.getElementsByTagName("Course").item(0).getChildNodes();
for (int i = 0; i < cMarkList.getLength(); i++) {
Node cMarkNode = cMarkList.item(i);
if (cMarkNode.getNodeName().equals("CompoundMark")) {
createAndAddMark(cMarkNode);
}
}
}
private void createAndAddMark(Node compoundMark) {
Boolean markSeen = false;
List<SingleMark> marksList = new ArrayList<>();
Integer compoundMarkID = getNodeAttributeInt(compoundMark, "CompoundMarkID");
String cMarkName = getNodeAttributeString(compoundMark, "Name");
NodeList childMarks = compoundMark.getChildNodes();
for (int i = 0; i < childMarks.getLength(); i++) {
Node markNode = childMarks.item(i);
if (markNode.getNodeName().equals("Mark")) {
Integer sourceID = getNodeAttributeInt(markNode, "SourceID");
String markName = getNodeAttributeString(markNode, "Name");
Double targetLat = getNodeAttributeDouble(markNode, "TargetLat");
Double targetLng = getNodeAttributeDouble(markNode, "TargetLng");
SingleMark mark = new SingleMark(markName, targetLat, targetLng, sourceID, compoundMarkID);
marksList.add(mark);
}
}
for (SingleMark mark : marksList) {
if (seenSourceIDs.contains(mark.getId())) {
markSeen = true;
} else {
seenSourceIDs.add(mark.getId());
}
}
if (marksList.size() == 1) {
if (!markSeen) {
nonDuplicateMarks.add(marksList.get(0));
}
allMarks.add(marksList.get(0));
} else if (marksList.size() == 2) {
GateMark thisGateMark = new GateMark(cMarkName, MarkType.OPEN_GATE, marksList.get(0),
marksList.get(1), marksList.get(0).getLatitude(),
marksList.get(0).getLongitude(), compoundMarkID);
if(!markSeen) {
nonDuplicateMarks.add(thisGateMark);
}
allMarks.add(thisGateMark);
}
}
public Integer getRaceID() {
return raceID;
}
public String getRaceType() {
return raceType;
}
public String getCreationTimeDate() {
return creationTimeDate;
}
public String getRaceStartTime() {
return raceStartTime;
}
public Boolean getPostponeStatus() {
return postponeStatus;
}
public ArrayList<Participant> getParticipants() {
return participants;
}
/**
* @return Returns ALL compound marks as stated in the RaceXML (INCLUDING DUPLICATE MARKS)
*/
public List<Mark> getAllCompoundMarks() {
return allMarks;
}
/**
* @return Returns Marks from the race XML without any duplicates
*/
public List<Mark> getNonDupCompoundMarks() {
return nonDuplicateMarks;
}
public ArrayList<Corner> getCompoundMarkSequence() {
return compoundMarkSequence;
}
public ArrayList<Limit> getCourseLimit() {
return courseLimit;
}
public class Participant {
Integer sourceID;
String entry;
Participant(Integer sourceID, String entry) {
this.sourceID = sourceID;
this.entry = entry;
}
public Integer getsourceID() {
return sourceID;
}
public String getEntry() {
return entry;
}
}
public class Corner {
private Integer seqID;
private Integer compoundMarkID;
private String rounding;
private Integer zoneSize;
Corner(Node cornerNode) {
this.seqID = getNodeAttributeInt(cornerNode, "SeqID");
this.compoundMarkID = getNodeAttributeInt(cornerNode, "CompoundMarkID");
this.rounding = getNodeAttributeString(cornerNode, "Rounding");
this.zoneSize = getNodeAttributeInt(cornerNode, "ZoneSize");
}
public Integer getSeqID() {
return seqID;
}
public Integer getCompoundMarkID() {
return compoundMarkID;
}
public String getRounding() {
return rounding;
}
public Integer getZoneSize() {
return zoneSize;
}
}
public class Limit {
private Integer seqID;
private Double lat;
private Double lng;
Limit(Node limitNode) {
this.seqID = getNodeAttributeInt(limitNode, "SeqID");
this.lat = getNodeAttributeDouble(limitNode, "Lat");
this.lng = getNodeAttributeDouble(limitNode, "Lon");
}
public Integer getSeqID() {
return seqID;
}
public Double getLat() {
return lat;
}
public Double getLng() {
return lng;
}
}
}
public class BoatXMLObject {
private String lastModified;
private Integer version;
//Settings for the boat type in the race. This may end up having to be reworked if multiple boat types compete.
private String boatType;
private Double boatLength;
private Double hullLength;
private Double markZoneSize;
private Double courseZoneSize;
private ArrayList<Double> zoneLimits;// will only contain 5 elements. Limits 1-5
//Boats
ArrayList<Yacht> boats;
//Competing boats
Map<Integer, Yacht> competingBoats = new HashMap<>();
/**
* Constructor for a BoatXMLObject.
* Takes the information from a Document object and creates a more usable format.
*
* @param doc XML Document Object
*/
BoatXMLObject(Document doc) {
Element docEle = doc.getDocumentElement();
this.lastModified = getElementString(docEle, "Modified");
this.version = getElementInt(docEle, "Version");
NodeList settingsList = docEle.getElementsByTagName("Settings").item(0).getChildNodes();
this.boatType = getNodeAttributeString(settingsList.item(1), "Type");
this.boatLength = getNodeAttributeDouble(settingsList.item(3), "BoatLength");
this.hullLength = getNodeAttributeDouble(settingsList.item(3), "HullLength");
this.markZoneSize = getNodeAttributeDouble(settingsList.item(5), "MarkZoneSize");
this.courseZoneSize = getNodeAttributeDouble(settingsList.item(5), "CourseZoneSize");
Node zoneLimitsList = settingsList.item(7);
this.zoneLimits = new ArrayList<>();
for (int i = 0; i < zoneLimitsList.getAttributes().getLength(); i++) {
String tag = String.format("Limit%d", i + 1);
this.zoneLimits.add(getNodeAttributeDouble(zoneLimitsList, tag));
}
this.boats = new ArrayList<>();
NodeList boatsList = docEle.getElementsByTagName("Boats").item(0).getChildNodes();
for (int i = 0; i < boatsList.getLength(); i++) {
Node currentBoat = boatsList.item(i);
if (currentBoat.getNodeName().equals("Boat")) {
// Boat boat = new Boat(currentBoat);
Yacht boat = new Yacht(getNodeAttributeString(currentBoat, "Type"),
getNodeAttributeInt(currentBoat, "SourceID"),
getNodeAttributeString(currentBoat, "HullNum"),
getNodeAttributeString(currentBoat, "ShortName"),
getNodeAttributeString(currentBoat, "BoatName"),
getNodeAttributeString(currentBoat, "Country"));
this.boats.add(boat);
if (boat.getBoatType().equals("Yacht")) {
competingBoats.put(boat.getSourceID(), boat);
}
}
}
}
public String getLastModified() {
return lastModified;
}
public Integer getVersion() {
return version;
}
public String getBoatType() {
return boatType;
}
public Double getBoatLength() {
return boatLength;
}
public Double getHullLength() {
return hullLength;
}
public Double getMarkZoneSize() {
return markZoneSize;
}
public Double getCourseZoneSize() {
return courseZoneSize;
}
public ArrayList<Double> getZoneLimits() {
return zoneLimits;
}
public ArrayList<Yacht> getBoats() {
return boats;
}
public Map<Integer, Yacht> getCompetingBoats() {
return competingBoats;
}
}
}
@@ -0,0 +1,39 @@
package seng302.models.stream.packets;
public class BoatPositionPacket {
private long boatId;
private long timeValid;
private double lat;
private double lon;
private double heading;
private double groundSpeed;
public BoatPositionPacket(long boatId, long timeValid, double lat, double lon, double heading, double groundSpeed) {
this.boatId = boatId;
this.timeValid = timeValid;
this.lat = lat;
this.lon = lon;
this.heading = heading;
this.groundSpeed = groundSpeed;
}
public long getTimeValid() {
return timeValid;
}
public double getLat() {
return lat;
}
public double getLon() {
return lon;
}
public double getHeading() {
return heading;
}
public double getGroundSpeed() {
return groundSpeed;
}
}
@@ -0,0 +1,51 @@
package seng302.models.stream.packets;
/**
* Created by Kusal on 4/24/2017.
*/
public enum PacketType {
HEARTBEAT,
RACE_STATUS,
DISPLAY_TEXT_MESSAGE,
XML_MESSAGE,
RACE_START_STATUS,
YACHT_EVENT_CODE,
YACHT_ACTION_CODE,
CHATTER_TEXT,
BOAT_LOCATION,
MARK_ROUNDING,
COURSE_WIND,
AVG_WIND,
OTHER;
public static PacketType assignPacketType(int packetType){
switch(packetType){
case 1:
return HEARTBEAT;
case 12:
return RACE_STATUS;
case 20:
return DISPLAY_TEXT_MESSAGE;
case 26:
return XML_MESSAGE;
case 27:
return RACE_START_STATUS;
case 29:
return YACHT_EVENT_CODE;
case 31:
return YACHT_ACTION_CODE;
case 36:
return CHATTER_TEXT;
case 37:
return BOAT_LOCATION;
case 38:
return MARK_ROUNDING;
case 44:
return COURSE_WIND;
case 47:
return AVG_WIND;
default:
}
return OTHER;
}
}
@@ -0,0 +1,37 @@
package seng302.models.stream.packets;
/**
* Created by kre39 on 23/04/17.
*/
public class StreamPacket {
//Change int to an ENUM for the type
private PacketType type;
private long messageLength;
private long timeStamp;
private byte[] payload;
public StreamPacket(int type, long messageLength, long timeStamp, byte[] payload) {
this.type = PacketType.assignPacketType(type);
this.messageLength = messageLength;
this.timeStamp = timeStamp;
this.payload = payload;
}
public PacketType getType() {
return type;
}
public long getMessageLength() {
return messageLength;
}
public byte[] getPayload() {
return payload;
}
public long getTimeStamp() {
return timeStamp;
}
}
@@ -0,0 +1,332 @@
package seng302.server;
import seng302.server.messages.*;
import seng302.server.simulator.Boat;
import seng302.server.simulator.Simulator;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class ServerThread implements Runnable, Observer {
private StreamingServerSocket server;
private long startTime;
private boolean raceStarted = false;
private Map<Integer,Boolean> boatsFinished = new HashMap<>();
private List<Boat> boats;
private Simulator raceSimulator;
private boolean sendingRaceFinishedLocationMessages = true;
private final int HEARTBEAT_PERIOD = 5000;
private final int RACE_STATUS_PERIOD = 1000/2;
private final int RACE_START_STATUS_PERIOD = 1000;
private final int BOAT_LOCATION_PERIOD = 1000/5;
private final int PORT_NUMBER = 4949;
private final int TIME_TILL_RACE_START = 20*1000;
private static final int LOG_LEVEL = 1;
public ServerThread(String threadName){
Thread runner = new Thread(this, threadName);
runner.setDaemon(true);
raceSimulator = new Simulator(BOAT_LOCATION_PERIOD);
raceSimulator.addObserver(this);
// run race simulator, so it can send boats' static location.
Thread raceSimulatorThread = new Thread(raceSimulator, "Race Simulator");
boats = raceSimulator.getBoats();
for (Boat b : boats){
boatsFinished.put(b.getSourceID(), false);
}
runner.start();
raceSimulatorThread.start();
}
static void serverLog(String message, int logLevel){
if(logLevel <= LOG_LEVEL){
System.out.println("[SERVER] " + message);
}
}
/**
* Creates and returns an XML Message from the file specified
* @param fileName The source XML file
* @param type The XML Message type
* @return The XML Message
*/
private Message getXmlMessage(String fileName, XMLMessageSubType type){
String fileContents = null;
try {
InputStream thisStream = this.getClass().getResourceAsStream(fileName);
fileContents = new String(org.apache.commons.io.IOUtils.toByteArray(thisStream));
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e){
return null;
}
if (fileContents != null){
return new XMLMessage(fileContents, type, server.getSequenceNumber());
}
return null;
}
/**
* @return Get a race status message for the current race
*/
private Message getRaceStatusMessage(){
List<BoatSubMessage> boatSubMessages = new ArrayList<>();
BoatStatus boatStatus;
RaceStatus raceStatus;
boolean thereAreBoatsNotFinished = false;
for (Boat b : boats){
if (!raceStarted){
boatStatus = BoatStatus.PRESTART;
thereAreBoatsNotFinished = true;
}
else if(boatsFinished.get(b.getSourceID())){
boatStatus = BoatStatus.FINISHED;
}
else{
boatStatus = BoatStatus.PRESTART;
thereAreBoatsNotFinished = true;
}
BoatSubMessage m = new BoatSubMessage(b.getSourceID(), boatStatus, b.getLastPassedCorner().getSeqID(), 0, 0, b.getEstimatedTimeTillFinish(), b.getEstimatedTimeTillFinish());
boatSubMessages.add(m);
}
if (thereAreBoatsNotFinished){
if (raceStarted){
raceStatus = RaceStatus.STARTED;
}
else{
long currentTime = System.currentTimeMillis();
long timeDifference = startTime - currentTime;
if (timeDifference > 60*3){
raceStatus = RaceStatus.PRESTART;
}
else if (timeDifference > 60){
raceStatus = RaceStatus.WARNING;
}
else{
raceStatus = RaceStatus.PREPARATORY;
}
}
}
else{
raceStatus = RaceStatus.TERMINATED;
}
return new RaceStatusMessage(1, raceStatus, startTime, WindDirection.SOUTH,
100, boats.size(), RaceType.MATCH_RACE, 1, boatSubMessages);
}
/**
* Starts an instance of the race simulator
*/
private void startRaceSim(){
// set race started to true, so the simulator will start moving boats
raceSimulator.setRaceStarted(true);
}
/**
* Starts sending heartbeat messages to the client
*/
private void startSendingHeartbeats() {
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
Message heartbeat = new Heartbeat(server.getSequenceNumber());
try {
server.send(heartbeat);
} catch (IOException e) {
e.printStackTrace();
}
}
}, 0, HEARTBEAT_PERIOD);
}
/**
* Start sending race start status messages until race starts
*/
private void startSendingRaceStartStatusMessages(){
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
Message raceStartStatusMessage = new RaceStartStatusMessage(server.getSequenceNumber(), startTime , 1,
RaceStartNotificationType.SET_RACE_START_TIME);
try {
if (startTime < System.currentTimeMillis() && !raceStarted){
startRaceSim();
raceStarted = true;
}
else{
server.send(raceStartStatusMessage);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, 0, RACE_START_STATUS_PERIOD);
}
/**
* Start sending race start status messages until race starts
*/
private void startSendingRaceStatusMessages(){
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
Message raceStatusMessage = getRaceStatusMessage();
try {
server.send(raceStatusMessage);
} catch (IOException e) {
e.printStackTrace();
}
}
}, 0, RACE_STATUS_PERIOD);
}
/**
* Sends the race, boat, and regatta XML files to the client
*/
private void sendXml(){
try{
Message raceData = getXmlMessage("/server_config/race.xml", XMLMessageSubType.RACE);
Message boatData = getXmlMessage("/server_config/boats.xml", XMLMessageSubType.BOAT);
Message regatta = getXmlMessage("/server_config/regatta.xml", XMLMessageSubType.REGATTA);
if (raceData != null){
server.send(raceData);
}
if (boatData != null){
server.send(boatData);
}
if (regatta != null){
server.send(regatta);
}
} catch (IOException e) {
serverLog("Couldn't send an XML Message: " + e.getMessage(), 0);
}
}
/**
* Send the post-start race course information
*/
private void sendPostStartCourseXml(){
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
try {
Message raceData = getXmlMessage("/server_config/courseLimits.xml", XMLMessageSubType.RACE);
if (raceData != null) {
server.send(raceData);
}
}catch (IOException e) {
serverLog("Couldn't send an XML Message: " + e.getMessage(), 0);
}
}
},25000);
//Delays the new course xml data for 25 seconds so the boats are able to pass the starting line
}
public void run() {
try{
server = new StreamingServerSocket(PORT_NUMBER);
}
catch (IOException e){
serverLog("Failed to bind socket: " + e.getMessage(), 0);
}
// Wait for client to connect
server.start();
startTime = System.currentTimeMillis() + TIME_TILL_RACE_START;
startSendingHeartbeats();
sendXml();
startSendingRaceStartStatusMessages();
startSendingRaceStatusMessages();
sendPostStartCourseXml();
}
/**
* Start sending static boat position updates when race has finished
*/
private void startSendingRaceFinishedBoatPositions(){
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Boat b : raceSimulator.getBoats()){
Message m = new BoatLocationMessage(b.getSourceID(), server.getSequenceNumber(), b.getLat(),
b.getLng(), b.getLastPassedCorner().getBearingToNextCorner(),
((long) 0));
server.send(m);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, 0, BOAT_LOCATION_PERIOD);
}
/**
* Send a boat location message when they are updated by the simulator
* @param o .
* @param arg .
*/
@Override
@SuppressWarnings("unchecked")
public void update(Observable o, Object arg) {
// Only send if server started
// TODO: I don't understand why i need to check server is null or not ... confused - haoming 2/5/17
if(server == null || !server.isStarted()){
return;
}
int numOfBoatsFinished = 0;
for (Boat boat : (List<Boat>) arg){
try {
if (boat.isFinished()) {
numOfBoatsFinished ++;
if (!boatsFinished.get(boat.getSourceID())) {
boatsFinished.put(boat.getSourceID(), true);
}
}
Message m = new BoatLocationMessage(boat.getSourceID(), 1, boat.getLat(),
boat.getLng(), boat.getLastPassedCorner().getBearingToNextCorner(),
((long) boat.getSpeed()));
server.send(m);
} catch (IOException e) {
serverLog("Couldn't send a boat status message", 3);
return;
}
catch (NullPointerException e){
e.printStackTrace();
}
}
if (numOfBoatsFinished == ((List<Boat>) arg).size()) {
startSendingRaceFinishedBoatPositions();
}
}
}
@@ -0,0 +1,61 @@
package seng302.server;
import seng302.server.messages.Message;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.Channels;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.List;
class StreamingServerSocket {
private ServerSocketChannel socket;
private SocketChannel client;
private short seqNum;
private boolean isServerStarted;
StreamingServerSocket(int port) throws IOException{
socket = ServerSocketChannel.open();
socket.socket().bind(new InetSocketAddress("localhost", port));
//socket.setSoTimeout(10000);
seqNum = 0;
isServerStarted = false;
}
void start(){
try {
client = socket.accept();
} catch (IOException e) {
e.getMessage();
}
if (client.socket() == null){
start();
}
else{
isServerStarted = true;
}
}
void send(Message message) throws IOException{
if (client == null){
return;
}
message.send(client);
seqNum++;
}
public short getSequenceNumber(){
return seqNum;
}
public boolean isStarted(){
return isServerStarted;
}
}
@@ -0,0 +1,164 @@
package seng302.server.messages;
import java.io.IOException;
import java.nio.channels.SocketChannel;
public class BoatLocationMessage extends Message {
private final int MESSAGE_SIZE = 56;
private long messageVersionNumber;
private long time;
private long sourceId;
private long sequenceNum;
private DeviceType deviceType;
private double latitude;
private double longitude;
private long altitude;
private Double heading;
private long pitch;
private long roll;
private long boatSpeed;
private long COG;
private long SOG;
private long apparentWindSpeed;
private long apparentWindAngle;
private long trueWindSpeed;
private long trueWindDirection;
private long trueWindAngle;
private long currentDrift;
private long currentSet;
private long rudderAngle;
/**
* Describes the location, altitude and sensor data from the boat.
* @param sourceId ID of the boat
* @param sequenceNum Sequence number of the message
* @param latitude The boats latitude
* @param longitude The boats longitude
* @param heading The boats heading
* @param boatSpeed The boats speed
*/
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
boatSpeed /= 10;
messageVersionNumber = 1;
time = System.currentTimeMillis();
this.sourceId = sourceId;
this.sequenceNum = sequenceNum;
this.deviceType = DeviceType.RACING_YACHT;
this.latitude = latitude;
this.longitude = longitude;
this.altitude = 0;
this.heading = heading;
this.pitch = 0;
this.roll = 0;
this.boatSpeed = boatSpeed;
this.COG = 2;
this.SOG = boatSpeed ;
this.apparentWindSpeed = 0;
this.apparentWindAngle = 0;
this.trueWindSpeed = 0;
this.trueWindDirection = 0;
this.trueWindAngle = 0;
this.currentDrift = 0;
this.currentSet = 0;
this.rudderAngle = 0;
setHeader(new Header(MessageType.BOAT_LOCATION, 1, (short) getSize()));
}
/**
* Convert binary latitude or longitude to floating point number
* @param binaryPackedLatLon Binary packed lat OR lon
* @return Floating point lat/lon
*/
public static double binaryPackedToLatLon(long binaryPackedLatLon){
return (double)binaryPackedLatLon * 180.0 / 2147483648.0;
}
/**
* Convert binary packed heading to floating point number
* @param binaryPackedHeading Binary packed heading
* @return heading as a decimal
*/
public static double binaryPackedHeadingToDouble(long binaryPackedHeading){
return (double)binaryPackedHeading * 360.0 / 65536.0;
}
/**
* Convert binary packed wind angle to floating point number
* @param binaryPackedWindAngle Binary packed wind angle
* @return wind angle as a decimal
*/
public static double binaryPackedWindAngleToDouble(long binaryPackedWindAngle){
return (double)binaryPackedWindAngle*180.0/32768.0;
}
/**
* Convert a latitude or longitude to a binary packed long
* @param latLon A floating point latitude/longitude
* @return A binary packed lat/lon
*/
public static long latLonToBinaryPackedLong(double latLon){
return (long)((536870912 * latLon) / 45);
}
/**
* Convert a heading to a binary packed long
* @param heading A floating point heading
* @return A binary packed heading
*/
public static long headingToBinaryPackedLong(double heading){
return (long)((8192*heading)/45);
}
/**
* Convert a wind angle to a binary packed long
* @param windAngle Floating point wind angle
* @return A binary packed wind angle
*/
public static long windAngleToBinaryPackedLong(double windAngle){
return (long)((8192*windAngle)/45);
}
@Override
public int getSize() {
return MESSAGE_SIZE;
}
@Override
public void send(SocketChannel outputStream) throws IOException{
allocateBuffer();
writeHeaderToBuffer();
long headingToSend = (long)((heading/360.0) * 65535.0);
putByte((byte) messageVersionNumber);
putInt(time, 6);
putInt((int) sourceId, 4);
putUnsignedInt((int) sequenceNum, 4);
putByte((byte) deviceType.getCode());
putInt((int) latLonToBinaryPackedLong(latitude), 4);
putInt((int) latLonToBinaryPackedLong(longitude), 4);
putInt((int) altitude, 4);
putInt(headingToSend, 2);
putInt((int) pitch, 2);
putInt((int) roll, 2);
putInt((int) boatSpeed, 2);
putUnsignedInt((int) COG, 2);
putUnsignedInt((int) SOG, 2);
putUnsignedInt((int) apparentWindSpeed, 2);
putInt((int) apparentWindAngle, 2);
putUnsignedInt((int) trueWindSpeed, 2);
putUnsignedInt((int) trueWindDirection, 2);
putInt((int) trueWindAngle, 2);
putUnsignedInt((int) currentDrift, 2);
putUnsignedInt((int) currentSet, 2);
putInt((int) rudderAngle, 2);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,25 @@
package seng302.server.messages;
/**
* The current status of a boat
*/
public enum BoatStatus {
UNDEFINED(0),
PRESTART(1),
RACING(2),
FINISHED(3),
DNS(4),
DNF(5),
DSQ(6),
CS(7);
private long code;
BoatStatus(long code) {
this.code = code;
}
public long getCode(){
return code;
}
}
@@ -0,0 +1,85 @@
package seng302.server.messages;
import java.nio.ByteBuffer;
/**
* The status of each boat, sent within a race status message
*/
public class BoatSubMessage{
private final int MESSAGE_SIZE = 20;
private long sourceId;
private BoatStatus boatStatus;
private long legNumber;
private long numberPenaltiesAwarded;
private long numberPenaltiesServed;
private long estimatedTimeAtNextMark;
private long estimatedTimeAtFinish;
private ByteBuffer buff = ByteBuffer.allocate(getSize());
private int buffPos = 0;
/**
* Boat Sub message from section 4.2 of the AC35 streaming data interface spec
* @param sourceId The source ID of the boat
* @param boatStatus The boats status
* @param legNumber The leg the boat is on (0= prestart, 1=start to first mark etc)
* @param numberPenaltiesAwarded The number of penalties awarded to the boat
* @param numberPenaltiesServed The number of penalties served to the boat
* @param estimatedTimeAtFinish The estimated time (UTC) the boat will finish the race
* @param estimatedTimeAtNextMark The estimated time (UTC) the boat will arrive at the next mark
*/
public BoatSubMessage(long sourceId, BoatStatus boatStatus, long legNumber, long numberPenaltiesAwarded, long numberPenaltiesServed,
long estimatedTimeAtFinish, long estimatedTimeAtNextMark){
this.sourceId = sourceId;
this.boatStatus = boatStatus;
this.legNumber = legNumber;
this.numberPenaltiesAwarded = numberPenaltiesAwarded;
this.numberPenaltiesServed = numberPenaltiesServed;
this.estimatedTimeAtFinish = estimatedTimeAtFinish;
this.estimatedTimeAtNextMark = estimatedTimeAtNextMark;
}
/**
* @return The size of this message in bytes
*/
public int getSize(){
return MESSAGE_SIZE;
}
private void putInBuffer(byte[] bytes, long val){
byte[] tmp = bytes.clone();
Message.reverse(tmp);
buff.put(tmp);
buffPos += tmp.length;
buff.position(buffPos);
}
/**
* @return a ByteBuffer containing this boat status message
*/
public ByteBuffer getByteBuffer(){
// Source ID, 4 bytes
putInBuffer(Message.intToByteArray(sourceId, 4), 4);
// Boat Status, 1 byte
putInBuffer(ByteBuffer.allocate(1).put((byte) (boatStatus.getCode() & 0xff)).array(), 1);
// Leg number, 1 byte
putInBuffer(ByteBuffer.allocate(1).put((byte) (legNumber & 0xff)).array(), 1);
// Number of penalties awarded, 1 byte
putInBuffer(ByteBuffer.allocate(1).put((byte) (numberPenaltiesAwarded & 0xff)).array(), 1);
// Number of penalties served, 1 byte
putInBuffer(ByteBuffer.allocate(1).put((byte) (numberPenaltiesServed & 0xff)).array(), 1);
// Estimated time at next mark, 6 bytes
putInBuffer(Message.intToByteArray((int) estimatedTimeAtNextMark, 6),6);
// Estimated time at finish, 6 bytes
putInBuffer(Message.intToByteArray((int) estimatedTimeAtFinish, 6), 6);
return buff;
}
}
@@ -0,0 +1,16 @@
package seng302.server.messages;
public enum DeviceType {
UNKNOWN(0),
RACING_YACHT(1);
private long code;
DeviceType(long code) {
this.code = code;
}
public long getCode(){
return code;
}
}
@@ -0,0 +1,72 @@
package seng302.server.messages;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Collections;
public class Header {
// From API spec
private final int syncByte1 = 0x47;
private final int syncByte2 = 0x83;
private MessageType messageType;
private int timeStamp;
private int sourceId;
private short messageLength;
private static final int MESSAGE_LEN = 15;
private ByteBuffer buff;
private int buffPos;
/**
* Message Header from section 3.2 of the AC35 Streaming
* Data spec
* @param messageType The type of the message following this header
* @param sourceId The message source (as defined in the spec)
* @param messageLength The length of the message following this header
*/
public Header(MessageType messageType, int sourceId, Short messageLength){
this.messageType = messageType;
this.sourceId = sourceId;
this.messageLength = messageLength;
timeStamp = (int) (System.currentTimeMillis() / 1000L);
buff = ByteBuffer.allocate(MESSAGE_LEN);
buffPos = 0;
}
private void putInBuffer(byte[] bytes, long val){
byte[] tmp = bytes.clone();
Message.reverse(tmp);
buff.put(tmp);
buffPos += tmp.length;
buff.position(buffPos);
}
/**
* @return a ByteBuffer containing the message header
*/
public ByteBuffer getByteBuffer(){
putInBuffer(ByteBuffer.allocate(1).put((byte)syncByte1).array(), syncByte1);
putInBuffer(ByteBuffer.allocate(1).put((byte)syncByte2).array(), syncByte2);
putInBuffer(ByteBuffer.allocate(1).put((byte)messageType.getCode()).array(), messageType.getCode());
putInBuffer(Message.intToByteArray(timeStamp, 6), timeStamp);
putInBuffer(Message.intToByteArray(sourceId, 4), sourceId);
putInBuffer(Message.intToByteArray(messageLength, 2), messageLength);
return buff;
}
/**
* Returns the size of this message
* @return the size of the message
*/
public static Integer getSize(){
return MESSAGE_LEN;
}
}
@@ -0,0 +1,42 @@
package seng302.server.messages;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.zip.CRC32;
public class Heartbeat extends Message {
private final int MESSAGE_SIZE = 4;
private int seqNo;
/**
* Heartbeat from the AC35 Streaming data spec
* @param seqNo Increment every time a message is sent
*/
public Heartbeat(int seqNo){
this.seqNo = seqNo;
}
@Override
public int getSize() {
return MESSAGE_SIZE;
}
@Override
public void send(SocketChannel outputStream) throws IOException {
setHeader(new Header(MessageType.HEARTBEAT, 0x01, (short) getSize()));
allocateBuffer();
writeHeaderToBuffer();
putUnsignedInt(seqNo, 4);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,62 @@
package seng302.server.messages;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
public class MarkRoundingMessage extends Message{
private final long MESSAGE_VERSION_NUMBER = 1;
private final int MESSAGE_SIZE = 21;
private long time;
private long ackNumber;
private long raceId;
private long sourceId;
private RoundingBoatStatus boatStatus;
private RoundingSide roundingSide;
private long markId;
/**
* This message is sent when a boat passes a mark, start line, or finish line
* The purpose of this is to record the time when yachts cross marks
*/
public MarkRoundingMessage(int ackNumber, int raceId, int sourceId, RoundingBoatStatus roundingBoatStatus,
RoundingSide roundingSide, int markId){
this.time = System.currentTimeMillis() / 1000L;
this.ackNumber = ackNumber;
this.raceId = raceId;
this.sourceId = sourceId;
this.boatStatus = roundingBoatStatus;
this.roundingSide = roundingSide;
this.markId = markId;
setHeader(new Header(MessageType.MARK_ROUNDING, 1, (short) getSize()));
}
@Override
public int getSize() {
return MESSAGE_SIZE;
}
@Override
public void send(SocketChannel outputStream) throws IOException {
allocateBuffer();
writeHeaderToBuffer();
putByte((byte) MESSAGE_VERSION_NUMBER);
putInt((int) time, 6);
putInt((int) ackNumber, 2);
putInt((int) raceId, 4);
putInt((int) sourceId, 4);
putByte((byte) boatStatus.getCode());
putByte((byte) roundingSide.getCode());
putByte((byte) markId);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,20 @@
package seng302.server.messages;
/**
* Types of marks boats can round
*/
public enum MarkType {
UNKNOWN(0),
ROUNDING_MARK(1),
GATE(2);
private long code;
MarkType(long code) {
this.code = code;
}
public long getCode(){
return code;
}
}
@@ -0,0 +1,207 @@
package seng302.server.messages;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
import java.util.zip.CRC32;
public abstract class Message {
private final int CRC_SIZE = 4;
private Header header;
private ByteBuffer buffer;
private int bufferPosition;
private CRC32 crc;
/**
* @param header Set the header for this message
*/
void setHeader(Header header){
this.header = header;
}
/**
* @return the header specified for this message
*/
Header getHeader(){
return header;
}
/**
* @return the size of the message
*/
public abstract int getSize();
/**
* Send the message as through the outputStream
*/
public abstract void send(SocketChannel outputStream) throws IOException;
/**
* Allocate byte buffer to correct size
*/
void allocateBuffer(){
buffer = ByteBuffer.allocate(Header.getSize() + getSize() + CRC_SIZE);
buffer.order(ByteOrder.LITTLE_ENDIAN);
bufferPosition = 0;
}
/**
* Write the set header to the byte buffer
*/
void writeHeaderToBuffer(){
buffer.put(getHeader().getByteBuffer().array());
bufferPosition += Header.getSize();
buffer.position(bufferPosition);
}
/**
* Move the buffer position by n bytes
* @param size Number of bytes to move the buffer by
*/
private void moveBufferPositionBy(int size){
bufferPosition += size;
buffer.position(bufferPosition);
}
/**
* Put an unsigned byte in the buffer
*/
void putUnsignedByte(byte b){
buffer.put(ByteBuffer.allocate(1).put((byte) (b & 0xff)).array());
moveBufferPositionBy(1);
}
/**
* Put an signed byte in the buffer
*/
void putByte(byte b){
buffer.put(ByteBuffer.allocate(1).put(b).array());
moveBufferPositionBy(1);
}
/**
* Place an unsigned integer of the specified length in the buffer
* @param val The integer value to add (Note: This must be long due to java not supporting unsigned integers)
* @param size The size of the int to be added to the buffer
*/
void putUnsignedInt(long val, int size){
if (size <= 1){
putUnsignedByte((byte) val);
}
else if (size < 4){
// Use short
byte[] tmp = Message.intToByteArray(val, size); //ByteBuffer.allocate(size).putShort((short) (val & 0xffff)).array();
reverse(tmp);
buffer.put(tmp);
moveBufferPositionBy(size);
}
else{
// Use int
byte[] tmp = Message.intToByteArray(val, size);
reverse(tmp);
moveBufferPositionBy(size);
}
}
/**
* Put a signed int of a specified length in the buffer
* @param val The integer value to add
* @param size The size of the integer to be added to the buffer
*/
void putInt(long val, int size){
if (size < 4){
byte[] tmp = Message.intToByteArray(val, size);
reverse(tmp);
buffer.put(tmp);
}
else{
byte[] tmp = Message.intToByteArray(val, size);
reverse(tmp);
buffer.put(tmp);
}
moveBufferPositionBy(size);
}
/**
* Write an array of bytes to the buffer
* @param bytes to write
*/
void putBytes(byte[] bytes){
buffer.put(bytes);
moveBufferPositionBy(bytes.length);
}
/**
* Write a ByteBuffer of bytes to the buffer
* @param bytes to write
* @param size number of bytes
*/
void putBytes(ByteBuffer bytes, int size){
buffer.put(bytes.array());
moveBufferPositionBy(size);
}
/**
* Calculate the CRC of the buffer and append it to the end of the buffer
*/
void writeCRC(){
crc = new CRC32();
buffer.position(0);
byte[] data = Arrays.copyOfRange(buffer.array(), 0, buffer.array().length-CRC_SIZE);
crc.update(data);
buffer.position(bufferPosition);
putInt((int) crc.getValue(), CRC_SIZE);
}
/**
* @return The current buffer
*/
public ByteBuffer getBuffer(){
return buffer;
}
/**
* Rewind the buffer to the beginning
*/
void rewind(){
buffer.flip();
}
/**
* Convert an integer to an array of bytes
* @param val The value to add
* @param len The width of the integer in the buffer
* @return
*/
public static byte[] intToByteArray(long val, int len){
int index = 0;
byte[] data = new byte[len];
for (int i = 0; i < len; i++){
data[len - index - 1] = (byte) (val & 0xFF);
val >>>= 8;
index++;
}
return data;
}
/**
* Reverse an array of bytes
* @param data The byte[] to reverse
*/
public static void reverse(byte[] data) {
for (int left = 0, right = data.length - 1; left < right; left++, right--) {
byte temp = (byte) (data[left] & 0xff);
data[left] = (byte) (data[right] & 0xff);
data[right] = (byte) (temp & 0xff);
}
}
}
@@ -0,0 +1,34 @@
package seng302.server.messages;
/**
* Enum containing the types of messages
* sent by the server
*/
public enum MessageType {
HEARTBEAT(1),
RACE_STATUS(12),
DISPLAY_TEXT_MESSAGE(20),
XML_MESSAGE(26),
RACE_START_STATUS(27),
YACHT_EVENT_CODE(29),
YACHT_ACTION_CODE(31),
CHATTER_TEXT(36),
BOAT_LOCATION(37),
MARK_ROUNDING(38),
COURSE_WIND(44),
AVERAGE_WIND(47);
private int code;
MessageType(int code){
this.code = code;
}
/**
* Get the message code (From the API Spec)
* @return the message code
*/
int getCode(){
return this.code;
}
}
@@ -0,0 +1,21 @@
package seng302.server.messages;
/**
* The types of race start status messages
*/
public enum RaceStartNotificationType {
SET_RACE_START_TIME(1),
RACE_POSTPONED(2),
RACE_ABANDONED(3),
RACE_TERMINATED(4);
private final long type;
RaceStartNotificationType(long type) {
this.type = type;
}
long getType(){
return type;
}
}
@@ -0,0 +1,59 @@
package seng302.server.messages;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
public class RaceStartStatusMessage extends Message {
private final int MESSAGE_SIZE = 20;
private long version;
private long timeStamp;
private long ackNumber;
private long raceStartTime;
private long raceId;
private RaceStartNotificationType notificationType;
/**
* Message sent to clients with the expected start time of the race
* @param ackNumber Sequence number of message.
* @param raceStartTime Expected race start time
* @param raceId Race ID#
* @param notificationType Type of this notification
*/
public RaceStartStatusMessage(long ackNumber, long raceStartTime, long raceId, RaceStartNotificationType notificationType){
this.version = 1;
this.timeStamp = System.currentTimeMillis() / 1000L;
this.ackNumber = ackNumber;
this.raceStartTime = raceStartTime;
this.notificationType = notificationType;
this.raceId = raceId;
setHeader(new Header(MessageType.RACE_START_STATUS, 1, (short) getSize()));
}
@Override
public int getSize() {
return MESSAGE_SIZE;
}
@Override
public void send(SocketChannel outputStream) throws IOException {
allocateBuffer();
writeHeaderToBuffer();
putUnsignedByte((byte) version);
putInt((int) timeStamp, 6);
putInt((int) ackNumber, 2);
putInt((int) raceStartTime, 6);
putInt((int) raceId, 4);
putUnsignedByte((byte) notificationType.getType());
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,26 @@
package seng302.server.messages;
/**
* The current status of the race
*/
public enum RaceStatus {
NOTACTIVE(0),
WARNING(1), // Between 3:00 and 1:00 before start
PREPARATORY(2), // Less than 1:00 before start
STARTED(3),
ABANDONED(6),
POSTPONED(7),
TERMINATED(8),
RACE_START_TIME_NOT_SET(9),
PRESTART(10); // More than 3:00 before start
private int code;
RaceStatus(int code){
this.code = code;
}
public int getCode(){
return this.code;
}
}
@@ -0,0 +1,88 @@
package seng302.server.messages;
import java.io.IOException;
import java.nio.channels.SocketChannel;
import java.util.List;
import java.util.zip.CRC32;
public class RaceStatusMessage extends Message{
private final MessageType MESSAGE_TYPE = MessageType.RACE_STATUS;
private final int MESSAGE_VERSION = 2; //Always set to 1
private final int MESSAGE_BASE_SIZE = 24;
private long currentTime;
private long raceId;
private RaceStatus raceStatus;
private long expectedStartTime;
private WindDirection raceWindDirection;
private long windSpeed;
private long numBoatsInRace;
private RaceType raceType;
private List<BoatSubMessage> boats;
private CRC32 crc;
/**
* A message containing the current status of the race
* @param raceId The ID of the current race
* @param raceStatus The status of the race
* @param expectedStartTime The expected start time
* @param raceWindDirection The wind direction (north, east, south)
* @param windSpeed The wind speed in mm/sec
* @param numBoatsInRace The number of boats in the race
* @param raceType The race type (Match/fleet)
* @param sourceId The source of this message
* @param boats A list of boat status sub messages
*/
public RaceStatusMessage(long raceId, RaceStatus raceStatus, long expectedStartTime, WindDirection raceWindDirection,
long windSpeed, long numBoatsInRace, RaceType raceType, long sourceId, List<BoatSubMessage> boats){
currentTime = System.currentTimeMillis();
this.raceId = raceId;
this.raceStatus = raceStatus;
this.expectedStartTime = expectedStartTime;
this.raceWindDirection = raceWindDirection;
this.windSpeed = windSpeed;
this.numBoatsInRace = numBoatsInRace;
this.raceType = raceType;
this.boats = boats;
crc = new CRC32();
setHeader(new Header(MESSAGE_TYPE, (int) sourceId, (short) getSize()));
}
/**
* @return the size of this message in bytes
*/
@Override
public int getSize() {
return MESSAGE_BASE_SIZE + (20 * ((int) numBoatsInRace));
}
/**
* Send this message as a stream of bytes
* @param outputStream The output stream to send the message
*/
@Override
public void send(SocketChannel outputStream) throws IOException {
allocateBuffer();
writeHeaderToBuffer();
putByte((byte) MESSAGE_VERSION);
putInt(currentTime, 6);
putInt((int) raceId, 4);
putByte((byte) raceStatus.getCode());
putInt(expectedStartTime, 6);
putInt((int) raceWindDirection.getCode(), 2);
putInt((int) windSpeed, 2);
putByte((byte) numBoatsInRace);
putByte((byte) raceType.getCode());
for (BoatSubMessage boatSubMessage : boats){
putBytes(boatSubMessage.getByteBuffer(), boatSubMessage.getSize());
}
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,20 @@
package seng302.server.messages;
/**
* Enum containing the types of races
* sent by the server
*/
public enum RaceType {
MATCH_RACE(1),
FLEET_RACE(2);
private long code;
RaceType(long code){
this.code = code;
}
public long getCode(){
return code;
}
}
@@ -0,0 +1,21 @@
package seng302.server.messages;
/**
* The status of a boat rounding a mark
*/
public enum RoundingBoatStatus {
UNKNOWN(0),
RACING(1),
DSQ(2),
WITHDRAWN(3);
private long code;
RoundingBoatStatus(long code) {
this.code = code;
}
public long getCode(){
return code;
}
}
@@ -0,0 +1,20 @@
package seng302.server.messages;
/**
* The side the boat rounded the mark
*/
public enum RoundingSide {
UNKNOWN(0),
PORT(1),
STARBOARD(2);
private long code;
RoundingSide(long code) {
this.code = code;
}
public long getCode(){
return code;
}
}
@@ -0,0 +1,20 @@
package seng302.server.messages;
/**
* Enum containing the supported wind directions
*/
public enum WindDirection {
NORTH(0x0000L),
EAST(0x4000L),
SOUTH(0x8000L);
private long code;
WindDirection(long code) {
this.code = code;
}
public long getCode() {
return code;
}
}
@@ -0,0 +1,69 @@
package seng302.server.messages;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.zip.CRC32;
public class XMLMessage extends Message{
private final MessageType MESSAGE_TYPE = MessageType.XML_MESSAGE;
private final int MESSAGE_VERSION = 1; //Always set to 1
private final int MESSAGE_SIZE = 14;
// Message fields
private long timeStamp;
private long ack = 0x00; //Unused
private XMLMessageSubType xmlMessageSubType;
private long length;
private long sequence;
private String content;
/**
* XML Message from the AC35 Streaming data spec
* @param content The XML content
* @param type The XML Message Sub Type
*/
public XMLMessage(String content, XMLMessageSubType type, long sequenceNum){
this.content = content;
this.xmlMessageSubType = type;
timeStamp = System.currentTimeMillis() / 1000L;
ack = 0;
length = this.content.length();
sequence = sequenceNum;
setHeader(new Header(MESSAGE_TYPE, 0x01, (short) getSize()));
}
/**
* @return The length of this message
*/
public int getSize(){
return MESSAGE_SIZE + content.length();
}
/**
* Send this message as a stream of bytes
* @param outputStream The output stream to send the message
*/
public void send(SocketChannel outputStream) throws IOException {
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putUnsignedByte((byte) MESSAGE_VERSION);
putInt((int) ack, 2);
putInt((int) timeStamp, 6);
putByte((byte)xmlMessageSubType.getType());
putInt((int) sequence, 2);
putInt((int) length, 2);
putBytes(content.getBytes());
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,20 @@
package seng302.server.messages;
/**
* Enum containing the types of XML messages
*/
public enum XMLMessageSubType {
REGATTA(5),
RACE(6),
BOAT(7);
private int type;
XMLMessageSubType(int type){
this.type = type;
}
public int getType(){
return this.type;
}
}
@@ -0,0 +1,125 @@
package seng302.server.simulator;
import seng302.server.simulator.mark.Corner;
import seng302.server.simulator.mark.Position;
public class Boat {
private int sourceID;
private double lat;
private double lng;
private double speed; // in mm/sec
private String boatName, shortName, shorterName;
private boolean isFinished;
private long estimatedTimeTillFinish;
private Corner lastPassedCorner, headingCorner;
public Boat(int sourceID, String boatName) {
this.sourceID = sourceID;
this.boatName = boatName;
this.isFinished = false;
estimatedTimeTillFinish = 0;
}
/**
* Moves boat to the heading direction for a given time duration
* @param heading moving direction in degree.
* @param duration moving duration in millisecond.
*/
public void move(double heading, double duration) {
Double distance = speed * duration / 1000000; // convert mm to meter
Position originPos = new Position(lat, lng);
Position newPos = GeoUtility.getGeoCoordinate(originPos, heading, distance);
this.lat = newPos.getLat();
this.lng = newPos.getLng();
}
public String toString() {
return String.format("Boat (%d): lat: %f, lng: %f", sourceID, lat, lng);
}
public int getSourceID() {
return sourceID;
}
public void setSourceID(int sourceID) {
this.sourceID = sourceID;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLng() {
return lng;
}
public void setLng(double lng) {
this.lng = lng;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public String getBoatName() {
return boatName;
}
public void setBoatName(String boatName) {
this.boatName = boatName;
}
public String getShortName() {
return shortName;
}
public void setShortName(String shortName) {
this.shortName = shortName;
}
public String getShorterName() {
return shorterName;
}
public void setShorterName(String shorterName) {
this.shorterName = shorterName;
}
public Corner getLastPassedCorner() {
return lastPassedCorner;
}
public void setLastPassedCorner(Corner lastPassedCorner) {
this.lastPassedCorner = lastPassedCorner;
}
public Corner getHeadingCorner() {
return headingCorner;
}
public void setHeadingCorner(Corner headingCorner) {
this.headingCorner = headingCorner;
}
public boolean isFinished() {
return isFinished;
}
public void setFinished(boolean finished) {
isFinished = finished;
}
public long getEstimatedTimeTillFinish(){
return (long) (-getSpeed()) + System.currentTimeMillis();
}
}
@@ -0,0 +1,82 @@
package seng302.server.simulator;
import seng302.server.simulator.mark.Position;
public class GeoUtility {
private static double EARTH_RADIUS = 6378.137;
/**
* Calculates the euclidean distance between two markers on the canvas using xy coordinates
*
* @param p1 first geographical position
* @param p2 second geographical position
* @return the distance in meter between two points in meters
*/
public static Double getDistance(Position p1, Position p2) {
double dLat = Math.toRadians(p2.getLat() - p1.getLat());
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
double a = Math.pow(Math.sin(dLat / 2), 2.0)
+ Math.cos(Math.toRadians(p1.getLat())) * Math.cos(Math.toRadians(p2.getLat()))
* Math.pow(Math.sin(dLon / 2), 2.0);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = EARTH_RADIUS * c;
return d * 1000; // distance from km to meter
}
/**
* Calculates the angle between to angular co-ordinates on a sphere.
*
* @param p1 the first geographical position, start point
* @param p2 the second geographical position, end point
* @return the initial bearing in degree from p1 to p2, value range (0 ~ 360 deg.).
* vertical up is 0 deg. horizontal right is 90 deg.
*
* NOTE:
* The final bearing will differ from the initial bearing by varying degrees
* according to distance and latitude (if you were to go from say 35°N,45°E
* (≈ Baghdad) to 35°N,135°E (≈ Osaka), you would start on a heading of 60°
* and end up on a heading of 120°
*/
public static Double getBearing(Position p1, Position p2) {
double dLon = Math.toRadians(p2.getLng() - p1.getLng());
double y = Math.sin(dLon) * Math.cos(Math.toRadians(p2.getLat()));
double x = Math.cos(Math.toRadians(p1.getLat())) * Math.sin(Math.toRadians(p2.getLat()))
- Math.sin(Math.toRadians(p1.getLat())) * Math.cos(Math.toRadians(p2.getLat())) * Math.cos(dLon);
double bearing = Math.toDegrees(Math.atan2(y, x));
return (bearing + 360.0) % 360.0;
}
/**
* Given an existing point in lat/lng, distance in (in meter) and bearing
* (in degrees), calculates the new lat/lng.
*
* @param origin the original position within lat / lng
* @param bearing the bearing in degree, from original position to the new position
* @param distance the distance in meter, from original position to the new position
* @return the new position
*/
public static Position getGeoCoordinate(Position origin, Double bearing, Double distance) {
double b = Math.toRadians(bearing); // bearing to radians
double d = distance / 1000.0; // distance to km
double originLat = Math.toRadians(origin.getLat());
double originLng = Math.toRadians(origin.getLng());
double endLat = Math.asin(Math.sin(originLat) * Math.cos(d / EARTH_RADIUS)
+ Math.cos(originLat) * Math.sin(d / EARTH_RADIUS) * Math.cos(b));
double endLng = originLng
+ Math.atan2(Math.sin(b) * Math.sin(d / EARTH_RADIUS) * Math.cos(originLat),
Math.cos(d / EARTH_RADIUS) - Math.sin(originLat) * Math.sin(endLat));
return new Position(Math.toDegrees(endLat), Math.toDegrees(endLng));
}
}
@@ -0,0 +1,138 @@
package seng302.server.simulator;
import seng302.server.simulator.mark.Corner;
import seng302.server.simulator.mark.Mark;
import seng302.server.simulator.mark.Position;
import seng302.server.simulator.parsers.RaceParser;
import java.util.List;
import java.util.Observable;
import java.util.concurrent.ThreadLocalRandom;
public class Simulator extends Observable implements Runnable {
private List<Corner> course;
private List<Boat> boats;
private long lapse;
private boolean isRaceStarted;
/**
* Creates a simulator instance with given time lapse.
* @param lapse time duration in millisecond.
*/
public Simulator(long lapse) {
RaceParser rp = new RaceParser("/server_config/race.xml");
course = rp.getCourse();
boats = rp.getBoats();
this.lapse = lapse;
isRaceStarted = false;
setLegs();
// set start line's coordinate to boats
Double startLat = course.get(0).getCompoundMark().getMark1().getLat();
Double startLng = course.get(0).getCompoundMark().getMark1().getLng();
for (Boat boat : boats) {
boat.setLat(startLat);
boat.setLng(startLng);
boat.setLastPassedCorner(course.get(0));
boat.setHeadingCorner(course.get(1));
boat.setSpeed(ThreadLocalRandom.current().nextInt(40000, 60000 + 1));
}
}
@Override
public void run() {
int numOfFinishedBoats = 0;
while (numOfFinishedBoats < boats.size()) {
// if race has started, then boat should start to move.
if (isRaceStarted) {
for (Boat boat : boats) {
numOfFinishedBoats += moveBoat(boat, lapse);
}
}
setChanged();
notifyObservers(boats);
try {
Thread.sleep(lapse);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* Moves a boat with given time duration.
* @param boat the boat to be moved
* @param duration the moving duration in milliseconds
* @return 1 if the boat has reached the final line, otherwise return 0
*/
private int moveBoat(Boat boat, double duration) {
if (boat.getHeadingCorner() != null) {
boat.move(boat.getLastPassedCorner().getBearingToNextCorner(), duration);
Position boatPos = new Position(boat.getLat(), boat.getLng());
Position lastMarkPos = boat.getLastPassedCorner().getCompoundMark().getMark1();
double distanceFromLastMark = GeoUtility.getDistance(boatPos, lastMarkPos);
// if a boat passes its heading mark
while (distanceFromLastMark >= boat.getLastPassedCorner().getDistanceToNextCorner()) {
double compensateDistance = distanceFromLastMark - boat.getLastPassedCorner().getDistanceToNextCorner();
boat.setLastPassedCorner(boat.getHeadingCorner());
boat.setHeadingCorner(boat.getLastPassedCorner().getNextCorner());
// heading corner == null means boat has reached the final mark
if (boat.getHeadingCorner() == null) {
boat.setFinished(true);
return 1;
}
// move compensate distance for the mark just passed
Position pos = GeoUtility.getGeoCoordinate(
boat.getLastPassedCorner().getCompoundMark().getMark1(),
boat.getLastPassedCorner().getBearingToNextCorner(),
compensateDistance);
boat.setLat(pos.getLat());
boat.setLng(pos.getLng());
distanceFromLastMark = GeoUtility.getDistance(new Position(boat.getLat(), boat.getLng()),
boat.getLastPassedCorner().getCompoundMark().getMark1());
}
}
return 0;
}
/**
* Link all the corners in the course list so that every corner knows its next
* corner, as well as the distance and bearing to its next corner. However,
* the last corner's heading is null, which means it is the final line.
*/
private void setLegs() {
// get the bearing from one mark to the next heading mark
for (int i = 0; i < course.size() - 1; i++) {
Mark mark1 = course.get(i).getCompoundMark().getMark1();
Mark mark2 = course.get(i + 1).getCompoundMark().getMark1();
course.get(i).setDistanceToNextCorner(GeoUtility.getDistance(mark1, mark2));
course.get(i).setNextCorner(course.get(i + 1));
course.get(i).setBearingToNextCorner(
GeoUtility.getBearing(course.get(i).getCompoundMark().getMark1(),
course.get(i + 1).getCompoundMark().getMark1()));
}
}
public List<Boat> getBoats(){
return boats;
}
public void setRaceStarted(boolean raceStarted) {
isRaceStarted = raceStarted;
}
}
@@ -0,0 +1,70 @@
package seng302.server.simulator.mark;
public class CompoundMark {
private int markID;
private String name;
private Mark mark1;
private Mark mark2;
public CompoundMark(int markID, String name) {
this.markID = markID;
this.name = name;
}
public void addMark(int seqId, Mark mark) {
if (seqId == 1) {
setMark1(mark);
} else if (seqId == 2) {
setMark2(mark);
}
}
/**
* Prints out compoundMark's info and its marks, good for testing
* @return a string showing its details
*/
@Override
public String toString(){
if (mark2 == null)
return String.format("CompoundMark: %d (%s), [%s]",
markID, name, mark1.toString());
return String.format("CompoundMark: %d (%s), [%s; %s]",
markID, name, mark1.toString(), mark2.toString());
}
public int getMarkID() {
return markID;
}
public void setMarkID(int markID) {
this.markID = markID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Mark getMark1() {
return mark1;
}
public void setMark1(Mark mark1) {
this.mark1 = mark1;
mark1.setSeqID(1);
}
public Mark getMark2() {
return mark2;
}
public void setMark2(Mark mark2) {
this.mark2 = mark2;
mark2.setSeqID(2);
}
}
@@ -0,0 +1,89 @@
package seng302.server.simulator.mark;
public class Corner {
private int seqID;
private CompoundMark compoundMark;
//private int CompoundMarkID;
private RoundingType roundingType;
private int zoneSize; // size of the zone around a mark in boat-lengths.
// TODO: this shouldn't be used in the future!!!!
private double bearingToNextCorner, distanceToNextCorner;
private Corner nextCorner;
public Corner(int seqID, CompoundMark compoundMark, RoundingType roundingType, int zoneSize) {
this.seqID = seqID;
this.compoundMark = compoundMark;
this.roundingType = roundingType;
this.zoneSize = zoneSize;
}
/**
* Prints out corner's info and its compound mark, good for testing
* @return a string showing its details
*/
@Override
public String toString() {
return String.format("Corner: %d - %s - %d, %s\n",
seqID, roundingType.getType(), zoneSize, compoundMark.toString());
}
public int getSeqID() {
return seqID;
}
public void setSeqID(int seqID) {
this.seqID = seqID;
}
public CompoundMark getCompoundMark() {
return compoundMark;
}
public void setCompoundMark(CompoundMark compoundMark) {
this.compoundMark = compoundMark;
}
public RoundingType getRoundingType() {
return roundingType;
}
public void setRoundingType(RoundingType roundingType) {
this.roundingType = roundingType;
}
public int getZoneSize() {
return zoneSize;
}
public void setZoneSize(int zoneSize) {
this.zoneSize = zoneSize;
}
// TODO: next six setters & getters shouldn't be used in the future.
public double getBearingToNextCorner() {
return bearingToNextCorner;
}
public void setBearingToNextCorner(double bearingToNextCorner) {
this.bearingToNextCorner = bearingToNextCorner;
}
public double getDistanceToNextCorner() {
return distanceToNextCorner;
}
public void setDistanceToNextCorner(double distanceToNextCorner) {
this.distanceToNextCorner = distanceToNextCorner;
}
public Corner getNextCorner() {
return nextCorner;
}
public void setNextCorner(Corner nextCorner) {
this.nextCorner = nextCorner;
}
}
@@ -0,0 +1,53 @@
package seng302.server.simulator.mark;
/**
* An abstract class to represent general marks
* Created by Haoming Yin (hyi25) on 17/3/17.
*/
public class Mark extends Position {
private int seqID;
private String name;
private int sourceID;
public Mark(String name, double lat, double lng, int sourceID) {
super(lat, lng);
this.name = name;
this.sourceID = sourceID;
}
/**
* Prints out mark's info and its geo location, good for testing
* @return a string showing its details
*/
@Override
public String toString() {
return String.format("Mark%d: %s, source: %d, lat: %f, lng: %f", seqID, name, sourceID, lat, lng);
}
public int getSeqID() {
return seqID;
}
public void setSeqID(int seqID) {
this.seqID = seqID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSourceID() {
return sourceID;
}
public void setSourceID(int sourceID) {
this.sourceID = sourceID;
}
}
@@ -0,0 +1,31 @@
package seng302.server.simulator.mark;
public class Position {
double lat, lng;
public Position(double lat, double lng) {
this.lat = lat;
this.lng = lng;
}
public String toString() {
return String.format("Position at lat:%f lng:%f.", lat, lng);
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLng() {
return lng;
}
public void setLng(double lng) {
this.lng = lng;
}
}
@@ -0,0 +1,43 @@
package seng302.server.simulator.mark;
public enum RoundingType {
// the mark should be rounded to port (boat's left)
PORT("Port"),
// the mark should be rounded to starboard (boat's right)
STARBOARD("Stbd"),
// the boat within the compound mark with the SeqID of 1 should be rounded
// to starboard and the boat within the compound mark with the SeqID of 2
// should be rounded to port.
SP("SP"),
// the opposite of SP
PS("PS");
private String type;
RoundingType(String type) {
this.type = type;
}
public String getType() {
return this.type;
}
public static RoundingType typeOf(String type) {
switch (type) {
case "Port":
return PORT;
case "Stbd":
return STARBOARD;
case "SP":
return SP;
case "PS":
return PS;
default:
return null;
}
}
}
@@ -0,0 +1,20 @@
package seng302.server.simulator.parsers;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
/**
* Parses the race xml file to get course details
* Created by Haoming Yin (hyi25) on 16/3/2017
*/
public class BoatsParser extends FileParser {
private Document doc;
public BoatsParser(String path) {
super(path);
this.doc = this.parseFile();
}
}
@@ -0,0 +1,118 @@
package seng302.server.simulator.parsers;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import seng302.server.simulator.mark.CompoundMark;
import seng302.server.simulator.mark.Corner;
import seng302.server.simulator.mark.Mark;
import seng302.server.simulator.mark.RoundingType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Parses the race xml file to get course details
* Created by Haoming Yin (hyi25) on 16/3/2017
*/
public class CourseParser extends FileParser {
private Document doc;
private Map<Integer, CompoundMark> compoundMarksMap;
public CourseParser(String path) {
super(path);
this.doc = this.parseFile();
}
// TODO: should handle error / invalid file gracefully
protected List<Corner> getCourse() {
compoundMarksMap = getCompoundMarks(doc.getDocumentElement());
List<Corner> corners = new ArrayList<>();
NodeList cMarksSequence = doc.getElementsByTagName("Corner");
for (int i = 0; i < cMarksSequence.getLength(); i++) {
corners.add(getCorner(cMarksSequence.item(i)));
}
return corners;
}
private Corner getCorner(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
Integer seqId = Integer.valueOf(e.getAttribute("SeqID"));
Integer cMarkId = Integer.valueOf(e.getAttribute("CompoundMarkID"));
CompoundMark cMark = compoundMarksMap.get(cMarkId);
RoundingType roundingType = RoundingType.typeOf(e.getAttribute("Rounding"));
Integer zoneSize = Integer.valueOf(e.getAttribute("ZoneSize"));
return new Corner(seqId, cMark, roundingType, zoneSize);
}
return null;
}
private Map<Integer, CompoundMark> getCompoundMarks(Node node) {
Map<Integer, CompoundMark> compoundMarksMap = new HashMap<>();
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
NodeList cMarks = element.getElementsByTagName("CompoundMark");
// loop through all compound marks who are the children of course node
for (int i = 0; i < cMarks.getLength(); i++) {
CompoundMark cMark = getCompoundMark(cMarks.item(i));
if (cMark != null)
compoundMarksMap.put(cMark.getMarkID(), cMark);
}
return compoundMarksMap;
}
return null;
}
private CompoundMark getCompoundMark(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
Integer markID = Integer.valueOf(e.getAttribute("CompoundMarkID"));
String name = e.getAttribute("Name");
CompoundMark cMark = new CompoundMark(markID, name);
NodeList marks = e.getElementsByTagName("Mark");
for (int i = 0; i < marks.getLength(); i++) {
Mark mark = getMark(marks.item(i));
if (mark != null)
cMark.addMark(mark.getSeqID(), mark);
}
return cMark;
}
System.out.println("Failed to create compound mark.");
return null;
}
private Mark getMark(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
Integer seqId = Integer.valueOf(e.getAttribute("SeqID"));
String name = e.getAttribute("Name");
Double lat = Double.valueOf(e.getAttribute("TargetLat"));
Double lng = Double.valueOf(e.getAttribute("TargetLng"));
Integer sourceId = Integer.valueOf(e.getAttribute("SourceID"));
Mark mark = new Mark(name, lat, lng, sourceId);
mark.setSeqID(seqId);
return mark;
}
System.out.println("Failed to create mark.");
return null;
}
}
@@ -1,12 +1,12 @@
package seng302.models.parsers; package seng302.server.simulator.parsers;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader;
/** /**
* Created by Haoming Yin (hyi25) on 16/3/2017 * Created by Haoming Yin (hyi25) on 16/3/2017
@@ -15,6 +15,8 @@ public abstract class FileParser {
private String filePath; private String filePath;
public FileParser() {}
public FileParser(String path) { public FileParser(String path) {
this.filePath = path; this.filePath = path;
} }
@@ -32,6 +34,19 @@ public abstract class FileParser {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
}
protected Document parseFile(String xmlString) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
// optional, in order to recover info from broken line.
doc.getDocumentElement().normalize();
return doc;
} catch (Exception e) {
e.printStackTrace();
}
return null;
} }
} }
@@ -0,0 +1,66 @@
package seng302.server.simulator.parsers;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import seng302.server.simulator.Boat;
import seng302.server.simulator.mark.Corner;
import java.util.ArrayList;
import java.util.List;
/**
* Parses the race xml file to get course details
* Created by Haoming Yin (hyi25) on 16/3/2017
*/
public class RaceParser extends FileParser {
private Document doc;
private String path;
public RaceParser(String path) {
super(path);
this.path = path;
this.doc = this.parseFile();
}
/**
* Parses race.xml file and returns a list of corner which is the race course.
* @return a list of ordered corner to represent the course.
*/
public List<Corner> getCourse() {
CourseParser cp = new CourseParser(path);
return cp.getCourse();
}
/**
* Parses race.xml file and return a list of boats which will compete in the
* race.
* @return a list of boats that are going to compete in the race.
*/
public List<Boat> getBoats() {
NodeList yachts = doc.getDocumentElement().getElementsByTagName("Yacht");
List<Boat> boats = new ArrayList<>();
for (int i = 0; i < yachts.getLength(); i++) {
boats.add(getBoat(yachts.item(i)));
}
return boats;
}
/**
* Parses a single boat from the given node
* @param node a node within a boat tag
* @return a boat instance parsed from the given node
*/
private Boat getBoat(Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
Integer sourceId = Integer.valueOf(e.getAttribute("SourceID"));
return new Boat(sourceId, "Test Boat");
}
return null;
}
}
+8
View File
@@ -0,0 +1,8 @@
Tws,Twa0,Bsp0,Twa1,Bsp1,UpTwa,UpBsp,Twa2,Bsp2,Twa3,Bsp3,Twa4,Bsp4,Twa5,Bsp5,Twa6,Bsp6,DnTwa,DnBsp,Twa7,Bsp7
4,0,0,30,4,45,8,60,9,75,10,90,10,115,10,145,10,155,10,175,4
8,0,0,30,7,43,10,60,11,75,11,90,11,115,12,145,12,153,12,175,10
12,0,0,30,11,43,14.4,60,16,75,20,90,23,115,24,145,23,153,21.6,175,14
16,0,0,30,12,42,19.2,60,25,75,27,90,31,115,32,145,30,153,28.8,175,20
20,0,0,30,13,41,24,60,29,75,37,90,39,115,40,145,38,153,36,175,24
25,0,0,30,15,40,30,60,38,75,44,90,49,115,50,145,49,151,47,175,30
30,0,0,30,15,42,30,60,37,75,42,90,48,115,49,145,48,150,46,175,32
1 Tws Twa0 Bsp0 Twa1 Bsp1 UpTwa UpBsp Twa2 Bsp2 Twa3 Bsp3 Twa4 Bsp4 Twa5 Bsp5 Twa6 Bsp6 DnTwa DnBsp Twa7 Bsp7
2 4 0 0 30 4 45 8 60 9 75 10 90 10 115 10 145 10 155 10 175 4
3 8 0 0 30 7 43 10 60 11 75 11 90 11 115 12 145 12 153 12 175 10
4 12 0 0 30 11 43 14.4 60 16 75 20 90 23 115 24 145 23 153 21.6 175 14
5 16 0 0 30 12 42 19.2 60 25 75 27 90 31 115 32 145 30 153 28.8 175 20
6 20 0 0 30 13 41 24 60 29 75 37 90 39 115 40 145 38 153 36 175 24
7 25 0 0 30 15 40 30 60 38 75 44 90 49 115 50 145 49 151 47 175 30
8 30 0 0 30 15 42 30 60 37 75 42 90 48 115 49 145 48 150 46 175 32
+29 -20
View File
@@ -1,62 +1,71 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<course> <markers>
<marks> <marks>
<gate> <gate>
<name type="start-line">Start</name> <name type="start-line">Start</name>
<mark> <mark>
<name>Start1</name> <name>Start1</name>
<latitude>32.296577</latitude> <latitude>57.6703330</latitude>
<longitude>-64.854304</longitude> <longitude>11.8278330</longitude>
<id>122</id>
</mark> </mark>
<mark> <mark>
<name>Start2</name> <name>Start2</name>
<latitude>32.293771</latitude> <latitude>57.6706330</latitude>
<longitude>-64.855242</longitude> <longitude>11.8281330</longitude>
<id>123</id>
</mark> </mark>
</gate> </gate>
<mark> <mark>
<name>Mid Mark</name> <name>Mid Mark</name>
<latitude>32.293039</latitude> <latitude>57.6675700</latitude>
<longitude>-64.843983</longitude> <longitude>11.8359880</longitude>
<id>131</id>
</mark> </mark>
<gate> <gate>
<name>Leeward Gate</name> <name>Leeward Gate</name>
<mark> <mark>
<name>Leeward Gate1</name> <name>Leeward Gate1</name>
<latitude>32.284680</latitude> <latitude>57.6708220</latitude>
<longitude>-64.850045</longitude> <longitude>11.8433900</longitude>
<id>124</id>
</mark> </mark>
<mark> <mark>
<name>Leeward Gate2</name> <name>Leeward Gate2</name>
<latitude>32.280164</latitude> <latitude>57.6711220</latitude>
<longitude>-64.847591</longitude> <longitude>11.8436900</longitude>
<id>125</id>
</mark> </mark>
</gate> </gate>
<gate> <gate>
<name>Windward Gate</name> <name>Windward Gate</name>
<mark> <mark>
<name>Windward Gate1</name> <name>Windward Gate1</name>
<latitude>32.309693</latitude> <latitude>57.6650170</latitude>
<longitude>-64.835249</longitude> <longitude>11.8279170</longitude>
<id>126</id>
</mark> </mark>
<mark> <mark>
<name>Windward Gate2</name> <name>Windward Gate2</name>
<latitude>32.308046</latitude> <latitude>57.6653170</latitude>
<longitude>-64.831785</longitude> <longitude>11.8282170</longitude>
<id>127</id>
</mark> </mark>
</gate> </gate>
<gate type="finish-line"> <gate type="finish-line">
<name>Finish</name> <name>Finish</name>
<mark> <mark>
<name>Finish1</name> <name>Finish1</name>
<latitude>32.317379</latitude> <latitude>57.6715240</latitude>
<longitude>-64.839291</longitude> <longitude>11.8444950</longitude>
<id>128</id>
</mark> </mark>
<mark> <mark>
<name>Finish2</name> <name>Finish2</name>
<latitude>32.317257</latitude> <latitude>57.6718240</latitude>
<longitude>-64.836260</longitude> <longitude>11.8447950</longitude>
<id>129</id>
</mark> </mark>
</gate> </gate>
</marks> </marks>
@@ -68,4 +77,4 @@
<five>Leeward Gate</five> <five>Leeward Gate</five>
<six>Finish</six> <six>Finish</six>
</order> </order>
</course> </markers>
+72
View File
@@ -0,0 +1,72 @@
<?xml version="1.0" ?>
<course>
<marks>
<gate>
<name type="start-line">Start</name>
<mark>
<name>Start1</name>
<latitude>32.296577</latitude>
<longitude>-64.854304</longitude>
</mark>
<mark>
<name>Start2</name>
<latitude>32.293771</latitude>
<longitude>-64.855242</longitude>
</mark>
</gate>
<mark>
<name>Mid Mark</name>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</mark>
<gate>
<name>Leeward Gate</name>
<mark>
<name>Leeward Gate1</name>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
</mark>
<mark>
<name>Leeward Gate2</name>
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</mark>
</gate>
<gate>
<name>Windward Gate</name>
<mark>
<name>Windward Gate1</name>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</mark>
<mark>
<name>Windward Gate2</name>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</mark>
</gate>
<gate type="finish-line">
<name>Finish</name>
<mark>
<name>Finish1</name>
<latitude>32.317379</latitude>
<longitude>-64.839291</longitude>
</mark>
<mark>
<name>Finish2</name>
<latitude>32.317257</latitude>
<longitude>-64.836260</longitude>
</mark>
</gate>
</marks>
<order>
<one>Start</one>
<two>Mid Mark</two>
<three>Leeward Gate</three>
<four>Windward Gate</four>
<five>Leeward Gate</five>
<six>Finish</six>
</order>
</course>
+12 -6
View File
@@ -4,31 +4,37 @@
<team> <team>
<name>Oracle Team USA</name> <name>Oracle Team USA</name>
<alias>USA</alias> <alias>USA</alias>
<velocity>12.9</velocity> <velocity>0.0</velocity>
<id>102</id>
</team> </team>
<team> <team>
<name>Artemis Racing</name> <name>Artemis Racing</name>
<alias>ART</alias> <alias>ART</alias>
<velocity>13.1</velocity> <velocity>0.0</velocity>
<id>101</id>
</team> </team>
<team> <team>
<name>Emirates Team New Zealand</name> <name>Emirates Team New Zealand</name>
<alias>NZL</alias> <alias>NZL</alias>
<velocity>15.6</velocity> <velocity>0.0</velocity>
<id>103</id>
</team> </team>
<team> <team>
<name>Land Rover BAR</name> <name>Land Rover BAR</name>
<alias>BAR</alias> <alias>BAR</alias>
<velocity>13.3</velocity> <velocity>0.0</velocity>
<id>104</id>
</team> </team>
<team> <team>
<name>SoftBank Team Japan</name> <name>SoftBank Team Japan</name>
<alias>JAP</alias> <alias>JAP</alias>
<velocity>14.7</velocity> <velocity>0.0</velocity>
<id>105</id>
</team> </team>
<team> <team>
<name>Groupama Team France</name> <name>Groupama Team France</name>
<alias>FRC</alias> <alias>FRC</alias>
<velocity>11.4</velocity> <velocity>0.0</velocity>
<id>106</id>
</team> </team>
</teams> </teams>
+200
View File
@@ -0,0 +1,200 @@
/**
Background colours
*/
.background-blue{
-fx-background-color: #119796;
}
.background-dark{
-fx-background-color: #2C2c36;
}
/**
Exit button with no background
*/
.clear-exit-btn{
-fx-background-insets: 0;
-fx-background-color: #119796;
-fx-border-style: none;
}
/**
Buttons
*/
.blue-ui-btn{
-fx-background-color: #119796;
-fx-text-fill: #fff;
}
.text-white {
-fx-text-fill: white !important;
-fx-fill:white !important;
}
/**
Sliders
*/
.ui-slider .thumb {
-fx-background-color: rgb(60, 60, 60);
-fx-border-radius: 10;
-fx-border-color: darkgray;
}
.ui-slider .track{
-fx-background-color: #119796;
}
.ui-slider .axis{
-fx-tick-label-fill: white;
}
.ui-slider .axis .axis-label{
-fx-text-fill: white;
}
/**
Checkbox
*/
.ui-checkbox .box{
-fx-background-color: white;
-fx-graphic:none;
-fx-shape: none;
}
.ui-checkbox .box .mark{
-fx-background-image: none;
-fx-image: none;
-fx-graphic: none;
-fx-shape: none;
}
.ui-checkbox:selected .box{
-fx-background-color: #119796;
-fx-shape: none;
}
.ui-checkbox:selected .box .mark{
-fx-background-color: #119796;
-fx-shape: none;
-fx-graphic: none;
}
/**
Table
*/
.ui-table{
-fx-background-color: transparent;
}
.ui-table:focused{
-fx-background-color: transparent;
}
.ui-table .column-header-background{
-fx-background-color: white
}
.ui-table .column-header-background .label{
-fx-background-color: transparent;
-fx-text-fill: black;
}
.ui-table .column-header {
-fx-background-color: transparent;
}
.ui-table .table-cell{
-fx-text-fill: white;
-fx-border-style: none;
}
.table-row-cell{
-fx-background-color: #119796;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.0em; /* 0 */
-fx-border-style: none;
}
.table-row-cell:odd{
-fx-background-color: #0e6d6c;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.0em; /* 0 */
-fx-border-style: none;
}
.table-row-cell:selected {
-fx-background-color: #005797;
-fx-background-insets: 0;
-fx-border-style: none;
}
/**
Combo Box
*/
.combo-box-base {
-fx-background-color: #119796;
-fx-text-fill: white;
}
.combo-box-popup .list-view .list-cell:hover {
-fx-text-fill: white;
}
.combo-box .cell:selected {
-fx-text-fill: white;
}
/**
Remove scroll bars
*/
.ui-table *.scroll-bar:horizontal *.increment-button,
.ui-table *.scroll-bar:horizontal *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.ui-table *.scroll-bar:horizontal *.increment-arrow,
.ui-table *.scroll-bar:horizontal *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
.ui-table *.scroll-bar:vertical *.increment-arrow,
.ui-table *.scroll-bar:vertical *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
.ui-table *.scroll-bar:vertical *.increment-button,
.ui-table *.scroll-bar:vertical *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.chart{
}
.chart-title {
-fx-text-fill: #ffffff;
-fx-font-size: 1.6em;
}
.axis-label {
-fx-text-fill: #ffffff;
}
.axis {
-fx-tick-label-fill: #ffffff;
}
+171
View File
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="utf-8"?>
<BoatConfig>
<Modified>2015-08-28T17:32:59+0100</Modified>
<Version>12</Version>
<Snapshot>219</Snapshot>
<Settings>
<RaceBoatType Type="AC45"/>
<BoatDimension BoatLength="14.019" HullLength="13.449"/>
<ZoneSize MarkZoneSize="40.347" CourseZoneSize="53.796"/>
<ZoneLimits Limit1="200" Limit2="100" Limit3="53.796" Limit4="0" Limit5="-100"/>
</Settings>
<BoatShapes>
<BoatShape ShapeID="0">
<Vertices>
<Vtx Seq="3" Y="25" X="0"/>
</Vertices>
</BoatShape>
<BoatShape ShapeID="14">
<Vertices>
<Vtx Seq="1" Y="0" X="-1"/>
<Vtx Seq="2" Y="0.75" X="-1"/>
<Vtx Seq="3" Y="0.75" X="-0.25"/>
<Vtx Seq="4" Y="3.5" X="-0.25"/>
<Vtx Seq="5" Y="4.5" X="-1"/>
<Vtx Seq="6" Y="6.5" X="-1"/>
<Vtx Seq="7" Y="7" X="-0.5"/>
<Vtx Seq="8" Y="7" X="0.5"/>
<Vtx Seq="9" Y="6.5" X="1"/>
<Vtx Seq="10" Y="4.5" X="1"/>
<Vtx Seq="11" Y="3.5" X="0.25"/>
<Vtx Seq="12" Y="0.75" X="0.25"/>
<Vtx Seq="13" Y="0.75" X="1"/>
<Vtx Seq="14" Y="0" X="1"/>
</Vertices>
</BoatShape>
<BoatShape ShapeID="15">
<Vertices>
<Vtx Seq="1" Y="0" X="-3.46"/>
<Vtx Seq="2" Y="13.449" X="-3.46"/>
<Vtx Seq="3" Y="14.019" X="0"/>
<Vtx Seq="4" Y="13.449" X="3.46"/>
<Vtx Seq="5" Y="0" X="3.46"/>
</Vertices>
<Catamaran>
<Vtx Seq="1" Y="1.769" X="-2.752"/>
<Vtx Seq="2" Y="0" X="-2.813"/>
<Vtx Seq="3" Y="0" X="-3.34"/>
<Vtx Seq="4" Y="5.351" X="-3.46"/>
<Vtx Seq="5" Y="10.544" X="-3.387"/>
<Vtx Seq="6" Y="13.449" X="-3.075"/>
<Vtx Seq="7" Y="10.851" X="-2.793"/>
<Vtx Seq="8" Y="6.669" X="-2.699"/>
<Vtx Seq="9" Y="6.669" X="2.699"/>
<Vtx Seq="10" Y="10.851" X="2.793"/>
<Vtx Seq="11" Y="13.449" X="3.075"/>
<Vtx Seq="12" Y="10.544" X="3.387"/>
<Vtx Seq="13" Y="5.351" X="3.46"/>
<Vtx Seq="14" Y="0" X="3.34"/>
<Vtx Seq="15" Y="0" X="2.813"/>
<Vtx Seq="16" Y="1.769" X="2.752"/>
</Catamaran>
<Bowsprit>
<Vtx Seq="1" Y="6.669" X="-0.2"/>
<Vtx Seq="2" Y="11.377" X="-0.2"/>
<Vtx Seq="3" Y="14.019" X="0"/>
<Vtx Seq="4" Y="11.377" X="0.2"/>
<Vtx Seq="5" Y="6.669" X="0.2"/>
</Bowsprit>
<Trampoline>
<Vtx Seq="1" Y="2" X="-2.699"/>
<Vtx Seq="2" Y="6.438" X="-2.699"/>
<Vtx Seq="3" Y="6.438" X="2.699"/>
<Vtx Seq="4" Y="2" X="2.699"/>
</Trampoline>
</BoatShape>
<BoatShape ShapeID="18">
<Vertices>
<Vtx Seq="1" Y="0" X="-1.04"/>
<Vtx Seq="2" Y="0.11" X="-1.18"/>
<Vtx Seq="3" Y="0.42" X="-1.28"/>
<Vtx Seq="4" Y="3.74" X="-1.29"/>
<Vtx Seq="5" Y="5.36" X="-1.21"/>
<Vtx Seq="6" Y="6.29" X="-1.08"/>
<Vtx Seq="7" Y="7.15" X="-0.84"/>
<Vtx Seq="8" Y="7.63" X="-0.62"/>
<Vtx Seq="9" Y="7.94" X="-0.34"/>
<Vtx Seq="10" Y="8.06" X="0"/>
<Vtx Seq="11" Y="7.94" X="0.34"/>
<Vtx Seq="12" Y="7.63" X="0.62"/>
<Vtx Seq="13" Y="7.15" X="0.84"/>
<Vtx Seq="14" Y="6.29" X="1.08"/>
<Vtx Seq="15" Y="5.36" X="1.21"/>
<Vtx Seq="16" Y="3.74" X="1.29"/>
<Vtx Seq="17" Y="0.42" X="1.28"/>
<Vtx Seq="18" Y="0.11" X="1.18"/>
<Vtx Seq="19" Y="0" X="1.04"/>
</Vertices>
</BoatShape>
<BoatShape ShapeID="24">
<Vertices>
<Vtx Seq="1" Y="0" X="-2.5"/>
<Vtx Seq="2" Y="7" X="-2.5"/>
<Vtx Seq="3" Y="12.6" X="-2.2"/>
<Vtx Seq="4" Y="12.6" X="2.2"/>
<Vtx Seq="5" Y="7" X="2.5"/>
<Vtx Seq="6" Y="0" X="2.5"/>
</Vertices>
</BoatShape>
<BoatShape ShapeID="34">
<Vertices>
<Vtx Seq="1" Y="0" X="-1.16"/>
<Vtx Seq="2" Y="5.51" X="-1.16"/>
<Vtx Seq="3" Y="5.846" X="-0.84"/>
<Vtx Seq="4" Y="5.846" X="0.84"/>
<Vtx Seq="5" Y="5.51" X="1.16"/>
<Vtx Seq="6" Y="0" X="1.16"/>
</Vertices>
</BoatShape>
<BoatShape ShapeID="35">
<Vertices>
<Vtx Seq="1" Y="0" X="-1.461"/>
<Vtx Seq="2" Y="6" X="-1.461"/>
<Vtx Seq="3" Y="7" X="-1.44"/>
<Vtx Seq="4" Y="8" X="-1.38"/>
<Vtx Seq="5" Y="9" X="-1.17"/>
<Vtx Seq="6" Y="10" X="-0.76"/>
<Vtx Seq="7" Y="10.6" X="-0.34"/>
<Vtx Seq="8" Y="10.61" X="0"/>
<Vtx Seq="9" Y="10.6" X="0.34"/>
<Vtx Seq="10" Y="10" X="0.76"/>
<Vtx Seq="11" Y="9" X="1.17"/>
<Vtx Seq="12" Y="8" X="1.38"/>
<Vtx Seq="13" Y="7" X="1.44"/>
<Vtx Seq="14" Y="6" X="1.461"/>
<Vtx Seq="15" Y="0" X="1.461"/>
</Vertices>
</BoatShape>
</BoatShapes>
<Boats>
<Boat Type="Yacht" SourceID="101" ShapeID="15" StoweName="USA" ShortName="ORACLE" ShorterName="USA" BoatName="ORACLE TEAM USA" HullNum="AC4515" Skipper="SPITHILL" Helmsman="SPITHILL" Country="USA" PeliID="101" RadioIP="172.20.2.101">
<GPSposition Z="1.78" Y="-0.331" X="-0.006"/>
<MastTop Z="21.496" Y="3.7" X="0"/>
<FlagPosition Z="0" Y="6.2" X="0"/>
</Boat>
<Boat Type="Yacht" SourceID="102" ShapeID="15" StoweName="SWE" ShortName="ARTEMIS" ShorterName="SWE" BoatName="ARTEMIS RACING" HullNum="AC4517" Skipper="OUTTERIDGE" Helmsman="OUTTERIDGE" Country="SWE" PeliID="102" RadioIP="172.20.2.102">
<GPSposition Z="1.727" Y="-0.359" X="-0.0121"/>
<MastTop Z="21.496" Y="3.7" X="0"/>
<FlagPosition Z="0" Y="6.2" X="0"/>
</Boat>
<Boat Type="Yacht" SourceID="103" ShapeID="15" StoweName="NZL" ShortName="ETNZ" ShorterName="NZL" BoatName="EMIRATES TEAM NZ" HullNum="AC4503" Skipper="ASHBY" Helmsman="BURLING" Country="NZL" PeliID="103" RadioIP="172.20.2.103">
<GPSposition Z="1.881" Y="-0.291" X="-0.003"/>
<MastTop Z="21.496" Y="3.7" X="0"/>
<FlagPosition Z="0" Y="6.2" X="0"/>
</Boat>
<Boat Type="Yacht" SourceID="104" ShapeID="15" StoweName="JPN" ShortName="JAPAN" ShorterName="JPN" BoatName="SOFTBANK TEAM JAPAN" HullNum="AC4504" Skipper="BARKER" Helmsman="BARKER" Country="JPN" PeliID="104" RadioIP="172.20.2.104">
<GPSposition Z="1.805" Y="-0.322" X="-0.003"/>
<MastTop Z="21.496" Y="3.7" X="0"/>
<FlagPosition Z="0" Y="6.2" X="0"/>
</Boat>
<Boat Type="Yacht" SourceID="105" ShapeID="15" StoweName="FRA" ShortName="FRANCE" ShorterName="FRA" BoatName="GROUPAMA TEAM FRANCE" HullNum="AC4505" Skipper="CAMMAS" Helmsman="CAMMAS" Country="FRA" PeliID="105" RadioIP="172.20.2.105">
<GPSposition Z="1.863" Y="-0.3" X="-0.003"/>
<MastTop Z="21.496" Y="3.7" X="0"/>
<FlagPosition Z="0" Y="6.2" X="0"/>
</Boat>
<Boat Type="Yacht" SourceID="106" ShapeID="15" StoweName="GBR" ShortName="GBR" ShorterName="GBR" BoatName="LAND ROVER BAR" HullNum="AC4516" Skipper="ANSLIE" Helmsman="ANSLIE" Country="GBR" PeliID="106" RadioIP="172.20.2.106">
<GPSposition Z="1.734" Y="-0.352" X="0"/>
<MastTop Z="21.496" Y="3.7" X="0"/>
<FlagPosition Z="0" Y="6.2" X="0"/>
</Boat>
</Boats>
</BoatConfig>
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Race>
<CreationTimeDate>2015-08-29T13:12:40+02:00</CreationTimeDate>
<RaceStartTime Start="2015-08-29T13:10:00+02:00" Postpone="False"/>
<RaceID>15082901</RaceID>
<RaceType>Fleet</RaceType>
<Participants>
<Yacht SourceID="101"/>
<Yacht SourceID="102"/>
<Yacht SourceID="103"/>
<Yacht SourceID="104"/>
<Yacht SourceID="105"/>
<Yacht SourceID="106"/>
</Participants>
<Course>
<CompoundMark CompoundMarkID="1" Name="Mark0">
<Mark SeqID="1" Name="Start Line 1" TargetLat="57.6703330" TargetLng="11.8278330"
SourceID="122"/>
<Mark SeqID="2" Name="Start Line 2" TargetLat="57.6703330" TargetLng="11.8278330"
SourceID="123"/>
</CompoundMark>
<CompoundMark CompoundMarkID="2" Name="Mark1">
<Mark SeqID="1" Name="Mark1" TargetLat="57.6675700" TargetLng="11.8359880" SourceID="131"/>
</CompoundMark>
<CompoundMark CompoundMarkID="3" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="4" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="5" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="6" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="7" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="8" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="9" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="10" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="11" Name="Mark4">
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950"
SourceID="128"/>
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950"
SourceID="129"/>
</CompoundMark>
</Course>
<CompoundMarkSequence>
<Corner SeqID="1" CompoundMarkID="1" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3"/>
<Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="5" CompoundMarkID="5" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="6" CompoundMarkID="6" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="7" CompoundMarkID="7" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="8" CompoundMarkID="8" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="9" CompoundMarkID="9" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="10" CompoundMarkID="10" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="11" CompoundMarkID="11" Rounding="PS" ZoneSize="3"/>
</CompoundMarkSequence>
<CourseLimit>
<Limit SeqID="1" Lat="57.6739450" Lon="11.8417100"/>
<Limit SeqID="2" Lat="57.6709520" Lon="11.8485010"/>
<Limit SeqID="3" Lat="57.6690260" Lon="11.8472790"/>
<Limit SeqID="4" Lat="57.6693140" Lon="11.8457610"/>
<Limit SeqID="5" Lat="57.6665370" Lon="11.8432910"/>
<Limit SeqID="6" Lat="57.6641400" Lon="11.8385840"/>
<Limit SeqID="7" Lat="57.6629430" Lon="11.8332030"/>
<Limit SeqID="8" Lat="57.6629480" Lon="11.8249660"/>
<Limit SeqID="9" Lat="57.6686890" Lon="11.8250920"/>
<Limit SeqID="10" Lat="57.6708220" Lon="11.8321340"/>
</CourseLimit>
</Race>
+87
View File
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Race>
<CreationTimeDate>2015-08-29T11:27:15+02:00</CreationTimeDate>
<RaceStartTime Start="2015-08-29T13:10:00+02:00" Postpone="False" />
<RaceID>15082901</RaceID>
<RaceType>Fleet</RaceType>
<Participants>
<Yacht SourceID="101" />
<Yacht SourceID="102" />
<Yacht SourceID="103" />
<Yacht SourceID="104" />
<Yacht SourceID="105" />
<Yacht SourceID="106" />
</Participants>
<Course>
<CompoundMark CompoundMarkID="1" Name="Mark0">
<Mark SeqID="1" Name="Start Line 1" TargetLat="57.6703330" TargetLng="11.8278330" SourceID="122" />
<Mark SeqID="2" Name="Start Line 2" TargetLat="57.6703330" TargetLng="11.8278330" SourceID="123" />
</CompoundMark>
<CompoundMark CompoundMarkID="2" Name="Mark1">
<Mark SeqID="1" Name="Mark1" TargetLat="57.6675700" TargetLng="11.8359880" SourceID="131" />
</CompoundMark>
<CompoundMark CompoundMarkID="3" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="4" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="5" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="6" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="7" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="8" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="9" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="124" />
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900" SourceID="125" />
</CompoundMark>
<CompoundMark CompoundMarkID="10" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="126" />
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170" SourceID="127" />
</CompoundMark>
<CompoundMark CompoundMarkID="11" Name="Mark4">
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="128" />
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950" SourceID="129" />
</CompoundMark>
</Course>
<CompoundMarkSequence>
<Corner SeqID="1" CompoundMarkID="1" Rounding="PS" ZoneSize="3" />
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" />
<Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3" />
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3" />
<Corner SeqID="5" CompoundMarkID="5" Rounding="SP" ZoneSize="3" />
<Corner SeqID="6" CompoundMarkID="6" Rounding="PS" ZoneSize="3" />
<Corner SeqID="7" CompoundMarkID="7" Rounding="SP" ZoneSize="3" />
<Corner SeqID="8" CompoundMarkID="8" Rounding="PS" ZoneSize="3" />
<Corner SeqID="9" CompoundMarkID="9" Rounding="SP" ZoneSize="3" />
<Corner SeqID="10" CompoundMarkID="10" Rounding="PS" ZoneSize="3" />
<Corner SeqID="11" CompoundMarkID="11" Rounding="PS" ZoneSize="3" />
</CompoundMarkSequence>
<CourseLimit>
<Limit SeqID="1" Lat="57.6739450" Lon="11.8417100" />
<Limit SeqID="2" Lat="57.6709520" Lon="11.8485010" />
<Limit SeqID="3" Lat="57.6690260" Lon="11.8472790" />
<Limit SeqID="4" Lat="57.6693140" Lon="11.8457610" />
<Limit SeqID="5" Lat="57.6665370" Lon="11.8432910" />
<Limit SeqID="6" Lat="57.6641400" Lon="11.8385840" />
<Limit SeqID="7" Lat="57.6629430" Lon="11.8332030" />
<Limit SeqID="8" Lat="57.6629480" Lon="11.8249660" />
<Limit SeqID="9" Lat="57.6686890" Lon="11.8250920" />
<Limit SeqID="10" Lat="57.6692230" Lon="11.8231430" />
<Limit SeqID="11" Lat="57.6725370" Lon="11.8272480" />
<Limit SeqID="12" Lat="57.6708220" Lon="11.8321340" />
</CourseLimit>
</Race>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<RegattaConfig>
<RegattaID>24</RegattaID>
<RegattaName>Gothenburg World Series 2015</RegattaName>
<CourseName>Gothenburg</CourseName>
<CentralLatitude>57.6679590</CentralLatitude>
<CentralLongitude>11.8503233</CentralLongitude>
<CentralAltitude>6.95</CentralAltitude>
<UtcOffset>2</UtcOffset>
<MagneticVariation>3.2</MagneticVariation>
<ShorelineName>gothenburg_shoreline</ShorelineName>
</RegattaConfig>
+1 -1
View File
@@ -4,4 +4,4 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<AnchorPane fx:id="canvasPane" prefHeight="960.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController" /> <AnchorPane fx:id="canvasPane" maxHeight="960.0" maxWidth="1280.0" prefHeight="960.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController" />
+4 -5
View File
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.canvas.*?> <?import javafx.scene.canvas.*?>
<?import java.lang.*?> <?import java.lang.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller"> <AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller" />
<children>
<!--<fx:include source="RaceView.fxml" fx:id="raceView"/>-->
</children>
</AnchorPane>
+31 -21
View File
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?> <?import java.lang.*?>
<?import javafx.scene.canvas.*?> <?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.canvas.Canvas?> <?import javafx.scene.shape.*?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.text.*?>
<GridPane prefHeight="1080.0" prefWidth="1920.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.RaceViewController"> <GridPane maxHeight="960.0" maxWidth="1530.0" prefHeight="960.0" prefWidth="1530.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.RaceViewController">
<columnConstraints> <columnConstraints>
<ColumnConstraints maxWidth="246.0" minWidth="246.0" prefWidth="246.0" /> <ColumnConstraints maxWidth="246.0" minWidth="246.0" prefWidth="246.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="1034.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="1034.0" />
@@ -20,38 +18,50 @@
<RowConstraints /> <RowConstraints />
</rowConstraints> </rowConstraints>
<children> <children>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3"> <AnchorPane prefHeight="960.0" prefWidth="250.0" style="-fx-background-color: #2C2c36;" GridPane.rowSpan="3">
<children> <children>
<Label layoutX="11.0" layoutY="259.0" text="Team Position" /> <Label layoutX="11.0" layoutY="259.0" text="Team Position" textFill="WHITE" />
<Label layoutX="13.0" layoutY="432.0" text="Settings" /> <Label layoutX="13.0" layoutY="432.0" text="Settings" textFill="WHITE" />
<Label layoutX="11.0" layoutY="14.0" text="Timer" /> <Label layoutX="11.0" layoutY="14.0" text="Timer" textFill="WHITE" />
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" /> <Label layoutX="11.0" layoutY="88.0" text="Wind direction" textFill="WHITE" />
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" /> <Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#3dcdc8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#d7d7d7" strokeType="INSIDE" strokeWidth="3.0" />
<Text fx:id="windArrowText" fill="#686868" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text=""> <Text fx:id="windArrowText" fill="#a8a8a8" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="">
<font> <font>
<Font name="AdobeArabic-Regular" size="55.0" /> <Font name="AdobeArabic-Regular" size="55.0" />
</font> </font>
</Text> </Text>
<Text fx:id="windDirectionText" fill="#a8a7a7" layoutX="171.0" layoutY="214.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0.0°" textAlignment="RIGHT"> <Text fx:id="windDirectionText" fill="#d3d3d3" layoutX="171.0" layoutY="214.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0.0°" textAlignment="RIGHT">
<font> <font>
<Font name="System Bold" size="13.0" /> <Font name="System Bold" size="13.0" />
</font> </font>
</Text> </Text>
<CheckBox fx:id="toggleAnnotation" layoutX="27.0" layoutY="462.0" mnemonicParsing="false" selected="true" text="Show annotations" /> <CheckBox fx:id="toggleFps" graphicTextGap="0.0" layoutX="21.0" layoutY="453.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="143.0" selected="true" styleClass="ui-checkbox" text="Show FPS" textFill="WHITE" />
<CheckBox fx:id="toggleFps" layoutX="27.0" layoutY="488.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="143.0" selected="true" text="Show FPS" /> <VBox fx:id="positionVbox" layoutX="12.0" layoutY="280.0" prefHeight="140.0" prefWidth="200.0" styleClass="text-white" />
<VBox fx:id="positionVbox" layoutX="12.0" layoutY="280.0" prefHeight="140.0" prefWidth="200.0" />
<Pane layoutX="11.0" layoutY="30.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="51.0" prefWidth="193.0"> <Pane layoutX="11.0" layoutY="30.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="51.0" prefWidth="193.0">
<children> <children>
<Text fx:id="timerLabel" layoutX="6.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="00:00" textAlignment="CENTER" wrappingWidth="181.0"> <Text fx:id="timerLabel" fill="#f8f8f8" layoutX="-26.0" layoutY="34.0" strokeType="OUTSIDE" strokeWidth="0.0" text="00:00" textAlignment="CENTER" wrappingWidth="246.0">
<font> <font>
<Font size="34.0" /> <Font size="25.0" />
</font> </font>
</Text> </Text>
</children> </children>
</Pane> </Pane>
<Slider fx:id="annotationSlider" blockIncrement="1.0" layoutX="38.0" layoutY="527.0" majorTickUnit="1.0" max="2.0" minorTickCount="0" prefHeight="51.0" prefWidth="170.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" styleClass="ui-slider" />
<Label layoutX="10.0" layoutY="499.0" text="Annotations" textFill="WHITE" />
<Button fx:id="selectAnnotationBtn" layoutX="35.0" layoutY="578.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="170.0" styleClass="blue-ui-btn" text="Select Annotations" textFill="WHITE" />
<Text fill="WHITE" layoutX="11.0" layoutY="649.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Selection" />
<ComboBox fx:id="boatSelectionComboBox" layoutX="37.0" layoutY="664.0" prefHeight="25.0" prefWidth="170.0" promptText="Select Boat" styleClass="combo-box-base" />
<LineChart fx:id="raceSparkLine" layoutX="-1.0" layoutY="719.0" legendVisible="false" prefHeight="277.0" prefWidth="246.0" title="Boat Positions">
<xAxis>
<CategoryAxis label="Leg Number" side="BOTTOM" styleClass="spark-line-xaxis" />
</xAxis>
<yAxis>
<NumberAxis fx:id="sparklineYAxis" minorTickCount="1" minorTickLength="1.0" side="LEFT" styleClass="spark-line-yaxis" tickLabelGap="1.0" tickUnit="1.0" upperBound="7.0" />
</yAxis>
</LineChart>
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane fx:id="contentAnchorPane" prefHeight="960.0" prefWidth="1280.0" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP"> <AnchorPane fx:id="contentAnchorPane" maxHeight="960.0" maxWidth="1280.0" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: skyblue;" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP">
<children> <children>
<fx:include fx:id="includedCanvas" source="CanvasView.fxml" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> <fx:include fx:id="includedCanvas" source="CanvasView.fxml" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children></AnchorPane> </children></AnchorPane>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.canvas.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<GridPane fx:id="gridPane" nodeOrientation="LEFT_TO_RIGHT" prefWidth="800.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.StartScreenController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints percentHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="52.0" minHeight="52.0" prefHeight="52.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="0.0" percentHeight="8.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="28.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="55.0" minHeight="55.0" percentHeight="9.0" prefHeight="55.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="0.0" minHeight="0.0" percentHeight="29.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="93.0" minHeight="72.0" prefHeight="72.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="283.0" minHeight="262.0" prefHeight="283.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" text="Welcome to Race Vision" textFill="WHITE" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
<font>
<Font size="40.0" />
</font>
</Label>
<Label text="Your live AC35 livestream" textFill="WHITE" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="20.0" />
</font>
</Label>
<Label text="Livestream Status:" textFill="WHITE" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
<font>
<Font size="28.0" />
</font>
</Label>
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="27.0" />
</font>
</Label>
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" styleClass="blue-ui-btn" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" styleClass="blue-ui-btn" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="7" GridPane.valignment="TOP" />
<TableView fx:id="teamList" maxWidth="661.0" prefHeight="324.0" prefWidth="629.0" styleClass="ui-table" GridPane.halignment="CENTER" GridPane.hgrow="NEVER" GridPane.rowIndex="5" GridPane.vgrow="NEVER">
<columns>
<TableColumn fx:id="posCol" editable="false" maxWidth="74.0" minWidth="74.0" prefWidth="74.0" resizable="false" sortable="false" text="Position" />
<TableColumn fx:id="boatNameCol" editable="false" maxWidth="171.0" minWidth="171.0" prefWidth="171.0" resizable="false" sortable="false" text="Boat Name" />
<TableColumn fx:id="shortNameCol" editable="false" maxWidth="155.18472290039062" minWidth="107.0" prefWidth="155.18472290039062" resizable="false" sortable="false" text="Short Name" />
<TableColumn fx:id="countryCol" editable="false" maxWidth="258.9999694824219" minWidth="147.0" prefWidth="258.9999694824219" resizable="false" sortable="false" text="Country" />
</columns>
<GridPane.margin>
<Insets top="10.0" />
</GridPane.margin>
</TableView>
<Label fx:id="realTime" text="Local time" textFill="WHITE" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="BOTTOM" />
</children>
</GridPane>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.layout.*?>
<?import java.lang.*?>
<?import javafx.scene.canvas.*?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: #ddd;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.models.map.TestMapController">
<children>
<Canvas fx:id="mapCanvas" height="960.0" width="1280.0" />
</children>
</Pane>
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="annotationSelectWindow" maxHeight="270.0" maxWidth="469.0" minHeight="270.0" minWidth="469.0" prefHeight="270.0" prefWidth="469.0" styleClass="background-blue" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Text fill="WHITE" layoutX="26.0" layoutY="52.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Select important annotations">
<font>
<Font size="24.0" />
</font>
</Text>
<CheckBox fx:id="boatWakeSelect" layoutX="26.0" layoutY="80.0" mnemonicParsing="false" style="-fx-border-width: 0; -fx-background-insets: 0;" text="Boat Wakes" textFill="#e7e7e7" />
<CheckBox fx:id="boatSpeedSelect" layoutX="26.0" layoutY="111.0" mnemonicParsing="false" text="Boat Speed" textFill="#e7e7e7" />
<CheckBox fx:id="boatTrackSelect" layoutX="26.0" layoutY="142.0" mnemonicParsing="false" text="Boat Tracks" textFill="#e7e7e7" />
<CheckBox fx:id="boatNameSelect" layoutX="26.0" layoutY="173.0" mnemonicParsing="false" text="Boat Name" textFill="#e7e7e7" />
<CheckBox fx:id="boatEstTimeToNextMarkSelect" layoutX="26.0" layoutY="204.0" mnemonicParsing="false" text="Boat Estimated Time To Next Mark" textFill="#e7e7e7" />
<Button fx:id="closeButton" layoutX="424.0" layoutY="-1.0" mnemonicParsing="false" prefHeight="11.0" prefWidth="49.0" style=": 0;" text="X" textFill="#ffffff4e">
<font>
<Font size="24.0" />
</font>
<styleClass>
<String fx:value="background-blue" />
<String fx:value="clearExitButton" />
</styleClass>
</Button>
<CheckBox fx:id="boatElapsedTimeSelect" layoutX="26.0" layoutY="235.0" mnemonicParsing="false" text="Boat Elapsed Time Since Last Mark" textFill="#e7e7e7" />
</children>
</AnchorPane>
+35 -35
View File
@@ -1,35 +1,35 @@
package seng302; //package seng302;
//
import org.junit.Test; //import org.junit.Test;
import seng302.models.Boat; //import seng302.models.Boat;
//
import static org.junit.Assert.assertEquals; //import static org.junit.Assert.assertEquals;
//
/** ///**
* Unit test for the Team class. // * Unit test for the Team class.
*/ // */
public class BoatTest { //public class BoatTest {
//
@Test // @Test
public void testBoatCreation() { // public void testBoatCreation() {
Boat boat1 = new Boat("Team 1"); // Boat boat1 = new Boat("Team 1");
assertEquals(boat1.getTeamName(), "Team 1"); // assertEquals(boat1.getTeamName(), "Team 1");
assertEquals(boat1.getVelocity(), (double) 10.0, 1e-15); // assertEquals(boat1.getVelocity(), (double) 10.0, 1e-15);
} // }
//
@Test // @Test
public void testChangeTeamName() { // public void testChangeTeamName() {
Boat boat1 = new Boat("Team 1"); // Boat boat1 = new Boat("Team 1");
boat1.setTeamName("Team 2"); // boat1.setTeamName("Team 2");
assertEquals(boat1.getTeamName(), "Team 2"); // assertEquals(boat1.getTeamName(), "Team 2");
} // }
//
@Test // @Test
public void testSetVelocity() { // public void testSetVelocity() {
Boat boat1 = new Boat("Team 1", 29.0, ""); // Boat boat1 = new Boat("Team 1", 29.0, "", 100);
assertEquals(boat1.getVelocity(), (double) 29.0, 1e-15); // assertEquals(boat1.getVelocity(), (double) 29.0, 1e-15);
//
boat1.setVelocity(12.0); // boat1.setVelocity(12.0);
assertEquals(boat1.getVelocity(), (double)12.0, 1e-15); // assertEquals(boat1.getVelocity(), (double)12.0, 1e-15);
} // }
} //}
+7 -31
View File
@@ -1,45 +1,21 @@
package seng302; package seng302;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import seng302.models.Boat;
import seng302.models.Colors; import seng302.models.Colors;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/**
* Created by ryan_ on 16/03/2017.
*/
public class ColorsTest { public class ColorsTest {
//@Test
@Test
public void testNextColor() { public void testNextColor() {
List<Boat> boats = new ArrayList<>(); Color expectedColors[] = {Color.RED, Color.PERU, Color.SEAGREEN, Color.GREEN, Color.BLUE, Color.PURPLE};
boats.add(new Boat("Team 1")); for (int i = 0; i<6; i++)
boats.add(new Boat("Team 2")); {
boats.add(new Boat("Team 3")); Assert.assertEquals(expectedColors[i], Colors.getColor());
boats.add(new Boat("Team 4"));
boats.add(new Boat("Team 5"));
boats.add(new Boat("Team 6"));
int count = 0;
List<Color> enumColors = new ArrayList<>();
while (count < 6) {
Color color = Colors.getColor();
enumColors.add(color);
count++;
} }
List<Color> boatColors = new ArrayList<>();
for (Boat boat : boats) {
Color color = boat.getColor();
boatColors.add(color);
}
assertEquals(enumColors, boatColors);
} }
} }
-38
View File
@@ -1,38 +0,0 @@
package seng302;
import org.junit.Test;
import seng302.models.Boat;
import seng302.models.Event;
import seng302.models.mark.SingleMark;
import static org.junit.Assert.assertEquals;
/**
* Test for Event class
* Created by Haoming on 7/03/17.
*/
public class EventTest {
@Test
public void getTimeString() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"), 0);
assertEquals("20:31:242", event.getTimeString());
}
@Test
public void testBoatHeading() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2), 0);
assertEquals(event.getBoatHeading(), 228.0266137055349, 1e-15);
}
@Test
public void testDistanceBetweenMarks() throws Exception {
Boat boat = new Boat("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2), 0);
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
}
}
-54
View File
@@ -1,54 +0,0 @@
package seng302;
import org.junit.Test;
import seng302.models.Leg;
import seng302.models.mark.SingleMark;
import static org.junit.Assert.assertEquals;
/**
* Unit test for the Leg class.
*/
public class LegTest {
/**
* Test creation of the leg by specifying a string
* for the marker label
*/
@Test
public void testLegCreationUsingMarkerLabel() {
Leg leg = new Leg(010, 100, "SingleMark");
assertEquals(leg.getHeading(), 010);
assertEquals(leg.getDistance(), 100);
assertEquals(leg.getMarkerLabel(), "SingleMark");
assertEquals(leg.getIsFinishingLeg(), false);
}
/**
* Test creation of the leg by providing a
* SingleMark object
*/
@Test
public void testLegCreation() {
Leg leg = new Leg(010, 100, new SingleMark("SingleMark"));
assertEquals(leg.getHeading(), 010);
assertEquals(leg.getDistance(), 100);
assertEquals(leg.getMarkerLabel(), "SingleMark");
assertEquals(leg.getIsFinishingLeg(), false);
}
/**
* Test changing whether or not a
* leg is the finishing leg
*/
@Test
public void testSetFinishLeg() {
Leg leg = new Leg(010, 100, "SingleMark");
leg.setFinishingLeg(true);
assertEquals(leg.getIsFinishingLeg(), true);
}
}
-41
View File
@@ -1,41 +0,0 @@
package seng302;
import org.junit.Test;
import seng302.models.Boat;
import seng302.models.Race;
import java.lang.reflect.Array;
import static org.junit.Assert.assertEquals;
/**
* Unit test for the Race class.
*/
public class RaceTest {
/**
* Test that all boats were added to the race
*/
@Test
public void testAddingBoatsToRace() {
Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2");
Race race = new Race();
race.addBoat(boat1);
race.addBoat(boat2);
assertEquals(Array.getLength(race.getBoats()), 2);
}
@Test
public void testGetShuffledBoats(){
Boat boat1 = new Boat("Team 1");
Boat boat2 = new Boat("Team 2");
Race race = new Race();
race.addBoat(boat1);
race.addBoat(boat2);
assertEquals(Array.getLength(race.getShuffledBoats()), 2);
}
}
+65
View File
@@ -0,0 +1,65 @@
package seng302;
import javafx.geometry.Point2D;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Test Class for the GeometryUtils class
* Created by wmu16 on 24/05/17.
*/
public class TestGeoUtils {
//Line in x = y
private Point2D linePoint1 = new Point2D(0, 0);
private Point2D linePoint2 = new Point2D(1, 1);
//Point below x = y
private Point2D arbitraryPoint1 = new Point2D(1, 0);
//Point above x = y
private Point2D arbitraryPoint2 = new Point2D(0, 1);
//Point on x = y
private Point2D arbitraryPoint3 = new Point2D(2, 2);
@Before
public void setUp() throws Exception {
}
@Test
public void testLineFunction() {
Integer lineFunctionResult1 = GeometryUtils.lineFunction(linePoint1, linePoint2, arbitraryPoint1);
Integer lineFunctionResult2 = GeometryUtils.lineFunction(linePoint1, linePoint2, arbitraryPoint2);
Integer lineFunctionResult3 = GeometryUtils.lineFunction(linePoint1, linePoint2, arbitraryPoint3);
//Point1 and Point2 are on opposite sides
assertEquals(Math.abs(lineFunctionResult1), Math.abs(lineFunctionResult2));
assertNotEquals(lineFunctionResult1, lineFunctionResult2);
//Point3 is on the line
assertEquals((long) lineFunctionResult3, 0L);
}
@Test
public void testMakeArbitraryVectorPoint() {
//Make a point (1,0) from point (0,0)
Point2D newPoint = GeometryUtils.makeArbitraryVectorPoint(linePoint1, 0d, 1d);
Point2D expected = new Point2D(1,0);
assertEquals(expected.getX(), newPoint.getX(), 1E-6);
assertEquals(expected.getY(), newPoint.getY(), 1E-6);
newPoint = GeometryUtils.makeArbitraryVectorPoint(linePoint1, 90d, 1d);
expected = new Point2D(0, 1);
assertEquals(expected.getX(), newPoint.getX(), 1E-6);
assertEquals(expected.getY(), newPoint.getY(), 1E-6);
}
}

Some files were not shown because too many files have changed in this diff Show More