Skip to content

Commit

Permalink
Merge pull request #6030 from DanielBoudreau/master
Browse files Browse the repository at this point in the history
Add car load type to CSV output files
  • Loading branch information
DanielBoudreau committed Oct 20, 2018
2 parents fb359cc + dc561fb commit f8d3728
Showing 1 changed file with 117 additions and 25 deletions.
142 changes: 117 additions & 25 deletions java/src/jmri/jmrit/operations/trains/TrainCsvCommon.java
Expand Up @@ -25,8 +25,8 @@ public class TrainCsvCommon extends TrainCommon {
protected final static String DEL = ","; // delimiter // NOI18N
protected final static String ESC = "\""; // escape // NOI18N

protected final static String HEADER = Bundle.getMessage("csvOperator") + DEL + Bundle.getMessage("csvDescription")
+ DEL + Bundle.getMessage("csvParameters");
protected final static String HEADER = Bundle.getMessage(
"csvOperator") + DEL + Bundle.getMessage("csvDescription") + DEL + Bundle.getMessage("csvParameters");

protected final static String AH = "AH" + DEL + Bundle.getMessage("csvAddHelpers"); // NOI18N
protected final static String AT = "AT" + DEL + Bundle.getMessage("csvArrivalTime") + DEL; // NOI18N
Expand Down Expand Up @@ -146,25 +146,83 @@ protected void fileOutCsvCar(PrintWriter fileOut, Car car, String operation, int
}
String carFinalDestinationName = car.getFinalDestinationName();
if (carFinalDestinationName.contains(DEL)) {
log.debug("Car (" + car.toString() + ") has delimiter in final destination field: "
+ carFinalDestinationName);
log.debug("Car (" +
car.toString() +
") has delimiter in final destination field: " +
carFinalDestinationName);
carFinalDestinationName = ESC + carFinalDestinationName + ESC;
}
String carFinalDestinationTrackName = car.getFinalDestinationTrackName();
if (carFinalDestinationTrackName.contains(DEL)) {
log.debug("Car (" + car.toString() + ") has delimiter in final destination track field: "
+ carFinalDestinationTrackName);
log.debug("Car (" +
car.toString() +
") has delimiter in final destination track field: " +
carFinalDestinationTrackName);
carFinalDestinationTrackName = ESC + carFinalDestinationTrackName + ESC;
}

addLine(fileOut, operation + DEL + carRoad + DEL + car.getNumber() + DEL + carType + DEL + car.getLength()
+ DEL + carLoad + DEL + carColor + DEL + carLocationName + DEL + carTrackName + DEL + carDestName + DEL
+ carDestTrackName + DEL + carOwner + DEL + carKernelName + DEL + ESC + car.getComment() + ESC + DEL
+ ESC + car.getPickupComment() + ESC + DEL + ESC + car.getDropComment() + ESC + DEL
+ (car.isCaboose() ? "C" : "") + DEL + (car.hasFred() ? "F" : "") + DEL
+ (car.isHazardous() ? "H" : "") + DEL + ESC + car.getRfid() + ESC + DEL + carRWEDestName + DEL
+ carRWETrackName + DEL + (car.isUtility() ? "U" : "") + DEL + count + DEL + carFinalDestinationName
+ DEL + carFinalDestinationTrackName);
addLine(fileOut,
operation +
DEL +
carRoad +
DEL +
car.getNumber() +
DEL +
carType +
DEL +
car.getLength() +
DEL +
carLoad +
DEL +
carColor +
DEL +
carLocationName +
DEL +
carTrackName +
DEL +
carDestName +
DEL +
carDestTrackName +
DEL +
carOwner +
DEL +
carKernelName +
DEL +
ESC +
car.getComment() +
ESC +
DEL +
ESC +
car.getPickupComment() +
ESC +
DEL +
ESC +
car.getDropComment() +
ESC +
DEL +
(car.isCaboose() ? "C" : "") +
DEL +
(car.hasFred() ? "F" : "") +
DEL +
(car.isHazardous() ? "H" : "") +
DEL +
ESC +
car.getRfid() +
ESC +
DEL +
carRWEDestName +
DEL +
carRWETrackName +
DEL +
(car.isUtility() ? "U" : "") +
DEL +
count +
DEL +
carFinalDestinationName +
DEL +
carFinalDestinationTrackName +
DEL +
car.getLoadType());
}

