use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilder method removeRollingStockFromTrain.
private void removeRollingStockFromTrain(RollingStock rs) {
// adjust train length and weight for each location that the rolling stock is in the train
boolean inTrain = false;
for (RouteLocation routeLocation : _routeList) {
if (rs.getRouteLocation() == routeLocation) {
inTrain = true;
}
if (rs.getRouteDestination() == routeLocation) {
break;
}
if (inTrain) {
// couplers are included
routeLocation.setTrainLength(routeLocation.getTrainLength() - rs.getTotalLength());
routeLocation.setTrainWeight(routeLocation.getTrainWeight() - rs.getAdjustedWeightTons());
}
}
// remove this rolling stock from the train
rs.reset();
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilder method checkNumnberOfEnginesNeeded.
/**
* Checks to see if additional engines are needed for the train based on the
* train's calculated tonnage. Minimum speed for the train is fixed at 36
* MPH. The formula HPT x 12 / % Grade = Speed, is used to determine the
* horsepower needed. For example a 1% grade requires a minimum of 3 HPT.
*
*/
private void checkNumnberOfEnginesNeeded() throws BuildFailedException {
if (_reqNumEngines == 0 || !_train.isBuildConsistEnabled() || Setup.getHorsePowerPerTon() == 0) {
return;
}
addLine(_buildReport, ONE, BLANK_LINE);
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildDetermineNeeds"), new Object[] { Setup.getHorsePowerPerTon() }));
Route route = _train.getRoute();
int hpAvailable = 0;
int extraHpNeeded = 0;
RouteLocation rlNeedHp = null;
RouteLocation rlStart = _train.getTrainDepartsRouteLocation();
RouteLocation rlEnd = _train.getTrainTerminatesRouteLocation();
if (route != null) {
boolean helper = false;
for (RouteLocation rl : route.getLocationsBySequenceList()) {
if ((_train.getSecondLegOptions() == Train.HELPER_ENGINES && rl == _train.getSecondLegStartLocation()) || (_train.getThirdLegOptions() == Train.HELPER_ENGINES && rl == _train.getThirdLegStartLocation())) {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("AddHelpersAt"), new Object[] { rl.getName() }));
helper = true;
}
if ((_train.getSecondLegOptions() == Train.HELPER_ENGINES && rl == _train.getSecondLegEndLocation()) || (_train.getThirdLegOptions() == Train.HELPER_ENGINES && rl == _train.getThirdLegEndLocation())) {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("RemoveHelpersAt"), new Object[] { rl.getName() }));
helper = false;
}
if (helper) {
continue;
}
// check for a change of engines in the train's route
if (((_train.getSecondLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES && rl == _train.getSecondLegStartLocation()) || ((_train.getThirdLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES && rl == _train.getThirdLegStartLocation())) {
log.debug("Loco change at ({})", rl.getName());
addLocos(hpAvailable, extraHpNeeded, rlNeedHp, rlStart, rl);
addLine(_buildReport, THREE, BLANK_LINE);
// reset for next leg of train's route
rlStart = rl;
rlNeedHp = null;
extraHpNeeded = 0;
}
int weight = rl.getTrainWeight();
if (weight > 0) {
double hptMinimum = Setup.getHorsePowerPerTon();
double hptGrade = (36 * rl.getGrade() / 12);
int hp = _train.getTrainHorsePower(rl);
int hpt = hp / weight;
if (hptGrade > hptMinimum) {
hptMinimum = hptGrade;
}
if (hptMinimum > hpt) {
int addHp = (int) (hptMinimum * weight - hp);
if (addHp > extraHpNeeded) {
hpAvailable = hp;
extraHpNeeded = addHp;
rlNeedHp = rl;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildAddLocosStatus"), new Object[] { weight, hp, rl.getGrade(), hpt, hptMinimum, rl.getName(), rl.getId() }));
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildTrainRequiresAddHp"), new Object[] { addHp, rl.getName(), hptMinimum }));
addLine(_buildReport, SEVEN, BLANK_LINE);
}
}
}
}
addLocos(hpAvailable, extraHpNeeded, rlNeedHp, rlStart, rlEnd);
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildDoneAssingEnginesTrain"), new Object[] { _train.getName() }));
addLine(_buildReport, THREE, BLANK_LINE);
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilder method setLocoDestination.
private boolean setLocoDestination(Engine engine, RouteLocation rl, RouteLocation rld, Track terminateTrack) {
// is there a staging track?
if (terminateTrack != null) {
String status = engine.testDestination(terminateTrack.getLocation(), terminateTrack);
if (status.equals(Track.OKAY)) {
addEngineToTrain(engine, rl, rld, terminateTrack);
// done
return true;
} else {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropEngineToTrack"), new Object[] { engine.toString(), terminateTrack.getName(), status, terminateTrack.getTrackTypeName() }));
}
// find a destination track for this engine
} else {
Location destination = rld.getLocation();
List<Track> destTracks = destination.getTrackByMovesList(null);
if (destTracks.size() == 0) {
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildNoTracksAtDestination"), new Object[] { rld.getName() }));
}
for (Track track : destTracks) {
if (!checkDropTrainDirection(engine, rld, track)) {
continue;
}
String status = engine.testDestination(destination, track);
if (status.equals(Track.OKAY)) {
addEngineToTrain(engine, rl, rld, track);
// done
return true;
} else {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropEngineToTrack"), new Object[] { engine.toString(), track.getName(), status, track.getTrackTypeName() }));
}
}
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildCanNotDropEngToDest"), new Object[] { engine.toString(), rld.getName() }));
}
// not able to set loco's destination
return false;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class AutomationManagerTest method testCopyAutomation.
/**
* Creates an automation with 5 items, and checks to see if all items
* are copied correctly.
*/
public void testCopyAutomation() {
AutomationManager manager = AutomationManager.instance();
Assert.assertNotNull("test creation", manager);
Automation automation = manager.newAutomation("TestAutomation");
automation.setComment("test comment for automation");
Assert.assertEquals(1, manager.getSize());
AutomationItem item1 = automation.addItem();
item1.setAction(new BuildTrainAction());
item1.setTrain(new Train("trainId", "trainName1"));
item1.setMessage("item1 OK message");
item1.setMessageFail("item1 fail message");
item1.setHaltFailureEnabled(false);
AutomationItem item2 = automation.addItem();
item2.setAction(new GotoAction());
item2.setGotoAutomationItem(item1);
AutomationItem item3 = automation.addItem();
item3.setAction(new MoveTrainAction());
item3.setTrain(new Train("trainId", "trainName2"));
item3.setRouteLocation(new RouteLocation("id", new Location("id", "testLocationName")));
AutomationItem item4 = automation.addItem();
item4.setAction(new ActivateTimetableAction());
TrainSchedule trainSchedule = TrainScheduleManager.instance().newSchedule("train schedule name");
item4.setOther(trainSchedule);
AutomationItem item5 = automation.addItem();
item5.setAction(new RunAutomationAction());
Automation automationToRun = manager.newAutomation("TestAutomation2");
item5.setOther(automationToRun);
item5.setMessage("item5 OK message");
item5.setMessageFail("item5 fail message");
item5.setHaltFailureEnabled(false);
Automation copy = manager.copyAutomation(automation, "Copy");
Assert.assertNotNull("test automation creation", copy);
// There are now three automations
Assert.assertEquals("The number of automations", 3, manager.getSize());
Assert.assertEquals("The number of items", 5, copy.getSize());
Assert.assertEquals(copy.getComment(), automation.getComment());
AutomationItem copyItem1 = copy.getItemBySequenceId(1);
Assert.assertEquals("1st item is build train", copyItem1.getActionName(), item1.getActionName());
Assert.assertNotNull(copyItem1.getTrain());
Assert.assertNull(copyItem1.getGotoAutomationItem());
Assert.assertNull(copyItem1.getTrainSchedule());
Assert.assertNull(copyItem1.getRouteLocation());
Assert.assertEquals(copyItem1.getTrain(), item1.getTrain());
Assert.assertEquals("item1 OK message", copyItem1.getMessage());
Assert.assertEquals("item1 fail message", copyItem1.getMessageFail());
Assert.assertNull(copyItem1.getAutomationToRun());
Assert.assertFalse(copyItem1.isHaltFailureEnabled());
AutomationItem copyItem2 = copy.getItemBySequenceId(2);
Assert.assertEquals("2nd item is goto", copyItem2.getActionName(), item2.getActionName());
Assert.assertNull(copyItem2.getTrain());
Assert.assertNotNull(copyItem2.getGotoAutomationItem());
Assert.assertNull(copyItem2.getTrainSchedule());
Assert.assertNull(copyItem2.getRouteLocation());
Assert.assertEquals(copyItem2.getGotoAutomationItem().getActionName(), item2.getGotoAutomationItem().getActionName());
Assert.assertNull(copyItem2.getAutomationToRun());
Assert.assertEquals("", copyItem2.getMessage());
Assert.assertEquals("", copyItem2.getMessageFail());
Assert.assertTrue(copyItem2.isHaltFailureEnabled());
AutomationItem copyItem3 = copy.getItemBySequenceId(3);
Assert.assertEquals("3rd item is move train", copyItem3.getActionName(), item3.getActionName());
Assert.assertNotNull(copyItem3.getTrain());
Assert.assertNull(copyItem3.getGotoAutomationItem());
Assert.assertNull(copyItem3.getTrainSchedule());
Assert.assertNotNull(copyItem3.getRouteLocation());
Assert.assertEquals(copyItem3.getTrain(), item3.getTrain());
Assert.assertEquals(copyItem3.getRouteLocation(), item3.getRouteLocation());
Assert.assertNull(copyItem3.getAutomationToRun());
Assert.assertEquals("", copyItem3.getMessage());
Assert.assertEquals("", copyItem3.getMessageFail());
Assert.assertTrue(copyItem3.isHaltFailureEnabled());
AutomationItem copyItem4 = copy.getItemBySequenceId(4);
Assert.assertEquals("4th item is activate train schedule", copyItem4.getActionName(), item4.getActionName());
Assert.assertNull(copyItem4.getTrain());
Assert.assertNull(copyItem4.getGotoAutomationItem());
Assert.assertNull(copyItem4.getRouteLocation());
Assert.assertNotNull(copyItem4.getTrainSchedule());
Assert.assertEquals(trainSchedule, copyItem4.getTrainSchedule());
Assert.assertNull(copyItem4.getAutomationToRun());
Assert.assertEquals("", copyItem4.getMessage());
Assert.assertEquals("", copyItem4.getMessageFail());
Assert.assertTrue(copyItem4.isHaltFailureEnabled());
AutomationItem copyItem5 = copy.getItemBySequenceId(5);
Assert.assertEquals("5th item is run automation", copyItem5.getActionName(), item5.getActionName());
Assert.assertNull(copyItem5.getTrain());
Assert.assertNull(copyItem5.getGotoAutomationItem());
Assert.assertNull(copyItem5.getRouteLocation());
Assert.assertNull(copyItem5.getTrainSchedule());
Assert.assertNotNull(copyItem5.getAutomationToRun());
Assert.assertEquals(automationToRun, copyItem5.getAutomationToRun());
Assert.assertEquals("item5 OK message", copyItem5.getMessage());
Assert.assertEquals("item5 fail message", copyItem5.getMessageFail());
Assert.assertFalse(copyItem5.isHaltFailureEnabled());
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class AutomationItemTest method testRouteLocation.
public void testRouteLocation() {
AutomationItem automationItem = new AutomationItem("TestId");
Assert.assertNotNull("test creation", automationItem);
Assert.assertEquals("test id", "TestId", automationItem.getId());
RouteLocation rl = new RouteLocation("testId", new Location("testId", "testLocationName"));
automationItem.setRouteLocation(rl);
Assert.assertEquals("Do nothing action can't have a routeLocation", null, automationItem.getRouteLocation());
automationItem.setAction(new WaitTrainAction());
Assert.assertEquals(rl, automationItem.getRouteLocation());
}
Aggregations