Search in sources :

Example 41 with RouteLocation

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

the class HtmlConductor method pickupCars.

private String pickupCars() {
    StringBuilder builder = new StringBuilder();
    RouteLocation location = train.getCurrentLocation();
    List<Car> carList = CarManager.instance().getByTrainDestinationList(train);
    List<Track> tracks = location.getLocation().getTrackByNameList(null);
    List<String> trackNames = new ArrayList<String>();
    List<String> pickedUp = new ArrayList<String>();
    this.clearUtilityCarTypes();
    for (Track track : tracks) {
        if (trackNames.contains(splitString(track.getName()))) {
            continue;
        }
        // use a track name once
        trackNames.add(splitString(track.getName()));
        // block cars by destination
        for (RouteLocation rld : train.getRoute().getLocationsBySequenceList()) {
            for (Car car : carList) {
                if (pickedUp.contains(car.getId()) || (Setup.isSortByTrackNameEnabled() && !splitString(track.getName()).equals(splitString(car.getTrackName())))) {
                    continue;
                }
                // note that a car in train doesn't have a track assignment
                if (car.getRouteLocation() == location && car.getTrack() != null && car.getRouteDestination() == rld) {
                    pickedUp.add(car.getId());
                    if (car.isUtility()) {
                        builder.append(pickupUtilityCars(carList, car, TrainCommon.IS_MANIFEST));
                    // use truncated format if there's a switch list
                    } else if (Setup.isTruncateManifestEnabled() && location.getLocation().isSwitchListEnabled()) {
                        builder.append(pickUpCar(car, Setup.getPickupTruncatedManifestMessageFormat()));
                    } else {
                        builder.append(pickUpCar(car, Setup.getPickupManifestMessageFormat()));
                    }
                }
            }
        }
    }
    return builder.toString();
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) ArrayList(java.util.ArrayList) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track)

Example 42 with RouteLocation

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

the class HtmlManifest method getLocations.

// TODO cache the results so a quick check that if the JsonManifest file is not
// newer than the Html manifest, the cached copy is returned instead.
public String getLocations() throws IOException {
    // build manifest from JSON manifest
    if (this.getJsonManifest() == null) {
        return "Error manifest file not found for this train";
    }
    StringBuilder builder = new StringBuilder();
    ArrayNode locations = (ArrayNode) this.getJsonManifest().path(JsonOperations.LOCATIONS);
    String previousLocationName = null;
    boolean hasWork;
    for (JsonNode location : locations) {
        RouteLocation routeLocation = train.getRoute().getLocationById(location.path(JSON.ID).textValue());
        log.debug("Processing {} ({})", routeLocation.getName(), location.path(JSON.ID).textValue());
        String routeLocationName = location.path(JSON.NAME).textValue();
        // NOI18N
        builder.append(String.format(locale, strings.getProperty("LocationStart"), routeLocation.getId()));
        hasWork = (location.path(JsonOperations.CARS).path(JSON.ADD).size() > 0 || location.path(JsonOperations.CARS).path(JSON.REMOVE).size() > 0 || location.path(JSON.ENGINES).path(JSON.ADD).size() > 0 || location.path(JSON.ENGINES).path(JSON.REMOVE).size() > 0);
        if (hasWork && !routeLocationName.equals(previousLocationName)) {
            if (!train.isShowArrivalAndDepartureTimesEnabled()) {
                // NOI18N
                builder.append(String.format(locale, strings.getProperty("ScheduledWorkAt"), routeLocationName));
            } else if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
                builder.append(String.format(locale, strings.getProperty("WorkDepartureTime"), routeLocationName, // NOI18N
                train.getFormatedDepartureTime()));
            } else if (!routeLocation.getDepartureTime().equals(RouteLocation.NONE)) {
                builder.append(String.format(locale, strings.getProperty("WorkDepartureTime"), routeLocationName, // NOI18N
                routeLocation.getFormatedDepartureTime()));
            } else if (Setup.isUseDepartureTimeEnabled() && routeLocation != train.getRoute().getTerminatesRouteLocation()) {
                builder.append(String.format(locale, strings.getProperty("WorkDepartureTime"), routeLocationName, // NOI18N
                train.getExpectedDepartureTime(routeLocation)));
            } else if (!train.getExpectedArrivalTime(routeLocation).equals(Train.ALREADY_SERVICED)) {
                // NOI18N
                builder.append(String.format(locale, strings.getProperty("WorkArrivalTime"), routeLocationName, // NOI18N
                train.getExpectedArrivalTime(routeLocation)));
            } else {
                // NOI18N
                builder.append(String.format(locale, strings.getProperty("ScheduledWorkAt"), routeLocationName));
            }
            // add route comment
            if (!location.path(JSON.COMMENT).textValue().trim().isEmpty()) {
                builder.append(String.format(locale, strings.getProperty("RouteLocationComment"), location.path(JSON.COMMENT).textValue()));
            }
            builder.append(getTrackComments(location.path(JsonOperations.TRACK), location.path(JsonOperations.CARS)));
            // add location comment
            if (Setup.isPrintLocationCommentsEnabled() && !location.path(JsonOperations.LOCATION).path(JSON.COMMENT).textValue().trim().isEmpty()) {
                builder.append(String.format(locale, strings.getProperty("LocationComment"), location.path(JsonOperations.LOCATION).path(JSON.COMMENT).textValue()));
            }
        }
        previousLocationName = routeLocationName;
        // engine change or helper service?
        if (location.path(JSON.OPTIONS).size() > 0) {
            Iterator<JsonNode> options = location.path(JSON.OPTIONS).elements();
            boolean changeEngines = false;
            boolean changeCaboose = false;
            while (options.hasNext()) {
                String option = options.next().textValue();
                if (option.equals(JSON.CHANGE_ENGINES)) {
                    changeEngines = true;
                } else if (option.equals(JSON.CHANGE_CABOOSE)) {
                    changeCaboose = true;
                } else if (option.equals(JSON.ADD_HELPERS)) {
                    builder.append(String.format(strings.getProperty("AddHelpersAt"), routeLocationName));
                } else if (option.equals(JSON.REMOVE_HELPERS)) {
                    builder.append(String.format(strings.getProperty("RemoveHelpersAt"), routeLocationName));
                }
            }
            if (changeEngines && changeCaboose) {
                // NOI18N
                builder.append(String.format(strings.getProperty("LocoAndCabooseChangeAt"), routeLocationName));
            } else if (changeEngines) {
                // NOI18N
                builder.append(String.format(strings.getProperty("LocoChangeAt"), routeLocationName));
            } else if (changeCaboose) {
                // NOI18N
                builder.append(String.format(strings.getProperty("CabooseChangeAt"), routeLocationName));
            }
        }
        builder.append(pickupEngines(location.path(JSON.ENGINES).path(JSON.ADD)));
        builder.append(blockCars(location.path(JsonOperations.CARS), routeLocation, true));
        builder.append(dropEngines(location.path(JSON.ENGINES).path(JSON.REMOVE)));
        if (routeLocation != train.getRoute().getTerminatesRouteLocation()) {
            // Is the next location the same as the current?
            RouteLocation rlNext = train.getRoute().getNextRouteLocation(routeLocation);
            if (!routeLocationName.equals(splitString(rlNext.getName()))) {
                if (hasWork) {
                    if (!Setup.isPrintLoadsAndEmptiesEnabled()) {
                        // Message format: Train departs Boston Westbound with 12 cars, 450 feet, 3000 tons
                        builder.append(String.format(strings.getProperty("TrainDepartsCars"), routeLocationName, strings.getProperty("Heading" + Setup.getDirectionString(location.path(JSON.DIRECTION).intValue())), location.path(JSON.LENGTH).path(JSON.LENGTH).intValue(), location.path(JSON.LENGTH).path(JSON.UNIT).asText().toLowerCase(), location.path(JsonOperations.WEIGHT).intValue(), location.path(JsonOperations.CARS).path(JSON.TOTAL).intValue()));
                    } else {
                        // Message format: Train departs Boston Westbound with 4 loads, 8 empties, 450 feet, 3000
                        // tons
                        builder.append(String.format(strings.getProperty("TrainDepartsLoads"), routeLocationName, strings.getProperty("Heading" + Setup.getDirectionString(location.path(JSON.DIRECTION).intValue())), location.path(JSON.LENGTH).path(JSON.LENGTH).intValue(), location.path(JSON.LENGTH).path(JSON.UNIT).asText().toLowerCase(), location.path(JsonOperations.WEIGHT).intValue(), location.path(JsonOperations.CARS).path(JSON.LOADS).intValue(), location.path(JsonOperations.CARS).path(JSON.EMPTIES).intValue()));
                    }
                } else {
                    log.debug("No work ({})", routeLocation.getComment());
                    if (routeLocation.getComment().trim().isEmpty()) {
                        // no route comment, no work at this location
                        if (train.isShowArrivalAndDepartureTimesEnabled()) {
                            if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
                                builder.append(String.format(locale, strings.getProperty("NoScheduledWorkAtWithDepartureTime"), routeLocationName, train.getFormatedDepartureTime()));
                            } else if (!routeLocation.getDepartureTime().isEmpty()) {
                                builder.append(String.format(locale, strings.getProperty("NoScheduledWorkAtWithDepartureTime"), routeLocationName, routeLocation.getFormatedDepartureTime()));
                            } else if (Setup.isUseDepartureTimeEnabled()) {
                                builder.append(String.format(locale, strings.getProperty("NoScheduledWorkAtWithDepartureTime"), routeLocationName, location.path(JSON.EXPECTED_DEPARTURE)));
                            } else {
                                // fall back to generic no scheduled work message
                                builder.append(String.format(locale, strings.getProperty("NoScheduledWorkAt"), routeLocationName));
                            }
                        } else {
                            builder.append(String.format(locale, strings.getProperty("NoScheduledWorkAt"), routeLocationName));
                        }
                    } else {
                        // route comment, so only use location and route comment (for passenger trains)
                        if (train.isShowArrivalAndDepartureTimesEnabled()) {
                            if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
                                builder.append(String.format(locale, strings.getProperty("CommentAtWithDepartureTime"), routeLocationName, train.getFormatedDepartureTime(), routeLocation.getComment()));
                            } else if (!routeLocation.getDepartureTime().isEmpty()) {
                                builder.append(String.format(locale, strings.getProperty("CommentAtWithDepartureTime"), routeLocationName, routeLocation.getFormatedDepartureTime(), routeLocation.getComment()));
                            }
                        } else {
                            builder.append(String.format(locale, strings.getProperty("CommentAt"), routeLocationName, null, routeLocation.getComment()));
                        }
                    }
                    // add location comment
                    if (Setup.isPrintLocationCommentsEnabled() && !routeLocation.getLocation().getComment().isEmpty()) {
                        builder.append(String.format(locale, strings.getProperty("LocationComment"), routeLocation.getLocation().getComment()));
                    }
                }
            }
        } else {
            builder.append(String.format(strings.getProperty("TrainTerminatesIn"), routeLocationName));
        }
    }
    return builder.toString();
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 43 with RouteLocation

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

