Search in sources :

Example 6 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class OperationsCarRouterTest method testRoutingWithSchedulesMatchMode.

/*
     * Using the setup from the previous tests, use trains and schedules to move
     * cars. This test creates 1 schedule in match mode with multiple items.
     * Test uses car loads to activate schedule.
     */
public void testRoutingWithSchedulesMatchMode() {
    TrainManager tmanager = TrainManager.instance();
    CarManager cmanager = CarManager.instance();
    LocationManager lmanager = LocationManager.instance();
    loadLocationsTrainsAndCars();
    List<Train> trains = tmanager.getTrainsByNameList();
    Assert.assertEquals("confirm number of trains", 7, trains.size());
    Car c3 = cmanager.getByRoadAndNumber("BA", "3");
    Car c4 = cmanager.getByRoadAndNumber("BB", "4");
    Car c5 = cmanager.getByRoadAndNumber("BC", "5");
    Car c6 = cmanager.getByRoadAndNumber("BD", "6");
    Car c7 = cmanager.getByRoadAndNumber("BA", "7");
    Car c8 = cmanager.getByRoadAndNumber("BB", "8");
    Car c9 = cmanager.getByRoadAndNumber("BC", "9");
    Location Acton = lmanager.getLocationByName("Acton MA");
    Location Clinton = lmanager.getLocationByName("Clinton MA");
    Location Danbury = lmanager.getLocationByName("Danbury MA");
    Location Essex = lmanager.getLocationByName("Essex MA");
    Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
    Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
    Track DS1 = Danbury.getTrackByName("Danbury Siding 1", Track.SPUR);
    Track DS2 = Danbury.getTrackByName("Danbury Siding 2", Track.SPUR);
    Track ES1 = Essex.getTrackByName("Essex Siding 1", Track.SPUR);
    Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
    // set the depart track Acton to service by local train only
    AS1.setTrainDirections(0);
    // create schedules
    ScheduleManager scheduleManager = ScheduleManager.instance();
    Schedule schA = scheduleManager.newSchedule("Schedule AAA");
    ScheduleItem schAItem1 = schA.addItem("Boxcar");
    schAItem1.setReceiveLoadName("Empty");
    schAItem1.setShipLoadName("Metal");
    schAItem1.setDestination(Acton);
    schAItem1.setDestinationTrack(AS1);
    ScheduleItem schAItem2 = schA.addItem("Flat");
    schAItem2.setReceiveLoadName("Junk");
    schAItem2.setShipLoadName("Metal");
    schAItem2.setDestination(Danbury);
    schAItem2.setDestinationTrack(DS2);
    ScheduleItem schAItem3 = schA.addItem("Boxcar");
    schAItem3.setReceiveLoadName("Boxes");
    schAItem3.setShipLoadName("Screws");
    schAItem3.setDestination(Essex);
    schAItem3.setDestinationTrack(ES1);
    ScheduleItem schAItem4 = schA.addItem("Boxcar");
    schAItem4.setReceiveLoadName("Boxes");
    schAItem4.setShipLoadName("Bolts");
    schAItem4.setDestination(Danbury);
    schAItem4.setDestinationTrack(DS1);
    ScheduleItem schAItem5 = schA.addItem("Boxcar");
    schAItem5.setReceiveLoadName("");
    schAItem5.setShipLoadName("Nuts");
    schAItem5.setDestination(Essex);
    schAItem5.setDestinationTrack(ES2);
    // Add schedule to tracks
    CS1.setScheduleId("");
    ES1.setScheduleId(schA.getId());
    // set schedule into match mode
    ES1.setScheduleMode(Track.MATCH);
    // c3 (BA 3) is a Boxcar
    c3.setLoadName("Boxes");
    // c4 (BB 4) is a Flat
    c4.setLoadName("Junk");
    // c5 (BC 5) is a Boxcar
    c5.setLoadName("Boxes");
    // c6 (BD 6) is a Boxcar
    c6.setLoadName("Boxes");
    // place cars
    Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Acton, AS1));
    // build train
    Train ActonTrain = tmanager.getTrainByName("Acton Local");
    ActonTrain.build();
    Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
    // check car destinations
    Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
    Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
    Assert.assertEquals("Car BA 3 final destination track", "Essex Siding 1", c3.getFinalDestinationTrackName());
    Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
    Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
    Assert.assertEquals("Car BB 4 final destination", "Essex MA", c4.getFinalDestinationName());
    Assert.assertEquals("Car BB 4 final destination track", "Essex Siding 1", c4.getFinalDestinationTrackName());
    Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
    Assert.assertEquals("Car BC 5 destination track", "Acton Interchange", c5.getDestinationTrackName());
    Assert.assertEquals("Car BC 5 final destination", "Essex MA", c5.getFinalDestinationName());
    Assert.assertEquals("Car BC 5 final destination track", "Essex Siding 1", c5.getFinalDestinationTrackName());
    Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
    Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
    Assert.assertEquals("Car BD 6 final destination", "Essex MA", c6.getFinalDestinationName());
    Assert.assertEquals("Car BD 6 final destination track", "Essex Siding 1", c6.getFinalDestinationTrackName());
    Assert.assertEquals("Car BD 7 destination", "Acton MA", c7.getDestinationName());
    Assert.assertEquals("Car BD 7 destination track", "Acton Interchange", c7.getDestinationTrackName());
    Assert.assertEquals("Car BD 7 final destination", "Essex MA", c7.getFinalDestinationName());
    Assert.assertEquals("Car BD 7 final destination track", "Essex Siding 1", c7.getFinalDestinationTrackName());
    // check car schedule ids
    Assert.assertEquals("Car BA 3 schedule id", schAItem3.getId(), c3.getScheduleItemId());
    Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
    Assert.assertEquals("Car BC 5 schedule id", schAItem3.getId(), c5.getScheduleItemId());
    Assert.assertEquals("Car BD 6 schedule id", schAItem4.getId(), c6.getScheduleItemId());
    Assert.assertEquals("Car BA 7 schedule id", schAItem5.getId(), c7.getScheduleItemId());
    Assert.assertEquals("Car BB 8 schedule id", schAItem1.getId(), c8.getScheduleItemId());
    Assert.assertEquals("Car BC 9 schedule id", schAItem5.getId(), c9.getScheduleItemId());
    ActonTrain.reset();
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ScheduleManager(jmri.jmrit.operations.locations.schedules.ScheduleManager) ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) TrainManager(jmri.jmrit.operations.trains.TrainManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 7 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class ScheduleManagerTest method testScheduleManager.

public void testScheduleManager() {
    LocationManager lm = LocationManager.instance();
    Location l = lm.newLocation("new test location");
    Track t = l.addTrack("track 1", Track.SPUR);
    ScheduleManager sm = ScheduleManager.instance();
    // clear out any previous schedules
    sm.dispose();
    sm = ScheduleManager.instance();
    Schedule s1 = sm.newSchedule("new schedule");
    Schedule s2 = sm.newSchedule("newer schedule");
    ScheduleItem i1 = s1.addItem("BoxCar");
    i1.setRoadName("new road");
    i1.setReceiveLoadName("new load");
    i1.setShipLoadName("new ship load");
    ScheduleItem i2 = s1.addItem("Caboose");
    i2.setRoadName("road");
    i2.setReceiveLoadName("load");
    i2.setShipLoadName("ship load");
    Assert.assertEquals("1 First schedule name", "new schedule", s1.getName());
    Assert.assertEquals("1 First schedule name", "newer schedule", s2.getName());
    List<Schedule> names = sm.getSchedulesByNameList();
    Assert.assertEquals("There should be 2 schedules", 2, names.size());
    Schedule sch1 = names.get(0);
    Schedule sch2 = names.get(1);
    Assert.assertEquals("2 First schedule name", "new schedule", sch1.getName());
    Assert.assertEquals("2 First schedule name", "newer schedule", sch2.getName());
    Assert.assertEquals("Schedule 1", sch1, sm.getScheduleByName("new schedule"));
    Assert.assertEquals("Schedule 2", sch2, sm.getScheduleByName("newer schedule"));
    // Remove references to swing
    // JComboBox box = sm.getComboBox();
    // Assert.assertEquals("3 First schedule name", "", box.getItemAt(0));
    // Assert.assertEquals("3 First schedule name", sch1, box.getItemAt(1));
    // Assert.assertEquals("3 First schedule name", sch2, box.getItemAt(2));
    //
    // JComboBox box2 = sm.getSidingsByScheduleComboBox(s1);
    // Assert.assertEquals("First siding name", null, box2.getItemAt(0));
    // now add a schedule to siding
    t.setScheduleId(sch1.getId());
    // JComboBox box3 = sm.getSidingsByScheduleComboBox(s1);
    // LocationTrackPair ltp = (LocationTrackPair)box3.getItemAt(0);
    // Assert.assertEquals("Location track pair location", l, ltp.getLocation());
    // Assert.assertEquals("Location track pair track", t, ltp.getTrack());
    Assert.assertEquals("1 Schedule Item 1 type", "BoxCar", i1.getTypeName());
    Assert.assertEquals("1 Schedule Item 1 road", "new road", i1.getRoadName());
    Assert.assertEquals("1 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
    Assert.assertEquals("1 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
    Assert.assertEquals("1 Schedule Item 2 type", "Caboose", i2.getTypeName());
    Assert.assertEquals("1 Schedule Item 2 road", "road", i2.getRoadName());
    Assert.assertEquals("1 Schedule Item 2 load", "load", i2.getReceiveLoadName());
    Assert.assertEquals("1 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
    sm.replaceRoad("new road", "replaced road");
    Assert.assertEquals("2 Schedule Item 1 type", "BoxCar", i1.getTypeName());
    Assert.assertEquals("2 Schedule Item 1 road", "replaced road", i1.getRoadName());
    Assert.assertEquals("2 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
    Assert.assertEquals("2 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
    Assert.assertEquals("2 Schedule Item 2 type", "Caboose", i2.getTypeName());
    Assert.assertEquals("2 Schedule Item 2 road", "road", i2.getRoadName());
    Assert.assertEquals("2 Schedule Item 2 load", "load", i2.getReceiveLoadName());
    Assert.assertEquals("2 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
    sm.replaceType("BoxCar", "replaced car type");
    Assert.assertEquals("3 Schedule Item 1 type", "replaced car type", i1.getTypeName());
    Assert.assertEquals("3 Schedule Item 1 road", "replaced road", i1.getRoadName());
    Assert.assertEquals("3 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
    Assert.assertEquals("3 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
    Assert.assertEquals("3 Schedule Item 2 type", "Caboose", i2.getTypeName());
    Assert.assertEquals("3 Schedule Item 2 road", "road", i2.getRoadName());
    Assert.assertEquals("3 Schedule Item 2 load", "load", i2.getReceiveLoadName());
    Assert.assertEquals("3 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
    sm.replaceType("Caboose", "BoxCar");
    Assert.assertEquals("4 Schedule Item 1 type", "replaced car type", i1.getTypeName());
    Assert.assertEquals("4 Schedule Item 1 road", "replaced road", i1.getRoadName());
    Assert.assertEquals("4 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
    Assert.assertEquals("4 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
    Assert.assertEquals("4 Schedule Item 2 type", "BoxCar", i2.getTypeName());
    Assert.assertEquals("4 Schedule Item 2 road", "road", i2.getRoadName());
    Assert.assertEquals("4 Schedule Item 2 load", "load", i2.getReceiveLoadName());
    Assert.assertEquals("4 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
    sm.replaceLoad("BoxCar", "load", "new load");
    Assert.assertEquals("5 Schedule Item 1 type", "replaced car type", i1.getTypeName());
    Assert.assertEquals("5 Schedule Item 1 road", "replaced road", i1.getRoadName());
    Assert.assertEquals("5 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
    Assert.assertEquals("5 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
    Assert.assertEquals("5 Schedule Item 2 type", "BoxCar", i2.getTypeName());
    Assert.assertEquals("5 Schedule Item 2 road", "road", i2.getRoadName());
    Assert.assertEquals("5 Schedule Item 2 load", "new load", i2.getReceiveLoadName());
    Assert.assertEquals("5 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
    sm.replaceLoad("BoxCar", "new load", "next load");
    Assert.assertEquals("6 Schedule Item 1 type", "replaced car type", i1.getTypeName());
    Assert.assertEquals("6 Schedule Item 1 road", "replaced road", i1.getRoadName());
    Assert.assertEquals("6 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
    Assert.assertEquals("6 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
    Assert.assertEquals("6 Schedule Item 2 type", "BoxCar", i2.getTypeName());
    Assert.assertEquals("6 Schedule Item 2 road", "road", i2.getRoadName());
    Assert.assertEquals("6 Schedule Item 2 load", "next load", i2.getReceiveLoadName());
    Assert.assertEquals("6 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
    // remove all schedules
    sm.dispose();
    names = sm.getSchedulesByNameList();
    Assert.assertEquals("There should be no schedules", 0, names.size());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ScheduleManager(jmri.jmrit.operations.locations.schedules.ScheduleManager) ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 8 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class LocationTest method testRoadNameSupport.

public void testRoadNameSupport() {
    // use LocationManager to allow replace car road to work properly
    Location l = LocationManager.instance().newLocation("Test Name 2");
    Assert.assertEquals("Location Name", "Test Name 2", l.getName());
    Track t = l.addTrack("new track", Track.SPUR);
    Assert.assertEquals("Location", l, t.getLocation());
    t.setRoadOption(Track.INCLUDE_ROADS);
    t.addRoadName("Test Road Name");
    t.addRoadName("Test Road Name 2");
    ScheduleManager sm = ScheduleManager.instance();
    Schedule s = sm.newSchedule("test schedule");
    ScheduleItem i1 = s.addItem("BoxCar");
    ScheduleItem i2 = s.addItem("BoxCar");
    i1.setRoadName("Test Road Name");
    i2.setRoadName("Test Road Name 2");
    Assert.assertTrue("track should accept road Test Road Name", t.acceptsRoadName("Test Road Name"));
    Assert.assertTrue("track should accept road Test Road Name 2", t.acceptsRoadName("Test Road Name 2"));
    Assert.assertFalse("track should Not accept road New Test Road Name", t.acceptsRoadName("New Test Road Name"));
    Assert.assertEquals("ScheudleItem i1 Road Test Road Name", "Test Road Name", i1.getRoadName());
    Assert.assertEquals("ScheudleItem i2 Road Test Road Name", "Test Road Name 2", i2.getRoadName());
    CarRoads cr = CarRoads.instance();
    cr.replaceName("Test Road Name", "New Test Road Name");
    Assert.assertFalse("track should Not accept road Test Road Name", t.acceptsRoadName("Test Road Name"));
    Assert.assertTrue("track should accept road Test Road Name 2", t.acceptsRoadName("Test Road Name 2"));
    Assert.assertTrue("track should accept road New Test Road Name", t.acceptsRoadName("New Test Road Name"));
    Assert.assertEquals("ScheudleItem i1 Road Test Road Name", "New Test Road Name", i1.getRoadName());
    Assert.assertEquals("Check ScheudleItem i2 Road Test Road Name", "Test Road Name 2", i2.getRoadName());
    // remove all schedules
    sm.dispose();
}
Also used : ScheduleManager(jmri.jmrit.operations.locations.schedules.ScheduleManager) ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) Schedule(jmri.jmrit.operations.locations.schedules.Schedule)

Example 9 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class SpurEditFrame method editAddSchedule.

private void editAddSchedule() {
    log.debug("Edit/add schedule");
    if (sef != null) {
        sef.dispose();
    }
    Schedule schedule = (Schedule) comboBoxSchedules.getSelectedItem();
    sef = new ScheduleEditFrame(schedule, _track);
}
Also used : Schedule(jmri.jmrit.operations.locations.schedules.Schedule) ScheduleEditFrame(jmri.jmrit.operations.locations.schedules.ScheduleEditFrame)

Example 10 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class PrintLocationsAction method printSchedulesSelected.

private void printSchedulesSelected() throws IOException {
    List<Location> locations = manager.getLocationsByNameList();
    String s = padOutString(Bundle.getMessage("Schedules"), MAX_NAME_LENGTH) + " " + Bundle.getMessage("Location") + " - " + Bundle.getMessage("SpurName") + NEW_LINE;
    writer.write(s);
    List<Schedule> schedules = ScheduleManager.instance().getSchedulesByNameList();
    for (Schedule schedule : schedules) {
        for (Location location : locations) {
            if (_location != null && location != _location) {
                continue;
            }
            List<Track> spurs = location.getTrackByNameList(Track.SPUR);
            for (Track spur : spurs) {
                if (spur.getScheduleId().equals(schedule.getId())) {
                    // pad out schedule name
                    s = padOutString(schedule.getName(), MAX_NAME_LENGTH) + " " + location.getName() + " - " + spur.getName();
                    String status = spur.checkScheduleValid();
                    if (!status.equals(Track.SCHEDULE_OKAY)) {
                        StringBuffer buf = new StringBuffer(s);
                        for (int m = s.length(); m < 63; m++) {
                            buf.append(" ");
                        }
                        s = buf.toString();
                        if (s.length() > 63) {
                            s = s.substring(0, 63);
                        }
                        s = s + TAB + status;
                    }
                    s = s + NEW_LINE;
                    writer.write(s);
                    // show the schedule's mode
                    String mode = Bundle.getMessage("Sequential");
                    if (spur.getScheduleMode() == Track.MATCH) {
                        mode = Bundle.getMessage("Match");
                    }
                    s = padOutString("", MAX_NAME_LENGTH) + SPACE + Bundle.getMessage("ScheduleMode") + ": " + mode + NEW_LINE;
                    writer.write(s);
                    // show alternate track if there's one
                    if (spur.getAlternateTrack() != null) {
                        s = padOutString("", MAX_NAME_LENGTH) + SPACE + MessageFormat.format(Bundle.getMessage("AlternateTrackName"), new Object[] { spur.getAlternateTrack().getName() }) + NEW_LINE;
                        writer.write(s);
                    }
                    // show custom loads from staging if not 100%
                    if (spur.getReservationFactor() != 100) {
                        s = padOutString("", MAX_NAME_LENGTH) + SPACE + MessageFormat.format(Bundle.getMessage("PercentageStaging"), new Object[] { spur.getReservationFactor() }) + NEW_LINE;
                        writer.write(s);
                    }
                }
            }
        }
    }
    if (printComments.isSelected() || printDetails.isSelected() || printAnalysis.isSelected()) {
        writer.write(FORM_FEED);
    }
}
Also used : Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Aggregations

Schedule (jmri.jmrit.operations.locations.schedules.Schedule)27 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)17 Location (jmri.jmrit.operations.locations.Location)11 Track (jmri.jmrit.operations.locations.Track)11 ScheduleManager (jmri.jmrit.operations.locations.schedules.ScheduleManager)10 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)9 LocationManager (jmri.jmrit.operations.locations.LocationManager)7 Car (jmri.jmrit.operations.rollingstock.cars.Car)7 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)6 Train (jmri.jmrit.operations.trains.Train)5 TrainManager (jmri.jmrit.operations.trains.TrainManager)5 TrainSchedule (jmri.jmrit.operations.trains.timetable.TrainSchedule)5 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)3 Route (jmri.jmrit.operations.routes.Route)3 Kernel (jmri.jmrit.operations.rollingstock.cars.Kernel)2 ScheduleEditFrame (jmri.jmrit.operations.locations.schedules.ScheduleEditFrame)1 CarRoads (jmri.jmrit.operations.rollingstock.cars.CarRoads)1 RouteManager (jmri.jmrit.operations.routes.RouteManager)1