Search in sources :

Example 96 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class WaitSwitchListAction method checkForlocationChange.

/*
     * Waiting for any location's switch list to change
     */
private void checkForlocationChange() {
    for (Location location : LocationManager.instance().getList()) {
        if (location != null && location.isSwitchListEnabled() && location.getStatus().equals(Location.MODIFIED)) {
            removePropertyChangeLocations();
            finishAction(true);
            break;
        }
    }
}
Also used : Location(jmri.jmrit.operations.locations.Location)

Example 97 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class PrintLocationsAction method printAnalysisSelected.

private void printAnalysisSelected() throws IOException {
    CarManager carManager = CarManager.instance();
    List<Location> locations = manager.getLocationsByNameList();
    List<RollingStock> cars = carManager.getByLocationList();
    String[] carTypes = CarTypes.instance().getNames();
    String s = Bundle.getMessage("TrackAnalysis") + NEW_LINE;
    writer.write(s);
    // print the car type being analyzed
    for (String type : carTypes) {
        // get the total length for a given car type
        int numberOfCars = 0;
        int totalTrackLength = 0;
        for (RollingStock car : cars) {
            if (car.getTypeName().equals(type) && car.getLocation() != null) {
                numberOfCars++;
                totalTrackLength += car.getTotalLength();
            }
        }
        writer.write(MessageFormat.format(Bundle.getMessage("NumberTypeLength"), new Object[] { numberOfCars, type, totalTrackLength, Setup.getLengthUnit().toLowerCase() }) + NEW_LINE);
        // don't bother reporting when the number of cars for a given type is zero
        if (numberOfCars > 0) {
            // spurs
            writer.write(SPACE + MessageFormat.format(Bundle.getMessage("SpurTrackThatAccept"), new Object[] { type }) + NEW_LINE);
            int trackLength = getTrackLengthAcceptType(locations, type, Track.SPUR);
            if (trackLength > 0) {
                writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthSpur"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
            } else {
                writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
            }
            // yards
            writer.write(SPACE + MessageFormat.format(Bundle.getMessage("YardTrackThatAccept"), new Object[] { type }) + NEW_LINE);
            trackLength = getTrackLengthAcceptType(locations, type, Track.YARD);
            if (trackLength > 0) {
                writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthYard"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
            } else {
                writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
            }
            // interchanges
            writer.write(SPACE + MessageFormat.format(Bundle.getMessage("InterchangesThatAccept"), new Object[] { type }) + NEW_LINE);
            trackLength = getTrackLengthAcceptType(locations, type, Track.INTERCHANGE);
            if (trackLength > 0) {
                writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthInterchange"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
            } else {
                writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
            }
            // staging
            if (showStaging) {
                writer.write(SPACE + MessageFormat.format(Bundle.getMessage("StageTrackThatAccept"), new Object[] { type }) + NEW_LINE);
                trackLength = getTrackLengthAcceptType(locations, type, Track.STAGING);
                if (trackLength > 0) {
                    writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthStage"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
                } else {
                    writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
                }
            }
        }
    }
}
Also used : CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Location(jmri.jmrit.operations.locations.Location)

Example 98 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class PrintLocationsAction method printSchedulesSelected.

