Search in sources :

Example 91 with RouteLocation

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

the class TrainTest method testSidingsYards.

// test siding and yard moves
// tests manual setting of destinations and trains for engines, cars, and cabooses.
// tests consists and kernels
public void testSidingsYards() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    // 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("FF");
    t1.setRoute(r1);
    t1.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    Assert.assertFalse("train built 6", t1.isBuilt());
    // set caboose to train TT
    c1.setTrain(t1);
    t1.build();
    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.build();
    Assert.assertTrue("train built 8", t1.isBuilt());
    Assert.assertEquals("5 Destination e1", "Foxboro", e1.getDestinationName());
    Assert.assertEquals("5 Destination e2", "Foxboro", e2.getDestinationName());
    t1.reset();
    // assign lead engine to train TT
    e1.setTrain(t2);
    // should fail
    t1.build();
    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.build();
    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.build();
    Assert.assertFalse("train built 11", t1.isBuilt());
    e1.setDestination(l1, l1s2);
    // program should ignore
    e2.setDestination(l2, l2s1);
    // should build
    t1.build();
    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.build();
    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.build();
    // 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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    Assert.assertFalse("train built 18", t1.isBuilt());
    // set car with FRED to train TT
    c2.setTrain(t1);
    t1.build();
    Assert.assertTrue("train built 19", t1.isBuilt());
    // test car out of service
    c2.setOutOfService(true);
    t1.build();
    Assert.assertFalse("required car is out of service", t1.isBuilt());
    // test location unknown
    c2.setOutOfService(false);
    c2.setLocationUnknown(true);
    t1.build();
    Assert.assertFalse("required car location is unknown", t1.isBuilt());
    c2.setLocationUnknown(false);
    t1.build();
    Assert.assertTrue("need car is available", t1.isBuilt());
    c2.setWait(1);
    t1.build();
    Assert.assertFalse("required car will wait for next train", t1.isBuilt());
    t1.build();
    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.build();
    // 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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    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.build();
    Assert.assertFalse("need car doesn't have a track assignment", t1.isBuilt());
// end testSidingsYards
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) 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) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 92 with RouteLocation

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

the class TrainTest method testInterchange.

