use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getCabooseRoadAndNumber.
/**
* Gets the current caboose road and number if there's one assigned to the
* train.
*
* @return Road and number of caboose.
*/
@Nonnull
public String getCabooseRoadAndNumber() {
String cabooseRoadNumber = NONE;
RouteLocation rl = getCurrentLocation();
List<RollingStock> cars = CarManager.instance().getByTrainList(this);
for (RollingStock rs : cars) {
Car car = (Car) rs;
if (car.getRouteLocation() == rl && car.getRouteDestination() != rl && car.isCaboose()) {
cabooseRoadNumber = car.toString();
}
}
return cabooseRoadNumber;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method setCurrentLocation.
/**
* Set train's current route location
* @param location The current RouteLocation.
*/
protected void setCurrentLocation(RouteLocation location) {
RouteLocation old = _current;
_current = location;
if ((old != null && !old.equals(location)) || (old == null && location != null)) {
// NOI18N
setDirtyAndFirePropertyChange("current", old, location);
}
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getDepartureTime.
/**
* Get's train's departure time
*
* @return train's departure time in the String format hh:mm
*/
public String getDepartureTime() {
// check to see if the route has a departure time
RouteLocation rl = getTrainDepartsRouteLocation();
if (rl != null) {
rl.removePropertyChangeListener(this);
rl.addPropertyChangeListener(this);
if (!rl.getDepartureTime().equals(RouteLocation.NONE)) {
return rl.getDepartureTime();
}
}
return _departureTime;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainCsvSwitchLists method buildSwitchList.
/**
* builds a csv file containing the switch list for a location
* @param location The Location requesting a switch list.
*
* @return File
*/
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "CarManager only provides Car Objects")
public File buildSwitchList(Location location) {
// create csv switch list file
File file = TrainManagerXml.instance().createCsvSwitchListFile(location.getName());
PrintWriter fileOut = null;
try {
fileOut = new // NOI18N
PrintWriter(// NOI18N
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")), // NOI18N
true);
} catch (IOException e) {
log.error("Can not open CSV switch list file: {}", file.getName());
return null;
}
// build header
addLine(fileOut, HEADER);
// this is a switch list
addLine(fileOut, SWL);
addLine(fileOut, RN + ESC + Setup.getRailroadName() + ESC);
addLine(fileOut, LN + ESC + splitString(location.getName()) + ESC);
addLine(fileOut, PRNTR + ESC + location.getDefaultPrinterName() + ESC);
addLine(fileOut, SWLC + ESC + location.getSwitchListComment() + ESC);
// add location comment
if (Setup.isPrintLocationCommentsEnabled() && !location.getComment().equals(Location.NONE)) {
// location comment can have multiple lines
// NOI18N
String[] comments = location.getComment().split(NEW_LINE);
for (String comment : comments) {
addLine(fileOut, LC + ESC + comment + ESC);
}
}
addLine(fileOut, VT + getDate(true));
// get a list of trains sorted by arrival time
List<Train> trains = TrainManager.instance().getTrainsArrivingThisLocationList(location);
for (Train train : trains) {
if (!train.isBuilt()) {
// train wasn't built so skip
continue;
}
if (!Setup.isSwitchListRealTime() && train.getSwitchListStatus().equals(Train.PRINTED)) {
// already printed this train
continue;
}
int pickupCars = 0;
int dropCars = 0;
int stops = 1;
boolean trainDone = false;
List<Car> carList = CarManager.instance().getByTrainDestinationList(train);
List<Engine> enginesList = EngineManager.instance().getByTrainBlockingList(train);
// does the train stop once or more at this location?
Route route = train.getRoute();
if (route == null) {
// no route for this train
continue;
}
List<RouteLocation> routeList = route.getLocationsBySequenceList();
RouteLocation rlPrevious = null;
// need to know where in the route we are for the various comments
for (RouteLocation rl : routeList) {
if (!splitString(rl.getName()).equals(splitString(location.getName()))) {
rlPrevious = rl;
continue;
}
String expectedArrivalTime = train.getExpectedArrivalTime(rl);
if (expectedArrivalTime.equals(Train.ALREADY_SERVICED)) {
trainDone = true;
}
// if it terminates at this location
if (stops == 1) {
// newLine(fileOut);
addLine(fileOut, TN + train.getName());
addLine(fileOut, TM + train.getDescription());
if (train.isTrainEnRoute()) {
addLine(fileOut, TIR);
addLine(fileOut, ETE + expectedArrivalTime);
} else {
addLine(fileOut, DL + splitString(splitString(train.getTrainDepartsName())));
addLine(fileOut, DT + train.getDepartureTime());
if (rl == train.getRoute().getDepartsRouteLocation() && routeList.size() > 1) {
addLine(fileOut, TD + splitString(rl.getName()) + DEL + rl.getTrainDirectionString());
}
if (rl != train.getRoute().getDepartsRouteLocation()) {
addLine(fileOut, ETA + expectedArrivalTime);
addLine(fileOut, TA + splitString(rl.getName()) + DEL + rl.getTrainDirectionString());
}
}
if (rl == train.getRoute().getTerminatesRouteLocation()) {
addLine(fileOut, TT + splitString(rl.getName()));
}
}
if (stops > 1) {
// Print visit number, etc. only if previous location wasn't the same
if (rlPrevious == null || !splitString(rl.getName()).equals(splitString(rlPrevious.getName()))) {
// After the first time a train stops at a location provide:
// if the train has started its route
// the arrival time or relative time if the train has started its route
// the train's direction when it arrives
// if it terminate at this location
addLine(fileOut, VN + stops);
if (train.isTrainEnRoute()) {
addLine(fileOut, ETE + expectedArrivalTime);
} else {
addLine(fileOut, ETA + expectedArrivalTime);
}
addLine(fileOut, TA + splitString(rl.getName()) + DEL + rl.getTrainDirectionString());
if (rl == train.getRoute().getTerminatesRouteLocation()) {
addLine(fileOut, TT + splitString(rl.getName()));
}
} else {
// don't bump stop count, same location
stops--;
// Does the train change direction?
if (rl.getTrainDirection() != rlPrevious.getTrainDirection()) {
addLine(fileOut, TDC + rl.getTrainDirectionString());
}
}
}
rlPrevious = rl;
// add route comment
if (!rl.getComment().equals(RouteLocation.NONE)) {
addLine(fileOut, RLC + ESC + rl.getComment() + ESC);
}
// engine change or helper service?
checkForEngineOrCabooseChange(fileOut, train, rl);
// go through the list of engines and determine if the engine departs here
for (Engine engine : enginesList) {
if (engine.getRouteLocation() == rl && engine.getTrack() != null) {
fileOutCsvEngine(fileOut, engine, PL);
}
}
// block pick up cars by destination
for (RouteLocation rld : routeList) {
for (Car car : carList) {
if (car.getRouteLocation() == rl && car.getTrack() != null && car.getRouteDestination() == rld) {
pickupCars++;
int count = 0;
if (car.isUtility()) {
count = countPickupUtilityCars(carList, car, !IS_MANIFEST);
if (count == 0) {
// already done this set of utility cars
continue;
}
}
fileOutCsvCar(fileOut, car, PC, count);
}
}
}
for (Engine engine : enginesList) {
if (engine.getRouteDestination() == rl) {
fileOutCsvEngine(fileOut, engine, SL);
}
}
// now do car set outs
for (Car car : carList) {
if (car.getRouteDestination() == rl) {
dropCars++;
int count = 0;
if (car.isUtility()) {
count = countSetoutUtilityCars(carList, car, !LOCAL, !IS_MANIFEST);
if (count == 0) {
// already done this set of utility cars
continue;
}
}
fileOutCsvCar(fileOut, car, SC, count);
}
}
stops++;
if (rl != train.getRoute().getTerminatesRouteLocation()) {
addLine(fileOut, TL + train.getTrainLength(rl) + DEL + train.getNumberEmptyCarsInTrain(rl) + DEL + train.getNumberCarsInTrain(rl));
addLine(fileOut, TW + train.getTrainWeight(rl));
}
}
if (trainDone && pickupCars == 0 && dropCars == 0) {
addLine(fileOut, TDONE);
} else if (stops > 1) {
if (pickupCars == 0) {
addLine(fileOut, NCPU);
}
if (dropCars == 0) {
addLine(fileOut, NCSO);
}
// done with this train
addLine(fileOut, TEND + train.getName());
}
}
// done with switch list
addLine(fileOut, END);
// now list hold cars
List<RollingStock> rsByLocation = CarManager.instance().getByLocationList();
List<Car> carList = new ArrayList<Car>();
for (RollingStock rs : rsByLocation) {
if (rs.getLocation() != null && splitString(rs.getLocation().getName()).equals(splitString(location.getName())) && rs.getRouteLocation() == null) {
carList.add((Car) rs);
}
}
// list utility cars by quantity
clearUtilityCarTypes();
for (Car car : carList) {
int count = 0;
if (car.isUtility()) {
count = countPickupUtilityCars(carList, car, !IS_MANIFEST);
if (count == 0) {
// already done this set of utility cars
continue;
}
}
fileOutCsvCar(fileOut, car, HOLD, count);
}
// done with hold cars
addLine(fileOut, END);
// Are there any cars that need to be found?
listCarsLocationUnknown(fileOut);
fileOut.flush();
fileOut.close();
location.setStatus(Location.CSV_GENERATED);
return file;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainEditFrame method dispose.
@Override
public void dispose() {
LocationManager.instance().removePropertyChangeListener(this);
EngineTypes.instance().removePropertyChangeListener(this);
EngineModels.instance().removePropertyChangeListener(this);
CarTypes.instance().removePropertyChangeListener(this);
CarRoads.instance().removePropertyChangeListener(this);
routeManager.removePropertyChangeListener(this);
for (Frame frame : children) {
frame.dispose();
}
if (_train != null) {
_train.removePropertyChangeListener(this);
Route route = _train.getRoute();
if (route != null) {
route.removePropertyChangeListener(this);
for (RouteLocation rl : route.getLocationsBySequenceList()) {
Location loc = rl.getLocation();
if (loc != null) {
loc.removePropertyChangeListener(this);
}
}
}
}
super.dispose();
}
Aggregations