Search in sources :

Example 91 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SignallingPanel method updatePressed.

/**
     * Update changes in SML when Update button is pressed in the Edit Logic - Add Logic pane.
     *
     * @param e the event heard
     */
void updatePressed(ActionEvent e) {
    sourceMast = (SignalMast) sourceMastBox.getSelectedBean();
    destMast = (SignalMast) destMastBox.getSelectedBean();
    boolean smlPairAdded = false;
    destOK = true;
    if (sourceMast == destMast || fixedSourceMastLabel.getText() == destMast.getDisplayName()) {
        JOptionPane.showMessageDialog(null, rb.getString("ErrorSignalMastIdentical"));
        destOK = false;
        log.debug("Destination Mast check failed, keep pane open");
        return;
    }
    if ((sml == null) && (useLayoutEditor.isSelected())) {
        boolean valid = false;
        try {
            valid = InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlockConnectivityTools().checkValidDest(sourceMast, destMast, LayoutBlockConnectivityTools.MASTTOMAST);
            if (!valid) {
                JOptionPane.showMessageDialog(null, rb.getString("ErrorUnReachableDestination"));
                return;
            }
        } catch (jmri.JmriException je) {
            JOptionPane.showMessageDialog(null, rb.getString("WarningUnabletoValidate"));
        }
    }
    if (sml == null) {
        // a new SML directly from the SML Table
        sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).newSignalMastLogic(sourceMast);
        // check if a similar SML pair already exists when in Add New session
        if (!sml.getDestinationList().contains(destMast)) {
            // not yet defined as a pair
            smlPairAdded = true;
            sml.setDestinationMast(destMast);
        } else {
            // show replace/update dialog
            int mes = JOptionPane.showConfirmDialog(null, rb.getString("WarningExistingPair"), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION);
            if (mes == JOptionPane.NO_OPTION) {
                return;
            }
        }
        fixedSourceMastLabel.setText(sourceMast.getDisplayName());
        fixedDestMastLabel.setText(destMast.getDisplayName());
        sourceMastBox.setVisible(false);
        destMastBox.setVisible(false);
        fixedSourceMastLabel.setVisible(true);
        fixedDestMastLabel.setVisible(true);
        _autoTurnoutModel.smlValid();
        _autoBlockModel.smlValid();
        _autoSignalMastModel.smlValid();
    }
    initializeIncludedList();
    sml.allowAutoMaticSignalMastGeneration(allowAutoMastGeneration.isSelected(), destMast);
    boolean layouteditorgen = true;
    try {
        sml.useLayoutEditor(useLayoutEditor.isSelected(), destMast);
    } catch (jmri.JmriException je) {
        JOptionPane.showMessageDialog(null, je.toString());
        layouteditorgen = false;
    }
    try {
        if (useLayoutEditor.isSelected()) {
            sml.useLayoutEditorDetails(useLayoutEditorTurnout.isSelected(), useLayoutEditorBlock.isSelected(), destMast);
        }
    } catch (jmri.JmriException ji) {
        if (layouteditorgen) {
            JOptionPane.showMessageDialog(null, ji.toString());
        }
    }
    Hashtable<Block, Integer> hashBlocks = new Hashtable<Block, Integer>();
    for (int i = 0; i < _includedManualBlockList.size(); i++) {
        Block blk = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(_includedManualBlockList.get(i).getSysName());
        hashBlocks.put(blk, _includedManualBlockList.get(i).getState());
    }
    sml.setBlocks(hashBlocks, destMast);
    Hashtable<NamedBeanHandle<Turnout>, Integer> hashTurnouts = new Hashtable<NamedBeanHandle<Turnout>, Integer>();
    for (int i = 0; i < _includedManualTurnoutList.size(); i++) {
        String turnoutName = _includedManualTurnoutList.get(i).getDisplayName();
        Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(_includedManualTurnoutList.get(i).getDisplayName());
        NamedBeanHandle<Turnout> namedTurnout = nbhm.getNamedBeanHandle(turnoutName, turnout);
        hashTurnouts.put(namedTurnout, _includedManualTurnoutList.get(i).getState());
    // no specific value, just show the current turnout state as selection in comboBox.
    // for existing SML pair, will be updated to show present setting by editDetails()
    }
    sml.setTurnouts(hashTurnouts, destMast);
    Hashtable<NamedBeanHandle<Sensor>, Integer> hashSensors = new Hashtable<NamedBeanHandle<Sensor>, Integer>();
    for (int i = 0; i < _includedManualSensorList.size(); i++) {
        String sensorName = _includedManualSensorList.get(i).getDisplayName();
        Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(_includedManualSensorList.get(i).getDisplayName());
        NamedBeanHandle<Sensor> namedSensor = nbhm.getNamedBeanHandle(sensorName, sensor);
        hashSensors.put(namedSensor, _includedManualSensorList.get(i).getState());
    // no specific value, just show the current sensor state as selection in comboBox.
    // for existing SML pair, will be updated to show present setting by editDetails()
    }
    sml.setSensors(hashSensors, destMast);
    Hashtable<SignalMast, String> hashSignalMasts = new Hashtable<SignalMast, String>();
    for (int i = 0; i < _includedManualSignalMastList.size(); i++) {
        if (_includedManualSignalMastList.get(i).getMast() == sourceMast || _includedManualSignalMastList.get(i).getMast() == destMast) {
            // warn user that control mast is either source or destination mast of this pair, but allow as a valid choice
            int mes = JOptionPane.showConfirmDialog(null, java.text.MessageFormat.format(rb.getString("SignalMastCriteriaOwn"), new Object[] { _includedManualSignalMastList.get(i).getMast().getDisplayName() }), rb.getString("SignalMastCriteriaOwnTitle"), JOptionPane.YES_NO_OPTION);
            if (mes == 0) {
                // Yes
                hashSignalMasts.put(_includedManualSignalMastList.get(i).getMast(), _includedManualSignalMastList.get(i).getSetToState());
            } else {
                // No
                // deselect "Included" checkBox for signal mast in manualSignalList
                _includedManualSignalMastList.get(i).setIncluded(false);
                initializeIncludedList();
                _signalMastModel.fireTableDataChanged();
            }
        } else {
            hashSignalMasts.put(_includedManualSignalMastList.get(i).getMast(), _includedManualSignalMastList.get(i).getSetToState());
        }
    }
    sml.setMasts(hashSignalMasts, destMast);
    sml.allowTurnoutLock(lockTurnouts.isSelected(), destMast);
    sml.initialise(destMast);
    if (smlPairAdded) {
        log.debug("New SML");
        // to show new SML in underlying table
        firePropertyChange("newDestination", null, destMastBox.getSelectedBean());
    }
}
Also used : Hashtable(java.util.Hashtable) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Sensor(jmri.Sensor)

