Search in sources :

Example 76 with RouteLocation

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;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Nonnull(javax.annotation.Nonnull)

Example 77 with RouteLocation

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);
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 78 with RouteLocation

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;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 79 with RouteLocation

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) BufferedWriter(java.io.BufferedWriter) Car(jmri.jmrit.operations.rollingstock.cars.Car) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Route(jmri.jmrit.operations.routes.Route) PrintWriter(java.io.PrintWriter) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 80 with RouteLocation

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();
}
Also used : RouteEditFrame(jmri.jmrit.operations.routes.RouteEditFrame) Frame(java.awt.Frame) OperationsFrame(jmri.jmrit.operations.OperationsFrame) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Location(jmri.jmrit.operations.locations.Location) RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Aggregations

RouteLocation (jmri.jmrit.operations.routes.RouteLocation)118 Route (jmri.jmrit.operations.routes.Route)64 Location (jmri.jmrit.operations.locations.Location)55 Track (jmri.jmrit.operations.locations.Track)52 Car (jmri.jmrit.operations.rollingstock.cars.Car)48 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)33 LocationManager (jmri.jmrit.operations.locations.LocationManager)21 RouteManager (jmri.jmrit.operations.routes.RouteManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)17 Train (jmri.jmrit.operations.trains.Train)16 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)13 ArrayList (java.util.ArrayList)12 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)12 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 IOException (java.io.IOException)6 TrainManager (jmri.jmrit.operations.trains.TrainManager)6 JCheckBox (javax.swing.JCheckBox)5