Search in sources :

Example 11 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class Track method checkScheduleValid.

/**
     * Check to see if schedule is valid for the track at this location.
     *
     * @return SCHEDULE_OKAY if schedule okay, otherwise an error message.
     */
public String checkScheduleValid() {
    String status = SCHEDULE_OKAY;
    if (getScheduleId().equals(NONE)) {
        return status;
    }
    Schedule schedule = getSchedule();
    if (schedule == null) {
        return MessageFormat.format(Bundle.getMessage("CanNotFindSchedule"), new Object[] { getScheduleId() });
    }
    List<ScheduleItem> scheduleItems = schedule.getItemsBySequenceList();
    if (scheduleItems.size() == 0) {
        return Bundle.getMessage("empty");
    }
    for (ScheduleItem si : scheduleItems) {
        // check train schedules
        if (!si.getSetoutTrainScheduleId().equals(ScheduleItem.NONE) && TrainScheduleManager.instance().getScheduleById(si.getSetoutTrainScheduleId()) == null) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getSetoutTrainScheduleId() });
            break;
        }
        if (!si.getPickupTrainScheduleId().equals(ScheduleItem.NONE) && TrainScheduleManager.instance().getScheduleById(si.getPickupTrainScheduleId()) == null) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getPickupTrainScheduleId() });
            break;
        }
        if (!_location.acceptsTypeName(si.getTypeName())) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getTypeName() });
            break;
        }
        if (!acceptsTypeName(si.getTypeName())) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getTypeName() });
            break;
        }
        // check roads, accepted by track, valid road, and there's at least one car with that road
        if (!si.getRoadName().equals(ScheduleItem.NONE) && (!acceptsRoadName(si.getRoadName()) || !CarRoads.instance().containsName(si.getRoadName()) || CarManager.instance().getByTypeAndRoad(si.getTypeName(), si.getRoadName()) == null)) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getRoadName() });
            break;
        }
        // check loads
        List<String> loads = CarLoads.instance().getNames(si.getTypeName());
        if (!si.getReceiveLoadName().equals(ScheduleItem.NONE) && (!acceptsLoad(si.getReceiveLoadName(), si.getTypeName()) || !loads.contains(si.getReceiveLoadName()))) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getReceiveLoadName() });
            break;
        }
        if (!si.getShipLoadName().equals(ScheduleItem.NONE) && !loads.contains(si.getShipLoadName())) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getShipLoadName() });
            break;
        }
        // check destination
        if (si.getDestination() != null && (!si.getDestination().acceptsTypeName(si.getTypeName()) || LocationManager.instance().getLocationById(si.getDestination().getId()) == null)) {
            status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getDestination() });
            break;
        }
        // check destination track
        if (si.getDestination() != null && si.getDestinationTrack() != null) {
            if (!si.getDestination().isTrackAtLocation(si.getDestinationTrack())) {
                status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getDestinationTrack() + " (" + Bundle.getMessage("Track") + ")" });
                break;
            }
            if (!si.getDestinationTrack().acceptsTypeName(si.getTypeName())) {
                status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getDestinationTrack() + " (" + Bundle.getMessage("Type") + ")" });
                break;
            }
            if (!si.getRoadName().equals(ScheduleItem.NONE) && !si.getDestinationTrack().acceptsRoadName(si.getRoadName())) {
                status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getDestinationTrack() + " (" + Bundle.getMessage("Road") + ")" });
                break;
            }
            if (!si.getShipLoadName().equals(ScheduleItem.NONE) && !si.getDestinationTrack().acceptsLoad(si.getShipLoadName(), si.getTypeName())) {
                status = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getDestinationTrack() + " (" + Bundle.getMessage("Load") + ")" });
                break;
            }
        }
    }
    return status;
}
Also used : ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) TrainSchedule(jmri.jmrit.operations.trains.timetable.TrainSchedule)

Example 12 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class Track method scheduleNext.

