use of jmri.implementation.DefaultConditionalAction in project JMRI by JMRI.
the class RouteTableAction method cloneActionList.
ArrayList<ConditionalAction> cloneActionList(ArrayList<ConditionalAction> actionList, int option) {
ArrayList<ConditionalAction> list = new ArrayList<>();
for (int i = 0; i < actionList.size(); i++) {
ConditionalAction action = actionList.get(i);
ConditionalAction clone = new DefaultConditionalAction();
clone.setType(action.getType());
clone.setOption(option);
clone.setDeviceName(action.getDeviceName());
clone.setActionData(action.getActionData());
clone.setActionString(action.getActionString());
list.add(clone);
}
return list;
}
use of jmri.implementation.DefaultConditionalAction in project JMRI by JMRI.
the class RouteTableAction method exportPressed.
/////////////////////// Export to Logix ////////////////////////////
/**
* Responds to the Export button - export to Logix.
*
* @param e the action event
*/
void exportPressed(ActionEvent e) {
curRoute = checkNamesOK();
String sName = _systemName.getText();
if (sName.length() == 0) {
sName = fixedSystemName.getText();
}
String uName = _userName.getText();
String logixSystemName = LOGIX_SYS_NAME + sName;
Logix logix = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(logixSystemName);
if (logix == null) {
logix = InstanceManager.getDefault(jmri.LogixManager.class).createNewLogix(logixSystemName, uName);
if (logix == null) {
log.error("Failed to create Logix " + logixSystemName + ", " + uName);
return;
}
}
logix.deActivateLogix();
initializeIncludedList();
/////////////////// Construct output actions for change to true //////////////////////
ArrayList<ConditionalAction> actionList = new ArrayList<>();
for (int i = 0; i < _includedSensorList.size(); i++) {
RouteSensor rSensor = _includedSensorList.get(i);
String name = rSensor.getUserName();
if (name == null || name.length() == 0) {
name = rSensor.getSysName();
}
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, name, rSensor.getState(), ""));
}
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_TURNOUT, name, rTurnout.getState(), ""));
}
String file = soundFile.getText();
if (file.length() > 0) {
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_RUN_SCRIPT, "", -1, file));
}
file = scriptFile.getText();
if (file.length() > 0) {
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_PLAY_SOUND, "", -1, file));
}
///// Construct 'AND' clause from 'VETO' controls ////////
ArrayList<ConditionalVariable> vetoList = new ArrayList<>();
// String andClause = null;
ConditionalVariable cVar = makeCtrlSensorVar(sensor1, sensor1mode, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
cVar = makeCtrlSensorVar(sensor2, sensor2mode, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
cVar = makeCtrlSensorVar(sensor3, sensor3mode, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
cVar = makeCtrlTurnoutVar(cTurnout, cTurnoutStateBox, true, false);
if (cVar != null) {
vetoList.add(cVar);
}
// remove old Conditionals for actions (ver 2.5.2 only -remove a bad idea)
char[] ch = sName.toCharArray();
int hash = 0;
for (int i = 0; i < ch.length; i++) {
hash += ch[i];
}
String cSystemName = CONDITIONAL_SYS_PREFIX + "T" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "F" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "A" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "L" + hash;
removeConditionals(cSystemName, logix);
int n = 0;
do {
n++;
cSystemName = logixSystemName + n + "A";
} while (removeConditionals(cSystemName, logix));
n = 0;
do {
n++;
cSystemName = logixSystemName + n + "T";
} while (removeConditionals(cSystemName, logix));
cSystemName = logixSystemName + "L";
removeConditionals(cSystemName, logix);
String cUserName;
///////////////// Make Trigger Conditionals //////////////////////
//ArrayList <ConditionalVariable> onChangeList = new ArrayList<ConditionalVariable>();
// passed through all these, with new value returned each time
int numConds = 1;
numConds = makeSensorConditional(sensor1, sensor1mode, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor2, sensor2mode, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor3, sensor3mode, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeTurnoutConditional(cTurnout, cTurnoutStateBox, numConds, false, actionList, vetoList, logix, logixSystemName, uName);
////// Construct actions for false from the 'any change' controls ////////////
numConds = makeSensorConditional(sensor1, sensor1mode, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor2, sensor2mode, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeSensorConditional(sensor3, sensor3mode, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
numConds = makeTurnoutConditional(cTurnout, cTurnoutStateBox, numConds, true, actionList, vetoList, logix, logixSystemName, uName);
log.debug("Final number of conditionals: {}", numConds);
//String sensorSystemName = turnoutsAlignedSensor.getText();
if (turnoutsAlignedSensor.getSelectedBean() != null) {
// verify name (logix doesn't use "provideXXX")
//Sensor s = turnoutsAlignedSensor.getSelectedBean();
/*if (s == null) {
s = InstanceManager.sensorManagerInstance().getBySystemName(sensorSystemName);
}*/
//if (s != null) {
String sensorSystemName = turnoutsAlignedSensor.getSelectedDisplayName();
// NOI18N
cSystemName = logixSystemName + "1A";
// NOI18N
cUserName = turnoutsAlignedSensor.getSelectedDisplayName() + "A " + uName;
ArrayList<ConditionalVariable> variableList = new ArrayList<>();
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
// exclude toggled outputs
switch(rTurnout.getState()) {
case Turnout.CLOSED:
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_AND, Conditional.TYPE_TURNOUT_CLOSED, name, true));
break;
case Turnout.THROWN:
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_AND, Conditional.TYPE_TURNOUT_THROWN, name, true));
break;
default:
// NOI18N
log.warn("Turnout {} was {}, neither CLOSED nor THROWN; not handled", name, rTurnout.getState());
}
}
actionList = new ArrayList<>();
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, sensorSystemName, Sensor.ACTIVE, ""));
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE, Conditional.ACTION_SET_SENSOR, sensorSystemName, Sensor.INACTIVE, ""));
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(cSystemName, cUserName);
c.setStateVariables(variableList);
c.setLogicType(Conditional.ALL_AND, "");
c.setAction(actionList);
logix.addConditional(cSystemName, 0);
c.calculate(true, null);
//}
}
///////////////// Set lock turnout information if there is any //////////////////////////
if (cLockTurnout.getSelectedBean() != null) {
String turnoutLockSystemName = cLockTurnout.getSelectedDisplayName();
// verify name (logix doesn't use "provideXXX")
// NOI18N
cSystemName = logixSystemName + "1L";
// NOI18N
cUserName = turnoutLockSystemName + "L " + uName;
ArrayList<ConditionalVariable> variableList = new ArrayList<>();
//String devName = cTurnout.getText();
int mode = turnoutModeFromBox(cTurnoutStateBox);
int type = Conditional.TYPE_TURNOUT_CLOSED;
if (mode == Route.ONTHROWN) {
type = Conditional.TYPE_TURNOUT_THROWN;
}
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_NONE, type, turnoutLockSystemName, true));
actionList = new ArrayList<>();
int option = Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE;
type = Turnout.LOCKED;
if (mode == Route.ONCHANGE) {
option = Conditional.ACTION_OPTION_ON_CHANGE;
type = Route.TOGGLE;
}
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
actionList.add(new DefaultConditionalAction(option, Conditional.ACTION_LOCK_TURNOUT, name, type, ""));
}
if (mode != Route.ONCHANGE) {
// add non-toggle actions on
option = Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE;
type = Turnout.UNLOCKED;
for (int i = 0; i < _includedTurnoutList.size(); i++) {
RouteTurnout rTurnout = _includedTurnoutList.get(i);
String name = rTurnout.getUserName();
if (name == null || name.length() == 0) {
name = rTurnout.getSysName();
}
actionList.add(new DefaultConditionalAction(option, Conditional.ACTION_LOCK_TURNOUT, name, type, ""));
}
}
// add new Conditionals for action on 'locks'
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(cSystemName, cUserName);
c.setStateVariables(variableList);
c.setLogicType(Conditional.ALL_AND, "");
c.setAction(actionList);
logix.addConditional(cSystemName, 0);
c.calculate(true, null);
}
logix.activateLogix();
if (curRoute != null) {
jmri.InstanceManager.getDefault(jmri.RouteManager.class).deleteRoute(curRoute);
curRoute = null;
}
status1.setText(Bundle.getMessage("BeanNameRoute") + "\"" + uName + "\" " + Bundle.getMessage("RouteAddStatusExported") + " (" + _includedTurnoutList.size() + Bundle.getMessage("Turnouts") + ", " + _includedSensorList.size() + " " + Bundle.getMessage("Sensors") + ")");
finishUpdate();
}
use of jmri.implementation.DefaultConditionalAction in project JMRI by JMRI.
the class LRouteTableAction method updatePressed.
/**
* Update the Route Table.
*/
void updatePressed() {
Logix logix = checkNamesOK();
if (logix == null) {
log.error("No Logix found!");
return;
}
String sName = logix.getSystemName();
// Check if the User Name has been changed
String uName = _userName.getText();
logix.setUserName(uName);
initializeIncludedInputList();
initializeIncludedOutputList();
initializeIncludedAlignList();
if (log.isDebugEnabled()) {
log.debug("updatePressed: _includedInputList.size()= " + _includedInputList.size() + ", _includedOutputList.size()= " + _includedOutputList.size() + ", _includedAlignList.size()= " + _includedAlignList.size());
}
////// Construct output actions for trigger conditionals ///////////
ArrayList<ConditionalAction> actionList = new ArrayList<>();
for (int i = 0; i < _includedOutputList.size(); i++) {
RouteOutputElement elt = _includedOutputList.get(i);
String name = elt.getUserName();
if (name == null || name.length() == 0) {
name = elt.getSysName();
}
// actionData
int state = elt.getState();
int actionType = 0;
String params = "";
switch(elt.getType()) {
case SENSOR_TYPE:
actionType = Conditional.ACTION_SET_SENSOR;
break;
case TURNOUT_TYPE:
actionType = Conditional.ACTION_SET_TURNOUT;
break;
case LIGHT_TYPE:
actionType = Conditional.ACTION_SET_LIGHT;
break;
case SIGNAL_TYPE:
actionType = Conditional.ACTION_SET_SIGNAL_APPEARANCE;
if (state > OFFSET) {
actionType = state & ~OFFSET;
}
break;
default:
log.debug("updatePressed: Unknown action type " + elt.getType());
}
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, actionType, name, state, params));
}
String file = scriptFile.getText();
if (file.length() > 0) {
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_RUN_SCRIPT, "", -1, file));
}
file = soundFile.getText();
if (file.length() > 0) {
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_PLAY_SOUND, "", -1, file));
}
ArrayList<ConditionalAction> onChangeList = cloneActionList(actionList, Conditional.ACTION_OPTION_ON_CHANGE);
/////// Construct 'AND' clause from 'VETO' controls ////////
ArrayList<ConditionalVariable> vetoList = new ArrayList<>();
if (!_initialize) {
for (int i = 0; i < _includedInputList.size(); i++) {
RouteInputElement elt = _includedInputList.get(i);
String name = elt.getUserName();
if (name == null || name.length() == 0) {
name = elt.getSysName();
}
//int opern = newRouteType ? Conditional.OPERATOR_AND : Conditional.OPERATOR_OR;
int opern = Conditional.OPERATOR_AND;
if (i == 0) {
opern = Conditional.OPERATOR_NONE;
}
int state = elt.getState();
if (VETO < state) {
vetoList.add(new ConditionalVariable(true, opern, (state & ~VETO), name, _newRouteType));
}
}
}
///////////////// Make Trigger Conditional Controls /////////////////
ArrayList<ConditionalVariable> oneTriggerList = new ArrayList<>();
ArrayList<ConditionalVariable> twoTriggerList = new ArrayList<>();
if (!_initialize) {
for (int i = 0; i < _includedInputList.size(); i++) {
RouteInputElement elt = _includedInputList.get(i);
String name = elt.getUserName();
if (name == null || name.length() == 0) {
name = elt.getSysName();
}
int opern = _newRouteType ? Conditional.OPERATOR_OR : Conditional.OPERATOR_AND;
if (i == 0) {
opern = Conditional.OPERATOR_NONE;
}
int type = elt.getState();
if (VETO > type) {
if (Route.ONCHANGE == type) {
switch(elt.getType()) {
case SENSOR_TYPE:
type = Conditional.TYPE_SENSOR_ACTIVE;
break;
case TURNOUT_TYPE:
type = Conditional.TYPE_TURNOUT_CLOSED;
break;
case LIGHT_TYPE:
type = Conditional.TYPE_LIGHT_ON;
break;
case SIGNAL_TYPE:
type = Conditional.TYPE_SIGNAL_HEAD_LIT;
break;
default:
log.debug("updatePressed: Unknown state variable type " + elt.getType());
}
twoTriggerList.add(new ConditionalVariable(false, opern, type, name, true));
} else {
oneTriggerList.add(new ConditionalVariable(false, opern, type, name, true));
}
}
}
if (actionList.isEmpty()) {
javax.swing.JOptionPane.showMessageDialog(_addFrame, rbx.getString("noAction"), rbx.getString("addErr"), javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
} else {
oneTriggerList.add(new ConditionalVariable(false, Conditional.OPERATOR_NONE, Conditional.TYPE_NONE, LOGIX_INITIALIZER, true));
}
if (log.isDebugEnabled()) {
log.debug("actionList.size()= " + actionList.size() + ", oneTriggerList.size()= " + oneTriggerList.size() + ", twoTriggerList.size()= " + twoTriggerList.size() + ", onChangeList.size()= " + onChangeList.size() + ", vetoList.size()= " + vetoList.size());
}
logix.deActivateLogix();
// remove old Conditionals for actions (ver 2.5.2 only -remove a bad idea)
char[] ch = sName.toCharArray();
int hash = 0;
for (int i = 0; i < ch.length; i++) {
hash += ch[i];
}
String cSystemName = CONDITIONAL_SYS_PREFIX + "T" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "F" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "A" + hash;
removeConditionals(cSystemName, logix);
cSystemName = CONDITIONAL_SYS_PREFIX + "L" + hash;
removeConditionals(cSystemName, logix);
int n = 0;
do {
n++;
cSystemName = sName + n + "A";
} while (removeConditionals(cSystemName, logix));
n = 0;
do {
n++;
cSystemName = sName + n + "T";
} while (removeConditionals(cSystemName, logix));
cSystemName = sName + "L";
removeConditionals(cSystemName, logix);
//String cUserName = null;
int numConds = 1;
if (_newRouteType) {
numConds = makeRouteConditional(numConds, /*false,*/
actionList, oneTriggerList, vetoList, logix, sName, uName, "T");
if (!_initialize && twoTriggerList.size() > 0) {
numConds = makeRouteConditional(numConds, /*true, actionList,*/
onChangeList, twoTriggerList, null, logix, sName, uName, "T");
}
} else {
for (int i = 0; i < oneTriggerList.size(); i++) {
ArrayList<ConditionalVariable> vList = new ArrayList<>();
vList.add(oneTriggerList.get(i));
numConds = makeRouteConditional(numConds, /*false,*/
actionList, vList, vetoList, logix, sName, uName, "T");
}
for (int i = 0; i < twoTriggerList.size(); i++) {
ArrayList<ConditionalVariable> vList = new ArrayList<>();
vList.add(twoTriggerList.get(i));
numConds = makeRouteConditional(numConds, /*true, actionList,*/
onChangeList, vList, vetoList, logix, sName, uName, "T");
}
}
if (numConds == 1) {
javax.swing.JOptionPane.showMessageDialog(_addFrame, rbx.getString("noVars"), rbx.getString("addErr"), javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
///////////////// Make Alignment Conditionals //////////////////////////
numConds = 1;
for (int i = 0; i < _includedAlignList.size(); i++) {
ArrayList<ConditionalVariable> vList = new ArrayList<>();
ArrayList<ConditionalAction> aList = new ArrayList<>();
AlignElement sensor = _includedAlignList.get(i);
String name = sensor.getUserName();
if (name == null || name.length() == 0) {
name = sensor.getSysName();
}
aList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, name, Sensor.ACTIVE, ""));
aList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE, Conditional.ACTION_SET_SENSOR, name, Sensor.INACTIVE, ""));
int alignType = sensor.getState();
for (int k = 0; k < _includedOutputList.size(); k++) {
RouteOutputElement elt = _includedOutputList.get(k);
int varType = 0;
boolean add = (ALL_TYPE == alignType);
switch(elt.getType()) {
case SENSOR_TYPE:
if (alignType == SENSOR_TYPE) {
add = true;
}
switch(elt.getState()) {
case Sensor.INACTIVE:
varType = Conditional.TYPE_SENSOR_INACTIVE;
break;
case Sensor.ACTIVE:
varType = Conditional.TYPE_SENSOR_ACTIVE;
break;
case Route.TOGGLE:
add = false;
break;
default:
log.warn("Unexpected state {} from elt.getState() in SENSOR_TYPE", elt.getState());
break;
}
break;
case TURNOUT_TYPE:
if (alignType == TURNOUT_TYPE) {
add = true;
}
switch(elt.getState()) {
case Turnout.CLOSED:
varType = Conditional.TYPE_TURNOUT_CLOSED;
break;
case Turnout.THROWN:
varType = Conditional.TYPE_TURNOUT_THROWN;
break;
case Route.TOGGLE:
add = false;
break;
default:
log.warn("Unexpected state {} from elt.getState() in TURNOUT_TYPE", elt.getState());
break;
}
break;
case LIGHT_TYPE:
if (alignType == LIGHT_TYPE) {
add = true;
}
switch(elt.getState()) {
case Light.ON:
varType = Conditional.TYPE_LIGHT_ON;
break;
case Light.OFF:
varType = Conditional.TYPE_LIGHT_OFF;
break;
case Route.TOGGLE:
add = false;
break;
default:
log.warn("Unexpected state {} from elt.getState() in LIGHT_TYPE", elt.getState());
break;
}
break;
case SIGNAL_TYPE:
if (alignType == SIGNAL_TYPE) {
add = true;
}
switch(elt.getState()) {
case SignalHead.DARK:
varType = Conditional.TYPE_SIGNAL_HEAD_DARK;
break;
case SignalHead.RED:
varType = Conditional.TYPE_SIGNAL_HEAD_RED;
break;
case SignalHead.FLASHRED:
varType = Conditional.TYPE_SIGNAL_HEAD_FLASHRED;
break;
case SignalHead.YELLOW:
varType = Conditional.TYPE_SIGNAL_HEAD_YELLOW;
break;
case SignalHead.FLASHYELLOW:
varType = Conditional.TYPE_SIGNAL_HEAD_FLASHYELLOW;
break;
case SignalHead.GREEN:
varType = Conditional.TYPE_SIGNAL_HEAD_GREEN;
break;
case SignalHead.FLASHGREEN:
varType = Conditional.TYPE_SIGNAL_HEAD_FLASHGREEN;
break;
case SET_SIGNAL_HELD:
varType = Conditional.TYPE_SIGNAL_HEAD_HELD;
break;
case CLEAR_SIGNAL_HELD:
// don't know how to test for this
add = false;
break;
case SET_SIGNAL_DARK:
varType = Conditional.TYPE_SIGNAL_HEAD_DARK;
break;
case SET_SIGNAL_LIT:
varType = Conditional.TYPE_SIGNAL_HEAD_LIT;
break;
default:
log.warn("Unexpected state {} from elt.getState() in SIGNAL_TYPE", elt.getState());
break;
}
break;
default:
log.debug("updatePressed: Unknown Alignment state variable type " + elt.getType());
}
if (add && !_initialize) {
String eltName = elt.getUserName();
if (eltName == null || eltName.length() == 0) {
eltName = elt.getSysName();
}
vList.add(new ConditionalVariable(false, Conditional.OPERATOR_AND, varType, eltName, true));
}
}
if (vList.size() > 0) {
numConds = makeAlignConditional(numConds, aList, vList, logix, sName, uName);
} else {
javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("NoAlign"), new Object[] { name, sensor.getAlignType() }), Bundle.getMessage("WarningTitle"), javax.swing.JOptionPane.WARNING_MESSAGE);
}
}
///////////////// Make Lock Conditional //////////////////////////
numConds = 1;
if (_lock) {
ArrayList<ConditionalAction> aList = new ArrayList<>();
for (int k = 0; k < _includedOutputList.size(); k++) {
RouteOutputElement elt = _includedOutputList.get(k);
if (elt.getType() != TURNOUT_TYPE) {
continue;
}
if (elt.getState() == Route.TOGGLE) {
continue;
}
String eltName = elt.getUserName();
if (eltName == null || eltName.length() == 0) {
eltName = elt.getSysName();
}
aList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_LOCK_TURNOUT, eltName, Turnout.LOCKED, ""));
aList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_FALSE, Conditional.ACTION_LOCK_TURNOUT, eltName, Turnout.UNLOCKED, ""));
}
numConds = makeRouteConditional(numConds, /*false,*/
aList, oneTriggerList, vetoList, logix, sName, uName, "L");
}
log.debug("Conditionals added= " + logix.getNumConditionals());
for (int i = 0; i < logix.getNumConditionals(); i++) {
log.debug("Conditional SysName= \"" + logix.getConditionalByNumberOrder(i) + "\"");
}
logix.activateLogix();
log.debug("Conditionals added= " + logix.getNumConditionals());
for (int i = 0; i < logix.getNumConditionals(); i++) {
log.debug("Conditional SysName= \"" + logix.getConditionalByNumberOrder(i) + "\"");
}
finishUpdate();
}
use of jmri.implementation.DefaultConditionalAction in project JMRI by JMRI.
the class SensorGroupFrame method addPressed.
void addPressed() {
deleteGroup(false);
String group = _nameField.getText();
if (group == null || group.length() == 0) {
javax.swing.JOptionPane.showMessageDialog(this, "Please enter a name for this group.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
Logix logix = getSystemLogix();
logix.deActivateLogix();
String cSystemName = ConditionalSystemPrefix + group.toUpperCase();
String cUserName = ConditionalUserPrefix + group;
// add new Conditional
ArrayList<ConditionalVariable> variableList = new ArrayList<ConditionalVariable>();
ArrayList<ConditionalAction> actionList = new ArrayList<ConditionalAction>();
int count = 0;
for (int i = 0; i < _sensorModel.getRowCount(); i++) {
if ((Boolean) _sensorModel.getValueAt(i, BeanTableModel.INCLUDE_COLUMN)) {
String sensor = (String) _sensorModel.getValueAt(i, BeanTableModel.SNAME_COLUMN);
variableList.add(new ConditionalVariable(false, Conditional.OPERATOR_OR, Conditional.TYPE_SENSOR_ACTIVE, sensor, true));
actionList.add(new DefaultConditionalAction(Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE, Conditional.ACTION_SET_SENSOR, sensor, Sensor.INACTIVE, ""));
count++;
}
}
if (count < 2) {
javax.swing.JOptionPane.showMessageDialog(this, "A Sensor Group needs to have at least 2 sensors to be useful.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
}
Conditional c = new SensorGroupConditional(cSystemName, cUserName);
// InstanceManager.getDefault(jmri.ConditionalManager.class).register(c);
c.setStateVariables(variableList);
c.setLogicType(Conditional.ALL_OR, "");
c.setAction(actionList);
// Update the Logix Conditional names list
logix.addConditional(cSystemName, 0);
// Update the Logix Conditional hash map
logix.addConditional(cSystemName, c);
logix.setEnabled(true);
logix.activateLogix();
((DefaultListModel<String>) _sensorGroupList.getModel()).addElement(cUserName.substring(ConditionalUserPrefix.length()));
clear();
}
use of jmri.implementation.DefaultConditionalAction in project JMRI by JMRI.
the class LogixTableAction method addActionPressed.
/**
* Respond to Add action button in the EditConditional window.
*
* @param e The event heard
*/
void addActionPressed(ActionEvent e) {
if (alreadyEditingActionOrVariable()) {
return;
}
_showReminder = true;
_actionList.add(new DefaultConditionalAction());
_newItem = true;
_actionTableModel.fireTableRowsInserted(_actionList.size(), _actionList.size());
makeEditActionWindow(_actionList.size() - 1);
}
Aggregations