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;
}
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;
}
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);
}
}
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);
}
}
}
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();
}
Aggregations