/**
     * Check to see if track has schedule and if it does will schedule the next
     * item in the list. Load the car with the next schedule load if one exists,
     * and set the car's final destination if there's one in the schedule.
     * @param car The Car to be modified.
     *
     * @return Track.OKAY or Track.SCHEDULE
     */
public String scheduleNext(Car car) {
    // clean up the car's final destination if sent to that destination and there isn't a schedule
    if (getScheduleId().equals(NONE) && car.getDestination() != null && car.getDestination().equals(car.getFinalDestination()) && car.getDestinationTrack() != null && (car.getDestinationTrack().equals(car.getFinalDestinationTrack()) || car.getFinalDestinationTrack() == null)) {
        car.setFinalDestination(null);
        car.setFinalDestinationTrack(null);
    }
    // check for schedule, only spurs can have a schedule
    if (getScheduleId().equals(NONE) || getSchedule() == null) {
        return OKAY;
    }
    // is car part of a kernel?
    if (car.getKernel() != null && !car.getKernel().isLead(car)) {
        log.debug("Car ({}) is part of kernel ({}) not lead", car.toString(), car.getKernelName());
        return OKAY;
    }
    if (!car.getScheduleItemId().equals(Car.NONE)) {
        String id = car.getScheduleItemId();
        log.debug("Car ({}) has schedule item id ({})", car.toString(), car.getScheduleItemId());
        Schedule sch = getSchedule();
        if (sch != null) {
            ScheduleItem si = sch.getItemById(id);
            car.setScheduleItemId(Car.NONE);
            if (si != null) {
                loadNext(si, car);
                return OKAY;
            }
            log.debug("Schedule id ({}) not valid for track ({})", id, getName());
        // user could have deleted the schedule item after build train, so not really an error
        // return SCHEDULE + " ERROR id " + id + " not valid for track ("+ getName() + ")"; // NOI18N
        }
    }
    if (getScheduleMode() == MATCH && !searchSchedule(car).equals(OKAY)) {
        return SCHEDULE + MessageFormat.format(Bundle.getMessage("matchMessage"), new Object[] { getScheduleName() });
    }
    ScheduleItem currentSi = getCurrentScheduleItem();
    log.debug("Destination track ({}) has schedule ({}) item id ({}) mode: {} ({})", getName(), getScheduleName(), getScheduleItemId(), getScheduleMode(), // NOI18N
    getScheduleMode() == SEQUENTIAL ? "Sequential" : "Match");
    if (currentSi != null && (currentSi.getSetoutTrainScheduleId().equals(ScheduleItem.NONE) || TrainManager.instance().getTrainScheduleActiveId().equals(currentSi.getSetoutTrainScheduleId())) && car.getTypeName().equals(currentSi.getTypeName()) && (currentSi.getRoadName().equals(ScheduleItem.NONE) || car.getRoadName().equals(currentSi.getRoadName())) && (currentSi.getReceiveLoadName().equals(ScheduleItem.NONE) || car.getLoadName().equals(currentSi.getReceiveLoadName()))) {
        loadNext(currentSi, car);
        car.setScheduleItemId(Car.NONE);
        // bump schedule
        bumpSchedule();
    } else if (currentSi != null) {
        // log.debug("Car (" + toString() + ") type (" + getType() + ") road (" + getRoad() + ") load ("
        // + getLoad() + ") arrived out of sequence, needed type (" + currentSi.getType() // NOI18N
        // + ") road (" + currentSi.getRoad() + ") load (" + currentSi.getLoad() + ")"); // NOI18N
        // build return message
        String timetableName = "";
        String currentTimetableName = "";
        TrainSchedule sch = TrainScheduleManager.instance().getScheduleById(TrainManager.instance().getTrainScheduleActiveId());
        if (sch != null) {
            timetableName = sch.getName();
        }
        sch = TrainScheduleManager.instance().getScheduleById(currentSi.getSetoutTrainScheduleId());
        if (sch != null) {
            currentTimetableName = sch.getName();
        }
        String mode = Bundle.getMessage("sequential");
        if (getScheduleMode() == 1) {
            mode = Bundle.getMessage("match");
        }
        return SCHEDULE + MessageFormat.format(Bundle.getMessage("sequentialMessage"), new Object[] { getScheduleName(), mode, car.toString(), car.getTypeName(), timetableName, car.getRoadName(), car.getLoadName(), currentSi.getTypeName(), currentTimetableName, currentSi.getRoadName(), currentSi.getReceiveLoadName() });
    } else {
        log.error("ERROR Track " + getName() + " current schedule item is null!");
        // NOI18N
        return SCHEDULE + " ERROR Track " + getName() + " current schedule item is null!";
    }
    return OKAY;
}
Also used : ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) TrainSchedule(jmri.jmrit.operations.trains.timetable.TrainSchedule) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) TrainSchedule(jmri.jmrit.operations.trains.timetable.TrainSchedule)

