use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class CarManager method store.
/**
* Create an XML element to represent this Entry. This member has to remain
* synchronized with the detailed DTD in operations-cars.dtd.
* @param root The common Element for operations-cars.dtd.
*/
public void store(Element root) {
// nothing to save under
root.addContent(new Element(Xml.OPTIONS));
// options
Element values;
List<String> names = getKernelNameList();
if (Control.backwardCompatible) {
root.addContent(values = new Element(Xml.KERNELS));
for (String name : names) {
// NOI18N
String kernelNames = name + "%%";
values.addContent(kernelNames);
}
}
// new format using elements
Element kernels = new Element(Xml.NEW_KERNELS);
for (String name : names) {
Element kernel = new Element(Xml.KERNEL);
kernel.setAttribute(new Attribute(Xml.NAME, name));
kernels.addContent(kernel);
}
root.addContent(kernels);
root.addContent(values = new Element(Xml.CARS));
// add entries
List<RollingStock> carList = getByIdList();
for (RollingStock rs : carList) {
Car car = (Car) rs;
values.addContent(car.store());
}
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class CarLoadEditFrame method updateCarQuanity.
private void updateCarQuanity() {
if (!showQuanity) {
return;
}
int number = 0;
String item = (String) loadComboBox.getSelectedItem();
for (RollingStock rs : CarManager.instance().getList()) {
Car car = (Car) rs;
if (car.getLoadName().equals(item)) {
number++;
}
}
quanity.setText(Integer.toString(number));
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class DeleteCarRosterAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent ae) {
if (_carsTableFrame.carsTableModel.trackName == null) {
if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("carSureDelete"), Bundle.getMessage("carDeleteAll"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
log.debug("removing all cars from roster");
CarManager.instance().deleteAll();
}
} else {
if (JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("carDeleteCarsTrack"), new Object[] { _carsTableFrame.carsTableModel.trackName }), Bundle.getMessage("carDeleteAll"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
for (RollingStock car : _carsTableFrame.carsTableModel.getSelectedCarList()) {
CarManager.instance().deregister(car);
}
}
}
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class Train method getTrainLength.
/**
* Gets the train's length at the route location specified
*
* @param routeLocation The route location
* @return The train length at the route location
*/
public int getTrainLength(RouteLocation routeLocation) {
int length = 0;
Route route = getRoute();
if (route != null) {
for (RouteLocation rl : route.getLocationsBySequenceList()) {
for (RollingStock rs : EngineManager.instance().getList(this)) {
if (rs.getRouteLocation() == rl) {
length += rs.getTotalLength();
}
if (rs.getRouteDestination() == rl) {
length += -rs.getTotalLength();
}
}
for (RollingStock rs : CarManager.instance().getList(this)) {
if (rs.getRouteLocation() == rl) {
length += rs.getTotalLength();
}
if (rs.getRouteDestination() == rl) {
length += -rs.getTotalLength();
}
}
if (rl == routeLocation) {
break;
}
}
}
return length;
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class TrainBuilder method redirectCarsFromAlternateTrack.
/**
* Checks to see if cars that are already in the train can be redirected
* from the alternate track to the spur that really wants the car. Fixes the
* issue of having cars placed at the alternate when the spur's cars get
* pulled by this train, but cars were sent to the alternate because the
* spur was full at the time it was tested.
*
* @return true if one or more cars were redirected
*/
private boolean redirectCarsFromAlternateTrack() {
if (!Setup.isBuildAggressive()) {
return false;
}
boolean redirected = false;
List<RollingStock> cars = carManager.getByTrainList(_train);
for (RollingStock rs : cars) {
Car car = (Car) rs;
// does the car have a final destination and the destination is this one?
if (car.getFinalDestination() == null || car.getFinalDestinationTrack() == null || !car.getFinalDestinationName().equals(car.getDestinationName())) {
continue;
}
log.debug("Car ({}) destination track ({}) has final destination track ({}) location ({})", car.toString(), car.getDestinationTrackName(), car.getFinalDestinationTrackName(), // NOI18N
car.getDestinationName());
// is the car in a kernel?
if (car.getKernel() != null && !car.getKernel().isLead(car)) {
continue;
}
if (car.testDestination(car.getFinalDestination(), car.getFinalDestinationTrack()).equals(Track.OKAY)) {
Track alternate = car.getFinalDestinationTrack().getAlternateTrack();
if (alternate != null && car.getDestinationTrack() == alternate && (alternate.getTrackType().equals(Track.YARD) || alternate.getTrackType().equals(Track.INTERCHANGE)) && checkDropTrainDirection(car, car.getRouteDestination(), car.getFinalDestinationTrack()) && checkTrainCanDrop(car, car.getFinalDestinationTrack())) {
log.debug("Car ({}) alternate track ({}) can be redirected to final destination track ({})", car.toString(), car.getDestinationTrackName(), car.getFinalDestinationTrackName());
if (car.getKernel() != null) {
for (Car k : car.getKernel().getCars()) {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildRedirectFromAlternate"), new Object[] { car.getFinalDestinationName(), car.getFinalDestinationTrackName(), k.toString(), car.getDestinationTrackName() }));
k.setDestination(car.getFinalDestination(), car.getFinalDestinationTrack());
}
} else {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildRedirectFromAlternate"), new Object[] { car.getFinalDestinationName(), car.getFinalDestinationTrackName(), car.toString(), car.getDestinationTrackName() }));
car.setDestination(car.getFinalDestination(), car.getFinalDestinationTrack());
}
redirected = true;
}
}
}
return redirected;
}
Aggregations