use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getNumberEmptyCarsInTrain.
/**
* Gets the number of empty cars in the train when train departs the route
* location.
* @param routeLocation The RouteLocation.
*
* @return The number of empty cars in the train departing the route
* location.
*/
public int getNumberEmptyCarsInTrain(RouteLocation routeLocation) {
int number = 0;
Route route = getRoute();
if (route != null) {
for (RouteLocation rl : route.getLocationsBySequenceList()) {
for (RollingStock rs : CarManager.instance().getList(this)) {
Car car = (Car) rs;
if (!car.getLoadType().equals(CarLoad.LOAD_TYPE_EMPTY)) {
continue;
}
if (car.getRouteLocation() == rl) {
number++;
}
if (car.getRouteDestination() == rl) {
number--;
}
}
if (rl == routeLocation) {
break;
}
}
}
return number;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method move.
/**
* Move train to next location in the route. Will move engines, cars, and
* train icon. Will also terminate a train after it arrives at its final
* destination.
*/
public void move() {
log.debug("Move train (" + getName() + ")");
if (getRoute() == null || getCurrentLocation() == null) {
// break terminate loop
setBuilt(false);
return;
}
if (!isBuilt()) {
log.error("ERROR attempt to move train ({}) that hasn't been built", getName());
return;
}
RouteLocation rl = getCurrentLocation();
RouteLocation rlNext = getNextLocation(rl);
setCurrentLocation(rlNext);
// cars and engines will move via property change
setDirtyAndFirePropertyChange(TRAIN_LOCATION_CHANGED_PROPERTY, rl, rlNext);
moveTrainIcon(rlNext);
updateStatus(rl, rlNext);
// tell GUI that train has complete its move
setDirtyAndFirePropertyChange(TRAIN_MOVE_COMPLETE_CHANGED_PROPERTY, rl, rlNext);
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-trains.dtd.
*
* @return Contents in a JDOM Element
*/
public Element store() {
Element e = new Element(Xml.TRAIN);
e.setAttribute(Xml.ID, getId());
e.setAttribute(Xml.NAME, getName());
e.setAttribute(Xml.DESCRIPTION, getRawDescription());
e.setAttribute(Xml.DEPART_HOUR, getDepartureTimeHour());
e.setAttribute(Xml.DEPART_MINUTE, getDepartureTimeMinute());
Element eRowColor = new Element(Xml.ROW_COLOR);
eRowColor.setAttribute(Xml.NAME, getTableRowColorName());
eRowColor.setAttribute(Xml.RESET_ROW_COLOR, getRowColorNameReset());
e.addContent(eRowColor);
Element eRoute = new Element(Xml.ROUTE);
if (getRoute() != null) {
// old format
if (Control.backwardCompatible) {
e.setAttribute(Xml.ROUTE, getRoute().getName());
e.setAttribute(Xml.ROUTE_ID, getRoute().getId());
}
// new format
eRoute.setAttribute(Xml.NAME, getRoute().getName());
eRoute.setAttribute(Xml.ID, getRoute().getId());
e.addContent(eRoute);
// build list of locations that this train skips
// new format
String[] locationIds = getTrainSkipsLocations();
if (locationIds.length > 0) {
Element eSkips = new Element(Xml.SKIPS);
for (String id : locationIds) {
Element eLoc = new Element(Xml.LOCATION);
RouteLocation rl = getRoute().getLocationById(id);
if (rl != null) {
eLoc.setAttribute(Xml.NAME, rl.getName());
eLoc.setAttribute(Xml.ID, id);
eSkips.addContent(eLoc);
}
}
eRoute.addContent(eSkips);
}
}
// old format
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String id : getTrainSkipsLocations()) {
// NOI18N
buf.append(id + "%%");
}
e.setAttribute(Xml.SKIP, buf.toString());
}
if (getCurrentLocation() != null) {
e.setAttribute(Xml.CURRENT, getCurrentLocation().getId());
}
if (getDepartureTrack() != null) {
e.setAttribute(Xml.DEPARTURE_TRACK, getDepartureTrack().getId());
}
if (getTerminationTrack() != null) {
e.setAttribute(Xml.TERMINATION_TRACK, getTerminationTrack().getId());
}
if (Control.backwardCompatible) {
// misspelled should have been option not operation
e.setAttribute(Xml.CAR_ROAD_OPERATION, getRoadOption());
}
e.setAttribute(Xml.BUILT_START_YEAR, getBuiltStartYear());
e.setAttribute(Xml.BUILT_END_YEAR, getBuiltEndYear());
e.setAttribute(Xml.NUMBER_ENGINES, getNumberEngines());
e.setAttribute(Xml.ENGINE_ROAD, getEngineRoad());
e.setAttribute(Xml.ENGINE_MODEL, getEngineModel());
e.setAttribute(Xml.REQUIRES, Integer.toString(getRequirements()));
e.setAttribute(Xml.CABOOSE_ROAD, getCabooseRoad());
e.setAttribute(Xml.BUILD_NORMAL, isBuildTrainNormalEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.TO_TERMINAL, isSendCarsToTerminalEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.ALLOW_LOCAL_MOVES, isAllowLocalMovesEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.ALLOW_RETURN, isAllowReturnToStagingEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.ALLOW_THROUGH_CARS, isAllowThroughCarsEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.SERVICE_ALL, isServiceAllCarsWithFinalDestinationsEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.SEND_CUSTOM_STAGING, isSendCarsWithCustomLoadsToStagingEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD_CONSIST, isBuildConsistEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILT, isBuilt() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD, isBuildEnabled() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD_FAILED, getBuildFailed() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.BUILD_FAILED_MESSAGE, getBuildFailedMessage());
e.setAttribute(Xml.PRINTED, isPrinted() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.MODIFIED, isModified() ? Xml.TRUE : Xml.FALSE);
e.setAttribute(Xml.SWITCH_LIST_STATUS, getSwitchListStatus());
if (getLeadEngine() != null) {
e.setAttribute(Xml.LEAD_ENGINE, getLeadEngine().getId());
}
e.setAttribute(Xml.STATUS, getStatus());
e.setAttribute(Xml.TERMINATION_DATE, getTerminationDate());
e.setAttribute(Xml.REQUESTED_CARS, Integer.toString(getNumberCarsRequested()));
e.setAttribute(Xml.STATUS_CODE, Integer.toString(getStatusCode()));
e.setAttribute(Xml.OLD_STATUS_CODE, Integer.toString(getOldStatusCode()));
e.setAttribute(Xml.COMMENT, getComment());
e.setAttribute(Xml.SHOW_TIMES, isShowArrivalAndDepartureTimesEnabled() ? Xml.TRUE : Xml.FALSE);
// build list of car types for this train
String[] types = getTypeNames();
// Old way of saving car types
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String type : types) {
// remove types that have been deleted by user
if (CarTypes.instance().containsName(type) || EngineTypes.instance().containsName(type)) {
// NOI18N
buf.append(type + "%%");
}
}
e.setAttribute(Xml.CAR_TYPES, buf.toString());
}
// new way of saving car types
Element eTypes = new Element(Xml.TYPES);
for (String type : types) {
// don't save types that have been deleted by user
if (EngineTypes.instance().containsName(type)) {
Element eType = new Element(Xml.LOCO_TYPE);
eType.setAttribute(Xml.NAME, type);
eTypes.addContent(eType);
} else if (CarTypes.instance().containsName(type)) {
Element eType = new Element(Xml.CAR_TYPE);
eType.setAttribute(Xml.NAME, type);
eTypes.addContent(eType);
}
}
e.addContent(eTypes);
// save list of car roads for this train
if (!getRoadOption().equals(ALL_ROADS)) {
e.setAttribute(Xml.CAR_ROAD_OPTION, getRoadOption());
String[] roads = getRoadNames();
// old way of saving road names
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String road : roads) {
// NOI18N
buf.append(road + "%%");
}
e.setAttribute(Xml.CAR_ROADS, buf.toString());
}
// new way of saving road names
Element eRoads = new Element(Xml.CAR_ROADS);
for (String road : roads) {
Element eRoad = new Element(Xml.CAR_ROAD);
eRoad.setAttribute(Xml.NAME, road);
eRoads.addContent(eRoad);
}
e.addContent(eRoads);
}
// save list of car loads for this train
if (!getLoadOption().equals(ALL_LOADS)) {
e.setAttribute(Xml.CAR_LOAD_OPTION, getLoadOption());
String[] loads = getLoadNames();
// old way of saving car loads
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String load : loads) {
// NOI18N
buf.append(load + "%%");
}
e.setAttribute(Xml.CAR_LOADS, buf.toString());
}
// new way of saving car loads
Element eLoads = new Element(Xml.CAR_LOADS);
for (String load : loads) {
Element eLoad = new Element(Xml.CAR_LOAD);
eLoad.setAttribute(Xml.NAME, load);
eLoads.addContent(eLoad);
}
e.addContent(eLoads);
}
// save list of car owners for this train
if (!getOwnerOption().equals(ALL_OWNERS)) {
e.setAttribute(Xml.CAR_OWNER_OPTION, getOwnerOption());
String[] owners = getOwnerNames();
// old way of saving car owners
if (Control.backwardCompatible) {
StringBuffer buf = new StringBuffer();
for (String owner : owners) {
// NOI18N
buf.append(owner + "%%");
}
e.setAttribute(Xml.CAR_OWNERS, buf.toString());
}
// new way of saving car owners
Element eOwners = new Element(Xml.CAR_OWNERS);
for (String owner : owners) {
Element eOwner = new Element(Xml.CAR_OWNER);
eOwner.setAttribute(Xml.NAME, owner);
eOwners.addContent(eOwner);
}
e.addContent(eOwners);
}
// save list of scripts for this train
if (getBuildScripts().size() > 0 || getAfterBuildScripts().size() > 0 || getMoveScripts().size() > 0 || getTerminationScripts().size() > 0) {
Element es = new Element(Xml.SCRIPTS);
if (getBuildScripts().size() > 0) {
for (String scriptPathname : getBuildScripts()) {
Element em = new Element(Xml.BUILD);
em.setAttribute(Xml.NAME, scriptPathname);
es.addContent(em);
}
}
if (getAfterBuildScripts().size() > 0) {
for (String scriptPathname : getAfterBuildScripts()) {
Element em = new Element(Xml.AFTER_BUILD);
em.setAttribute(Xml.NAME, scriptPathname);
es.addContent(em);
}
}
if (getMoveScripts().size() > 0) {
for (String scriptPathname : getMoveScripts()) {
Element em = new Element(Xml.MOVE);
em.setAttribute(Xml.NAME, scriptPathname);
es.addContent(em);
}
}
// save list of termination scripts for this train
if (getTerminationScripts().size() > 0) {
for (String scriptPathname : getTerminationScripts()) {
Element et = new Element(Xml.TERMINATE);
et.setAttribute(Xml.NAME, scriptPathname);
es.addContent(et);
}
}
e.addContent(es);
}
if (!getRailroadName().equals(NONE)) {
Element r = new Element(Xml.RAIL_ROAD);
r.setAttribute(Xml.NAME, getRailroadName());
e.addContent(r);
}
if (!getManifestLogoURL().equals(NONE)) {
Element l = new Element(Xml.MANIFEST_LOGO);
l.setAttribute(Xml.NAME, getManifestLogoURL());
e.addContent(l);
}
if (getSecondLegOptions() != NO_CABOOSE_OR_FRED) {
e.setAttribute(Xml.LEG2_OPTIONS, Integer.toString(getSecondLegOptions()));
e.setAttribute(Xml.LEG2_ENGINES, getSecondLegNumberEngines());
e.setAttribute(Xml.LEG2_ROAD, getSecondLegEngineRoad());
e.setAttribute(Xml.LEG2_MODEL, getSecondLegEngineModel());
e.setAttribute(Xml.LEG2_CABOOSE_ROAD, getSecondLegCabooseRoad());
if (getSecondLegStartLocation() != null) {
e.setAttribute(Xml.LEG2_START, getSecondLegStartLocation().getId());
}
if (getSecondLegEndLocation() != null) {
e.setAttribute(Xml.LEG2_END, getSecondLegEndLocation().getId());
}
}
if (getThirdLegOptions() != NO_CABOOSE_OR_FRED) {
e.setAttribute(Xml.LEG3_OPTIONS, Integer.toString(getThirdLegOptions()));
e.setAttribute(Xml.LEG3_ENGINES, getThirdLegNumberEngines());
e.setAttribute(Xml.LEG3_ROAD, getThirdLegEngineRoad());
e.setAttribute(Xml.LEG3_MODEL, getThirdLegEngineModel());
e.setAttribute(Xml.LEG3_CABOOSE_ROAD, getThirdLegCabooseRoad());
if (getThirdLegStartLocation() != null) {
e.setAttribute(Xml.LEG3_START, getThirdLegStartLocation().getId());
}
if (getThirdLegEndLocation() != null) {
e.setAttribute(Xml.LEG3_END, getThirdLegEndLocation().getId());
}
}
return e;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getTrainHorsePower.
/**
* Gets the train's locomotive horsepower at the route location specified
*
* @param routeLocation The route location
* @return The train's locomotive horsepower at the route location
*/
public int getTrainHorsePower(RouteLocation routeLocation) {
int hp = 0;
Route route = getRoute();
if (route != null) {
for (RouteLocation rl : route.getLocationsBySequenceList()) {
for (RollingStock rs : EngineManager.instance().getList(this)) {
Engine eng = (Engine) rs;
if (eng.getRouteLocation() == rl) {
hp += eng.getHpInteger();
}
if (eng.getRouteDestination() == rl) {
hp += -eng.getHpInteger();
}
}
if (rl == routeLocation) {
break;
}
}
}
return hp;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class Train method getExpectedTravelTimeInMinutes.
protected int getExpectedTravelTimeInMinutes(RouteLocation routeLocation) {
int minutes = 0;
if (!isTrainEnRoute()) {
minutes += Integer.parseInt(getDepartureTimeMinute());
minutes += 60 * Integer.parseInt(getDepartureTimeHour());
} else {
// -1 means train has already served the location
minutes = -1;
}
// boolean trainAt = false;
boolean trainLocFound = false;
if (getRoute() != null) {
List<RouteLocation> routeList = getRoute().getLocationsBySequenceList();
for (int i = 0; i < routeList.size(); i++) {
RouteLocation rl = routeList.get(i);
if (rl == routeLocation) {
// done
break;
}
// start recording time after finding where the train is
if (!trainLocFound && isTrainEnRoute()) {
if (rl == getCurrentLocation()) {
trainLocFound = true;
// add travel time
minutes = Setup.getTravelTime();
}
continue;
}
// is there a departure time from this location?
if (!rl.getDepartureTime().equals(RouteLocation.NONE)) {
String dt = rl.getDepartureTime();
log.debug("Location " + rl.getName() + " departure time " + dt);
String[] time = dt.split(":");
minutes = 60 * Integer.parseInt(time[0]) + Integer.parseInt(time[1]);
// log.debug("New minutes: "+minutes);
}
// add wait time
minutes += rl.getWait();
// add travel time if new location
RouteLocation next = routeList.get(i + 1);
if (next != null && !TrainCommon.splitString(rl.getName()).equals(TrainCommon.splitString(next.getName()))) {
minutes += Setup.getTravelTime();
}
// don't count work if there's a departure time
if (i == 0 || !rl.getDepartureTime().equals(RouteLocation.NONE)) {
continue;
}
// now add the work at the location
minutes = minutes + calculateWorkTimeAtLocation(rl);
}
}
return minutes;
}
Aggregations