use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrackDestinationEditFrame method checkBoxActionPerformed.
@Override
public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) {
JCheckBox b = (JCheckBox) ae.getSource();
log.debug("checkbox change {}", b.getText());
if (_track == null) {
return;
}
Location loc = locationManager.getLocationByName(b.getText());
if (loc != null) {
if (b.isSelected() ^ _track.getDestinationOption().equals(Track.EXCLUDE_DESTINATIONS)) {
_track.addDestination(loc);
} else {
_track.deleteDestination(loc);
}
}
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class Router method routeUsingOneTrain.
/**
* A single train can service the car. Provide various messages to build
* report detailing which train can service the car. Also checks to see if
* the needs to go the alternate track or yard track if the car's final
* destination track is full. Returns false if car is stuck in staging.
*
* @return true for all cases except if car is departing staging and is
* stuck there.
*/
private boolean routeUsingOneTrain(Train testTrain, Car car, Car clone) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterTrainCanTransport"), new Object[] { testTrain.getName(), car.toString(), car.getTrack().getTrackTypeName(), car.getLocationName(), car.getTrackName(), clone.getDestinationName(), clone.getDestinationTrackName() }));
if (_addtoReport) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterRoute1TrainsForCar"), new Object[] { car.toString(), car.getLocationName(), car.getTrackName(), testTrain.getName(), clone.getDestinationName(), clone.getDestinationTrackName() }));
}
// now check to see if specific train can service car directly
if (_train != null && _train != testTrain) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("TrainDoesNotServiceCar"), new Object[] { _train.getName(), car.toString(), clone.getDestinationName(), clone.getDestinationTrackName() }));
if (!_train.getServiceStatus().equals(Train.NONE)) {
addLine(_buildReport, SEVEN, _train.getServiceStatus());
}
_status = STATUS_NOT_THIS_TRAIN;
// car can be routed, but not by this train!
return true;
}
_status = car.setDestination(clone.getDestination(), clone.getDestinationTrack());
if (_status.equals(Track.OKAY)) {
// done, car has new destination
return true;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterCanNotDeliverCar"), new Object[] { car.toString(), clone.getDestinationName(), clone.getDestinationTrackName(), _status, (clone.getDestinationTrack() == null ? Bundle.getMessage("RouterDestination") : clone.getDestinationTrack().getTrackTypeName()) }));
// check to see if an alternative track was specified
if ((_status.startsWith(Track.LENGTH) || _status.startsWith(Track.SCHEDULE)) && clone.getDestinationTrack() != null && clone.getDestinationTrack().getAlternateTrack() != null && clone.getDestinationTrack().getAlternateTrack() != car.getTrack()) {
String status = car.setDestination(clone.getDestination(), clone.getDestinationTrack().getAlternateTrack());
if (status.equals(Track.OKAY)) {
if (_train == null || _train.services(car)) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterSendCarToAlternative"), new Object[] { car.toString(), clone.getDestinationTrack().getAlternateTrack().getName(), clone.getDestination().getName() }));
// car is going to alternate track
return true;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterNotSendCarToAlternative"), new Object[] { _train.getName(), car.toString(), clone.getDestinationTrack().getAlternateTrack().getName(), clone.getDestination().getName() }));
} else {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterAlternateFailed"), new Object[] { clone.getDestinationTrack().getAlternateTrack().getName(), status }));
}
} else if (clone.getDestinationTrack() != null && clone.getDestinationTrack().getAlternateTrack() != null && clone.getDestinationTrack().getAlternateTrack() == car.getTrack()) {
// state that car is spotted at the alternative track
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterAtAlternate"), new Object[] { car.toString(), clone.getDestinationTrack().getAlternateTrack().getName(), clone.getLocationName(), clone.getDestinationTrackName() }));
} else if (car.getLocation() == clone.getDestination()) {
// state that alternative and yard track options are not available if car is at final destination
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterIgnoreAlternate"), new Object[] { car.toString(), car.getLocationName() }));
}
// check to see if spur was full, if so, forward to yard if possible
if (Setup.isForwardToYardEnabled() && _status.startsWith(Track.LENGTH) && car.getLocation() != clone.getDestination()) {
// log.debug("Spur full, searching for a yard at destination ("+clone.getDestinationName()+")");
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterSpurFull"), new Object[] { clone.getDestinationTrackName(), clone.getDestinationName() }));
Location dest = clone.getDestination();
List<Track> yards = dest.getTrackByMovesList(Track.YARD);
log.debug("Found {} yard(s) at destination ({})", yards.size(), clone.getDestinationName());
for (Track track : yards) {
String status = car.setDestination(dest, track);
if (status.equals(Track.OKAY)) {
if (_train != null && !_train.services(car)) {
log.debug("Train ({}) can not deliver car ({}) to yard ({})", _train.getName(), car.toString(), track.getName());
continue;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterSendCarToYard"), new Object[] { car.toString(), track.getName(), dest.getName() }));
// car is going to a yard
return true;
} else {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterCanNotUseYard"), new Object[] { track.getName(), status }));
}
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("RouterNoYardTracks"), new Object[] { dest.getName(), car.toString() }));
}
car.setDestination(null, null);
if (car.getTrack().getTrackType().equals(Track.STAGING)) {
log.debug("Car ({}) departing staging, single train can't deliver car to ({}, {})", car.toString(), clone.getDestinationName(), clone.getDestinationTrackName());
// try 2 or more trains
return false;
}
// able to route, but not able to set the car's destination
return true;
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrainBuilder method findFinalDestinationForCarLoad.
/**
* Find the final destination and track for a car with a custom load. Car
* doesn't have a destination or final destination. There's a check to see
* if there's a spur/ schedule for this car. Returns true if a schedule was
* found. Hold car at current location if any of the spurs checked has the
* the option to "always forward cars to this spur" enabled.
*
* @param car the car with the load
* @return true if there's a schedule that can be routed to for this car and
* load
*/
private boolean findFinalDestinationForCarLoad(Car car) throws BuildFailedException {
boolean routeToSpurFound = false;
if (car.getLoadName().equals(CarLoads.instance().getDefaultEmptyName()) || car.getLoadName().equals(CarLoads.instance().getDefaultLoadName()) || car.getDestination() != null || car.getFinalDestination() != null) {
// no schedule found for this car
return false;
}
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildSearchForSpur"), new Object[] { car.toString(), car.getTypeName(), car.getLoadName(), car.getLocationName() + ", " + car.getTrackName() }));
if (car.getKernel() != null) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCarLeadKernel"), new Object[] { car.toString(), car.getKernelName(), car.getKernel().getSize(), car.getKernel().getTotalLength(), Setup.getLengthUnit().toLowerCase() }));
}
List<Track> tracks = locationManager.getTracksByMoves(Track.SPUR);
log.debug("Found {} spurs", tracks.size());
// locations not reachable
List<Location> locations = new ArrayList<Location>();
for (Track track : tracks) {
if (car.getTrack() == track || track.getSchedule() == null) {
continue;
}
if (locations.contains(track.getLocation())) {
continue;
}
if (!car.getTrack().acceptsDestination(track.getLocation())) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildDestinationNotServiced"), new Object[] { track.getLocation().getName(), car.getTrackName() }));
locations.add(track.getLocation());
continue;
}
if (!_train.isAllowThroughCarsEnabled() && !_train.isLocalSwitcher() && !car.isCaboose() && !car.hasFred() && !car.isPassenger() && splitString(car.getLocationName()).equals(splitString(_departLocation.getName())) && splitString(track.getLocation().getName()).equals(splitString(_terminateLocation.getName())) && !splitString(_departLocation.getName()).equals(splitString(_terminateLocation.getName()))) {
log.debug("Skipping track ({}), through cars not allowed to terminal ({})", track.getName(), _terminateLocation.getName());
continue;
}
String status = car.testDestination(track.getLocation(), track);
if (status.equals(Track.OKAY) && !_train.isAllowLocalMovesEnabled() && splitString(car.getLocationName()).equals(splitString(track.getLocation().getName()))) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoLocalMoveToSpur"), new Object[] { _train.getName(), track.getLocation().getName(), track.getName() }));
// log.debug("Skipping track ({}), it would require a local move", track.getName()); // NOI18N
continue;
}
if (!status.equals(Track.OKAY)) {
if (track.getScheduleMode() == Track.SEQUENTIAL && status.startsWith(Track.SCHEDULE)) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildTrackSequentialMode"), new Object[] { track.getName(), track.getLocation().getName(), status }));
}
// if the track has an alternate track don't abort if the issue was space
if (!status.startsWith(Track.LENGTH) || !track.checkSchedule(car).equals(Track.OKAY)) {
continue;
}
if (track.getAlternateTrack() == null) {
// report that the spur is full and no alternate
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildSpurFullNoAlternate"), new Object[] { track.getLocation().getName(), track.getName() }));
continue;
} else {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildTrackFullHasAlternate"), new Object[] { track.getLocation().getName(), track.getName(), track.getAlternateTrack().getName() }));
// check to see if alternate and track are configured properly
if (!_train.isLocalSwitcher() && (track.getTrainDirections() & track.getAlternateTrack().getTrainDirections()) == 0) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCanNotDropRsUsingTrain4"), new Object[] { track.getName(), formatStringToCommaSeparated(Setup.getDirectionStrings(track.getTrainDirections())), track.getAlternateTrack().getName(), formatStringToCommaSeparated(Setup.getDirectionStrings(track.getAlternateTrack().getTrainDirections())) }));
continue;
}
}
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildSetFinalDestination"), new Object[] { car.toString(), car.getLoadName(), track.getLocation().getName(), track.getName() }));
// show if track is requesting cars with custom loads to only go to spurs
if (track.isHoldCarsWithCustomLoadsEnabled()) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildHoldCarsCustom"), new Object[] { track.getLocation().getName(), track.getName() }));
}
// check the number of in bound cars to this track
if (!track.isSpaceAvailable(car)) {
// Now determine if we should move the car or just leave it where it is
// save the tracks schedule item id
String id = track.getScheduleItemId();
// determine if this car can be routed to the spur
car.setFinalDestination(track.getLocation());
car.setFinalDestinationTrack(track);
// hold car if able to route to track
if (Router.instance().setDestination(car, _train, _buildReport) && track.isHoldCarsWithCustomLoadsEnabled()) {
// if we don't find another spur, keep the car here for now
routeToSpurFound = true;
}
car.setDestination(null, null);
car.setFinalDestination(null);
car.setFinalDestinationTrack(null);
// restore id
track.setScheduleItemId(id);
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoDestTrackSpace"), new Object[] { car.toString(), track.getLocation().getName(), track.getName(), track.getNumberOfCarsInRoute(), track.getReservedInRoute(), Setup.getLengthUnit().toLowerCase(), track.getReservationFactor() }));
continue;
}
// try to send car to this spur
car.setFinalDestination(track.getLocation());
car.setFinalDestinationTrack(track);
// test to see if destination is reachable by this train
if (Router.instance().setDestination(car, _train, _buildReport) && track.isHoldCarsWithCustomLoadsEnabled()) {
// found a route to the spur
routeToSpurFound = true;
}
if (car.getDestination() != null) {
// is car part of kernel?
car.updateKernel();
if (car.getDestinationTrack() != track) {
car.setScheduleItemId(track.getCurrentScheduleItem().getId());
track.bumpSchedule();
}
// done, car has a new destination
return true;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNotAbleToSetDestination"), new Object[] { car.toString(), Router.instance().getStatus() }));
car.setFinalDestination(null);
car.setFinalDestinationTrack(null);
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildCouldNotFindSpur"), new Object[] { car.toString(), car.getLoadName() }));
if (routeToSpurFound && !_train.isSendCarsWithCustomLoadsToStagingEnabled() && !car.getLocation().isStaging()) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildHoldCarValidRoute"), new Object[] { car.toString(), car.getLocationName(), car.getTrackName() }));
} else {
// try and send car to staging
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildTrySendCarToStaging"), new Object[] { car.toString(), car.getLoadName() }));
tracks = locationManager.getTracks(Track.STAGING);
log.debug("Found {} staging tracks", tracks.size());
while (tracks.size() > 0) {
// pick a track randomly
int rnd = (int) (Math.random() * tracks.size());
Track track = tracks.get(rnd);
tracks.remove(track);
log.debug("Staging track ({}, {})", track.getLocation().getName(), track.getName());
if (track.getLocation() == car.getLocation()) {
continue;
}
if (locations.contains(track.getLocation())) {
continue;
}
if (_terminateStageTrack != null && track.getLocation() == _terminateLocation && track != _terminateStageTrack) {
// ignore other staging tracks at terminus
continue;
}
if (!car.getTrack().acceptsDestination(track.getLocation())) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildDestinationNotServiced"), new Object[] { track.getLocation().getName(), car.getTrackName() }));
locations.add(track.getLocation());
continue;
}
String status = track.accepts(car);
if (!status.equals(Track.OKAY) && !status.startsWith(Track.LENGTH)) {
log.debug("Staging track ({}) can't accept car ({})", track.getName(), car.toString());
continue;
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildStagingCanAcceptLoad"), new Object[] { track.getLocation(), track.getName(), car.getLoadName() }));
// try to send car to staging
car.setFinalDestination(track.getLocation());
// test to see if destination is reachable by this train
if (Router.instance().setDestination(car, _train, _buildReport)) {
// found a route to staging
routeToSpurFound = true;
}
if (car.getDestination() != null) {
// is car part of kernel?
car.updateKernel();
return true;
}
// couldn't route to this staging location
locations.add(track.getLocation());
car.setFinalDestination(null);
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildNoStagingForCarLoad"), new Object[] { car.toString(), car.getLoadName() }));
}
// done
return routeToSpurFound;
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrainCsvCommon method printTrackComments.
protected void printTrackComments(PrintWriter fileOut, RouteLocation rl, List<Car> carList) {
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;
}
}
// each comment can have multiple lines
if (pickup && setout && !track.getCommentBoth().equals(Track.NONE)) {
String[] comments = track.getCommentBoth().split(NEW_LINE);
for (String comment : comments) {
addLine(fileOut, TKCB + comment);
}
} else if (pickup && !setout && !track.getCommentPickup().equals(Track.NONE)) {
String[] comments = track.getCommentPickup().split(NEW_LINE);
for (String comment : comments) {
addLine(fileOut, TKCP + comment);
}
} else if (!pickup && setout && !track.getCommentSetout().equals(Track.NONE)) {
String[] comments = track.getCommentSetout().split(NEW_LINE);
for (String comment : comments) {
addLine(fileOut, TKCS + comment);
}
}
}
}
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrainSwitchListEditFrame method commentButtonActionPerformed.
public void commentButtonActionPerformed(ActionEvent ae) {
JButton b = (JButton) ae.getSource();
log.debug("button action " + b.getName());
Location l = locationManager.getLocationByName(b.getName());
new TrainSwitchListCommentFrame(l);
}
Aggregations