Search in sources :

Example 46 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class LayoutBlockManager method getLayoutTurnoutFromTurnoutName.

private LayoutTurnout getLayoutTurnoutFromTurnoutName(String turnoutName, LayoutEditor panel) {
    Turnout t = InstanceManager.turnoutManagerInstance().getTurnout(turnoutName);
    if (t == null) {
        return null;
    }
    LayoutTurnout lt = null;
    for (int i = 0; i < panel.turnoutList.size(); i++) {
        lt = panel.turnoutList.get(i);
        if (lt.getTurnout() == t) {
            return lt;
        }
    }
    return null;
}
Also used : Turnout(jmri.Turnout)

Example 47 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SerialTurnoutManager method getNextValidAddress.

/**
     * A method that returns the next valid free turnout hardware address
     */
@Override
public String getNextValidAddress(String curAddress, String prefix) throws JmriException {
    String tmpSName = "";
    try {
        tmpSName = createSystemName(curAddress, prefix);
    } catch (JmriException ex) {
        throw ex;
    }
    //If the hardware address part does not already exist then this can
    //be considered the next valid address.
    Turnout t = getBySystemName(tmpSName);
    if (t == null) {
        /*We look for the last instance of T, as the hardware address side 
             of the system name should not contain the letter, however parts of the prefix might */
        int seperator = tmpSName.lastIndexOf("T") + 1;
        curAddress = tmpSName.substring(seperator);
        return curAddress;
    }
    //The Number of Output Bits of the previous turnout will help determine the next
    //valid address.
    bitNum = bitNum + t.getNumberOutputBits();
    //Check to determine if the systemName is in use, return null if it is,
    //otherwise return the next valid address.
    tmpSName = _memo.makeSystemName("T", nAddress, bitNum);
    t = getBySystemName(tmpSName);
    if (t != null) {
        for (int x = 1; x < 10; x++) {
            bitNum = bitNum + t.getNumberOutputBits();
            //System.out.println("This should increment " + bitNum);
            tmpSName = _memo.makeSystemName("T", nAddress, bitNum);
            t = getBySystemName(tmpSName);
            if (t == null) {
                int seperator = tmpSName.lastIndexOf("T") + 1;
                curAddress = tmpSName.substring(seperator);
                return curAddress;
            }
        }
        return null;
    } else {
        int seperator = tmpSName.lastIndexOf("T") + 1;
        curAddress = tmpSName.substring(seperator);
        return curAddress;
    }
}
Also used : JmriException(jmri.JmriException) Turnout(jmri.Turnout)

Example 48 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SerialTurnoutManager method createNewTurnout.

@Override
public Turnout createNewTurnout(String systemName, String userName) {
    // validate the system name, and normalize it
    String sName = "";
    sName = _memo.normalizeSystemName(systemName);
    if (sName.equals("")) {
        // system name is not valid
        return null;
    }
    // does this turnout already exist
    Turnout t = getBySystemName(sName);
    if (t != null) {
        return t;
    }
    // check under alternate name
    String altName = _memo.convertSystemNameToAlternate(sName);
    t = getBySystemName(altName);
    if (t != null) {
        return t;
    }
    // check if the addressed output bit is available
    int nAddress = -1;
    nAddress = _memo.getNodeAddressFromSystemName(sName);
    if (nAddress == -1) {
        return (null);
    }
    int bitNum = _memo.getBitFromSystemName(sName);
    if (bitNum == 0) {
        return (null);
    }
    String conflict = "";
    conflict = _memo.isOutputBitFree(nAddress, bitNum);
    if ((!conflict.equals("")) && (!conflict.equals(sName))) {
        log.error(sName + " assignment conflict with " + conflict + ".");
        notifyTurnoutCreationError(conflict, bitNum);
        return (null);
    }
    // create the turnout
    t = new SerialTurnout(sName, userName, _memo);
    // does system name correspond to configured hardware
    if (!_memo.validSystemNameConfig(sName, 'T', _memo.getTrafficController())) {
        // system name does not correspond to configured hardware
        log.warn("Turnout '" + sName + "' refers to an undefined Serial Node.");
    }
    return t;
}
Also used : Turnout(jmri.Turnout)

Example 49 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class CMRISystemConnectionMemo method isOutputBitFree.

/**
     * Public static method to test if a C/MRI output bit is free for assignment
     * Returns "" (null string) if the specified output bit is free for
     * assignment, else returns the system name of the conflicting assignment.
     * Test is not performed if the node address or bit number are illegal.
     */
public String isOutputBitFree(int nAddress, int bitNum) {
    if ((nAddress < 0) || (nAddress > 127)) {
        log.error("illegal node adddress in free bit test");
        return "";
    }
    if ((bitNum < 1) || (bitNum > 2048)) {
        log.error("illegal bit number in free bit test");
        return "";
    }
    Turnout t = null;
    String sysName = "";
    sysName = makeSystemName("T", nAddress, bitNum);
    t = InstanceManager.turnoutManagerInstance().getBySystemName(sysName);
    if (t != null) {
        return sysName;
    }
    String altName = "";
    altName = convertSystemNameToAlternate(sysName);
    t = InstanceManager.turnoutManagerInstance().getBySystemName(altName);
    if (t != null) {
        return altName;
    }
    if (bitNum > 1) {
        sysName = makeSystemName("T", nAddress, bitNum - 1);
        t = InstanceManager.turnoutManagerInstance().getBySystemName(sysName);
        if (t != null) {
            if (t.getNumberOutputBits() == 2) {
                return sysName;
            }
        } else {
            altName = convertSystemNameToAlternate(sysName);
            if (altName != null) {
                t = InstanceManager.turnoutManagerInstance().getBySystemName(altName);
                if (t != null) {
                    if (t.getNumberOutputBits() == 2) {
                        return altName;
                    }
                }
            }
        }
    }
    Light lgt = null;
    sysName = makeSystemName("L", nAddress, bitNum);
    lgt = InstanceManager.lightManagerInstance().getBySystemName(sysName);
    if (lgt != null) {
        return sysName;
    }
    altName = convertSystemNameToAlternate(sysName);
    lgt = InstanceManager.lightManagerInstance().getBySystemName(altName);
    if (lgt != null) {
        return altName;
    }
    // not assigned to a turnout or a light
    return "";
}
Also used : Light(jmri.Light) Turnout(jmri.Turnout)

Example 50 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SerialTurnoutManager method createNewTurnout.

@Override
public Turnout createNewTurnout(String systemName, String userName) {
    // validate the system name, and normalize it
    String sName = SerialAddress.normalizeSystemName(systemName);
    if (sName.equals("")) {
        // system name is not valid
        return null;
    }
    // does this turnout already exist
    Turnout t = getBySystemName(sName);
    if (t != null) {
        return null;
    }
    // check under alternate name
    String altName = SerialAddress.convertSystemNameToAlternate(sName);
    t = getBySystemName(altName);
    if (t != null) {
        return null;
    }
    // create the turnout
    t = new SerialTurnout(sName, userName);
    // does system name correspond to configured hardware
    if (!SerialAddress.validSystemNameConfig(sName, 'T')) {
        // system name does not correspond to configured hardware
        log.warn("Turnout '" + sName + "' refers to an undefined Serial Node.");
    }
    return t;
}
Also used : 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