the class TrainBuilderTest method testSidingsYards.

// testSidingsYards tests the build procedure
// through the train's build method.
// test siding and yard moves
// tests manual setting of destinations and trains for engines, cars, and cabooses.
// tests consists and kernels
public void testSidingsYards() {
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    // Set up two cabooses and six box cars
    Car c1 = cmanager.newCar("CP", "10");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(10);
    c1.setCaboose(true);
    Car c2 = cmanager.newCar("CP", "200");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setMoves(11);
    c2.setCaboose(true);
    Car c3 = cmanager.newCar("CP", "30");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c2.setMoves(12);
    Car c4 = cmanager.newCar("CP", "4000");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setMoves(13);
    Car c5 = cmanager.newCar("CP", "5");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setMoves(14);
    Car c6 = cmanager.newCar("CP", "60");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(15);
    Car c7 = cmanager.newCar("CP", "700");
    c7.setTypeName("Flat");
    c7.setLength("50");
    c7.setMoves(16);
    Car c8 = cmanager.newCar("CP", "8000");
    c8.setTypeName("Boxcar");
    c8.setLength("60");
    c8.setMoves(17);
    Car c9 = cmanager.newCar("CP", "9");
    c9.setTypeName("Flat");
    c9.setLength("40");
    c9.setMoves(18);
    Car c10 = cmanager.newCar("CP", "1000");
    c10.setTypeName("Flat");
    c10.setLength("40");
    c10.setMoves(19);
    // place two engines in a consist
    Consist con1 = emanager.newConsist("CP");
    Engine e1 = emanager.newEngine("CP", "10");
    e1.setModel("GP30");
    e1.setConsist(con1);
    Engine e2 = emanager.newEngine("CP", "20");
    e2.setModel("GP30");
    e2.setConsist(con1);
    // Set up a route of 3 locations: Foxboro (2 tracks, yard and siding),
    // Acton (2 tracks, sidings), and Nashua (2 tracks, yards).
    Location l1 = lmanager.newLocation("Foxboro");
    Assert.assertEquals("Location 1 Name", "Foxboro", l1.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
    Track l1s1 = l1.addTrack("Foxboro Siding", Track.SPUR);
    l1s1.setLength(600);
    Assert.assertEquals("Location 1s1 Name", "Foxboro Siding", l1s1.getName());
    Assert.assertEquals("Location 1s1 LocType", "Siding", l1s1.getTrackType());
    Assert.assertEquals("Location 1s1 Length", 600, l1s1.getLength());
    Assert.assertEquals("Default directions", DIRECTION_ALL, l1s1.getTrainDirections());
    Track l1s2 = l1.addTrack("Foxboro Yard", Track.YARD);
    l1s2.setLength(400);
    Assert.assertEquals("Location 1s2 Name", "Foxboro Yard", l1s2.getName());
    Assert.assertEquals("Location 1s2 LocType", "Yard", l1s2.getTrackType());
    Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
    Assert.assertEquals("Location 1 Length", 1000, l1.getLength());
    Location l2 = lmanager.newLocation("Acton");
    Assert.assertEquals("Location 2 Name", "Acton", l2.getName());
    Track l2s1 = l2.addTrack("Acton Siding 1", Track.SPUR);
    l2s1.setLength(543);
    l2s1.setMoves(1);
    Assert.assertEquals("Location 2s1 Name", "Acton Siding 1", l2s1.getName());
    Assert.assertEquals("Location 2s1 LocType", Track.SPUR, l2s1.getTrackType());
    Assert.assertEquals("Location 2s1 Length", 543, l2s1.getLength());
    Track l2s2 = l2.addTrack("Acton Siding 2", Track.SPUR);
    l2s2.setLength(345);
    Assert.assertEquals("Acton Length", 888, l2.getLength());
    Location l3 = lmanager.newLocation("Nashua");
    Track l3s1 = l3.addTrack("Nashua Yard 1", Track.YARD);
    l3s1.setLength(301);
    Track l3s2 = l3.addTrack("Nashua Yard 2", Track.YARD);
    l3s2.setLength(402);
    Assert.assertEquals("Location 3 Length", 703, l3.getLength());
    // define the route
    // set default to 6 moves per location
    Setup.setCarMoves(6);
    Route r1 = rmanager.newRoute("Foxboro-Acton-Nashua-Acton-Foxboro");
    RouteLocation rl1 = r1.addLocation(l1);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(225);
    RouteLocation rl2 = r1.addLocation(l2);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(225);
    RouteLocation rl3 = r1.addLocation(l3);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(225);
    RouteLocation rl4 = r1.addLocation(l2);
    // set the train icon coordinates
    rl4.setTrainIconX(175);
    rl4.setTrainIconY(225);
    RouteLocation rl5 = r1.addLocation(l1);
    // set the train icon coordinates
    rl5.setTrainIconX(225);
    rl5.setTrainIconY(225);
    // don't include cars at destination
    rl5.setPickUpAllowed(false);
    // define the train
    Train t1 = tmanager.newTrain("TestSidingsYards");
    t1.setRoute(r1);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 1", t1.isBuilt());
    Assert.assertEquals("should be 0 cars", 0, t1.getNumberCarsWorked());
    // place the cars on the tracks
    // Place cars
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(l1, l1s1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(l1, l1s1));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(l1, l1s1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(l1, l1s1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(l1, l1s1));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(l1, l1s1));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l1, l1s1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l1, l1s1));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(l1, l1s1));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(l1, l1s1));
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 2", t1.isBuilt());
    Assert.assertEquals("should be 6 cars", 6, t1.getNumberCarsWorked());
    // check car destinations
    Assert.assertEquals("Destination c1", "", c1.getDestinationName());
    Assert.assertEquals("Destination c2", "", c2.getDestinationName());
    Assert.assertEquals("Destination c3", "Acton", c3.getDestinationName());
    Assert.assertEquals("Destination c4", "Nashua", c4.getDestinationName());
    Assert.assertEquals("Destination c5", "Acton", c5.getDestinationName());
    Assert.assertEquals("Destination c6", "Nashua", c6.getDestinationName());
    Assert.assertEquals("Destination c7", "Acton", c7.getDestinationName());
    Assert.assertEquals("Destination c8", "Nashua", c8.getDestinationName());
    Assert.assertEquals("Destination c9", "", c9.getDestinationName());
    Assert.assertEquals("Destination c10", "", c10.getDestinationName());
    Assert.assertEquals("Destination e1", "", e1.getDestinationName());
    // release cars from train
    Assert.assertTrue("reset train", t1.reset());
    Assert.assertEquals("Train reset", Train.CODE_TRAIN_RESET, t1.getStatusCode());
    // set c3, c5, c6, c8, c10 destination to be Nashua
    c3.setDestination(l3, l3s1);
    c5.setDestination(l3, l3s1);
    c6.setDestination(l3, l3s1);
    c8.setDestination(l3, l3s1);
    c10.setDestination(l3, l3s1);
    // set c5 and c9 to be serviced by train TT
    Train t2 = tmanager.newTrain("TT");
    c5.setTrain(t2);
    c9.setTrain(t2);
    // set c6 to be serviced by train FF
    c6.setTrain(t1);
    // require a caboose
    t1.setRequirements(Train.CABOOSE);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 3", t1.isBuilt());
    // check car destinations
    Assert.assertEquals("2 Destination  c1", "Foxboro", c1.getDestinationName());
    Assert.assertEquals("2 Destination  c2", "", c2.getDestinationName());
    Assert.assertEquals("2 Destination  c3", "Nashua", c3.getDestinationName());
    Assert.assertEquals("2 Destination  c4", "Acton", c4.getDestinationName());
    Assert.assertEquals("2 Destination  c5", "Nashua", c5.getDestinationName());
    Assert.assertEquals("2 Destination  c6", "Nashua", c6.getDestinationName());
    Assert.assertEquals("2 Destination  c7", "Acton", c7.getDestinationName());
    Assert.assertEquals("2 Destination  c8", "Nashua", c8.getDestinationName());
    Assert.assertEquals("2 Destination  c9", "", c9.getDestinationName());
    Assert.assertEquals("2 Destination  c10", "Nashua", c10.getDestinationName());
    // move and terminate the train
    // to Acton
    t1.move();
    // to Nashua
    t1.move();
    // to Acton
    t1.move();
    // to Foxboro
    t1.move();
    // terminate
    t1.move();
    // check car destinations
    Assert.assertEquals("3 Destination c1", "", c1.getDestinationName());
    Assert.assertEquals("3 Destination c2", "", c2.getDestinationName());
    Assert.assertEquals("3 Destination c3", "", c3.getDestinationName());
    Assert.assertEquals("3 Destination c4", "", c4.getDestinationName());
    Assert.assertEquals("3 Destination c5", "Nashua", c5.getDestinationName());
    Assert.assertEquals("3 Destination c6", "", c6.getDestinationName());
    Assert.assertEquals("3 Destination c7", "", c7.getDestinationName());
    Assert.assertEquals("3 Destination c8", "", c8.getDestinationName());
    Assert.assertEquals("3 Destination c9", "", c9.getDestinationName());
    Assert.assertEquals("3 Destination c10", "Nashua", c10.getDestinationName());
    // check car locations
    Assert.assertEquals("Location c1", "Foxboro", c1.getLocationName());
    Assert.assertEquals("Location c2", "Foxboro", c2.getLocationName());
    Assert.assertEquals("Location c3", "Nashua", c3.getLocationName());
    Assert.assertEquals("Location c4", "Acton", c4.getLocationName());
    Assert.assertEquals("Location c5", "Foxboro", c5.getLocationName());
    Assert.assertEquals("Location c6", "Nashua", c6.getLocationName());
    Assert.assertEquals("Location c7", "Acton", c7.getLocationName());
    Assert.assertEquals("Location c8", "Nashua", c8.getLocationName());
    Assert.assertEquals("Location c9", "Foxboro", c9.getLocationName());
    Assert.assertEquals("Location c10", "Foxboro", c10.getLocationName());
    // now set caboose destinations that aren't the terminal
    Assert.assertEquals("set destination c1", Track.OKAY, c1.setDestination(l2, l2s1));
    Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l3, l3s1));
    // train requires a caboose, should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 4", t1.isBuilt());
    // Set caboose destination to be the terminal
    Assert.assertEquals("set caboose destination", Track.OKAY, c2.setDestination(l1, l1s2));
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 5", t1.isBuilt());
    Assert.assertTrue("train reset 5", t1.reset());
    // set the cabooses to train FF
    c1.setTrain(t2);
    c2.setTrain(t2);
    // build should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 6", t1.isBuilt());
    // set caboose to train TT
    c1.setTrain(t1);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 7", t1.isBuilt());
    // check car destinations
    Assert.assertEquals("4 Destination c1", "Foxboro", c1.getDestinationName());
    Assert.assertEquals("4 Destination c2", "", c2.getDestinationName());
    Assert.assertEquals("4 Destination c3", "Acton", c3.getDestinationName());
    Assert.assertEquals("4 Destination c4", "Nashua", c4.getDestinationName());
    Assert.assertEquals("4 Destination c5", "Nashua", c5.getDestinationName());
    Assert.assertEquals("4 Destination c6", "Foxboro", c6.getDestinationName());
    Assert.assertEquals("4 Destination c7", "Foxboro", c7.getDestinationName());
    Assert.assertEquals("4 Destination c8", "Foxboro", c8.getDestinationName());
    Assert.assertEquals("4 Destination c9", "", c9.getDestinationName());
    Assert.assertEquals("4 Destination c10", "Acton", c10.getDestinationName());
    // add an engine
    t1.setNumberEngines("2");
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 8", t1.isBuilt());
    Assert.assertEquals("5 Destination e1", "Foxboro", e1.getDestinationName());
    Assert.assertEquals("5 Destination e2", "Foxboro", e2.getDestinationName());
    // assign lead engine to train TT
    e1.setTrain(t2);
    // should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 9", t1.isBuilt());
    // assign one of the consist engine to train TT
    e1.setTrain(t1);
    // shouldn't pay attention to the other engine
    e2.setTrain(t2);
    // should build
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 10", t1.isBuilt());
    t1.reset();
    // both engines should release
    Assert.assertEquals("6 Destination e1", "", e1.getDestinationName());
    Assert.assertEquals("6 Train e1", "", e1.getTrainName());
    Assert.assertEquals("6 Destination e2", "", e2.getDestinationName());
    Assert.assertEquals("6 Train e2", "", e2.getTrainName());
    // now try setting engine destination that isn't the terminal
    Assert.assertEquals("set destination e1", Track.OKAY, e1.setDestination(l2, l2s1));
    // should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 11", t1.isBuilt());
    e1.setDestination(l1, l1s2);
    // program should ignore
    e2.setDestination(l2, l2s1);
    // should build
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 12", t1.isBuilt());
    // set lead engine's track to null
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, null));
    // should not build
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train will not build engine track is null", t1.isBuilt());
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    // should now build
    t1.reset();
    new TrainBuilder().build(t1);
    // move and terminate the train
    // to Acton
    t1.move();
    // to Nashua
    t1.move();
    // to Acton
    t1.move();
    // to Foxboro
    t1.move();
    // terminate
    t1.move();
    // check engine final locations
    Assert.assertEquals("Location e1", "Foxboro", e1.getLocationName());
    Assert.assertEquals("Location e2", "Foxboro", e2.getLocationName());
    // move c7 & c8 to Foxboro to help test kernels
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(l1, l1s1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(l1, l1s1));
    // now test kernels
    Kernel k1 = cmanager.newKernel("group of cars");
    // lead car
    c8.setKernel(k1);
    c7.setKernel(k1);
    // program should ignore
    c7.setTrain(t2);
    c3.setLocation(l1, l1s1);
    c3.setKernel(k1);
    // program should ignore (produces debug warning)
    c3.setDestination(l1, l1s1);
    // should build
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 12", t1.isBuilt());
    // Confirm partial build
    Assert.assertEquals("Train built", Train.CODE_PARTIAL_BUILT, t1.getStatusCode());
    Assert.assertEquals("12 Location c3", "Foxboro", c3.getLocationName());
    Assert.assertEquals("12 Location c7", "Foxboro", c7.getLocationName());
    Assert.assertEquals("12 Location c8", "Foxboro", c8.getLocationName());
    Assert.assertEquals("12 Destination c3", "Nashua", c3.getDestinationName());
    Assert.assertEquals("12 Destination c7", "Nashua", c7.getDestinationName());
    Assert.assertEquals("12 Destination c8", "Nashua", c8.getDestinationName());
    // move and terminate the train
    // to Acton
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // to Nashua
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // to Acton
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // to Foxboro
    t1.move();
    Assert.assertEquals("Train en route", Train.CODE_TRAIN_EN_ROUTE, t1.getStatusCode());
    // terminate
    t1.move();
    Assert.assertEquals("Train Terminated", Train.CODE_TERMINATED, t1.getStatusCode());
    Assert.assertEquals("13 Location c3", "Nashua", c3.getLocationName());
    Assert.assertEquals("13 Location c7", "Nashua", c7.getLocationName());
    Assert.assertEquals("13 Location c8", "Nashua", c8.getLocationName());
    Assert.assertEquals("13 Destination c3", "", c3.getDestinationName());
    Assert.assertEquals("13 Destination c7", "", c7.getDestinationName());
    Assert.assertEquals("13 Destination c8", "", c8.getDestinationName());
    Assert.assertEquals("13 Train c3", "", c3.getTrainName());
    Assert.assertEquals("13 Train c7", "", c7.getTrainName());
    Assert.assertEquals("13 Train c8", "", c8.getTrainName());
    // now test car with FRED
    c1.setCaboose(false);
    c2.setCaboose(false);
    c1.setFred(true);
    c2.setFred(true);
    // change the type, now Boxcar with FRED
    c1.setTypeName("Boxcar");
    c2.setTypeName("Boxcar");
    c2.setTrain(null);
    // train requires a caboose, there are none, should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 14", t1.isBuilt());
    // change requirement to car with FRED
    t1.setRequirements(Train.FRED);
    // train requires a car with FRED, should pass
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 15", t1.isBuilt());
    // release cars
    Assert.assertTrue("train reset 15", t1.reset());
    // now set FRED destinations that aren't the terminal
    Assert.assertEquals("set destination c1", Track.OKAY, c1.setDestination(l2, l2s1));
    Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l3, l3s1));
    // train requires a car with FRED, should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 16", t1.isBuilt());
    // Set FRED destination to be the terminal
    Assert.assertEquals("set destination c2", Track.OKAY, c2.setDestination(l1, l1s2));
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 17", t1.isBuilt());
    Assert.assertTrue("train reset 17", t1.reset());
    // set the cars with FRED to train FF
    c1.setTrain(t2);
    c2.setTrain(t2);
    // build should fail
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("train built 18", t1.isBuilt());
    // set car with FRED to train TT
    c2.setTrain(t1);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("train built 19", t1.isBuilt());
    // test car out of service
    c2.setOutOfService(true);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("required car is out of service", t1.isBuilt());
    // test location unknown
    c2.setOutOfService(false);
    c2.setLocationUnknown(true);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("required car location is unknown", t1.isBuilt());
    c2.setLocationUnknown(false);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("need car is available", t1.isBuilt());
    c2.setWait(1);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("required car will wait for next train", t1.isBuilt());
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("next train!", t1.isBuilt());
    Assert.assertEquals("CP 4000 destination", "Nashua", c4.getDestinationName());
    // test train and location direction controls
    // place led car of kernel in Action Siding 1
    c8.setLocation(l2, l2s1);
    // train is north bound
    l2.setTrainDirections(Location.EAST + Location.SOUTH + Location.WEST);
    t1.reset();
    new TrainBuilder().build(t1);
    // build should fail, cars c3 and c7 which is part of c8 kernel are on the wrong track
    Assert.assertFalse("Train direction test", t1.isBuilt());
    // place c3 Action Siding 1
    c3.setLocation(l2, l2s1);
    // place c7 Action Siding 1
    c7.setLocation(l2, l2s1);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("Train direction test", t1.isBuilt());
    Assert.assertEquals("CP 1000 destination is now Nashua", "Nashua", c10.getDestinationName());
    Assert.assertEquals("CP 30 at Acton, not serviced", null, c3.getTrain());
    Assert.assertEquals("CP 700 at Acton, not serviced", null, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton, not serviced", null, c8.getTrain());
    // restore Acton
    // train is north bound
    l2.setTrainDirections(Location.NORTH);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertEquals("CP 1000 destination is now", "Acton", c10.getDestinationName());
    Assert.assertEquals("CP 30 at Acton", t1, c3.getTrain());
    Assert.assertEquals("CP 700 at Acton", t1, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton", t1, c8.getTrain());
    // restrict train direction at the track level
    l2s2.setTrainDirections(Track.EAST + Track.SOUTH + Track.WEST);
    // take one car out of kernel
    c3.setKernel(null);
    // place car in Action Siding 1
    c3.setLocation(l2, l2s1);
    // place lead car in Action Yard
    c8.setLocation(l2, l2s2);
    // place c7 in Action Yard
    c7.setLocation(l2, l2s2);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertEquals("CP 1000 destination track", "Acton Siding 1", c1.getDestinationTrackName());
    Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
    Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
    Assert.assertEquals("CP 30 destination track", "Nashua Yard 2", c3.getDestinationTrackName());
    Assert.assertEquals("CP 4000 at Foxboro Siding", t1, c4.getTrain());
    Assert.assertEquals("CP 4000 destination", "Foxboro", c4.getDestinationName());
    Assert.assertEquals("CP 4000 destination track", "Foxboro Yard", c4.getDestinationTrackName());
    Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
    Assert.assertEquals("CP 700 at Acton, not serviced, part of kernel CP 8000", null, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton, Acton Siding 2 not serviced", null, c8.getTrain());
    // test train length restrictions
    // only enough for the two engines, train needs a car with FRED
    rl1.setMaxTrainLength(155);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("Train length test, can't service car with FRED", t1.isBuilt());
    // build failed after engines were assigned to train 1
    Assert.assertEquals("Engine assignment ignores train length restrictions", t1, e1.getTrain());
    Assert.assertEquals("Engine assignment ignores train length restrictions", t1, e2.getTrain());
    Assert.assertEquals("Engine destination ignores train length restrictions", "Foxboro", e1.getDestinationName());
    Assert.assertEquals("Engine destination ignores train length restrictions", "Foxboro", e2.getDestinationName());
    Assert.assertEquals("Check CP30 engine length", "56", e1.getLength());
    Assert.assertEquals("Check CP 200 length", "32", c2.getLength());
    // enough for the two engines and a car with FRED 56 + 56 + 32 + 12(couplers) = 156
    rl1.setMaxTrainLength(156);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("Train length test, just enough length for engines and car with FRED", t1.isBuilt());
    Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
    Assert.assertEquals("CP 200 destination track", "Foxboro Siding", c2.getDestinationTrackName());
    Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
    Assert.assertEquals("CP 30 destination track", "Nashua Yard 1", c3.getDestinationTrackName());
    Assert.assertEquals("CP 4000 at Foxboro Siding", t1, c4.getTrain());
    Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
    Assert.assertEquals("CP 700 at Acton, not serviced, part of kernel CP 8000", null, c7.getTrain());
    Assert.assertEquals("CP 8000 at Acton, Acton Siding 2 not serviced", null, c8.getTrain());
    Assert.assertEquals("CP 1000 not part of train", null, c10.getTrain());
    // Increase the train length from the departure location
    rl1.setMaxTrainLength(1000);
    // restrict train length from Acton
    rl2.setMaxTrainLength(156);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("Train length test, just enough length for engines and car with FRED", t1.isBuilt());
    Assert.assertEquals("CP 200 at Foxboro Siding", t1, c2.getTrain());
    Assert.assertEquals("CP 200 destination track", "Foxboro Yard", c2.getDestinationTrackName());
    Assert.assertEquals("CP 30 at Acton Siding 1", t1, c3.getTrain());
    Assert.assertEquals("CP 30 destination track", "Foxboro Yard", c3.getDestinationTrackName());
    Assert.assertEquals("CP 4000 at Foxboro Yard", t1, c4.getTrain());
    Assert.assertEquals("CP 4000 destination track", "Foxboro Siding", c4.getDestinationTrackName());
    Assert.assertEquals("CP 60 destination track", "", c6.getDestinationTrackName());
    Assert.assertEquals("CP 1000 part of train", t1, c10.getTrain());
    Assert.assertEquals("CP 1000 destination track", "Acton Siding 1", c10.getDestinationTrackName());
    // test setting car's destination to Foxboro Siding
    c2.setDestination(l1, l1s1);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("car with FRED has destination", t1.isBuilt());
    t1.reset();
    // again, but now change car type serviced by Foxboro Yard
    c2.setDestination(l1, l1s1);
    l1s1.deleteTypeName("Boxcar");
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("car with FRED has destination that won't accept it", t1.isBuilt());
    l1s1.addTypeName("Boxcar");
    // destination Action Siding 2
    c6.setDestination(l2, l2s2);
    // don't allow Boxcar to drop
    l2s2.deleteTypeName("Boxcar");
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertTrue("car with FRED has destination that will now accept it", t1.isBuilt());
    Assert.assertEquals("CP 60 can't be delivered", null, c6.getTrain());
    c2.setLocation(l1, null);
    t1.reset();
    new TrainBuilder().build(t1);
    Assert.assertFalse("need car doesn't have a track assignment", t1.isBuilt());
// end testSidingsYards
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Kernel(jmri.jmrit.operations.rollingstock.cars.Kernel) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 44 with RouteLocation

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

the class TrainBuilderTest method testStagingtoStaging2.

// testStagingtoStaging2 tests the build procedure
// through the train's build method.
// test train staging to staging
public void testStagingtoStaging2() {
    // register the car colors used
    Assert.assertEquals("Bob Test CarColor Silver false", false, cc.containsName("Silver"));
    Assert.assertEquals("Bob Test CarColor Black false", false, cc.containsName("Black"));
    Assert.assertEquals("Bob Test CarColor Red false", false, cc.containsName("Red"));
    cc.addName("Silver");
    Assert.assertEquals("Bob Test CarColor Silver true", true, cc.containsName("Silver"));
    cc.addName("Black");
    Assert.assertEquals("Bob Test CarColor Black true", true, cc.containsName("Black"));
    cc.addName("Red");
    Assert.assertEquals("Bob Test CarColor Red true", true, cc.containsName("Red"));
    // register the car lengths used
    Assert.assertEquals("Bob Test CarLength 32 false", false, cl.containsName("32"));
    Assert.assertEquals("Bob Test CarLength 38 false", false, cl.containsName("38"));
    Assert.assertEquals("Bob Test CarLength 40 false", false, cl.containsName("40"));
    cl.addName("32");
    Assert.assertEquals("Bob Test CarLength 32 true", true, cl.containsName("32"));
    cl.addName("38");
    Assert.assertEquals("Bob Test CarLength 38 true", true, cl.containsName("38"));
    cl.addName("40");
    Assert.assertEquals("Bob Test CarLength 40 true", true, cl.containsName("40"));
    // register the car owners used
    Assert.assertEquals("Bob Test CarOwner Owner1 false", false, co.containsName("Owner1"));
    Assert.assertEquals("Bob Test CarOwner Owner2 false", false, co.containsName("Owner2"));
    Assert.assertEquals("Bob Test CarOwner Owner3 false", false, co.containsName("Owner3"));
    co.addName("Owner1");
    Assert.assertEquals("Bob Test CarOwner Owner1 true", true, co.containsName("Owner1"));
    co.addName("Owner2");
    Assert.assertEquals("Bob Test CarOwner Owner2 true", true, co.containsName("Owner2"));
    co.addName("Owner3");
    Assert.assertEquals("Bob Test CarOwner Owner3 true", true, co.containsName("Owner3"));
    // register the car roads used
    Assert.assertEquals("Bob Test CarRoads CP false", false, cr.containsName("CP"));
    Assert.assertEquals("Bob Test CarRoads Road2 false", false, cr.containsName("Road2"));
    Assert.assertEquals("Bob Test CarRoads Road3 false", false, cr.containsName("Road3"));
    cr.addName("CP");
    Assert.assertEquals("Bob Test CarRoads CP true", true, cr.containsName("CP"));
    cr.addName("Road2");
    Assert.assertEquals("Bob Test CarRoads Road2 true", true, cr.containsName("Road2"));
    cr.addName("Road3");
    Assert.assertEquals("Bob Test CarRoads Road3 true", true, cr.containsName("Road3"));
    // register the car types used
    Assert.assertEquals("Bob Test CarType Caboose false", false, ct.containsName("Caboose"));
    Assert.assertEquals("Bob Test CarType Tanker false", false, ct.containsName("Tanker"));
    Assert.assertEquals("Bob Test CarType Boxcar false", false, ct.containsName("Boxcar"));
    ct.addName("Caboose");
    Assert.assertEquals("Bob Test CarType Caboose true", true, ct.containsName("Caboose"));
    ct.addName("Tanker");
    Assert.assertEquals("Bob Test CarType Tanker true", true, ct.containsName("Tanker"));
    ct.addName("Boxcar");
    Assert.assertEquals("Bob Test CarType Boxcar true", true, ct.containsName("Boxcar"));
    // register the car loads used
    cld.addType("Boxcar");
    Assert.assertEquals("Bob Test CarLoad Boxcar Flour false", false, cld.containsName("Boxcar", "Flour"));
    Assert.assertEquals("Bob Test CarLoad Boxcar Bags false", false, cld.containsName("Boxcar", "Bags"));
    cld.addName("Boxcar", "Flour");
    Assert.assertEquals("Bob Test CarLoad Boxcar Flour true", true, cld.containsName("Boxcar", "Flour"));
    cld.addName("Boxcar", "Bags");
    Assert.assertEquals("Bob Test CarLoad Boxcar Bags true", true, cld.containsName("Boxcar", "Bags"));
    // register the engine models used
    Assert.assertEquals("Bob Test EngineModel GP40 false", false, em.containsName("GP40"));
    Assert.assertEquals("Bob Test EngineModel GP30 false", false, em.containsName("GP30"));
    em.addName("GP40");
    Assert.assertEquals("Bob Test EngineModel GP40 true", true, em.containsName("GP40"));
    em.addName("GP30");
    Assert.assertEquals("Bob Test EngineModel GP30 true", true, em.containsName("GP30"));
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("Westend");
    loc1.setTrainDirections(Location.WEST + Location.EAST);
    Assert.assertEquals("Bob Test Location Westend Name", "Westend", loc1.getName());
    Assert.assertEquals("Bob Test Location Westend Directions", 3, loc1.getTrainDirections());
    Assert.assertEquals("Bob Test Location Westend Type Diesel", true, loc1.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Location Westend Type Boxcar", true, loc1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Location Westend Type Caboose", true, loc1.acceptsTypeName("Caboose"));
    Location loc2;
    loc2 = lmanager.newLocation("Midtown");
    loc2.setTrainDirections(Location.WEST + Location.EAST);
    Assert.assertEquals("Bob Test Location Midtown Name", "Midtown", loc2.getName());
    Assert.assertEquals("Bob Test Location Midtown Directions", 3, loc2.getTrainDirections());
    Assert.assertEquals("Bob Test Location Midtown Type Diesel", true, loc2.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Location Midtown Type Boxcar", true, loc2.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Location Midtown Type Caboose", true, loc2.acceptsTypeName("Caboose"));
    Location loc3;
    loc3 = lmanager.newLocation("Eastend");
    loc3.setTrainDirections(Location.WEST + Location.EAST);
    Assert.assertEquals("Bob Test Location Eastend Name", "Eastend", loc3.getName());
    Assert.assertEquals("Bob Test Location Eastend Directions", 3, loc3.getTrainDirections());
    Assert.assertEquals("Bob Test Location Eastend Type Diesel", true, loc3.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Location Eastend Type Boxcar", true, loc3.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Location Eastend Type Caboose", true, loc3.acceptsTypeName("Caboose"));
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westend Staging 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(500);
    Assert.assertEquals("Bob Test Track Westend Staging 1 Name", "Westend Staging 1", loc1trk1.getName());
    Assert.assertEquals("Bob Test Track Westend Staging 1 Directions", 3, loc1trk1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Westend Staging 1 Length", 500, loc1trk1.getLength());
    Assert.assertEquals("Bob Test Track Westend Staging 1 Type Diesel", true, loc1trk1.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Track Westend Staging 1 Type Boxcar", true, loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Track Westend Staging 1 Type Caboose", true, loc1trk1.acceptsTypeName("Caboose"));
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Midtown Inbound from West", Track.YARD);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown West Inbound Name", "Midtown Inbound from West", loc2trk1.getName());
    Assert.assertEquals("Bob Test Track Midtown West Inbound Directions", 3, loc2trk1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown West Inbound Length", 500, loc2trk1.getLength());
    Track loc2trk2;
    loc2trk2 = loc2.addTrack("Midtown Inbound from East", Track.YARD);
    loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk2.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown East Inbound Name", "Midtown Inbound from East", loc2trk2.getName());
    Assert.assertEquals("Bob Test Track Midtown East Inbound Directions", 3, loc2trk2.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Inbound Length", 500, loc2trk2.getLength());
    Track loc2trk3;
    loc2trk3 = loc2.addTrack("Midtown Outbound to West", Track.YARD);
    loc2trk3.setTrainDirections(Track.WEST);
    loc2trk3.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown West Outbound Name", "Midtown Outbound to West", loc2trk3.getName());
    Assert.assertEquals("Bob Test Track Midtown West Outbound Directions", 2, loc2trk3.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown West Outbound Length", 500, loc2trk3.getLength());
    Track loc2trk4;
    loc2trk4 = loc2.addTrack("Midtown Outbound to East", Track.YARD);
    loc2trk4.setTrainDirections(Track.EAST);
    loc2trk4.setLength(500);
    Assert.assertEquals("Bob Test Track Midtown East Outbound Name", "Midtown Outbound to East", loc2trk4.getName());
    Assert.assertEquals("Bob Test Track Midtown East Outbound Directions", 1, loc2trk4.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Outbound Length", 500, loc2trk4.getLength());
    Track loc2trkc1;
    loc2trkc1 = loc2.addTrack("Midtown Caboose to East", Track.YARD);
    loc2trkc1.setTrainDirections(Track.EAST);
    loc2trkc1.setLength(100);
    Assert.assertEquals("Bob Test Track Midtown East Caboose Name", "Midtown Caboose to East", loc2trkc1.getName());
    Assert.assertEquals("Bob Test Track Midtown East Caboose Directions", 1, loc2trkc1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Caboose Length", 100, loc2trkc1.getLength());
    Track loc2trkc2;
    loc2trkc2 = loc2.addTrack("Midtown Caboose to West", Track.YARD);
    loc2trkc2.setTrainDirections(Track.WEST);
    loc2trkc2.setLength(100);
    Assert.assertEquals("Bob Test Track Midtown West Caboose Name", "Midtown Caboose to West", loc2trkc2.getName());
    Assert.assertEquals("Bob Test Track Midtown West Caboose Directions", 2, loc2trkc2.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown west Caboose Length", 100, loc2trkc2.getLength());
    Track loc2trke1;
    loc2trke1 = loc2.addTrack("Midtown Engine to East", Track.YARD);
    loc2trke1.setTrainDirections(Track.EAST);
    loc2trke1.setLength(200);
    Assert.assertEquals("Bob Test Track Midtown East Engine Name", "Midtown Engine to East", loc2trke1.getName());
    Assert.assertEquals("Bob Test Track Midtown East Engine Directions", 1, loc2trke1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown East Engine Length", 200, loc2trke1.getLength());
    Track loc2trke2;
    loc2trke2 = loc2.addTrack("Midtown Engine to West", Track.YARD);
    loc2trke2.setTrainDirections(Track.WEST);
    loc2trke2.setLength(200);
    Assert.assertEquals("Bob Test Track Midtown West Engine Name", "Midtown Engine to West", loc2trke2.getName());
    Assert.assertEquals("Bob Test Track Midtown West Engine Directions", 2, loc2trke2.getTrainDirections());
    Assert.assertEquals("Bob Test Track Midtown west Engine Length", 200, loc2trke2.getLength());
    Track loc3trk1;
    loc3trk1 = loc3.addTrack("Eastend Staging 1", Track.YARD);
    loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc3trk1.setLength(500);
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Name", "Eastend Staging 1", loc3trk1.getName());
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Directions", 3, loc3trk1.getTrainDirections());
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Length", 500, loc3trk1.getLength());
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Type Diesel", true, loc3trk1.acceptsTypeName("Diesel"));
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Type Boxcar", true, loc3trk1.acceptsTypeName("Boxcar"));
    Assert.assertEquals("Bob Test Track Eastend Staging 1 Type Caboose", true, loc3trk1.acceptsTypeName("Caboose"));
    Assert.assertEquals("Bob Test Location Westend Length", 500, loc1.getLength());
    Assert.assertEquals("Bob Test Location Midtown Length", 2600, loc2.getLength());
    Assert.assertEquals("Bob Test Location Eastend Length", 500, loc3.getLength());
    // Create engines used
    Engine e1;
    e1 = emanager.newEngine("CP", "5501");
    e1.setModel("GP30");
    e1.setMoves(5);
    Assert.assertEquals("Bob Test Engine CP1801 Type", "Diesel", e1.getTypeName());
    Assert.assertEquals("Bob Test Engine CP1801 Length", "56", e1.getLength());
    Assert.assertEquals("Bob Test Engine CP1801 Hp", "2250", e1.getHp());
    // Test that first "Diesel" is an acceptable type at all locations and tracks
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 1s1", "okay", e1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s1", "okay", e1.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s2", "okay", e1.setLocation(loc2, loc2trk2));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s3", "okay", e1.setLocation(loc2, loc2trk3));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s4", "okay", e1.setLocation(loc2, loc2trk4));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 3s1", "okay", e1.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Bob Test Engine CP1801 SetLocation 2s4 for real", "okay", e1.setLocation(loc2, loc2trke1));
    Engine e2;
    e2 = emanager.newEngine("CP", "5888");
    e2.setModel("GP40");
    Assert.assertEquals("Bob Test Engine CP5801 Type", "Diesel", e2.getTypeName());
    Assert.assertEquals("Bob Test Engine CP5801 Length", "59", e2.getLength());
    Assert.assertEquals("Bob Test Engine CP5801 Hp", "3000", e2.getHp());
    Assert.assertEquals("Bob Test Engine CP5801 SetLocation 2s4", "okay", e2.setLocation(loc2, loc2trke2));
    // Create cars used
    Car b1;
    b1 = cmanager.newCar("CP", "81234567");
    b1.setTypeName("Boxcar");
    b1.setLength("40");
    b1.setLoadName("L");
    b1.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234567 Length", "40", b1.getLength());
    Assert.assertEquals("Bob Test Car CP81234567 Load", "L", b1.getLoadName());
    // Test that first "Boxcar" is an acceptable type at all locations and tracks
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 1s1", "okay", b1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s1", "okay", b1.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s2", "okay", b1.setLocation(loc2, loc2trk2));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s3", "okay", b1.setLocation(loc2, loc2trk3));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s4", "okay", b1.setLocation(loc2, loc2trk4));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 3s1", "okay", b1.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Bob Test Test Car CP81234567 SetLocation 2s4 for real", "okay", b1.setLocation(loc2, loc2trk4));
    Car b2;
    b2 = cmanager.newCar("CP", "81234568");
    b2.setTypeName("Boxcar");
    b2.setLength("40");
    b2.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234568 Length", "40", b2.getLength());
    Assert.assertEquals("Bob Test Car CP81234568 Load", "E", b2.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP81234568 SetLocation 2s4", "okay", b2.setLocation(loc2, loc2trk4));
    Car b3;
    b3 = cmanager.newCar("CP", "81234569");
    b3.setTypeName("Boxcar");
    b3.setLength("40");
    b3.setLoadName("Flour");
    b3.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234569 Length", "40", b3.getLength());
    Assert.assertEquals("Bob Test Car CP81234569 Load", "Flour", b3.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP81234569 SetLocation 2s4", "okay", b3.setLocation(loc2, loc2trk4));
    Car b4;
    b4 = cmanager.newCar("CP", "81234566");
    b4.setTypeName("Boxcar");
    b4.setLength("40");
    b4.setLoadName("Bags");
    b4.setMoves(5);
    Assert.assertEquals("Bob Test Car CP81234566 Length", "40", b4.getLength());
    Assert.assertEquals("Bob Test Car CP81234566 Load", "Bags", b4.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP81234566 SetLocation 2s4", "okay", b4.setLocation(loc2, loc2trk4));
    Car b5;
    b5 = cmanager.newCar("CP", "71234567");
    b5.setTypeName("Boxcar");
    b5.setLength("40");
    // b5.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234567 Length", "40", b5.getLength());
    Assert.assertEquals("Bob Test Car CP71234567 Load", "E", b5.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234567 SetLocation 2s4", "okay", b5.setLocation(loc2, loc2trk3));
    Car b6;
    b6 = cmanager.newCar("CP", "71234568");
    b6.setTypeName("Boxcar");
    b6.setLength("40");
    // b6.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234568 Length", "40", b6.getLength());
    Assert.assertEquals("Bob Test Car CP71234568 Load", "E", b6.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234568 SetLocation 2s4", "okay", b6.setLocation(loc2, loc2trk3));
    Car b7;
    b7 = cmanager.newCar("CP", "71234569");
    b7.setTypeName("Boxcar");
    b7.setLength("40");
    // b7.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234569 Length", "40", b7.getLength());
    Assert.assertEquals("Bob Test Car CP71234569 Load", "E", b7.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234569 SetLocation 2s4", "okay", b7.setLocation(loc2, loc2trk3));
    Car b8;
    b8 = cmanager.newCar("CP", "71234566");
    b8.setTypeName("Boxcar");
    b8.setLength("40");
    // b2.setLoad("E");
    Assert.assertEquals("Bob Test Car CP71234566 Length", "40", b8.getLength());
    Assert.assertEquals("Bob Test Car CP71234566 Load", "E", b8.getLoadName());
    Assert.assertEquals("Bob Test Test Car CP71234566 SetLocation 2s4", "okay", b8.setLocation(loc2, loc2trk3));
    // Create cars used
    Car c1;
    c1 = cmanager.newCar("CP", "12345678");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setCaboose(true);
    c1.setMoves(5);
    Assert.assertEquals("Bob Test Caboose CP12345678 Length", "32", c1.getLength());
    Assert.assertEquals("Bob Test Caboose CP12345678 Load", "E", c1.getLoadName());
    // Test that first "Caboose" is an acceptable type at all locations and tracks
    Assert.assertEquals("Bob Test Test Caboose CP12345678 SetLocation 1s1", "okay", c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Bob Test Test Caboose CP12345678 SetLocation 3s1", "okay", c1.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Bob Test Test Caboose CP12345678 SetLocation 2s5 for real", "okay", c1.setLocation(loc2, loc2trkc1));
    Car c2;
    c2 = cmanager.newCar("CP", "12345679");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setCaboose(true);
    Assert.assertEquals("Bob Test Caboose CP12345679 Length", "32", c2.getLength());
    Assert.assertEquals("Bob Test Caboose CP12345679 Load", "E", c2.getLoadName());
    Assert.assertEquals("Bob Test Test Caboose CP12345679 SetLocation 2s5 for real", "okay", c2.setLocation(loc2, loc2trkc2));
    Assert.assertEquals("Bob Test Location Westend Used Length", 0, loc1.getUsedLength());
    // 56+4 + 59+4 + 2*(4*(40+4) + 32+4) = 123 + 2*(176 + 36) = 547
    Assert.assertEquals("Bob Test Location Midtown Used Length", 547, loc2.getUsedLength());
    Assert.assertEquals("Bob Test Location Eastend Used Length", 0, loc3.getUsedLength());
    // Create routes used
    Route rte1;
    rte1 = rmanager.newRoute("Midtown to Eastend Through");
    Assert.assertEquals("Bob Test Route rte1 Name", "Midtown to Eastend Through", rte1.getName());
    RouteLocation rte1rln1;
    rte1rln1 = rte1.addLocation(loc2);
    rte1rln1.setTrainDirection(RouteLocation.EAST);
    // set the train icon coordinates
    rte1rln1.setTrainIconX(175);
    rte1rln1.setTrainIconY(25);
    Assert.assertEquals("Bob Test Route Location rte1rln1 Name", "Midtown", rte1rln1.getName());
    Assert.assertEquals("Bob Test Route Location rte1rln1 Seq", 1, rte1rln1.getSequenceId());
    RouteLocation rte1rln2;
    rte1rln2 = rte1.addLocation(loc3);
    rte1rln2.setTrainDirection(RouteLocation.EAST);
    // set the train icon coordinates
    rte1rln2.setTrainIconX(25);
    rte1rln2.setTrainIconY(50);
    Assert.assertEquals("Bob Test Route Location rte1rln2 Name", "Eastend", rte1rln2.getName());
    Assert.assertEquals("Bob Test Route Location rte1rln2 Seq", 2, rte1rln2.getSequenceId());
    Route rte2;
    rte2 = rmanager.newRoute("Midtown to Westend Through");
    Assert.assertEquals("Bob Test Route rte2 Name", "Midtown to Westend Through", rte2.getName());
    RouteLocation rte2rln1;
    rte2rln1 = rte2.addLocation(loc2);
    rte2rln1.setTrainDirection(RouteLocation.WEST);
    // set the train icon coordinates
    rte2rln1.setTrainIconX(75);
    rte2rln1.setTrainIconY(50);
    Assert.assertEquals("Bob Test Route Location rte2rln1 Name", "Midtown", rte2rln1.getName());
    Assert.assertEquals("Bob Test Route Location rte2rln1 Seq", 1, rte2rln1.getSequenceId());
    RouteLocation rte2rln2;
    rte2rln2 = rte2.addLocation(loc1);
    rte2rln2.setTrainDirection(RouteLocation.WEST);
    // set the train icon coordinates
    rte2rln2.setTrainIconX(125);
    rte2rln2.setTrainIconY(50);
    Assert.assertEquals("Bob Test Route Location rte2rln2 Name", "Westend", rte2rln2.getName());
    Assert.assertEquals("Bob Test Route Location rte2rln2 Seq", 2, rte2rln2.getSequenceId());
    // Create trains used
    Train train1;
    train1 = tmanager.newTrain("TestStagingtoStaging2");
    train1.setRoute(rte1);
    train1.setNumberEngines("1");
    train1.setRequirements(Train.CABOOSE);
    // train1.addTypeName("Diesel");
    // train1.addTypeName("Boxcar");
    // train1.addTypeName("Caboose");
    Assert.assertEquals("Bob Test Train train1 Name", "TestStagingtoStaging2", train1.getName());
    Assert.assertEquals("Bob Test Train train1 Departs Name", "Midtown", train1.getTrainDepartsName());
    Assert.assertEquals("Bob Test Train train1 Terminates Name", "Eastend", train1.getTrainTerminatesName());
    Train train2;
    train2 = tmanager.newTrain("MWT");
    train2.setRoute(rte2);
    train2.setNumberEngines("1");
    train2.setRequirements(Train.CABOOSE);
    // train2.addTypeName("Diesel");
    // train2.addTypeName("Boxcar");
    // train2.addTypeName("Caboose");
    Assert.assertEquals("Bob Test Train train2 Name", "MWT", train2.getName());
    Assert.assertEquals("Bob Test Train train2 Departs Name", "Midtown", train2.getTrainDepartsName());
    Assert.assertEquals("Bob Test Train train2 Terminates Name", "Westend", train2.getTrainTerminatesName());
    // Build trains
    train1.reset();
    new TrainBuilder().build(train1);
    train2.reset();
    new TrainBuilder().build(train2);
    Assert.assertTrue("Bob test train1 built", train1.isBuilt());
    Assert.assertTrue("Bob test train2 built", train2.isBuilt());
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 45 with RouteLocation

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

the class TrainBuilderTest method testAutoEnginesTwoEngines.

public void testAutoEnginesTwoEngines() {
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("TestAutoEnginesTwoEngines");
    train.setNumberEngines(Train.AUTO);
    Route route = rmanager.newRoute("AutoEngineTest");
    train.setRoute(route);
    Location A = lmanager.newLocation("A");
    Location B = lmanager.newLocation("B");
    Location C = lmanager.newLocation("C");
    Track At = A.addTrack("track", Track.SPUR);
    Track Bt = B.addTrack("track", Track.SPUR);
    Track Ct = C.addTrack("track", Track.SPUR);
    At.setLength(300);
    Bt.setLength(300);
    Ct.setLength(300);
    RouteLocation rA = route.addLocation(A);
    RouteLocation rB = route.addLocation(B);
    RouteLocation rC = route.addLocation(C);
    rA.setMaxCarMoves(5);
    rB.setMaxCarMoves(5);
    rC.setMaxCarMoves(5);
    Engine e1 = emanager.newEngine("E", "1");
    e1.setModel("GP40");
    Engine e2 = emanager.newEngine("E", "2");
    e2.setModel("GP40");
    Engine e3 = emanager.newEngine("E", "3");
    e3.setModel("GP40");
    Engine e4 = emanager.newEngine("E", "4");
    e4.setModel("GP40");
    e1.setLocation(A, At);
    e2.setLocation(A, At);
    e3.setLocation(A, At);
    e4.setLocation(A, At);
    // change requirements
    rA.setMaxCarMoves(12);
    rB.setMaxCarMoves(12);
    rC.setMaxCarMoves(12);
    train.reset();
    new TrainBuilder().build(train);
    Assert.assertFalse("Train should not build, only single engines", train.isBuilt());
    Consist c = emanager.newConsist("c");
    e1.setConsist(c);
    e2.setConsist(c);
    // train should require two engines
    train.reset();
    new TrainBuilder().build(train);
    Assert.assertTrue("Train should build", train.isBuilt());
    Assert.assertEquals("e1 should be assigned to train", train, e1.getTrain());
    Assert.assertEquals("e2 should be assigned to train", train, e2.getTrain());
}
Also used : Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

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