Skip to content

Commit

Permalink
Merge remote-tracking branch 'JMRI/master' into eb-help-img
Browse files Browse the repository at this point in the history
  • Loading branch information
silverailscolo committed Jan 28, 2016
2 parents 6734dd5 + 6e4cb13 commit ce3ed9e
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 56 deletions.
28 changes: 19 additions & 9 deletions help/en/package/jmri/jmrit/operations/Operations.shtml
Expand Up @@ -3238,7 +3238,7 @@
train's route. The last two actions are "Terminate" and "Reset", pressing "Terminate" moves a
built train to the last location in the train's route, and completes the work assigned to the
train. "Reset" is used to release all cars assigned to a built train. You can only reset a train
that hasn't been moved.</p>
that hasn't moved.</p>

<p>There are several checkboxes along the bottom of the Trains window. The "Show All" when
selected shows all trains in your roster. When deselected, only trains that have the "Build"
Expand Down Expand Up @@ -3806,7 +3806,7 @@

<p>To add your first action to the table, press the "Add" button in the lower left part of
the window in a section labeled "Add Item". This should add a line to the table, with four pull
down menus labeled "Action", "Train", "Route Location", and "Automation". The three pull down
down menus labeled "Action", "Train", "Route Location", and "Automation / Other". The three pull down
menus after "Action" are enabled if the action selected requires them. For example to build a
train, you need to select under the "Action" column "Build Train" and under the "Train" column
which train you want to build. If the desired action is to wait for a train to arrive at a
Expand Down Expand Up @@ -3873,16 +3873,26 @@

<h5>Wait for Train</h5>

This action will wait for a train to build or move before executing the next action in the table. If a
location is selected in the "Route Location" menu, the program will wait until the train arrives
at the location selected. Note that if the train is already at the location selected, that the
program will wait until the next time the train arrives at that location. You must select a train
using the "Train" menu.
This action will wait for a train to build or move before executing the next action in the table.
If a location is selected in the "Route Location" menu, the program will wait until the train
arrives at the location selected. Note that if the train is already at the location selected,
that the program will wait until the next time the train arrives at that location. You must
select a train using the "Train" menu. If the "Build" checkbox for the train being waited on is
deselected, the program will cancel the wait and move to the next action in the table.

<p>The program also allows you to wait for more than one train. Just enter each of the trains
you want to wait for in consecutive rows. The program will then continue when all of the trains
either move or arrived at the locations selected.</p>


<h5>Wait for Train to Terminate</h5>

This action will wait for a train to terminate before executing the next action in the table.
Note that if the train is already terminated, that the program will wait until the next time the
train is terminated. You must select a train using the "Train" menu. If the "Build" checkbox for
the train being waited on is deselected, the program will cancel the wait and move to the next
action in the table. You can wait for more than one train to terminate by entering each train
you want to wait for in consecutive rows.

<h5>Activate Timetable</h5>

This action will activate the selected day in the "Automation / Other" column. Works the same as the
Expand All @@ -3893,7 +3903,7 @@
This action will select trains using the checkboxes in the "Build" column from the
<a href="#Trains">Trains</a> window based on which day is active, see "Activate Timetable" above to
select which day is active. Works the same as the "Apply" button in the
<a href="#Timetable">Timetable</a> window.
<a href="#Timetable">Timetable</a> window. There must be an active day for this action to work.

