Search in sources :

Example 1 with Engine

use of jmri.jmrit.operations.rollingstock.engines.Engine 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 2 with Engine

use of jmri.jmrit.operations.rollingstock.engines.Engine in project JMRI by JMRI.

the class YardmasterByTrackPanel method runUpdate.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "CarManager only provides Car Objects")
private void runUpdate() {
    log.debug("run update");
    removePropertyChangeListerners();
    // reset the utility car counts
    trainCommon.clearUtilityCarTypes();
    checkBoxes.clear();
    pTrack.removeAll();
    boolean pickup = false;
    boolean setout = false;
    if (_track != null) {
        pTrackPane.setBorder(BorderFactory.createTitledBorder(_track.getName()));
        textTrackCommentPane.setText(_track.getComment());
        textTrackCommentPane.setVisible(!_track.getComment().equals(Track.NONE));
        textTrackCommentWorkPane.setText("");
        for (Train train : trainManager.getTrainsArrivingThisLocationList(_track.getLocation())) {
            JPanel pTrain = new JPanel();
            pTrain.setLayout(new BoxLayout(pTrain, BoxLayout.Y_AXIS));
            pTrain.setBorder(BorderFactory.createTitledBorder(MessageFormat.format(TrainSwitchListText.getStringScheduledWork(), new Object[] { train.getName(), train.getDescription() })));
            // List locos first
            List<Engine> engList = engManager.getByTrainBlockingList(train);
            if (Setup.isPrintHeadersEnabled()) {
                for (Engine engine : engList) {
                    if (engine.getTrack() == _track) {
                        JLabel header = new JLabel(Tab + trainCommon.getPickupEngineHeader());
                        setLabelFont(header);
                        pTrain.add(header);
                        break;
                    }
                }
            }
            for (Engine engine : engList) {
                if (engine.getTrack() == _track) {
                    engine.addPropertyChangeListener(this);
                    rollingStock.add(engine);
                    JCheckBox checkBox = new JCheckBox(trainCommon.pickupEngine(engine));
                    setCheckBoxFont(checkBox);
                    pTrain.add(checkBox);
                    checkBoxes.put(engine.getId(), checkBox);
                    pTrack.add(pTrain);
                }
            }
            // now do locomotive set outs
            if (Setup.isPrintHeadersEnabled()) {
                for (Engine engine : engList) {
                    if (engine.getDestinationTrack() == _track) {
                        JLabel header = new JLabel(Tab + trainCommon.getDropEngineHeader());
                        setLabelFont(header);
                        pTrain.add(header);
                        break;
                    }
                }
            }
            for (Engine engine : engList) {
                if (engine.getDestinationTrack() == _track) {
                    engine.addPropertyChangeListener(this);
                    rollingStock.add(engine);
                    JCheckBox checkBox = new JCheckBox(trainCommon.dropEngine(engine));
                    setCheckBoxFont(checkBox);
                    pTrain.add(checkBox);
                    checkBoxes.put(engine.getId(), checkBox);
                    pTrack.add(pTrain);
                }
            }
            // now cars
            List<Car> carList = carManager.getByTrainDestinationList(train);
            if (Setup.isPrintHeadersEnabled()) {
                for (Car car : carList) {
                    if (car.getTrack() == _track && car.getRouteDestination() != car.getRouteLocation()) {
                        JLabel header = new JLabel(Tab + trainCommon.getPickupCarHeader(!IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK));
                        setLabelFont(header);
                        pTrain.add(header);
                        break;
                    }
                }
            }
            // sort car pick ups by their destination
            List<RouteLocation> routeList = train.getRoute().getLocationsBySequenceList();
            for (RouteLocation rl : routeList) {
                for (Car car : carList) {
                    if (car.getTrack() == _track && car.getRouteDestination() != car.getRouteLocation() && car.getRouteDestination() == rl) {
                        car.addPropertyChangeListener(this);
                        rollingStock.add(car);
                        String text;
                        if (car.isUtility()) {
                            text = trainCommon.pickupUtilityCars(carList, car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
                            if (text == null) {
                                // this car type has already been processed
                                continue;
                            }
                        } else {
                            text = trainCommon.pickupCar(car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
                        }
                        pickup = true;
                        JCheckBox checkBox = new JCheckBox(text);
                        setCheckBoxFont(checkBox);
                        pTrain.add(checkBox);
                        checkBoxes.put(car.getId(), checkBox);
                        pTrack.add(pTrain);
                    }
                }
            }
            // now do car set outs
            if (Setup.isPrintHeadersEnabled()) {
                for (Car car : carList) {
                    if (car.getDestinationTrack() == _track && car.getRouteDestination() != car.getRouteLocation()) {
                        JLabel header = new JLabel(Tab + trainCommon.getDropCarHeader(!IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK));
                        setLabelFont(header);
                        pTrain.add(header);
                        break;
                    }
                }
            }
            for (Car car : carList) {
                if (car.getDestinationTrack() == _track && car.getRouteLocation() != car.getRouteDestination()) {
                    car.addPropertyChangeListener(this);
                    rollingStock.add(car);
                    String text;
                    if (car.isUtility()) {
                        text = trainCommon.setoutUtilityCars(carList, car, !TrainCommon.LOCAL, !IS_MANIFEST);
                        if (text == null) {
                            // this car type has already been processed
                            continue;
                        }
                    } else {
                        text = trainCommon.dropCar(car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
                    }
                    setout = true;
                    JCheckBox checkBox = new JCheckBox(text);
                    setCheckBoxFont(checkBox);
                    pTrain.add(checkBox);
                    checkBoxes.put(car.getId(), checkBox);
                    pTrack.add(pTrain);
                }
            }
            // now do local car moves
            if (Setup.isPrintHeadersEnabled()) {
                for (Car car : carList) {
                    if ((car.getTrack() == _track || car.getDestinationTrack() == _track) && car.getRouteDestination() == car.getRouteLocation()) {
                        JLabel header = new JLabel(Tab + trainCommon.getLocalMoveHeader(!IS_MANIFEST));
                        setLabelFont(header);
                        pTrain.add(header);
                        break;
                    }
                }
            }
            for (Car car : carList) {
                if ((car.getTrack() == _track || car.getDestinationTrack() == _track) && car.getRouteLocation() != null && car.getRouteLocation() == car.getRouteDestination()) {
                    car.addPropertyChangeListener(this);
                    rollingStock.add(car);
                    String text;
                    if (car.isUtility()) {
                        text = trainCommon.setoutUtilityCars(carList, car, TrainCommon.LOCAL, !IS_MANIFEST);
                        if (text == null) {
                            // this car type has already been processed
                            continue;
                        }
                    } else {
                        text = trainCommon.localMoveCar(car, !IS_MANIFEST);
                    }
                    setout = true;
                    JCheckBox checkBox = new JCheckBox(text);
                    setCheckBoxFont(checkBox);
                    pTrain.add(checkBox);
                    checkBoxes.put(car.getId(), checkBox);
                    pTrack.add(pTrain);
                }
            }
            pTrackPane.validate();
            pTrain.setMaximumSize(new Dimension(2000, pTrain.getHeight()));
            pTrain.revalidate();
        }
        // now do car holds
        // we only need the cars on this track
        List<RollingStock> rsList = carManager.getByTrainList();
        List<Car> carList = new ArrayList<Car>();
        for (RollingStock rs : rsList) {
            if (rs.getTrack() != _track || rs.getRouteLocation() != null)
                continue;
            carList.add((Car) rs);
        }
        JPanel pHoldCars = new JPanel();
        pHoldCars.setLayout(new BoxLayout(pHoldCars, BoxLayout.Y_AXIS));
        pHoldCars.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("HoldCars")));
        for (Car car : carList) {
            String text;
            if (car.isUtility()) {
                String s = trainCommon.pickupUtilityCars(carList, car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
                if (s == null)
                    continue;
                text = TrainSwitchListText.getStringHoldCar().split("\\{")[0] + s.trim();
            } else {
                text = MessageFormat.format(TrainSwitchListText.getStringHoldCar(), new Object[] { TrainCommon.padAndTruncateString(car.getRoadName(), CarRoads.instance().getMaxNameLength()), TrainCommon.padAndTruncateString(TrainCommon.splitString(car.getNumber()), Control.max_len_string_print_road_number), TrainCommon.padAndTruncateString(car.getTypeName().split("-")[0], CarTypes.instance().getMaxNameLength()), TrainCommon.padAndTruncateString(car.getLength() + TrainCommon.LENGTHABV, Control.max_len_string_length_name), TrainCommon.padAndTruncateString(car.getLoadName(), CarLoads.instance().getMaxNameLength()), TrainCommon.padAndTruncateString(_track.getName(), LocationManager.instance().getMaxTrackNameLength()), TrainCommon.padAndTruncateString(car.getColor(), CarColors.instance().getMaxNameLength()) });
            }
            JCheckBox checkBox = new JCheckBox(text);
            setCheckBoxFont(checkBox);
            pHoldCars.add(checkBox);
            checkBoxes.put(car.getId(), checkBox);
            pTrack.add(pHoldCars);
        }
        pTrackPane.validate();
        pHoldCars.setMaximumSize(new Dimension(2000, pHoldCars.getHeight()));
        pHoldCars.revalidate();
        if (pickup && !setout) {
            textTrackCommentWorkPane.setText(_track.getCommentPickup());
        } else if (!pickup && setout) {
            textTrackCommentWorkPane.setText(_track.getCommentSetout());
        } else if (pickup && setout) {
            textTrackCommentWorkPane.setText(_track.getCommentBoth());
        }
        textTrackCommentWorkPane.setVisible(!textTrackCommentWorkPane.getText().equals(""));
    } else {
        pTrackPane.setBorder(BorderFactory.createTitledBorder(""));
        textTrackCommentPane.setVisible(false);
        textTrackCommentWorkPane.setVisible(false);
    }
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Dimension(java.awt.Dimension) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) JCheckBox(javax.swing.JCheckBox) Car(jmri.jmrit.operations.rollingstock.cars.Car) Train(jmri.jmrit.operations.trains.Train) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with Engine

use of jmri.jmrit.operations.rollingstock.engines.Engine in project JMRI by JMRI.

the class TrainCommon method pickupEngines.

/**
     * Adds a list of locomotive pick ups for the route location to the output
     * file. Used to generate "Standard" format.
     * 
     * @param file Manifest or Switch List File
     * @param engineList List of engines for this train.
     * @param rl The RouteLocation being printed.
     * @param isManifest True if manifest, false if switch list
     *
     */
protected void pickupEngines(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) {
    boolean printHeader = Setup.isPrintHeadersEnabled();
    for (Engine engine : engineList) {
        if (engine.getRouteLocation() == rl && !engine.getTrackName().equals(Engine.NONE)) {
            if (printHeader) {
                printPickupEngineHeader(file, isManifest);
                printHeader = false;
            }
            pickupEngine(file, engine, isManifest);
        }
    }
}
Also used : Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Example 4 with Engine

use of jmri.jmrit.operations.rollingstock.engines.Engine in project JMRI by JMRI.

the class TrainCommon method blockLocosTwoColumn.

/**
     * Used to generate "Two Column" format for engines.
     * 
     * @param file Manifest or Switch List File
     * @param engineList List of engines for this train.
     * @param rl The RouteLocation being printed.
     * @param isManifest True if manifest, false if switch list.
     *
     */
protected void blockLocosTwoColumn(PrintWriter file, List<Engine> engineList, RouteLocation rl, boolean isManifest) {
    if (isThereWorkAtLocation(null, engineList, rl)) {
        printEngineHeader(file, isManifest);
    }
    int lineLength = getLineLength(isManifest);
    for (Engine engine : engineList) {
        if (engine.getRouteLocation() == rl && !engine.getTrackName().equals(Engine.NONE)) {
            String s = padAndTruncateString(pickupEngine(engine).trim(), lineLength / 2, true);
            s = padAndTruncateString(s + VERTICAL_LINE_CHAR, lineLength, true);
            addLine(file, s);
        }
        if (engine.getRouteDestination() == rl) {
            String s = padAndTruncateString(tabString("", lineLength / 2, true) + VERTICAL_LINE_CHAR + dropEngine(engine).trim(), lineLength, true);
            addLine(file, s);
        }
    }
}
Also used : Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Example 5 with Engine

use of jmri.jmrit.operations.rollingstock.engines.Engine in project JMRI by JMRI.

the class TrainBuilder method checkDepartureStagingTrack.

/**
     * Check departure staging track to see if engines and cars are available to
     * a new train. Also confirms that the engine and car type, load, road, etc.
     * are accepted by the train.
     *
     * @return true is there are engines and cars available.
     */
private boolean checkDepartureStagingTrack(Track departStageTrack) {
    // does this staging track service this train?
    if (!departStageTrack.acceptsPickupTrain(_train)) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNotTrain"), new Object[] { departStageTrack.getName() }));
        return false;
    }
    if (departStageTrack.getNumberRS() == 0 && _train.getTrainDepartsRouteLocation().getMaxCarMoves() > 0) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingEmpty"), new Object[] { departStageTrack.getName() }));
        return false;
    }
    if (departStageTrack.getUsedLength() > _train.getTrainDepartsRouteLocation().getMaxTrainLength()) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingTrainTooLong"), new Object[] { departStageTrack.getName(), departStageTrack.getUsedLength(), Setup.getLengthUnit().toLowerCase(), _train.getTrainDepartsRouteLocation().getMaxTrainLength() }));
        return false;
    }
    if (departStageTrack.getNumberCars() > _train.getTrainDepartsRouteLocation().getMaxCarMoves()) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingTooManyCars"), new Object[] { departStageTrack.getName(), departStageTrack.getNumberCars(), _train.getTrainDepartsRouteLocation().getMaxCarMoves() }));
        return false;
    }
    // does the staging track have the right number of locomotives?
    if (_reqNumEngines > 0 && _reqNumEngines != departStageTrack.getNumberEngines()) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNotEngines"), new Object[] { departStageTrack.getName(), departStageTrack.getNumberEngines(), _reqNumEngines }));
        return false;
    }
    // is the staging track direction correct for this train?
    if ((departStageTrack.getTrainDirections() & _train.getTrainDepartsRouteLocation().getTrainDirection()) == 0) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNotDirection"), new Object[] { departStageTrack.getName() }));
        return false;
    }
    if (departStageTrack.getNumberEngines() > 0) {
        for (RollingStock rs : engineManager.getList()) {
            Engine eng = (Engine) rs;
            if (eng.getTrack() == departStageTrack) {
                // has engine been assigned to another train?
                if (eng.getRouteLocation() != null) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepart"), new Object[] { departStageTrack.getName(), eng.getTrainName() }));
                    return false;
                }
                if (eng.getTrain() != null && eng.getTrain() != _train) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineTrain"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getTrainName() }));
                    return false;
                }
                // does the train accept the engine type from the staging track?
                if (!_train.acceptsTypeName(eng.getTypeName())) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineType"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getTypeName(), _train.getName() }));
                    return false;
                }
                // does the train accept the engine model from the staging track?
                if (!_train.getEngineModel().equals(Train.NONE) && !_train.getEngineModel().equals(eng.getModel())) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineModel"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getModel(), _train.getName() }));
                    return false;
                }
                // does the engine road match the train requirements?
                if (!_train.getRoadOption().equals(Train.ALL_LOADS) && !_train.getEngineRoad().equals(Train.NONE) && !_train.getEngineRoad().equals(eng.getRoadName())) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineRoad"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getRoadName(), _train.getName() }));
                    return false;
                }
                // does the train accept the engine road from the staging track?
                if (_train.getEngineRoad().equals(Train.NONE) && !_train.acceptsRoadName(eng.getRoadName())) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineRoad"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getRoadName(), _train.getName() }));
                    return false;
                }
                // does the train accept the engine owner from the staging track?
                if (!_train.acceptsOwnerName(eng.getOwner())) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineOwner"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getOwner(), _train.getName() }));
                    return false;
                }
                // does the train accept the engine built date from the staging track?
                if (!_train.acceptsBuiltDate(eng.getBuilt())) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartEngineBuilt"), new Object[] { departStageTrack.getName(), eng.toString(), eng.getBuilt(), _train.getName() }));
                    return false;
                }
            }
        }
    }
    boolean foundCaboose = false;
    boolean foundFRED = false;
    if (departStageTrack.getNumberCars() > 0) {
        for (RollingStock rs : carManager.getList()) {
            Car car = (Car) rs;
            if (car.getTrack() != departStageTrack) {
                continue;
            }
            // ignore non-lead cars in kernels
            if (car.getKernel() != null && !car.getKernel().isLead(car)) {
                // ignore non-lead cars
                continue;
            }
            // has car been assigned to another train?
            if (car.getRouteLocation() != null) {
                log.debug("Car ({}) has route location ({})", car.toString(), car.getRouteLocation().getName());
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepart"), new Object[] { departStageTrack.getName(), car.getTrainName() }));
                return false;
            }
            if (car.getTrain() != null && car.getTrain() != _train) {
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarTrain"), new Object[] { departStageTrack.getName(), car.toString(), car.getTrainName() }));
                return false;
            }
            // does the train accept the car type from the staging track?
            if (!_train.acceptsTypeName(car.getTypeName())) {
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarType"), new Object[] { departStageTrack.getName(), car.toString(), car.getTypeName(), _train.getName() }));
                return false;
            }
            // does the train accept the car road from the staging track?
            if (!_train.acceptsRoadName(car.getRoadName())) {
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarRoad"), new Object[] { departStageTrack.getName(), car.toString(), car.getRoadName(), _train.getName() }));
                return false;
            }
            // does the train accept the car load from the staging track?
            if (!car.isCaboose() && !car.isPassenger() && (!car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) || !departStageTrack.isAddCustomLoadsEnabled() && !departStageTrack.isAddCustomLoadsAnySpurEnabled() && !departStageTrack.isAddCustomLoadsAnyStagingTrackEnabled()) && !_train.acceptsLoad(car.getLoadName(), car.getTypeName())) {
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarLoad"), new Object[] { departStageTrack.getName(), car.toString(), car.getLoadName(), _train.getName() }));
                return false;
            }
            // does the train accept the car owner from the staging track?
            if (!_train.acceptsOwnerName(car.getOwner())) {
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarOwner"), new Object[] { departStageTrack.getName(), car.toString(), car.getOwner(), _train.getName() }));
                return false;
            }
            // does the train accept the car built date from the staging track?
            if (!_train.acceptsBuiltDate(car.getBuilt())) {
                addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarBuilt"), new Object[] { departStageTrack.getName(), car.toString(), car.getBuilt(), _train.getName() }));
                return false;
            }
            // does the car have a destination serviced by this train?
            if (car.getDestination() != null) {
                log.debug("Car ({}) has a destination ({}, {})", car.toString(), car.getDestinationName(), car.getDestinationTrackName());
                if (!_train.services(car)) {
                    addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingDepartCarDestination"), new Object[] { departStageTrack.getName(), car.toString(), car.getDestinationName(), _train.getName() }));
                    return false;
                }
            }
            // is this car a caboose with the correct road for this train?
            if (car.isCaboose() && (_train.getCabooseRoad().equals(Train.NONE) || _train.getCabooseRoad().equals(car.getRoadName()))) {
                foundCaboose = true;
            }
            // is this car have a FRED with the correct road for this train?
            if (car.hasFred() && (_train.getCabooseRoad().equals(Train.NONE) || _train.getCabooseRoad().equals(car.getRoadName()))) {
                foundFRED = true;
            }
        }
    }
    // does the train require a caboose and did we find one from staging?
    if ((_train.getRequirements() & Train.CABOOSE) == Train.CABOOSE && !foundCaboose) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNoCaboose"), new Object[] { departStageTrack.getName(), _train.getCabooseRoad() }));
        return false;
    }
    // does the train require a car with FRED and did we find one from staging?
    if ((_train.getRequirements() & Train.FRED) == Train.FRED && !foundFRED) {
        addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildStagingNoCarFRED"), new Object[] { departStageTrack.getName(), _train.getCabooseRoad() }));
        return false;
    }
    addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildTrainCanDepartTrack"), new Object[] { _train.getName(), departStageTrack.getName() }));
    return true;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Aggregations

Engine (jmri.jmrit.operations.rollingstock.engines.Engine)50 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)36 Route (jmri.jmrit.operations.routes.Route)31 Location (jmri.jmrit.operations.locations.Location)29 Track (jmri.jmrit.operations.locations.Track)29 Car (jmri.jmrit.operations.rollingstock.cars.Car)26 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)18 LocationManager (jmri.jmrit.operations.locations.LocationManager)13 RouteManager (jmri.jmrit.operations.routes.RouteManager)13 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)10 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)10 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)7 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)5 ArrayList (java.util.ArrayList)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 BufferedWriter (java.io.BufferedWriter)3 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3