private void printSchedulesSelected() throws IOException {
    List<Location> locations = manager.getLocationsByNameList();
    String s = padOutString(Bundle.getMessage("Schedules"), MAX_NAME_LENGTH) + " " + Bundle.getMessage("Location") + " - " + Bundle.getMessage("SpurName") + NEW_LINE;
    writer.write(s);
    List<Schedule> schedules = ScheduleManager.instance().getSchedulesByNameList();
    for (Schedule schedule : schedules) {
        for (Location location : locations) {
            if (_location != null && location != _location) {
                continue;
            }
            List<Track> spurs = location.getTrackByNameList(Track.SPUR);
            for (Track spur : spurs) {
                if (spur.getScheduleId().equals(schedule.getId())) {
                    // pad out schedule name
                    s = padOutString(schedule.getName(), MAX_NAME_LENGTH) + " " + location.getName() + " - " + spur.getName();
                    String status = spur.checkScheduleValid();
                    if (!status.equals(Track.SCHEDULE_OKAY)) {
                        StringBuffer buf = new StringBuffer(s);
                        for (int m = s.length(); m < 63; m++) {
                            buf.append(" ");
                        }
                        s = buf.toString();
                        if (s.length() > 63) {
                            s = s.substring(0, 63);
                        }
                        s = s + TAB + status;
                    }
                    s = s + NEW_LINE;
                    writer.write(s);
                    // show the schedule's mode
                    String mode = Bundle.getMessage("Sequential");
                    if (spur.getScheduleMode() == Track.MATCH) {
                        mode = Bundle.getMessage("Match");
                    }
                    s = padOutString("", MAX_NAME_LENGTH) + SPACE + Bundle.getMessage("ScheduleMode") + ": " + mode + NEW_LINE;
                    writer.write(s);
                    // show alternate track if there's one
                    if (spur.getAlternateTrack() != null) {
                        s = padOutString("", MAX_NAME_LENGTH) + SPACE + MessageFormat.format(Bundle.getMessage("AlternateTrackName"), new Object[] { spur.getAlternateTrack().getName() }) + NEW_LINE;
                        writer.write(s);
                    }
                    // show custom loads from staging if not 100%
                    if (spur.getReservationFactor() != 100) {
                        s = padOutString("", MAX_NAME_LENGTH) + SPACE + MessageFormat.format(Bundle.getMessage("PercentageStaging"), new Object[] { spur.getReservationFactor() }) + NEW_LINE;
                        writer.write(s);
                    }
                }
            }
        }
    }
    if (printComments.isSelected() || printDetails.isSelected() || printAnalysis.isSelected()) {
        writer.write(FORM_FEED);
    }
}
Also used : Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 99 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class LocationsByCarLoadFrame method updateLocations.

/**
     * Update tracks at locations based on car type serviced, or car loads
     * serviced. If car loads, disable any tracks that don't service the car
     * type selected.
     */
private void updateLocations() {
    log.debug("update checkboxes");
    removePropertyChangeLocations();
    trackCheckBoxList.clear();
    int x = 0;
    pLocations.removeAll();
    String type = (String) typeComboBox.getSelectedItem();
    String load = (String) loadComboBox.getSelectedItem();
    log.debug("Selected car type : ({}) load ({})", type, load);
    // did the location get deleted?
    if (_location != null && locationManager.getLocationByName(_location.getName()) == null) {
        _location = null;
    }
    List<Location> locations = locationManager.getLocationsByNameList();
    for (Location location : locations) {
        // show only one location?
        if (_location != null && _location != location) {
            continue;
        }
        location.addPropertyChangeListener(this);
        JLabel locationName = new JLabel(location.getName());
        addItemLeft(pLocations, locationName, 0, x++);
        List<Track> tracks = location.getTrackByNameList(null);
        for (Track track : tracks) {
            track.addPropertyChangeListener(this);
            JCheckBox cb = new JCheckBox(track.getName());
            cb.setName(track.getId() + "-" + "r");
            addCheckBoxAction(cb);
            trackCheckBoxList.add(cb);
            cb.setEnabled(track.acceptsTypeName(type));
            cb.setSelected(track.acceptsLoad(load, type));
            addItemLeft(pLocations, cb, 1, x++);
            if (cb.isEnabled()) {
                cb.setToolTipText(MessageFormat.format(Bundle.getMessage("TipTrackCarLoad"), new Object[] { load }));
            } else {
                cb.setToolTipText(MessageFormat.format(Bundle.getMessage("TipTrackNotThisType"), new Object[] { type }));
            }
        }
        if (location.isStaging()) {
            JLabel ships = new JLabel(location.getName() + " (" + Bundle.getMessage("Ships") + ")");
            addItemLeft(pLocations, ships, 0, x++);
            for (Track track : tracks) {
                JCheckBox cb = new JCheckBox(track.getName());
                cb.setName(track.getId() + "-" + "s");
                addCheckBoxAction(cb);
                trackCheckBoxList.add(cb);
                cb.setEnabled(track.acceptsTypeName(type));
                cb.setSelected(track.shipsLoad(load, type));
                addItemLeft(pLocations, cb, 1, x++);
                if (cb.isEnabled()) {
                    cb.setToolTipText(MessageFormat.format(Bundle.getMessage("TipTrackCarShipsLoad"), new Object[] { load }));
                } else {
                    cb.setToolTipText(MessageFormat.format(Bundle.getMessage("TipTrackNotThisType"), new Object[] { type }));
                }
            }
        }
    }
    pLocations.revalidate();
    repaint();
}
Also used : JCheckBox(javax.swing.JCheckBox) JLabel(javax.swing.JLabel) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 100 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class CarSetFrame method change.

