Search in sources :

Example 26 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class CarManager method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in operations-cars.dtd.
     * @param root The common Element for operations-cars.dtd.
     */
public void store(Element root) {
    // nothing to save under
    root.addContent(new Element(Xml.OPTIONS));
    // options
    Element values;
    List<String> names = getKernelNameList();
    if (Control.backwardCompatible) {
        root.addContent(values = new Element(Xml.KERNELS));
        for (String name : names) {
            // NOI18N
            String kernelNames = name + "%%";
            values.addContent(kernelNames);
        }
    }
    // new format using elements
    Element kernels = new Element(Xml.NEW_KERNELS);
    for (String name : names) {
        Element kernel = new Element(Xml.KERNEL);
        kernel.setAttribute(new Attribute(Xml.NAME, name));
        kernels.addContent(kernel);
    }
    root.addContent(kernels);
    root.addContent(values = new Element(Xml.CARS));
    // add entries
    List<RollingStock> carList = getByIdList();
    for (RollingStock rs : carList) {
        Car car = (Car) rs;
        values.addContent(car.store());
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 27 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class CarLoadEditFrame method updateCarQuanity.

private void updateCarQuanity() {
    if (!showQuanity) {
        return;
    }
    int number = 0;
    String item = (String) loadComboBox.getSelectedItem();
    for (RollingStock rs : CarManager.instance().getList()) {
        Car car = (Car) rs;
        if (car.getLoadName().equals(item)) {
            number++;
        }
    }
    quanity.setText(Integer.toString(number));
}
Also used : RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 28 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class DeleteCarRosterAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ae) {
    if (_carsTableFrame.carsTableModel.trackName == null) {
        if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("carSureDelete"), Bundle.getMessage("carDeleteAll"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            log.debug("removing all cars from roster");
            CarManager.instance().deleteAll();
        }
    } else {
        if (JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("carDeleteCarsTrack"), new Object[] { _carsTableFrame.carsTableModel.trackName }), Bundle.getMessage("carDeleteAll"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            for (RollingStock car : _carsTableFrame.carsTableModel.getSelectedCarList()) {
                CarManager.instance().deregister(car);
            }
        }
    }
}
Also used : RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 29 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class Train method getTrainLength.

/**
     * Gets the train's length at the route location specified
     *
     * @param routeLocation The route location
     * @return The train length at the route location
     */
public int getTrainLength(RouteLocation routeLocation) {
    int length = 0;
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            for (RollingStock rs : EngineManager.instance().getList(this)) {
                if (rs.getRouteLocation() == rl) {
                    length += rs.getTotalLength();
                }
                if (rs.getRouteDestination() == rl) {
                    length += -rs.getTotalLength();
                }
            }
            for (RollingStock rs : CarManager.instance().getList(this)) {
                if (rs.getRouteLocation() == rl) {
                    length += rs.getTotalLength();
                }
                if (rs.getRouteDestination() == rl) {
                    length += -rs.getTotalLength();
                }
            }
            if (rl == routeLocation) {
                break;
            }
        }
    }
    return length;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 30 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class TrainBuilder method redirectCarsFromAlternateTrack.

/**
     * Checks to see if cars that are already in the train can be redirected
     * from the alternate track to the spur that really wants the car. Fixes the
     * issue of having cars placed at the alternate when the spur's cars get
     * pulled by this train, but cars were sent to the alternate because the
     * spur was full at the time it was tested.
     *
     * @return true if one or more cars were redirected
     */
private boolean redirectCarsFromAlternateTrack() {
    if (!Setup.isBuildAggressive()) {
        return false;
    }
    boolean redirected = false;
    List<RollingStock> cars = carManager.getByTrainList(_train);
    for (RollingStock rs : cars) {
        Car car = (Car) rs;
        // does the car have a final destination and the destination is this one?
        if (car.getFinalDestination() == null || car.getFinalDestinationTrack() == null || !car.getFinalDestinationName().equals(car.getDestinationName())) {
            continue;
        }
        log.debug("Car ({}) destination track ({}) has final destination track ({}) location ({})", car.toString(), car.getDestinationTrackName(), car.getFinalDestinationTrackName(), // NOI18N
        car.getDestinationName());
        // is the car in a kernel?
        if (car.getKernel() != null && !car.getKernel().isLead(car)) {
            continue;
        }
        if (car.testDestination(car.getFinalDestination(), car.getFinalDestinationTrack()).equals(Track.OKAY)) {
            Track alternate = car.getFinalDestinationTrack().getAlternateTrack();
            if (alternate != null && car.getDestinationTrack() == alternate && (alternate.getTrackType().equals(Track.YARD) || alternate.getTrackType().equals(Track.INTERCHANGE)) && checkDropTrainDirection(car, car.getRouteDestination(), car.getFinalDestinationTrack()) && checkTrainCanDrop(car, car.getFinalDestinationTrack())) {
                log.debug("Car ({}) alternate track ({}) can be redirected to final destination track ({})", car.toString(), car.getDestinationTrackName(), car.getFinalDestinationTrackName());
                if (car.getKernel() != null) {
                    for (Car k : car.getKernel().getCars()) {
                        addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildRedirectFromAlternate"), new Object[] { car.getFinalDestinationName(), car.getFinalDestinationTrackName(), k.toString(), car.getDestinationTrackName() }));
                        k.setDestination(car.getFinalDestination(), car.getFinalDestinationTrack());
                    }
                } else {
                    addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildRedirectFromAlternate"), new Object[] { car.getFinalDestinationName(), car.getFinalDestinationTrackName(), car.toString(), car.getDestinationTrackName() }));
                    car.setDestination(car.getFinalDestination(), car.getFinalDestinationTrack());
                }
                redirected = true;
            }
        }
    }
    return redirected;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Track(jmri.jmrit.operations.locations.Track)

Aggregations

RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)43 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)13 Car (jmri.jmrit.operations.rollingstock.cars.Car)13 Route (jmri.jmrit.operations.routes.Route)11 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)11 Track (jmri.jmrit.operations.locations.Track)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 Location (jmri.jmrit.operations.locations.Location)5 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)5 Train (jmri.jmrit.operations.trains.Train)5 BufferedWriter (java.io.BufferedWriter)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 PrintWriter (java.io.PrintWriter)4 Dimension (java.awt.Dimension)2 JPanel (javax.swing.JPanel)2 XmlFile (jmri.jmrit.XmlFile)2 HardcopyWriter (jmri.util.davidflanagan.HardcopyWriter)2