use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainTest method testScheduleLoads.
public void testScheduleLoads() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
CarManager cmanager = CarManager.instance();
ScheduleManager smanager = ScheduleManager.instance();
CarTypes ct = CarTypes.instance();
ct.addName("Boxcar");
ct.addName("Gon");
ct.addName("Coil Car");
ct.addName("Flat Car");
// create schedules
Schedule sch1 = smanager.newSchedule("Schedule 1");
ScheduleItem sch1Item1 = sch1.addItem("Boxcar");
// request a UP Boxcar
sch1Item1.setRoadName("UP");
ScheduleItem sch1Item2 = sch1.addItem("Flat Car");
// request an empty car and load it with Scrap
sch1Item2.setReceiveLoadName("E");
sch1Item2.setShipLoadName("Scrap");
ScheduleItem sch1Item3 = sch1.addItem("Gon");
// request a loaded car and load it with Tin
sch1Item3.setReceiveLoadName("L");
sch1Item3.setShipLoadName("Tin");
// Allows c13 which is part of a kernel to get a new load
CarLoads.instance().addName("Gon", "Tin");
Schedule sch2 = smanager.newSchedule("Schedule 2");
ScheduleItem sch2Item1 = sch2.addItem("Coil Car");
sch2Item1.setCount(2);
sch2.addItem("Boxcar");
// Create locations used
Location loc1;
loc1 = lmanager.newLocation("New Westford");
loc1.setTrainDirections(DIRECTION_ALL);
// loc1.addTypeName("Flat Car");
Location loc2;
loc2 = lmanager.newLocation("New Chelmsford");
loc2.setTrainDirections(DIRECTION_ALL);
Location loc3;
loc3 = lmanager.newLocation("New Bedford");
loc3.setTrainDirections(DIRECTION_ALL);
Track loc1trk1;
loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
loc1trk1.setLength(900);
// loc1trk1.addTypeName("Flat Car");
Track loc1trk2;
loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
loc1trk2.setLength(500);
loc1trk2.deleteTypeName("Coil Car");
Track loc1trk3;
loc1trk3 = loc1.addTrack("Westford Express 3", Track.SPUR);
loc1trk3.setTrainDirections(Track.WEST + Track.EAST);
loc1trk3.setLength(300);
loc1trk3.deleteTypeName("Gon");
loc1trk3.deleteTypeName("Coil Car");
Track loc1trk4;
loc1trk4 = loc1.addTrack("Westford Express 4", Track.SPUR);
loc1trk4.setTrainDirections(Track.WEST + Track.EAST);
loc1trk4.setLength(300);
loc1trk4.deleteTypeName("Gon");
loc1trk4.deleteTypeName("Coil Car");
Track loc2trk1;
loc2trk1 = loc2.addTrack("Chelmsford Freight 1", Track.SPUR);
loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
loc2trk1.setLength(900);
loc2trk1.deleteTypeName("Coil Car");
loc2trk1.setScheduleId(sch1.getId());
loc2trk1.setScheduleMode(Track.SEQUENTIAL);
// start the schedule with 2nd item Flat Car
loc2trk1.setScheduleItemId(sch1.getItemsBySequenceList().get(1).getId());
Track loc2trk2;
loc2trk2 = loc2.addTrack("Chelmsford Freight 2", Track.SPUR);
loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
loc2trk2.setLength(900);
loc2trk2.deleteTypeName("Coil Car");
loc2trk2.setScheduleId(sch1.getId());
loc2trk2.setScheduleMode(Track.SEQUENTIAL);
// start the schedule with 3rd item Gon
loc2trk2.setScheduleItemId(sch1.getItemsBySequenceList().get(2).getId());
Track loc2trk3;
loc2trk3 = loc2.addTrack("Chelmsford Yard 3", Track.YARD);
loc2trk3.setTrainDirections(Track.WEST + Track.EAST);
loc2trk3.setLength(900);
loc2trk3.deleteTypeName("Gon");
loc2trk3.deleteTypeName("Coil Car");
Track loc2trk4;
loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
loc2trk4.setLength(900);
loc2trk4.setScheduleId(sch2.getId());
loc2trk4.setScheduleMode(Track.SEQUENTIAL);
Track loc3trk1;
loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.STAGING);
loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
loc3trk1.setLength(900);
loc3trk1.setRemoveCustomLoadsEnabled(true);
// Create route with 2 location
Route rte1;
rte1 = rmanager.newRoute("Two Location Route");
RouteLocation rl1 = rte1.addLocation(loc1);
rl1.setTrainDirection(RouteLocation.EAST);
rl1.setMaxCarMoves(12);
// set the train icon coordinates
rl1.setTrainIconX(25);
rl1.setTrainIconY(75);
RouteLocation rl2 = rte1.addLocation(loc2);
rl2.setTrainDirection(RouteLocation.EAST);
rl2.setMaxCarMoves(12);
// set the train icon coordinates
rl2.setTrainIconX(75);
rl2.setTrainIconY(75);
// Create train
Train train1;
train1 = tmanager.newTrain("NWNC");
train1.setRoute(rte1);
// Set up 13 cars
Car c1 = new Car("BM", "S1");
c1.setTypeName("Gon");
c1.setLength("90");
c1.setMoves(13);
c1.setLoadName("L");
cmanager.register(c1);
Car c2 = new Car("UP", "S2");
c2.setTypeName("Boxcar");
c2.setLength("80");
c2.setMoves(12);
cmanager.register(c2);
Car c3 = new Car("XP", "S3");
c3.setTypeName("Flat Car");
c3.setLength("70");
c3.setMoves(0);
c3.setLoadName("L");
// force this car to Chelmsford
c3.setDestination(loc2, null);
cmanager.register(c3);
Car c4 = new Car("PU", "S4");
c4.setTypeName("Boxcar");
c4.setLength("60");
c4.setMoves(10);
cmanager.register(c4);
// place two cars in a kernel
Kernel k1 = cmanager.newKernel("TwoCars");
Car c5 = new Car("UP", "S5");
c5.setTypeName("Gon");
c5.setLength("50");
c5.setMoves(9);
c5.setLoadName("L");
c5.setKernel(k1);
cmanager.register(c5);
Car c6 = new Car("CP", "S6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(8);
c6.setLoadName("L");
cmanager.register(c6);
Car c7 = new Car("UP", "S7");
c7.setTypeName("Boxcar");
c7.setLength("50");
c7.setMoves(7);
cmanager.register(c7);
Car c8 = new Car("XP", "S8");
c8.setTypeName("Gon");
c8.setLength("60");
c8.setMoves(6);
cmanager.register(c8);
Car c9 = new Car("XP", "S9");
c9.setTypeName("Flat Car");
c9.setLength("90");
c9.setMoves(5);
c9.setLoadName("E");
cmanager.register(c9);
Car c10 = new Car("CP", "S10");
c10.setTypeName("Coil Car");
c10.setLength("40");
c10.setMoves(2);
c10.setLoadName("L");
cmanager.register(c10);
Car c11 = new Car("CP", "S11");
c11.setTypeName("Coil Car");
c11.setLength("40");
c11.setMoves(3);
c11.setLoadName("Coils");
cmanager.register(c11);
Car c12 = new Car("CP", "S12");
c12.setTypeName("Coil Car");
c12.setLength("40");
c12.setMoves(4);
cmanager.register(c12);
// place car in kernel with c5
Car c13 = new Car("UP", "S13");
c13.setTypeName("Gon");
c13.setLength("50");
c13.setMoves(1);
c13.setLoadName("L");
c13.setKernel(k1);
cmanager.register(c13);
// place the cars in the yards
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(loc1, loc1trk2));
train1.build();
// Schedule sch1 should cause c2 to be delivered to Chelmsford Freight 2
Assert.assertEquals("c2 destination", "Chelmsford Freight 2", c2.getDestinationTrackName());
Assert.assertEquals("c2 next load", "", c2.getNextLoadName());
// Schedule sch1 and sch2 should reject c3, to be delivered to Chelmsford Yard 3
Assert.assertEquals("c3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("c3 next load", "", c3.getNextLoadName());
Assert.assertEquals("c4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName());
// Schedule sch1 should cause c5 & c13 to be delivered to Chelmsford Freight 2
Assert.assertEquals("c5 destination", "Chelmsford Freight 2", c5.getDestinationTrackName());
Assert.assertEquals("c5 next load", "Tin", c5.getNextLoadName());
Assert.assertEquals("c6 destination", "Chelmsford Yard 3", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination", "Chelmsford Freight 4", c7.getDestinationTrackName());
Assert.assertEquals("c9 destination", "Chelmsford Freight 1", c9.getDestinationTrackName());
Assert.assertEquals("c9 next load", "Scrap", c9.getNextLoadName());
Assert.assertEquals("c10 destination", "Chelmsford Freight 4", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination", "Chelmsford Freight 4", c11.getDestinationTrackName());
// C13 is part of kernel, load will flip between E and L
Assert.assertEquals("c13 destination", "Chelmsford Freight 2", c13.getDestinationTrackName());
Assert.assertEquals("c13 next load", "Tin", c13.getNextLoadName());
// move and terminate train
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track", "Chelmsford Freight 1", c1.getTrackName());
Assert.assertEquals("c1 load", "Tin", c1.getLoadName());
Assert.assertEquals("c2 track", "Chelmsford Freight 2", c2.getTrackName());
Assert.assertEquals("c2 load", "L", c2.getLoadName());
Assert.assertEquals("c3 track", "Chelmsford Yard 3", c3.getTrackName());
Assert.assertEquals("c3 load", "L", c3.getLoadName());
Assert.assertEquals("c4 track", "Chelmsford Yard 3", c4.getTrackName());
Assert.assertEquals("c4 load", "E", c4.getLoadName());
Assert.assertEquals("c5 track", "Chelmsford Freight 2", c5.getTrackName());
Assert.assertEquals("c5 load", "Tin", c5.getLoadName());
Assert.assertEquals("c6 track", "Chelmsford Yard 3", c6.getTrackName());
Assert.assertEquals("c6 load", "L", c6.getLoadName());
Assert.assertEquals("c7 track", "Chelmsford Freight 4", c7.getTrackName());
Assert.assertEquals("c7 load", "L", c7.getLoadName());
Assert.assertEquals("c8 track", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load", "E", c8.getLoadName());
Assert.assertEquals("c9 track", "Chelmsford Freight 1", c9.getTrackName());
Assert.assertEquals("c9 load", "Scrap", c9.getLoadName());
Assert.assertEquals("c10 track", "Chelmsford Freight 4", c10.getTrackName());
Assert.assertEquals("c10 load", "E", c10.getLoadName());
Assert.assertEquals("c11 track", "Chelmsford Freight 4", c11.getTrackName());
Assert.assertEquals("c11 load", "E", c11.getLoadName());
Assert.assertEquals("c12 track", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load", "E", c12.getLoadName());
Assert.assertEquals("c13 track", "Chelmsford Freight 2", c13.getTrackName());
Assert.assertEquals("c13 load", "Tin", c13.getLoadName());
// create a route to staging to test remove schedule load
// Create route with 2 location
Route rte2;
rte2 = rmanager.newRoute("Chelmsford to Staging");
RouteLocation r2rl1 = rte2.addLocation(loc2);
r2rl1.setTrainDirection(RouteLocation.EAST);
r2rl1.setMaxCarMoves(12);
// set the train icon coordinates
r2rl1.setTrainIconX(125);
r2rl1.setTrainIconY(75);
RouteLocation r2rl3 = rte2.addLocation(loc3);
r2rl3.setTrainDirection(RouteLocation.EAST);
r2rl3.setMaxCarMoves(12);
// set the train icon coordinates
r2rl3.setTrainIconX(175);
r2rl3.setTrainIconY(75);
train1.setRoute(rte2);
train1.setName("Chelmsford to Bedford");
train1.build();
// move and terminate train
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track to staging", "Bedford Yard 1", c1.getTrackName());
Assert.assertEquals("c1 load to staging", "E", c1.getLoadName());
Assert.assertEquals("c2 track to staging", "Bedford Yard 1", c2.getTrackName());
Assert.assertEquals("c2 load to staging", "L", c2.getLoadName());
Assert.assertEquals("c3 track to staging", "Bedford Yard 1", c3.getTrackName());
Assert.assertEquals("c3 load to staging", "L", c3.getLoadName());
Assert.assertEquals("c4 track to staging", "Bedford Yard 1", c4.getTrackName());
Assert.assertEquals("c4 load to staging", "E", c4.getLoadName());
Assert.assertEquals("c5 track to staging", "Bedford Yard 1", c5.getTrackName());
Assert.assertEquals("c5 load to staging", "E", c5.getLoadName());
Assert.assertEquals("c6 track to staging", "Bedford Yard 1", c6.getTrackName());
Assert.assertEquals("c6 load to staging", "L", c6.getLoadName());
Assert.assertEquals("c7 track to staging", "Bedford Yard 1", c7.getTrackName());
Assert.assertEquals("c7 load to staging", "L", c7.getLoadName());
Assert.assertEquals("c8 track to staging", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load to staging", "E", c8.getLoadName());
Assert.assertEquals("c9 track to staging", "Bedford Yard 1", c9.getTrackName());
Assert.assertEquals("c9 load to staging", "E", c9.getLoadName());
Assert.assertEquals("c10 track to staging", "Bedford Yard 1", c10.getTrackName());
Assert.assertEquals("c10 load to staging", "E", c10.getLoadName());
Assert.assertEquals("c11 track to staging", "Bedford Yard 1", c11.getTrackName());
Assert.assertEquals("c11 load to staging", "E", c11.getLoadName());
Assert.assertEquals("c12 track to staging", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load to staging", "E", c12.getLoadName());
Assert.assertEquals("c13 track to staging", "Bedford Yard 1", c13.getTrackName());
Assert.assertEquals("c13 load to staging", "E", c13.getLoadName());
// create a route from staging to test generate schedule load
// Create route with 3 locations
Route rte3;
rte3 = rmanager.newRoute("Staging to Chelmsford");
RouteLocation r3rl1 = rte3.addLocation(loc3);
r3rl1.setTrainDirection(RouteLocation.EAST);
// there are 11 cars departing staging
r3rl1.setMaxCarMoves(11);
// set the train icon coordinates
r3rl1.setTrainIconX(25);
r3rl1.setTrainIconY(100);
RouteLocation r3rl2 = rte3.addLocation(loc2);
r3rl2.setTrainDirection(RouteLocation.EAST);
r3rl2.setMaxCarMoves(12);
RouteLocation r3rl3 = rte3.addLocation(loc1);
r3rl3.setTrainDirection(RouteLocation.EAST);
r3rl3.setMaxCarMoves(12);
// set the train icon coordinates
r3rl3.setTrainIconX(75);
r3rl3.setTrainIconY(100);
loc3trk1.setRemoveCustomLoadsEnabled(false);
// generate schedule loads
loc3trk1.setAddCustomLoadsEnabled(true);
// request these loads from staging
sch1Item1.setReceiveLoadName("Metal 1");
sch1Item2.setReceiveLoadName("Metal 2");
sch1Item3.setReceiveLoadName("Metal 3");
// Allows c13 which is part of a kernel to get a new load
CarLoads.instance().addName("Gon", "Metal 3");
train1.setRoute(rte3);
train1.setName("BCW");
train1.build();
Assert.assertEquals("Train Bedford Chelmsford Westford build status", true, train1.isBuilt());
Assert.assertEquals("c1 load from staging", "E", c1.getLoadName());
Assert.assertEquals("c2 load from staging", "L", c2.getLoadName());
Assert.assertEquals("c3 load from staging", "L", c3.getLoadName());
Assert.assertEquals("c4 load from staging", "E", c4.getLoadName());
Assert.assertEquals("c5 load from staging", "Metal 3", c5.getLoadName());
Assert.assertEquals("c6 load from staging", "L", c6.getLoadName());
Assert.assertEquals("c7 load from staging", "L", c7.getLoadName());
Assert.assertEquals("c8 load from staging", "E", c8.getLoadName());
Assert.assertEquals("c9 load from staging", "Metal 2", c9.getLoadName());
Assert.assertEquals("c9 next load from staging", "Scrap", c9.getNextLoadName());
Assert.assertEquals("c10 load from staging", "E", c10.getLoadName());
Assert.assertEquals("c11 load from staging", "E", c11.getLoadName());
Assert.assertEquals("c13 load from staging", "Metal 3", c13.getLoadName());
// move and terminate train
train1.move();
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track from staging terminated", "Westford Yard 1", c1.getTrackName());
Assert.assertEquals("c1 load from staging terminated", "E", c1.getLoadName());
Assert.assertEquals("c2 track from staging terminated", "Westford Yard 2", c2.getTrackName());
Assert.assertEquals("c2 load from staging terminated", "L", c2.getLoadName());
Assert.assertEquals("c3 track from staging terminated", "Westford Yard 1", c3.getTrackName());
Assert.assertEquals("c3 load from staging terminated", "L", c3.getLoadName());
Assert.assertEquals("c4 track from staging terminated", "Westford Express 4", c4.getTrackName());
Assert.assertEquals("c4 load from staging terminated", "L", c4.getLoadName());
Assert.assertEquals("c5 track from staging terminated", "Chelmsford Freight 2", c5.getTrackName());
Assert.assertEquals("c5 load from staging terminated", "Tin", c5.getLoadName());
Assert.assertEquals("c6 track from staging terminated", "Westford Express 3", c6.getTrackName());
Assert.assertEquals("c6 load from staging terminated", "E", c6.getLoadName());
Assert.assertEquals("c7 track from staging terminated", "Westford Yard 2", c7.getTrackName());
Assert.assertEquals("c7 load from staging terminated", "L", c7.getLoadName());
Assert.assertEquals("c8 track from staging terminated", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load from staging terminated", "E", c8.getLoadName());
Assert.assertEquals("c9 track from staging terminated", "Chelmsford Freight 2", c9.getTrackName());
Assert.assertEquals("c9 load from staging terminated", "Scrap", c9.getLoadName());
Assert.assertEquals("c10 track from staging terminated", "Chelmsford Freight 4", c10.getTrackName());
Assert.assertEquals("c10 load from staging terminated", "L", c10.getLoadName());
Assert.assertEquals("c11 track from staging terminated", "Westford Yard 1", c11.getTrackName());
Assert.assertEquals("c11 load from staging terminated", "E", c11.getLoadName());
Assert.assertEquals("c12 track from staging terminated", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load from staging terminated", "E", c12.getLoadName());
Assert.assertEquals("c13 track from staging terminated", "Chelmsford Freight 2", c13.getTrackName());
Assert.assertEquals("c13 load from staging terminated", "Tin", c13.getLoadName());
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainByCarTypeFrame method updateRoute.
private void updateRoute() {
if (_train != null) {
_train.removePropertyChangeListener(this);
}
pRoute.removeAll();
if (trainsComboBox.getSelectedItem() == null) {
_train = null;
} else {
_train = (Train) trainsComboBox.getSelectedItem();
}
if (_train == null) {
setTitle(Bundle.getMessage("MenuItemShowCarTypes"));
repaint();
return;
}
setTitle(Bundle.getMessage("MenuItemShowCarTypes") + " " + _train.getName());
_train.addPropertyChangeListener(this);
setTitle(Bundle.getMessage("MenuItemShowCarTypes") + " " + _train.getName());
log.debug("update locations served by train ({})", _train.getName());
int y = 0;
String carType = (String) typeComboBox.getSelectedItem();
if (_car != null) {
_car.removePropertyChangeListener(this);
}
_car = null;
if (carsComboBox.getSelectedItem() != null) {
_car = (Car) carsComboBox.getSelectedItem();
_car.addPropertyChangeListener(this);
}
Route route = _train.getRoute();
if (route == null) {
return;
}
List<RouteLocation> routeList = route.getLocationsBySequenceList();
for (RouteLocation rl : routeList) {
JLabel loc = new JLabel();
String locationName = rl.getName();
loc.setText(locationName);
addItemLeft(pRoute, loc, 0, y++);
Location location = locationManager.getLocationByName(locationName);
if (location == null) {
continue;
}
if (_car != null && _car.getTrack() != null && !_car.getTrack().acceptsDestination(location)) {
JLabel locText = new JLabel();
locText.setText(MessageFormat.format(Bundle.getMessage("CarOnTrackDestinationRestriction"), new Object[] { _car.toString(), _car.getTrackName(), locationName }));
addItemWidth(pRoute, locText, 2, 1, y++);
if (_car.getLocation() != location)
continue;
}
List<Track> tracks = location.getTrackByNameList(null);
for (Track track : tracks) {
// show the car's track if there's a track destination restriction
if (_car != null && _car.getTrack() != null && !_car.getTrack().acceptsDestination(location) && _car.getTrack() != track) {
continue;
}
JLabel trk = new JLabel();
trk.setText(track.getName());
addItemLeft(pRoute, trk, 1, y);
// is the car at this location and track?
if (_car != null && location.equals(_car.getLocation()) && track.equals(_car.getTrack())) {
// NOI18N
JLabel here = new JLabel(" -->");
addItemLeft(pRoute, here, 0, y);
}
JLabel op = new JLabel();
addItemLeft(pRoute, op, 2, y++);
if (!_train.acceptsTypeName(carType)) {
op.setText(Bundle.getMessage("X(TrainType)"));
} else if (_car != null && !_train.acceptsRoadName(_car.getRoadName())) {
op.setText(Bundle.getMessage("X(TrainRoad)"));
} else // TODO need to do the same tests for caboose changes in the train's route
if (_car != null && _car.isCaboose() && (_train.getRequirements() & Train.CABOOSE) == Train.CABOOSE && location.equals(_car.getLocation()) && track.equals(_car.getTrack()) && !_train.getCabooseRoad().equals(Train.NONE) && !_car.getRoadName().equals(_train.getCabooseRoad()) && location.getName().equals(_train.getTrainDepartsName())) {
op.setText(Bundle.getMessage("X(TrainRoad)"));
} else if (_car != null && _car.hasFred() && (_train.getRequirements() & Train.FRED) == Train.FRED && location.equals(_car.getLocation()) && track.equals(_car.getTrack()) && !_train.getCabooseRoad().equals(Train.NONE) && !_car.getRoadName().equals(_train.getCabooseRoad()) && location.getName().equals(_train.getTrainDepartsName())) {
op.setText(Bundle.getMessage("X(TrainRoad)"));
} else if (_car != null && !_car.isCaboose() && !_car.isPassenger() && !_train.acceptsLoad(_car.getLoadName(), _car.getTypeName())) {
op.setText(Bundle.getMessage("X(TrainLoad)"));
} else if (_car != null && !_train.acceptsBuiltDate(_car.getBuilt())) {
op.setText(Bundle.getMessage("X(TrainBuilt)"));
} else if (_car != null && !_train.acceptsOwnerName(_car.getOwner())) {
op.setText(Bundle.getMessage("X(TrainOwner)"));
} else if (_train.skipsLocation(rl.getId())) {
op.setText(Bundle.getMessage("X(TrainSkips)"));
} else if (!rl.isDropAllowed() && !rl.isPickUpAllowed()) {
op.setText(Bundle.getMessage("X(Route)"));
} else if (rl.getMaxCarMoves() <= 0) {
op.setText(Bundle.getMessage("X(RouteMoves)"));
} else if (!location.acceptsTypeName(carType)) {
op.setText(Bundle.getMessage("X(LocationType)"));
} else // check route before checking train, check train calls check route
if (!track.acceptsPickupRoute(route) && !track.acceptsDropRoute(route)) {
op.setText(Bundle.getMessage("X(TrackRoute)"));
} else if (!track.acceptsPickupTrain(_train) && !track.acceptsDropTrain(_train)) {
op.setText(Bundle.getMessage("X(TrackTrain)"));
} else if (!track.acceptsTypeName(carType)) {
op.setText(Bundle.getMessage("X(TrackType)"));
} else if (_car != null && !track.acceptsRoadName(_car.getRoadName())) {
op.setText(Bundle.getMessage("X(TrackRoad)"));
} else if (_car != null && _car.getTrack() != track && !track.acceptsLoad(_car.getLoadName(), _car.getTypeName())) {
op.setText(Bundle.getMessage("X(TrackLoad)"));
} else if (_car != null && !track.acceptsDestination(_car.getFinalDestination()) && _car.getDestination() == null) {
op.setText(Bundle.getMessage("X(TrackDestination)"));
} else if ((rl.getTrainDirection() & location.getTrainDirections()) == 0) {
op.setText(Bundle.getMessage("X(DirLoc)"));
} else if ((rl.getTrainDirection() & track.getTrainDirections()) == 0) {
op.setText(Bundle.getMessage("X(DirTrk)"));
} else if (!checkScheduleAttribute(TYPE, carType, null, track)) {
op.setText(Bundle.getMessage("X(ScheduleType)"));
} else if (!checkScheduleAttribute(LOAD, carType, _car, track)) {
op.setText(Bundle.getMessage("X(ScheduleLoad)"));
} else if (!checkScheduleAttribute(ROAD, carType, _car, track)) {
op.setText(Bundle.getMessage("X(ScheduleRoad)"));
} else if (!checkScheduleAttribute(TIMETABLE, carType, _car, track)) {
op.setText(Bundle.getMessage("X(ScheduleTimeTable)"));
} else if (!checkScheduleAttribute(ALL, carType, _car, track)) {
op.setText(Bundle.getMessage("X(Schedule)"));
} else if (!track.acceptsPickupTrain(_train)) {
// can the train drop off car?
if (rl.isDropAllowed() && track.acceptsDropTrain(_train)) {
op.setText(Bundle.getMessage("DropOnly"));
} else {
op.setText(Bundle.getMessage("X(TrainPickup)"));
}
} else if (!track.acceptsDropTrain(_train)) {
// can the train pick up car?
if (rl.isPickUpAllowed() && track.acceptsPickupTrain(_train)) {
op.setText(Bundle.getMessage("PickupOnly"));
} else {
op.setText(Bundle.getMessage("X(TrainDrop)"));
}
// determine if a local move with default loads
} else if (!_train.isLocalSwitcher() && _car != null && _car.getTrack() != track && _car.getLocation() == track.getLocation() && _car.getFinalDestination() == null && (_car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) || _car.getLoadName().equals(CarLoads.instance().getDefaultLoadName()))) {
op.setText(Bundle.getMessage("X(LocalMove)"));
// determine if local move with custom load or final destination is allowed
} else if (!_train.isAllowLocalMovesEnabled() && _car != null && _car.getTrack() != track && _car.getLocation() == track.getLocation() && (_car.getFinalDestination() != null || !_car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) && !_car.getLoadName().equals(CarLoads.instance().getDefaultLoadName()))) {
op.setText(Bundle.getMessage("X(TrainLocalMove)"));
// determine if spur can accept car with custom load
} else if (track.getTrackType().equals(Track.SPUR) && track.getSchedule() == null && _car != null && _car.getTrack() != track && !_car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) && !_car.getLoadName().equals(CarLoads.instance().getDefaultLoadName())) {
op.setText(Bundle.getMessage("X(TrackCustomLoad)"));
} else if (rl.isDropAllowed() && rl.isPickUpAllowed()) {
op.setText(Bundle.getMessage("ButtonOK"));
} else if (rl.isDropAllowed()) {
op.setText(Bundle.getMessage("DropOnly"));
} else if (rl.isPickUpAllowed()) {
op.setText(Bundle.getMessage("PickupOnly"));
} else {
// default shouldn't occur
op.setText("X");
}
}
}
pRoute.revalidate();
repaint();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class CarManagerTest method testListCarsAvailableByTrain.
public void testListCarsAvailableByTrain() {
resetCarManager();
CarManager manager = CarManager.instance();
Route r = new Route("id", "Test");
r.addLocation(l1);
r.addLocation(l2);
RouteLocation last = r.addLocation(l3);
Train t1;
Train t3;
t1 = new Train("id1", "F");
t1.setRoute(r);
t3 = new Train("id3", "E");
t3.setRoute(r);
c1.setTrain(t1);
c2.setTrain(t3);
c3.setTrain(t3);
c4.setTrain(new Train("id4", "B"));
c5.setTrain(t3);
c6.setTrain(new Train("id6", "A"));
// how many cars available?
List<Car> carList = manager.getAvailableTrainList(t1);
Assert.assertEquals("Number of Cars available for t1", 1, carList.size());
Assert.assertEquals("1st car in list available for t1", c1, carList.get(0));
carList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Cars available for t3", 3, carList.size());
Assert.assertEquals("1st car in list available for t3", c5, carList.get(0));
Assert.assertEquals("2nd car in list available for t3", c2, carList.get(1));
Assert.assertEquals("3rd car in list available for t3", c3, carList.get(2));
// now don't allow pickups at the last location in the train's route
last.setPickUpAllowed(false);
carList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Cars available for t3", 2, carList.size());
Assert.assertEquals("1st car in list available for t3", c2, carList.get(0));
Assert.assertEquals("2nd car in list available for t3", c3, carList.get(1));
// note that c5 isn't available since it is located at the end of the train's route
// release cars from trains
c2.setTrain(null);
c4.setTrain(null);
// c6 is located at the end of the route, therefore not available
c6.setTrain(null);
// there should be more cars now
carList = manager.getAvailableTrainList(t1);
Assert.assertEquals("Number of Cars available t1 after release", 3, carList.size());
// should be sorted by moves
Assert.assertEquals("1st car in list available for t1", c1, carList.get(0));
Assert.assertEquals("2nd car in list available for t1", c4, carList.get(1));
Assert.assertEquals("3rd car in list available for t1", c2, carList.get(2));
carList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Cars available for t3 after release", 3, carList.size());
Assert.assertEquals("1st car in list available for t3", c4, carList.get(0));
Assert.assertEquals("2nd car in list available for t3", c2, carList.get(1));
Assert.assertEquals("3rd car in list available for t3", c3, carList.get(2));
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class CarManagerTest method testListCarsByTrainDestination.
public void testListCarsByTrainDestination() {
resetCarManager();
CarManager manager = CarManager.instance();
Route r = new Route("id", "Test");
r.addLocation(l1);
r.addLocation(l2);
r.addLocation(l3);
Train t1;
Train t3;
t1 = new Train("id1", "F");
t1.setRoute(r);
t3 = new Train("id3", "E");
t3.setRoute(r);
c1.setTrain(t1);
c2.setTrain(t3);
c3.setTrain(t3);
c4.setTrain(new Train("id4", "B"));
c5.setTrain(t3);
c6.setTrain(new Train("id6", "A"));
// now get cars by specific train
List<Car> carList = manager.getByTrainDestinationList(t1);
Assert.assertEquals("Number of Cars in t1 by dest", 1, carList.size());
Assert.assertEquals("1st car in list by t1 by dest", c1, carList.get(0));
carList = manager.getByTrainDestinationList(t3);
Assert.assertEquals("Number of Cars in t3 by dest", 3, carList.size());
Assert.assertEquals("1st car in list by t3 by dest", c2, carList.get(0));
Assert.assertEquals("2nd car in list by t3 by dest", c3, carList.get(1));
Assert.assertEquals("3rd car in list by t3 by dest", c5, carList.get(2));
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class EngineManagerTest method testAvailableAfterReleaseFromTrain.
public void testAvailableAfterReleaseFromTrain() {
resetEngineManager();
EngineManager manager = EngineManager.instance();
Route r = new Route("id", "Test");
r.addLocation(l1);
r.addLocation(l2);
r.addLocation(l3);
Train t1 = new Train("id1", "F");
t1.setRoute(r);
Train t3 = new Train("id3", "E");
t3.setRoute(r);
//setup the engines
e1.setTrain(t1);
e2.setTrain(t3);
e3.setTrain(t3);
e4.setTrain(new Train("id4", "B"));
e5.setTrain(t3);
e6.setTrain(new Train("id6", "A"));
// release engines from trains
e2.setTrain(null);
// e4 is located in the middle of the route, therefore not available
e4.setTrain(null);
// e6 is located at the end of the route, therefore not available
e6.setTrain(null);
// there should be more engines now
List<Engine> engineList = manager.getAvailableTrainList(t1);
Assert.assertEquals("Number of Engines available t1 after release", 4, engineList.size());
// should be sorted by moves
Assert.assertEquals("1st engine in list available for t1", e1, engineList.get(0));
Assert.assertEquals("2nd engine in list available for t1", e4, engineList.get(1));
engineList = manager.getAvailableTrainList(t3);
Assert.assertEquals("Number of Engines available for t3 after release", 5, engineList.size());
Assert.assertEquals("1st engine in list available for t3", e5, engineList.get(0));
}
Aggregations