use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainCommon method printTrackComments.
protected void printTrackComments(PrintWriter file, RouteLocation rl, List<Car> carList, boolean isManifest) {
Location location = rl.getLocation();
if (location != null) {
List<Track> tracks = location.getTrackByNameList(null);
for (Track track : tracks) {
// any pick ups or set outs to this track?
boolean pickup = false;
boolean setout = false;
for (Car car : carList) {
if (car.getRouteLocation() == rl && car.getTrack() != null && car.getTrack() == track) {
pickup = true;
}
if (car.getRouteDestination() == rl && car.getDestinationTrack() != null && car.getDestinationTrack() == track) {
setout = true;
}
}
// print the appropriate comment if there's one
if (pickup && setout && !track.getCommentBoth().equals(Track.NONE)) {
newLine(file, track.getCommentBoth(), isManifest);
} else if (pickup && !setout && !track.getCommentPickup().equals(Track.NONE)) {
newLine(file, track.getCommentPickup(), isManifest);
} else if (!pickup && setout && !track.getCommentSetout().equals(Track.NONE)) {
newLine(file, track.getCommentSetout(), isManifest);
}
}
}
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilder method finishAddRsToTrain.
private void finishAddRsToTrain(RollingStock rs, RouteLocation rl, RouteLocation rld, int length, int weightTons) {
// rld.getLocation().setStatusModified();
if (!_modifiedLocations.contains(rl.getLocation())) {
_modifiedLocations.add(rl.getLocation());
}
if (!_modifiedLocations.contains(rld.getLocation())) {
_modifiedLocations.add(rld.getLocation());
}
rs.setTrain(_train);
rs.setRouteLocation(rl);
rs.setRouteDestination(rld);
// now adjust train length and weight for each location that the rolling stock is in the train
boolean inTrain = false;
for (RouteLocation routeLocation : _routeList) {
if (rl == routeLocation) {
inTrain = true;
}
if (rld == routeLocation) {
break;
}
if (inTrain) {
// couplers are included
routeLocation.setTrainLength(routeLocation.getTrainLength() + length);
routeLocation.setTrainWeight(routeLocation.getTrainWeight() + weightTons);
}
}
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainBuilder method getLocationWithMaximumMoves.
/**
* Returns the routeLocation with the most available moves.
*
* @param routeList The route for this train.
* @param blockId Where these cars were originally picked up from.
* @return The location in the route with the most available moves.
*/
private RouteLocation getLocationWithMaximumMoves(List<RouteLocation> routeList, String blockId) {
RouteLocation rlMax = null;
int maxMoves = 0;
for (RouteLocation rl : routeList) {
if (rl == _train.getTrainDepartsRouteLocation()) {
continue;
}
if (rl.getMaxCarMoves() - rl.getCarMoves() > maxMoves) {
maxMoves = rl.getMaxCarMoves() - rl.getCarMoves();
rlMax = rl;
}
// if two locations have the same number of moves, return the one that doesn't match the block id
if (rl.getMaxCarMoves() - rl.getCarMoves() == maxMoves && !rl.getLocation().getId().equals(blockId)) {
rlMax = rl;
}
}
return rlMax;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class RollingStock method setRouteLocation.
/**
* Sets the location where the rolling stock will be picked up by the train.
*
* @param routeLocation the pick up location for this rolling stock.
*/
public void setRouteLocation(RouteLocation routeLocation) {
// a couple of error checks before setting the route location
if (_location == null && routeLocation != null) {
// NOI18N
log.debug("WARNING rolling stock ({}) does not have an assigned location", toString());
} else if (routeLocation != null && _location != null && !routeLocation.getName().equals(_location.getName())) {
log.error("ERROR route location name({}) not equal to location name ({}) for rolling stock ({})", routeLocation.getName(), _location.getName(), // NOI18N
toString());
}
RouteLocation old = _routeLocation;
_routeLocation = routeLocation;
if (old != routeLocation) {
setDirtyAndFirePropertyChange(ROUTE_LOCATION_CHANGED_PROPERTY, old, routeLocation);
}
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method services.
public boolean services(PrintWriter buildReport, Car car) {
boolean addToReport = Setup.getRouterBuildReportLevel().equals(SEVEN);
setServiceStatus(NONE);
// check to see if train can carry car
if (!acceptsTypeName(car.getTypeName())) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotServiceCarType"), new Object[] { getName(), car.toString(), car.getTypeName() }));
}
return false;
}
if (!acceptsLoad(car.getLoadName(), car.getTypeName())) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotServiceCarLoad"), new Object[] { getName(), car.toString(), car.getTypeName(), car.getLoadName() }));
}
return false;
}
if (!acceptsBuiltDate(car.getBuilt()) || !acceptsOwnerName(car.getOwner()) || !acceptsRoadName(car.getRoadName())) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotServiceCar"), new Object[] { getName(), car.toString() }));
}
return false;
}
int length = car.getTotalLength();
// car can be a kernel so get total length
if (car.getKernel() != null) {
length = car.getKernel().getTotalLength();
}
Route route = getRoute();
if (route != null) {
// determine if the car's location and destination is serviced by this train
if (route.getLastLocationByName(car.getLocationName()) == null) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainNotThisLocation"), new Object[] { getName(), car.getLocationName() }));
}
return false;
}
if (car.getDestination() != null && route.getLastLocationByName(car.getDestinationName()) == null) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainNotThisLocation"), new Object[] { getName(), car.getDestinationName() }));
}
return false;
}
List<RouteLocation> rLocations = route.getLocationsBySequenceList();
for (int j = 0; j < rLocations.size(); j++) {
RouteLocation rLoc = rLocations.get(j);
if (rLoc.getName().equals(car.getLocationName()) && rLoc.isPickUpAllowed() && rLoc.getMaxCarMoves() > 0 && !skipsLocation(rLoc.getId()) && ((car.getLocation().getTrainDirections() & rLoc.getTrainDirection()) != 0 || isLocalSwitcher())) {
if (car.getTrack() != null) {
if (((car.getTrack().getTrainDirections() & rLoc.getTrainDirection()) == 0 && !isLocalSwitcher()) || !car.getTrack().acceptsPickupTrain(this)) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotServiceCarFrom"), new Object[] { getName(), car.toString(), car.getLocationName(), car.getTrackName(), rLoc.getId() }));
}
continue;
}
}
if (debugFlag) {
log.debug("Car ({}) can be picked up by train ({}) location ({}, {}) destination ({}, {})", car.toString(), getName(), car.getLocationName(), car.getTrackName(), car.getDestinationName(), car.getDestinationTrackName());
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanPickUpCar"), new Object[] { getName(), car.toString(), car.getLocationName(), car.getTrackName(), rLoc.getId() }));
}
if (car.getDestination() == null) {
if (debugFlag) {
log.debug("Car ({}) does not have a destination", car.toString());
}
return true;
}
// now check car's destination
for (int k = j; k < rLocations.size(); k++) {
RouteLocation rldest = rLocations.get(k);
if (rldest.getName().equals(car.getDestinationName()) && rldest.isDropAllowed() && rldest.getMaxCarMoves() > 0 && !skipsLocation(rldest.getId()) && ((car.getDestination().getTrainDirections() & rldest.getTrainDirection()) != 0 || isLocalSwitcher()) && (!Setup.isCheckCarDestinationEnabled() || car.getTrack() == null || car.getTrack().acceptsDestination(car.getDestination()))) {
// found a destination, now check destination track
if (car.getDestinationTrack() != null) {
if ((car.getDestinationTrack().getTrainDirections() & rldest.getTrainDirection()) == 0 && !isLocalSwitcher()) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropRsUsingTrain"), new Object[] { car.toString(), rldest.getTrainDirectionString() }));
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropRsUsingTrain2"), new Object[] { car.getDestinationTrackName() }));
}
continue;
}
if (!car.getDestinationTrack().acceptsDropTrain(this)) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropCarTrain"), new Object[] { car.toString(), getName(), car.getDestinationTrack().getTrackTypeName(), car.getDestinationTrackName() }));
}
continue;
}
} else if (rldest.getLocation().isStaging() && getStatusCode() == CODE_BUILDING && getTerminationTrack() != null && getTerminationTrack().getLocation() == rldest.getLocation()) {
if (debugFlag) {
log.debug("Car ({}) destination is staging, check train ({}) termination track ({})", car.toString(), getName(), getTerminationTrack().getName());
}
String status = car.testDestination(getTerminationTrack().getLocation(), getTerminationTrack());
if (!status.equals(Track.OKAY)) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotDeliverToStaging"), new Object[] { getName(), car.toString(), getTerminationTrack().getLocation().getName(), getTerminationTrack().getName(), status }));
}
continue;
}
} else {
if (debugFlag) {
log.debug("Find track for car ({}) at destination ({})", car.toString(), car.getDestinationName());
}
// determine if there's a track that is willing to accept this car
String status = "";
List<Track> tracks = rldest.getLocation().getTrackList();
for (Track track : tracks) {
if ((track.getTrainDirections() & rldest.getTrainDirection()) == 0 && !isLocalSwitcher()) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropRsUsingTrain"), new Object[] { car.toString(), rldest.getTrainDirectionString() }));
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropRsUsingTrain2"), new Object[] { track.getName() }));
}
continue;
}
if (!track.acceptsDropTrain(this)) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropCarTrain"), new Object[] { car.toString(), getName(), track.getTrackTypeName(), track.getName() }));
}
continue;
}
// will the track accept this car?
status = track.accepts(car);
if (status.equals(Track.OKAY) || status.startsWith(Track.LENGTH)) {
if (debugFlag) {
log.debug("Found track ({}) for car ({})", track.getName(), car.toString());
}
// yes, done
break;
}
}
if (!status.equals(Track.OKAY) && !status.startsWith(Track.LENGTH)) {
if (debugFlag) {
log.debug("Destination ({}) can not service car ({}) using train ({}) no track available", car.getDestinationName(), car.toString(), // NOI18N
getName());
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotDeliverNoTracks"), new Object[] { getName(), car.toString(), car.getDestinationName(), rldest.getId() }));
}
continue;
}
}
// carry cars only to terminal?
if (isSendCarsToTerminalEnabled() && !TrainCommon.splitString(car.getLocationName()).equals(TrainCommon.splitString(getTrainDepartsName())) && !TrainCommon.splitString(car.getDestinationName()).equals(TrainCommon.splitString(getTrainTerminatesName()))) {
if (debugFlag) {
log.debug("option send cars to terminal is enabled");
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotCarryCarOption"), new Object[] { getName(), car.toString(), car.getLocationName(), car.getTrackName(), car.getDestinationName(), car.getDestinationTrackName() }));
}
continue;
}
// allow car to return to staging?
if (isAllowReturnToStagingEnabled() && car.getTrack().getTrackType().equals(Track.STAGING) && rldest.getLocation() == car.getLocation()) {
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanReturnCarToStaging"), new Object[] { getName(), car.toString(), car.getDestinationName(), car.getDestinationTrackName() }));
}
return true;
}
// is this a local move?
if (!isAllowLocalMovesEnabled() && !car.isCaboose() && !car.hasFred() && !car.isPassenger() && TrainCommon.splitString(car.getLocationName()).equals(TrainCommon.splitString(car.getDestinationName()))) {
if (debugFlag) {
log.debug("Local moves is disabled");
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotPerformLocalMove"), new Object[] { getName(), car.toString(), car.getLocationName() }));
}
continue;
}
// Can cars travel from origin to terminal?
if (!isAllowThroughCarsEnabled() && TrainCommon.splitString(getTrainDepartsName()).equals(TrainCommon.splitString(rLoc.getName())) && TrainCommon.splitString(getTrainTerminatesName()).equals(TrainCommon.splitString(rldest.getName())) && !isLocalSwitcher() && !car.isCaboose() && !car.hasFred() && !car.isPassenger()) {
if (debugFlag) {
log.debug("Through car (" + car.toString() + ") not allowed");
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainDoesNotCarryOriginTerminal"), new Object[] { getName(), car.getLocationName(), car.getDestinationName() }));
}
continue;
}
// check to see if moves are available
if (getStatusCode() == CODE_BUILDING && rldest.getMaxCarMoves() - rldest.getCarMoves() <= 0) {
setServiceStatus(MessageFormat.format(Bundle.getMessage("trainNoMoves"), new Object[] { getName(), getRoute().getName(), rldest.getId(), rldest.getName() }));
if (debugFlag) {
log.debug("No available moves for destination " + rldest.getName());
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, getServiceStatus());
}
continue;
}
if (debugFlag) {
log.debug("Car (" + car.toString() + ") can be dropped by train (" + getName() + ") to (" + car.getDestinationName() + // NOI18N
", " + car.getDestinationTrackName() + ")");
}
return true;
}
// check to see if train length is okay
if (getStatusCode() == CODE_BUILDING && rLoc.getTrainLength() + length > rLoc.getMaxTrainLength()) {
setServiceStatus(MessageFormat.format(Bundle.getMessage("trainExceedsMaximumLength"), new Object[] { getName(), getRoute().getName(), rLoc.getId(), rLoc.getMaxTrainLength(), Setup.getLengthUnit().toLowerCase(), rLoc.getName(), car.toString() }));
if (debugFlag) {
log.debug("Car (" + car.toString() + ") exceeds maximum train length " + rldest.getMaxTrainLength() + // NOI18N
" when departing (" + rldest.getName() + ")");
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, getServiceStatus());
}
return false;
}
}
if (addToReport) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotDeliverToDestination"), new Object[] { getName(), car.toString(), car.getDestinationName(), car.getDestinationTrackName() }));
}
} else if (addToReport && rLoc.getName().equals(car.getLocationName())) {
TrainCommon.addLine(buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("trainCanNotServiceCarFrom"), new Object[] { getName(), car.toString(), car.getLocationName(), car.getTrackName(), rLoc.getId() }));
}
}
}
if (debugFlag) {
log.debug("Train ({}) can't service car ({}) from ({}, {})", getName(), car.toString(), car.getLocationName(), car.getTrackName());
}
return false;
}
Aggregations