use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class ShowTrainsServingLocationFrame method updateTrainPane.
private void updateTrainPane() {
pTrains.removeAll();
int y = 0;
for (Train train : TrainManager.instance().getTrainsByNameList()) {
Route route = train.getRoute();
if (route == null) {
continue;
}
for (RouteLocation rl : route.getLocationsBySequenceList()) {
if (rl.getName().equals(_location.getName())) {
boolean pickup = false;
boolean setout = false;
// monitor move count in the route for this location
train.getRoute().removePropertyChangeListener(this);
train.getRoute().addPropertyChangeListener(this);
if (rl.isPickUpAllowed() && rl.getMaxCarMoves() > 0 && !train.skipsLocation(rl.getId()) && (typeComboBox.getSelectedItem() == null || typeComboBox.getSelectedItem().equals(NONE) || train.acceptsTypeName((String) typeComboBox.getSelectedItem())) && (train.isLocalSwitcher() || (rl.getTrainDirection() & _location.getTrainDirections()) != 0) && (train.isLocalSwitcher() || _track == null || ((rl.getTrainDirection() & _track.getTrainDirections()) != 0)) && (_track == null || _track.acceptsPickupTrain(train))) {
pickup = true;
}
if (rl.isDropAllowed() && rl.getMaxCarMoves() > 0 && !train.skipsLocation(rl.getId()) && (typeComboBox.getSelectedItem() == null || typeComboBox.getSelectedItem().equals(NONE) || train.acceptsTypeName((String) typeComboBox.getSelectedItem())) && (train.isLocalSwitcher() || (rl.getTrainDirection() & _location.getTrainDirections()) != 0) && (train.isLocalSwitcher() || _track == null || ((rl.getTrainDirection() & _track.getTrainDirections()) != 0)) && (_track == null || _track.acceptsDropTrain(train))) {
setout = true;
}
// now display results
if (showAllTrainsCheckBox.isSelected() || pickup || setout) {
addItemLeft(pTrains, new JLabel(train.getName()), 0, y);
if (pickup) {
addItem(pTrains, new JLabel(Bundle.getMessage("OkayPickUp")), 1, y);
} else {
addItem(pTrains, new JLabel(Bundle.getMessage("NoPickUp")), 1, y);
}
if (setout) {
addItem(pTrains, new JLabel(Bundle.getMessage("OkaySetOut")), 2, y);
} else {
addItem(pTrains, new JLabel(Bundle.getMessage("NoSetOut")), 2, y);
}
}
y++;
}
}
}
pTrains.repaint();
pTrains.revalidate();
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilder method checkTrainLength.
/**
* Checks to see if train length would be exceeded if this car was added to
* the train.
*
* @param car the car
* @param rl the planned origin for this car
* @param rld the planned destination for this car
* @return true if car can be added to train
*/
private boolean checkTrainLength(Car car, RouteLocation rl, RouteLocation rld) {
// car can be a kernel so get total length
int length = car.getTotalLength();
if (car.getKernel() != null) {
length = car.getKernel().getTotalLength();
}
boolean carInTrain = false;
for (RouteLocation rlt : _routeList) {
if (rl == rlt) {
carInTrain = true;
}
if (rld == rlt) {
break;
}
if (carInTrain && rlt.getTrainLength() + length > rlt.getMaxTrainLength()) {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildCanNotPickupCarLength"), new Object[] { car.toString(), length, Setup.getLengthUnit().toLowerCase() }));
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildCanNotPickupCarLength2"), new Object[] { rlt.getMaxTrainLength(), Setup.getLengthUnit().toLowerCase(), rlt.getTrainLength() + length - rlt.getMaxTrainLength(), rlt.getName(), rlt.getId() }));
return false;
}
}
return true;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method move.
/**
* Move train to a location in the train's route. Code checks to see if the
* location requested is part of the train's route and if the train hasn't
* already visited the location. This command can only move the train
* forward in its route. Note that you can not terminate the train using
* this command. See move() or terminate().
*
* @param locationName The name of the location to move this train.
* @return true if train was able to move to the named location.
*/
public boolean move(String locationName) {
log.info("Move train (" + getName() + ") to location (" + locationName + ")");
if (getRoute() == null || getCurrentLocation() == null) {
return false;
}
List<RouteLocation> routeList = getRoute().getLocationsBySequenceList();
for (int i = 0; i < routeList.size(); i++) {
RouteLocation rl = routeList.get(i);
if (getCurrentLocation() == rl) {
for (int j = i + 1; j < routeList.size(); j++) {
rl = routeList.get(j);
if (rl.getName().equals(locationName)) {
log.debug("Found location (" + locationName + ") moving train to this location");
for (j = i + 1; j < routeList.size(); j++) {
rl = routeList.get(j);
move();
if (rl.getName().equals(locationName)) {
return true;
}
}
}
}
// done
break;
}
}
return false;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getTrainWeight.
public int getTrainWeight(RouteLocation routeLocation) {
int weight = 0;
Route route = getRoute();
if (route != null) {
for (RouteLocation rl : route.getLocationsBySequenceList()) {
for (RollingStock rs : EngineManager.instance().getList(this)) {
if (rs.getRouteLocation() == rl) {
weight += rs.getAdjustedWeightTons();
}
if (rs.getRouteDestination() == rl) {
weight += -rs.getAdjustedWeightTons();
}
}
for (RollingStock rs : CarManager.instance().getList(this)) {
Car car = (Car) rs;
if (car.getRouteLocation() == rl) {
// weight depends on car load
weight += car.getAdjustedWeightTons();
}
if (car.getRouteDestination() == rl) {
weight += -car.getAdjustedWeightTons();
}
}
if (rl == routeLocation) {
break;
}
}
}
return weight;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getExpectedDepartureTime.
public String getExpectedDepartureTime(RouteLocation routeLocation) {
int minutes = getExpectedTravelTimeInMinutes(routeLocation);
if (minutes == -1) {
return ALREADY_SERVICED;
}
// figure out the work at this location, note that there can be consecutive locations with the same name
if (getRoute() != null) {
boolean foundRouteLocation = false;
for (RouteLocation rl : getRoute().getLocationsBySequenceList()) {
if (rl == routeLocation) {
foundRouteLocation = true;
}
if (foundRouteLocation) {
if (TrainCommon.splitString(rl.getName()).equals(TrainCommon.splitString(routeLocation.getName()))) {
minutes = minutes + calculateWorkTimeAtLocation(rl);
} else {
// done
break;
}
}
}
}
log.debug("Expected departure time {} for train ({}) at ({})", minutes, getName(), routeLocation.getName());
return parseTime(minutes);
}
Aggregations