use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilderTest method testCabooseChanges.
/**
* The program allows up to two caboose changes in a train's route.
*/
public void testCabooseChanges() {
// test confirms the order cabooses are assigned to the train
Setup.setBuildAggressive(true);
// create 5 locations with tracks
Location harvard = lmanager.newLocation("Harvard");
Track loc1trk1 = harvard.addTrack("Harvard Yard 1", Track.YARD);
loc1trk1.setLength(80);
Location arlington = lmanager.newLocation("Arlington");
Track loc2trk1 = arlington.addTrack("Arlington Siding", Track.YARD);
loc2trk1.setLength(80);
Location boston = lmanager.newLocation("Boston");
Track loc3trk1 = boston.addTrack("Boston Yard 1", Track.YARD);
loc3trk1.setLength(80);
Location chelmsford = lmanager.newLocation("Chelmsford");
Track loc4trk1 = chelmsford.addTrack("Chelmsford Yard 1", Track.YARD);
loc4trk1.setLength(80);
Location westford = lmanager.newLocation("Westford");
Track loc5trk1 = westford.addTrack("Westford Yard", Track.YARD);
loc5trk1.setLength(40);
// create and place cabooses
Car c1 = cmanager.newCar("ABC", "1");
c1.setTypeName("Caboose");
c1.setLength("32");
c1.setCaboose(true);
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(harvard, loc1trk1));
Car c2 = cmanager.newCar("ABC", "2");
c2.setTypeName("Caboose");
c2.setLength("32");
c2.setCaboose(true);
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(arlington, loc2trk1));
Car c3 = cmanager.newCar("XYZ", "3");
c3.setTypeName("Caboose");
c3.setLength("32");
c3.setCaboose(true);
c2.setMoves(10);
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(arlington, loc2trk1));
Car c4 = cmanager.newCar("ABC", "4");
c4.setTypeName("Caboose");
c4.setLength("32");
c4.setCaboose(true);
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(chelmsford, loc4trk1));
Car c5 = cmanager.newCar("XYZ", "5");
c5.setTypeName("Caboose");
c5.setLength("32");
c5.setCaboose(true);
c5.setMoves(10);
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(chelmsford, loc4trk1));
// car with FRED at departure
Car f1 = cmanager.newCar("CBA", "1");
f1.setTypeName("Boxcar");
f1.setLength("32");
f1.setFred(true);
Assert.assertEquals("Place f1", Track.OKAY, f1.setLocation(harvard, loc1trk1));
Route rte1 = rmanager.newRoute("Route Harvard to Westford");
rte1.addLocation(harvard);
RouteLocation rlArlington = rte1.addLocation(arlington);
rte1.addLocation(boston);
RouteLocation rlChelmsford = rte1.addLocation(chelmsford);
rte1.addLocation(westford);
// Create train
Train train1 = tmanager.newTrain("TestCabooseChanges");
train1.setRoute(rte1);
// depart with caboose
train1.setRequirements(Train.CABOOSE);
// swap out caboose at Arlington
train1.setSecondLegOptions(Train.ADD_CABOOSE);
train1.setSecondLegStartLocation(rlArlington);
train1.setSecondLegCabooseRoad("XYZ");
// swap out caboose at Chelmsford
train1.setThirdLegOptions(Train.ADD_CABOOSE);
train1.setThirdLegStartLocation(rlChelmsford);
train1.setThirdLegCabooseRoad("XYZ");
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// confirm caboose destinations
Assert.assertEquals("Caboose is part of train", arlington, c1.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
Assert.assertEquals("Caboose is part of train", chelmsford, c3.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
Assert.assertEquals("Caboose is part of train", westford, c5.getDestination());
// now test failures by removing required cabooses
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(null, null));
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train should not build", false, train1.isBuilt());
train1.reset();
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(arlington, loc2trk1));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
train1.reset();
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(null, null));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should not build", false, train1.isBuilt());
train1.reset();
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(chelmsford, loc4trk1));
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// now test removing caboose from train
train1.setSecondLegOptions(Train.REMOVE_CABOOSE);
// need room for 1st caboose at Arlington
loc2trk1.setLength(150);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// confirm caboose destinations
Assert.assertEquals("Caboose is part of train", arlington, c1.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c3.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
Assert.assertEquals("Caboose is part of train", westford, c5.getDestination());
// now depart without a caboose, add one, then remove it, and continue to destination
train1.setRequirements(Train.NO_CABOOSE_OR_FRED);
train1.setSecondLegOptions(Train.ADD_CABOOSE);
train1.setThirdLegOptions(Train.REMOVE_CABOOSE);
// need room for caboose at Chelmsford
loc4trk1.setLength(150);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// confirm caboose destinations
Assert.assertEquals("Caboose is not part of train", null, c1.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
Assert.assertEquals("Caboose is part of train", chelmsford, c3.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
Assert.assertEquals("Caboose is part of train", null, c5.getDestination());
// try departing with FRED and swapping it for a caboose
train1.setRequirements(Train.FRED);
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train should build", true, train1.isBuilt());
// confirm destinations
Assert.assertEquals("Boxcar is part of train", arlington, f1.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c1.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c1.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
Assert.assertEquals("Caboose is part of train", chelmsford, c3.getDestination());
Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
Assert.assertEquals("Caboose is part of train", null, c5.getDestination());
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainTest method testRouteLocationsBuild.
public void testRouteLocationsBuild() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
Train train = tmanager.newTrain("Test");
// exercise manifest build
train.setRailroadName("Working Railroad");
train.setComment("One Hard Working Train");
// now add a route that doesn't have any locations
Route route = rmanager.newRoute("TestRoute");
train.setRoute(route);
// now add a location to the route
Location depart = lmanager.newLocation("depart");
RouteLocation rl = route.addLocation(depart);
train.build();
Assert.assertTrue("Train should build", train.isBuilt());
Assert.assertEquals("Train built", Train.CODE_PARTIAL_BUILT, train.getStatusCode());
// delete location
lmanager.deregister(depart);
train.build();
Assert.assertFalse("Train should not build, location deleted", train.isBuilt());
Assert.assertEquals("Train build failed", Train.CODE_BUILD_FAILED, train.getStatusCode());
// recreate location
depart = lmanager.newLocation("depart");
train.build();
Assert.assertFalse("Train should not build, location recreated, but not part of route", train.isBuilt());
route.deleteLocation(rl);
route.addLocation(depart);
train.build();
Assert.assertTrue("Train should build, route repaired", train.isBuilt());
Location terminate = lmanager.newLocation("terminate");
rl = route.addLocation(terminate);
train.build();
Assert.assertTrue("Train should build, route has two locations", train.isBuilt());
// delete terminal location
lmanager.deregister(terminate);
train.build();
Assert.assertFalse("Train should not build, terminal location deleted", train.isBuilt());
route.deleteLocation(rl);
terminate = lmanager.newLocation("terminate");
rl = route.addLocation(terminate);
train.build();
Assert.assertTrue("Train should build, route has been repaired", train.isBuilt());
Location middle = lmanager.newLocation("middle");
// staging tracks in the middle of the route are ignored
middle.addTrack("staging in the middle", Track.STAGING);
// next 5 lines exercise manifest build messages
Setup.setPrintLocationCommentsEnabled(true);
middle.setComment("Middle comment");
// put location in middle of route
rl = route.addLocation(middle, 2);
rl.setDepartureTime("12:30");
rl.setComment("This location has a departure time");
train.build();
Assert.assertTrue("Train should build, three location route", train.isBuilt());
// delete location in the middle
lmanager.deregister(middle);
train.build();
Assert.assertFalse("Train should not build, middle location deleted", train.isBuilt());
// remove the middle location from the route
route.deleteLocation(rl);
train.build();
Assert.assertTrue("Train should build, two location route", train.isBuilt());
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainTest method testAutoEnginesBuildFailNoEngines.
public void testAutoEnginesBuildFailNoEngines() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
// This test uses the maximum length of a train in route
Setup.setMaxTrainLength(1000);
Train train = tmanager.newTrain("AutoEngineTest");
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);
// Auto Engines calculates the number of engines based on requested moves in the route
train.build();
Assert.assertFalse("Train should not build, no engines", train.isBuilt());
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class JsonUtil method getRouteLocationsForTrain.
private ArrayNode getRouteLocationsForTrain(Locale locale, Train train) throws JsonException {
ArrayNode rlan = mapper.createArrayNode();
List<RouteLocation> routeList = train.getRoute().getLocationsBySequenceList();
for (RouteLocation route : routeList) {
ObjectNode rln = mapper.createObjectNode();
RouteLocation rl = route;
rln.put(ID, rl.getId());
rln.put(NAME, rl.getName());
rln.put(DIRECTION, rl.getTrainDirectionString());
rln.put(COMMENT, rl.getComment());
rln.put(SEQUENCE, rl.getSequenceId());
rln.put(EXPECTED_ARRIVAL, train.getExpectedArrivalTime(rl));
rln.put(EXPECTED_DEPARTURE, train.getExpectedDepartureTime(rl));
rln.put(LOCATION, getLocation(locale, rl.getLocation().getId()).get(DATA));
//add this routeLocation to the routeLocation array
rlan.add(rln);
}
//return array of routeLocations
return rlan;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class HtmlConductor method getLocation.
public String getLocation() throws IOException {
RouteLocation location = train.getCurrentLocation();
if (location == null) {
return String.format(locale, FileUtil.readURL(FileUtil.findURL(Bundle.getMessage(locale, "ConductorSnippet.html"))), train.getIconName(), StringEscapeUtils.escapeHtml4(train.getDescription()), StringEscapeUtils.escapeHtml4(train.getComment()), Setup.isPrintRouteCommentsEnabled() ? train.getRoute().getComment() : "", strings.getProperty(// terminated train has nothing to do // NOI18N
"Terminated"), // terminated train has nothing to do // NOI18N
"", // engines in separate section
"", // pickup=true, local=false
"", // pickup=false, local=false
"", // pickup=false, local=true
"", // engines in separate section
"", // terminate with null string, use empty string to indicate terminated
"", // NOI18N
strings.getProperty("Terminated"), train.getStatusCode());
}
List<Engine> engineList = EngineManager.instance().getByTrainBlockingList(train);
List<Car> carList = CarManager.instance().getByTrainDestinationList(train);
log.debug("Train has {} cars assigned to it", carList.size());
// pickup=true, local=false
String pickups = performWork(true, false);
// pickup=false, local=false
String setouts = performWork(false, false);
// pickup=false, local=true
String localMoves = performWork(false, true);
return String.format(locale, FileUtil.readURL(FileUtil.findURL(Bundle.getMessage(locale, "ConductorSnippet.html"))), train.getIconName(), StringEscapeUtils.escapeHtml4(train.getDescription()), StringEscapeUtils.escapeHtml4(train.getComment()), Setup.isPrintRouteCommentsEnabled() ? train.getRoute().getComment() : "", getCurrentAndNextLocation(), getLocationComments(), // engines in separate section
pickupEngines(engineList, location), pickups, setouts, localMoves, // engines in separate section
dropEngines(engineList, location), (train.getNextLocation(train.getCurrentLocation()) != null) ? train.getNextLocationName() : null, getMoveButton(), train.getStatusCode());
}
Aggregations