use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.
the class Track method getNextScheduleItem.
public ScheduleItem getNextScheduleItem() {
Schedule sch = getSchedule();
if (sch == null) {
log.warn("Can not find schedule (" + getScheduleId() + ") assigned to track (" + getName() + ")");
return null;
}
List<ScheduleItem> items = sch.getItemsBySequenceList();
ScheduleItem nextSi = null;
for (int i = 0; i < items.size(); i++) {
nextSi = items.get(i);
if (getCurrentScheduleItem() == nextSi) {
if (++i < items.size()) {
nextSi = items.get(i);
} else {
nextSi = items.get(0);
}
setScheduleItemId(nextSi.getId());
break;
}
}
return nextSi;
}
use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.
the class Track method getCurrentScheduleItem.
/**
* Get's the current schedule item for this track Protects against user
* deleting an item in a shared schedule. Recommend using this versus
* getScheduleItemId() as the id can be obsolete.
* @return The current ScheduleItem.
*/
public ScheduleItem getCurrentScheduleItem() {
Schedule sch = getSchedule();
if (sch == null) {
log.debug("Can not find schedule id: ({}) assigned to track ({})", getScheduleId(), getName());
return null;
}
ScheduleItem currentSi = sch.getItemById(getScheduleItemId());
if (currentSi == null && sch.getSize() > 0) {
log.debug("Can not find schedule item id: ({}) for schedule ({})", getScheduleItemId(), getScheduleName());
// reset schedule
setScheduleItemId((sch.getItemsBySequenceList().get(0)).getId());
currentSi = sch.getItemById(getScheduleItemId());
}
return currentSi;
}
use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.
the class TrainByCarTypeFrame method removeLocationAndTrackPropertyChange.
/**
* Remove property listeners for locations and tracks
*/
private void removeLocationAndTrackPropertyChange() {
for (Location loc : locationManager.getList()) {
loc.removePropertyChangeListener(this);
for (Track track : loc.getTrackList()) {
track.removePropertyChangeListener(this);
Schedule schedule = track.getSchedule();
if (schedule != null) {
schedule.removePropertyChangeListener(this);
}
}
}
}
use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.
the class SpurEditFrame method saveTrack.
@Override
protected void saveTrack(Track track) {
// save the schedule
Object selected = comboBoxSchedules.getSelectedItem();
if (selected == null) {
track.setScheduleId(Track.NONE);
} else {
Schedule sch = (Schedule) selected;
// update only if the schedule has changed
track.setScheduleId(sch.getId());
}
textSchError.setText(track.checkScheduleValid());
super.saveTrack(track);
}
use of jmri.jmrit.operations.locations.schedules.Schedule in project JMRI by JMRI.
the class LocationTest method testTrackPriority.
// test track priority
public void testTrackPriority() {
LocationManager locMan = new LocationManager();
Location l = locMan.newLocation("TestPriority Location");
Track t1 = l.addTrack("Yard 1", Track.YARD);
Track t2 = l.addTrack("Yard 2", Track.YARD);
Track t3 = l.addTrack("Siding 1", Track.SPUR);
Track t4 = l.addTrack("Siding 2", Track.SPUR);
Track t5 = l.addTrack("Interchange 1", Track.INTERCHANGE);
Track t6 = l.addTrack("Interchange 2", Track.INTERCHANGE);
Track t7 = l.addTrack("Interchange 3", Track.INTERCHANGE);
// set the priority bias
t1.setMoves(12);
t2.setMoves(14);
// lowest priority
t3.setMoves(18);
t4.setMoves(11);
// highest priority
t5.setMoves(10);
t6.setMoves(16);
t7.setMoves(15);
// get all tracks ids
List<Track> tracks = l.getTrackByMovesList(null);
Assert.assertEquals("number of tracks", 7, tracks.size());
Assert.assertEquals("1st track", t5, tracks.get(0));
Assert.assertEquals("2nd track", t4, tracks.get(1));
Assert.assertEquals("3rd track", t1, tracks.get(2));
Assert.assertEquals("4th track", t2, tracks.get(3));
Assert.assertEquals("5th track", t7, tracks.get(4));
Assert.assertEquals("6th track", t6, tracks.get(5));
Assert.assertEquals("7th track", t3, tracks.get(6));
// get interchange tracks ids
tracks = l.getTrackByMovesList(Track.INTERCHANGE);
Assert.assertEquals("number of tracks", 3, tracks.size());
Assert.assertEquals("1st track", t5, tracks.get(0));
Assert.assertEquals("2nd track", t7, tracks.get(1));
Assert.assertEquals("3rd track", t6, tracks.get(2));
// get siding tracks ids
tracks = l.getTrackByMovesList(Track.SPUR);
Assert.assertEquals("number of tracks", 2, tracks.size());
Assert.assertEquals("1st track", t4, tracks.get(0));
Assert.assertEquals("2nd track", t3, tracks.get(1));
// get yard tracks ids
tracks = l.getTrackByMovesList(Track.YARD);
Assert.assertEquals("number of tracks", 2, tracks.size());
Assert.assertEquals("1st track", t1, tracks.get(0));
Assert.assertEquals("2nd track", t2, tracks.get(1));
// tracks with schedules get priority
Schedule sch = ScheduleManager.instance().newSchedule("dummy schedule");
t3.setScheduleId(sch.getId());
// get all tracks ids
tracks = l.getTrackByMovesList(null);
Assert.assertEquals("number of tracks", 7, tracks.size());
Assert.assertEquals("1st track", t3, tracks.get(0));
Assert.assertEquals("2nd track", t5, tracks.get(1));
Assert.assertEquals("3rd track", t4, tracks.get(2));
Assert.assertEquals("4th track", t1, tracks.get(3));
Assert.assertEquals("5th track", t2, tracks.get(4));
Assert.assertEquals("6th track", t7, tracks.get(5));
Assert.assertEquals("7th track", t6, tracks.get(6));
// t4 has less moves than t3 so it will move up in priority
t4.setScheduleId(sch.getId());
// get all tracks ids
tracks = l.getTrackByMovesList(null);
Assert.assertEquals("number of tracks", 7, tracks.size());
Assert.assertEquals("1st track", t4, tracks.get(0));
Assert.assertEquals("2nd track", t3, tracks.get(1));
Assert.assertEquals("3rd track", t5, tracks.get(2));
Assert.assertEquals("4th track", t1, tracks.get(3));
Assert.assertEquals("5th track", t2, tracks.get(4));
Assert.assertEquals("6th track", t7, tracks.get(5));
Assert.assertEquals("7th track", t6, tracks.get(6));
// remove dummy schedule
ScheduleManager.instance().deregister(sch);
}
Aggregations