use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class YardmasterByTrackPanel method runUpdate.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "CarManager only provides Car Objects")
private void runUpdate() {
log.debug("run update");
removePropertyChangeListerners();
// reset the utility car counts
trainCommon.clearUtilityCarTypes();
checkBoxes.clear();
pTrack.removeAll();
boolean pickup = false;
boolean setout = false;
if (_track != null) {
pTrackPane.setBorder(BorderFactory.createTitledBorder(_track.getName()));
textTrackCommentPane.setText(_track.getComment());
textTrackCommentPane.setVisible(!_track.getComment().equals(Track.NONE));
textTrackCommentWorkPane.setText("");
for (Train train : trainManager.getTrainsArrivingThisLocationList(_track.getLocation())) {
JPanel pTrain = new JPanel();
pTrain.setLayout(new BoxLayout(pTrain, BoxLayout.Y_AXIS));
pTrain.setBorder(BorderFactory.createTitledBorder(MessageFormat.format(TrainSwitchListText.getStringScheduledWork(), new Object[] { train.getName(), train.getDescription() })));
// List locos first
List<Engine> engList = engManager.getByTrainBlockingList(train);
if (Setup.isPrintHeadersEnabled()) {
for (Engine engine : engList) {
if (engine.getTrack() == _track) {
JLabel header = new JLabel(Tab + trainCommon.getPickupEngineHeader());
setLabelFont(header);
pTrain.add(header);
break;
}
}
}
for (Engine engine : engList) {
if (engine.getTrack() == _track) {
engine.addPropertyChangeListener(this);
rollingStock.add(engine);
JCheckBox checkBox = new JCheckBox(trainCommon.pickupEngine(engine));
setCheckBoxFont(checkBox);
pTrain.add(checkBox);
checkBoxes.put(engine.getId(), checkBox);
pTrack.add(pTrain);
}
}
// now do locomotive set outs
if (Setup.isPrintHeadersEnabled()) {
for (Engine engine : engList) {
if (engine.getDestinationTrack() == _track) {
JLabel header = new JLabel(Tab + trainCommon.getDropEngineHeader());
setLabelFont(header);
pTrain.add(header);
break;
}
}
}
for (Engine engine : engList) {
if (engine.getDestinationTrack() == _track) {
engine.addPropertyChangeListener(this);
rollingStock.add(engine);
JCheckBox checkBox = new JCheckBox(trainCommon.dropEngine(engine));
setCheckBoxFont(checkBox);
pTrain.add(checkBox);
checkBoxes.put(engine.getId(), checkBox);
pTrack.add(pTrain);
}
}
// now cars
List<Car> carList = carManager.getByTrainDestinationList(train);
if (Setup.isPrintHeadersEnabled()) {
for (Car car : carList) {
if (car.getTrack() == _track && car.getRouteDestination() != car.getRouteLocation()) {
JLabel header = new JLabel(Tab + trainCommon.getPickupCarHeader(!IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK));
setLabelFont(header);
pTrain.add(header);
break;
}
}
}
// sort car pick ups by their destination
List<RouteLocation> routeList = train.getRoute().getLocationsBySequenceList();
for (RouteLocation rl : routeList) {
for (Car car : carList) {
if (car.getTrack() == _track && car.getRouteDestination() != car.getRouteLocation() && car.getRouteDestination() == rl) {
car.addPropertyChangeListener(this);
rollingStock.add(car);
String text;
if (car.isUtility()) {
text = trainCommon.pickupUtilityCars(carList, car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
if (text == null) {
// this car type has already been processed
continue;
}
} else {
text = trainCommon.pickupCar(car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
}
pickup = true;
JCheckBox checkBox = new JCheckBox(text);
setCheckBoxFont(checkBox);
pTrain.add(checkBox);
checkBoxes.put(car.getId(), checkBox);
pTrack.add(pTrain);
}
}
}
// now do car set outs
if (Setup.isPrintHeadersEnabled()) {
for (Car car : carList) {
if (car.getDestinationTrack() == _track && car.getRouteDestination() != car.getRouteLocation()) {
JLabel header = new JLabel(Tab + trainCommon.getDropCarHeader(!IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK));
setLabelFont(header);
pTrain.add(header);
break;
}
}
}
for (Car car : carList) {
if (car.getDestinationTrack() == _track && car.getRouteLocation() != car.getRouteDestination()) {
car.addPropertyChangeListener(this);
rollingStock.add(car);
String text;
if (car.isUtility()) {
text = trainCommon.setoutUtilityCars(carList, car, !TrainCommon.LOCAL, !IS_MANIFEST);
if (text == null) {
// this car type has already been processed
continue;
}
} else {
text = trainCommon.dropCar(car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
}
setout = true;
JCheckBox checkBox = new JCheckBox(text);
setCheckBoxFont(checkBox);
pTrain.add(checkBox);
checkBoxes.put(car.getId(), checkBox);
pTrack.add(pTrain);
}
}
// now do local car moves
if (Setup.isPrintHeadersEnabled()) {
for (Car car : carList) {
if ((car.getTrack() == _track || car.getDestinationTrack() == _track) && car.getRouteDestination() == car.getRouteLocation()) {
JLabel header = new JLabel(Tab + trainCommon.getLocalMoveHeader(!IS_MANIFEST));
setLabelFont(header);
pTrain.add(header);
break;
}
}
}
for (Car car : carList) {
if ((car.getTrack() == _track || car.getDestinationTrack() == _track) && car.getRouteLocation() != null && car.getRouteLocation() == car.getRouteDestination()) {
car.addPropertyChangeListener(this);
rollingStock.add(car);
String text;
if (car.isUtility()) {
text = trainCommon.setoutUtilityCars(carList, car, TrainCommon.LOCAL, !IS_MANIFEST);
if (text == null) {
// this car type has already been processed
continue;
}
} else {
text = trainCommon.localMoveCar(car, !IS_MANIFEST);
}
setout = true;
JCheckBox checkBox = new JCheckBox(text);
setCheckBoxFont(checkBox);
pTrain.add(checkBox);
checkBoxes.put(car.getId(), checkBox);
pTrack.add(pTrain);
}
}
pTrackPane.validate();
pTrain.setMaximumSize(new Dimension(2000, pTrain.getHeight()));
pTrain.revalidate();
}
// now do car holds
// we only need the cars on this track
List<RollingStock> rsList = carManager.getByTrainList();
List<Car> carList = new ArrayList<Car>();
for (RollingStock rs : rsList) {
if (rs.getTrack() != _track || rs.getRouteLocation() != null)
continue;
carList.add((Car) rs);
}
JPanel pHoldCars = new JPanel();
pHoldCars.setLayout(new BoxLayout(pHoldCars, BoxLayout.Y_AXIS));
pHoldCars.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("HoldCars")));
for (Car car : carList) {
String text;
if (car.isUtility()) {
String s = trainCommon.pickupUtilityCars(carList, car, !IS_MANIFEST, !TrainCommon.IS_TWO_COLUMN_TRACK);
if (s == null)
continue;
text = TrainSwitchListText.getStringHoldCar().split("\\{")[0] + s.trim();
} else {
text = MessageFormat.format(TrainSwitchListText.getStringHoldCar(), new Object[] { TrainCommon.padAndTruncateString(car.getRoadName(), CarRoads.instance().getMaxNameLength()), TrainCommon.padAndTruncateString(TrainCommon.splitString(car.getNumber()), Control.max_len_string_print_road_number), TrainCommon.padAndTruncateString(car.getTypeName().split("-")[0], CarTypes.instance().getMaxNameLength()), TrainCommon.padAndTruncateString(car.getLength() + TrainCommon.LENGTHABV, Control.max_len_string_length_name), TrainCommon.padAndTruncateString(car.getLoadName(), CarLoads.instance().getMaxNameLength()), TrainCommon.padAndTruncateString(_track.getName(), LocationManager.instance().getMaxTrackNameLength()), TrainCommon.padAndTruncateString(car.getColor(), CarColors.instance().getMaxNameLength()) });
}
JCheckBox checkBox = new JCheckBox(text);
setCheckBoxFont(checkBox);
pHoldCars.add(checkBox);
checkBoxes.put(car.getId(), checkBox);
pTrack.add(pHoldCars);
}
pTrackPane.validate();
pHoldCars.setMaximumSize(new Dimension(2000, pHoldCars.getHeight()));
pHoldCars.revalidate();
if (pickup && !setout) {
textTrackCommentWorkPane.setText(_track.getCommentPickup());
} else if (!pickup && setout) {
textTrackCommentWorkPane.setText(_track.getCommentSetout());
} else if (pickup && setout) {
textTrackCommentWorkPane.setText(_track.getCommentBoth());
}
textTrackCommentWorkPane.setVisible(!textTrackCommentWorkPane.getText().equals(""));
} else {
pTrackPane.setBorder(BorderFactory.createTitledBorder(""));
textTrackCommentPane.setVisible(false);
textTrackCommentWorkPane.setVisible(false);
}
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class NceConsistEngines method syncEngines.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "EngineManager only provides Engine Objects")
private void syncEngines(int offset, int step) {
for (int consistNum = 1; consistNum < 128; consistNum++) {
int engNum = getEngineNumberFromArray(consistNum, offset, step);
if (engNum != 0) {
log.debug("NCE consist " + consistNum + " has engine " + engNum);
boolean engMatch = false;
for (RollingStock rs : engineList) {
Engine engine = (Engine) rs;
if (engine.getNumber().equals(Integer.toString(engNum))) {
log.debug("found engine match {}", engine.getNumber());
engMatch = true;
Consist engConsist = engineManager.getConsistByName(NCE + consistNum);
if (engConsist != null) {
engine.setConsist(engConsist);
if (offset == CS_CON_MEM_REAR) {
// place rear loco at end of consist
engine.setBlocking(Engine.NCE_REAR_BLOCK_NUMBER);
} else {
// mid block numbers 2 through 5
engine.setBlocking(engConsist.getSize());
}
break;
}
log.warn("Engine ({}) needs lead engine {} for consist {}", engNum, getEngineNumberFromArray(consistNum, 0, 2), consistNum);
JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("NceConsistNeedsLeadEngine"), new Object[] { engNum, getEngineNumberFromArray(consistNum, 0, 2), consistNum }), Bundle.getMessage("NceConsist"), JOptionPane.ERROR_MESSAGE);
syncOK = false;
}
}
if (!engMatch) {
log.warn("Engine " + engNum + " not found in operations for NCE consist " + consistNum);
if (consists.contains(Integer.toString(consistNum))) {
JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("NceConsistMissingEngineNumber"), new Object[] { engNum, consistNum }), Bundle.getMessage("NceConsist"), JOptionPane.ERROR_MESSAGE);
syncOK = false;
}
}
}
}
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class NceConsistEngines method run.
@Override
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "EngineManager only provides Engine Objects")
public // we use a thread so the status frame will work!
void run() {
if (tc == null) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NceSynchronizationFailed"), Bundle.getMessage("NceConsist"), JOptionPane.ERROR_MESSAGE);
return;
}
if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("SynchronizeWithNce"), Bundle.getMessage("NceConsist"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
return;
}
// reset
index = 0;
waiting = 0;
syncOK = true;
// create a status frame
JPanel ps = new JPanel();
jmri.util.JmriJFrame fstatus = new jmri.util.JmriJFrame(Bundle.getMessage("ReadingNceConsistMemory"));
fstatus.setLocationRelativeTo(null);
fstatus.setSize(300, 100);
ps.add(textConsist);
ps.add(indexNumber);
fstatus.getContentPane().add(ps);
textConsist.setText(Bundle.getMessage("ReadNumber"));
textConsist.setVisible(true);
indexNumber.setVisible(true);
fstatus.setVisible(true);
// now copy NCE memory into array
for (int readIndex = 0; readIndex < NUM_CONSIST_READS; readIndex++) {
indexNumber.setText(Integer.toString(readIndex));
fstatus.setVisible(true);
getNceConsist(readIndex);
if (!syncOK) {
break;
}
}
// kill status panel
fstatus.dispose();
if (syncOK) {
// now check each engine in the operations to see if there are any matches
engineList = engineManager.getByNumberList();
consists = new ArrayList<String>();
// look for lead engines
for (int consistNum = 1; consistNum < 128; consistNum++) {
engineManager.deleteConsist(NCE + consistNum);
int engNum = getEngineNumberFromArray(consistNum, 0, 2);
if (engNum != 0) {
log.debug("NCE consist {} has lead engine {}", consistNum, engNum);
boolean engMatch = false;
for (RollingStock rs : engineList) {
Engine engine = (Engine) rs;
if (engine.getNumber().equals(Integer.toString(engNum))) {
log.debug("found lead engine match {}", engine.getNumber());
Consist engConsist = engineManager.newConsist(NCE + consistNum);
// load the consist number
engConsist.setConsistNumber(consistNum);
engine.setConsist(engConsist);
engine.setBlocking(Engine.DEFAULT_BLOCKING_ORDER);
engMatch = true;
consists.add(Integer.toString(consistNum));
break;
}
}
if (!engMatch) {
// NOI18N
log.info("Lead engine " + engNum + " not found in operations for NCE consist " + consistNum);
}
}
}
// look for rear engines
syncEngines(CS_CON_MEM_REAR, 2);
// look for mid engines
syncEngines(CS_CON_MEM_MID, 8);
syncEngines(CS_CON_MEM_MID + 2, 8);
syncEngines(CS_CON_MEM_MID + 4, 8);
syncEngines(CS_CON_MEM_MID + 6, 8);
}
if (syncOK) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("SuccessfulSynchronization"), Bundle.getMessage("NceConsist"), JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, Bundle.getMessage("SynchronizationFailed"), Bundle.getMessage("NceConsist"), JOptionPane.ERROR_MESSAGE);
}
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class ExportEngines method writeFile.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "EngineManager only provides Engine Objects")
public void writeFile(String name) {
log.debug("writeFile {}", name);
// This is taken in large part from "Java and XML" page 368
File file = findFile(name);
if (file == null) {
file = new File(name);
}
PrintWriter fileOut = null;
try {
fileOut = new // NOI18N
PrintWriter(// NOI18N
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")), true);
} catch (IOException e) {
log.error("Can not open export engines CSV file: " + file.getName());
return;
}
EngineManager manager = EngineManager.instance();
List<RollingStock> engineList = manager.getByNumberList();
String line = "";
// check for delimiter in the following Engine fields
String engineModel;
String engineLocationName;
String engineTrackName;
// assume delimiter in the value field
String value;
String comment;
// create header
String header = Bundle.getMessage("Number") + del + Bundle.getMessage("Road") + del + Bundle.getMessage("Model") + del + Bundle.getMessage("Length") + del + Bundle.getMessage("Owner") + del + Bundle.getMessage("Built") + del + Bundle.getMessage("Location") + del + "-" + del + Bundle.getMessage("Track") + del + Bundle.getMessage("Moves") + del + Setup.getValueLabel() + del + Bundle.getMessage("Comment") + del + Bundle.getMessage("Miscellaneous");
fileOut.println(header);
// store engine number, road, model, length, owner, built date, location and track
for (RollingStock rs : engineList) {
Engine engine = (Engine) rs;
engineModel = engine.getModel();
if (engineModel.contains(del)) {
engineModel = ESC + engine.getModel() + ESC;
}
engineLocationName = engine.getLocationName();
if (engineLocationName.contains(del)) {
engineLocationName = ESC + engine.getLocationName() + ESC;
}
engineTrackName = engine.getTrackName();
if (engineTrackName.contains(del)) {
engineTrackName = ESC + engine.getTrackName() + ESC;
}
value = engine.getValue();
if (value.contains(del)) {
value = ESC + engine.getValue() + ESC;
}
comment = engine.getComment();
if (comment.contains(del)) {
comment = ESC + engine.getComment() + ESC;
}
line = engine.getNumber() + del + engine.getRoadName() + del + engineModel + del + engine.getLength() + del + engine.getOwner() + del + engine.getBuilt() + del + engineLocationName + ",-," + // NOI18N
engineTrackName + del + engine.getMoves() + del + value + del + comment + del + (engine.isOutOfService() ? Bundle.getMessage("OutOfService") : "");
fileOut.println(line);
}
fileOut.flush();
fileOut.close();
log.info("Exported " + engineList.size() + " engines to file " + defaultOperationsFilename());
JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("ExportedEnginesToFile"), new Object[] { engineList.size(), defaultOperationsFilename() }), Bundle.getMessage("ExportComplete"), JOptionPane.INFORMATION_MESSAGE);
}
use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.
the class TrainBuilder method addLocos.
private void addLocos(int hpAvailable, int extraHpNeeded, RouteLocation rlNeedHp, RouteLocation rl, RouteLocation rld) throws BuildFailedException {
if (rlNeedHp == null) {
return;
}
int numberLocos = 0;
// determine how many locos have already been assigned to the train
List<RollingStock> engines = EngineManager.instance().getList(_train);
for (RollingStock rs : engines) {
if (rs.getRouteLocation() == rl) {
numberLocos++;
}
}
addLine(_buildReport, ONE, BLANK_LINE);
addLine(_buildReport, ONE, MessageFormat.format(Bundle.getMessage("buildTrainReqExtraHp"), new Object[] { extraHpNeeded, rlNeedHp.getName(), rld.getName(), numberLocos }));
// determine engine model and road
String model = _train.getEngineModel();
String road = _train.getEngineRoad();
if ((_train.getSecondLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES && rl == _train.getSecondLegStartLocation()) {
model = _train.getSecondLegEngineModel();
road = _train.getSecondLegEngineRoad();
} else if ((_train.getThirdLegOptions() & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES && rl == _train.getThirdLegStartLocation()) {
model = _train.getThirdLegEngineModel();
road = _train.getThirdLegEngineRoad();
}
while (numberLocos < Setup.getMaxNumberEngines()) {
// if no engines assigned, can't use B unit as first engine
if (!getEngines(1, model, road, rl, rld, numberLocos > 0)) {
throw new BuildFailedException(MessageFormat.format(Bundle.getMessage("buildErrorEngines"), new Object[] { Bundle.getMessage("additional"), rl.getName(), rld.getName() }));
}
numberLocos++;
int currentHp = _train.getTrainHorsePower(rlNeedHp);
if (currentHp > hpAvailable + extraHpNeeded) {
// done
break;
}
if (numberLocos < Setup.getMaxNumberEngines()) {
addLine(_buildReport, FIVE, BLANK_LINE);
addLine(_buildReport, THREE, MessageFormat.format(Bundle.getMessage("buildContinueAddLocos"), new Object[] { (hpAvailable + extraHpNeeded - currentHp), rlNeedHp.getName(), rld.getName(), numberLocos }));
} else {
addLine(_buildReport, FIVE, MessageFormat.format(Bundle.getMessage("buildMaxNumberLocoAssigned"), new Object[] { Setup.getMaxNumberEngines() }));
}
}
}
Aggregations