@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "GUI ease of use")
protected boolean change(Car car) {
    // save the auto button
    autoReturnWhenEmptyTrackCheckBoxSelected = autoReturnWhenEmptyTrackCheckBox.isSelected();
    // car load
    if (!ignoreLoadCheckBox.isSelected() && loadComboBox.getSelectedItem() != null) {
        String load = (String) loadComboBox.getSelectedItem();
        if (!car.getLoadName().equals(load)) {
            if (CarLoads.instance().containsName(car.getTypeName(), load)) {
                car.setLoadName(load);
                updateComboBoxesLoadChange();
            } else {
                JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("carLoadNotValid"), new Object[] { load, car.getTypeName() }), Bundle.getMessage("carCanNotChangeLoad"), JOptionPane.WARNING_MESSAGE);
            }
        }
    }
    // set final destination fields before destination in case there's a schedule at destination
    if (!ignoreFinalDestinationCheckBox.isSelected()) {
        if (finalDestinationBox.getSelectedItem() == null) {
            car.setFinalDestination(null);
            car.setFinalDestinationTrack(null);
        } else {
            Track finalDestTrack = null;
            if (finalDestTrackBox.getSelectedItem() != null) {
                finalDestTrack = (Track) finalDestTrackBox.getSelectedItem();
            }
            if (finalDestTrack != null && car.getFinalDestinationTrack() != finalDestTrack && finalDestTrack.getTrackType().equals(Track.STAGING)) {
                log.debug("Destination track ({}) is staging", finalDestTrack.getName());
                JOptionPane.showMessageDialog(this, Bundle.getMessage("rsDoNotSelectStaging"), Bundle.getMessage("rsCanNotFinal"), JOptionPane.ERROR_MESSAGE);
                return false;
            }
            car.setFinalDestination((Location) finalDestinationBox.getSelectedItem());
            car.setFinalDestinationTrack(finalDestTrack);
            String status = car.testDestination((Location) finalDestinationBox.getSelectedItem(), finalDestTrack);
            if (!status.equals(Track.OKAY)) {
                JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("rsCanNotFinalMsg"), new Object[] { car.toString(), status }), Bundle.getMessage("rsCanNotFinal"), JOptionPane.WARNING_MESSAGE);
            }
        }
    }
    // kernel
    if (!ignoreKernelCheckBox.isSelected() && kernelComboBox.getSelectedItem() != null) {
        if (kernelComboBox.getSelectedItem().equals(CarManager.NONE)) {
            car.setKernel(null);
        } else if (!car.getKernelName().equals(kernelComboBox.getSelectedItem())) {
            car.setKernel(carManager.getKernelByName((String) kernelComboBox.getSelectedItem()));
            // if car has FRED or is caboose make lead
            if (car.hasFred() || car.isCaboose()) {
                car.getKernel().setLead(car);
            }
            car.setBlocking(car.getKernel().getSize());
        }
    }
    // save car's track
    Track saveTrack = car.getTrack();
    if (!super.change(car)) {
        return false;
    }
    // return when empty fields
    if (!ignoreRWECheckBox.isSelected()) {
        // check that RWE load is valid for this car's type
        if (CarLoads.instance().getNames(car.getTypeName()).contains(loadReturnWhenEmptyBox.getSelectedItem())) {
            car.setReturnWhenEmptyLoadName((String) loadReturnWhenEmptyBox.getSelectedItem());
        } else {
            log.debug("Car ({}) type ({}) doesn't support RWE load ({})", car.toString(), car.getTypeName(), loadReturnWhenEmptyBox.getSelectedItem());
            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("carLoadNotValid"), new Object[] { loadReturnWhenEmptyBox.getSelectedItem(), car.getTypeName() }), Bundle.getMessage("carCanNotChangeRweLoad"), JOptionPane.WARNING_MESSAGE);
        }
        if (destReturnWhenEmptyBox.getSelectedItem() == null) {
            car.setReturnWhenEmptyDestination(null);
            car.setReturnWhenEmptyDestTrack(null);
        } else {
            Location locationRWE = (Location) destReturnWhenEmptyBox.getSelectedItem();
            if (trackReturnWhenEmptyBox.getSelectedItem() != null) {
                Track trackRWE = (Track) trackReturnWhenEmptyBox.getSelectedItem();
                // warn user if they selected a staging track
                if (trackRWE != null && trackRWE.getTrackType().equals(Track.STAGING)) {
                    log.debug("Return when empty track ({}) is staging", trackRWE.getName());
                    JOptionPane.showMessageDialog(this, Bundle.getMessage("rsDoNotSelectStaging"), Bundle.getMessage("rsCanNotRWE"), JOptionPane.ERROR_MESSAGE);
                    return false;
                }
                // use a test car with a load of "E" and no length
                String status = getTestCar(car).testDestination(locationRWE, trackRWE);
                if (!status.equals(Track.OKAY)) {
                    JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("rsCanNotRWEMsg"), new Object[] { car.toString(), status }), Bundle.getMessage("rsCanNotRWE"), JOptionPane.WARNING_MESSAGE);
                }
                car.setReturnWhenEmptyDestTrack(trackRWE);
            } else {
                car.setReturnWhenEmptyDestTrack(null);
            }
            car.setReturnWhenEmptyDestination(locationRWE);
        }
    }
    // check to see if there's a schedule when placing the car at a spur
    if (!ignoreLocationCheckBox.isSelected() && trackLocationBox.getSelectedItem() != null && saveTrack != trackLocationBox.getSelectedItem()) {
        Track track = (Track) trackLocationBox.getSelectedItem();
        if (track.getSchedule() != null) {
            if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("rsDoYouWantSchedule"), new Object[] { car.toString() }), MessageFormat.format(Bundle.getMessage("rsSpurHasSchedule"), new Object[] { track.getName(), track.getScheduleName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                String results = track.checkSchedule(car);
                if (!results.equals(Track.OKAY)) {
                    JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("rsNotAbleToApplySchedule"), new Object[] { results }), Bundle.getMessage("rsApplyingScheduleFailed"), JOptionPane.ERROR_MESSAGE);
                    // restore previous location and track so we'll ask to test schedule again
                    if (saveTrack != null) {
                        car.setLocation(saveTrack.getLocation(), saveTrack);
                    } else {
                        car.setLocation(null, null);
                    }
                    return false;
                }
                // now apply schedule to car
                track.scheduleNext(car);
                car.loadNext(track);
            }
        }
    }
    // determine if train services this car's load
    if (car.getTrain() != null) {
        Train train = car.getTrain();
        if (!train.acceptsLoad(car.getLoadName(), car.getTypeName())) {
            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("carTrainNotServLoad"), new Object[] { car.getLoadName(), train.getName() }), Bundle.getMessage("rsNotMove"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
        if (car.getLocation() != null && car.getDestination() != null && !train.services(car)) {
            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("carTrainNotService"), new Object[] { car.toString(), train.getName() }), Bundle.getMessage("rsNotMove"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }
    checkTrain(car);
    // is this car part of a kernel?
    if (askKernelChange && car.getKernel() != null) {
        List<RollingStock> list = car.getKernel().getGroup();
        if (list.size() > 1) {
            if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("carInKernel"), new Object[] { car.toString() }), MessageFormat.format(Bundle.getMessage("carPartKernel"), new Object[] { car.getKernelName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                if (!updateGroup(list)) {
                    return false;
                }
            } else if (outOfServiceCheckBox.isSelected()) {
                // don't leave car in kernel if out of service
                car.setKernel(null);
            }
        }
    }
    return true;
}
Also used : Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Location(jmri.jmrit.operations.locations.Location) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Location (jmri.jmrit.operations.locations.Location)186 Track (jmri.jmrit.operations.locations.Track)108 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)82 Route (jmri.jmrit.operations.routes.Route)51 LocationManager (jmri.jmrit.operations.locations.LocationManager)43 Car (jmri.jmrit.operations.rollingstock.cars.Car)41 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)29 RouteManager (jmri.jmrit.operations.routes.RouteManager)21 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 Test (org.junit.Test)18 JCheckBox (javax.swing.JCheckBox)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 Train (jmri.jmrit.operations.trains.Train)13 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)10 File (java.io.File)9 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)9 TrainManager (jmri.jmrit.operations.trains.TrainManager)8