Example 92 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SignallingPanel method initializeIncludedList.

/**
     * Create new lists of control items configured as part of an SML.
     */
void initializeIncludedList() {
    _includedManualBlockList = new ArrayList<ManualBlockList>();
    for (int i = 0; i < _manualBlockList.size(); i++) {
        if (_manualBlockList.get(i).isIncluded()) {
            _includedManualBlockList.add(_manualBlockList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Block> blkList = sml.getAutoBlocks(destMast);
        _automaticBlockList = new ArrayList<AutoBlockList>(blkList.size());
        Iterator<Block> iter = blkList.iterator();
        while (iter.hasNext()) {
            Block blk = iter.next();
            AutoBlockList newABlk = new AutoBlockList(blk);
            _automaticBlockList.add(newABlk);
            newABlk.setState(sml.getAutoBlockState(blk, destMast));
        }
    }
    _includedManualTurnoutList = new ArrayList<ManualTurnoutList>();
    for (int i = 0; i < _manualTurnoutList.size(); i++) {
        if (_manualTurnoutList.get(i).isIncluded()) {
            _includedManualTurnoutList.add(_manualTurnoutList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Turnout> turnList = sml.getAutoTurnouts(destMast);
        _automaticTurnoutList = new ArrayList<AutoTurnoutList>(turnList.size());
        Iterator<Turnout> iter = turnList.iterator();
        while (iter.hasNext()) {
            Turnout turn = iter.next();
            String systemName = turn.getSystemName();
            String userName = turn.getUserName();
            AutoTurnoutList newAturn = new AutoTurnoutList(systemName, userName);
            _automaticTurnoutList.add(newAturn);
            newAturn.setState(sml.getAutoTurnoutState(turn, destMast));
        }
    }
    _includedManualSensorList = new ArrayList<ManualSensorList>();
    for (int i = 0; i < _manualSensorList.size(); i++) {
        if (_manualSensorList.get(i).isIncluded()) {
            _includedManualSensorList.add(_manualSensorList.get(i));
        }
    }
    _includedManualSignalMastList = new ArrayList<ManualSignalMastList>();
    for (int i = 0; i < _manualSignalMastList.size(); i++) {
        if (_manualSignalMastList.get(i).isIncluded()) {
            _includedManualSignalMastList.add(_manualSignalMastList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<SignalMast> mastList = sml.getAutoMasts(destMast);
        _automaticSignalMastList = new ArrayList<AutoSignalMastList>(mastList.size());
        Iterator<SignalMast> iter = mastList.iterator();
        while (iter.hasNext()) {
            SignalMast mast = iter.next();
            AutoSignalMastList newAmast = new AutoSignalMastList(mast);
            _automaticSignalMastList.add(newAmast);
            newAmast.setState(sml.getAutoSignalMastState(mast, destMast));
        }
    }
}
Also used : SignalMast(jmri.SignalMast) Block(jmri.Block) Turnout(jmri.Turnout)

Example 93 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SignallingPanel method editDetails.

/**
     * Fill in existing SML configuration on the edit panel
     */
void editDetails() {
    int setRow = 0;
    for (int i = _manualBlockList.size() - 1; i >= 0; i--) {
        ManualBlockList block = _manualBlockList.get(i);
        String tSysName = block.getSysName();
        Block blk = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(tSysName);
        if (sml.isBlockIncluded(blk, destMast)) {
            block.setIncluded(true);
            block.setState(sml.getBlockState(blk, destMast));
            setRow = i;
        } else {
            block.setIncluded(false);
            block.setState(Block.UNOCCUPIED);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualBlockScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _blockModel.fireTableDataChanged();
    setRow = 0;
    for (int i = _manualTurnoutList.size() - 1; i >= 0; i--) {
        ManualTurnoutList turnout = _manualTurnoutList.get(i);
        String tSysName = turnout.getSysName();
        Turnout turn = InstanceManager.turnoutManagerInstance().getTurnout(tSysName);
        if (sml.isTurnoutIncluded(turn, destMast)) {
            turnout.setIncluded(true);
            turnout.setState(sml.getTurnoutState(turn, destMast));
            setRow = i;
        } else {
            turnout.setIncluded(false);
            turnout.setState(Turnout.CLOSED);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualSensorScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _sensorModel.fireTableDataChanged();
    setRow = 0;
    for (int i = _manualSensorList.size() - 1; i >= 0; i--) {
        ManualSensorList sensor = _manualSensorList.get(i);
        String tSysName = sensor.getSysName();
        Sensor sen = InstanceManager.sensorManagerInstance().getSensor(tSysName);
        if (sml.isSensorIncluded(sen, destMast)) {
            sensor.setIncluded(true);
            sensor.setState(sml.getSensorState(sen, destMast));
            setRow = i;
        } else {
            sensor.setIncluded(false);
            sensor.setState(Sensor.INACTIVE);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualSensorScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _sensorModel.fireTableDataChanged();
    setRow = 0;
    for (int i = _manualSignalMastList.size() - 1; i >= 0; i--) {
        ManualSignalMastList mast = _manualSignalMastList.get(i);
        SignalMast sigMast = _manualSignalMastList.get(i).getMast();
        if (sml.isSignalMastIncluded(sigMast, destMast)) {
            mast.setIncluded(true);
            mast.setSetToState(sml.getSignalMastState(sigMast, destMast));
            setRow = i;
        } else {
            mast.setIncluded(false);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualSignalMastScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _signalMastModel.fireTableDataChanged();
}
Also used : LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 94 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class DCCppTurnoutManager method createNewTurnout.

// DCCpp-specific methods
@Override
public Turnout createNewTurnout(String systemName, String userName) {
    int addr = Integer.valueOf(systemName.substring(prefix.length() + 1)).intValue();
    Turnout t = new DCCppTurnout(prefix, addr, tc);
    t.setUserName(userName);
    return t;
}
Also used : Turnout(jmri.Turnout)

Example 95 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class EcosTurnout method sendMessage.

/**
     * Tell the layout to go to new state.
     *
     * @param closed State of the turnout to be sent to the command station
     */
protected void sendMessage(boolean closed) {
    newKnownState(Turnout.UNKNOWN);
    if (getInverted()) {
        closed = !closed;
    }
    if ((masterObjectNumber) && (extended == 0)) {
        EcosMessage m;
        // get control
        m = new EcosMessage("request(" + objectNumber + ", control)");
        tc.sendEcosMessage(m, null);
        // set state
        m = new EcosMessage("set(" + objectNumber + ", state[" + (closed ? "0" : "1") + "])");
        tc.sendEcosMessage(m, null);
        // release control
        m = new EcosMessage("release(" + objectNumber + ", control)");
        tc.sendEcosMessage(m, null);
    } else {
        //we have a 3 way or double slip!
        //Working upon the basis that if the materObjectNumber is false than this is the second
        //decoder address assigned, while if it is true then we are the first decoder address.
        boolean firststate;
        boolean secondstate;
        if (!masterObjectNumber) {
            //Here we are dealing with the second address
            int turnaddr = _number - 1;
            Turnout t = tm.getTurnout(prefix + "T" + turnaddr);
            secondstate = closed;
            if (t.getKnownState() == CLOSED) {
                firststate = true;
            } else {
                firststate = false;
            }
        } else {
            Turnout t = tm.getTurnout(slaveAddress);
            firststate = closed;
            if (t.getKnownState() == CLOSED) {
                secondstate = true;
            } else {
                secondstate = false;
            }
        }
        int setState = 0;
        if (extended == THREEWAY) {
            if ((firststate) && (secondstate)) {
                setState = 0;
            } else if ((firststate) && (!secondstate)) {
                setState = 1;
            } else {
                setState = 2;
            }
        } else if (extended == DOUBLESLIP) {
            if ((firststate) && (secondstate)) {
                setState = 0;
            } else if ((!firststate) && (!secondstate)) {
                setState = 1;
            } else if ((!firststate) && (secondstate)) {
                setState = 2;
            } else {
                setState = 3;
            }
        }
        if (setState == 99) {
            //System.out.println("Invalid selection old state " + getKnownState() + " " + getCommandedState());
            if (closed) {
                setCommandedState(THROWN);
            } else {
                setCommandedState(CLOSED);
            }
        //System.out.println("After - " + getKnownState() + " " + getCommandedState() + " " + "Is consistant " + isConsistentState());
        } else {
            EcosMessage m = new EcosMessage("request(" + objectNumber + ", control)");
            tc.sendEcosMessage(m, this);
            // set state
            m = new EcosMessage("set(" + objectNumber + ", state[" + setState + "])");
            tc.sendEcosMessage(m, this);
            // release control
            m = new EcosMessage("release(" + objectNumber + ", control)");
            tc.sendEcosMessage(m, this);
        }
    }
}
Also used : AbstractTurnout(jmri.implementation.AbstractTurnout) Turnout(jmri.Turnout)

Aggregations

Turnout (jmri.Turnout)221 Test (org.junit.Test)63 Sensor (jmri.Sensor)26 SignalHead (jmri.SignalHead)20 Element (org.jdom2.Element)20 TurnoutManager (jmri.TurnoutManager)17 JmriException (jmri.JmriException)11 Light (jmri.Light)10 SignalMast (jmri.SignalMast)10 ActionEvent (java.awt.event.ActionEvent)9 NamedBeanHandle (jmri.NamedBeanHandle)9 JsonException (jmri.server.json.JsonException)9 ActionListener (java.awt.event.ActionListener)8 Block (jmri.Block)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 NamedBean (jmri.NamedBean)6 Route (jmri.Route)6 AbstractTurnout (jmri.implementation.AbstractTurnout)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5