Skip to content

Commit

Permalink
Operations, don't allow local move to tracks with similar names
Browse files Browse the repository at this point in the history
  • Loading branch information
danielboudreau authored and danielboudreau committed Jun 5, 2021
1 parent 50fa711 commit 93960e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions java/src/jmri/jmrit/operations/trains/TrainBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3571,6 +3571,11 @@ private boolean findFinalDestinationForCarLoad(Car car) throws BuildFailedExcept
if (car.getTrack() == track || track.getSchedule() == null) {
continue;
}
// don't allow local move to track with a "similar" name
if (splitString(car.getLocationName()).equals(splitString(track.getLocation().getName())) &&
splitString(car.getTrackName()).equals(splitString(track.getName()))) {
continue;
}
if (locationsNotServiced.contains(track.getLocation())) {
continue;
}
Expand Down Expand Up @@ -3662,6 +3667,11 @@ private boolean sendCarToDestinationSpur(Car car, Track track) {
if (car.getTrack() == track) {
return false;
}
// don't allow local move to track with a "similar" name
if (splitString(car.getLocationName()).equals(splitString(track.getLocation().getName())) &&
splitString(car.getTrackName()).equals(splitString(track.getName()))) {
return false;
}
// is the car's destination the terminal and is that allowed?
if (!checkThroughCarsAllowed(car, track.getLocation().getName())) {
return false;
Expand Down Expand Up @@ -3774,6 +3784,11 @@ private boolean sendCarToDestinationTrack(Car car, Track track) {
if (car.getTrack() == track) {
return false;
}
// don't allow local move to track with a "similar" name
if (splitString(car.getLocationName()).equals(splitString(track.getLocation().getName())) &&
splitString(car.getTrackName()).equals(splitString(track.getName()))) {
return false;
}
if (track.isStaging() && car.getLocation() == track.getLocation()) {
return false; // don't use same staging location
}
Expand Down
25 changes: 24 additions & 1 deletion java/test/jmri/jmrit/operations/trains/TrainBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14322,7 +14322,7 @@ public void testCarOrderLIFO() {
}

/**
* Confirms that car with custom load in staging get routed to the correct spur
* Confirms that car with custom load gets routed to the correct spur
* that has a schedule demanding the car's type and load.
*/
@Test
Expand Down Expand Up @@ -14521,6 +14521,8 @@ public void testFindFinalDestinationForCarLoadD() {
Location eastend = lmanager.newLocation("Eastend");

Track westendSpur1 = westend.getTrackByName("Westend spur 1", null);
Track westendSpur2 = westend.addTrack("Westend spur 1-2", Track.SPUR);
westendSpur2.setLength(200);
Track westendInterchange1 = westend.getTrackByName("Westend interchange 1", null);
Track midtownSpur1 = midtown.getTrackByName("Midtown spur 1", null);
Track midtownSpur2 = midtown.getTrackByName("Midtown spur 2", null);
Expand All @@ -14542,6 +14544,7 @@ public void testFindFinalDestinationForCarLoadD() {
// program
Schedule sch1 = smanager.getScheduleByName("Schedule for car load");
westendSpur1.setSchedule(sch1); // now all spurs have schedules
westendSpur2.setSchedule(sch1);

new TrainBuilder().build(train);
Assert.assertTrue(train.isBuilt());
Expand All @@ -14551,6 +14554,7 @@ public void testFindFinalDestinationForCarLoadD() {

// confirm track move counts are correct
Assert.assertEquals("Westend spur 1", 1, westendSpur1.getMoves());
Assert.assertEquals("Westend spur 2", 0, westendSpur2.getMoves());
Assert.assertEquals("Midtown spur 1", 20, midtownSpur1.getMoves());
Assert.assertEquals("Midtown spur 2", 40, midtownSpur2.getMoves());
Assert.assertEquals("Eastend spur 1", 60, eastendSpur1.getMoves());
Expand All @@ -14567,9 +14571,28 @@ public void testFindFinalDestinationForCarLoadD() {

// confirm track move counts are correct
Assert.assertEquals("Westend spur 1", 1, westendSpur1.getMoves());
Assert.assertEquals("Westend spur 2", 0, westendSpur2.getMoves());
Assert.assertEquals("Midtown spur 1", 21, midtownSpur1.getMoves());
Assert.assertEquals("Midtown spur 2", 40, midtownSpur2.getMoves());
Assert.assertEquals("Eastend spur 1", 60, eastendSpur1.getMoves());

// allow local moves, place car on spur with "Similar" name
train.reset();
train.setAllowLocalMovesEnabled(true);
c1.setLocation(westend, westendSpur1);

new TrainBuilder().build(train);
Assert.assertTrue(train.isBuilt());

// confirm that car destination is correct
Assert.assertEquals("car destination is midtown spur 1", midtownSpur1, c1.getDestinationTrack());

// confirm track move counts are correct
Assert.assertEquals("Westend spur 1", 1, westendSpur1.getMoves());
Assert.assertEquals("Westend spur 2", 0, westendSpur2.getMoves());
Assert.assertEquals("Midtown spur 1", 22, midtownSpur1.getMoves());
Assert.assertEquals("Midtown spur 2", 40, midtownSpur2.getMoves());
Assert.assertEquals("Eastend spur 1", 60, eastendSpur1.getMoves());

JUnitOperationsUtil.checkOperationsShutDownTask();
}
Expand Down

0 comments on commit 93960e0

Please sign in to comment.