Search in sources :

Example 21 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class LRouteTableAction method getAlignmentSensors.

// getControlsAndActions
/**
     * Extract the Alignment Sensors and their types.
     *
     * @param cSysName the conditional system name
     */
void getAlignmentSensors(String cSysName) {
    Conditional c = _conditionalManager.getBySystemName(cSysName);
    if (c != null) {
        AlignElement element = null;
        ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
        for (int k = 0; k < actionList.size(); k++) {
            ConditionalAction action = actionList.get(k);
            if (action.getType() != Conditional.ACTION_SET_SENSOR) {
                javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("AlignWarn1"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
            } else {
                String name = action.getDeviceName();
                String key = SENSOR_TYPE + name;
                element = _alignUserMap.get(key);
                if (element == null) {
                    // try in system name map
                    element = _alignMap.get(key);
                }
                if (element == null) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                } else if (!name.equals(action.getDeviceName())) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("AlignWarn2"), new Object[] { action.toString(), action.getDeviceName(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                } else {
                    element.setIncluded(true);
                }
            }
        }
        // the action elements are identified in getControlsAndActions().
        //  Just identify the type of sensing
        ArrayList<ConditionalVariable> varList = c.getCopyOfStateVariables();
        int atype = 0;
        for (int k = 0; k < varList.size(); k++) {
            ConditionalVariable variable = varList.get(k);
            int testState = variable.getType();
            int type;
            switch(testState) {
                case Conditional.TYPE_SENSOR_ACTIVE:
                case Conditional.TYPE_SENSOR_INACTIVE:
                    type = SENSOR_TYPE;
                    break;
                case Conditional.TYPE_TURNOUT_CLOSED:
                case Conditional.TYPE_TURNOUT_THROWN:
                    type = TURNOUT_TYPE;
                    break;
                case Conditional.TYPE_LIGHT_ON:
                case Conditional.TYPE_LIGHT_OFF:
                    type = LIGHT_TYPE;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_LIT:
                case Conditional.TYPE_SIGNAL_HEAD_RED:
                case Conditional.TYPE_SIGNAL_HEAD_YELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_GREEN:
                case Conditional.TYPE_SIGNAL_HEAD_DARK:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHRED:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHYELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHGREEN:
                case Conditional.TYPE_SIGNAL_HEAD_HELD:
                    type = SIGNAL_TYPE;
                    break;
                default:
                    if (!LOGIX_INITIALIZER.equals(variable.getName())) {
                        javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarnVar"), new Object[] { variable.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    }
                    continue;
            }
            if (k == 0) {
                atype = type;
            } else if (atype != type) {
                // more than one type. therefor, ALL
                atype = ALL_TYPE;
                break;
            }
        }
        if (element != null) {
            element.setState(atype);
        }
    }
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Example 22 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class LRouteTableAction method getControlsAndActions.

/**
     * Extract the Control (input) and Action (output) elements and their
     * states.
     *
     * @param cSysName the conditional system name
     */
void getControlsAndActions(String cSysName) {
    Conditional c = _conditionalManager.getBySystemName(cSysName);
    if (c != null) {
        ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
        boolean onChange = false;
        for (int k = 0; k < actionList.size(); k++) {
            ConditionalAction action = actionList.get(k);
            int type;
            switch(action.getType()) {
                case Conditional.ACTION_SET_SENSOR:
                    type = SENSOR_TYPE;
                    break;
                case Conditional.ACTION_SET_TURNOUT:
                    type = TURNOUT_TYPE;
                    break;
                case Conditional.ACTION_SET_LIGHT:
                    type = LIGHT_TYPE;
                    break;
                case Conditional.ACTION_SET_SIGNAL_APPEARANCE:
                case Conditional.ACTION_SET_SIGNAL_HELD:
                case Conditional.ACTION_CLEAR_SIGNAL_HELD:
                case Conditional.ACTION_SET_SIGNAL_DARK:
                case Conditional.ACTION_SET_SIGNAL_LIT:
                    type = SIGNAL_TYPE;
                    break;
                case Conditional.ACTION_RUN_SCRIPT:
                    scriptFile.setText(action.getActionString());
                    continue;
                case Conditional.ACTION_PLAY_SOUND:
                    soundFile.setText(action.getActionString());
                    continue;
                default:
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    continue;
            }
            String name = action.getDeviceName();
            String key = type + name;
            RouteOutputElement elt = _outputUserMap.get(key);
            if (elt == null) {
                // try in system name map
                elt = _outputMap.get(key);
            }
            if (elt == null) {
                javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
            } else {
                elt.setIncluded(true);
                elt.setState(action.getActionData());
                boolean change = (action.getOption() == Conditional.ACTION_OPTION_ON_CHANGE);
                if (k == 0) {
                    onChange = change;
                } else if (change != onChange) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("OnChangeWarn"), new Object[] { action.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                }
            }
        }
        ArrayList<ConditionalVariable> varList = c.getCopyOfStateVariables();
        for (int k = 0; k < varList.size(); k++) {
            ConditionalVariable variable = varList.get(k);
            int testState = variable.getType();
            //boolean negated = variable.isNegated();
            int type;
            switch(testState) {
                case Conditional.TYPE_SENSOR_ACTIVE:
                    type = SENSOR_TYPE;
                    //if (negated) testState = Conditional.TYPE_SENSOR_INACTIVE;
                    break;
                case Conditional.TYPE_SENSOR_INACTIVE:
                    type = SENSOR_TYPE;
                    //if (negated) testState = Conditional.TYPE_SENSOR_ACTIVE;
                    break;
                case Conditional.TYPE_TURNOUT_CLOSED:
                    type = TURNOUT_TYPE;
                    //if (negated) testState = Conditional.TYPE_TURNOUT_THROWN;
                    break;
                case Conditional.TYPE_TURNOUT_THROWN:
                    type = TURNOUT_TYPE;
                    //if (negated) testState = Conditional.TYPE_TURNOUT_CLOSED;
                    break;
                case Conditional.TYPE_LIGHT_ON:
                    type = LIGHT_TYPE;
                    //if (negated) testState = Conditional.TYPE_LIGHT_OFF;
                    break;
                case Conditional.TYPE_LIGHT_OFF:
                    type = LIGHT_TYPE;
                    //if (negated) testState = Conditional.TYPE_LIGHT_ON;
                    break;
                case Conditional.TYPE_SIGNAL_HEAD_LIT:
                case Conditional.TYPE_SIGNAL_HEAD_RED:
                case Conditional.TYPE_SIGNAL_HEAD_YELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_GREEN:
                case Conditional.TYPE_SIGNAL_HEAD_DARK:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHRED:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHYELLOW:
                case Conditional.TYPE_SIGNAL_HEAD_FLASHGREEN:
                case Conditional.TYPE_SIGNAL_HEAD_HELD:
                    type = SIGNAL_TYPE;
                    break;
                default:
                    if (!LOGIX_INITIALIZER.equals(variable.getName())) {
                        javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarnVar"), new Object[] { variable.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                    }
                    continue;
            }
            int opern = variable.getOpern();
            if (k != 0 && (opern == Conditional.OPERATOR_AND || opern == Conditional.OPERATOR_AND_NOT)) {
                // guess this is a VETO
                testState += VETO;
            } else if (onChange) {
                testState = Route.ONCHANGE;
            }
            String name = variable.getName();
            String key = type + name;
            RouteInputElement elt = _inputUserMap.get(key);
            if (elt == null) {
                // try in system name map
                elt = _inputMap.get(key);
            }
            if (elt == null) {
                if (!LOGIX_INITIALIZER.equals(name)) {
                    javax.swing.JOptionPane.showMessageDialog(_addFrame, java.text.MessageFormat.format(rbx.getString("TypeWarnVar"), new Object[] { variable.toString(), c.getSystemName() }), rbx.getString("EditDiff"), javax.swing.JOptionPane.WARNING_MESSAGE);
                }
            } else {
                elt.setIncluded(true);
                elt.setState(testState);
            }
        }
    }
}
Also used : ConditionalAction(jmri.ConditionalAction) DefaultConditionalAction(jmri.implementation.DefaultConditionalAction) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Example 23 with ConditionalVariable

use of jmri.ConditionalVariable in project JMRI by JMRI.

the class RouteTableAction method makeTurnoutConditional.

/**
     * Create a new turnout conditional.
     *
     * @param jmriBox    control, the selection from which, will be used to
     *                   determine which sensor to make a conditional for
     * @param box        control, the selection from which, will be used to
     *                   determine the mode for the conditional
     * @param numConds   number of existing route conditionals
     * @param onChange   ???
     * @param actionList actions to take in conditional
     * @param vetoList   conditionals that can veto an action
     * @param logix      Logix to add the conditional to
     * @param prefix     system prefix for conditional
     * @param uName      user name for conditional
     * @return number of conditionals after the creation
     * @throws IllegalArgumentException if "user input no good"
     */
// why are the controls being passed, and not their selections?
int makeTurnoutConditional(JmriBeanComboBox jmriBox, JComboBox<String> box, int numConds, boolean onChange, ArrayList<ConditionalAction> actionList, ArrayList<ConditionalVariable> vetoList, Logix logix, String prefix, String uName) {
    ConditionalVariable cVar = makeCtrlTurnoutVar(jmriBox, box, false, onChange);
    if (cVar != null) {
        ArrayList<ConditionalVariable> varList = new ArrayList<>();
        varList.add(cVar);
        for (int i = 0; i < vetoList.size(); i++) {
            varList.add(cloneVariable(vetoList.get(i)));
        }
        String cSystemName = prefix + numConds + "T";
        String cUserName = jmriBox.getSelectedDisplayName() + numConds + "C " + uName;
        Conditional c = null;
        try {
            c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(cSystemName, cUserName);
        } catch (Exception ex) {
            // user input no good
            handleCreateException(cSystemName);
            // throw without creating any 
            throw new IllegalArgumentException("user input no good");
        }
        c.setStateVariables(varList);
        int option = onChange ? Conditional.ACTION_OPTION_ON_CHANGE : Conditional.ACTION_OPTION_ON_CHANGE_TO_TRUE;
        c.setAction(cloneActionList(actionList, option));
        c.setLogicType(Conditional.ALL_AND, "");
        logix.addConditional(cSystemName, 0);
        c.calculate(true, null);
        numConds++;
    }
    return numConds;
}
Also used : ArrayList(java.util.ArrayList) Conditional(jmri.Conditional) ConditionalVariable(jmri.ConditionalVariable)

Aggregations

ConditionalVariable (jmri.ConditionalVariable)23 Conditional (jmri.Conditional)16 ConditionalAction (jmri.ConditionalAction)10 DefaultConditionalAction (jmri.implementation.DefaultConditionalAction)9 ArrayList (java.util.ArrayList)8 Logix (jmri.Logix)8 ConditionalManager (jmri.ConditionalManager)3 DefaultListModel (javax.swing.DefaultListModel)2 DefaultConditional (jmri.implementation.DefaultConditional)2 SensorGroupConditional (jmri.implementation.SensorGroupConditional)2 DefaultConditionalManager (jmri.managers.DefaultConditionalManager)2 Element (org.jdom2.Element)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Vector (java.util.Vector)1 JButton (javax.swing.JButton)1 JList (javax.swing.JList)1 JScrollPane (javax.swing.JScrollPane)1 Block (jmri.Block)1 Memory (jmri.Memory)1