Search in sources :

Example 16 with RouteLocation

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

the class ShowTrainsServingLocationFrame method updateTrainPane.

private void updateTrainPane() {
    pTrains.removeAll();
    int y = 0;
    for (Train train : TrainManager.instance().getTrainsByNameList()) {
        Route route = train.getRoute();
        if (route == null) {
            continue;
        }
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            if (rl.getName().equals(_location.getName())) {
                boolean pickup = false;
                boolean setout = false;
                // monitor move count in the route for this location
                train.getRoute().removePropertyChangeListener(this);
                train.getRoute().addPropertyChangeListener(this);
                if (rl.isPickUpAllowed() && rl.getMaxCarMoves() > 0 && !train.skipsLocation(rl.getId()) && (typeComboBox.getSelectedItem() == null || typeComboBox.getSelectedItem().equals(NONE) || train.acceptsTypeName((String) typeComboBox.getSelectedItem())) && (train.isLocalSwitcher() || (rl.getTrainDirection() & _location.getTrainDirections()) != 0) && (train.isLocalSwitcher() || _track == null || ((rl.getTrainDirection() & _track.getTrainDirections()) != 0)) && (_track == null || _track.acceptsPickupTrain(train))) {
                    pickup = true;
                }
                if (rl.isDropAllowed() && rl.getMaxCarMoves() > 0 && !train.skipsLocation(rl.getId()) && (typeComboBox.getSelectedItem() == null || typeComboBox.getSelectedItem().equals(NONE) || train.acceptsTypeName((String) typeComboBox.getSelectedItem())) && (train.isLocalSwitcher() || (rl.getTrainDirection() & _location.getTrainDirections()) != 0) && (train.isLocalSwitcher() || _track == null || ((rl.getTrainDirection() & _track.getTrainDirections()) != 0)) && (_track == null || _track.acceptsDropTrain(train))) {
                    setout = true;
                }
                // now display results
                if (showAllTrainsCheckBox.isSelected() || pickup || setout) {
                    addItemLeft(pTrains, new JLabel(train.getName()), 0, y);
                    if (pickup) {
                        addItem(pTrains, new JLabel(Bundle.getMessage("OkayPickUp")), 1, y);
                    } else {
                        addItem(pTrains, new JLabel(Bundle.getMessage("NoPickUp")), 1, y);
                    }
                    if (setout) {
                        addItem(pTrains, new JLabel(Bundle.getMessage("OkaySetOut")), 2, y);
                    } else {
                        addItem(pTrains, new JLabel(Bundle.getMessage("NoSetOut")), 2, y);
                    }
                }
                y++;
            }
        }
    }
    pTrains.repaint();
    pTrains.revalidate();
}
Also used : JLabel(javax.swing.JLabel) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) Route(jmri.jmrit.operations.routes.Route)

Example 17 with RouteLocation

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

the class TrainBuilder method checkTrainLength.

/**
     * Checks to see if train length would be exceeded if this car was added to
     * the train.
     *
     * @param car the car
     * @param rl the planned origin for this car
     * @param rld the planned destination for this car
     * @return true if car can be added to train
     */
private boolean checkTrainLength(Car car, RouteLocation rl, RouteLocation rld) {
    // car can be a kernel so get total length
    int length = car.getTotalLength();
    if (car.getKernel() != null) {
        length = car.getKernel().getTotalLength();
    }
    boolean carInTrain = false;
    for (RouteLocation rlt : _routeList) {
        if (rl == rlt) {
            carInTrain = true;
        }
        if (rld == rlt) {
            break;
        }
        if (carInTrain && rlt.getTrainLength() + length > rlt.getMaxTrainLength()) {
            addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildCanNotPickupCarLength"), new Object[] { car.toString(), length, Setup.getLengthUnit().toLowerCase() }));
            addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildCanNotPickupCarLength2"), new Object[] { rlt.getMaxTrainLength(), Setup.getLengthUnit().toLowerCase(), rlt.getTrainLength() + length - rlt.getMaxTrainLength(), rlt.getName(), rlt.getId() }));
            return false;
        }
    }
    return true;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 18 with RouteLocation

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

the class Train method move.

/**
     * Move train to a location in the train's route. Code checks to see if the
     * location requested is part of the train's route and if the train hasn't
     * already visited the location. This command can only move the train
     * forward in its route. Note that you can not terminate the train using
     * this command. See move() or terminate().
     *
     * @param locationName The name of the location to move this train.
     * @return true if train was able to move to the named location.
     */
public boolean move(String locationName) {
    log.info("Move train (" + getName() + ") to location (" + locationName + ")");
    if (getRoute() == null || getCurrentLocation() == null) {
        return false;
    }
    List<RouteLocation> routeList = getRoute().getLocationsBySequenceList();
    for (int i = 0; i < routeList.size(); i++) {
        RouteLocation rl = routeList.get(i);
        if (getCurrentLocation() == rl) {
            for (int j = i + 1; j < routeList.size(); j++) {
                rl = routeList.get(j);
                if (rl.getName().equals(locationName)) {
                    log.debug("Found location (" + locationName + ") moving train to this location");
                    for (j = i + 1; j < routeList.size(); j++) {
                        rl = routeList.get(j);
                        move();
                        if (rl.getName().equals(locationName)) {
                            return true;
                        }
                    }
                }
            }
            // done
            break;
        }
    }
    return false;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 19 with RouteLocation

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

the class Train method getTrainWeight.

public int getTrainWeight(RouteLocation routeLocation) {
    int weight = 0;
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            for (RollingStock rs : EngineManager.instance().getList(this)) {
                if (rs.getRouteLocation() == rl) {
                    weight += rs.getAdjustedWeightTons();
                }
                if (rs.getRouteDestination() == rl) {
                    weight += -rs.getAdjustedWeightTons();
                }
            }
            for (RollingStock rs : CarManager.instance().getList(this)) {
                Car car = (Car) rs;
                if (car.getRouteLocation() == rl) {
                    // weight depends on car load
                    weight += car.getAdjustedWeightTons();
                }
                if (car.getRouteDestination() == rl) {
                    weight += -car.getAdjustedWeightTons();
                }
            }
            if (rl == routeLocation) {
                break;
            }
        }
    }
    return weight;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 20 with RouteLocation

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

the class Train method getExpectedDepartureTime.

public String getExpectedDepartureTime(RouteLocation routeLocation) {
    int minutes = getExpectedTravelTimeInMinutes(routeLocation);
    if (minutes == -1) {
        return ALREADY_SERVICED;
    }
    // figure out the work at this location, note that there can be consecutive locations with the same name
    if (getRoute() != null) {
        boolean foundRouteLocation = false;
        for (RouteLocation rl : getRoute().getLocationsBySequenceList()) {
            if (rl == routeLocation) {
                foundRouteLocation = true;
            }
            if (foundRouteLocation) {
                if (TrainCommon.splitString(rl.getName()).equals(TrainCommon.splitString(routeLocation.getName()))) {
                    minutes = minutes + calculateWorkTimeAtLocation(rl);
                } else {
                    // done
                    break;
                }
            }
        }
    }
    log.debug("Expected departure time {} for train ({}) at ({})", minutes, getName(), routeLocation.getName());
    return parseTime(minutes);
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

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