Class TrainBuilderBase
java.lang.Object
jmri.jmrit.operations.trains.trainbuilder.TrainCommon
jmri.jmrit.operations.trains.trainbuilder.TrainBuilderBase
- Direct Known Subclasses:
TrainBuilderEngines
Methods to support the TrainBuilder class.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) PrintWriter(package private) int(package private) int(package private) Location(package private) Track(package private) Engine(package private) int(package private) int(package private) List<RouteLocation>(package private) Engine(package private) Date(package private) Location(package private) Track(package private) Engine(package private) Train(package private) int(package private) CarLoadsprotected static final intprotected static final intprotected static final intprotected static final Stringprotected static final String(package private) Router(package private) booleanprotected static final Stringprotected static final Stringprotected static final String(package private) TrainManager(package private) TrainScheduleManagerprotected static final booleanFields inherited from class jmri.jmrit.operations.trains.trainbuilder.TrainCommon
_dropCars, _pickupCars, _printLocalMoveHeader, _printPickupHeader, _printSetoutHeader, BLANK_LINE, BUILD_REPORT_CHAR, carManager, doneCars, ENGINE, engineManager, HORIZONTAL_LINE_CHAR, HYPHEN, index, IS_MANIFEST, IS_TWO_COLUMN_TRACK, LOCAL, locationManager, NEW_LINE, PAPER_MARGINS, PICKUP, SPACE, TAB, TEXT_COLOR_DONE, TEXT_COLOR_END, TEXT_COLOR_START, utilityCarTypes, VERTICAL_LINE_CHAR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddEnginesBasedHPT(int hpAvailable, int extraHpNeeded, RouteLocation rlNeedHp, RouteLocation rl, RouteLocation rld) Adds engines to the train if needed based on HPT.protected voidAdjust car list to only have cars from one staging trackprotected booleancheckBasicMoves(Car car, Track track) protected booleancheckDepartureStagingTrack(Track departStageTrack) Check departure staging track to see if engines and cars are available to a new train.protected booleancheckDropTrainDirection(RollingStock rs, RouteLocation rld, Track track) protected booleanprotected booleancheckForAlternate(Car car, Track testTrack) Checks to see if track has an alternate and can be usedprotected RouteLocationcheckForEarlierDrop(Car car, Track trackTemp, RouteLocation rld, int start, int routeEnd) Used to determine if car could be set out at earlier location in the train's route.protected booleancheckForLaterPickUp(Car car, RouteLocation rl, RouteLocation rld) Returns true if car can be picked up later in a train's routeprotected booleanChecks to see if an interchange track has destination restrictions.protected booleanDetermines if car can be pulled from an interchange or spur.protected booleanDetermine if rolling stock can be picked up based on train direction at the route location.protected booleanUsed to report a problem picking up the rolling stock due to train direction.protected StringcheckReserved(Train train, RouteLocation rld, Car car, Track destTrack, boolean printMsg) protected voidChecks to see if all cars on a staging track have been given a destination.protected booleancheckTerminateStagingTrack(Track terminateStageTrack) Checks to see if staging track can accept train.protected booleancheckThroughCarsAllowed(Car car, String destinationName) Returns true is cars are allowed to travel from origin to terminalprotected booleancheckTrainCanDrop(RollingStock rs, Track track) Determinate if rolling stock can be dropped by this train to the track specified.protected booleancheckTrainLength(Car car, RouteLocation rl, RouteLocation rld) Checks to see if train length would be exceeded if this car was added to the train.protected intcountRollingStockAt(RouteLocation rl, List<RollingStock> list) protected voidprotected voidfinishAddRsToTrain(RollingStock rs, RouteLocation rl, RouteLocation rld, int length, int weightTons) protected booleangenerateLoadCarDepartingAndTerminatingIntoStaging(Car car, Track stageTrack) Creates a car load for a car departing staging and eventually terminating into staging.protected voidCreates the carList.protected booleangetConsist(String reqNumEngines, String model, String road, RouteLocation rl, RouteLocation rld) protected booleangetEngines(String requestedEngines, String model, String road, RouteLocation rl, RouteLocation rld) protected booleangetEngines(String requestedEngines, String model, String road, RouteLocation rl, RouteLocation rld, boolean useBunit) Get the engines for this train at a route location.protected Stringprotected RouteLocationgetLocationWithMaximumMoves(List<RouteLocation> blockRouteList, String blockId) Returns the routeLocation with the most available moves.protected voidgetNewEngine(int hpNeeded, Engine leadEngine, String model, String road) Removes engine from train and attempts to replace it with engine or consist that meets the HP requirements of the train.protected intgetNumberEngines(String requestEngines) Used to determine the number of engines requested by the user.protected ScheduleItemgetScheduleItem(Car car, Track track) Used when generating a car load from staging.getTracksAtDestination(Car car, RouteLocation rld) Returns a list containing two tracks.protected booleanUsed to determine if a car on a staging track doesn't have a destination or trainprotected voidTemporally remove cars from staging track if train returning to the same staging track to free up track space.protected TrackAsk which staging track the train is to depart on.protected TrackAsk which staging track the train is to terminate on.protected voidRemoves the remaining cabooses and cars with FRED from consideration.protected voidbuild has failed due to cars in staging not having destinations this routine removes those cars from the staging track by user request.protected voidremoveEngineFromTrain(Engine engine) protected voidRemove rolling stock from trainprotected voidRestores cars departing staging track assignment.protected voidSave the car's final destination and schedule id in case of train resetprotected voidsetDepartureTrack(Track departStageTrack) Will also set the termination track if returning to stagingprotected booleansetEngineDestination(Engine engine, RouteLocation rl, RouteLocation rld) Sets the destination track for an engine and assigns it to the train.protected voidprotected voidShow and initialize the train's route.protected voidCreates the build report header information lines.protected voidList available cars by location.protected voidshowCarServiceOrder(Car car) protected voidreport any cars left at route locationprotected voidLists cars that couldn't be routed.protected voidprotected voidreports if local switcherprotected voidprotected voidprotected voidshow train build options when in detailed modeprotected voidprotected voidprotected voidprotected voidprotected voidShow how many engines are required for this train, and if a certain road name for the engine is requested.protected voidAdds to the build report what the train will service.protected voidprotected TracktryStaging(Car car, RouteLocation rldSave) Methods inherited from class jmri.jmrit.operations.trains.trainbuilder.TrainCommon
addCarsLocationUnknown, addLine, addLine, blockCarsByTrack, blockCarsByTrackNameTwoColumn, blockCarsTwoColumn, blockLocosTwoColumn, clearUtilityCarTypes, convertStringTime, convertStringToDate, countPickupUtilityCars, countSetoutUtilityCars, countUtilityCars, createTabIfNeeded, dropCar, dropCar, dropEngine, dropEngines, formatColorString, formatStringToCommaSeparated, getDate, getDate, getDropCarHeader, getDropEngineHeader, getISO8601Date, getLineLength, getLocalMoveHeader, getManifestHeaderLineLength, getPageSize, getPickupCarHeader, getPickupEngineHeader, getSwitchListTrainStatus, getTextColor, getTextColorName, getTextColorString, getTrainMessage, isNextCar, isNextCar, isThereWorkAtLocation, isThereWorkAtLocation, localMoveCar, newLine, newLine, padAndTruncate, padAndTruncateIfNeeded, padString, pickupCar, pickUpCar, pickUpCarTruncated, pickupEngine, pickupEngines, pickupUtilityCars, pickupUtilityCars, printCarHeader, printDropCarHeader, printDropEngineHeader, printEngineHeader, printHorizontalLine, printHorizontalLine, printHorizontalLine1, printHorizontalLine2, printHorizontalLine3, printLocalCarMoveHeader, printPickupCarHeader, printPickupEngineHeader, printTrackComments, printTrackNameHeader, setCarPickupAndSetoutTimes, setoutUtilityCars, setoutUtilityCars, setoutUtilityCars, splitString, splitStringLeftParenthesis, tabString, truncatedDropCar
-
Field Details
-
ONE
- See Also:
-
THREE
- See Also:
-
FIVE
- See Also:
-
SEVEN
- See Also:
-
DISPLAY_CAR_LIMIT_20
- See Also:
-
DISPLAY_CAR_LIMIT_50
- See Also:
-
DISPLAY_CAR_LIMIT_100
- See Also:
-
USE_BUNIT
- See Also:
-
TIMING
- See Also:
-
_startTime
-
_train
-
_numberCars
int _numberCars -
_engineList
-
_lastEngine
-
_secondLeadEngine
-
_thirdLeadEngine
-
_carIndex
int _carIndex -
_carList
-
_routeList
-
_numOfBlocks
-
_completedMoves
int _completedMoves -
_reqNumOfMoves
int _reqNumOfMoves -
_departLocation
-
_departStageTrack
-
_terminateLocation
-
_terminateStageTrack
-
_buildReport
-
_notRoutable
-
_modifiedLocations
-
_warnings
int _warnings -
trainManager
-
trainScheduleManager
-
carLoads
-
router
-
routeToTrackFound
boolean routeToTrackFound
-
-
Constructor Details
-
TrainBuilderBase
public TrainBuilderBase()
-
-
Method Details
-
createBuildReportFile
- Throws:
BuildFailedException
-
showBuildReportInfo
Creates the build report header information lines. Build report date, JMRI version, train schedule, build report display levels, setup comment. -
setUpRoute
- Throws:
BuildFailedException
-
showTrainBuildOptions
show train build options when in detailed mode -
showSpecificTrainBuildOptions
-
showTrainServices
Adds to the build report what the train will service. Road and owner names, built dates, and engine types. -
showAndInitializeTrainRoute
Show and initialize the train's route. Determines the number of car moves requested for this train. Also adjust the number of car moves if the random car moves option was selected.- Throws:
BuildFailedException- if random variable isn't an integer
-
showIfLocalSwitcher
reports if local switcher -
showTrainRequirements
Show how many engines are required for this train, and if a certain road name for the engine is requested. Show if there are any engine changes in the route, or if helper engines are needed. There can be up to 2 engine changes or helper requests. Show if caboose or FRED is needed for train, and if there's a road name requested. There can be up to 2 caboose changes in the route. -
setDepartureTrack
Will also set the termination track if returning to staging- Parameters:
departStageTrack- departure track from staging
-
showTrainCarRoads
-
showTrainCabooseRoads
-
showTrainCarTypes
-
showTrainLoadNames
-
promptFromStagingDialog
Ask which staging track the train is to depart on.- Returns:
- The departure track the user selected.
-
promptToStagingDialog
Ask which staging track the train is to terminate on.- Returns:
- The termination track selected by the user.
-
removeCaboosesAndCarsWithFred
Removes the remaining cabooses and cars with FRED from consideration.- Throws:
BuildFailedException- code check if car being removed is in staging
-
saveCarFinalDestinations
Save the car's final destination and schedule id in case of train reset -
getCarList
Creates the carList. Only cars that can be serviced by this train are in the list.- Throws:
BuildFailedException- if car is marked as missing and is in staging
-
adjustCarsInStaging
Adjust car list to only have cars from one staging track- Throws:
BuildFailedException- if all cars departing staging can't be used
-
showCarsByLocation
List available cars by location. Removes non-lead kernel cars from the car list.- Throws:
BuildFailedException- if kernel doesn't have lead or cars aren't on the same track.
-
sortCarsOnFifoLifoTracks
-
getLargestBlock
-
getLocationWithMaximumMoves
protected RouteLocation getLocationWithMaximumMoves(List<RouteLocation> blockRouteList, String blockId) Returns the routeLocation with the most available moves. Used for blocking a train out of staging.- Parameters:
blockRouteList- The route for this train, modified by deleting RouteLocations servicedblockId- Where these cars were originally picked up from.- Returns:
- The location in the route with the most available moves.
-
makeAdjustmentsIfDepartingStaging
Temporally remove cars from staging track if train returning to the same staging track to free up track space. -
restoreCarsIfDepartingStaging
Restores cars departing staging track assignment. -
showLoadGenerationOptionsStaging
-
checkStuckCarsInStaging
Checks to see if all cars on a staging track have been given a destination. Throws exception if there's a car without a destination.- Throws:
BuildFailedException- if car on staging track not assigned to train
-
isCarStuckStaging
Used to determine if a car on a staging track doesn't have a destination or train- Returns:
- true if at least one car doesn't have a destination or train. false if all cars have a destination.
-
finishAddRsToTrain
protected void finishAddRsToTrain(RollingStock rs, RouteLocation rl, RouteLocation rld, int length, int weightTons) -
checkPickUpTrainDirection
protected boolean checkPickUpTrainDirection(RollingStock rs, RouteLocation rl) throws BuildFailedException Determine if rolling stock can be picked up based on train direction at the route location.- Parameters:
rs- The rolling stockrl- The rolling stock's route location- Returns:
- true if there isn't a problem
- Throws:
BuildFailedException- if coding issue
-
checkPickUpTrainDirection
Used to report a problem picking up the rolling stock due to train direction.- Parameters:
rl- The route location- Returns:
- true if there isn't a problem
-
checkPickupInterchangeOrSpur
Determines if car can be pulled from an interchange or spur. Needed for quick service tracks.- Parameters:
car- the car being pulled- Returns:
- true if car can be pulled, otherwise false.
-
checkPickupInterchangeDestinationRestrictions
Checks to see if an interchange track has destination restrictions. Returns true if there's at least one destination in the train's route that can service the car departing the interchange.- Parameters:
car- the car being evaluated- Returns:
- true if car can be pulled
-
checkTrainLength
Checks to see if train length would be exceeded if this car was added to the train.- Parameters:
car- the car in questionrl- the departure route location for this carrld- the destination route location for this car- Returns:
- true if car can be added to train
-
checkDropTrainDirection
-
checkDropTrainDirection
-
checkTrainCanDrop
Determinate if rolling stock can be dropped by this train to the track specified.- Parameters:
rs- the rolling stock to be set out.track- the destination track.- Returns:
- true if able to drop.
-
checkDepartureStagingTrack
Check departure staging track to see if engines and cars are available to a new train. Also confirms that the engine and car type, load, road, etc. are accepted by the train.- Parameters:
departStageTrack- The staging track- Returns:
- true is there are engines and cars available.
-
checkTerminateStagingTrack
Checks to see if staging track can accept train.- Parameters:
terminateStageTrack- the staging track- Returns:
- true if staging track is empty, not reserved, and accepts car and engine types, roads, and loads.
-
checkBasicMoves
-
getScheduleItem
Used when generating a car load from staging.- Parameters:
car- the car.track- the car's destination track that has the schedule.- Returns:
- ScheduleItem si if match found, null otherwise.
- Throws:
BuildFailedException- if schedule doesn't have any line items
-
showCarServiceOrder
-
getTracksAtDestination
Returns a list containing two tracks. The 1st track found for the car, the 2nd track is the car's final destination if an alternate track was used for the car. 2nd track can be null.- Parameters:
car- The car needing a destination trackrld- the RouteLocation destination- Returns:
- List containing up to two tracks. No tracks if none found.
-
checkForAlternate
Checks to see if track has an alternate and can be used- Parameters:
car- the car being droppedtestTrack- the destination track- Returns:
- true if track has an alternate and can be used
-
checkForEarlierDrop
protected RouteLocation checkForEarlierDrop(Car car, Track trackTemp, RouteLocation rld, int start, int routeEnd) Used to determine if car could be set out at earlier location in the train's route.- Parameters:
car- The cartrackTemp- The destination track for this carrld- Where in the route the destination track was foundstart- Where to begin the checkrouteEnd- Where to stop the check- Returns:
- The best RouteLocation to drop off the car
-
checkReserved
protected String checkReserved(Train train, RouteLocation rld, Car car, Track destTrack, boolean printMsg) -
tryStaging
- Throws:
BuildFailedException
-
checkForLaterPickUp
protected boolean checkForLaterPickUp(Car car, RouteLocation rl, RouteLocation rld) throws BuildFailedException Returns true if car can be picked up later in a train's route- Parameters:
car- the carrl- car's route locationrld- car's route location destination- Returns:
- true if car can be picked up later in a train's route
- Throws:
BuildFailedException- if coding issue
-
checkThroughCarsAllowed
Returns true is cars are allowed to travel from origin to terminal- Parameters:
car- The cardestinationName- Destination name for this car- Returns:
- true if through cars are allowed. false if not.
-
generateLoadCarDepartingAndTerminatingIntoStaging
protected boolean generateLoadCarDepartingAndTerminatingIntoStaging(Car car, Track stageTrack) throws BuildFailedException Creates a car load for a car departing staging and eventually terminating into staging.- Parameters:
car- the car!stageTrack- the staging track the car will terminate to- Returns:
- true if a load was generated this this car.
- Throws:
BuildFailedException- if coding check fails
-
showCarsNotMoved
report any cars left at route location- Parameters:
rl- route location
-
removeRollingStockFromTrain
Remove rolling stock from train- Parameters:
rs- the rolling stock to be removed
-
showCarsNotRoutable
Lists cars that couldn't be routed. -
removeCarsFromStaging
build has failed due to cars in staging not having destinations this routine removes those cars from the staging track by user request. -
addEnginesBasedHPT
protected void addEnginesBasedHPT(int hpAvailable, int extraHpNeeded, RouteLocation rlNeedHp, RouteLocation rl, RouteLocation rld) throws BuildFailedException Adds engines to the train if needed based on HPT. Note that the engine additional weight isn't considered in this method so HP requirements can be lower compared to the original calculation which did include the weight of the engines.- Parameters:
hpAvailable- the engine hp already assigned to the train for this legextraHpNeeded- the additional hp neededrlNeedHp- where in the route the additional hp is neededrl- the start of the legrld- the end of the leg- Throws:
BuildFailedException- if unable to add engines to train
-
getNumberEngines
Used to determine the number of engines requested by the user.- Parameters:
requestEngines- Can be a number, AUTO or AUTO HPT.- Returns:
- the number of engines requested by user.
-
setEngineDestination
Sets the destination track for an engine and assigns it to the train.- Parameters:
engine- The engine to be added to trainrl- Departure route locationrld- Destination route location- Returns:
- true if destination track found and set
-
getConsist
protected boolean getConsist(String reqNumEngines, String model, String road, RouteLocation rl, RouteLocation rld) throws BuildFailedException - Throws:
BuildFailedException
-
showEnginesByLocation
-
countRollingStockAt
-
getEngines
protected boolean getEngines(String requestedEngines, String model, String road, RouteLocation rl, RouteLocation rld) throws BuildFailedException - Throws:
BuildFailedException
-
getEngines
protected boolean getEngines(String requestedEngines, String model, String road, RouteLocation rl, RouteLocation rld, boolean useBunit) throws BuildFailedException Get the engines for this train at a route location. If departing from staging engines must come from that track. Finds the required number of engines in a consist, or if the option to build from single locos, builds a consist for the user. When true, engines successfully added to train for the leg requested.- Parameters:
requestedEngines- Requested number of Engines, can be number, AUTO or AUTO HPTmodel- Optional model name for the enginesroad- Optional road name for the enginesrl- Departure route location for the enginesrld- Destination route location for the enginesuseBunit- true if B unit engine is allowed- Returns:
- true if correct number of engines found.
- Throws:
BuildFailedException- if coding issue
-
getNewEngine
protected void getNewEngine(int hpNeeded, Engine leadEngine, String model, String road) throws BuildFailedException Removes engine from train and attempts to replace it with engine or consist that meets the HP requirements of the train.- Parameters:
hpNeeded- How much hp is neededleadEngine- The lead engine for this legmodel- The engine's modelroad- The engine's road- Throws:
BuildFailedException- if new engine not found
-
removeEngineFromTrain
-