Example 13 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class Track method setScheduleId.

public void setScheduleId(String id) {
    String old = _scheduleId;
    _scheduleId = id;
    if (!old.equals(id)) {
        Schedule schedule = ScheduleManager.instance().getScheduleById(id);
        if (schedule == null) {
            _scheduleName = NONE;
        } else {
            // set the id to the first item in the list
            if (schedule.getItemsBySequenceList().size() > 0) {
                setScheduleItemId(schedule.getItemsBySequenceList().get(0).getId());
            }
            setScheduleCount(0);
        }
        setDirtyAndFirePropertyChange(SCHEDULE_ID_CHANGED_PROPERTY, old, id);
    }
}
Also used : Schedule(jmri.jmrit.operations.locations.schedules.Schedule) TrainSchedule(jmri.jmrit.operations.trains.timetable.TrainSchedule)

Example 14 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class SpurEditFrame method updateScheduleComboBox.

private void updateScheduleComboBox() {
    ScheduleManager.instance().updateComboBox(comboBoxSchedules);
    if (_track != null) {
        Schedule sch = ScheduleManager.instance().getScheduleById(_track.getScheduleId());
        comboBoxSchedules.setSelectedItem(sch);
        textSchError.setText(_track.checkScheduleValid());
        if (sch != null) {
            sch.removePropertyChangeListener(this);
            sch.addPropertyChangeListener(this);
        }
    }
}
Also used : Schedule(jmri.jmrit.operations.locations.schedules.Schedule)

Example 15 with Schedule

use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.

the class SpurEditFrame method dispose.

@Override
public void dispose() {
    ScheduleManager.instance().removePropertyChangeListener(this);
    if (_track != null) {
        Schedule sch = ScheduleManager.instance().getScheduleById(_track.getScheduleId());
        if (sch != null)
            sch.removePropertyChangeListener(this);
    }
    super.dispose();
}
Also used : Schedule(jmri.jmrit.operations.locations.schedules.Schedule)

Aggregations

Schedule (jmri.jmrit.operations.locations.schedules.Schedule)27 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)17 Location (jmri.jmrit.operations.locations.Location)11 Track (jmri.jmrit.operations.locations.Track)11 ScheduleManager (jmri.jmrit.operations.locations.schedules.ScheduleManager)10 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)9 LocationManager (jmri.jmrit.operations.locations.LocationManager)7 Car (jmri.jmrit.operations.rollingstock.cars.Car)7 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)6 Train (jmri.jmrit.operations.trains.Train)5 TrainManager (jmri.jmrit.operations.trains.TrainManager)5 TrainSchedule (jmri.jmrit.operations.trains.timetable.TrainSchedule)5 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)3 Route (jmri.jmrit.operations.routes.Route)3 Kernel (jmri.jmrit.operations.rollingstock.cars.Kernel)2 ScheduleEditFrame (jmri.jmrit.operations.locations.schedules.ScheduleEditFrame)1 CarRoads (jmri.jmrit.operations.rollingstock.cars.CarRoads)1 RouteManager (jmri.jmrit.operations.routes.RouteManager)1