Search in sources :

Example 1 with BlockBossLogic

use of jmri.jmrit.blockboss.BlockBossLogic in project JMRI by JMRI.

the class Maintenance method search.

/**
     * Search if a given string is used as the name of a NamedBean.
     *
     * @param name the string to look for
     * @param text body of the message to be displayed reporting the result
     * @return true if name is found at least once as a bean name
     */
static boolean search(String name, JTextArea text) {
    String[] names = getTypeAndNames(name);
    if (log.isDebugEnabled()) {
        log.debug("search for " + name + " as " + names[0] + " \"" + names[1] + "\" (" + names[2] + ")");
    }
    if (names[0].length() == 0) {
        if (text != null) {
            text.append(MessageFormat.format(rbm.getString("ElementNotFound"), (Object[]) names));
            return false;
        }
    }
    if (text != null) {
        text.append(MessageFormat.format(rbm.getString("ReferenceFollows"), (Object[]) names));
    }
    String sysName = names[2];
    String userName = names[1];
    int referenceCount = 0;
    StringBuilder tempText = new StringBuilder();
    boolean found = false;
    boolean empty = true;
    // search for references among each class known to be listeners
    Iterator<String> iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
        if (x == null) {
            log.error("Error getting Logix  - " + sName);
            break;
        }
        tempText = new StringBuilder();
        String uName = x.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "", Bundle.getMessage("BeanNameLogix"), uName, sName });
        for (int i = 0; i < x.getNumConditionals(); i++) {
            sName = x.getConditionalByNumberOrder(i);
            if (sName == null) {
                log.error("Null conditional system name");
                break;
            }
            Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(sName);
            if (c == null) {
                log.error("Invalid conditional system name - " + sName);
                break;
            }
            uName = c.getUserName();
            String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameConditional"), uName, sName });
            String line = MessageFormat.format(rbm.getString("ConditionalReference"), "\t");
            if (sysName.equals(sName) || (userName != null && userName.length() > 0 && userName.equals(uName))) {
                if (testName(sysName, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
            ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
            for (int k = 0; k < variableList.size(); k++) {
                ConditionalVariable v = variableList.get(k);
                line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
                if (testName(v.getName(), found, names, line1, line2, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
            ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
            for (int k = 0; k < actionList.size(); k++) {
                ConditionalAction a = actionList.get(k);
                line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
                if (testName(a.getDeviceName(), found, names, line1, line2, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
            if (text != null && found) {
                text.append(tempText.toString());
                tempText = new StringBuilder();
                found = false;
                empty = false;
                line1 = null;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append("\t" + MessageFormat.format(rbm.getString("NoReference"), "Logix"));
        // cannot put escaped tab char at start of getString
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.jmrit.logix.OBlockManager oBlockManager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    iter1 = oBlockManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.jmrit.logix.OBlock block = oBlockManager.getBySystemName(sName);
        String uName = block.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameOBlock"), uName, sName });
        Sensor sensor = block.getSensor();
        if (sensor != null) {
            String line = MessageFormat.format(rbm.getString("OBlockSensor"), "\t");
            if (testName(sensor.getSystemName(), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "OBlock"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.RouteManager routeManager = InstanceManager.getDefault(jmri.RouteManager.class);
    iter1 = routeManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Route r = routeManager.getBySystemName(sName);
        if (r == null) {
            log.error("Error getting Route  - " + sName);
            break;
        }
        String uName = r.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameRoute"), uName, sName });
        for (int i = 0; i < jmri.Route.MAX_CONTROL_SENSORS; i++) {
            String line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameSensor"));
            if (testName(r.getRouteSensorName(i), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        String line = MessageFormat.format("TurnoutsAlignedSensor", Bundle.getMessage("BeanNameSensor"));
        if (testName(r.getTurnoutsAlignedSensor(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameTurnout"));
        if (testName(r.getControlTurnout(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format("LockControlTurnout", Bundle.getMessage("BeanNameTurnout"));
        if (testName(r.getLockControlTurnout(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        for (int i = 0; i < r.getNumOutputTurnouts(); i++) {
            line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameTurnout"));
            if (testName(r.getOutputTurnoutByIndex(i), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        for (int i = 0; i < r.getNumOutputSensors(); i++) {
            line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameSensor"));
            if (testName(r.getOutputSensorByIndex(i), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Route"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.TransitManager transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
    iter1 = transitManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Transit transit = transitManager.getBySystemName(sName);
        if (transit == null) {
            log.error("Error getting Transit - " + sName);
            break;
        }
        String uName = transit.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameTransit"), uName, sName });
        ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
        for (int i = 0; i < sectionList.size(); i++) {
            jmri.TransitSection transitSection = sectionList.get(i);
            jmri.Section section = transitSection.getSection();
            uName = section.getUserName();
            sName = section.getSystemName();
            String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", rbm.getString("TransitSection"), uName, sName });
            if (sName.equals(sysName) || uName.equals(userName)) {
                tempText.append(line1);
                tempText.append(line2);
                tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t\t"));
                found = true;
                referenceCount++;
            }
            String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t\t");
            if (testName(section.getForwardBlockingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t\t");
            if (testName(section.getForwardStoppingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t\t");
            if (testName(section.getReverseBlockingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t\t");
            if (testName(section.getReverseStoppingSensorName(), found, names, line1, line2, line, tempText)) {
                found = true;
                referenceCount++;
            }
            ArrayList<jmri.Block> blockList = section.getBlockList();
            for (int k = 0; k < blockList.size(); k++) {
                jmri.Block block = blockList.get(k);
                sName = block.getSystemName();
                uName = block.getUserName();
                tempText.append(MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t\t", Bundle.getMessage("BeanNameBlock"), uName, sName }));
                if (sName.equals(sysName) || uName.equals(userName)) {
                    tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t\t"));
                    found = true;
                    referenceCount++;
                }
                Sensor sensor = block.getSensor();
                if (sensor != null) {
                    line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
                    if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
            }
            if (text != null && found) {
                text.append(tempText.toString());
                tempText = new StringBuilder();
                found = false;
                empty = false;
                line1 = null;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Transit"));
        } else {
            text.append("\n");
        }
    }
    // if (text != null) {
    //   text.append(rbm.getString("NestMessage"));
    // }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.SectionManager sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
    java.util.List<String> sysNameList = sectionManager.getSystemNameList();
    transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
    iter1 = transitManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Transit transit = transitManager.getBySystemName(sName);
        if (transit != null) {
            ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
            for (int i = 0; i < sectionList.size(); i++) {
                jmri.TransitSection transitSection = sectionList.get(i);
                jmri.Section section = transitSection.getSection();
                sysNameList.remove(section.getSystemName());
            }
        }
    }
    iter1 = sysNameList.iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Section section = sectionManager.getBySystemName(sName);
        if (section == null) {
            log.error("Error getting Section - " + sName);
            break;
        }
        String uName = section.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameSection"), uName, sName });
        if (sName.equals(sysName) || uName.equals(userName)) {
            tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t"));
            found = true;
            referenceCount++;
        }
        String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t");
        if (testName(section.getForwardBlockingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t");
        if (testName(section.getForwardStoppingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t");
        if (testName(section.getReverseBlockingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t");
        if (testName(section.getReverseStoppingSensorName(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        ArrayList<jmri.Block> blockList = section.getBlockList();
        for (int k = 0; k < blockList.size(); k++) {
            jmri.Block block = blockList.get(k);
            sName = block.getSystemName();
            uName = block.getUserName();
            String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameBlock"), uName, sName });
            if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
                tempText.append(line2);
                tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
                found = true;
                referenceCount++;
            }
            Sensor sensor = block.getSensor();
            if (sensor != null) {
                line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
                if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Section"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.BlockManager blockManager = InstanceManager.getDefault(jmri.BlockManager.class);
    sysNameList = blockManager.getSystemNameList();
    sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
    iter1 = sectionManager.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        String sName = iter1.next();
        jmri.Section section = sectionManager.getBySystemName(sName);
        if (section != null) {
            for (Block block : section.getBlockList()) {
                sysNameList.remove(block.getSystemName());
            }
        }
    }
    iter1 = sysNameList.iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Block b = blockManager.getBySystemName(sName);
        String uName = b.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameBlock"), uName, sName });
        if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
            tempText.append(line1);
            tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
            found = true;
            referenceCount++;
        }
        jmri.Sensor s = b.getSensor();
        if (s != null) {
            String line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
            if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Block"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
    iter1 = lbm.getSystemNameList().iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.jmrit.display.layoutEditor.LayoutBlock lb = lbm.getBySystemName(sName);
        if (lb == null) {
            log.error("Error getting LayoutBlock - " + sName);
            break;
        }
        String uName = lb.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("LayoutBlock"), uName, sName });
        jmri.Sensor s = lb.getOccupancySensor();
        if (s != null) {
            String line = MessageFormat.format(rbm.getString("OccupancySensor"), "\t\t");
            if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
                found = true;
                referenceCount++;
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "LayoutBlock"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    java.util.Enumeration<BlockBossLogic> enumeration = BlockBossLogic.entries();
    while (enumeration.hasMoreElements()) {
        // get the next Logix
        BlockBossLogic bbl = enumeration.nextElement();
        String sName = bbl.getName();
        String uName = bbl.getDrivenSignal();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("BlockBossLogic"), uName, sName });
        if (uName.equals(sysName) || uName.equals(userName) || sName.equals(sysName) || sName.equals(userName)) {
            tempText.append(line1);
            tempText.append(MessageFormat.format(rbm.getString("SignalReference"), "\t"));
            found = true;
            referenceCount++;
        }
        String line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
        if (testName(bbl.getSensor1(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
        if (testName(bbl.getSensor2(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "3\t");
        if (testName(bbl.getSensor3(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "4\t");
        if (testName(bbl.getSensor4(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "5\t");
        if (testName(bbl.getSensor5(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "\t");
        if (testName(bbl.getTurnout(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSignalReference"), "1\t");
        if (testName(bbl.getWatchedSignal1(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "1Alt\t");
        if (testName(bbl.getWatchedSignal1Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2\t");
        if (testName(bbl.getWatchedSignal2(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2Alt\t");
        if (testName(bbl.getWatchedSignal2Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
        if (testName(bbl.getWatchedSensor1(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1Alt\t");
        if (testName(bbl.getWatchedSensor1Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
        if (testName(bbl.getWatchedSensor2(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2Alt\t");
        if (testName(bbl.getWatchedSensor2Alt(), found, names, line1, null, line, tempText)) {
            found = true;
            referenceCount++;
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "BlockBossLogic"));
        } else {
            text.append("\n");
        }
    }
    tempText = new StringBuilder();
    found = false;
    empty = true;
    jmri.ConditionalManager conditionalManager = InstanceManager.getDefault(jmri.ConditionalManager.class);
    sysNameList = conditionalManager.getSystemNameList();
    iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
    while (iter1.hasNext()) {
        String sName = iter1.next();
        Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
        for (int i = 0; i < x.getNumConditionals(); i++) {
            sName = x.getConditionalByNumberOrder(i);
            sysNameList.remove(sName);
        }
    }
    iter1 = sysNameList.iterator();
    while (iter1.hasNext()) {
        // get the next Logix
        String sName = iter1.next();
        jmri.Conditional c = conditionalManager.getBySystemName(sName);
        if (c == null) {
            log.error("Error getting Condition - " + sName);
            break;
        }
        String uName = c.getUserName();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameConditional"), uName, sName });
        if (sName.equals(sysName) || uName.equals(userName)) {
            tempText.append(line1);
            tempText.append(MessageFormat.format(rbm.getString("ConditionalReference"), "\t"));
            found = true;
        //referenceCount++; Don't count, this conditional is orphaned by logix(es)
        }
        ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
        for (int k = 0; k < variableList.size(); k++) {
            ConditionalVariable v = variableList.get(k);
            String line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
            if (testName(v.getName(), found, names, line1, null, line, tempText)) {
                found = true;
            //referenceCount++; Don't count, this conditional is orphaned by logix(es)
            }
        }
        ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
        for (int k = 0; k < actionList.size(); k++) {
            ConditionalAction a = actionList.get(k);
            String line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
            if (testName(a.getDeviceName(), found, names, line1, null, line, tempText)) {
                found = true;
            //referenceCount++; Don't count, this conditional is orphaned by logix(es)
            }
        }
        if (text != null && found) {
            text.append(tempText.toString());
            tempText = new StringBuilder();
            found = false;
            empty = false;
            line1 = null;
        }
    }
    if (text != null) {
        if (empty) {
            text.append(MessageFormat.format(rbm.getString("NoReference"), "Conditional"));
        }
        text.append("\n");
    }
    found = false;
    empty = true;
    ArrayList<jmri.jmrit.display.Editor> panelList = jmri.jmrit.display.PanelMenu.instance().getEditorPanelList();
    for (int i = 0; i < panelList.size(); i++) {
        jmri.jmrit.display.Editor panelEditor = panelList.get(i);
        name = panelEditor.getTitle();
        String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("Panel"), name, name });
        List<Positionable> contents = panelEditor.getContents();
        for (int k = 0; k < contents.size(); k++) {
            Positionable o = contents.get(k);
            if (o.getClass().getName().equals("jmri.jmrit.display.SensorIcon")) {
                name = ((jmri.jmrit.display.SensorIcon) o).getSensor().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSensor") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.TurnoutIcon")) {
                name = ((jmri.jmrit.display.TurnoutIcon) o).getTurnout().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameTurnout") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.SignalHeadIcon")) {
                name = ((jmri.jmrit.display.SignalHeadIcon) o).getSignalHead().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSignalHead") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.MultiSensorIcon")) {
                jmri.jmrit.display.MultiSensorIcon msi = (jmri.jmrit.display.MultiSensorIcon) o;
                for (int j = 0; j < msi.getNumEntries(); j++) {
                    name = msi.getSensorName(j);
                    String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("MultiSensor") });
                    if (testName(name, found, names, line1, null, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTurnoutIcon")) {
                jmri.jmrit.display.IndicatorTurnoutIcon ito = (jmri.jmrit.display.IndicatorTurnoutIcon) o;
                name = ito.getTurnout().getSystemName();
                String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
                if (testName(name, found, names, line1, null, line, tempText)) {
                    found = true;
                    referenceCount++;
                }
                Sensor sensor = ito.getOccSensor();
                if (sensor != null) {
                    name = sensor.getSystemName();
                    line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
                    if (testName(name, found, names, line1, null, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
                jmri.jmrit.logix.OBlock block = ito.getOccBlock();
                if (block != null) {
                    sensor = block.getSensor();
                    if (sensor != null) {
                        name = sensor.getSystemName();
                        line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
                        if (testName(name, found, names, line1, null, line, tempText)) {
                            found = true;
                            referenceCount++;
                        }
                    }
                }
            } else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTrackIcon")) {
                jmri.jmrit.display.IndicatorTrackIcon track = (jmri.jmrit.display.IndicatorTrackIcon) o;
                Sensor sensor = track.getOccSensor();
                if (sensor != null) {
                    name = sensor.getSystemName();
                    String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
                    if (testName(name, found, names, line1, null, line, tempText)) {
                        found = true;
                        referenceCount++;
                    }
                }
                jmri.jmrit.logix.OBlock block = track.getOccBlock();
                if (block != null) {
                    sensor = block.getSensor();
                    if (sensor != null) {
                        name = sensor.getSystemName();
                        String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
                        if (testName(name, found, names, line1, null, line, tempText)) {
                            found = true;
                            referenceCount++;
                        }
                    }
                }
            }
            if (text != null && found) {
                text.append(tempText.toString());
                tempText = new StringBuilder();
                found = false;
                empty = false;
                line1 = null;
            }
        }
        if (text != null) {
            if (empty) {
                text.append(MessageFormat.format(rbm.getString("NoReference"), "Panel"));
            }
        }
    }
    if (text != null) {
        if (referenceCount == 0) {
            text.append(MessageFormat.format(rbm.getString("Orphan"), (Object[]) names));
        } else {
            text.append(MessageFormat.format(rbm.getString("ReferenceFound"), new Object[] { Integer.valueOf(referenceCount), userName, sysName }));
        }
    }
    if (names[0] != null) {
        // The manager is always a listener
        int numListeners = Integer.parseInt(names[3]) - 1;
        // PickLists are also listeners
        numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances(names[0]);
        if (names[0].equals("Sensor")) {
            // NOI18N
            numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances("MultiSensor");
        }
        if (numListeners > referenceCount) {
            if (names[0].length() == 0) {
                names[0] = "Unknown Type?";
            }
            /*
                 JOptionPane.showMessageDialog(null,
                 MessageFormat.format(rbm.getString("OrphanName"), (Object[])names)+" has "+numListeners+
                 " listeners installed and only "+referenceCount+
                 " references found.\n"+names[0]+
                 " Tables are listeneners.  Check that the table is closed.",
                 rbm.getString("infoTitle"), JOptionPane.INFORMATION_MESSAGE);
                 */
            if (text != null) {
                text.append(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) names) + " has " + numListeners + " listeners installed and only " + referenceCount + " references found.\n" + names[0] + " Tables are listeneners.  Check that the table is closed.");
            }
        }
    }
    return (referenceCount > 0);
}
Also used : Sensor(jmri.Sensor) Conditional(jmri.Conditional) Conditional(jmri.Conditional) Block(jmri.Block) Logix(jmri.Logix) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) Sensor(jmri.Sensor) ConditionalAction(jmri.ConditionalAction) ConditionalVariable(jmri.ConditionalVariable) BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Positionable(jmri.jmrit.display.Positionable)

Example 2 with BlockBossLogic

use of jmri.jmrit.blockboss.BlockBossLogic in project JMRI by JMRI.

the class BlockBossLogicXml method store.

/**
     * Default implementation for storing the contents of all the BLockBossLogic
     * elements.
     * <P>
     * Static members in the BlockBossLogic class record the complete set of
     * items. This function writes those out as a single XML element.
     *
     * @param o Object to start process, but not actually used
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Enumeration<BlockBossLogic> e = BlockBossLogic.entries();
    if (!e.hasMoreElements()) {
        // nothing to write!
        return null;
    }
    Element blocks = new Element("signalelements");
    blocks.setAttribute("class", this.getClass().getName());
    while (e.hasMoreElements()) {
        BlockBossLogic p = e.nextElement();
        Element block = new Element("signalelement");
        block.setAttribute("signal", p.getDrivenSignal());
        block.setAttribute("mode", "" + p.getMode());
        if (p.getApproachSensor1() != null) {
            block.setAttribute("approachsensor1", p.getApproachSensor1());
        }
        if (p.getSensor1() != null) {
            block.addContent(storeSensor(p.getSensor1()));
        }
        if (p.getSensor2() != null) {
            block.addContent(storeSensor(p.getSensor2()));
        }
        if (p.getSensor3() != null) {
            block.addContent(storeSensor(p.getSensor3()));
        }
        if (p.getSensor4() != null) {
            block.addContent(storeSensor(p.getSensor4()));
        }
        if (p.getSensor5() != null) {
            block.addContent(storeSensor(p.getSensor5()));
        }
        if (p.getTurnout() != null) {
            block.setAttribute("watchedturnout", p.getTurnout());
        }
        if (p.getWatchedSignal1() != null) {
            block.setAttribute("watchedsignal1", p.getWatchedSignal1());
        }
        if (p.getWatchedSignal1Alt() != null) {
            block.setAttribute("watchedsignal1alt", p.getWatchedSignal1Alt());
        }
        if (p.getWatchedSignal2() != null) {
            block.setAttribute("watchedsignal2", p.getWatchedSignal2());
        }
        if (p.getWatchedSignal2Alt() != null) {
            block.setAttribute("watchedsignal2alt", p.getWatchedSignal2Alt());
        }
        if (p.getWatchedSensor1() != null) {
            block.setAttribute("watchedsensor1", p.getWatchedSensor1());
        }
        if (p.getWatchedSensor1Alt() != null) {
            block.setAttribute("watchedsensor1alt", p.getWatchedSensor1Alt());
        }
        if (p.getWatchedSensor2() != null) {
            block.setAttribute("watchedsensor2", p.getWatchedSensor2());
        }
        if (p.getWatchedSensor2Alt() != null) {
            block.setAttribute("watchedsensor2alt", p.getWatchedSensor2Alt());
        }
        block.setAttribute("limitspeed1", "" + p.getLimitSpeed1());
        block.setAttribute("limitspeed2", "" + p.getLimitSpeed2());
        block.setAttribute("useflashyellow", "" + p.getUseFlash());
        block.setAttribute("distantsignal", "" + p.getDistantSignal());
        // add comment, if present
        if (p.getComment() != null) {
            Element c = new Element("comment");
            c.addContent(p.getComment());
            block.addContent(c);
        }
        blocks.addContent(block);
    }
    return blocks;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Element(org.jdom2.Element)

Example 3 with BlockBossLogic

use of jmri.jmrit.blockboss.BlockBossLogic in project JMRI by JMRI.

the class ConnectivityUtil method removeSensorsFromSignalHeadLogic.

/*
     * Revoves the specified sensors ('names') from the SSL for the specified signal head if
     *      any of the sensors is currently in the SSL.
     * Returns 'false' if an error was found, and issues a message to the error log.
     * Returns 'true' if no error, whether any sensors were found or not.
     */
public boolean removeSensorsFromSignalHeadLogic(ArrayList<String> names, SignalHead sh) {
    if (sh == null) {
        log.error("Null signal head on entry to removeSensorsFromSignalHeadLogic");
        return false;
    }
    if (names == null) {
        log.error("Null ArrayList of sensor names on entry to removeSensorsFromSignalHeadLogic");
        return false;
    }
    BlockBossLogic bbLogic = BlockBossLogic.getStoppedObject(sh.getSystemName());
    for (int i = 0; i < names.size(); i++) {
        String name = names.get(i);
        if ((bbLogic.getSensor1() != null) && (bbLogic.getSensor1()).equals(name)) {
            bbLogic.setSensor1(null);
        }
        if ((bbLogic.getSensor2() != null) && (bbLogic.getSensor2()).equals(name)) {
            bbLogic.setSensor2(null);
        }
        if ((bbLogic.getSensor3() != null) && (bbLogic.getSensor3()).equals(name)) {
            bbLogic.setSensor3(null);
        }
        if ((bbLogic.getSensor4() != null) && (bbLogic.getSensor4()).equals(name)) {
            bbLogic.setSensor4(null);
        }
        if ((bbLogic.getSensor5() != null) && (bbLogic.getSensor5()).equals(name)) {
            bbLogic.setSensor5(null);
        }
        if (bbLogic.getMode() == BlockBossLogic.FACING) {
            if ((bbLogic.getWatchedSensor1() != null) && (bbLogic.getWatchedSensor1()).equals(name)) {
                bbLogic.setWatchedSensor1(null);
            }
            if ((bbLogic.getWatchedSensor1Alt() != null) && (bbLogic.getWatchedSensor1Alt()).equals(name)) {
                bbLogic.setWatchedSensor1Alt(null);
            }
            if ((bbLogic.getWatchedSensor2() != null) && (bbLogic.getWatchedSensor2()).equals(name)) {
                bbLogic.setWatchedSensor2(null);
            }
            if ((bbLogic.getWatchedSensor2Alt() != null) && (bbLogic.getWatchedSensor2Alt()).equals(name)) {
                bbLogic.setWatchedSensor2Alt(null);
            }
        }
    }
    if (bbLogic.getMode() == 0) {
        // this to avoid Unexpected mode ERROR message at startup
        bbLogic.setMode(BlockBossLogic.SINGLEBLOCK);
    }
    bbLogic.retain();
    bbLogic.start();
    return true;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) EntryPoint(jmri.EntryPoint)

Example 4 with BlockBossLogic

use of jmri.jmrit.blockboss.BlockBossLogic in project JMRI by JMRI.

the class BlockBossLogicXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    List<Element> l = shared.getChildren("signalelement");
    // this is for backward compatibility only
    if (l.size() == 0) {
        l = shared.getChildren("block");
    }
    // process each item
    for (int i = 0; i < l.size(); i++) {
        Element block = l.get(i);
        BlockBossLogic bb = null;
        try {
            bb = BlockBossLogic.getStoppedObject(block.getAttributeValue("signal"));
        } catch (java.lang.Exception e) {
            log.error("An error occured trying to find the signal for the signal elements for " + block.getAttributeValue("signal"));
            result = false;
        }
        if (bb != null) {
            if (block.getAttribute("approachsensor1") != null) {
                try {
                    bb.setApproachSensor1(block.getAttributeValue("approachsensor1"));
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured loading the approach sensor for the signal elements for " + bb.getDrivenSignal());
                    result = false;
                }
            }
            if (block.getAttribute("watchedsensor") != null) {
                // for older XML files
                try {
                    bb.setSensor1(block.getAttributeValue("watchedsensor"));
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured loading the watched sensor in the SSL for " + bb.getDrivenSignal());
                    result = false;
                }
            }
            // old form of sensors with system names
            List<Element> sl = block.getChildren("sensor");
            try {
                if (sl.size() >= 1 && sl.get(0) != null) {
                    bb.setSensor1(sl.get(0).getAttributeValue("systemName"));
                }
                if (sl.size() >= 2 && sl.get(1) != null) {
                    bb.setSensor2(sl.get(1).getAttributeValue("systemName"));
                }
                if (sl.size() >= 3 && sl.get(2) != null) {
                    bb.setSensor3(sl.get(2).getAttributeValue("systemName"));
                }
                if (sl.size() >= 4 && sl.get(3) != null) {
                    bb.setSensor4(sl.get(3).getAttributeValue("systemName"));
                }
                if (sl.size() >= 5 && sl.get(4) != null) {
                    bb.setSensor5(sl.get(4).getAttributeValue("systemName"));
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensors list in the SSL");
                result = false;
            }
            // new form of sensors with system names
            sl = block.getChildren("sensorname");
            try {
                if (sl.size() >= 1 && sl.get(0) != null) {
                    bb.setSensor1(sl.get(0).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor1 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 2 && sl.get(1) != null) {
                    bb.setSensor2(sl.get(1).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor2 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 3 && sl.get(2) != null) {
                    bb.setSensor3(sl.get(2).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor3 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 4 && sl.get(3) != null) {
                    bb.setSensor4(sl.get(3).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor4 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 5 && sl.get(4) != null) {
                    bb.setSensor5(sl.get(4).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor5 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                bb.setMode(block.getAttribute("mode").getIntValue());
                if (block.getAttribute("distantsignal") != null) {
                    bb.setDistantSignal(block.getAttribute("distantsignal").getBooleanValue());
                }
                if (block.getAttribute("limitspeed1") != null) {
                    bb.setLimitSpeed1(block.getAttribute("limitspeed1").getBooleanValue());
                }
                if (block.getAttribute("limitspeed2") != null) {
                    bb.setLimitSpeed2(block.getAttribute("limitspeed2").getBooleanValue());
                }
                try {
                    if (block.getAttribute("watchedturnout") != null) {
                        bb.setTurnout(block.getAttributeValue("watchedturnout"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched turnout (" + block.getAttributeValue("watchedturnout") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal1") != null) {
                        bb.setWatchedSignal1(block.getAttributeValue("watchedsignal1"), block.getAttribute("useflashyellow").getBooleanValue());
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 1 (" + block.getAttributeValue("watchedsignal1") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal1alt") != null) {
                        bb.setWatchedSignal1Alt(block.getAttributeValue("watchedsignal1alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 1 alt (" + block.getAttributeValue("watchedsignal1alt") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal2") != null) {
                        bb.setWatchedSignal2(block.getAttributeValue("watchedsignal2"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 2 (" + block.getAttributeValue("watchedsignal2") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal2alt") != null) {
                        bb.setWatchedSignal2Alt(block.getAttributeValue("watchedsignal2alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 2 alt (" + block.getAttributeValue("watchedsignal2alt") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor1") != null) {
                        bb.setWatchedSensor1(block.getAttributeValue("watchedsensor1"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 1 (" + block.getAttributeValue("watchedsensor1") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor1alt") != null) {
                        bb.setWatchedSensor1Alt(block.getAttributeValue("watchedsensor1alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 1 alt (" + block.getAttributeValue("watchedsensor1alt") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor2") != null) {
                        bb.setWatchedSensor2(block.getAttributeValue("watchedsensor2"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 2 (" + block.getAttributeValue("watchedsensor2") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor2alt") != null) {
                        bb.setWatchedSensor2Alt(block.getAttributeValue("watchedsensor2alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 2 alt (" + block.getAttributeValue("watchedsensor2alt") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                // load comment, if present
                String c = block.getChildText("comment");
                if (c != null) {
                    bb.setComment(c);
                }
            } catch (org.jdom2.DataConversionException e) {
                log.warn("error reading blocks from file" + e);
                result = false;
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured in the signal element attribute list");
                result = false;
            }
            try {
                bb.retain();
                bb.start();
            } catch (java.lang.NullPointerException e) {
                log.error("An error occured trying to start the signal logic " + bb.getDrivenSignal());
                result = false;
            }
        }
    }
    return result;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Element(org.jdom2.Element)

Example 5 with BlockBossLogic

use of jmri.jmrit.blockboss.BlockBossLogic in project JMRI by JMRI.

the class ConnectivityUtil method addSensorToSignalHeadLogic.

/*
     * Adds the specified sensor ('name') to the SSL for the specified signal head
     * 'name' should be the system name for the sensor.
     * Returns 'true' if the sensor was already in the signal head SSL or if it has been
     *      added successfully.  Returns 'false' and logs an error if not.
     * If the SSL has not been set up yet, the sensor is not added, an error message is output,
     *      and 'false' is returned.
     * Parameters: 'name' - sensor name, 'sh' - signal head, 'where' should be DIVERGING if the sensor
     *      is being added to the diverging (second) part of a facing mode SSL, 'CONTINUING' if
     *      the sensor is being added to the continuing (first) part of a facing mode SSL, OVERALL if
     *      the sensor is being added to the overall sensor list of a facing mode SSL. 'where' is
     *      ignored if not a facing mode SSL.
     */
public boolean addSensorToSignalHeadLogic(String name, SignalHead sh, int where) {
    if (sh == null) {
        log.error("Null signal head on entry to addSensorToSignalHeadLogic");
        return false;
    }
    if ((name == null) || name.equals("")) {
        log.error("Null string for sensor name on entry to addSensorToSignalHeadLogic");
        return false;
    }
    BlockBossLogic bbLogic = BlockBossLogic.getStoppedObject(sh.getSystemName());
    int mode = bbLogic.getMode();
    if (((mode == BlockBossLogic.SINGLEBLOCK) || (mode == BlockBossLogic.TRAILINGMAIN) || (mode == BlockBossLogic.TRAILINGDIVERGING)) || ((mode == BlockBossLogic.FACING) && (where == OVERALL))) {
        if (((bbLogic.getSensor1() != null) && (bbLogic.getSensor1()).equals(name)) || ((bbLogic.getSensor2() != null) && (bbLogic.getSensor2()).equals(name)) || ((bbLogic.getSensor3() != null) && (bbLogic.getSensor3()).equals(name)) || ((bbLogic.getSensor4() != null) && (bbLogic.getSensor4()).equals(name)) || ((bbLogic.getSensor5() != null) && (bbLogic.getSensor5()).equals(name))) {
            bbLogic.retain();
            bbLogic.start();
            return true;
        }
        if (bbLogic.getSensor1() == null) {
            bbLogic.setSensor1(name);
        } else if (bbLogic.getSensor2() == null) {
            bbLogic.setSensor2(name);
        } else if (bbLogic.getSensor3() == null) {
            bbLogic.setSensor3(name);
        } else if (bbLogic.getSensor4() == null) {
            bbLogic.setSensor4(name);
        } else if (bbLogic.getSensor5() == null) {
            bbLogic.setSensor5(name);
        } else {
            log.error("Error - could not add sensor to SSL for signal head " + sh.getSystemName() + " because there is no room in the SSL.");
            bbLogic.retain();
            bbLogic.start();
            return false;
        }
    } else if (mode == BlockBossLogic.FACING) {
        if (where == DIVERGING) {
            if (((bbLogic.getWatchedSensor2() != null) && (bbLogic.getWatchedSensor2()).equals(name)) || ((bbLogic.getWatchedSensor2Alt() != null) && (bbLogic.getWatchedSensor2Alt()).equals(name))) {
                bbLogic.retain();
                bbLogic.start();
                return true;
            }
            if (bbLogic.getWatchedSensor2() == null) {
                bbLogic.setWatchedSensor2(name);
            } else if (bbLogic.getWatchedSensor2Alt() == null) {
                bbLogic.setWatchedSensor2Alt(name);
            } else {
                log.error("Error - could not add watched sensor to SSL for signal head " + sh.getSystemName() + " because there is no room in the facing SSL diverging part.");
                bbLogic.retain();
                bbLogic.start();
                return false;
            }
        } else if (where == CONTINUING) {
            if (((bbLogic.getWatchedSensor1() != null) && (bbLogic.getWatchedSensor1()).equals(name)) || ((bbLogic.getWatchedSensor1Alt() != null) && (bbLogic.getWatchedSensor1Alt()).equals(name))) {
                bbLogic.retain();
                bbLogic.start();
                return true;
            }
            if (bbLogic.getWatchedSensor1() == null) {
                bbLogic.setWatchedSensor1(name);
            } else if (bbLogic.getWatchedSensor1Alt() == null) {
                bbLogic.setWatchedSensor1Alt(name);
            } else {
                log.error("Error - could not add watched sensor to SSL for signal head " + sh.getSystemName() + " because there is no room in the facing SSL continuing part.");
                bbLogic.retain();
                bbLogic.start();
                return false;
            }
        } else {
            log.error("Error - could not add watched sensor to SSL for signal head " + sh.getSystemName() + "because 'where' to place the sensor was not correctly designated.");
            bbLogic.retain();
            bbLogic.start();
            return false;
        }
    } else {
        log.error("SSL has not been set up for signal head " + sh.getSystemName() + ". Could not add sensor - " + name + ".");
        return false;
    }
    bbLogic.retain();
    bbLogic.start();
    return true;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) EntryPoint(jmri.EntryPoint)

Aggregations

BlockBossLogic (jmri.jmrit.blockboss.BlockBossLogic)5 EntryPoint (jmri.EntryPoint)2 Element (org.jdom2.Element)2 Block (jmri.Block)1 Conditional (jmri.Conditional)1 ConditionalAction (jmri.ConditionalAction)1 ConditionalVariable (jmri.ConditionalVariable)1 Logix (jmri.Logix)1 Sensor (jmri.Sensor)1 Positionable (jmri.jmrit.display.Positionable)1 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)1