Search in sources :

Example 1 with CityRoad

use of il.ac.technion.cs.yp.btw.citysimulation.CityRoad in project BTW by TechnionYearlyProject.

the class MapGraphics method createLines.

/**
 * @author Shay and Anat and Adam Elgressy
 * @Date 20-1-2018
 * creating the array of lines to represent roads
 * @param roads - roads in the map
 */
private void createLines(Set<CityRoad> roads) {
    HashSet<CityRoad> l_roads = new HashSet<>();
    for (CityRoad currRoad : roads) {
        double deviationAngle = 0.0;
        double deviationDistance = -0.00003;
        Point newSource = getDeviationFromVectorEnd(currRoad.getDestinationCrossroad(), currRoad.getSourceCrossroad(), deviationAngle, deviationDistance);
        Point newDestination = getDeviationFromVectorEnd(currRoad.getSourceCrossroad(), currRoad.getDestinationCrossroad(), deviationAngle, deviationDistance);
        deviationAngle = 0.5;
        deviationDistance = 0.000125;
        newSource = getDeviationFromVectorEnd(newDestination, newSource, -deviationAngle, deviationDistance);
        newDestination = getDeviationFromVectorEnd(newSource, newDestination, deviationAngle, deviationDistance);
        double xroad1 = newSource.getCoordinateX();
        double yroad1 = newSource.getCoordinateY();
        double xroad2 = newDestination.getCoordinateX();
        double yroad2 = newDestination.getCoordinateY();
        Line roadLine = new Line(xroad1, yroad1, xroad2, yroad2);
        roadLine.setStroke(Color.BLACK);
        roadLine.setStrokeWidth(0.00025);
        roadLine.toBack();
        deviationAngle = 0.0;
        deviationDistance = -0.0003;
        newSource = getDeviationFromVectorEnd(currRoad.getDestinationCrossroad(), currRoad.getSourceCrossroad(), deviationAngle, deviationDistance);
        newDestination = getDeviationFromVectorEnd(currRoad.getSourceCrossroad(), currRoad.getDestinationCrossroad(), deviationAngle, deviationDistance);
        double xSeperateLine1 = newSource.getCoordinateX();
        double ySeperateLine1 = newSource.getCoordinateY();
        double xSeperateLine2 = newDestination.getCoordinateX();
        double ySeperateLine2 = newDestination.getCoordinateY();
        Line separateline = new Line(xSeperateLine1, ySeperateLine1, xSeperateLine2, ySeperateLine2);
        separateline.setStroke(Color.WHITE);
        separateline.setStrokeWidth(0.00005);
        lines.add(new Pair(roadLine, currRoad.getRoadName()));
        lines.add(new Pair(separateline, currRoad.getRoadName()));
        roadLine.setOnMouseClicked(event -> {
            RoadData roadData = currRoad.getStatisticalData();
            int length = roadData.getRoadLength();
            double averageSpeed = roadData.getAverageSpeed();
            int numOfVehicles = roadData.getNumOfVehicles();
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/road_real_time_statistics.fxml"));
            try {
                Parent root = fxmlLoader.load();
                RoadRealTimeStatisticsController roadRealTimeStatisticsController = fxmlLoader.getController();
                roadRealTimeStatisticsController.generateView(length, averageSpeed, numOfVehicles, root);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : Parent(javafx.scene.Parent) Point(il.ac.technion.cs.yp.btw.classes.Point) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) Point(il.ac.technion.cs.yp.btw.classes.Point) Line(javafx.scene.shape.Line) RoadData(il.ac.technion.cs.yp.btw.citysimulation.RoadData) CityRoad(il.ac.technion.cs.yp.btw.citysimulation.CityRoad) HashSet(java.util.HashSet) Pair(javafx.util.Pair)

Aggregations

CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 RoadData (il.ac.technion.cs.yp.btw.citysimulation.RoadData)1 Point (il.ac.technion.cs.yp.btw.classes.Point)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Parent (javafx.scene.Parent)1 Line (javafx.scene.shape.Line)1 Pair (javafx.util.Pair)1