public void testInterchange() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    Setup.setMaxTrainLength(500);
    ct.addName("Boxcar");
    ct.addName("Gon");
    ct.addName("Coil Car");
    ct.addName("Flat Car");
    ct.addName("XCaboose");
    // confirm no locations
    Assert.assertEquals("number of locations", 0, lmanager.getNumberOfLocations());
    // Create locations used
    Location loc1;
    loc1 = lmanager.newLocation("Old Westford");
    loc1.setTrainDirections(DIRECTION_ALL);
    Location loc2;
    loc2 = lmanager.newLocation("Old Chelmsford");
    loc2.setTrainDirections(DIRECTION_ALL);
    Location loc3;
    loc3 = lmanager.newLocation("Old Bedford");
    loc3.setTrainDirections(DIRECTION_ALL);
    Track loc1trk1;
    loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
    loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk1.setLength(900);
    Track loc1trk2;
    loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
    loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc1trk2.setLength(500);
    loc1trk2.deleteTypeName("Coil Car");
    loc1trk2.deleteTypeName("XCaboose");
    Track loc2trk1;
    loc2trk1 = loc2.addTrack("Chelmsford Interchange 1", Track.INTERCHANGE);
    loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk1.setLength(900);
    loc2trk1.deleteTypeName("Coil Car");
    loc2trk1.deleteTypeName("XCaboose");
    Track loc2trk2;
    loc2trk2 = loc2.addTrack("Chelmsford Interchange 2", Track.INTERCHANGE);
    loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk2.setLength(900);
    loc2trk2.deleteTypeName("XCaboose");
    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");
    loc2trk3.deleteTypeName("XCaboose");
    Track loc2trk4;
    loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
    loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
    loc2trk4.setLength(900);
    loc2trk4.deleteTypeName("Gon");
    loc2trk4.deleteTypeName("XCaboose");
    // bias interchange tracks
    loc2trk3.setMoves(20);
    loc2trk4.setMoves(20);
    Track loc3trk1;
    loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.YARD);
    loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
    loc3trk1.setLength(900);
    // Create route with 3 location
    Route rte1;
    rte1 = rmanager.newRoute("Route 1 East");
    RouteLocation r1l1 = rte1.addLocation(loc1);
    r1l1.setTrainDirection(RouteLocation.EAST);
    r1l1.setMaxCarMoves(4);
    // set the train icon coordinates
    r1l1.setTrainIconX(125);
    r1l1.setTrainIconY(100);
    RouteLocation r1l2 = rte1.addLocation(loc2);
    r1l2.setTrainDirection(RouteLocation.EAST);
    r1l2.setMaxCarMoves(3);
    // set the train icon coordinates
    r1l2.setTrainIconX(25);
    r1l2.setTrainIconY(125);
    RouteLocation r1l3 = rte1.addLocation(loc3);
    r1l3.setTrainDirection(RouteLocation.EAST);
    r1l3.setMaxCarMoves(3);
    // set the train icon coordinates
    r1l3.setTrainIconX(75);
    r1l3.setTrainIconY(125);
    // Create route with 3 location
    Route rte2;
    rte2 = rmanager.newRoute("Route 2 East");
    RouteLocation r2l1 = rte2.addLocation(loc1);
    r2l1.setTrainDirection(RouteLocation.EAST);
    r2l1.setMaxCarMoves(2);
    // set the train icon coordinates
    r2l1.setTrainIconX(125);
    r2l1.setTrainIconY(125);
    RouteLocation r2l2 = rte2.addLocation(loc2);
    r2l2.setTrainDirection(RouteLocation.EAST);
    r2l2.setMaxCarMoves(6);
    // set the train icon coordinates
    r2l2.setTrainIconX(175);
    r2l2.setTrainIconY(125);
    RouteLocation r2l3 = rte2.addLocation(loc3);
    r2l3.setTrainDirection(RouteLocation.EAST);
    r2l3.setMaxCarMoves(6);
    // set the train icon coordinates
    r2l3.setTrainIconX(25);
    r2l3.setTrainIconY(150);
    // Create trains
    Train train1;
    train1 = tmanager.newTrain("TT1OWOB");
    train1.setRoute(rte1);
    Train train2;
    train2 = tmanager.newTrain("TT2OWOB");
    train2.setRoute(rte1);
    Train train3;
    train3 = tmanager.newTrain("TT3OWOB");
    train3.setRoute(rte1);
    // Set up 7 box cars and 2 flat cars
    Car c1 = new Car("BM", "Q1");
    c1.setTypeName("Gon");
    c1.setLength("90");
    c1.setMoves(20);
    c1.setLoadName("L");
    c1.setWeightTons("10");
    cmanager.register(c1);
    Car c2 = new Car("UP", "Q2");
    c2.setTypeName("Boxcar");
    c2.setLength("80");
    c2.setMoves(18);
    c2.setWeightTons("20");
    cmanager.register(c2);
    Car c3 = new Car("XP", "Q3");
    c3.setTypeName("Flat Car");
    c3.setLength("70");
    c3.setMoves(17);
    c3.setWeightTons("30");
    cmanager.register(c3);
    Car c4 = new Car("PU", "Q4");
    c4.setTypeName("Boxcar");
    c4.setLength("60");
    c4.setMoves(16);
    c4.setWeightTons("40");
    cmanager.register(c4);
    Car c5 = new Car("UP", "Q5");
    c5.setTypeName("Gon");
    c5.setLength("50");
    c5.setMoves(15);
    c5.setLoadName("L");
    c5.setWeightTons("50");
    cmanager.register(c5);
    Car c6 = new Car("CP", "Q6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(14);
    c6.setLoadName("L");
    c6.setWeightTons("60");
    cmanager.register(c6);
    Car c7 = new Car("UP", "Q7");
    c7.setTypeName("Boxcar");
    c7.setLength("50");
    c7.setMoves(13);
    c7.setWeightTons("70");
    cmanager.register(c7);
    Car c8 = new Car("XP", "Q8");
    c8.setTypeName("Gon");
    c8.setLength("60");
    c8.setMoves(12);
    c8.setWeightTons("80");
    cmanager.register(c8);
    Car c9 = new Car("XP", "Q9");
    c9.setTypeName("Flat Car");
    c9.setLength("90");
    c9.setMoves(11);
    c9.setLoadName("L");
    c9.setWeightTons("90");
    cmanager.register(c9);
    Car c10 = new Car("CP", "Q10");
    c10.setTypeName("Coil Car");
    c10.setLength("40");
    c10.setMoves(8);
    c10.setLoadName("L");
    c10.setWeightTons("100");
    cmanager.register(c10);
    Car c11 = new Car("CP", "Q11");
    c11.setTypeName("Coil Car");
    c11.setLength("40");
    c11.setMoves(9);
    c11.setLoadName("Coils");
    c11.setWeightTons("110");
    cmanager.register(c11);
    Car c12 = new Car("CP", "Q12");
    c12.setTypeName("Coil Car");
    c12.setLength("40");
    c12.setMoves(10);
    c12.setWeightTons("120");
    cmanager.register(c12);
    Car c13 = new Car("CP", "Q13");
    c13.setTypeName("XCaboose");
    c13.setCaboose(true);
    c13.setLength("40");
    c13.setMoves(7);
    c13.setWeightTons("130");
    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, loc1trk1));
    train1.build();
    train2.build();
    // now check to where cars are going to be delivered
    Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination", "", c4.getDestinationTrackName());
    Assert.assertEquals("c9 destination", "Chelmsford Interchange 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination", "Bedford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination", "Chelmsford Interchange 2", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination", "Bedford Yard 1", c12.getDestinationTrackName());
    Assert.assertEquals("c5 destination", "Chelmsford Interchange 2", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination", "Bedford Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination", "Chelmsford Interchange 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination", "Bedford Yard 1", c8.getDestinationTrackName());
    // now check which trains
    Assert.assertEquals("c9 train", train1, c9.getTrain());
    Assert.assertEquals("c10 train", train1, c10.getTrain());
    Assert.assertEquals("c11 train", train1, c11.getTrain());
    Assert.assertEquals("c12 train", train1, c12.getTrain());
    Assert.assertEquals("c5 train", train2, c5.getTrain());
    Assert.assertEquals("c6 train", train2, c6.getTrain());
    Assert.assertEquals("c7 train", train2, c7.getTrain());
    Assert.assertEquals("c8 train", train2, c8.getTrain());
    // try restricting interchange 1 to train1 and interchange 2 to train2
    loc2trk1.setDropOption(Track.TRAINS);
    loc2trk1.addDropId(train1.getId());
    loc2trk2.setDropOption(Track.TRAINS);
    loc2trk2.addDropId(train2.getId());
    train1.build();
    train2.build();
    // now check to where cars are going to be delivered
    Assert.assertEquals("c1 destination", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination", "", c3.getDestinationTrackName());
    Assert.assertEquals("c5 destination", "", c5.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Chelmsford Interchange 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "Bedford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "Bedford Yard 1", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination 2", "Chelmsford Freight 4", c12.getDestinationTrackName());
    Assert.assertEquals("c4 destination 2", "Chelmsford Interchange 2", c4.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "Bedford Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Chelmsford Interchange 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Bedford Yard 1", c8.getDestinationTrackName());
    // now check which trains
    Assert.assertEquals("c9 train", train1, c9.getTrain());
    Assert.assertEquals("c10 train", train1, c10.getTrain());
    Assert.assertEquals("c11 train", train1, c11.getTrain());
    Assert.assertEquals("c12 train", train1, c12.getTrain());
    Assert.assertEquals("c4 train", train2, c4.getTrain());
    Assert.assertEquals("c6 train", train2, c6.getTrain());
    Assert.assertEquals("c7 train", train2, c7.getTrain());
    Assert.assertEquals("c8 train", train2, c8.getTrain());
    // move and terminate
    Assert.assertEquals("Check train 1 departure location name", "Old Westford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 departure location", r1l1, train1.getCurrentLocation());
    // #1
    train1.move();
    Assert.assertEquals("Check train 1 location name", "Old Chelmsford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", r1l2, train1.getCurrentLocation());
    // #2
    train1.move();
    Assert.assertEquals("Check train 1 location name", "Old Bedford", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", r1l3, train1.getCurrentLocation());
    // #3 terminate
    train1.move();
    Assert.assertEquals("Check train 1 location name", "", train1.getCurrentLocationName());
    Assert.assertEquals("Check train 1 location", null, train1.getCurrentLocation());
    Assert.assertEquals("Check train 2 departure location name", "Old Westford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 departure location", r1l1, train2.getCurrentLocation());
    // #1
    train2.move();
    Assert.assertEquals("Check train 2 location name", "Old Chelmsford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", r1l2, train2.getCurrentLocation());
    // #2
    train2.move();
    Assert.assertEquals("Check train 2 location name", "Old Bedford", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", r1l3, train2.getCurrentLocation());
    // #3 terminate
    train2.move();
    Assert.assertEquals("Check train 2 location name", "", train2.getCurrentLocationName());
    Assert.assertEquals("Check train 2 location", null, train2.getCurrentLocation());
    r1l1.setMaxCarMoves(2);
    r1l2.setMaxCarMoves(6);
    r1l3.setMaxCarMoves(6);
    // note that train3 uses rte1, should not pickup cars at interchange
    train3.build();
    Assert.assertEquals("c1 destination 3", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 3", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 3", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 3", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 3", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 3", "", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 3", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 3", "", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 3", "Bedford Yard 1", c12.getDestinationTrackName());
    // Change the route to 2, should be able to pickup c4, c7, c9
    train3.reset();
    train3.setRoute(rte2);
    // confirm that c2 and c3 have the same move counts
    Assert.assertEquals("c2 move count", 18, c2.getMoves());
    Assert.assertEquals("c3 move count", 18, c3.getMoves());
    Assert.assertEquals("c4 move count", 17, c4.getMoves());
    // bias c2
    c2.setMoves(19);
    train3.build();
    Assert.assertEquals("c1 destination 4", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 4", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 4", "Chelmsford Yard 3", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 4", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 4", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 4", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 4", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 4", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 4", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 4", "Bedford Yard 1", c12.getDestinationTrackName());
    // bias c3
    c3.setMoves(20);
    // Change back to route to 1, should be able to pickup c4, c7
    train3.reset();
    train3.setRoute(rte1);
    loc2trk2.setPickupOption(Track.TRAINS);
    loc2trk2.addPickupId(train3.getId());
    train3.build();
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "Chelmsford Freight 4", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 5", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 5", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 5", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 5", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 5", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 5", "Bedford Yard 1", c12.getDestinationTrackName());
    // check car move counts
    Assert.assertEquals("c1 move count", 20, c1.getMoves());
    Assert.assertEquals("c2 move count", 19, c2.getMoves());
    Assert.assertEquals("c3 move count", 21, c3.getMoves());
    Assert.assertEquals("c4 move count", 18, c4.getMoves());
    Assert.assertEquals("c5 move count", 18, c5.getMoves());
    Assert.assertEquals("c6 move count", 16, c6.getMoves());
    Assert.assertEquals("c7 move count", 16, c7.getMoves());
    Assert.assertEquals("c8 move count", 14, c8.getMoves());
    Assert.assertEquals("c9 move count", 14, c9.getMoves());
    Assert.assertEquals("c12 move count", 14, c12.getMoves());
    c1.setMoves(19);
    // Change back to route to 1, should be able to pickup c4, c7, and c9
    train3.reset();
    train3.setRoute(rte1);
    loc2trk1.setPickupOption(Track.ROUTES);
    loc2trk1.addPickupId(rte1.getId());
    train3.build();
    Assert.assertEquals("c1 destination 6", "Bedford Yard 1", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 6", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 6", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 6", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 6", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 6", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 6", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 6", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 6", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 6", "", c11.getDestinationTrackName());
    Assert.assertEquals("c12 destination 6", "Bedford Yard 1", c12.getDestinationTrackName());
    // now allow train 3 to drop
    train3.reset();
    loc2trk1.setDropOption(Track.ROUTES);
    loc2trk1.addDropId(rte1.getId());
    c5.setMoves(19);
    c2.setMoves(20);
    c1.setMoves(21);
    train3.build();
    Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 7", "Chelmsford Interchange 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 7", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 7", "Bedford Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 7", "Bedford Yard 1", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 7", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 7", "Bedford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 7", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 7", "Bedford Yard 1", c9.getDestinationTrackName());
    Assert.assertEquals("c12 destination 7", "Bedford Yard 1", c12.getDestinationTrackName());
    // move and terminate
    train3.move();
    train3.move();
    train3.move();
    train3.move();
    // check tracks
    Assert.assertEquals("c1 track", "Westford Yard 1", c1.getTrackName());
    Assert.assertEquals("c2 track", "Chelmsford Interchange 1", c2.getTrackName());
    Assert.assertEquals("c3 track", "Westford Yard 1", c3.getTrackName());
    Assert.assertEquals("c4 track", "Bedford Yard 1", c4.getTrackName());
    Assert.assertEquals("c5 track", "Bedford Yard 1", c5.getTrackName());
    Assert.assertEquals("c6 track", "Bedford Yard 1", c6.getTrackName());
    Assert.assertEquals("c7 track", "Bedford Yard 1", c7.getTrackName());
    Assert.assertEquals("c8 track", "Bedford Yard 1", c8.getTrackName());
    Assert.assertEquals("c9 track", "Bedford Yard 1", c9.getTrackName());
    Assert.assertEquals("c10 track", "Bedford Yard 1", c10.getTrackName());
    Assert.assertEquals("c11 track", "Bedford Yard 1", c11.getTrackName());
    Assert.assertEquals("c12 track", "Bedford Yard 1", c12.getTrackName());
    // check train length and tonnage
    Assert.assertEquals("Depart Westford length", 138, r1l1.getTrainLength());
    Assert.assertEquals("Depart Old Chelmsford length", 310, r1l2.getTrainLength());
    // In train 2 cars, c2 E and c5 L car weight 20/3 + 50 = 56
    Assert.assertEquals("Depart Old Westford tonnage", 56, r1l1.getTrainWeight());
    // In train 5 cars, c4 E, c5 L, c7 E, c9 L, c12 L = 40/3 + 50 + 70/3 + 90 + 120 = 296
    Assert.assertEquals("Depart Old Chelmsford tonnage", 296, r1l2.getTrainWeight());
    // test route pickup and drop controls
    train3.setRequirements(Train.CABOOSE);
    r1l1.setPickUpAllowed(false);
    c1.setMoves(10);
    c3.setMoves(21);
    train3.build();
    Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 8", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 8", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 8", "Bedford Yard 1", c13.getDestinationTrackName());
    r1l1.setPickUpAllowed(true);
    r1l2.setPickUpAllowed(false);
    train3.build();
    Assert.assertEquals("c1 destination 9", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 9", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 9", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 9", "Bedford Yard 1", c13.getDestinationTrackName());
    r1l2.setPickUpAllowed(true);
    // Old Chelmsford
    r1l2.setDropAllowed(false);
    train3.build();
    Assert.assertEquals("c1 destination 10", "Bedford Yard 1", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 10", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 10", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 10", "Bedford Yard 1", c13.getDestinationTrackName());
    train3.reset();
    // try forcing c1 to Chelmsford
    c1.setDestination(loc2, null);
    train3.build();
    Assert.assertEquals("c1 destination Old Chelmsford", "", c1.getDestinationTrackName());
    // confirm that c1 isn't part of this train
    Assert.assertNull("c1 isn't assigned to a train", c1.getTrain());
    Assert.assertNull("c1 destination has been set to null", c1.getDestination());
    Assert.assertNull("c1 next destination should be null", c1.getFinalDestination());
    Assert.assertNull("c1 next destination track should be null", c1.getFinalDestinationTrack());
    // try without moves
    r1l2.setDropAllowed(true);
    r1l2.setMaxCarMoves(0);
    c1.setDestination(loc2, null);
    train3.build();
    Assert.assertEquals("c1 destination Old Chelmsford, no moves", "", c1.getDestinationTrackName());
    c1.setDestination(null, null);
    r1l2.setMaxCarMoves(6);
    // Should be able to drop off caboose
    r1l3.setDropAllowed(false);
    train3.build();
    Assert.assertEquals("c1 destination 11", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c5 destination 11", "", c5.getDestinationTrackName());
    Assert.assertEquals("c3 destination 11", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 11", "Bedford Yard 1", c13.getDestinationTrackName());
    // test to see if FRED also get delivered
    train3.setRequirements(Train.FRED);
    Assert.assertEquals("Place c2 at start of route", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    c2.setFred(true);
    train3.build();
    Assert.assertTrue("Train 3 built", train3.isBuilt());
    Assert.assertEquals("c1 destination 12", "Chelmsford Interchange 1", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 12", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 12", "", c3.getDestinationTrackName());
    Assert.assertEquals("c13 destination 12", "", c13.getDestinationTrackName());
    // move and terminate
    train3.move();
    train3.move();
    train3.move();
    train3.move();
    Assert.assertEquals("c1 track 12", "Chelmsford Interchange 1", c1.getTrackName());
    Assert.assertEquals("c2 track 12", "Bedford Yard 1", c2.getTrackName());
    Assert.assertEquals("c3 track 12", "Westford Yard 1", c3.getTrackName());
    Assert.assertEquals("c13 track 12", "Westford Yard 1", c13.getTrackName());
    // test previous car delivered pickup interchange operation
    loc2trk1.setDropOption(Track.ANY);
    loc2trk1.setPickupOption(Track.TRAINS);
    loc2trk2.setDropOption(Track.ANY);
    loc2trk2.setPickupOption(Track.TRAINS);
    // Place car with FRED back at start of route
    Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    train3.build();
    Assert.assertTrue("train 3 should build", train3.isBuilt());
    Assert.assertEquals("car BM Q1 should not be part of train", null, c1.getTrain());
    Assert.assertEquals("car XP Q3 should be part of train", train3, c3.getTrain());
    // put some cars at start of Route
    Assert.assertEquals("Place c1 again", Track.OKAY, c1.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c2 again", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c3 again", Track.OKAY, c3.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c4 again", Track.OKAY, c4.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c6 again", Track.OKAY, c6.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c7 again", Track.OKAY, c7.setLocation(loc2, loc2trk2));
    r1l1.setMaxCarMoves(5);
    loc2trk1.setDropOption(Track.ROUTES);
    loc2trk1.setPickupOption(Track.ROUTES);
    loc2trk2.setDropOption(Track.ROUTES);
    loc2trk2.setPickupOption(Track.ROUTES);
    train3.build();
    Assert.assertTrue("train 3 should build", train3.isBuilt());
    Assert.assertEquals("BM Q1 in train", null, c1.getTrain());
    Assert.assertEquals("UP Q2 in train", train3, c2.getTrain());
    Assert.assertEquals("XP Q3 in train", train3, c3.getTrain());
    Assert.assertEquals("PU Q4 in train", train3, c4.getTrain());
    Assert.assertEquals("UP Q5 in train", null, c5.getTrain());
    Assert.assertEquals("CP Q6 in train", null, c6.getTrain());
    Assert.assertEquals("UP Q7 in train", null, c7.getTrain());
    Assert.assertEquals("UP Q2 destination", "Bedford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("XP Q3 destination", "Chelmsford Freight 4", c3.getDestinationTrackName());
    Assert.assertEquals("PU Q4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName());
    Assert.assertEquals("UP Q5 destination", "", c5.getDestinationTrackName());
    // interchange testing done, now test replace car type and road
    Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    // replace should modify locations and trains
    ct.replaceName("Boxcar", "boxcar");
    Assert.assertFalse("loc1 should not accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("loc2 should not accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    Assert.assertFalse("track loc1trk1 should not accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("track loc2trk1 should not accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 1 should not accept Boxcar", train1.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 2 should not accept Boxcar", train2.acceptsTypeName("Boxcar"));
    Assert.assertFalse("train 3 should not accept Boxcar", train3.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc1 should accept boxcar", loc1.acceptsTypeName("boxcar"));
    Assert.assertTrue("loc2 should accept boxcar", loc2.acceptsTypeName("boxcar"));
    Assert.assertTrue("track loc1trk1 should accept boxcar", loc1trk1.acceptsTypeName("boxcar"));
    Assert.assertTrue("track loc2trk1 should accept boxcar", loc2trk1.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 1 should accept boxcar", train1.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 2 should accept boxcar", train2.acceptsTypeName("boxcar"));
    Assert.assertTrue("train 3 should accept boxcar", train3.acceptsTypeName("boxcar"));
    ct.replaceName("boxcar", "Boxcar");
    Assert.assertTrue("loc1 should accept Boxcar", loc1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("loc2 should accept Boxcar", loc2.acceptsTypeName("Boxcar"));
    Assert.assertTrue("track loc1trk1 should accept Boxcar", loc1trk1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("track loc2trk1 should accept Boxcar", loc2trk1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 1 should accept Boxcar", train1.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 2 should accept Boxcar", train2.acceptsTypeName("Boxcar"));
    Assert.assertTrue("train 3 should accept Boxcar", train3.acceptsTypeName("Boxcar"));
    // now test road name replace
    CarRoads cr = CarRoads.instance();
    cr.addName("CP");
    loc1trk1.setRoadOption(Track.INCLUDE_ROADS);
    loc1trk1.addRoadName("CP");
    loc1trk1.addRoadName("PC");
    train1.setRoadOption(Train.INCLUDE_ROADS);
    train1.addRoadName("CP");
    train1.addRoadName("PC");
    train1.setCabooseRoad("CP");
    train1.setEngineRoad("CP");
    Assert.assertTrue("track loc1trk1 should accept road CP", loc1trk1.acceptsRoadName("CP"));
    Assert.assertTrue("track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
    Assert.assertFalse("track loc1trk1 should Not accept road PC", loc1trk1.acceptsRoadName("UP"));
    Assert.assertTrue("Train 1 should accept road CP", train1.acceptsRoadName("CP"));
    Assert.assertTrue("Train 1 should accept road PC", train1.acceptsRoadName("PC"));
    Assert.assertFalse("Train 1 should Not accept road UP", train1.acceptsRoadName("UP"));
    Assert.assertEquals("Caboose road", "CP", train1.getCabooseRoad());
    Assert.assertEquals("Engine road", "CP", train1.getEngineRoad());
    cr.replaceName("CP", "UP");
    Assert.assertFalse("after replace track loc1trk1 should Not accept road CP", loc1trk1.acceptsRoadName("CP"));
    Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("PC"));
    Assert.assertTrue("after replace track loc1trk1 should accept road PC", loc1trk1.acceptsRoadName("UP"));
    Assert.assertFalse("after replace Train 1 should Not accept road CP", train1.acceptsRoadName("CP"));
    Assert.assertTrue("after replace Train 1 should accept road PC", train1.acceptsRoadName("PC"));
    Assert.assertTrue("after replace Train 1 should accept road UP", train1.acceptsRoadName("UP"));
    Assert.assertEquals("Caboose road", "UP", train1.getCabooseRoad());
    Assert.assertEquals("Engine road", "UP", train1.getEngineRoad());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) CarRoads(jmri.jmrit.operations.rollingstock.cars.CarRoads) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 93 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation 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());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ScheduleManager(jmri.jmrit.operations.locations.schedules.ScheduleManager) ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Kernel(jmri.jmrit.operations.rollingstock.cars.Kernel) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 94 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation 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();
}
Also used : JLabel(javax.swing.JLabel) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 95 with RouteLocation

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

the class VSDecoder method getTrainPosition.

// Methods for handling location tracking based on JMRI Operations
/**
     * Get the physical location of the given Operations Train
     *
     * @param t (Train) the Train to interrogate
     * @return PhysicalLocation location of the train
     */
protected PhysicalLocation getTrainPosition(Train t) {
    if (t == null) {
        log.debug("Train is null.");
        return (null);
    }
    RouteLocation rloc = t.getCurrentLocation();
    if (rloc == null) {
        log.debug("RouteLocation is null.");
        return (null);
    }
    Location loc = rloc.getLocation();
    if (loc == null) {
        log.debug("Location is null.");
        return (null);
    }
    return (loc.getPhysicalLocation());
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) PhysicalLocation(jmri.util.PhysicalLocation) 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