Search in sources :

Example 1 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class AutomationItem method setRouteLocation.

public void setRouteLocation(RouteLocation rl) {
    RouteLocation old = _routeLocation;
    _routeLocation = rl;
    if (old != rl) {
        // NOI18N
        setDirtyAndFirePropertyChange("AutomationItemRouteLocationChange", old, rl);
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 2 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class CommonConductorYardmasterPanel method blockCars.

/**
     * Block cars by track (optional), then pick up and set out for each
     * location in a train's route. This shows each car with a check box or with
     * a set button. The set button is displayed when the checkbox isn't
     * selected and the display is in "set" mode. If the car is a utility. Show
     * the number of cars that have the same attributes, and not the car's road
     * and number. Each car is displayed only once in one of three panes. The
     * three panes are pick up, set out, or local move. To keep track of each
     * car and which pane to use, they are placed in the list "rollingStock"
     * with the prefix "p", "s" or "m" and the car's unique id.
     * @param rl The RouteLocation
     * @param isManifest True if manifest, false if switch list
     *
     */
protected void blockCars(RouteLocation rl, boolean isManifest) {
    if (Setup.isPrintHeadersEnabled()) {
        JLabel header = new JLabel(Tab + trainCommon.getPickupCarHeader(isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK));
        setLabelFont(header);
        pPickups.add(header);
        header = new JLabel(Tab + trainCommon.getDropCarHeader(isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK));
        setLabelFont(header);
        pSetouts.add(header);
        header = new JLabel(Tab + trainCommon.getLocalMoveHeader(isManifest));
        setLabelFont(header);
        pMoves.add(header);
    }
    List<Track> tracks = rl.getLocation().getTrackByNameList(null);
    List<RouteLocation> routeList = _train.getRoute().getLocationsBySequenceList();
    List<Car> carList = carManager.getByTrainDestinationList(_train);
    for (Track track : tracks) {
        for (RouteLocation rld : routeList) {
            for (Car car : carList) {
                // passenger trains are already blocked in the car list
                if (car.getTrack() != null && car.getRouteLocation() == rl && car.getRouteDestination() != rl && (!Setup.isSortByTrackNameEnabled() || car.getTrackName().equals(track.getName())) && ((car.getRouteDestination() == rld && !car.isCaboose() && !car.hasFred()) || (rld == routeList.get(routeList.size() - 1) && (car.isCaboose() || car.hasFred())) || car.isPassenger())) {
                    // yes we have a pick up
                    pWorkPanes.setVisible(true);
                    pickupPane.setVisible(true);
                    if (!rollingStock.contains(car)) {
                        rollingStock.add(car);
                        car.addPropertyChangeListener(this);
                    }
                    // did we already process this car?
                    if (checkBoxes.containsKey("p" + car.getId())) {
                        if (isSetMode && !checkBoxes.get("p" + car.getId()).isSelected()) {
                            // change to set button so user can remove car from train
                            pPickups.add(addSet(car));
                        } else {
                            pPickups.add(checkBoxes.get("p" + car.getId()));
                        }
                    // figure out the checkbox text, either single car or utility
                    } else {
                        String text;
                        if (car.isUtility()) {
                            text = trainCommon.pickupUtilityCars(carList, car, isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK);
                            if (text == null) {
                                // this car type has already been processed
                                continue;
                            }
                        } else {
                            text = trainCommon.pickupCar(car, isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK);
                        }
                        JCheckBox checkBox = new JCheckBox(text);
                        setCheckBoxFont(checkBox);
                        addCheckBoxAction(checkBox);
                        pPickups.add(checkBox);
                        checkBoxes.put("p" + car.getId(), checkBox);
                    }
                }
            }
        }
        // set outs and local moves
        for (Car car : carList) {
            if (car.getRouteDestination() != rl || car.getDestinationTrack() == null) {
                continue;
            }
            // car in train if track null, second check is for yard master window
            if (car.getTrack() == null || car.getTrack() != null && (car.getRouteLocation() != rl)) {
                if (Setup.isSortByTrackNameEnabled() && !car.getDestinationTrack().getName().equals(track.getName())) {
                    continue;
                }
                // we have set outs
                pWorkPanes.setVisible(true);
                setoutPane.setVisible(true);
                if (!rollingStock.contains(car)) {
                    rollingStock.add(car);
                    car.addPropertyChangeListener(this);
                }
                if (checkBoxes.containsKey("s" + car.getId())) {
                    if (isSetMode && !checkBoxes.get("s" + car.getId()).isSelected()) {
                        // change to set button so user can remove car from train
                        pSetouts.add(addSet(car));
                    } else {
                        pSetouts.add(checkBoxes.get("s" + car.getId()));
                    }
                } else {
                    String text;
                    if (car.isUtility()) {
                        text = trainCommon.setoutUtilityCars(carList, car, !TrainCommon.LOCAL, isManifest);
                        if (text == null) {
                            // this car type has already been processed
                            continue;
                        }
                    } else {
                        text = trainCommon.dropCar(car, isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK);
                    }
                    JCheckBox checkBox = new JCheckBox(text);
                    setCheckBoxFont(checkBox);
                    addCheckBoxAction(checkBox);
                    pSetouts.add(checkBox);
                    checkBoxes.put("s" + car.getId(), checkBox);
                }
            // local move?
            } else if (car.getTrack() != null && car.getRouteLocation() == rl && (!Setup.isSortByTrackNameEnabled() || car.getTrack().getName().equals(track.getName()))) {
                movePane.setVisible(true);
                if (!rollingStock.contains(car)) {
                    rollingStock.add(car);
                    car.addPropertyChangeListener(this);
                }
                if (checkBoxes.containsKey("m" + car.getId())) {
                    if (isSetMode && !checkBoxes.get("m" + car.getId()).isSelected()) {
                        // change to set button so user can remove car from train
                        pMoves.add(addSet(car));
                    } else {
                        pMoves.add(checkBoxes.get("m" + car.getId()));
                    }
                } else {
                    String text;
                    if (car.isUtility()) {
                        text = trainCommon.setoutUtilityCars(carList, car, TrainCommon.LOCAL, isManifest);
                        if (text == null) {
                            // this car type has already been processed
                            continue;
                        }
                    } else {
                        text = trainCommon.localMoveCar(car, isManifest);
                    }
                    JCheckBox checkBox = new JCheckBox(text);
                    setCheckBoxFont(checkBox);
                    addCheckBoxAction(checkBox);
                    pMoves.add(checkBox);
                    checkBoxes.put("m" + car.getId(), checkBox);
                }
            }
        }
        // if not sorting by track, we're done
        if (!Setup.isSortByTrackNameEnabled()) {
            break;
        }
    }
    // pad the panels in case the horizontal scroll bar appears
    pPickups.add(new JLabel(Space));
    pSetouts.add(new JLabel(Space));
    pMoves.add(new JLabel(Space));
}
Also used : JCheckBox(javax.swing.JCheckBox) Car(jmri.jmrit.operations.rollingstock.cars.Car) JLabel(javax.swing.JLabel) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track)

Example 3 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class TrackEditFrame method checkRoute.

// check to see if the route services this location
private boolean checkRoute(Route route) {
    if (route == null) {
        return false;
    }
    RouteLocation rl = null;
    rl = route.getLastLocationByName(_location.getName());
    if (rl == null) {
        return false;
    }
    return true;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 4 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class JsonManifest method getLocations.

public ArrayNode getLocations() {
    // get engine and car lists
    List<Engine> engineList = engineManager.getByTrainBlockingList(train);
    List<Car> carList = carManager.getByTrainDestinationList(train);
    ArrayNode locations = this.mapper.createArrayNode();
    List<RouteLocation> route = train.getRoute().getLocationsBySequenceList();
    for (RouteLocation routeLocation : route) {
        String locationName = splitString(routeLocation.getName());
        ObjectNode jsonLocation = this.mapper.createObjectNode();
        ObjectNode jsonCars = this.mapper.createObjectNode();
        jsonLocation.put(JSON.NAME, StringEscapeUtils.escapeHtml4(locationName));
        jsonLocation.put(JSON.ID, routeLocation.getId());
        if (routeLocation != train.getRoute().getDepartsRouteLocation()) {
            jsonLocation.put(JSON.ARRIVAL_TIME, train.getExpectedArrivalTime(routeLocation));
        }
        if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
            jsonLocation.put(JSON.DEPARTURE_TIME, train.getDepartureTime());
        } else if (!routeLocation.getDepartureTime().equals(RouteLocation.NONE)) {
            jsonLocation.put(JSON.DEPARTURE_TIME, routeLocation.getDepartureTime());
        } else {
            jsonLocation.put(JSON.EXPECTED_DEPARTURE, train.getExpectedDepartureTime(routeLocation));
        }
        // add location comment and id
        ObjectNode locationNode = this.mapper.createObjectNode();
        locationNode.put(JSON.COMMENT, StringEscapeUtils.escapeHtml4(routeLocation.getLocation().getComment()));
        locationNode.put(JSON.ID, routeLocation.getLocation().getId());
        jsonLocation.put(JsonOperations.LOCATION, locationNode);
        jsonLocation.put(JSON.COMMENT, StringEscapeUtils.escapeHtml4(routeLocation.getComment()));
        // engine change or helper service?
        if (train.getSecondLegOptions() != Train.NO_CABOOSE_OR_FRED) {
            ArrayNode options = this.mapper.createArrayNode();
            if (routeLocation == train.getSecondLegStartLocation()) {
                if ((train.getSecondLegOptions() & Train.HELPER_ENGINES) == Train.HELPER_ENGINES) {
                    options.add(JSON.ADD_HELPERS);
                } else if ((train.getSecondLegOptions() & Train.REMOVE_CABOOSE) == Train.REMOVE_CABOOSE || (train.getSecondLegOptions() & Train.ADD_CABOOSE) == Train.ADD_CABOOSE) {
                    options.add(JSON.CHANGE_CABOOSE);
                } else if ((train.getSecondLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES) {
                    options.add(JSON.CHANGE_ENGINES);
                }
            }
            if (routeLocation == train.getSecondLegEndLocation()) {
                options.add(JSON.REMOVE_HELPERS);
            }
            jsonLocation.put(JSON.OPTIONS, options);
        }
        if (train.getThirdLegOptions() != Train.NO_CABOOSE_OR_FRED) {
            ArrayNode options = this.mapper.createArrayNode();
            if (routeLocation == train.getThirdLegStartLocation()) {
                if ((train.getThirdLegOptions() & Train.HELPER_ENGINES) == Train.HELPER_ENGINES) {
                    options.add(JSON.ADD_HELPERS);
                } else if ((train.getThirdLegOptions() & Train.REMOVE_CABOOSE) == Train.REMOVE_CABOOSE || (train.getThirdLegOptions() & Train.ADD_CABOOSE) == Train.ADD_CABOOSE) {
                    options.add(JSON.CHANGE_CABOOSE);
                } else if ((train.getThirdLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES) {
                    options.add(JSON.CHANGE_ENGINES);
                }
            }
            if (routeLocation == train.getThirdLegEndLocation()) {
                options.add(JSON.ADD_HELPERS);
            }
            jsonLocation.put(JSON.OPTIONS, options);
        }
        ObjectNode engines = this.mapper.createObjectNode();
        engines.put(JSON.ADD, pickupEngines(engineList, routeLocation));
        engines.put(JSON.REMOVE, dropEngines(engineList, routeLocation));
        jsonLocation.put(JSON.ENGINES, engines);
        // block cars by destination
        ArrayNode pickups = this.mapper.createArrayNode();
        for (RouteLocation destination : route) {
            for (Car car : carList) {
                if (car.getRouteLocation() == routeLocation && car.getRouteDestination() == destination) {
                    pickups.add(this.utilities.getCar(car));
                }
            }
        }
        jsonCars.put(JSON.ADD, pickups);
        // car set outs
        ArrayNode setouts = this.mapper.createArrayNode();
        for (Car car : carList) {
            if (car.getRouteDestination() == routeLocation) {
                setouts.add(this.utilities.getCar(car));
            }
        }
        jsonCars.put(JSON.REMOVE, setouts);
        if (routeLocation != train.getRoute().getTerminatesRouteLocation()) {
            jsonLocation.put(JsonOperations.TRACK, this.getTrackComments(routeLocation, carList));
            jsonLocation.put(JSON.DIRECTION, routeLocation.getTrainDirection());
            ObjectNode length = this.mapper.createObjectNode();
            length.put(JSON.LENGTH, train.getTrainLength(routeLocation));
            length.put(JSON.UNIT, Setup.getLengthUnit());
            jsonLocation.put(JSON.LENGTH, length);
            jsonLocation.put(JsonOperations.WEIGHT, train.getTrainWeight(routeLocation));
            int cars = train.getNumberCarsInTrain(routeLocation);
            int emptyCars = train.getNumberEmptyCarsInTrain(routeLocation);
            jsonCars.put(JSON.TOTAL, cars);
            jsonCars.put(JSON.LOADS, cars - emptyCars);
            jsonCars.put(JSON.EMPTIES, emptyCars);
        } else {
            log.debug("Train terminates in {}", locationName);
            jsonLocation.put("TrainTerminatesIn", StringEscapeUtils.escapeHtml4(locationName));
        }
        jsonLocation.put(JsonOperations.CARS, jsonCars);
        locations.add(jsonLocation);
    }
    return locations;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Car(jmri.jmrit.operations.rollingstock.cars.Car) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Example 5 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class Train method getNumberCarsInTrain.

/**
     * Gets the number of cars in the train when train departs the route
     * location.
     * @param routeLocation The RouteLocation.
     *
     * @return The number of cars in the train departing the route location.
     */
public int getNumberCarsInTrain(RouteLocation routeLocation) {
    int number = 0;
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            for (RollingStock rs : CarManager.instance().getList(this)) {
                if (rs.getRouteLocation() == rl) {
                    number++;
                }
                if (rs.getRouteDestination() == rl) {
                    number--;
                }
            }
            if (rl == routeLocation) {
                break;
            }
        }
    }
    return number;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Aggregations

RouteLocation (jmri.jmrit.operations.routes.RouteLocation)118 Route (jmri.jmrit.operations.routes.Route)64 Location (jmri.jmrit.operations.locations.Location)55 Track (jmri.jmrit.operations.locations.Track)52 Car (jmri.jmrit.operations.rollingstock.cars.Car)48 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)33 LocationManager (jmri.jmrit.operations.locations.LocationManager)21 RouteManager (jmri.jmrit.operations.routes.RouteManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)17 Train (jmri.jmrit.operations.trains.Train)16 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)13 ArrayList (java.util.ArrayList)12 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)12 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 IOException (java.io.IOException)6 TrainManager (jmri.jmrit.operations.trains.TrainManager)6 JCheckBox (javax.swing.JCheckBox)5