protected void fileOutCsvEngine(PrintWriter fileOut, Engine engine, String operation) {
Expand Down Expand Up @@ -201,8 +259,10 @@ protected void fileOutCsvEngine(PrintWriter fileOut, Engine engine, String opera
}
String engineDestTrackName = engine.getDestinationTrackName();
if (engineDestTrackName.contains(DEL)) {
log.debug("Engine (" + engine.toString() + ") has delimiter in destination track field: "
+ engineDestTrackName);
log.debug("Engine (" +
engine.toString() +
") has delimiter in destination track field: " +
engineDestTrackName);
engineDestTrackName = ESC + engine.getDestinationTrackName() + ESC;
}
String engineOwner = engine.getOwner();
Expand All @@ -219,11 +279,42 @@ protected void fileOutCsvEngine(PrintWriter fileOut, Engine engine, String opera
if (engine.getConsist() != null && engine.getConsist().isLead(engine)) {
engineIsLead = "Lead loco"; // NOI18N
}
addLine(fileOut, operation + DEL + engineRoad + DEL + engine.getNumber() + DEL + engineModel + DEL
+ engine.getLength() + DEL + engineType + DEL + engine.getHp() + DEL + engineLocationName + DEL
+ engineTrackName + DEL + engineDestName + DEL + engineDestTrackName + DEL + engineOwner + DEL
+ engineConsistName + DEL + engineIsLead + DEL + ESC + engine.getComment() + ESC + DEL + ESC
+ engine.getRfid() + ESC);
addLine(fileOut,
operation +
DEL +
engineRoad +
DEL +
engine.getNumber() +
DEL +
engineModel +
DEL +
engine.getLength() +
DEL +
engineType +
DEL +
engine.getHp() +
DEL +
engineLocationName +
DEL +
engineTrackName +
DEL +
engineDestName +
DEL +
engineDestTrackName +
DEL +
engineOwner +
DEL +
engineConsistName +
DEL +
engineIsLead +
DEL +
ESC +
engine.getComment() +
ESC +
DEL +
ESC +
engine.getRfid() +
ESC);
}

protected void checkForEngineOrCabooseChange(PrintWriter fileOut, Train train, RouteLocation rl) {
Expand All @@ -249,8 +340,8 @@ protected void engineCsvChange(PrintWriter fileOut, RouteLocation rl, int legOpt
if ((legOptions & Train.HELPER_ENGINES) == Train.HELPER_ENGINES) {
addLine(fileOut, AH);
}
if ((legOptions & Train.REMOVE_CABOOSE) == Train.REMOVE_CABOOSE
|| (legOptions & Train.ADD_CABOOSE) == Train.ADD_CABOOSE) {
if ((legOptions & Train.REMOVE_CABOOSE) == Train.REMOVE_CABOOSE ||
(legOptions & Train.ADD_CABOOSE) == Train.ADD_CABOOSE) {
addLine(fileOut, CC);
}
if ((legOptions & Train.CHANGE_ENGINES) == Train.CHANGE_ENGINES) {
Expand All @@ -270,8 +361,9 @@ protected void printTrackComments(PrintWriter fileOut, RouteLocation rl, List<Ca
if (car.getRouteLocation() == rl && car.getTrack() != null && car.getTrack() == track) {
pickup = true;
}
if (car.getRouteDestination() == rl && car.getDestinationTrack() != null
&& car.getDestinationTrack() == track) {
if (car.getRouteDestination() == rl &&
car.getDestinationTrack() != null &&
car.getDestinationTrack() == track) {
setout = true;
}
}
Expand Down

0 comments on commit f8d3728

Please sign in to comment.