<h5>Select Train Build</h5>

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/display/PositionableLabel.java
Expand Up @@ -910,7 +910,7 @@ protected void setSuperText(String text) {
@Override
public void setText(String text) {
_unRotatedText = text;
_text = (text !=null);
_text = (text !=null && text.length()>0); // when "" is entered for text, and a font has been specified, the descender distance moves the position
if (/*_rotateText &&*/ !isIcon() && _namedIcon != null) {
log.debug("setText calls rotate({})", _degrees);
rotate(_degrees); //this will change text label as a icon with a new _namedIcon.
Expand Down
4 changes: 4 additions & 0 deletions java/src/jmri/jmrit/operations/automation/AutomationItem.java
Expand Up @@ -14,8 +14,10 @@
import jmri.jmrit.operations.automation.actions.GotoFailureAction;
import jmri.jmrit.operations.automation.actions.GotoSuccessAction;
import jmri.jmrit.operations.automation.actions.HaltAction;
import jmri.jmrit.operations.automation.actions.MessageYesNoAction;
import jmri.jmrit.operations.automation.actions.MoveTrainAction;
import jmri.jmrit.operations.automation.actions.NoAction;
import jmri.jmrit.operations.automation.actions.PrintSwitchListAction;
import jmri.jmrit.operations.automation.actions.PrintTrainManifestAction;
import jmri.jmrit.operations.automation.actions.PrintTrainManifestIfSelectedAction;
import jmri.jmrit.operations.automation.actions.ResetTrainAction;
Expand Down Expand Up @@ -394,13 +396,15 @@ public List<Action> getActionList() {
list.add(new ApplyTimetableAction());
list.add(new SelectTrainAction());
list.add(new DeselectTrainAction());
list.add(new PrintSwitchListAction());
list.add(new UpdateSwitchListAction());
list.add(new WaitSwitchListAction());
list.add(new RunSwitchListAction());
list.add(new RunSwitchListChangesAction());
list.add(new RunAutomationAction());
list.add(new ResumeAutomationAction());
list.add(new StopAutomationAction());
list.add(new MessageYesNoAction());
list.add(new GotoAction());
list.add(new GotoSuccessAction());
list.add(new GotoFailureAction());
Expand Down
Expand Up @@ -326,7 +326,7 @@ private JComboBox<Train> getTrainComboBox(AutomationItem item) {

private JComboBox<RouteLocation> getRouteLocationComboBox(AutomationItem item) {
JComboBox<RouteLocation> cb = new JComboBox<RouteLocation>();
if (item.getTrain() != null) {
if (item.getTrain() != null && item.getTrain().getRoute() != null) {
cb = item.getTrain().getRoute().getComboBox();
cb.setSelectedItem(item.getRouteLocation());
}
Expand Down
Expand Up @@ -31,6 +31,10 @@ DeselectTrain = Deselect Train (Build)
ActivateTimetable = Activate Timetable
ApplyTimetable = Apply Timetable

# next two used by same action
PreviewSwitchList = Preview Switch List
PrintSwitchList = Print Switch List

# next three are used for the same action
UpdateSwitchList = Update Switch List
PreviewSwitchListChanges = Preview Switch List Changes
Expand All @@ -40,6 +44,8 @@ WaitForSwitchListChange = Wait for Switch List Change
RunSwitchList = Run Excel Switch List
RunSwitchListChanges = Run Excel Switch List Changes

MessageYesNo = Message Yes or No

Goto = GOTO
GotoIfSuccess = If success GOTO
GotoIfFailure = If failure GOTO
Expand All @@ -50,6 +56,9 @@ FAILED = FAILED
Failed = Failed
Running = Running

Yes = Yes
No = No

#AutomationsTableFrame
TitleAutomationsTableFrame = Automate Train Building, Manifests, and Switch Lists
SortBy = Sort by
Expand Down
34 changes: 25 additions & 9 deletions java/src/jmri/jmrit/operations/automation/actions/Action.java
Expand Up @@ -73,13 +73,14 @@ public boolean isAutomationMenuEnabled() {
public boolean isGotoMenuEnabled() {
return (getCode() & ActionCodes.ENABLE_GOTO) == ActionCodes.ENABLE_GOTO;
}

public boolean isOtherMenuEnabled() {
return (getCode() & ActionCodes.ENABLE_OTHER) == ActionCodes.ENABLE_OTHER;
}

/**
* Used to determine if this action can run concurrently with other actions.
*
* @return true if a concurrent action
*/
public boolean isConcurrentAction() {
Expand All @@ -97,11 +98,11 @@ public AutomationItem getAutomationItem() {
public String getActionString() {
return getFormatedMessage("{0}{1}{2}{3}{4}{5}");
}

public String getActionSuccessfulString() {
return Bundle.getMessage("OK");
}

public String getActionFailedString() {
return Bundle.getMessage("FAILED");
}
Expand All @@ -125,21 +126,34 @@ public void setRunning(boolean running) {
* @return OKAY, HALT, CLOSED, NO_MESSAGE_SENT, FINISH_FAILED
*/
public int finishAction(boolean success) {
return finishAction(success, new Object[]{Bundle.getMessage("HALT"), Bundle.getMessage("OK")});
}

/**
* Completes the action by displaying the correct message if there's one.
* Will halt if the option to halt the automation is enabled or the user
* requested the automation to halt.
*
* @param success true if action succeeded
* @param buttons buttons to display in message
* @return OKAY, HALT, CLOSED, NO_MESSAGE_SENT, FINISH_FAILED
*/
public int finishAction(boolean success, Object[] buttons) {
int response = FINISH_FAILED;
if (getAutomationItem() != null) {
setRunning(true);
getAutomationItem().setActionSuccessful(success);
setRunning(false);
String message = getAutomationItem().getMessage();
Object[] buttons = new Object[]{Bundle.getMessage("HALT"), Bundle.getMessage("OK")};
if (!success) {
message = getAutomationItem().getMessageFail();
if (getAutomationItem().isHaltFailureEnabled()) {
buttons = new Object[]{Bundle.getMessage("HALT")}; // Must halt, only the HALT button shown
}
}
response = sendMessage(message, buttons, success);
if (response == HALT || (!success && getAutomationItem().isHaltFailureEnabled())) {
if (response == HALT && buttons[0].equals(Bundle.getMessage("HALT"))
|| (!success && getAutomationItem().isHaltFailureEnabled())) {
firePropertyChange(ACTION_HALT_CHANGED_PROPERTY, !success, success);
} else {
firePropertyChange(ACTION_COMPLETE_CHANGED_PROPERTY, !success, success);
Expand Down Expand Up @@ -194,15 +208,17 @@ public String getFormatedMessage(String message) {
}
return MessageFormat.format(message, new Object[]{getName(), trainName, routeLocationName, automationName, itemId, day});
}

// to be overridden if action needs a ComboBox
public JComboBox<?> getComboBox() {
JComboBox<?> cb = new JComboBox<>();
JComboBox<?> cb = new JComboBox<>();
cb.setEnabled(false);
return cb;
}

/**
* ComboBox for GOTO
*
* @return ComboBox with a list of automationItems.
*/
protected JComboBox<AutomationItem> getAutomationItemComboBox() {
Expand All @@ -214,7 +230,7 @@ protected JComboBox<AutomationItem> getAutomationItemComboBox() {
}
return null;
}

protected JComboBox<Automation> getAutomationComboBox() {
if (getAutomationItem() != null) {
JComboBox<Automation> cb = AutomationManager.instance().getComboBox();
Expand Down
Expand Up @@ -51,9 +51,9 @@ public class ActionCodes {
public static final int STOP_AUTOMATION = 0x3200 + OK_MESSAGE + FAIL_MESSAGE + ENABLE_AUTOMATION;
public static final int RESUME_AUTOMATION = 0x3300 + OK_MESSAGE + FAIL_MESSAGE + ENABLE_AUTOMATION;

public static final int MESSAGE = 0x4000 + ENABLE_TRAINS + ENABLE_ROUTES + ENABLE_AUTOMATION + OK_MESSAGE;
public static final int WAIT_MESSAGE_OK = 0x4100 + OK_MESSAGE;
public static final int WAIT_MESSAGE_YES_NO = 0x4200 + OK_MESSAGE;
// public static final int MESSAGE = 0x4000 + ENABLE_TRAINS + ENABLE_ROUTES + OK_MESSAGE;
// public static final int MESSAGE_OK = 0x4100 + ENABLE_TRAINS + ENABLE_ROUTES + OK_MESSAGE;
public static final int MESSAGE_YES_NO = 0x4200 + ENABLE_TRAINS + ENABLE_ROUTES + OK_MESSAGE;
// public static final int IF_MESSAGE_NO = 0x4300 + OK_MESSAGE + ENABLE_GOTO_LIST;

public static final int GOTO = 0x5000 + OK_MESSAGE + FAIL_MESSAGE + ENABLE_GOTO;
Expand Down
Expand Up @@ -20,7 +20,7 @@ public String getName() {
public void doAction() {
if (getAutomationItem() != null) {
Train train = getAutomationItem().getTrain();
if (train == null || train.isBuilt()) {
if (train == null || train.isBuilt() || train.getRoute() == null) {
finishAction(false); // failed to build train
} else {
setRunning(true);
Expand Down
Expand Up @@ -20,7 +20,7 @@ public String getName() {
public void doAction() {
if (getAutomationItem() != null) {
Train train = getAutomationItem().getTrain();
if (train == null || train.isBuilt()) {
if (train == null || train.isBuilt() || train.getRoute() == null) {
finishAction(false); // failed to build train
} else {
setRunning(true);
Expand Down
@@ -0,0 +1,42 @@
package jmri.jmrit.operations.automation.actions;


public class MessageYesNoAction extends Action {

private static final int _code = ActionCodes.MESSAGE_YES_NO;

@Override
public int getCode() {
return _code;
}

@Override
public String getName() {
return Bundle.getMessage("MessageYesNo");
}

@Override
public String getActionSuccessfulString() {
return Bundle.getMessage("Yes");
}

@Override
public String getActionFailedString() {
return Bundle.getMessage("No");
}

@Override
public void doAction() {
setRunning(true);
int response = sendMessage(getAutomationItem().getMessage(), new Object[]{Bundle.getMessage("Yes"), Bundle.getMessage("No")}, true);
getAutomationItem().setActionSuccessful(response != 1);
setRunning(false);
firePropertyChange(ACTION_COMPLETE_CHANGED_PROPERTY, false, true);
}

@Override
public void cancelAction() {
// no cancel for this action
}

}
Expand Up @@ -21,7 +21,7 @@ public String getName() {
public void doAction() {
if (getAutomationItem() != null) {
Train train = getAutomationItem().getTrain();
if (train != null && train.isBuilt()) {
if (train != null && train.getRoute() != null && train.isBuilt()) {
setRunning(true);
RouteLocation rl = getAutomationItem().getRouteLocation();
if (rl != null) {
Expand Down
@@ -0,0 +1,48 @@
package jmri.jmrit.operations.automation.actions;

import jmri.jmrit.operations.locations.Location;
import jmri.jmrit.operations.locations.LocationManager;
import jmri.jmrit.operations.trains.Train;
import jmri.jmrit.operations.trains.TrainManager;
import jmri.jmrit.operations.trains.TrainSwitchLists;

public class PrintSwitchListAction extends Action {

private static final int _code = ActionCodes.PRINT_SWITCHLIST;

@Override
public int getCode() {
return _code;
}

@Override
public String getName() {
if (TrainManager.instance().isPrintPreviewEnabled()) {
return Bundle.getMessage("PreviewSwitchList");
} else {
return Bundle.getMessage("PrintSwitchList");
}
}

@Override
public void doAction() {
if (getAutomationItem() != null) {
setRunning(true);
TrainSwitchLists trainSwitchLists = new TrainSwitchLists();
for (Location location : LocationManager.instance().getLocationsByNameList()) {
if (location.isSwitchListEnabled()) {
trainSwitchLists.buildSwitchList(location);
trainSwitchLists.printSwitchList(location, TrainManager.instance().isPrintPreviewEnabled());
}
}
// set trains switch lists printed
TrainManager.instance().setTrainsSwitchListStatus(Train.PRINTED);
}
finishAction(true);
}

@Override
public void cancelAction() {
// no cancel for this action
}
}
Expand Up @@ -20,7 +20,7 @@ public String getName() {
public void doAction() {
if (getAutomationItem() != null) {
Train train = getAutomationItem().getTrain();
if (train == null) {
if (train == null || train.getRoute() == null) {
finishAction(false); // failed, need train to reset
} else {
setRunning(true);
Expand Down
Expand Up @@ -22,7 +22,7 @@ public String getName() {
public void doAction() {
if (getAutomationItem() != null) {
Train train = getAutomationItem().getTrain();
if (train != null && train.isBuilt() && TrainCustomManifest.manifestCreatorFileExists()) {
if (train != null && train.getRoute() != null && train.isBuilt() && TrainCustomManifest.manifestCreatorFileExists()) {
setRunning(true);
TrainCustomManifest.addCVSFile(train.createCSVManifestFile());
boolean status = TrainCustomManifest.process();
Expand Down
Expand Up @@ -20,7 +20,7 @@ public String getName() {
public void doAction() {
if (getAutomationItem() != null) {
Train train = getAutomationItem().getTrain();
if (train != null && train.isBuilt()) {
if (train != null && train.getRoute() != null && train.isBuilt()) {
setRunning(true);
train.terminate();
finishAction(true);
Expand Down

0 comments on commit ce3ed9e

Please sign in to comment.